SERVICE_ERROR_LOG sync
authorVolker Birk <vb@pep-project.org>
Tue, 28 May 2019 12:09:20 +0200
branchsync
changeset 374782fe58af7b53
parent 3745 1ee3caae7f33
child 3748 2626a1c321ff
child 3752 856412ae847e
child 3754 7d9c7bc6f412
SERVICE_ERROR_LOG
src/pEpEngine.c
src/pEpEngine.h
src/status_to_string.h
sync/gen_statemachine.ysl2
     1.1 --- a/src/pEpEngine.c	Mon May 27 16:58:22 2019 +0200
     1.2 +++ b/src/pEpEngine.c	Tue May 28 12:09:20 2019 +0200
     1.3 @@ -2017,32 +2017,31 @@
     1.4  #if !defined(NDEBUG) && !defined(_PEP_SERVICE_LOG_OFF)
     1.5      fprintf(stdout, "\n*** %s %s %s %s\n", title, entity, description, comment);
     1.6      session->service_log = true;
     1.7 +
     1.8 +    int result;
     1.9 +    
    1.10 +    assert(session);
    1.11 +    assert(title);
    1.12 +    assert(entity);
    1.13 +    
    1.14 +    if (!(session && title && entity))
    1.15 +        return PEP_ILLEGAL_VALUE;
    1.16 +    
    1.17 +    sqlite3_reset(session->log);
    1.18 +    sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
    1.19 +    sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
    1.20 +    if (description)
    1.21 +        sqlite3_bind_text(session->log, 3, description, -1, SQLITE_STATIC);
    1.22 +    else
    1.23 +        sqlite3_bind_null(session->log, 3);
    1.24 +    if (comment)
    1.25 +        sqlite3_bind_text(session->log, 4, comment, -1, SQLITE_STATIC);
    1.26 +    else
    1.27 +        sqlite3_bind_null(session->log, 4);
    1.28 +    result = Sqlite3_step(session->log);
    1.29 +    sqlite3_reset(session->log);
    1.30 +    
    1.31  #endif
    1.32 -
    1.33 -    // PEP_STATUS status = PEP_STATUS_OK;
    1.34 -    // int result;
    1.35 -    // 
    1.36 -    // assert(session);
    1.37 -    // assert(title);
    1.38 -    // assert(entity);
    1.39 -    // 
    1.40 -    // if (!(session && title && entity))
    1.41 -    //     return PEP_ILLEGAL_VALUE;
    1.42 -    // 
    1.43 -    // sqlite3_reset(session->log);
    1.44 -    // sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
    1.45 -    // sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
    1.46 -    // if (description)
    1.47 -    //     sqlite3_bind_text(session->log, 3, description, -1, SQLITE_STATIC);
    1.48 -    // else
    1.49 -    //     sqlite3_bind_null(session->log, 3);
    1.50 -    // if (comment)
    1.51 -    //     sqlite3_bind_text(session->log, 4, comment, -1, SQLITE_STATIC);
    1.52 -    // else
    1.53 -    //     sqlite3_bind_null(session->log, 4);
    1.54 -    // result = Sqlite3_step(session->log);
    1.55 -    // sqlite3_reset(session->log);
    1.56 -    // 
    1.57      return PEP_STATUS_OK; // We ignore errors for this function.
    1.58  }
    1.59  
    1.60 @@ -5071,3 +5070,18 @@
    1.61  }
    1.62  
    1.63  #endif
    1.64 +
    1.65 +DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
    1.66 +        PEP_STATUS status, const char *where)
    1.67 +{
    1.68 +    char buffer[128];
    1.69 +    static const size_t size = 127;
    1.70 +    memset(buffer, 0, size+1);
    1.71 +#ifdef PEP_STATUS_TO_STRING
    1.72 +    snprintf(buffer, size, "%s %.4x", pEp_status_to_string(status), status);
    1.73 +#else
    1.74 +    snprintf(buffer, size, "error %.4x", status);
    1.75 +#endif
    1.76 +    log_service(session, "### service error log ###", entity, buffer, where);
    1.77 +}
    1.78 +
     2.1 --- a/src/pEpEngine.h	Mon May 27 16:58:22 2019 +0200
     2.2 +++ b/src/pEpEngine.h	Tue May 28 12:09:20 2019 +0200
     2.3 @@ -438,6 +438,11 @@
     2.4  #define SERVICE_LOG(session, title, entity, desc) \
     2.5      log_service((session), (title), (entity), (desc), "service " __FILE__ ":" S_LINE)
     2.6  
     2.7 +DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
     2.8 +        PEP_STATUS status, const char *where);
     2.9 +
    2.10 +#define SERVICE_ERROR_LOG(session, entity, status) \
    2.11 +    _service_error_log((session), (entity), (status), __FILE__ ":" S_LINE)
    2.12  
    2.13  // trustword() - get the corresponding trustword for a 16 bit value
    2.14  //
    2.15 @@ -563,47 +568,6 @@
    2.16      PEP_ct_pEp = 0xff
    2.17  } PEP_comm_type;
    2.18  
    2.19 -static inline const char *pep_comm_type_to_string(PEP_comm_type ct) {
    2.20 -    switch (ct) {
    2.21 -    case PEP_ct_unknown: return "unknown";
    2.22 -    case PEP_ct_no_encryption: return "no_encryption";
    2.23 -    case PEP_ct_no_encrypted_channel: return "no_encrypted_channel";
    2.24 -    case PEP_ct_key_not_found: return "key_not_found";
    2.25 -    case PEP_ct_key_expired: return "key_expired";
    2.26 -    case PEP_ct_key_revoked: return "key_revoked";
    2.27 -    case PEP_ct_key_b0rken: return "key_b0rken";
    2.28 -    case PEP_ct_my_key_not_included: return "my_key_not_included";
    2.29 -    case PEP_ct_security_by_obscurity: return "security_by_obscurity";
    2.30 -    case PEP_ct_b0rken_crypto: return "b0rken_crypto";
    2.31 -    case PEP_ct_key_too_short: return "key_too_short";
    2.32 -    case PEP_ct_compromised: return "compromised";
    2.33 -    case PEP_ct_mistrusted: return "mistrusted";
    2.34 -    case PEP_ct_unconfirmed_encryption: return "unconfirmed_encryption";
    2.35 -    case PEP_ct_OpenPGP_weak_unconfirmed: return "OpenPGP_weak_unconfirmed";
    2.36 -    case PEP_ct_to_be_checked: return "to_be_checked";
    2.37 -    case PEP_ct_SMIME_unconfirmed: return "SMIME_unconfirmed";
    2.38 -    case PEP_ct_CMS_unconfirmed: return "CMS_unconfirmed";
    2.39 -    case PEP_ct_strong_but_unconfirmed: return "strong_but_unconfirmed";
    2.40 -    case PEP_ct_OpenPGP_unconfirmed: return "OpenPGP_unconfirmed";
    2.41 -    case PEP_ct_OTR_unconfirmed: return "OTR_unconfirmed";
    2.42 -    case PEP_ct_unconfirmed_enc_anon: return "unconfirmed_enc_anon";
    2.43 -    case PEP_ct_pEp_unconfirmed: return "pEp_unconfirmed";
    2.44 -    case PEP_ct_confirmed: return "confirmed";
    2.45 -    case PEP_ct_confirmed_encryption: return "confirmed_encryption";
    2.46 -    case PEP_ct_OpenPGP_weak: return "OpenPGP_weak";
    2.47 -    case PEP_ct_to_be_checked_confirmed: return "to_be_checked_confirmed";
    2.48 -    case PEP_ct_SMIME: return "SMIME";
    2.49 -    case PEP_ct_CMS: return "CMS";
    2.50 -    case PEP_ct_strong_encryption: return "strong_encryption";
    2.51 -    case PEP_ct_OpenPGP: return "OpenPGP";
    2.52 -    case PEP_ct_OTR: return "OTR";
    2.53 -    case PEP_ct_confirmed_enc_anon: return "confirmed_enc_anon";
    2.54 -    case PEP_ct_pEp: return "pEp";
    2.55 -    default: return "invalid comm type";
    2.56 -    }
    2.57 -}
    2.58 -
    2.59 -
    2.60  typedef enum _identity_flags {
    2.61      // the first octet flags are app defined settings
    2.62      PEP_idf_not_for_sync = 0x0001,   // don't use this identity for sync
     3.1 --- a/src/status_to_string.h	Mon May 27 16:58:22 2019 +0200
     3.2 +++ b/src/status_to_string.h	Tue May 28 12:09:20 2019 +0200
     3.3 @@ -4,6 +4,10 @@
     3.4  extern "C" {
     3.5  #endif
     3.6  
     3.7 +#ifndef PEP_STATUS_TO_STRING
     3.8 +#define PEP_STATUS_TO_STRING
     3.9 +#endif
    3.10 +
    3.11  static inline const char *pEp_status_to_string(PEP_STATUS status) {
    3.12      switch (status) {
    3.13      case PEP_STATUS_OK: return "PEP_STATUS_OK";
    3.14 @@ -103,6 +107,46 @@
    3.15      }
    3.16  }
    3.17  
    3.18 +static inline const char *pEp_comm_type_to_string(PEP_comm_type ct) {
    3.19 +    switch (ct) {
    3.20 +    case PEP_ct_unknown: return "unknown";
    3.21 +    case PEP_ct_no_encryption: return "no_encryption";
    3.22 +    case PEP_ct_no_encrypted_channel: return "no_encrypted_channel";
    3.23 +    case PEP_ct_key_not_found: return "key_not_found";
    3.24 +    case PEP_ct_key_expired: return "key_expired";
    3.25 +    case PEP_ct_key_revoked: return "key_revoked";
    3.26 +    case PEP_ct_key_b0rken: return "key_b0rken";
    3.27 +    case PEP_ct_my_key_not_included: return "my_key_not_included";
    3.28 +    case PEP_ct_security_by_obscurity: return "security_by_obscurity";
    3.29 +    case PEP_ct_b0rken_crypto: return "b0rken_crypto";
    3.30 +    case PEP_ct_key_too_short: return "key_too_short";
    3.31 +    case PEP_ct_compromised: return "compromised";
    3.32 +    case PEP_ct_mistrusted: return "mistrusted";
    3.33 +    case PEP_ct_unconfirmed_encryption: return "unconfirmed_encryption";
    3.34 +    case PEP_ct_OpenPGP_weak_unconfirmed: return "OpenPGP_weak_unconfirmed";
    3.35 +    case PEP_ct_to_be_checked: return "to_be_checked";
    3.36 +    case PEP_ct_SMIME_unconfirmed: return "SMIME_unconfirmed";
    3.37 +    case PEP_ct_CMS_unconfirmed: return "CMS_unconfirmed";
    3.38 +    case PEP_ct_strong_but_unconfirmed: return "strong_but_unconfirmed";
    3.39 +    case PEP_ct_OpenPGP_unconfirmed: return "OpenPGP_unconfirmed";
    3.40 +    case PEP_ct_OTR_unconfirmed: return "OTR_unconfirmed";
    3.41 +    case PEP_ct_unconfirmed_enc_anon: return "unconfirmed_enc_anon";
    3.42 +    case PEP_ct_pEp_unconfirmed: return "pEp_unconfirmed";
    3.43 +    case PEP_ct_confirmed: return "confirmed";
    3.44 +    case PEP_ct_confirmed_encryption: return "confirmed_encryption";
    3.45 +    case PEP_ct_OpenPGP_weak: return "OpenPGP_weak";
    3.46 +    case PEP_ct_to_be_checked_confirmed: return "to_be_checked_confirmed";
    3.47 +    case PEP_ct_SMIME: return "SMIME";
    3.48 +    case PEP_ct_CMS: return "CMS";
    3.49 +    case PEP_ct_strong_encryption: return "strong_encryption";
    3.50 +    case PEP_ct_OpenPGP: return "OpenPGP";
    3.51 +    case PEP_ct_OTR: return "OTR";
    3.52 +    case PEP_ct_confirmed_enc_anon: return "confirmed_enc_anon";
    3.53 +    case PEP_ct_pEp: return "pEp";
    3.54 +    default: return "invalid comm type";
    3.55 +    }
    3.56 +}
    3.57 +
    3.58  #ifdef __cplusplus
    3.59  } // "C"
    3.60  #endif
     4.1 --- a/sync/gen_statemachine.ysl2	Mon May 27 16:58:22 2019 +0200
     4.2 +++ b/sync/gen_statemachine.ysl2	Tue May 28 12:09:20 2019 +0200
     4.3 @@ -766,6 +766,8 @@
     4.4                  free(data);
     4.5                  free(key_data);
     4.6                  free_«@name»_message(msg);
     4.7 +                if (status)
     4.8 +                    SERVICE_ERROR_LOG(session, "send_«@name»_message()", status);
     4.9                  return status;
    4.10              }
    4.11