Browse Source

SERVICE_ERROR_LOG

ENGINE-641
Volker Birk 3 years ago
parent
commit
932aea2e83
4 changed files with 90 additions and 66 deletions
  1. +39
    -25
      src/pEpEngine.c
  2. +5
    -41
      src/pEpEngine.h
  3. +44
    -0
      src/status_to_string.h
  4. +2
    -0
      sync/gen_statemachine.ysl2

+ 39
- 25
src/pEpEngine.c View File

@ -2017,32 +2017,31 @@ DYNAMIC_API PEP_STATUS log_event(
#if !defined(NDEBUG) && !defined(_PEP_SERVICE_LOG_OFF)
fprintf(stdout, "\n*** %s %s %s %s\n", title, entity, description, comment);
session->service_log = true;
#endif
// PEP_STATUS status = PEP_STATUS_OK;
// int result;
//
// assert(session);
// assert(title);
// assert(entity);
//
// if (!(session && title && entity))
// return PEP_ILLEGAL_VALUE;
//
// sqlite3_reset(session->log);
// sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
// sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
// if (description)
// sqlite3_bind_text(session->log, 3, description, -1, SQLITE_STATIC);
// else
// sqlite3_bind_null(session->log, 3);
// if (comment)
// sqlite3_bind_text(session->log, 4, comment, -1, SQLITE_STATIC);
// else
// sqlite3_bind_null(session->log, 4);
// result = Sqlite3_step(session->log);
// sqlite3_reset(session->log);
//
int result;
assert(session);
assert(title);
assert(entity);
if (!(session && title && entity))
return PEP_ILLEGAL_VALUE;
sqlite3_reset(session->log);
sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
if (description)
sqlite3_bind_text(session->log, 3, description, -1, SQLITE_STATIC);
else
sqlite3_bind_null(session->log, 3);
if (comment)
sqlite3_bind_text(session->log, 4, comment, -1, SQLITE_STATIC);
else
sqlite3_bind_null(session->log, 4);
result = Sqlite3_step(session->log);
sqlite3_reset(session->log);
#endif
return PEP_STATUS_OK; // We ignore errors for this function.
}
@ -5071,3 +5070,18 @@ DYNAMIC_API void clear_errorstack(PEP_SESSION session)
}
#endif
DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
PEP_STATUS status, const char *where)
{
char buffer[128];
static const size_t size = 127;
memset(buffer, 0, size+1);
#ifdef PEP_STATUS_TO_STRING
snprintf(buffer, size, "%s %.4x", pEp_status_to_string(status), status);
#else
snprintf(buffer, size, "error %.4x", status);
#endif
log_service(session, "### service error log ###", entity, buffer, where);
}

+ 5
- 41
src/pEpEngine.h View File

@ -438,6 +438,11 @@ DYNAMIC_API PEP_STATUS log_service(PEP_SESSION session, const char *title,
#define SERVICE_LOG(session, title, entity, desc) \
log_service((session), (title), (entity), (desc), "service " __FILE__ ":" S_LINE)
DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
PEP_STATUS status, const char *where);
#define SERVICE_ERROR_LOG(session, entity, status) \
_service_error_log((session), (entity), (status), __FILE__ ":" S_LINE)
// trustword() - get the corresponding trustword for a 16 bit value
//
@ -563,47 +568,6 @@ typedef enum _PEP_comm_type {
PEP_ct_pEp = 0xff
} PEP_comm_type;
static inline const char *pep_comm_type_to_string(PEP_comm_type ct) {
switch (ct) {
case PEP_ct_unknown: return "unknown";
case PEP_ct_no_encryption: return "no_encryption";
case PEP_ct_no_encrypted_channel: return "no_encrypted_channel";
case PEP_ct_key_not_found: return "key_not_found";
case PEP_ct_key_expired: return "key_expired";
case PEP_ct_key_revoked: return "key_revoked";
case PEP_ct_key_b0rken: return "key_b0rken";
case PEP_ct_my_key_not_included: return "my_key_not_included";
case PEP_ct_security_by_obscurity: return "security_by_obscurity";
case PEP_ct_b0rken_crypto: return "b0rken_crypto";
case PEP_ct_key_too_short: return "key_too_short";
case PEP_ct_compromised: return "compromised";
case PEP_ct_mistrusted: return "mistrusted";
case PEP_ct_unconfirmed_encryption: return "unconfirmed_encryption";
case PEP_ct_OpenPGP_weak_unconfirmed: return "OpenPGP_weak_unconfirmed";
case PEP_ct_to_be_checked: return "to_be_checked";
case PEP_ct_SMIME_unconfirmed: return "SMIME_unconfirmed";
case PEP_ct_CMS_unconfirmed: return "CMS_unconfirmed";
case PEP_ct_strong_but_unconfirmed: return "strong_but_unconfirmed";
case PEP_ct_OpenPGP_unconfirmed: return "OpenPGP_unconfirmed";
case PEP_ct_OTR_unconfirmed: return "OTR_unconfirmed";
case PEP_ct_unconfirmed_enc_anon: return "unconfirmed_enc_anon";
case PEP_ct_pEp_unconfirmed: return "pEp_unconfirmed";
case PEP_ct_confirmed: return "confirmed";
case PEP_ct_confirmed_encryption: return "confirmed_encryption";
case PEP_ct_OpenPGP_weak: return "OpenPGP_weak";
case PEP_ct_to_be_checked_confirmed: return "to_be_checked_confirmed";
case PEP_ct_SMIME: return "SMIME";
case PEP_ct_CMS: return "CMS";
case PEP_ct_strong_encryption: return "strong_encryption";
case PEP_ct_OpenPGP: return "OpenPGP";
case PEP_ct_OTR: return "OTR";
case PEP_ct_confirmed_enc_anon: return "confirmed_enc_anon";
case PEP_ct_pEp: return "pEp";
default: return "invalid comm type";
}
}
typedef enum _identity_flags {
// the first octet flags are app defined settings
PEP_idf_not_for_sync = 0x0001, // don't use this identity for sync


+ 44
- 0
src/status_to_string.h View File

@ -4,6 +4,10 @@
extern "C" {
#endif
#ifndef PEP_STATUS_TO_STRING
#define PEP_STATUS_TO_STRING
#endif
static inline const char *pEp_status_to_string(PEP_STATUS status) {
switch (status) {
case PEP_STATUS_OK: return "PEP_STATUS_OK";
@ -103,6 +107,46 @@ static inline const char *pEp_status_to_string(PEP_STATUS status) {
}
}
static inline const char *pEp_comm_type_to_string(PEP_comm_type ct) {
switch (ct) {
case PEP_ct_unknown: return "unknown";
case PEP_ct_no_encryption: return "no_encryption";
case PEP_ct_no_encrypted_channel: return "no_encrypted_channel";
case PEP_ct_key_not_found: return "key_not_found";
case PEP_ct_key_expired: return "key_expired";
case PEP_ct_key_revoked: return "key_revoked";
case PEP_ct_key_b0rken: return "key_b0rken";
case PEP_ct_my_key_not_included: return "my_key_not_included";
case PEP_ct_security_by_obscurity: return "security_by_obscurity";
case PEP_ct_b0rken_crypto: return "b0rken_crypto";
case PEP_ct_key_too_short: return "key_too_short";
case PEP_ct_compromised: return "compromised";
case PEP_ct_mistrusted: return "mistrusted";
case PEP_ct_unconfirmed_encryption: return "unconfirmed_encryption";
case PEP_ct_OpenPGP_weak_unconfirmed: return "OpenPGP_weak_unconfirmed";
case PEP_ct_to_be_checked: return "to_be_checked";
case PEP_ct_SMIME_unconfirmed: return "SMIME_unconfirmed";
case PEP_ct_CMS_unconfirmed: return "CMS_unconfirmed";
case PEP_ct_strong_but_unconfirmed: return "strong_but_unconfirmed";
case PEP_ct_OpenPGP_unconfirmed: return "OpenPGP_unconfirmed";
case PEP_ct_OTR_unconfirmed: return "OTR_unconfirmed";
case PEP_ct_unconfirmed_enc_anon: return "unconfirmed_enc_anon";
case PEP_ct_pEp_unconfirmed: return "pEp_unconfirmed";
case PEP_ct_confirmed: return "confirmed";
case PEP_ct_confirmed_encryption: return "confirmed_encryption";
case PEP_ct_OpenPGP_weak: return "OpenPGP_weak";
case PEP_ct_to_be_checked_confirmed: return "to_be_checked_confirmed";
case PEP_ct_SMIME: return "SMIME";
case PEP_ct_CMS: return "CMS";
case PEP_ct_strong_encryption: return "strong_encryption";
case PEP_ct_OpenPGP: return "OpenPGP";
case PEP_ct_OTR: return "OTR";
case PEP_ct_confirmed_enc_anon: return "confirmed_enc_anon";
case PEP_ct_pEp: return "pEp";
default: return "invalid comm type";
}
}
#ifdef __cplusplus
} // "C"
#endif


+ 2
- 0
sync/gen_statemachine.ysl2 View File

@ -766,6 +766,8 @@ tstylesheet {
free(data);
free(key_data);
free_«@name»_message(msg);
if (status)
SERVICE_ERROR_LOG(session, "send_«@name»_message()", status);
return status;
}


Loading…
Cancel
Save