Add convenience functions for debugging. sequoia
authorNeal H. Walfield <neal@pep.foundation>
Sat, 15 Dec 2018 16:59:05 +0100
branchsequoia
changeset 31893f8d3904ba8a
parent 3188 cbc9da42a49e
child 3190 92c7a348b84f
Add convenience functions for debugging.
src/pEpEngine.h
     1.1 --- a/src/pEpEngine.h	Tue Dec 04 19:22:50 2018 +0100
     1.2 +++ b/src/pEpEngine.h	Sat Dec 15 16:59:05 2018 +0100
     1.3 @@ -162,6 +162,100 @@
     1.4  
     1.5  typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
     1.6  
     1.7 +static inline const char *pep_status_to_string(PEP_STATUS status) {
     1.8 +    switch (status) {
     1.9 +    case PEP_STATUS_OK: return "PEP_STATUS_OK";
    1.10 +
    1.11 +    case PEP_INIT_CANNOT_LOAD_GPGME: return "PEP_INIT_CANNOT_LOAD_GPGME";
    1.12 +    case PEP_INIT_GPGME_INIT_FAILED: return "PEP_INIT_GPGME_INIT_FAILED";
    1.13 +    case PEP_INIT_NO_GPG_HOME: return "PEP_INIT_NO_GPG_HOME";
    1.14 +    case PEP_INIT_NETPGP_INIT_FAILED: return "PEP_INIT_NETPGP_INIT_FAILED";
    1.15 +    case PEP_INIT_CANNOT_DETERMINE_GPG_VERSION: return "PEP_INIT_CANNOT_DETERMINE_GPG_VERSION";
    1.16 +    case PEP_INIT_UNSUPPORTED_GPG_VERSION: return "PEP_INIT_UNSUPPORTED_GPG_VERSION";
    1.17 +    case PEP_INIT_CANNOT_CONFIG_GPG_AGENT: return "PEP_INIT_CANNOT_CONFIG_GPG_AGENT";
    1.18 +    case PEP_INIT_SQLITE3_WITHOUT_MUTEX: return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
    1.19 +    case PEP_INIT_CANNOT_OPEN_DB: return "PEP_INIT_CANNOT_OPEN_DB";
    1.20 +    case PEP_INIT_CANNOT_OPEN_SYSTEM_DB: return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
    1.21 +    case PEP_UNKNOWN_DB_ERROR: return "PEP_UNKNOWN_DB_ERROR";
    1.22 +    case PEP_KEY_NOT_FOUND: return "PEP_KEY_NOT_FOUND";
    1.23 +    case PEP_KEY_HAS_AMBIG_NAME: return "PEP_KEY_HAS_AMBIG_NAME";
    1.24 +    case PEP_GET_KEY_FAILED: return "PEP_GET_KEY_FAILED";
    1.25 +    case PEP_CANNOT_EXPORT_KEY: return "PEP_CANNOT_EXPORT_KEY";
    1.26 +    case PEP_CANNOT_EDIT_KEY: return "PEP_CANNOT_EDIT_KEY";
    1.27 +    case PEP_KEY_UNSUITABLE: return "PEP_KEY_UNSUITABLE";
    1.28 +    case PEP_MALFORMED_KEY_RESET_MSG: return "PEP_MALFORMED_KEY_RESET_MSG";
    1.29 +    case PEP_KEY_NOT_RESET: return "PEP_KEY_NOT_RESET";
    1.30 +
    1.31 +    case PEP_CANNOT_FIND_IDENTITY: return "PEP_CANNOT_FIND_IDENTITY";
    1.32 +    case PEP_CANNOT_SET_PERSON: return "PEP_CANNOT_SET_PERSON";
    1.33 +    case PEP_CANNOT_SET_PGP_KEYPAIR: return "PEP_CANNOT_SET_PGP_KEYPAIR";
    1.34 +    case PEP_CANNOT_SET_IDENTITY: return "PEP_CANNOT_SET_IDENTITY";
    1.35 +    case PEP_CANNOT_SET_TRUST: return "PEP_CANNOT_SET_TRUST";
    1.36 +    case PEP_KEY_BLACKLISTED: return "PEP_KEY_BLACKLISTED";
    1.37 +    case PEP_CANNOT_FIND_PERSON: return "PEP_CANNOT_FIND_PERSON";
    1.38 +
    1.39 +    case PEP_CANNOT_FIND_ALIAS: return "PEP_CANNOT_FIND_ALIAS";
    1.40 +    case PEP_CANNOT_SET_ALIAS: return "PEP_CANNOT_SET_ALIAS";
    1.41 +
    1.42 +    case PEP_UNENCRYPTED: return "PEP_UNENCRYPTED";
    1.43 +    case PEP_VERIFIED: return "PEP_VERIFIED";
    1.44 +    case PEP_DECRYPTED: return "PEP_DECRYPTED";
    1.45 +    case PEP_DECRYPTED_AND_VERIFIED: return "PEP_DECRYPTED_AND_VERIFIED";
    1.46 +    case PEP_DECRYPT_WRONG_FORMAT: return "PEP_DECRYPT_WRONG_FORMAT";
    1.47 +    case PEP_DECRYPT_NO_KEY: return "PEP_DECRYPT_NO_KEY";
    1.48 +    case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH: return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
    1.49 +    case PEP_VERIFY_NO_KEY: return "PEP_VERIFY_NO_KEY";
    1.50 +    case PEP_VERIFIED_AND_TRUSTED: return "PEP_VERIFIED_AND_TRUSTED";
    1.51 +    case PEP_CANNOT_REENCRYPT: return "PEP_CANNOT_REENCRYPT";
    1.52 +    case PEP_CANNOT_DECRYPT_UNKNOWN: return "PEP_CANNOT_DECRYPT_UNKNOWN";
    1.53 +
    1.54 +    case PEP_TRUSTWORD_NOT_FOUND: return "PEP_TRUSTWORD_NOT_FOUND";
    1.55 +    case PEP_TRUSTWORDS_FPR_WRONG_LENGTH: return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
    1.56 +    case PEP_TRUSTWORDS_DUPLICATE_FPR: return "PEP_TRUSTWORDS_DUPLICATE_FPR";
    1.57 +
    1.58 +    case PEP_CANNOT_CREATE_KEY: return "PEP_CANNOT_CREATE_KEY";
    1.59 +    case PEP_CANNOT_SEND_KEY: return "PEP_CANNOT_SEND_KEY";
    1.60 +
    1.61 +    case PEP_PHRASE_NOT_FOUND: return "PEP_PHRASE_NOT_FOUND";
    1.62 +
    1.63 +    case PEP_SEND_FUNCTION_NOT_REGISTERED: return "PEP_SEND_FUNCTION_NOT_REGISTERED";
    1.64 +    case PEP_CONTRAINTS_VIOLATED: return "PEP_CONTRAINTS_VIOLATED";
    1.65 +    case PEP_CANNOT_ENCODE: return "PEP_CANNOT_ENCODE";
    1.66 +
    1.67 +    case PEP_SYNC_NO_NOTIFY_CALLBACK: return "PEP_SYNC_NO_NOTIFY_CALLBACK";
    1.68 +    case PEP_SYNC_ILLEGAL_MESSAGE: return "PEP_SYNC_ILLEGAL_MESSAGE";
    1.69 +    case PEP_SYNC_NO_INJECT_CALLBACK: return "PEP_SYNC_NO_INJECT_CALLBACK";
    1.70 +    case PEP_SYNC_NO_CHANNEL: return "PEP_SYNC_NO_CHANNEL";
    1.71 +    case PEP_SYNC_CANNOT_ENCRYPT: return "PEP_SYNC_CANNOT_ENCRYPT";
    1.72 +    case PEP_SYNC_NO_MESSAGE_SEND_CALLBACK: return "PEP_SYNC_NO_MESSAGE_SEND_CALLBACK";
    1.73 +
    1.74 +    case PEP_CANNOT_INCREASE_SEQUENCE: return "PEP_CANNOT_INCREASE_SEQUENCE";
    1.75 +
    1.76 +    case PEP_STATEMACHINE_ERROR: return "PEP_STATEMACHINE_ERROR";
    1.77 +    case PEP_NO_TRUST: return "PEP_NO_TRUST";
    1.78 +    case PEP_STATEMACHINE_INVALID_STATE: return "PEP_STATEMACHINE_INVALID_STATE";
    1.79 +    case PEP_STATEMACHINE_INVALID_EVENT: return "PEP_STATEMACHINE_INVALID_EVENT";
    1.80 +    case PEP_STATEMACHINE_INVALID_CONDITION: return "PEP_STATEMACHINE_INVALID_CONDITION";
    1.81 +    case PEP_STATEMACHINE_INVALID_ACTION: return "PEP_STATEMACHINE_INVALID_ACTION";
    1.82 +    case PEP_STATEMACHINE_INHIBITED_EVENT: return "PEP_STATEMACHINE_INHIBITED_EVENT";
    1.83 +    case PEP_STATEMACHINE_CANNOT_SEND: return "PEP_STATEMACHINE_CANNOT_SEND";
    1.84 +
    1.85 +    case PEP_COMMIT_FAILED: return "PEP_COMMIT_FAILED";
    1.86 +    case PEP_MESSAGE_CONSUME: return "PEP_MESSAGE_CONSUME";
    1.87 +    case PEP_MESSAGE_IGNORE: return "PEP_MESSAGE_IGNORE";
    1.88 +
    1.89 +    case PEP_RECORD_NOT_FOUND: return "PEP_RECORD_NOT_FOUND";
    1.90 +    case PEP_CANNOT_CREATE_TEMP_FILE: return "PEP_CANNOT_CREATE_TEMP_FILE";
    1.91 +    case PEP_ILLEGAL_VALUE: return "PEP_ILLEGAL_VALUE";
    1.92 +    case PEP_BUFFER_TOO_SMALL: return "PEP_BUFFER_TOO_SMALL";
    1.93 +    case PEP_OUT_OF_MEMORY: return "PEP_OUT_OF_MEMORY";
    1.94 +    case PEP_UNKNOWN_ERROR: return "PEP_UNKNOWN_ERROR";
    1.95 +
    1.96 +    case PEP_VERSION_MISMATCH: return "PEP_VERSION_MISMATCH";
    1.97 +
    1.98 +    default: return "unknown status code";
    1.99 +    }
   1.100 +}
   1.101  
   1.102  // INIT_STATUS init() - initialize pEpEngine for a thread
   1.103  //
   1.104 @@ -535,6 +629,47 @@
   1.105      PEP_ct_pEp = 0xff
   1.106  } PEP_comm_type;
   1.107  
   1.108 +static inline const char *pep_comm_type_to_string(PEP_comm_type ct) {
   1.109 +    switch (ct) {
   1.110 +    case PEP_ct_unknown: return "unknown";
   1.111 +    case PEP_ct_no_encryption: return "no_encryption";
   1.112 +    case PEP_ct_no_encrypted_channel: return "no_encrypted_channel";
   1.113 +    case PEP_ct_key_not_found: return "key_not_found";
   1.114 +    case PEP_ct_key_expired: return "key_expired";
   1.115 +    case PEP_ct_key_revoked: return "key_revoked";
   1.116 +    case PEP_ct_key_b0rken: return "key_b0rken";
   1.117 +    case PEP_ct_my_key_not_included: return "my_key_not_included";
   1.118 +    case PEP_ct_security_by_obscurity: return "security_by_obscurity";
   1.119 +    case PEP_ct_b0rken_crypto: return "b0rken_crypto";
   1.120 +    case PEP_ct_key_too_short: return "key_too_short";
   1.121 +    case PEP_ct_compromised: return "compromised";
   1.122 +    case PEP_ct_mistrusted: return "mistrusted";
   1.123 +    case PEP_ct_unconfirmed_encryption: return "unconfirmed_encryption";
   1.124 +    case PEP_ct_OpenPGP_weak_unconfirmed: return "OpenPGP_weak_unconfirmed";
   1.125 +    case PEP_ct_to_be_checked: return "to_be_checked";
   1.126 +    case PEP_ct_SMIME_unconfirmed: return "SMIME_unconfirmed";
   1.127 +    case PEP_ct_CMS_unconfirmed: return "CMS_unconfirmed";
   1.128 +    case PEP_ct_strong_but_unconfirmed: return "strong_but_unconfirmed";
   1.129 +    case PEP_ct_OpenPGP_unconfirmed: return "OpenPGP_unconfirmed";
   1.130 +    case PEP_ct_OTR_unconfirmed: return "OTR_unconfirmed";
   1.131 +    case PEP_ct_unconfirmed_enc_anon: return "unconfirmed_enc_anon";
   1.132 +    case PEP_ct_pEp_unconfirmed: return "pEp_unconfirmed";
   1.133 +    case PEP_ct_confirmed: return "confirmed";
   1.134 +    case PEP_ct_confirmed_encryption: return "confirmed_encryption";
   1.135 +    case PEP_ct_OpenPGP_weak: return "OpenPGP_weak";
   1.136 +    case PEP_ct_to_be_checked_confirmed: return "to_be_checked_confirmed";
   1.137 +    case PEP_ct_SMIME: return "SMIME";
   1.138 +    case PEP_ct_CMS: return "CMS";
   1.139 +    case PEP_ct_strong_encryption: return "strong_encryption";
   1.140 +    case PEP_ct_OpenPGP: return "OpenPGP";
   1.141 +    case PEP_ct_OTR: return "OTR";
   1.142 +    case PEP_ct_confirmed_enc_anon: return "confirmed_enc_anon";
   1.143 +    case PEP_ct_pEp: return "pEp";
   1.144 +    default: return "invalid comm type";
   1.145 +    }
   1.146 +}
   1.147 +
   1.148 +
   1.149  typedef enum _identity_flags {
   1.150      // the first octet flags are app defined settings
   1.151      PEP_idf_not_for_sync = 0x0001,   // don't use this identity for sync