add stringlist_t errorstack to session and functions to deal with it, when -DDEBUG_ERRORSTACK ENGINE-199
authorRoker <roker@pep-project.org>
Wed, 19 Apr 2017 17:44:19 +0200
branchENGINE-199
changeset 17221d16b6822287
parent 1721 66a4d1b05d28
child 1728 3c032ad43e6e
add stringlist_t errorstack to session and functions to deal with it, when -DDEBUG_ERRORSTACK
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Wed Apr 19 13:42:06 2017 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Apr 19 17:44:19 2017 +0200
     1.3 @@ -234,6 +234,10 @@
     1.4  
     1.5      _session->version = PEP_ENGINE_VERSION;
     1.6  
     1.7 +#ifdef DEBUG_ERRORSTACK
     1.8 +    _session->errorstack = new_stringlist(NULL);
     1.9 +#endif
    1.10 +
    1.11      assert(LOCAL_DB);
    1.12      if (LOCAL_DB == NULL) {
    1.13          status = PEP_INIT_CANNOT_OPEN_DB;
    1.14 @@ -749,6 +753,9 @@
    1.15          release_transport_system(session, out_last);
    1.16          release_cryptotech(session, out_last);
    1.17  
    1.18 +#ifdef DEBUG_ERRORSTACK
    1.19 +        free_stringlist(session->errorstack);
    1.20 +#endif
    1.21          free(session);
    1.22      }
    1.23  }
    1.24 @@ -2272,3 +2279,39 @@
    1.25  
    1.26      return PEP_STATUS_OK;
    1.27  }
    1.28 +
    1.29 +#ifdef DEBUG_ERRORSTACK
    1.30 +PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status)
    1.31 +{
    1.32 +    char logline[48];
    1.33 +    if(status>0)
    1.34 +    {
    1.35 +        snprintf(logline,47, "%24s:%u status=%u (0x%x)", file, line, status, status);
    1.36 +    }else{
    1.37 +        snprintf(logline,47, "%24s:%u status=%i.", file, line, status);
    1.38 +    }
    1.39 +    stringlist_add(session->errorstack, logline); // logline is copied! :-)
    1.40 +    return status;
    1.41 +}
    1.42 +
    1.43 +DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session)
    1.44 +{
    1.45 +    return session->errorstack;
    1.46 +}
    1.47 +
    1.48 +#else
    1.49 +
    1.50 +static stringlist_t* dummy_errorstack = NULL;
    1.51 +
    1.52 +DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session)
    1.53 +{
    1.54 +	if(dummy_errorstack == NULL)
    1.55 +	{
    1.56 +		dummy_errorstack = new_stringlist("( Please recompile pEpEngine with -DDEBUG_ERRORSTACK )");
    1.57 +	}
    1.58 +	
    1.59 +    return dummy_errorstack;
    1.60 +}
    1.61 +
    1.62 +#endif
    1.63 +
     2.1 --- a/src/pEpEngine.h	Wed Apr 19 13:42:06 2017 +0200
     2.2 +++ b/src/pEpEngine.h	Wed Apr 19 17:44:19 2017 +0200
     2.3 @@ -147,6 +147,17 @@
     2.4  DYNAMIC_API void release(PEP_SESSION session);
     2.5  
     2.6  
     2.7 +// const stringlist_t* get_errorstack(PEP_SESSION) - get the error stack for that session, if any
     2.8 +//
     2.9 +//  parameters:
    2.10 +//        session (in)    session handle
    2.11 +//
    2.12 +//    caveat:
    2.13 +//        To get a useful error stack you have to compile with -DDEBUG_ERRORSTACK
    2.14 +//        The error stack belongs to the session. Do no not change it!
    2.15 +DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session);
    2.16 +
    2.17 +
    2.18  // config_passive_mode() - enable passive mode
    2.19  //
    2.20  //  parameters:
     3.1 --- a/src/pEp_internal.h	Wed Apr 19 13:42:06 2017 +0200
     3.2 +++ b/src/pEp_internal.h	Wed Apr 19 17:44:19 2017 +0200
     3.3 @@ -162,8 +162,12 @@
     3.4      bool use_only_own_private_keys;
     3.5      bool keep_sync_msg;
     3.6      
     3.7 +#ifdef DEBUG_ERRORSTACK
     3.8 +    stringlist_t* errorstack;
     3.9 +#endif
    3.10  };
    3.11  
    3.12 +
    3.13  PEP_STATUS init_transport_system(PEP_SESSION session, bool in_first);
    3.14  void release_transport_system(PEP_SESSION session, bool out_last);
    3.15  
    3.16 @@ -229,3 +233,11 @@
    3.17      
    3.18      return ai == fpras && bi == fprbs;
    3.19  }
    3.20 +
    3.21 +
    3.22 +#ifdef DEBUG_ERRORSTACK
    3.23 +    PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status);
    3.24 +    #define ERROR(status)   session_add_error(session, __FILE__, __LINE__, (status))
    3.25 +#else
    3.26 +    #define ERROR(status)   (status)
    3.27 +#endif