...
authorvb
Fri, 16 Jan 2015 18:39:27 +0100
changeset 4537a80387790d
parent 44 4013b57a6a69
child 46 7471e31bb278
...
src/message_api.c
src/pgp_gpg.c
src/transport.h
test/message_api_test.cc
     1.1 --- a/src/message_api.c	Sat Jan 03 16:37:53 2015 +0100
     1.2 +++ b/src/message_api.c	Fri Jan 16 18:39:27 2015 +0100
     1.3 @@ -98,6 +98,7 @@
     1.4      if (fp == NULL) {
     1.5          return PEP_CANNOT_CREATE_TEMP_FILE;
     1.6      }
     1.7 +    // unlink(fn);
     1.8  
     1.9      int col = 0;
    1.10      int r = mailmime_write_file(fp, &col, mime_body);
     2.1 --- a/src/pgp_gpg.c	Sat Jan 03 16:37:53 2015 +0100
     2.2 +++ b/src/pgp_gpg.c	Fri Jan 16 18:39:27 2015 +0100
     2.3 @@ -1,6 +1,8 @@
     2.4  #include "pgp_gpg.h"
     2.5  #include "pEp_internal.h"
     2.6  
     2.7 +#define _GPGERR(X) ((X) & 0xffffL)
     2.8 +
     2.9  static bool ensure_keyserver()
    2.10  {
    2.11      static char buf[MAX_LINELENGTH];
    2.12 @@ -209,7 +211,7 @@
    2.13      _session->gpg.gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
    2.14  
    2.15      gpgme_error = _session->gpg.gpgme_new(&_session->ctx);
    2.16 -    gpgme_error = gpg_err_code(gpgme_error);
    2.17 +    gpgme_error = _GPGERR(gpgme_error);
    2.18      if (gpgme_error != GPG_ERR_NO_ERROR) {
    2.19          dlclose(_session->gpgme);
    2.20          free(_session);
    2.21 @@ -219,7 +221,7 @@
    2.22  
    2.23      gpgme_error = _session->gpg.gpgme_set_protocol(_session->ctx,
    2.24          GPGME_PROTOCOL_OpenPGP);
    2.25 -    gpgme_error = gpg_err_code(gpgme_error);
    2.26 +    gpgme_error = _GPGERR(gpgme_error);
    2.27      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.28  
    2.29      _session->gpg.gpgme_set_armor(_session->ctx, 1);
    2.30 @@ -264,7 +266,7 @@
    2.31      *keylist = NULL;
    2.32  
    2.33      gpgme_error = _session->gpg.gpgme_data_new_from_mem(&cipher, ctext, csize, 0);
    2.34 -    gpgme_error = gpg_err_code(gpgme_error);
    2.35 +    gpgme_error = _GPGERR(gpgme_error);
    2.36      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.37      if (gpgme_error != GPG_ERR_NO_ERROR) {
    2.38          if (gpgme_error == GPG_ERR_ENOMEM)
    2.39 @@ -274,7 +276,7 @@
    2.40      }
    2.41  
    2.42      gpgme_error = _session->gpg.gpgme_data_new(&plain);
    2.43 -    gpgme_error = gpg_err_code(gpgme_error);
    2.44 +    gpgme_error = _GPGERR(gpgme_error);
    2.45      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.46      if (gpgme_error != GPG_ERR_NO_ERROR) {
    2.47          _session->gpg.gpgme_data_release(cipher);
    2.48 @@ -290,7 +292,7 @@
    2.49      case GPGME_DATA_TYPE_PGP_OTHER:
    2.50          gpgme_error = _session->gpg.gpgme_op_decrypt_verify(_session->ctx, cipher,
    2.51              plain);
    2.52 -        gpgme_error = gpg_err_code(gpgme_error);
    2.53 +        gpgme_error = _GPGERR(gpgme_error);
    2.54          assert(gpgme_error != GPG_ERR_INV_VALUE);
    2.55          assert(gpgme_error != GPG_ERR_NO_DATA);
    2.56  
    2.57 @@ -450,7 +452,7 @@
    2.58      *keylist = NULL;
    2.59  
    2.60      gpgme_error = _session->gpg.gpgme_data_new_from_mem(&d_text, text, size, 0);
    2.61 -    gpgme_error = gpg_err_code(gpgme_error);
    2.62 +    gpgme_error = _GPGERR(gpgme_error);
    2.63      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.64      if (gpgme_error != GPG_ERR_NO_ERROR) {
    2.65          if (gpgme_error == GPG_ERR_ENOMEM)
    2.66 @@ -460,7 +462,7 @@
    2.67      }
    2.68  
    2.69      gpgme_error = _session->gpg.gpgme_data_new_from_mem(&d_sig, signature, sig_size, 0);
    2.70 -    gpgme_error = gpg_err_code(gpgme_error);
    2.71 +    gpgme_error = _GPGERR(gpgme_error);
    2.72      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.73      if (gpgme_error != GPG_ERR_NO_ERROR) {
    2.74          _session->gpg.gpgme_data_release(d_text);
    2.75 @@ -471,7 +473,7 @@
    2.76      }
    2.77  
    2.78      gpgme_error = _session->gpg.gpgme_op_verify(_session->ctx, d_sig, d_text, NULL);
    2.79 -    gpgme_error = gpg_err_code(gpgme_error);
    2.80 +    gpgme_error = _GPGERR(gpgme_error);
    2.81      assert(gpgme_error != GPG_ERR_INV_VALUE);
    2.82  
    2.83      switch (gpgme_error) {
    2.84 @@ -587,7 +589,7 @@
    2.85      *csize = 0;
    2.86  
    2.87      gpgme_error = _session->gpg.gpgme_data_new_from_mem(&plain, ptext, psize, 0);
    2.88 -    gpgme_error = gpg_err_code(gpgme_error);
    2.89 +    gpgme_error = _GPGERR(gpgme_error);
    2.90      assert(gpgme_error == GPG_ERR_NO_ERROR);
    2.91      if (gpgme_error != GPG_ERR_NO_ERROR) {
    2.92          if (gpgme_error == GPG_ERR_ENOMEM)
    2.93 @@ -597,7 +599,7 @@
    2.94      }
    2.95  
    2.96      gpgme_error = _session->gpg.gpgme_data_new(&cipher);
    2.97 -    gpgme_error = gpg_err_code(gpgme_error);
    2.98 +    gpgme_error = _GPGERR(gpgme_error);
    2.99      assert(gpgme_error == GPG_ERR_NO_ERROR);
   2.100      if (gpgme_error != GPG_ERR_NO_ERROR) {
   2.101          _session->gpg.gpgme_data_release(plain);
   2.102 @@ -622,7 +624,7 @@
   2.103          assert(_keylist->value);
   2.104          gpgme_error = _session->gpg.gpgme_get_key(_session->ctx, _keylist->value,
   2.105              &rcpt[i], 0);
   2.106 -        gpgme_error = gpg_err_code(gpgme_error);
   2.107 +        gpgme_error = _GPGERR(gpgme_error);
   2.108          assert(gpgme_error != GPG_ERR_ENOMEM);
   2.109  
   2.110          switch (gpgme_error) {
   2.111 @@ -636,7 +638,7 @@
   2.112          case GPG_ERR_NO_ERROR:
   2.113              if (i == 0) {
   2.114                  gpgme_error_t _gpgme_error = _session->gpg.gpgme_signers_add(_session->ctx, rcpt[0]);
   2.115 -                _gpgme_error = gpg_err_code(_gpgme_error);
   2.116 +                _gpgme_error = _GPGERR(_gpgme_error);
   2.117                  assert(_gpgme_error == GPG_ERR_NO_ERROR);
   2.118              }
   2.119              break;
   2.120 @@ -670,7 +672,7 @@
   2.121  
   2.122      gpgme_error = _session->gpg.gpgme_op_encrypt_sign(_session->ctx, rcpt, flags,
   2.123          plain, cipher);
   2.124 -    gpgme_error = gpg_err_code(gpgme_error);
   2.125 +    gpgme_error = _GPGERR(gpgme_error);
   2.126      switch (gpgme_error) {
   2.127      case GPG_ERR_NO_ERROR:
   2.128      {
   2.129 @@ -754,7 +756,7 @@
   2.130      }
   2.131  
   2.132      gpgme_error = _session->gpg.gpgme_op_genkey(_session->ctx, parms, NULL, NULL);
   2.133 -    gpgme_error = gpg_err_code(gpgme_error);
   2.134 +    gpgme_error = _GPGERR(gpgme_error);
   2.135      free(parms);
   2.136  
   2.137      switch (gpgme_error) {
   2.138 @@ -788,7 +790,7 @@
   2.139      assert(fpr);
   2.140  
   2.141      gpgme_error = _session->gpg.gpgme_get_key(_session->ctx, fpr, &key, 0);
   2.142 -    gpgme_error = gpg_err_code(gpgme_error);
   2.143 +    gpgme_error = _GPGERR(gpgme_error);
   2.144      assert(gpgme_error != GPG_ERR_ENOMEM);
   2.145      switch (gpgme_error) {
   2.146      case GPG_ERR_NO_ERROR:
   2.147 @@ -807,7 +809,7 @@
   2.148      }
   2.149  
   2.150      gpgme_error = _session->gpg.gpgme_op_delete(_session->ctx, key, 1);
   2.151 -    gpgme_error = gpg_err_code(gpgme_error);
   2.152 +    gpgme_error = _GPGERR(gpgme_error);
   2.153      _session->gpg.gpgme_key_unref(key);
   2.154      switch (gpgme_error) {
   2.155      case GPG_ERR_NO_ERROR:
   2.156 @@ -839,7 +841,7 @@
   2.157      assert(key_data);
   2.158  
   2.159      gpgme_error = _session->gpg.gpgme_data_new_from_mem(&dh, key_data, size, 0);
   2.160 -    gpgme_error = gpg_err_code(gpgme_error);
   2.161 +    gpgme_error = _GPGERR(gpgme_error);
   2.162      assert(gpgme_error != GPG_ERR_ENOMEM);
   2.163      switch (gpgme_error) {
   2.164      case GPG_ERR_NO_ERROR:
   2.165 @@ -855,7 +857,7 @@
   2.166      }
   2.167  
   2.168      gpgme_error = _session->gpg.gpgme_op_import(_session->ctx, dh);
   2.169 -    gpgme_error = gpg_err_code(gpgme_error);
   2.170 +    gpgme_error = _GPGERR(gpgme_error);
   2.171      switch (gpgme_error) {
   2.172      case GPG_ERR_NO_ERROR:
   2.173          break;
   2.174 @@ -893,7 +895,7 @@
   2.175      assert(size);
   2.176  
   2.177      gpgme_error = _session->gpg.gpgme_data_new(&dh);
   2.178 -    gpgme_error = gpg_err_code(gpgme_error);
   2.179 +    gpgme_error = _GPGERR(gpgme_error);
   2.180      assert(gpgme_error != GPG_ERR_ENOMEM);
   2.181      switch (gpgme_error) {
   2.182      case GPG_ERR_NO_ERROR:
   2.183 @@ -910,7 +912,7 @@
   2.184  
   2.185      gpgme_error = _session->gpg.gpgme_op_export(_session->ctx, fpr,
   2.186          GPGME_EXPORT_MODE_MINIMAL, dh);
   2.187 -    gpgme_error = gpg_err_code(gpgme_error);
   2.188 +    gpgme_error = _GPGERR(gpgme_error);
   2.189      switch (gpgme_error) {
   2.190      case GPG_ERR_NO_ERROR:
   2.191          break;
   2.192 @@ -963,7 +965,7 @@
   2.193      mode |= add_mode;
   2.194  
   2.195      gpgme_error = _session->gpg.gpgme_set_keylist_mode(_session->ctx, mode);
   2.196 -    gpgme_error = gpg_err_code(gpgme_error);
   2.197 +    gpgme_error = _GPGERR(gpgme_error);
   2.198      assert(gpgme_error == GPG_ERR_NO_ERROR);
   2.199  }
   2.200  
   2.201 @@ -979,7 +981,7 @@
   2.202      _switch_mode(_session, GPGME_KEYLIST_MODE_LOCAL, GPGME_KEYLIST_MODE_EXTERN);
   2.203  
   2.204      gpgme_error = _session->gpg.gpgme_op_keylist_start(_session->ctx, pattern, 0);
   2.205 -    gpgme_error = gpg_err_code(gpgme_error);
   2.206 +    gpgme_error = _GPGERR(gpgme_error);
   2.207      switch (gpgme_error) {
   2.208      case GPG_ERR_NO_ERROR:
   2.209          break;
   2.210 @@ -996,7 +998,7 @@
   2.211  
   2.212      do {
   2.213          gpgme_error = _session->gpg.gpgme_op_keylist_next(_session->ctx, &key);
   2.214 -        gpgme_error = gpg_err_code(gpgme_error);
   2.215 +        gpgme_error = _GPGERR(gpgme_error);
   2.216          assert(gpgme_error != GPG_ERR_INV_VALUE);
   2.217          switch (gpgme_error) {
   2.218          case GPG_ERR_EOF:
   2.219 @@ -1010,7 +1012,7 @@
   2.220              keys[1] = NULL;
   2.221  
   2.222              gpgme_error = _session->gpg.gpgme_op_import_keys(_session->ctx, keys);
   2.223 -            gpgme_error = gpg_err_code(gpgme_error);
   2.224 +            gpgme_error = _GPGERR(gpgme_error);
   2.225              _session->gpg.gpgme_key_unref(key);
   2.226              assert(gpgme_error != GPG_ERR_INV_VALUE);
   2.227              assert(gpgme_error != GPG_ERR_CONFLICT);
   2.228 @@ -1056,7 +1058,7 @@
   2.229      *keylist = NULL;
   2.230  
   2.231      gpgme_error = _session->gpg.gpgme_op_keylist_start(_session->ctx, pattern, 0);
   2.232 -    gpgme_error = gpg_err_code(gpgme_error);
   2.233 +    gpgme_error = _GPGERR(gpgme_error);
   2.234      switch (gpgme_error) {
   2.235      case GPG_ERR_NO_ERROR:
   2.236          break;
   2.237 @@ -1072,7 +1074,7 @@
   2.238  
   2.239      do {
   2.240          gpgme_error = _session->gpg.gpgme_op_keylist_next(_session->ctx, &key);
   2.241 -        gpgme_error = gpg_err_code(gpgme_error);
   2.242 +        gpgme_error = _GPGERR(gpgme_error);
   2.243          assert(gpgme_error != GPG_ERR_INV_VALUE);
   2.244          switch (gpgme_error) {
   2.245          case GPG_ERR_EOF:
   2.246 @@ -1117,7 +1119,7 @@
   2.247  
   2.248      gpgme_error = _session->gpg.gpgme_op_export(_session->ctx, pattern,
   2.249          GPGME_EXPORT_MODE_EXTERN, NULL);
   2.250 -    gpgme_error = gpg_err_code(gpgme_error);
   2.251 +    gpgme_error = _GPGERR(gpgme_error);
   2.252      assert(gpgme_error != GPG_ERR_INV_VALUE);
   2.253      if (gpgme_error == GPG_ERR_NO_ERROR)
   2.254          return PEP_STATUS_OK;
   2.255 @@ -1144,7 +1146,7 @@
   2.256      *comm_type = PEP_ct_unknown;
   2.257  
   2.258      gpgme_error = _session->gpg.gpgme_op_keylist_start(_session->ctx, fpr, 0);
   2.259 -    gpgme_error = gpg_err_code(gpgme_error);
   2.260 +    gpgme_error = _GPGERR(gpgme_error);
   2.261      switch (gpgme_error) {
   2.262      case GPG_ERR_NO_ERROR:
   2.263          break;
   2.264 @@ -1156,7 +1158,7 @@
   2.265      };
   2.266  
   2.267      gpgme_error = _session->gpg.gpgme_op_keylist_next(_session->ctx, &key);
   2.268 -    gpgme_error = gpg_err_code(gpgme_error);
   2.269 +    gpgme_error = _GPGERR(gpgme_error);
   2.270      assert(gpgme_error != GPG_ERR_INV_VALUE);
   2.271  
   2.272      if (key == NULL) {
     3.1 --- a/src/transport.h	Sat Jan 03 16:37:53 2015 +0100
     3.2 +++ b/src/transport.h	Fri Jan 16 18:39:27 2015 +0100
     3.3 @@ -35,7 +35,7 @@
     3.4  //  caveat:
     3.5  //      ident is being moved, the caller loses ownership
     3.6  
     3.7 -identity_list *new_identity_list(pEp_identity *ident);
     3.8 +DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident);
     3.9  
    3.10  
    3.11  // identity_list_dup() - duplicate identity_list (deep copy)
    3.12 @@ -46,7 +46,7 @@
    3.13  //  return value:
    3.14  //      new identity_list or NULL if out of memory
    3.15  
    3.16 -identity_list *identity_list_dup(const identity_list *src);
    3.17 +DYNAMIC_API identity_list *identity_list_dup(const identity_list *src);
    3.18  
    3.19  
    3.20  // free_identity_list() - free memory allocated by identity_list
    3.21 @@ -58,7 +58,7 @@
    3.22  //      this function frees all identities in the list additional to the
    3.23  //      identity_list itself
    3.24  
    3.25 -void free_identity_list(identity_list *id_list);
    3.26 +DYNAMIC_API void free_identity_list(identity_list *id_list);
    3.27  
    3.28  
    3.29  // identity_list_add - add identity to an identity_list
    3.30 @@ -73,7 +73,7 @@
    3.31  //  caveat:
    3.32  //      ident is being moved, the caller loses ownership
    3.33  
    3.34 -identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
    3.35 +DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
    3.36  
    3.37  typedef enum _PEP_msg_format {
    3.38      PEP_format_plain = 0,
    3.39 @@ -111,7 +111,7 @@
    3.40  //      the ownership of the blob goes to the bloblist; mime_type and file_name
    3.41  //      are being copied, the originals remain in the ownership of the caller
    3.42  
    3.43 -bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
    3.44 +DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
    3.45          const char *file_name);
    3.46  
    3.47  
    3.48 @@ -120,7 +120,7 @@
    3.49  //  parameters:
    3.50  //      bloblist        bloblist to free
    3.51  
    3.52 -void free_bloblist(bloblist_t *bloblist);
    3.53 +DYNAMIC_API void free_bloblist(bloblist_t *bloblist);
    3.54  
    3.55  
    3.56  // bloblist_add() - add reference to a blob to bloblist
    3.57 @@ -139,7 +139,7 @@
    3.58  //      the ownership of the blob goes to the bloblist; mime_type and file_name
    3.59  //      are being copied, the originals remain in the ownership of the caller
    3.60  
    3.61 -bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    3.62 +DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    3.63          const char *mime_type, const char *file_name);
    3.64  
    3.65  
    3.66 @@ -205,7 +205,7 @@
    3.67  //      them; shortmsg is being copied, the ownership of the original remains
    3.68  //      with the caller
    3.69  
    3.70 -message *new_message(
    3.71 +DYNAMIC_API message *new_message(
    3.72          PEP_msg_direction dir,
    3.73          pEp_identity *from,
    3.74          identity_list *to,
    3.75 @@ -222,7 +222,7 @@
    3.76  //      raw data as well as referenced other messages aren't freed and remain
    3.77  //      in the ownership of the caller
    3.78  
    3.79 -void free_message(message *msg);
    3.80 +DYNAMIC_API void free_message(message *msg);
    3.81  
    3.82  
    3.83  // new_message_ref_list() - allocate new message reference list
    3.84 @@ -233,7 +233,7 @@
    3.85  //  return value:
    3.86  //      pointer to new message_ref_list or NULL if out of memory
    3.87  
    3.88 -message_ref_list *new_message_ref_list(message *msg);
    3.89 +DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
    3.90  
    3.91  
    3.92  // free_message_ref_list() - free message reference list
    3.93 @@ -241,7 +241,7 @@
    3.94  //  parameters:
    3.95  //      msg_list        message_ref_list to free
    3.96  
    3.97 -void free_message_ref_list(message_ref_list *msg_list);
    3.98 +DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
    3.99  
   3.100  
   3.101  // message_ref_list_add() - add a reference to a message to a message reference
   3.102 @@ -255,7 +255,7 @@
   3.103  //      pointer to the last element of message_ref_list or NULL if out of
   3.104  //      memory
   3.105  
   3.106 -message_ref_list *message_ref_list_add(message_ref_list *msg_list,
   3.107 +DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list,
   3.108          message *msg);
   3.109  
   3.110  
     4.1 --- a/test/message_api_test.cc	Sat Jan 03 16:37:53 2015 +0100
     4.2 +++ b/test/message_api_test.cc	Fri Jan 16 18:39:27 2015 +0100
     4.3 @@ -29,9 +29,19 @@
     4.4      assert(enc_msg);
     4.5      cout << "message encrypted.\n";
     4.6  
     4.7 +//     cout << "MIME encoding message…\n";
     4.8 +//     message *mmsg;
     4.9 +//     PEP_STATUS status3 = mime_encode_parts(msg, &mmsg);
    4.10 +//     assert(mmsg);
    4.11 +//     assert(status3 == PEP_STATUS_OK);
    4.12 +//     cout << "message:\n";
    4.13 +//     cout << mmsg->longmsg;
    4.14 +//     cout << "\n";
    4.15 +
    4.16      cout << "freeing messages…\n";
    4.17      free_message(msg);
    4.18      free_message(enc_msg);
    4.19 +//     free_message(mmsg);
    4.20      cout << "done.\n";
    4.21  
    4.22      cout << "calling release()\n";