src/pEpEngine.h
author Volker Birk <vb@pep.foundation>
Tue, 04 Sep 2018 15:39:20 +0200
branchsync
changeset 2927 bab83a0e7f46
parent 2899 63b619aef131
child 2955 3b2500a15709
permissions -rw-r--r--
adding free_Sync_event() to pEpEngine.h
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #pragma once
     5 
     6 #ifdef __cplusplus
     7 extern "C" {
     8 #endif
     9 
    10 #include <stddef.h>
    11 #include <stdint.h>
    12 #include <stdbool.h>
    13 
    14 #include "dynamic_api.h"
    15 #include "stringlist.h"
    16 #include "stringpair.h"    
    17 #include "timestamp.h"
    18 
    19 #define PEP_VERSION "2.0" // protocol version
    20 
    21 #define PEP_OWN_USERID "pEp_own_userId"
    22     
    23 // pEp Engine API
    24 
    25 //  caveat:
    26 //      Unicode data has to be normalized to NFC before calling
    27 //      UTF-8 strings are UTF-8 encoded C strings (zero terminated)
    28 
    29 
    30 struct _pEpSession;
    31 typedef struct _pEpSession * PEP_SESSION;
    32 
    33 typedef enum {
    34     PEP_STATUS_OK                                   = 0,
    35 
    36     PEP_INIT_CANNOT_LOAD_GPGME                      = 0x0110,
    37     PEP_INIT_GPGME_INIT_FAILED                      = 0x0111,
    38     PEP_INIT_NO_GPG_HOME                            = 0x0112,
    39     PEP_INIT_NETPGP_INIT_FAILED                     = 0x0113,
    40     PEP_INIT_CANNOT_DETERMINE_GPG_VERSION           = 0x0114,
    41     PEP_INIT_UNSUPPORTED_GPG_VERSION                = 0x0115,
    42     PEP_INIT_CANNOT_CONFIG_GPG_AGENT                = 0x0116,
    43 
    44     PEP_INIT_SQLITE3_WITHOUT_MUTEX                  = 0x0120,
    45     PEP_INIT_CANNOT_OPEN_DB                         = 0x0121,
    46     PEP_INIT_CANNOT_OPEN_SYSTEM_DB                  = 0x0122,
    47     
    48     PEP_KEY_NOT_FOUND                               = 0x0201,
    49     PEP_KEY_HAS_AMBIG_NAME                          = 0x0202,
    50     PEP_GET_KEY_FAILED                              = 0x0203,
    51     PEP_CANNOT_EXPORT_KEY                           = 0x0204,
    52     PEP_CANNOT_EDIT_KEY                             = 0x0205,
    53     PEP_KEY_UNSUITABLE                              = 0x0206,
    54     
    55     PEP_CANNOT_FIND_IDENTITY                        = 0x0301,
    56     PEP_CANNOT_SET_PERSON                           = 0x0381,
    57     PEP_CANNOT_SET_PGP_KEYPAIR                      = 0x0382,
    58     PEP_CANNOT_SET_IDENTITY                         = 0x0383,
    59     PEP_CANNOT_SET_TRUST                            = 0x0384,
    60     PEP_KEY_BLACKLISTED                             = 0x0385,
    61     PEP_CANNOT_FIND_PERSON                          = 0x0386,
    62     
    63     PEP_CANNOT_FIND_ALIAS                           = 0x0391,
    64     PEP_CANNOT_SET_ALIAS                            = 0x0392,
    65     
    66     PEP_UNENCRYPTED                                 = 0x0400,
    67     PEP_VERIFIED                                    = 0x0401,
    68     PEP_DECRYPTED                                   = 0x0402,
    69     PEP_DECRYPTED_AND_VERIFIED                      = 0x0403,
    70     PEP_DECRYPT_WRONG_FORMAT                        = 0x0404,
    71     PEP_DECRYPT_NO_KEY                              = 0x0405,
    72     PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH            = 0x0406,
    73     PEP_VERIFY_NO_KEY                               = 0x0407,
    74     PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
    75     PEP_CANNOT_REENCRYPT                            = 0x0409,
    76     PEP_CANNOT_DECRYPT_UNKNOWN                      = 0x04ff,
    77 
    78     PEP_TRUSTWORD_NOT_FOUND                         = 0x0501,
    79     PEP_TRUSTWORDS_FPR_WRONG_LENGTH                 = 0x0502,
    80     PEP_TRUSTWORDS_DUPLICATE_FPR                    = 0x0503,
    81 
    82     PEP_CANNOT_CREATE_KEY                           = 0x0601,
    83     PEP_CANNOT_SEND_KEY                             = 0x0602,
    84 
    85     PEP_PHRASE_NOT_FOUND                            = 0x0701,
    86 
    87     PEP_SEND_FUNCTION_NOT_REGISTERED                = 0x0801,
    88     PEP_CONTRAINTS_VIOLATED                         = 0x0802,
    89     PEP_CANNOT_ENCODE                               = 0x0803,
    90 
    91     PEP_SYNC_NO_NOTIFY_CALLBACK                     = 0x0901,
    92     PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
    93     PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
    94     PEP_SYNC_NO_CHANNEL                             = 0x0904,
    95     PEP_SYNC_CANNOT_ENCRYPT                         = 0x0905,
    96 
    97     PEP_CANNOT_INCREASE_SEQUENCE                    = 0x0971,
    98 
    99     PEP_STATEMACHINE_ERROR                          = 0x0980,
   100     PEP_NO_TRUST                                    = 0x0981,
   101     PEP_STATEMACHINE_INVALID_STATE                  = 0x0982,
   102     PEP_STATEMACHINE_INVALID_EVENT                  = 0x0983,
   103     PEP_STATEMACHINE_INVALID_CONDITION              = 0x0984,
   104     PEP_STATEMACHINE_INVALID_ACTION                 = 0x0985,
   105     PEP_STATEMACHINE_INHIBITED_EVENT                = 0x0986,
   106 
   107     PEP_COMMIT_FAILED                               = 0xff01,
   108     PEP_MESSAGE_CONSUME                             = 0xff02,
   109     PEP_MESSAGE_IGNORE                              = 0xff03,
   110 
   111     PEP_RECORD_NOT_FOUND                            = -6,
   112     PEP_CANNOT_CREATE_TEMP_FILE                     = -5,
   113     PEP_ILLEGAL_VALUE                               = -4,
   114     PEP_BUFFER_TOO_SMALL                            = -3,
   115     PEP_OUT_OF_MEMORY                               = -2,
   116     PEP_UNKNOWN_ERROR                               = -1,
   117     
   118     PEP_VERSION_MISMATCH                            = -7,
   119 } PEP_STATUS;
   120 
   121 
   122 // messageToSend() - a message needs to be delivered by application
   123 //
   124 //  parameters:
   125 //      msg (in)        message struct with message to send
   126 //
   127 //  return value:
   128 //      PEP_STATUS_OK or any other value on error
   129 //
   130 //  caveat:
   131 //      the ownership of msg goes to the callee
   132 
   133 struct _message;
   134 typedef PEP_STATUS (*messageToSend_t)(struct _message *msg);
   135 
   136 
   137 struct Sync_event;
   138 typedef struct Sync_event *SYNC_EVENT;
   139 
   140 // free_Sync_event() - free memory occupied by sync protocol message
   141 //
   142 //  parameters:
   143 //      ev (in)         event to free
   144 
   145 void free_Sync_event(SYNC_EVENT ev);
   146 
   147 
   148 // inject_sync_event - inject sync protocol message
   149 //
   150 //  parameters:
   151 //      ev (in)             event to inject
   152 //      management (in)     application defined; usually a locked queue
   153 //
   154 //  return value:
   155 //      0 if event could be stored successfully or nonzero otherwise
   156 
   157 typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
   158 
   159 
   160 // INIT_STATUS init() - initialize pEpEngine for a thread
   161 //
   162 //  parameters:
   163 //      session (out)                       init() allocates session memory and
   164 //                                          returns a pointer as a handle
   165 //      messageToSend (in)                  callback for sending message by the
   166 //                                          application
   167 //      inject_sync_event (in)              callback for injecting a sync event
   168 //
   169 //  return value:
   170 //      PEP_STATUS_OK = 0                   if init() succeeds
   171 //      PEP_INIT_SQLITE3_WITHOUT_MUTEX      if SQLite3 was compiled with
   172 //                                          SQLITE_THREADSAFE 0
   173 //      PEP_INIT_CANNOT_LOAD_GPGME          if libgpgme.dll cannot be found
   174 //      PEP_INIT_GPGME_INIT_FAILED          if GPGME init fails
   175 //      PEP_INIT_CANNOT_OPEN_DB             if user's management db cannot be
   176 //                                          opened
   177 //      PEP_INIT_CANNOT_OPEN_SYSTEM_DB      if system's management db cannot be
   178 //                                          opened
   179 //
   180 //  caveat:
   181 //      THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. release()
   182 //      should be similarly guarded.
   183 //
   184 //      the pointer is valid only if the return value is PEP_STATUS_OK
   185 //      in other case a NULL pointer will be returned; a valid handle must
   186 //      be released using release() when it's no longer needed
   187 //
   188 //      the caller has to guarantee that the first call to this function
   189 //      will succeed before further calls can be done
   190 //
   191 //      messageToSend can only be null if no transport is application based
   192 //      if transport system is not used it must not be NULL
   193 
   194 DYNAMIC_API PEP_STATUS init(
   195         PEP_SESSION *session,
   196         messageToSend_t messageToSend,
   197         inject_sync_event_t inject_sync_event
   198     );
   199 
   200 
   201 // void release() - release thread session handle
   202 //
   203 //  parameters:
   204 //        session (in)    session handle to release
   205 //
   206 //    caveat:
   207 //        THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. init() should
   208 //        be similarly guarded.
   209 //       
   210 //        the last release() can be called only when all other release() calls
   211 //        are done
   212 
   213 DYNAMIC_API void release(PEP_SESSION session);
   214 
   215 
   216 // const stringlist_t* get_errorstack(PEP_SESSION) - get the error stack for that session, if any
   217 //
   218 //  parameters:
   219 //        session (in)    session handle
   220 //
   221 //    caveat:
   222 //        To get a useful error stack you have to compile with -DDEBUG_ERRORSTACK
   223 //        The error stack belongs to the session. Do no not change it!
   224 DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session);
   225 
   226 
   227 // void clear_errorstack(PEP_SESSION) - clear the error stack for that session, if any
   228 //
   229 //  parameters:
   230 //        session (in)    session handle
   231 //
   232 DYNAMIC_API void clear_errorstack(PEP_SESSION session);
   233 
   234 
   235 // config_passive_mode() - enable passive mode
   236 //
   237 //  parameters:
   238 //      session (in)    session handle
   239 //      enable (in)     flag if enabled or disabled
   240 
   241 DYNAMIC_API void config_passive_mode(PEP_SESSION session, bool enable);
   242 
   243 
   244 // config_unencrypted_subject() - disable subject encryption
   245 //
   246 //  parameters:
   247 //      session (in)    session handle
   248 //      enable (in)     flag if enabled or disabled
   249 
   250 DYNAMIC_API void config_unencrypted_subject(PEP_SESSION session, bool enable);
   251 
   252 
   253 // config_use_only_own_private_keys() - enable passive mode
   254 //
   255 //  parameters:
   256 //      session (in)    session handle
   257 //      enable (in)     flag if enabled or disabled
   258 
   259 DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session, bool enable);
   260 
   261 
   262 // config_keep_sync_msg() - do not remove sync messages (for debugging purposes)
   263 //
   264 //      session (in)    session handle
   265 //      enable (in)     flag if enabled or disabled
   266 
   267 DYNAMIC_API void config_keep_sync_msg(PEP_SESSION session, bool enable);
   268 
   269 
   270 // config_service_log() - log more for service purposes
   271 //
   272 //      session (in)    session handle
   273 //      enable (in)     flag if enabled or disabled
   274 
   275 DYNAMIC_API void config_service_log(PEP_SESSION session, bool enable);
   276 
   277 
   278 // decrypt_and_verify() - decrypt and/or verify a message
   279 //
   280 //    parameters:
   281 //        session (in)    session handle
   282 //        ctext (in)      cipher text to decrypt and/or verify
   283 //        csize (in)      size of cipher text
   284 //        dsigtext (in)   if extant, *detached* signature text for this
   285 //                        message (or NULL if not)
   286 //        dsize (in)      size of *detached* signature text for this
   287 //                        message (0, if no detached sig exists)
   288 //        ptext (out)     pointer to internal buffer with plain text
   289 //        psize (out)     size of plain text
   290 //        keylist (out)   list of key ids which where used to encrypt
   291 //
   292 //    return value:
   293 //        PEP_UNENCRYPTED               message was unencrypted and not signed
   294 //        PEP_VERIFIED                  message was unencrypted, signature matches
   295 //        PEP_DECRYPTED                 message is decrypted now, no signature
   296 //        PEP_DECRYPTED_AND_VERIFIED    message is decrypted now and verified
   297 //        PEP_DECRYPT_WRONG_FORMAT      message has wrong format to handle
   298 //        PEP_DECRYPT_NO_KEY            key not available to decrypt and/or verify
   299 //        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
   300 //
   301 //    caveat:
   302 //        the ownerships of ptext as well as keylist are going to the caller
   303 //        the caller must use free() (or an Windoze pEp_free()) and
   304 //        free_stringlist() to free them
   305 //
   306 //      if this function failes an error message may be the first element of
   307 //      keylist and the other elements may be the keys used for encryption
   308 
   309 DYNAMIC_API PEP_STATUS decrypt_and_verify(
   310         PEP_SESSION session, const char *ctext, size_t csize,
   311         const char *dsigtext, size_t dsigsize,
   312         char **ptext, size_t *psize, stringlist_t **keylist
   313     );
   314 
   315 
   316 // verify_text() - verfy plain text with a digital signature
   317 //
   318 //  parameters:
   319 //      session (in)    session handle
   320 //      text (in)       text to verify
   321 //      size (in)       size of text
   322 //      signature (in)  signature text
   323 //      sig_size (in)   size of signature
   324 //      keylist (out)   list of key ids which where used to encrypt or NULL on
   325 //                        error
   326 //
   327 //  return value:
   328 //        PEP_VERIFIED                message was unencrypted, signature matches
   329 //        PEP_DECRYPT_NO_KEY          key not available to decrypt and/or verify
   330 //        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
   331 
   332 DYNAMIC_API PEP_STATUS verify_text(
   333         PEP_SESSION session, const char *text, size_t size,
   334         const char *signature, size_t sig_size, stringlist_t **keylist
   335     );
   336 
   337 
   338 // encrypt_and_sign() - encrypt and sign a message
   339 //
   340 //    parameters:
   341 //        session (in)    session handle
   342 //        keylist (in)    list of key ids to encrypt with as C strings
   343 //        ptext (in)      plain text to decrypt and/or verify
   344 //        psize (in)      size of plain text
   345 //        ctext (out)     pointer to internal buffer with cipher text
   346 //        csize (out)     size of cipher text
   347 //
   348 //    return value:
   349 //        PEP_STATUS_OK = 0            encryption and signing succeeded
   350 //        PEP_KEY_NOT_FOUND            at least one of the recipient keys
   351 //                                     could not be found
   352 //        PEP_KEY_HAS_AMBIG_NAME       at least one of the recipient keys has
   353 //                                     an ambiguous name
   354 //        PEP_GET_KEY_FAILED           cannot retrieve key
   355 //
   356 //    caveat:
   357 //      the ownership of ctext is going to the caller
   358 //      the caller is responsible to free() it (on Windoze use pEp_free())
   359 //      the first key in keylist is being used to sign the message
   360 //      this implies there has to be a private key for that keypair
   361 
   362 DYNAMIC_API PEP_STATUS encrypt_and_sign(
   363         PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
   364         size_t psize, char **ctext, size_t *csize
   365     );
   366 
   367 
   368 // log_event() - log a user defined event defined by UTF-8 encoded strings into
   369 // management log
   370 //
   371 //    parameters:
   372 //        session (in)        session handle
   373 //        title (in)          C string with event name
   374 //        entity (in)         C string with name of entity which is logging
   375 //        description (in)    C string with long description for event or NULL if
   376 //                            omitted
   377 //        comment (in)        C string with user defined comment or NULL if
   378 //                            omitted
   379 //
   380 //    return value:
   381 //        PEP_STATUS_OK       log entry created
   382 
   383 DYNAMIC_API PEP_STATUS log_event(
   384         PEP_SESSION session,
   385         const char *title,
   386         const char *entity,
   387         const char *description,
   388         const char *comment
   389     );
   390 
   391 
   392 DYNAMIC_API PEP_STATUS log_service(PEP_SESSION session, const char *title,
   393         const char *entity, const char *description, const char *comment);
   394 
   395 #define _STR_(x) #x
   396 #define _D_STR_(x) _STR_(x)
   397 #define S_LINE _D_STR_(__LINE__)
   398 
   399 #define SERVICE_LOG(session, title, entity, desc) \
   400     log_service((session), (title), (entity), (desc), "service " __FILE__ ":" S_LINE)
   401 
   402 
   403 // trustword() - get the corresponding trustword for a 16 bit value
   404 //
   405 //    parameters:
   406 //        session (in)            session handle
   407 //        value (in)              value to find a trustword for
   408 //        lang (in)               C string with ISO 639-1 language code
   409 //        word (out)              pointer to C string with trustword UTF-8 encoded
   410 //                                NULL if language is not supported or trustword
   411 //                                wordlist is damaged or unavailable
   412 //        wsize (out)             length of trustword
   413 //
   414 //    return value:
   415 //        PEP_STATUS_OK            trustword retrieved
   416 //        PEP_TRUSTWORD_NOT_FOUND  trustword not found
   417 //
   418 //    caveat:
   419 //        the word pointer goes to the ownership of the caller
   420 //      the caller is responsible to free() it (on Windoze use pEp_free())
   421 
   422 DYNAMIC_API PEP_STATUS trustword(
   423             PEP_SESSION session, uint16_t value, const char *lang,
   424             char **word, size_t *wsize
   425         );
   426 
   427 
   428 // trustwords() - get trustwords for a string of hex values of a fingerprint
   429 //
   430 //    parameters:
   431 //        session (in)        session handle
   432 //        fingerprint (in)    C string with hex values to find trustwords for
   433 //        lang (in)           C string with ISO 639-1 language code
   434 //        words (out)         pointer to C string with trustwords UTF-8 encoded,
   435 //                            separated by a blank each
   436 //                            NULL if language is not supported or trustword
   437 //                            wordlist is damaged or unavailable
   438 //        wsize (out)         length of trustwords string
   439 //        max_words (in)      only generate a string with max_words;
   440 //                            if max_words == 0 there is no such limit
   441 //
   442 //    return value:
   443 //        PEP_STATUS_OK            trustwords retrieved
   444 //        PEP_OUT_OF_MEMORY        out of memory
   445 //        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
   446 //
   447 //    caveat:
   448 //        the word pointer goes to the ownership of the caller
   449 //      the caller is responsible to free() it (on Windoze use pEp_free())
   450 //
   451 //  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
   452 //
   453 //  Better implement a simple one in the adapter yourself using trustword(), and
   454 //  return a list of trustwords.
   455 //  This function is provided for being used by C and C++ programs only.
   456 
   457 DYNAMIC_API PEP_STATUS trustwords(
   458         PEP_SESSION session, const char *fingerprint, const char *lang,
   459         char **words, size_t *wsize, int max_words
   460     );
   461 
   462 
   463 // TODO: increase versions in pEp.asn1 if rating changes
   464 
   465 typedef enum _PEP_comm_type {
   466     PEP_ct_unknown = 0,
   467 
   468     // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
   469 
   470     PEP_ct_no_encryption = 0x01,                // generic
   471     PEP_ct_no_encrypted_channel = 0x02,
   472     PEP_ct_key_not_found = 0x03,
   473     PEP_ct_key_expired = 0x04,
   474     PEP_ct_key_revoked = 0x05,
   475     PEP_ct_key_b0rken = 0x06,
   476     PEP_ct_my_key_not_included = 0x09,
   477 
   478     PEP_ct_security_by_obscurity = 0x0a,
   479     PEP_ct_b0rken_crypto = 0x0b,
   480     PEP_ct_key_too_short = 0x0c,
   481 
   482     PEP_ct_compromised = 0x0e,                  // known compromised connection
   483     PEP_ct_compromized = 0x0e,                  // deprecated misspelling
   484     PEP_ct_mistrusted = 0x0f,                   // known mistrusted key
   485 
   486     // range 0x10 to 0x3f: unconfirmed encryption
   487 
   488     PEP_ct_unconfirmed_encryption = 0x10,       // generic
   489     PEP_ct_OpenPGP_weak_unconfirmed = 0x11,     // RSA 1024 is weak
   490 
   491     PEP_ct_to_be_checked = 0x20,                // generic
   492     PEP_ct_SMIME_unconfirmed = 0x21,
   493     PEP_ct_CMS_unconfirmed = 0x22,
   494 
   495     PEP_ct_strong_but_unconfirmed = 0x30,       // generic
   496     PEP_ct_OpenPGP_unconfirmed = 0x38,          // key at least 2048 bit RSA or EC
   497     PEP_ct_OTR_unconfirmed = 0x3a,
   498 
   499     // range 0x40 to 0x7f: unconfirmed encryption and anonymization
   500 
   501     PEP_ct_unconfirmed_enc_anon = 0x40,         // generic
   502     PEP_ct_pEp_unconfirmed = 0x7f,
   503 
   504     PEP_ct_confirmed = 0x80,                    // this bit decides if trust is confirmed
   505 
   506     // range 0x81 to 0x8f: reserved
   507     // range 0x90 to 0xbf: confirmed encryption
   508 
   509     PEP_ct_confirmed_encryption = 0x90,         // generic
   510     PEP_ct_OpenPGP_weak = 0x91,                 // RSA 1024 is weak (unused)
   511 
   512     PEP_ct_to_be_checked_confirmed = 0xa0,      // generic
   513     PEP_ct_SMIME = 0xa1,
   514     PEP_ct_CMS = 0xa2,
   515 
   516     PEP_ct_strong_encryption = 0xb0,            // generic
   517     PEP_ct_OpenPGP = 0xb8,                      // key at least 2048 bit RSA or EC
   518     PEP_ct_OTR = 0xba,
   519 
   520     // range 0xc0 to 0xff: confirmed encryption and anonymization
   521 
   522     PEP_ct_confirmed_enc_anon = 0xc0,           // generic
   523     PEP_ct_pEp = 0xff
   524 } PEP_comm_type;
   525 
   526 typedef enum _identity_flags {
   527     // the first octet flags are app defined settings
   528     PEP_idf_not_for_sync = 0x0001,   // don't use this identity for sync
   529     PEP_idf_list = 0x0002,           // identity of list of persons
   530     // the second octet flags are calculated
   531     PEP_idf_devicegroup = 0x0100     // identity of a device group member
   532 } identity_flags;
   533 
   534 typedef unsigned int identity_flags_t;
   535 
   536 // typedef enum _keypair_flags {
   537 // } keypair_flags;
   538 
   539 typedef unsigned int keypair_flags_t;
   540 
   541 typedef struct _pEp_identity {
   542     char *address;              // C string with address UTF-8 encoded
   543     char *fpr;                  // C string with fingerprint UTF-8 encoded
   544     char *user_id;              // C string with user ID UTF-8 encoded
   545                                 // user_id MIGHT be set to "pEp_own_userId"
   546                                 // (use PEP_OWN_USERID preprocessor define)
   547                                 // if this is own user's identity.
   548                                 // But it is not REQUIRED to be.
   549     char *username;             // C string with user name UTF-8 encoded
   550     PEP_comm_type comm_type;    // type of communication with this ID
   551     char lang[3];               // language of conversation
   552                                 // ISO 639-1 ALPHA-2, last byte is 0
   553     bool me;                    // if this is the local user herself/himself
   554     identity_flags_t flags;     // identity_flag1 | identity_flag2 | ...
   555 } pEp_identity;
   556 
   557 typedef struct _identity_list {
   558     pEp_identity *ident;
   559     struct _identity_list *next;
   560 } identity_list;
   561 
   562 
   563 // new_identity() - allocate memory and set the string and size fields
   564 //
   565 //  parameters:
   566 //      address (in)        UTF-8 string or NULL 
   567 //      fpr (in)            UTF-8 string or NULL 
   568 //      user_id (in)        UTF-8 string or NULL 
   569 //      username (in)       UTF-8 string or NULL 
   570 //
   571 //  return value:
   572 //      pEp_identity struct or NULL if out of memory
   573 //
   574 //  caveat:
   575 //      the strings are copied; the original strings are still being owned by
   576 //      the caller
   577 
   578 DYNAMIC_API pEp_identity *new_identity(
   579         const char *address, const char *fpr, const char *user_id,
   580         const char *username
   581     );
   582 
   583 
   584 // identity_dup() - allocate memory and duplicate
   585 //
   586 //  parameters:
   587 //      src (in)            identity to duplicate
   588 //
   589 //  return value:
   590 //      pEp_identity struct or NULL if out of memory
   591 //
   592 //  caveat:
   593 //      the strings are copied; the original strings are still being owned by
   594 //      the caller
   595 
   596 DYNAMIC_API pEp_identity *identity_dup(const pEp_identity *src);
   597 
   598 
   599 // free_identity() - free all memory being occupied by a pEp_identity struct
   600 //
   601 //  parameters:
   602 //      identity (in)       struct to release
   603 //
   604 //  caveat:
   605 //      not only the struct but also all string memory referenced by the
   606 //      struct is being freed; all pointers inside are invalid afterwards
   607 
   608 DYNAMIC_API void free_identity(pEp_identity *identity);
   609 
   610 
   611 // get_identity() - get identity information
   612 //
   613 //    parameters:
   614 //        session (in)        session handle
   615 //        address (in)        C string with communication address, UTF-8 encoded
   616 //        user_id (in)        unique C string to identify person that identity
   617 //                            is refering to
   618 //        identity (out)      pointer to pEp_identity structure with results or
   619 //                            NULL if failure
   620 //
   621 //    caveat:
   622 //        address and user_id are being copied; the original strings remains in
   623 //        the ownership of the caller
   624 //        the resulting pEp_identity structure goes to the ownership of the
   625 //        caller and has to be freed with free_identity() when not in use any
   626 //        more
   627 
   628 DYNAMIC_API PEP_STATUS get_identity(
   629         PEP_SESSION session,
   630         const char *address,
   631         const char *user_id,
   632         pEp_identity **identity
   633     );
   634 
   635 PEP_STATUS replace_identities_fpr(PEP_SESSION session, 
   636                                  const char* old_fpr, 
   637                                  const char* new_fpr); 
   638 
   639 
   640 // set_identity() - set identity information
   641 //
   642 //    parameters:
   643 //        session (in)        session handle
   644 //        identity (in)       pointer to pEp_identity structure
   645 //
   646 //    return value:
   647 //        PEP_STATUS_OK = 0             encryption and signing succeeded
   648 //        PEP_CANNOT_SET_PERSON         writing to table person failed
   649 //        PEP_CANNOT_SET_PGP_KEYPAIR    writing to table pgp_keypair failed
   650 //        PEP_CANNOT_SET_IDENTITY       writing to table identity failed
   651 //        PEP_COMMIT_FAILED             SQL commit failed
   652 //
   653 //    caveat:
   654 //        address, fpr, user_id and username must be given
   655 
   656 DYNAMIC_API PEP_STATUS set_identity(
   657         PEP_SESSION session, const pEp_identity *identity
   658     );
   659 
   660 // get_default own_userid() - get the user_id of the own user
   661 //
   662 //    parameters:
   663 //        session (in)        session handle
   664 //        userid  (out)       own user id (if it exists)
   665 //
   666 //    return value:
   667 //        PEP_STATUS_OK = 0             userid was found
   668 //        PEP_CANNOT_FIND_IDENTITY      no own_user found in the DB
   669 //        PEP_UNKNOWN_ERROR             results were returned, but no ID
   670 //                                      found (no reason this should ever occur)
   671 //    caveat:
   672 //        userid will be NULL if not found; otherwise, returned string
   673 //        belongs to the caller.
   674 
   675 DYNAMIC_API PEP_STATUS get_default_own_userid(
   676         PEP_SESSION session, 
   677         char** userid
   678     );
   679 
   680 // get_userid_alias_default() - get the default user_id which corresponds
   681 //                              to an alias
   682 //    parameters:
   683 //        session (in)        session handle
   684 //        alias_id (in)       the user_id which may be an alias for a default id
   685 //        default_id (out)    the default id for this alias, if the alias
   686 //                            is in the DB as an alias, else NULL
   687 //    return value:
   688 //        PEP_STATUS_OK = 0             userid was found
   689 //        PEP_CANNOT_FIND_ALIAS         this userid is not listed as an 
   690 //                                      alias in the DB
   691 //        PEP_UNKNOWN_ERROR             results were returned, but no ID
   692 //                                      found (no reason this should ever occur)
   693 //    caveat:
   694 //        default_id will be NULL if not found; otherwise, returned string
   695 //        belongs to the caller.
   696 //        also, current implementation does NOT check to see if this userid
   697 //        IS a default.
   698 
   699 DYNAMIC_API PEP_STATUS get_userid_alias_default(
   700         PEP_SESSION session, 
   701         const char* alias_id,
   702         char** default_id);
   703 
   704 // set_userid_alias() - set an alias to correspond to a default id
   705 //    parameters:
   706 //        session (in)        session handle
   707 //        default_id (in)     the default id for this alias. This must
   708 //                            correspond to the default user_id for an
   709 //                            entry in the person (user) table.
   710 //        alias_id (in)       the alias to be set for this default id
   711 //    return value:
   712 //        PEP_STATUS_OK = 0             userid was found
   713 //        PEP_CANNOT_SET_ALIAS          there was an error setting this
   714 
   715 DYNAMIC_API PEP_STATUS set_userid_alias (
   716         PEP_SESSION session, 
   717         const char* default_id,
   718         const char* alias_id);
   719 
   720 
   721 // set_device_group() - update own person's device group
   722 //
   723 //    parameters:
   724 //        session (in)        session handle
   725 //        group_name (in)     new group name
   726 //
   727 //    return value:
   728 //        PEP_STATUS_OK = 0             device group was updated
   729 //        PEP_CANNOT_SET_PERSON         update failed
   730 
   731 DYNAMIC_API PEP_STATUS set_device_group(
   732         PEP_SESSION session,
   733         const char *group_name
   734     );
   735 
   736 // get_device_group() - get own person's device group
   737 //
   738 //    parameters:
   739 //        session (in)        session handle
   740 //        group_name (in)     new group name
   741 //
   742 //    return value:
   743 //        PEP_STATUS_OK = 0             couldn't get device group
   744 //        PEP_RECORD_NOT_FOUND          update failed
   745 //
   746 //    caveat:
   747 //        the ownerships of group_name is going to the caller
   748 
   749 DYNAMIC_API PEP_STATUS get_device_group(
   750         PEP_SESSION session, 
   751         char **group_name
   752     );
   753 
   754 // set_identity_flags() - update identity flags on existing identity
   755 //
   756 //    parameters:
   757 //        session (in)        session handle
   758 //        identity (in,out)   pointer to pEp_identity structure
   759 //        flags (in)          new value for flags
   760 //
   761 //    return value:
   762 //        PEP_STATUS_OK = 0             encryption and signing succeeded
   763 //        PEP_CANNOT_SET_IDENTITY       update of identity failed
   764 //
   765 //    caveat:
   766 //        address and user_id must be given in identity
   767 
   768 DYNAMIC_API PEP_STATUS set_identity_flags(
   769         PEP_SESSION session,
   770         pEp_identity *identity,
   771         identity_flags_t flags
   772     );
   773 
   774 // unset_identity_flags() - update identity flags on existing identity
   775 //
   776 //    parameters:
   777 //        session (in)        session handle
   778 //        identity (in,out)   pointer to pEp_identity structure
   779 //        flags (in)          new value for flags
   780 //
   781 //    return value:
   782 //        PEP_STATUS_OK = 0             encryption and signing succeeded
   783 //        PEP_CANNOT_SET_IDENTITY       update of identity failed
   784 //
   785 //    caveat:
   786 //        address and user_id must be given in identity
   787 
   788 DYNAMIC_API PEP_STATUS unset_identity_flags(
   789         PEP_SESSION session,
   790         pEp_identity *identity,
   791         identity_flags_t flags
   792     );
   793 
   794 // mark_as_compromised() - mark key in trust db as compromised
   795 //
   796 //    parameters:
   797 //        session (in)        session handle
   798 //        fpr (in)            fingerprint of key to mark
   799 
   800 DYNAMIC_API PEP_STATUS mark_as_compromised(
   801         PEP_SESSION session,
   802         const char *fpr
   803     );
   804 
   805 
   806 // mark_as_compromized() - deprecated to fix misspelling. Please move to
   807 //                         mark_as_compromised();
   808 
   809 DYNAMIC_API PEP_STATUS mark_as_compromized(
   810         PEP_SESSION session,
   811         const char *fpr
   812     );
   813 
   814 
   815 // generate_keypair() - generate a new key pair and add it to the key ring
   816 //
   817 //  parameters:
   818 //      session (in)            session handle
   819 //        identity (inout)      pointer to pEp_identity structure
   820 //
   821 //    return value:
   822 //        PEP_STATUS_OK = 0       encryption and signing succeeded
   823 //        PEP_ILLEGAL_VALUE       illegal values for identity fields given
   824 //        PEP_CANNOT_CREATE_KEY   key engine is on strike
   825 //
   826 //  caveat:
   827 //      address and username fields must be set to UTF-8 strings
   828 //      the fpr field must be set to NULL
   829 //
   830 //      this function allocates a string and sets set fpr field of identity
   831 //      the caller is responsible to call free() for that string or use
   832 //      free_identity() on the struct
   833 
   834 DYNAMIC_API PEP_STATUS generate_keypair(
   835         PEP_SESSION session, pEp_identity *identity
   836     );
   837 
   838 
   839 // delete_keypair() - delete a public key or a key pair from the key ring
   840 //
   841 //  parameters:
   842 //      session (in)            session handle
   843 //      fpr (in)                C string with key id or fingerprint of the
   844 //                              public key
   845 //
   846 //  return value:
   847 //      PEP_STATUS_OK = 0       key was successfully deleted
   848 //      PEP_KEY_NOT_FOUND       key not found
   849 //      PEP_ILLEGAL_VALUE       not a valid key id or fingerprint
   850 //      PEP_KEY_HAS_AMBIG_NAME  fpr does not uniquely identify a key
   851 //      PEP_OUT_OF_MEMORY       out of memory
   852 
   853 DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
   854 
   855 
   856 // import_key() - import key from data
   857 //
   858 //  parameters:
   859 //      session (in)            session handle
   860 //      key_data (in)           key data, i.e. ASCII armored OpenPGP key
   861 //      size (in)               amount of data to handle
   862 //      private_keys (out)      list of private keys that have been imported
   863 //
   864 //  return value:
   865 //      PEP_STATUS_OK = 0       key was successfully imported
   866 //      PEP_OUT_OF_MEMORY       out of memory
   867 //      PEP_ILLEGAL_VALUE       there is no key data to import
   868 //
   869 //  caveat:
   870 //      private_keys goes to the ownership of the caller
   871 //      private_keys can be left NULL, it is then ignored
   872 
   873 DYNAMIC_API PEP_STATUS import_key(
   874         PEP_SESSION session,
   875         const char *key_data,
   876         size_t size,
   877         identity_list **private_keys
   878     );
   879 
   880 
   881 // export_key() - export ascii armored key
   882 //
   883 //  parameters:
   884 //      session (in)            session handle
   885 //      fpr (in)                key id or fingerprint of key
   886 //      key_data (out)          ASCII armored OpenPGP key
   887 //      size (out)              amount of data to handle
   888 //
   889 //  return value:
   890 //      PEP_STATUS_OK = 0       key was successfully exported
   891 //      PEP_OUT_OF_MEMORY       out of memory
   892 //      PEP_KEY_NOT_FOUND       key not found
   893 //
   894 //  caveat:
   895 //      the key_data goes to the ownership of the caller
   896 //      the caller is responsible to free() it (on Windoze use pEp_free())
   897 
   898 DYNAMIC_API PEP_STATUS export_key(
   899         PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   900     );
   901 
   902 
   903 // export_secret_key() - export secret key ascii armored
   904 //
   905 //  parameters:
   906 //      session (in)            session handle
   907 //      fpr (in)                fingerprint of key, at least 16 hex digits
   908 //      key_data (out)          ASCII armored OpenPGP secret key
   909 //      size (out)              amount of data to handle
   910 //
   911 //  return value:
   912 //      PEP_STATUS_OK = 0       key was successfully exported
   913 //      PEP_OUT_OF_MEMORY       out of memory
   914 //      PEP_KEY_NOT_FOUND       key not found
   915 //      PEP_CANNOT_EXPORT_KEY   cannot export secret key (i.e. it's on an HKS)
   916 //
   917 //  caveat:
   918 //      the key_data goes to the ownership of the caller
   919 //      the caller is responsible to free() it (on Windoze use pEp_free())
   920 //      beware of leaking secret key data - overwrite it in memory after use
   921 
   922 DYNAMIC_API PEP_STATUS export_secret_key(
   923         PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   924     );
   925 
   926 
   927 // export_secrect_key() - deprecated misspelled function. Please replace with
   928 //                        export_secret_key
   929 
   930 DYNAMIC_API PEP_STATUS export_secrect_key(
   931         PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   932     );
   933 
   934 
   935 // recv_key() - update key(s) from keyserver
   936 //
   937 //  parameters:
   938 //      session (in)            session handle
   939 //      pattern (in)            key id, user id or address to search for as
   940 //                              UTF-8 string
   941 
   942 DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
   943 
   944 
   945 // find_keys() - find keys in keyring
   946 //
   947 //  parameters:
   948 //      session (in)            session handle
   949 //      pattern (in)            key id, user id or address to search for as
   950 //                              UTF-8 string
   951 //      keylist (out)           list of fingerprints found or NULL on error
   952 //
   953 //  caveat:
   954 //        the ownerships of keylist isgoing to the caller
   955 //        the caller must use free_stringlist() to free it
   956 
   957 
   958 DYNAMIC_API PEP_STATUS find_keys(
   959         PEP_SESSION session, const char *pattern, stringlist_t **keylist
   960     );
   961 
   962 // send_key() - send key(s) to keyserver
   963 //
   964 //  parameters:
   965 //      session (in)            session handle
   966 //      pattern (in)            key id, user id or address to search for as
   967 //                              UTF-8 string
   968 
   969 DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
   970 
   971 
   972 // pEp_free() - free memory allocated by pEp engine
   973 //
   974 //  parameters:
   975 //      p (in)                  pointer to free
   976 //
   977 //  The reason for this function is that heap management can be a pretty
   978 //  complex task with Windoze. This free() version calls the free()
   979 //  implementation of the C runtime library which was used to build pEp engine,
   980 //  so you're using the correct heap. For more information, see:
   981 //  <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
   982 
   983 DYNAMIC_API void pEp_free(void *p);
   984 
   985 
   986 // get_trust() - get the trust level a key has for a person
   987 //
   988 //  parameters:
   989 //      session (in)            session handle
   990 //      identity (inout)        user_id and fpr to check as UTF-8 strings (in)
   991 //                              comm_type as result (out)
   992 //
   993 //  this function modifies the given identity struct; the struct remains in
   994 //  the ownership of the caller
   995 //  if the trust level cannot be determined identity->comm_type is set
   996 //  to PEP_ct_unknown
   997 
   998 DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
   999 
  1000 
  1001 PEP_STATUS set_trust(PEP_SESSION session, 
  1002                      pEp_identity* identity);
  1003                             
  1004 PEP_STATUS update_trust_for_fpr(PEP_SESSION session, 
  1005                                 const char* fpr, 
  1006                                 PEP_comm_type comm_type);
  1007 
  1008 // least_trust() - get the least known trust level for a key in the database
  1009 //
  1010 //  parameters:
  1011 //      session (in)            session handle
  1012 //      fpr (in)                fingerprint of key to check
  1013 //      comm_type (out)         least comm_type as result (out)
  1014 //
  1015 //  if the trust level cannot be determined comm_type is set to PEP_ct_unknown
  1016 
  1017 DYNAMIC_API PEP_STATUS least_trust(
  1018         PEP_SESSION session,
  1019         const char *fpr,
  1020         PEP_comm_type *comm_type
  1021     );
  1022 
  1023 
  1024 // get_key_rating() - get the rating a bare key has
  1025 //
  1026 //  parameters:
  1027 //      session (in)            session handle
  1028 //      fpr (in)                unique identifyer for key as UTF-8 string
  1029 //      comm_type (out)         key rating
  1030 //
  1031 //  if an error occurs, *comm_type is set to PEP_ct_unknown and an error
  1032 //  is returned
  1033 
  1034 DYNAMIC_API PEP_STATUS get_key_rating(
  1035         PEP_SESSION session,
  1036         const char *fpr,
  1037         PEP_comm_type *comm_type
  1038     );
  1039 
  1040 
  1041 // renew_key() - renew an expired key
  1042 //
  1043 //  parameters:
  1044 //      session (in)            session handle
  1045 //      fpr (in)                ID of key to renew as UTF-8 string
  1046 //      ts (in)                 timestamp when key should expire or NULL for
  1047 //                              default
  1048 
  1049 DYNAMIC_API PEP_STATUS renew_key(
  1050         PEP_SESSION session,
  1051         const char *fpr,
  1052         const timestamp *ts
  1053     );
  1054 
  1055 
  1056 // revoke_key() - revoke a key
  1057 //
  1058 //  parameters:
  1059 //      session (in)            session handle
  1060 //      fpr (in)                ID of key to revoke as UTF-8 string
  1061 //      reason (in)             text with reason for revoke as UTF-8 string
  1062 //                              or NULL if reason unknown
  1063 //
  1064 //  caveat:
  1065 //      reason text must not include empty lines
  1066 //      this function is meant for internal use only; better use
  1067 //      key_mistrusted() of keymanagement API
  1068 
  1069 DYNAMIC_API PEP_STATUS revoke_key(
  1070         PEP_SESSION session,
  1071         const char *fpr,
  1072         const char *reason
  1073     );
  1074 
  1075 
  1076 // key_expired() - flags if a key is already expired
  1077 //
  1078 //  parameters:
  1079 //      session (in)            session handle
  1080 //      fpr (in)                ID of key to check as UTF-8 string
  1081 //      when (in)               UTC time of when should expiry be considered
  1082 //      expired (out)           flag if key expired
  1083 
  1084 DYNAMIC_API PEP_STATUS key_expired(
  1085         PEP_SESSION session,
  1086         const char *fpr,
  1087         const time_t when,
  1088         bool *expired
  1089     );
  1090 
  1091     
  1092 // key_revoked() - flags if a key is already revoked
  1093 //
  1094 //  parameters:
  1095 //      session (in)            session handle
  1096 //      fpr (in)                ID of key to check as UTF-8 string
  1097 //      revoked (out)           flag if key revoked
  1098 
  1099 DYNAMIC_API PEP_STATUS key_revoked(
  1100         PEP_SESSION session,
  1101         const char *fpr,
  1102         bool *revoked
  1103     );
  1104 
  1105 PEP_STATUS get_key_userids(
  1106         PEP_SESSION session,
  1107         const char* fpr,
  1108         stringlist_t** keylist
  1109     );
  1110 
  1111 
  1112 // get_crashdump_log() - get the last log messages out
  1113 //
  1114 //  parameters:
  1115 //      session (in)            session handle
  1116 //      maxlines (in)           maximum number of lines (0 for default)
  1117 //      logdata (out)           logdata as string in double quoted CSV format
  1118 //                              column1 is title
  1119 //                              column2 is entity
  1120 //                              column3 is description
  1121 //                              column4 is comment
  1122 //
  1123 //  caveat:
  1124 //      the ownership of logdata goes to the caller
  1125 
  1126 DYNAMIC_API PEP_STATUS get_crashdump_log(
  1127         PEP_SESSION session,
  1128         int maxlines,
  1129         char **logdata
  1130     );
  1131 
  1132 
  1133 // get_languagelist() - get the list of languages
  1134 //
  1135 //  parameters:
  1136 //      session (in)            session handle
  1137 //      languages (out)         languages as string in double quoted CSV format
  1138 //                              column 1 is the ISO 639-1 language code
  1139 //                              column 2 is the name of the language
  1140 //
  1141 //  caveat:
  1142 //      the ownership of languages goes to the caller
  1143 
  1144 DYNAMIC_API PEP_STATUS get_languagelist(
  1145         PEP_SESSION session,
  1146         char **languages
  1147     );
  1148 
  1149 
  1150 // get_phrase() - get phrase in a dedicated language through i18n
  1151 //
  1152 //  parameters:
  1153 //      session (in)            session handle
  1154 //      lang (in)               C string with ISO 639-1 language code
  1155 //      phrase_id (in)          id of phrase in i18n
  1156 //      phrase (out)            phrase as UTF-8 string
  1157 //
  1158 //  caveat:
  1159 //      the ownership of phrase goes to the caller
  1160 
  1161 DYNAMIC_API PEP_STATUS get_phrase(
  1162         PEP_SESSION session,
  1163         const char *lang,
  1164         int phrase_id,
  1165         char **phrase
  1166     );
  1167 
  1168 
  1169 // sequence_value() - raise the value of a named sequence and retrieve it
  1170 //
  1171 //  parameters:
  1172 //      session (in)            session handle
  1173 //      name (in)               name of sequence
  1174 //      value (out)             value of sequence
  1175 //
  1176 //  returns:
  1177 //      PEP_STATUS_OK                   no error, not own sequence
  1178 //      PEP_SEQUENCE_VIOLATED           if sequence violated
  1179 //      PEP_CANNOT_INCREASE_SEQUENCE    if sequence cannot be increased
  1180 //      PEP_OWN_SEQUENCE                if own sequence
  1181 
  1182 DYNAMIC_API PEP_STATUS sequence_value(
  1183         PEP_SESSION session,
  1184         const char *name,
  1185         int32_t *value
  1186     );
  1187 
  1188 
  1189 // set_revoked() - records relation between a revoked key and its replacement
  1190 //
  1191 //  parameters:
  1192 //      session (in)            session handle
  1193 //      revoked_fpr (in)        revoked fingerprint
  1194 //      replacement_fpr (in)    replacement key fingerprint
  1195 //      revocation_date (in)    revocation date
  1196 
  1197 DYNAMIC_API PEP_STATUS set_revoked(
  1198        PEP_SESSION session,
  1199        const char *revoked_fpr,
  1200        const char *replacement_fpr,
  1201        const uint64_t revocation_date
  1202     );
  1203 
  1204 
  1205 // get_revoked() - find revoked key that may have been replaced by given key, if any
  1206 //
  1207 //  parameters:
  1208 //      session (in)            session handle
  1209 //      fpr (in)                given fingerprint
  1210 //      revoked_fpr (out)       revoked fingerprint
  1211 //      revocation_date (out)   revocation date
  1212     
  1213 DYNAMIC_API PEP_STATUS get_revoked(
  1214         PEP_SESSION session,
  1215         const char *fpr,
  1216         char **revoked_fpr,
  1217         uint64_t *revocation_date
  1218     );
  1219 
  1220 
  1221 // key_created() - get creation date of a key
  1222 //
  1223 //  parameters:
  1224 //      session (in)            session handle
  1225 //      fpr (in)                fingerprint of key
  1226 //      created (out)           date of creation
  1227 
  1228 PEP_STATUS key_created(
  1229         PEP_SESSION session,
  1230         const char *fpr,
  1231         time_t *created
  1232     );
  1233 
  1234 
  1235 // find_private_keys() - find keys in keyring
  1236 //
  1237 //  parameters:
  1238 //      session (in)            session handle
  1239 //      pattern (in)            key id, user id or address to search for as
  1240 //                              UTF-8 string
  1241 //      keylist (out)           list of fingerprints found or NULL on error
  1242 //
  1243 //  caveat:
  1244 //        the ownerships of keylist isgoing to the caller
  1245 //        the caller must use free_stringlist() to free it
  1246 PEP_STATUS find_private_keys(PEP_SESSION session, const char* pattern,
  1247                              stringlist_t **keylist);
  1248 
  1249 // get_engine_version() - returns the current version of pEpEngine (this is different
  1250 //                        from the pEp protocol version!)
  1251 //
  1252 //  parameters: none
  1253 //
  1254 //  return_value: const char* to the engine version string constant
  1255 //
  1256 DYNAMIC_API const char* get_engine_version();
  1257 
  1258 // is_pEp_user() - returns true if the USER corresponding to this identity 
  1259 //                 has been listed in the *person* table as a pEp user. 
  1260 //
  1261 //  parameters:
  1262 //      identity (in) - identity containing the user_id to check (this is
  1263 //                      the only part of the struct we require to be set)
  1264 //      is_pEp (out)  - boolean pointer - will return true or false by
  1265 //                      reference with respect to whether or not user is
  1266 //                      a known pEp user
  1267 //
  1268 //  return_value: PEP_STATUS_OK if user found in person table
  1269 //                PEP_ILLEGAL_VALUE if no user_id in input
  1270 //                PEP_CANNOT_FIND_PERSON if user_id doesn't exist
  1271 //
  1272 //  caveat: This *does not check comm_type*
  1273 //                         
  1274 DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session, 
  1275                                    pEp_identity *identity, 
  1276                                    bool* is_pEp);
  1277 
  1278 
  1279 
  1280 DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session);
  1281 
  1282 // This is used internally when there is a temporary identity to be retrieved
  1283 // that may not yet have an FPR attached. See get_identity() for functionality,
  1284 // params and caveats.
  1285 PEP_STATUS get_identity_without_trust_check(
  1286         PEP_SESSION session,
  1287         const char *address,
  1288         const char *user_id,
  1289         pEp_identity **identity
  1290     );
  1291     
  1292 PEP_STATUS get_identities_by_address(
  1293         PEP_SESSION session,
  1294         const char *address,
  1295         identity_list** id_list
  1296     );
  1297         
  1298 PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
  1299                               const char* new_uid);
  1300                               
  1301 PEP_STATUS remove_fpr_as_default(PEP_SESSION session, 
  1302                                     const char* fpr);
  1303                               
  1304                                     
  1305 PEP_STATUS get_main_user_fpr(PEP_SESSION session, 
  1306                              const char* user_id,
  1307                              char** main_fpr);
  1308 
  1309 PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
  1310                               const char* new_fpr);
  1311     
  1312 PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id);
  1313 
  1314 // This ONLY sets the *user* flag, and creates a shell identity if necessary.
  1315 PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user);
  1316 
  1317 // returns true (by reference) if a person with this user_id exists; 
  1318 // Also replaces aliased user_ids by defaults in identity.
  1319 PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity, bool* exists);
  1320 
  1321 PEP_STATUS set_pgp_keypair(PEP_SESSION session, const char* fpr);
  1322 
  1323 #ifdef __cplusplus
  1324 }
  1325 #endif