src/pEpEngine.h
author Volker Birk <vb@pep.foundation>
Wed, 31 Aug 2016 10:13:37 +0200
branchkeysync
changeset 1101 a9e46b630bf4
parent 1091 0571ce4b97a2
child 1103 aba4f9ea5bce
permissions -rw-r--r--
adding trust check on outgoing side
vb@23
     1
#pragma once
vb@23
     2
vb@0
     3
#ifdef __cplusplus
vb@0
     4
extern "C" {
vb@0
     5
#endif
vb@0
     6
vb@25
     7
#include <stddef.h>
vb@0
     8
#include <stdint.h>
vb@0
     9
#include <stdbool.h>
vb@0
    10
vb@98
    11
#include "dynamic_api.h"
vb@98
    12
#include "stringlist.h"
krista@1005
    13
#include "stringpair.h"    
vb@201
    14
#include "timestamp.h"
vb@0
    15
krista@942
    16
#define PEP_VERSION "1.0" // protocol version
vb@94
    17
Edouard@658
    18
#define PEP_OWN_USERID "pEp_own_userId"
Edouard@658
    19
    
vb@0
    20
// pEp Engine API
vb@0
    21
vb@0
    22
//  caveat:
vb@0
    23
//      Unicode data has to be normalized to NFC before calling
vb@0
    24
//      UTF-8 strings are UTF-8 encoded C strings (zero terminated)
vb@0
    25
vb@0
    26
vb@46
    27
struct _pEpSession;
vb@46
    28
typedef struct _pEpSession * PEP_SESSION;
vb@0
    29
vb@0
    30
typedef enum {
roker@529
    31
    PEP_STATUS_OK                                   = 0,
vb@0
    32
roker@529
    33
    PEP_INIT_CANNOT_LOAD_GPGME                      = 0x0110,
roker@529
    34
    PEP_INIT_GPGME_INIT_FAILED                      = 0x0111,
roker@529
    35
    PEP_INIT_NO_GPG_HOME                            = 0x0112,
roker@529
    36
    PEP_INIT_NETPGP_INIT_FAILED                     = 0x0113,
vb@0
    37
roker@529
    38
    PEP_INIT_SQLITE3_WITHOUT_MUTEX                  = 0x0120,
roker@529
    39
    PEP_INIT_CANNOT_OPEN_DB                         = 0x0121,
roker@529
    40
    PEP_INIT_CANNOT_OPEN_SYSTEM_DB                  = 0x0122,
roker@529
    41
    
roker@529
    42
    PEP_KEY_NOT_FOUND                               = 0x0201,
roker@529
    43
    PEP_KEY_HAS_AMBIG_NAME                          = 0x0202,
roker@529
    44
    PEP_GET_KEY_FAILED                              = 0x0203,
roker@529
    45
    
roker@529
    46
    PEP_CANNOT_FIND_IDENTITY                        = 0x0301,
roker@529
    47
    PEP_CANNOT_SET_PERSON                           = 0x0381,
roker@529
    48
    PEP_CANNOT_SET_PGP_KEYPAIR                      = 0x0382,
roker@529
    49
    PEP_CANNOT_SET_IDENTITY                         = 0x0383,
vb@370
    50
    PEP_CANNOT_SET_TRUST                            = 0x0384,
vb@515
    51
    PEP_KEY_BLACKLISTED                             = 0x0385,
roker@529
    52
    
roker@529
    53
    PEP_UNENCRYPTED                                 = 0x0400,
roker@529
    54
    PEP_VERIFIED                                    = 0x0401,
roker@529
    55
    PEP_DECRYPTED                                   = 0x0402,
roker@529
    56
    PEP_DECRYPTED_AND_VERIFIED                      = 0x0403,
roker@529
    57
    PEP_DECRYPT_WRONG_FORMAT                        = 0x0404,
roker@529
    58
    PEP_DECRYPT_NO_KEY                              = 0x0405,
roker@529
    59
    PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH            = 0x0406,
vb@0
    60
    PEP_VERIFY_NO_KEY                               = 0x0407,
vb@0
    61
    PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
roker@529
    62
    PEP_CANNOT_DECRYPT_UNKNOWN                      = 0x04ff,
vb@0
    63
roker@529
    64
    PEP_TRUSTWORD_NOT_FOUND                         = 0x0501,
vb@0
    65
vb@0
    66
    PEP_CANNOT_CREATE_KEY                           = 0x0601,
vb@0
    67
    PEP_CANNOT_SEND_KEY                             = 0x0602,
vb@0
    68
vb@458
    69
    PEP_PHRASE_NOT_FOUND                            = 0x0701,
vb@458
    70
vb@690
    71
    PEP_SEND_FUNCTION_NOT_REGISTERED                = 0x0801,
vb@691
    72
    PEP_CONTRAINTS_VIOLATED                         = 0x0802,
vb@691
    73
    PEP_CANNOT_ENCODE                               = 0x0803,
vb@690
    74
vb@884
    75
    PEP_SYNC_NO_TRUSTWORDS_CALLBACK                 = 0x0901,
vb@951
    76
    PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
vb@884
    77
vb@1085
    78
    PEP_SEQUENCE_VIOLATED                           = 0x0970,
vb@1085
    79
    PEP_CANNOT_INCREASE_SEQUENCE                    = 0x0971,
vb@1087
    80
    PEP_CANNOT_SET_SEQUENCE_VALUE                   = 0x0972,
vb@1087
    81
    PEP_OWN_SEQUENCE                                = 0x097f,
vb@1085
    82
vb@964
    83
    PEP_SYNC_STATEMACHINE_ERROR                     = 0x0980,
vb@1101
    84
    PEP_SYNC_NO_TRUST                               = 0x0981,
vb@964
    85
    PEP_STATEMACHINE_INVALID_STATE                  = 0x0982,
vb@964
    86
    PEP_STATEMACHINE_INVALID_EVENT                  = 0x0983,
vb@964
    87
    PEP_STATEMACHINE_INVALID_CONDITION              = 0x0984,
vb@964
    88
    PEP_STATEMACHINE_INVALID_ACTION                 = 0x0985,
vb@884
    89
roker@529
    90
    PEP_COMMIT_FAILED                               = 0xff01,
vb@952
    91
    PEP_MESSAGE_CONSUMED                            = 0xff02,
vb@0
    92
vb@1091
    93
    PEP_RECORD_NOT_FOUND                            = -6,
vb@44
    94
    PEP_CANNOT_CREATE_TEMP_FILE                     = -5,
vb@0
    95
    PEP_ILLEGAL_VALUE                               = -4,
vb@0
    96
    PEP_BUFFER_TOO_SMALL                            = -3,
roker@529
    97
    PEP_OUT_OF_MEMORY                               = -2,
roker@529
    98
    PEP_UNKNOWN_ERROR                               = -1
vb@0
    99
} PEP_STATUS;
vb@0
   100
vb@0
   101
vb@0
   102
// INIT_STATUS init() - initialize pEpEngine for a thread
vb@0
   103
//
vb@0
   104
//  parameters:
roker@529
   105
//        session (out)   init() allocates session memory and returns a pointer
roker@529
   106
//                        as a handle
vb@0
   107
//
vb@0
   108
//  return value:
roker@529
   109
//        PEP_STATUS_OK = 0                 if init() succeeds
roker@529
   110
//        PEP_INIT_SQLITE3_WITHOUT_MUTEX    if SQLite3 was compiled with
roker@529
   111
//                                            SQLITE_THREADSAFE 0
roker@529
   112
//        PEP_INIT_CANNOT_LOAD_GPGME        if libgpgme.dll cannot be found
roker@529
   113
//        PEP_INIT_GPGME_INIT_FAILED        if GPGME init fails
roker@529
   114
//        PEP_INIT_CANNOT_OPEN_DB           if user's management db cannot be
roker@529
   115
//                                            opened
roker@529
   116
//        PEP_INIT_CANNOT_OPEN_SYSTEM_DB    if system's management db cannot be
roker@529
   117
//                                            opened
vb@0
   118
//
vb@0
   119
//  caveat:
vb@0
   120
//      the pointer is valid only if the return value is PEP_STATUS_OK
vb@0
   121
//      in other case a NULL pointer will be returned; a valid handle must
vb@0
   122
//      be released using release() when it's no longer needed
vb@62
   123
//
vb@62
   124
//      the caller has to guarantee that the first call to this function
vb@62
   125
//      will succeed before further calls can be done
vb@0
   126
vb@0
   127
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session);
vb@0
   128
vb@0
   129
vb@0
   130
// void release() - release thread session handle
vb@0
   131
//
vb@0
   132
//  parameters:
roker@529
   133
//        session (in)    session handle to release
vb@62
   134
//
roker@529
   135
//    caveat:
roker@529
   136
//        the last release() can be called only when all other release() calls
roker@529
   137
//        are done
vb@0
   138
vb@0
   139
DYNAMIC_API void release(PEP_SESSION session);
vb@0
   140
vb@0
   141
vb@464
   142
// config_passive_mode() - enable passive mode
vb@464
   143
//
vb@464
   144
//  parameters:
vb@464
   145
//      session (in)    session handle
vb@467
   146
//      enable (in)     flag if enabled or disabled
vb@467
   147
vb@467
   148
DYNAMIC_API void config_passive_mode(PEP_SESSION session, bool enable);
vb@467
   149
vb@464
   150
vb@553
   151
// config_unencrypted_subject() - disable subject encryption
vb@467
   152
//
vb@467
   153
//  parameters:
vb@467
   154
//      session (in)    session handle
vb@467
   155
//      enable (in)     flag if enabled or disabled
vb@467
   156
vb@467
   157
DYNAMIC_API void config_unencrypted_subject(PEP_SESSION session, bool enable);
vb@464
   158
vb@464
   159
Edouard@721
   160
// config_use_only_own_private_keys() - enable passive mode
Edouard@721
   161
//
Edouard@721
   162
//  parameters:
Edouard@721
   163
//      session (in)    session handle
Edouard@721
   164
//      enable (in)     flag if enabled or disabled
Edouard@721
   165
Edouard@721
   166
DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session, bool enable);
Edouard@721
   167
Edouard@721
   168
vb@0
   169
// decrypt_and_verify() - decrypt and/or verify a message
vb@0
   170
//
roker@529
   171
//    parameters:
roker@529
   172
//        session (in)    session handle
roker@529
   173
//        ctext (in)      cipher text to decrypt and/or verify
roker@529
   174
//        csize (in)      size of cipher text
roker@529
   175
//        ptext (out)     pointer to internal buffer with plain text
roker@529
   176
//        psize (out)     size of plain text
roker@529
   177
//        keylist (out)   list of key ids which where used to encrypt
vb@0
   178
//
roker@529
   179
//    return value:
roker@529
   180
//        PEP_UNENCRYPTED               message was unencrypted and not signed
roker@529
   181
//        PEP_VERIFIED                  message was unencrypted, signature matches
roker@529
   182
//        PEP_DECRYPTED                 message is decrypted now, no signature
roker@529
   183
//        PEP_DECRYPTED_AND_VERIFIED    message is decrypted now and verified
roker@529
   184
//        PEP_DECRYPT_WRONG_FORMAT      message has wrong format to handle
roker@529
   185
//        PEP_DECRYPT_NO_KEY            key not available to decrypt and/or verify
roker@529
   186
//        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
vb@0
   187
//
roker@529
   188
//    caveat:
roker@529
   189
//        the ownerships of ptext as well as keylist are going to the caller
roker@529
   190
//        the caller must use free() (or an Windoze pEp_free()) and
roker@529
   191
//        free_stringlist() to free them
vb@15
   192
//
vb@15
   193
//      if this function failes an error message may be the first element of
vb@15
   194
//      keylist and the other elements may be the keys used for encryption
vb@0
   195
vb@0
   196
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@0
   197
        PEP_SESSION session, const char *ctext, size_t csize,
vb@0
   198
        char **ptext, size_t *psize, stringlist_t **keylist
vb@0
   199
    );
vb@0
   200
vb@0
   201
vb@0
   202
// verify_text() - verfy plain text with a digital signature
vb@0
   203
//
vb@0
   204
//  parameters:
vb@0
   205
//      session (in)    session handle
vb@0
   206
//      text (in)       text to verify
vb@0
   207
//      size (in)       size of text
vb@0
   208
//      signature (in)  signature text
vb@0
   209
//      sig_size (in)   size of signature
roker@529
   210
//      keylist (out)   list of key ids which where used to encrypt or NULL on
roker@529
   211
//                        error
vb@0
   212
//
vb@0
   213
//  return value:
roker@529
   214
//        PEP_VERIFIED                message was unencrypted, signature matches
roker@529
   215
//        PEP_DECRYPT_NO_KEY          key not available to decrypt and/or verify
roker@529
   216
//        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
vb@0
   217
vb@0
   218
DYNAMIC_API PEP_STATUS verify_text(
vb@0
   219
        PEP_SESSION session, const char *text, size_t size,
vb@0
   220
        const char *signature, size_t sig_size, stringlist_t **keylist
vb@0
   221
    );
vb@0
   222
vb@0
   223
vb@0
   224
// encrypt_and_sign() - encrypt and sign a message
vb@0
   225
//
roker@529
   226
//    parameters:
roker@529
   227
//        session (in)    session handle
roker@529
   228
//        keylist (in)    list of key ids to encrypt with as C strings
roker@529
   229
//        ptext (in)      plain text to decrypt and/or verify
roker@529
   230
//        psize (in)      size of plain text
roker@529
   231
//        ctext (out)     pointer to internal buffer with cipher text
roker@529
   232
//        csize (out)     size of cipher text
vb@0
   233
//
roker@529
   234
//    return value:
roker@529
   235
//        PEP_STATUS_OK = 0            encryption and signing succeeded
roker@529
   236
//        PEP_KEY_NOT_FOUND            at least one of the receipient keys
roker@529
   237
//                                     could not be found
roker@529
   238
//        PEP_KEY_HAS_AMBIG_NAME       at least one of the receipient keys has
roker@529
   239
//                                     an ambiguous name
roker@529
   240
//        PEP_GET_KEY_FAILED           cannot retrieve key
vb@0
   241
//
roker@529
   242
//    caveat:
roker@529
   243
//      the ownership of ctext is going to the caller
vb@0
   244
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@20
   245
//      the first key in keylist is being used to sign the message
vb@20
   246
//      this implies there has to be a private key for that keypair
vb@0
   247
vb@0
   248
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@0
   249
        PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@0
   250
        size_t psize, char **ctext, size_t *csize
vb@0
   251
    );
vb@0
   252
vb@0
   253
vb@0
   254
// log_event() - log a user defined event defined by UTF-8 encoded strings into
vb@0
   255
// management log
vb@0
   256
//
roker@529
   257
//    parameters:
roker@529
   258
//        session (in)        session handle
roker@529
   259
//        title (in)          C string with event name
roker@529
   260
//        entity (in)         C string with name of entity which is logging
roker@529
   261
//        description (in)    C string with long description for event or NULL if
roker@529
   262
//                            omitted
roker@529
   263
//        comment (in)        C string with user defined comment or NULL if
roker@529
   264
//                            omitted
vb@0
   265
//
roker@529
   266
//    return value:
roker@529
   267
//        PEP_STATUS_OK       log entry created
vb@0
   268
vb@0
   269
DYNAMIC_API PEP_STATUS log_event(
vb@450
   270
        PEP_SESSION session,
vb@451
   271
        const char *title,
vb@451
   272
        const char *entity,
vb@451
   273
        const char *description,
vb@451
   274
        const char *comment
vb@0
   275
    );
vb@0
   276
vb@0
   277
vb@233
   278
// trustword() - get the corresponding trustword for a 16 bit value
vb@0
   279
//
roker@529
   280
//    parameters:
roker@529
   281
//        session (in)            session handle
roker@529
   282
//        value (in)              value to find a trustword for
roker@529
   283
//        lang (in)               C string with ISO 639-1 language code
roker@529
   284
//        word (out)              pointer to C string with trustword UTF-8 encoded
roker@529
   285
//                                NULL if language is not supported or trustword
roker@529
   286
//                                wordlist is damaged or unavailable
roker@529
   287
//        wsize (out)             length of trustword
vb@0
   288
//
roker@529
   289
//    return value:
roker@529
   290
//        PEP_STATUS_OK            trustword retrieved
roker@529
   291
//        PEP_TRUSTWORD_NOT_FOUND  trustword not found
vb@0
   292
//
roker@529
   293
//    caveat:
roker@529
   294
//        the word pointer goes to the ownership of the caller
vb@0
   295
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   296
vb@233
   297
DYNAMIC_API PEP_STATUS trustword(
vb@0
   298
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   299
            char **word, size_t *wsize
vb@0
   300
        );
vb@0
   301
vb@0
   302
vb@233
   303
// trustwords() - get trustwords for a string of hex values of a fingerprint
vb@0
   304
//
roker@529
   305
//    parameters:
roker@529
   306
//        session (in)        session handle
roker@529
   307
//        fingerprint (in)    C string with hex values to find trustwords for
roker@529
   308
//        lang (in)           C string with ISO 639-1 language code
roker@529
   309
//        words (out)         pointer to C string with trustwords UTF-8 encoded,
roker@529
   310
//                            separated by a blank each
roker@529
   311
//                            NULL if language is not supported or trustword
roker@529
   312
//                            wordlist is damaged or unavailable
roker@529
   313
//        wsize (out)         length of trustwords string
roker@529
   314
//        max_words (in)      only generate a string with max_words;
roker@529
   315
//                            if max_words == 0 there is no such limit
vb@0
   316
//
roker@529
   317
//    return value:
roker@529
   318
//        PEP_STATUS_OK            trustwords retrieved
roker@529
   319
//        PEP_OUT_OF_MEMORY        out of memory
roker@529
   320
//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
vb@0
   321
//
roker@529
   322
//    caveat:
roker@529
   323
//        the word pointer goes to the ownership of the caller
vb@0
   324
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   325
//
vb@0
   326
//  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
vb@0
   327
//
vb@233
   328
//  Better implement a simple one in the adapter yourself using trustword(), and
vb@233
   329
//  return a list of trustwords.
vb@0
   330
//  This function is provided for being used by C and C++ programs only.
vb@0
   331
vb@233
   332
DYNAMIC_API PEP_STATUS trustwords(
vb@0
   333
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   334
        char **words, size_t *wsize, int max_words
vb@0
   335
    );
vb@0
   336
vb@0
   337
vb@951
   338
// TODO: increase versions in pEp.asn1 if rating changes
vb@951
   339
vb@0
   340
typedef enum _PEP_comm_type {
vb@9
   341
    PEP_ct_unknown = 0,
vb@0
   342
vb@9
   343
    // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
vb@0
   344
vb@9
   345
    PEP_ct_no_encryption = 0x01,                // generic
vb@9
   346
    PEP_ct_no_encrypted_channel = 0x02,
vb@9
   347
    PEP_ct_key_not_found = 0x03,
vb@9
   348
    PEP_ct_key_expired = 0x04,
vb@9
   349
    PEP_ct_key_revoked = 0x05,
vb@9
   350
    PEP_ct_key_b0rken = 0x06,
vb@9
   351
    PEP_ct_my_key_not_included = 0x09,
vb@9
   352
vb@9
   353
    PEP_ct_security_by_obscurity = 0x0a,
vb@9
   354
    PEP_ct_b0rken_crypto = 0x0b,
Edouard@442
   355
    PEP_ct_key_too_short = 0x0c,
vb@9
   356
Edouard@442
   357
    PEP_ct_compromized = 0x0e,                  // known compromized connection
Edouard@442
   358
    PEP_ct_mistrusted = 0x0f,                   // known mistrusted key
vb@0
   359
vb@9
   360
    // range 0x10 to 0x3f: unconfirmed encryption
vb@0
   361
vb@0
   362
    PEP_ct_unconfirmed_encryption = 0x10,       // generic
roker@529
   363
    PEP_ct_OpenPGP_weak_unconfirmed = 0x11,     // RSA 1024 is weak
vb@190
   364
vb@190
   365
    PEP_ct_to_be_checked = 0x20,                // generic
vb@190
   366
    PEP_ct_SMIME_unconfirmed = 0x21,
vb@190
   367
    PEP_ct_CMS_unconfirmed = 0x22,
vb@190
   368
vb@190
   369
    PEP_ct_strong_but_unconfirmed = 0x30,       // generic
vb@122
   370
    PEP_ct_OpenPGP_unconfirmed = 0x38,          // key at least 2048 bit RSA or EC
vb@122
   371
    PEP_ct_OTR_unconfirmed = 0x3a,
vb@0
   372
vb@9
   373
    // range 0x40 to 0x7f: unconfirmed encryption and anonymization
vb@0
   374
vb@0
   375
    PEP_ct_unconfirmed_enc_anon = 0x40,         // generic
lix@710
   376
    PEP_ct_pEp_unconfirmed = 0x7f,
vb@0
   377
vb@9
   378
    PEP_ct_confirmed = 0x80,                    // this bit decides if trust is confirmed
vb@9
   379
vb@9
   380
    // range 0x81 to 0x8f: reserved
vb@9
   381
    // range 0x90 to 0xbf: confirmed encryption
vb@0
   382
vb@0
   383
    PEP_ct_confirmed_encryption = 0x90,         // generic
roker@529
   384
    PEP_ct_OpenPGP_weak = 0x91,                 // RSA 1024 is weak
vb@190
   385
vb@190
   386
    PEP_ct_to_be_checked_confirmed = 0xa0,      //generic
vb@190
   387
    PEP_ct_SMIME = 0xa1,
vb@190
   388
    PEP_ct_CMS = 0xa2,
vb@190
   389
vb@190
   390
    PEP_ct_strong_encryption = 0xb0,            // generic
roker@529
   391
    PEP_ct_OpenPGP = 0xb8,                      // key at least 2048 bit RSA or EC
roker@529
   392
    PEP_ct_OTR = 0xba,
vb@0
   393
vb@0
   394
    // range 0xc0 to 0xff: confirmed encryption and anonymization
vb@0
   395
vb@0
   396
    PEP_ct_confirmed_enc_anon = 0xc0,           // generic
roker@529
   397
    PEP_ct_pEp = 0xff
vb@0
   398
} PEP_comm_type;
vb@0
   399
vb@928
   400
typedef enum _identity_flags {
vb@951
   401
    // the first octet flags are app defined settings
vb@934
   402
    PEP_idf_not_for_sync = 1,   // don't use this identity for sync
vb@951
   403
    PEP_idf_list = 2,           // identity of list of persons
vb@945
   404
vb@951
   405
    // the second octet flags are calculated
vb@951
   406
    PEP_idf_devicegroup = 256   // identity of a device group member
vb@928
   407
} identity_flags;
vb@928
   408
vb@944
   409
typedef unsigned int identity_flags_t;
vb@944
   410
vb@0
   411
typedef struct _pEp_identity {
roker@529
   412
    char *address;              // C string with address UTF-8 encoded
roker@529
   413
    char *fpr;                  // C string with fingerprint UTF-8 encoded
roker@529
   414
    char *user_id;              // C string with user ID UTF-8 encoded
roker@529
   415
    char *username;             // C string with user name UTF-8 encoded
roker@529
   416
    PEP_comm_type comm_type;    // type of communication with this ID
roker@529
   417
    char lang[3];               // language of conversation
vb@0
   418
                                // ISO 639-1 ALPHA-2, last byte is 0
vb@0
   419
    bool me;                    // if this is the local user herself/himself
vb@944
   420
    identity_flags_t flags;     // identity_flag1 | identity_flag2 | ...
vb@0
   421
} pEp_identity;
vb@0
   422
Edouard@730
   423
typedef struct _identity_list {
Edouard@730
   424
    pEp_identity *ident;
Edouard@730
   425
    struct _identity_list *next;
Edouard@730
   426
} identity_list;
Edouard@730
   427
vb@0
   428
vb@0
   429
// new_identity() - allocate memory and set the string and size fields
vb@0
   430
//
vb@0
   431
//  parameters:
vb@0
   432
//      address (in)        UTF-8 string or NULL 
vb@0
   433
//      fpr (in)            UTF-8 string or NULL 
vb@0
   434
//      user_id (in)        UTF-8 string or NULL 
vb@0
   435
//      username (in)       UTF-8 string or NULL 
vb@0
   436
//
vb@0
   437
//  return value:
vb@932
   438
//      pEp_identity struct or NULL if out of memory
vb@0
   439
//
vb@0
   440
//  caveat:
vb@0
   441
//      the strings are copied; the original strings are still being owned by
vb@0
   442
//      the caller
vb@0
   443
vb@0
   444
DYNAMIC_API pEp_identity *new_identity(
vb@0
   445
        const char *address, const char *fpr, const char *user_id,
vb@0
   446
        const char *username
vb@0
   447
    );
vb@0
   448
vb@0
   449
vb@932
   450
// identity_dup() - allocate memory and duplicate
vb@37
   451
//
vb@37
   452
//  parameters:
vb@37
   453
//      src (in)            identity to duplicate
vb@37
   454
//
vb@37
   455
//  return value:
vb@932
   456
//      pEp_identity struct or NULL if out of memory
vb@37
   457
//
vb@37
   458
//  caveat:
vb@37
   459
//      the strings are copied; the original strings are still being owned by
vb@37
   460
//      the caller
vb@37
   461
vb@37
   462
DYNAMIC_API pEp_identity *identity_dup(const pEp_identity *src);
vb@37
   463
vb@37
   464
vb@0
   465
// free_identity() - free all memory being occupied by a pEp_identity struct
vb@0
   466
//
vb@0
   467
//  parameters:
vb@0
   468
//      identity (in)       struct to release
vb@0
   469
//
vb@0
   470
//  caveat:
vb@0
   471
//      not only the struct but also all string memory referenced by the
vb@0
   472
//      struct is being freed; all pointers inside are invalid afterwards
vb@0
   473
vb@0
   474
DYNAMIC_API void free_identity(pEp_identity *identity);
vb@0
   475
vb@0
   476
vb@0
   477
// get_identity() - get identity information
vb@0
   478
//
roker@529
   479
//    parameters:
roker@529
   480
//        session (in)        session handle
roker@529
   481
//        address (in)        C string with communication address, UTF-8 encoded
Edouard@562
   482
//        user_id (in)        unique C string to identify person that identity
Edouard@562
   483
//                            is refering to
roker@529
   484
//        identity (out)      pointer to pEp_identity structure with results or
roker@529
   485
//                            NULL if failure
vb@0
   486
//
roker@529
   487
//    caveat:
vb@951
   488
//        address and user_id are being copied; the original strings remains in
vb@951
   489
//        the ownership of the caller
roker@529
   490
//        the resulting pEp_identity structure goes to the ownership of the
roker@529
   491
//        caller and has to be freed with free_identity() when not in use any
roker@529
   492
//        more
vb@0
   493
vb@0
   494
DYNAMIC_API PEP_STATUS get_identity(
Edouard@559
   495
        PEP_SESSION session,
Edouard@559
   496
        const char *address,
Edouard@559
   497
        const char *user_id,
vb@0
   498
        pEp_identity **identity
vb@0
   499
    );
vb@0
   500
vb@0
   501
// set_identity() - set identity information
vb@0
   502
//
roker@529
   503
//    parameters:
roker@529
   504
//        session (in)        session handle
roker@529
   505
//        identity (in)       pointer to pEp_identity structure
vb@0
   506
//
roker@529
   507
//    return value:
roker@529
   508
//        PEP_STATUS_OK = 0             encryption and signing succeeded
roker@529
   509
//        PEP_CANNOT_SET_PERSON         writing to table person failed
roker@529
   510
//        PEP_CANNOT_SET_PGP_KEYPAIR    writing to table pgp_keypair failed
roker@529
   511
//        PEP_CANNOT_SET_IDENTITY       writing to table identity failed
roker@529
   512
//        PEP_COMMIT_FAILED             SQL commit failed
vb@932
   513
//        PEP_KEY_BLACKLISTED           Key blacklisted, cannot set identity
vb@0
   514
//
roker@529
   515
//    caveat:
vb@932
   516
//        address, fpr, user_id and username must be given
vb@0
   517
vb@0
   518
DYNAMIC_API PEP_STATUS set_identity(
vb@0
   519
        PEP_SESSION session, const pEp_identity *identity
vb@0
   520
    );
vb@0
   521
vb@0
   522
vb@932
   523
// set_identity_flags() - update identity flags on existing identity
vb@932
   524
//
vb@932
   525
//    parameters:
vb@932
   526
//        session (in)        session handle
vb@934
   527
//        identity (in,out)   pointer to pEp_identity structure
vb@934
   528
//        flags (in)          new value for flags
vb@932
   529
//
vb@932
   530
//    return value:
vb@932
   531
//        PEP_STATUS_OK = 0             encryption and signing succeeded
vb@932
   532
//        PEP_CANNOT_SET_IDENTITY       update of identity failed
vb@932
   533
//
vb@932
   534
//    caveat:
vb@934
   535
//        address and user_id must be given in identity
vb@932
   536
vb@932
   537
DYNAMIC_API PEP_STATUS set_identity_flags(
vb@934
   538
        PEP_SESSION session,
vb@934
   539
        pEp_identity *identity,
vb@934
   540
        unsigned int flags
vb@932
   541
    );
vb@932
   542
vb@932
   543
vb@357
   544
// mark_as_compromized() - mark key in trust db as compromized
vb@357
   545
//
roker@529
   546
//    parameters:
roker@529
   547
//        session (in)        session handle
roker@529
   548
//        fpr (in)            fingerprint of key to mark
vb@357
   549
vb@357
   550
DYNAMIC_API PEP_STATUS mark_as_compromized(
vb@357
   551
        PEP_SESSION session,
vb@357
   552
        const char *fpr
vb@357
   553
    );
vb@357
   554
vb@357
   555
vb@0
   556
// generate_keypair() - generate a new key pair and add it to the key ring
vb@0
   557
//
vb@0
   558
//  parameters:
vb@0
   559
//      session (in)            session handle
roker@529
   560
//        identity (inout)      pointer to pEp_identity structure
vb@0
   561
//
roker@529
   562
//    return value:
roker@529
   563
//        PEP_STATUS_OK = 0       encryption and signing succeeded
roker@529
   564
//        PEP_ILLEGAL_VALUE       illegal values for identity fields given
roker@529
   565
//        PEP_CANNOT_CREATE_KEY   key engine is on strike
vb@0
   566
//
vb@0
   567
//  caveat:
vb@0
   568
//      address and username fields must be set to UTF-8 strings
vb@0
   569
//      the fpr field must be set to NULL
vb@0
   570
//
vb@0
   571
//      this function allocates a string and sets set fpr field of identity
vb@0
   572
//      the caller is responsible to call free() for that string or use
vb@0
   573
//      free_identity() on the struct
vb@0
   574
vb@0
   575
DYNAMIC_API PEP_STATUS generate_keypair(
vb@0
   576
        PEP_SESSION session, pEp_identity *identity
vb@0
   577
    );
vb@0
   578
vb@0
   579
vb@0
   580
// delete_keypair() - delete a public key or a key pair from the key ring
vb@0
   581
//
vb@0
   582
//  parameters:
vb@0
   583
//      session (in)            session handle
vb@0
   584
//      fpr (in)                C string with key id or fingerprint of the
vb@0
   585
//                              public key
vb@0
   586
//
vb@0
   587
//  return value:
vb@0
   588
//      PEP_STATUS_OK = 0       key was successfully deleted
vb@0
   589
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   590
//      PEP_ILLEGAL_VALUE       not a valid key id or fingerprint
vb@0
   591
//      PEP_KEY_HAS_AMBIG_NAME  fpr does not uniquely identify a key
vb@0
   592
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   593
vb@0
   594
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
vb@0
   595
vb@0
   596
vb@0
   597
// import_key() - import key from data
vb@0
   598
//
vb@0
   599
//  parameters:
vb@0
   600
//      session (in)            session handle
vb@0
   601
//      key_data (in)           key data, i.e. ASCII armored OpenPGP key
vb@0
   602
//      size (in)               amount of data to handle
Edouard@772
   603
//      private_keys (out)      list of private keys that have been imported
vb@0
   604
//
vb@0
   605
//  return value:
vb@0
   606
//      PEP_STATUS_OK = 0       key was successfully imported
vb@0
   607
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   608
//      PEP_ILLEGAL_VALUE       there is no key data to import
Edouard@772
   609
//
Edouard@772
   610
//  caveat:
Edouard@772
   611
//      private_keys goes to the ownership of the caller
Edouard@772
   612
//      private_keys can be left NULL, it is then ignored
vb@0
   613
Edouard@728
   614
DYNAMIC_API PEP_STATUS import_key(
Edouard@728
   615
        PEP_SESSION session,
Edouard@728
   616
        const char *key_data,
Edouard@728
   617
        size_t size,
Edouard@728
   618
        identity_list **private_keys
Edouard@728
   619
    );
vb@0
   620
vb@0
   621
vb@0
   622
// export_key() - export ascii armored key
vb@0
   623
//
vb@0
   624
//  parameters:
vb@0
   625
//      session (in)            session handle
vb@0
   626
//      fpr (in)                key id or fingerprint of key
vb@0
   627
//      key_data (out)          ASCII armored OpenPGP key
roker@529
   628
//      size (out)              amount of data to handle
vb@0
   629
//
vb@0
   630
//  return value:
vb@0
   631
//      PEP_STATUS_OK = 0       key was successfully exported
vb@0
   632
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   633
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   634
//
vb@0
   635
//  caveat:
vb@0
   636
//      the key_data goes to the ownership of the caller
vb@0
   637
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   638
vb@0
   639
DYNAMIC_API PEP_STATUS export_key(
vb@0
   640
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@0
   641
    );
vb@0
   642
vb@0
   643
vb@0
   644
// recv_key() - update key(s) from keyserver
vb@0
   645
//
vb@0
   646
//  parameters:
vb@0
   647
//      session (in)            session handle
vb@0
   648
//      pattern (in)            key id, user id or address to search for as
vb@0
   649
//                              UTF-8 string
vb@0
   650
vb@0
   651
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
vb@0
   652
vb@0
   653
vb@0
   654
// find_keys() - find keys in keyring
vb@0
   655
//
vb@0
   656
//  parameters:
vb@0
   657
//      session (in)            session handle
vb@0
   658
//      pattern (in)            key id, user id or address to search for as
vb@0
   659
//                              UTF-8 string
vb@0
   660
//      keylist (out)           list of fingerprints found or NULL on error
vb@0
   661
//
vb@0
   662
//  caveat:
roker@529
   663
//        the ownerships of keylist isgoing to the caller
roker@529
   664
//        the caller must use free_stringlist() to free it
vb@0
   665
vb@0
   666
vb@0
   667
DYNAMIC_API PEP_STATUS find_keys(
vb@0
   668
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@0
   669
    );
vb@0
   670
vb@0
   671
// send_key() - send key(s) to keyserver
vb@0
   672
//
vb@0
   673
//  parameters:
vb@0
   674
//      session (in)            session handle
vb@0
   675
//      pattern (in)            key id, user id or address to search for as
vb@0
   676
//                              UTF-8 string
vb@0
   677
vb@0
   678
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
vb@0
   679
vb@0
   680
vb@0
   681
// pEp_free() - free memory allocated by pEp engine
vb@0
   682
//
vb@0
   683
//  parameters:
vb@0
   684
//      p (in)                  pointer to free
vb@0
   685
//
vb@0
   686
//  The reason for this function is that heap management can be a pretty
vb@0
   687
//  complex task with Windoze. This free() version calls the free()
vb@0
   688
//  implementation of the C runtime library which was used to build pEp engine,
vb@0
   689
//  so you're using the correct heap. For more information, see:
vb@0
   690
//  <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
vb@0
   691
vb@0
   692
DYNAMIC_API void pEp_free(void *p);
vb@0
   693
vb@8
   694
vb@8
   695
// get_trust() - get the trust level a key has for a person
vb@8
   696
//
vb@8
   697
//  parameters:
vb@8
   698
//      session (in)            session handle
vb@8
   699
//      identity (inout)        user_id and fpr to check as UTF-8 strings (in)
vb@8
   700
//                              user_id and comm_type as result (out)
vb@8
   701
//
vb@14
   702
//  this function modifies the given identity struct; the struct remains in
vb@251
   703
//  the ownership of the caller
vb@14
   704
//  if the trust level cannot be determined identity->comm_type is set
vb@14
   705
//  to PEP_ct_unknown
vb@8
   706
vb@8
   707
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
vb@8
   708
vb@8
   709
vb@251
   710
// least_trust() - get the least known trust level for a key in the database
vb@251
   711
//
vb@251
   712
//  parameters:
vb@251
   713
//      session (in)            session handle
vb@251
   714
//      fpr (in)                fingerprint of key to check
vb@251
   715
//      comm_type (out)         least comm_type as result (out)
vb@251
   716
//
vb@251
   717
//  if the trust level cannot be determined comm_type is set to PEP_ct_unknown
vb@251
   718
vb@251
   719
DYNAMIC_API PEP_STATUS least_trust(
vb@251
   720
        PEP_SESSION session,
vb@251
   721
        const char *fpr,
vb@251
   722
        PEP_comm_type *comm_type
vb@251
   723
    );
vb@251
   724
vb@251
   725
vb@9
   726
// get_key_rating() - get the rating a bare key has
vb@9
   727
//
vb@9
   728
//  parameters:
vb@9
   729
//      session (in)            session handle
vb@9
   730
//      fpr (in)                unique identifyer for key as UTF-8 string
vb@9
   731
//      comm_type (out)         key rating
vb@10
   732
//
vb@14
   733
//  if an error occurs, *comm_type is set to PEP_ct_unknown and an error
vb@10
   734
//  is returned
vb@9
   735
vb@9
   736
DYNAMIC_API PEP_STATUS get_key_rating(
vb@14
   737
        PEP_SESSION session,
vb@14
   738
        const char *fpr,
vb@14
   739
        PEP_comm_type *comm_type
vb@9
   740
    );
vb@9
   741
vb@9
   742
vb@198
   743
// renew_key() - renew an expired key
vb@196
   744
//
vb@196
   745
//  parameters:
vb@196
   746
//      session (in)            session handle
vb@214
   747
//      fpr (in)                ID of key to renew as UTF-8 string
vb@201
   748
//      ts (in)                 timestamp when key should expire or NULL for
vb@201
   749
//                              default
vb@196
   750
vb@201
   751
DYNAMIC_API PEP_STATUS renew_key(
vb@201
   752
        PEP_SESSION session,
vb@201
   753
        const char *fpr,
vb@201
   754
        const timestamp *ts
vb@201
   755
    );
vb@196
   756
vb@196
   757
vb@224
   758
// revoke_key() - revoke a key
vb@197
   759
//
vb@197
   760
//  parameters:
vb@197
   761
//      session (in)            session handle
vb@214
   762
//      fpr (in)                ID of key to revoke as UTF-8 string
vb@211
   763
//      reason (in)             text with reason for revoke as UTF-8 string
vb@211
   764
//                              or NULL if reason unknown
vb@211
   765
//
vb@211
   766
//  caveat:
vb@211
   767
//      reason text must not include empty lines
vb@224
   768
//      this function is meant for internal use only; better use
vb@224
   769
//      key_compromized() of keymanagement API
vb@197
   770
vb@211
   771
DYNAMIC_API PEP_STATUS revoke_key(
vb@211
   772
        PEP_SESSION session,
vb@211
   773
        const char *fpr,
vb@211
   774
        const char *reason
vb@211
   775
    );
vb@197
   776
vb@197
   777
vb@214
   778
// key_expired() - flags if a key is already expired
vb@214
   779
//
vb@214
   780
//  parameters:
vb@214
   781
//      session (in)            session handle
vb@214
   782
//      fpr (in)                ID of key to check as UTF-8 string
Edouard@701
   783
//      when (in)               UTC time of when should expiry be considered
vb@214
   784
//      expired (out)           flag if key expired
vb@214
   785
vb@214
   786
DYNAMIC_API PEP_STATUS key_expired(
vb@214
   787
        PEP_SESSION session,
vb@214
   788
        const char *fpr,
Edouard@701
   789
        const time_t when,
vb@214
   790
        bool *expired
vb@214
   791
    );
vb@214
   792
Edouard@694
   793
    
Edouard@694
   794
// key_revoked() - flags if a key is already revoked
Edouard@694
   795
//
Edouard@694
   796
//  parameters:
Edouard@694
   797
//      session (in)            session handle
Edouard@694
   798
//      fpr (in)                ID of key to check as UTF-8 string
Edouard@694
   799
//      revoked (out)           flag if key revoked
Edouard@694
   800
Edouard@694
   801
DYNAMIC_API PEP_STATUS key_revoked(
Edouard@694
   802
        PEP_SESSION session,
Edouard@694
   803
        const char *fpr,
Edouard@694
   804
        bool *revoked
Edouard@694
   805
    );
Edouard@694
   806
vb@214
   807
vb@450
   808
// get_crashdump_log() - get the last log messages out
vb@450
   809
//
vb@450
   810
//  parameters:
vb@450
   811
//      session (in)            session handle
vb@450
   812
//      maxlines (in)           maximum number of lines (0 for default)
vb@458
   813
//      logdata (out)           logdata as string in double quoted CSV format
vb@463
   814
//                              column1 is title
vb@463
   815
//                              column2 is entity
vb@463
   816
//                              column3 is description
vb@463
   817
//                              column4 is comment
vb@462
   818
//
vb@462
   819
//  caveat:
vb@462
   820
//      the ownership of logdata goes to the caller
vb@450
   821
vb@450
   822
DYNAMIC_API PEP_STATUS get_crashdump_log(
vb@450
   823
        PEP_SESSION session,
vb@450
   824
        int maxlines,
vb@450
   825
        char **logdata
vb@450
   826
    );
vb@450
   827
vb@450
   828
dirk@501
   829
// get_languagelist() - get the list of languages
vb@458
   830
//
vb@458
   831
//  parameters:
vb@458
   832
//      session (in)            session handle
vb@458
   833
//      languages (out)         languages as string in double quoted CSV format
vb@463
   834
//                              column 1 is the ISO 639-1 language code
vb@463
   835
//                              column 2 is the name of the language
vb@462
   836
//
vb@462
   837
//  caveat:
vb@462
   838
//      the ownership of languages goes to the caller
vb@458
   839
vb@458
   840
DYNAMIC_API PEP_STATUS get_languagelist(
vb@458
   841
        PEP_SESSION session,
vb@458
   842
        char **languages
vb@458
   843
    );
vb@458
   844
vb@458
   845
vb@458
   846
// get_phrase() - get phrase in a dedicated language through i18n
vb@458
   847
//
vb@458
   848
//  parameters:
vb@458
   849
//      session (in)            session handle
roker@529
   850
//      lang (in)               C string with ISO 639-1 language code
vb@458
   851
//      phrase_id (in)          id of phrase in i18n
vb@458
   852
//      phrase (out)            phrase as UTF-8 string
vb@462
   853
//
vb@462
   854
//  caveat:
vb@462
   855
//      the ownership of phrase goes to the caller
vb@458
   856
vb@458
   857
DYNAMIC_API PEP_STATUS get_phrase(
vb@458
   858
        PEP_SESSION session,
vb@458
   859
        const char *lang,
vb@458
   860
        int phrase_id,
vb@458
   861
        char **phrase
vb@458
   862
    );
vb@458
   863
vb@458
   864
vb@632
   865
// sequence_value() - raise the value of a named sequence and retrieve it
vb@632
   866
//
vb@632
   867
//  parameters:
vb@632
   868
//      session (in)            session handle
vb@1085
   869
//      name (inout)            name of sequence or char[37] set to {0, }
vb@1086
   870
//                              for new own sequence named as UUID
vb@1085
   871
//      value (inout)           value of sequence value to test or 0 for
vb@1085
   872
//                              getting next value
vb@1085
   873
//
vb@1085
   874
//  returns:
vb@1086
   875
//      PEP_STATUS_OK                   no error, not own sequence
vb@1086
   876
//      PEP_SEQUENCE_VIOLATED           if sequence violated
vb@1086
   877
//      PEP_CANNOT_INCREASE_SEQUENCE    if sequence cannot be increased
vb@1086
   878
//      PEP_OWN_SEQUENCE                if own sequence
vb@632
   879
vb@632
   880
DYNAMIC_API PEP_STATUS sequence_value(
vb@632
   881
        PEP_SESSION session,
vb@1085
   882
        char *name,
vb@652
   883
        int32_t *value
vb@632
   884
    );
vb@632
   885
vb@1044
   886
Edouard@694
   887
// set_revoked() - records relation between a revoked key and its replacement
Edouard@694
   888
//
Edouard@694
   889
//  parameters:
Edouard@694
   890
//      session (in)            session handle
Edouard@694
   891
//      revoked_fpr (in)        revoked fingerprint
Edouard@694
   892
//      replacement_fpr (in)    replacement key fingerprint
Edouard@694
   893
//      revocation_date (in)    revocation date
Edouard@694
   894
Edouard@693
   895
DYNAMIC_API PEP_STATUS set_revoked(
Edouard@693
   896
       PEP_SESSION session,
Edouard@693
   897
       const char *revoked_fpr,
Edouard@693
   898
       const char *replacement_fpr,
Edouard@693
   899
       const uint64_t revocation_date
Edouard@693
   900
    );
Edouard@693
   901
vb@958
   902
Edouard@694
   903
// get_revoked() - find revoked key that may have been replaced by given key, if any
Edouard@694
   904
//
Edouard@694
   905
//  parameters:
Edouard@694
   906
//      session (in)            session handle
Edouard@694
   907
//      fpr (in)                given fingerprint
Edouard@694
   908
//      revoked_fpr (out)       revoked fingerprint
Edouard@694
   909
//      revocation_date (out)   revocation date
Edouard@694
   910
    
Edouard@693
   911
DYNAMIC_API PEP_STATUS get_revoked(
Edouard@693
   912
        PEP_SESSION session,
Edouard@693
   913
        const char *fpr,
Edouard@693
   914
        char **revoked_fpr,
Edouard@693
   915
        uint64_t *revocation_date
Edouard@693
   916
    );
Edouard@693
   917
vb@632
   918
vb@958
   919
// key_created() - get creation date of a key
vb@958
   920
//
vb@958
   921
//  parameters:
vb@958
   922
//      session (in)            session handle
vb@958
   923
//      fpr (in)                fingerprint of key
vb@958
   924
//      created (out)           date of creation
vb@958
   925
vb@958
   926
PEP_STATUS key_created(
vb@958
   927
        PEP_SESSION session,
vb@958
   928
        const char *fpr,
vb@958
   929
        time_t *created
vb@958
   930
    );
vb@958
   931
vb@958
   932
krista@1011
   933
// get_engine_version() - returns the current version of pEpEngine (this is different
krista@1011
   934
//                        from the pEp protocol version!)
krista@1011
   935
//
krista@1011
   936
//  parameters: none
krista@1011
   937
//
krista@1011
   938
//  return_value: const char* to the engine version string constant
krista@1011
   939
//
krista@1011
   940
DYNAMIC_API const char* get_engine_version();
krista@1011
   941
vb@482
   942
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
vb@482
   943
vb@0
   944
#ifdef __cplusplus
vb@0
   945
}
vb@0
   946
#endif