...
authorvb
Tue, 24 Feb 2015 02:19:11 +0100
changeset 74c94f9b9cb7f2
parent 73 075aa4eaeb4f
child 75 b447045162f8
child 76 6da29caa5dae
...
src/message_api.c
src/pEp_internal.h
src/pgp_gpg.c
src/pgp_gpg.h
     1.1 --- a/src/message_api.c	Tue Feb 24 02:06:11 2015 +0100
     1.2 +++ b/src/message_api.c	Tue Feb 24 02:19:11 2015 +0100
     1.3 @@ -280,9 +280,16 @@
     1.4      PEP_STATUS status = PEP_STATUS_OK;
     1.5      message *msg = NULL;
     1.6  
     1.7 -    msg = new_message(src->dir, from, to, NULL);
     1.8 +    assert(session);
     1.9 +    assert(src);
    1.10 +    assert(dst);
    1.11  
    1.12 -    return msg;
    1.13 +    *dst = NULL;
    1.14 +    
    1.15 +    // msg = new_message(src->dir, from, to, NULL);
    1.16 +
    1.17 +    *dst = msg;
    1.18 +    return PEP_STATUS_OK;
    1.19  
    1.20  enomem:
    1.21      status = PEP_OUT_OF_MEMORY;
     2.1 --- a/src/pEp_internal.h	Tue Feb 24 02:06:11 2015 +0100
     2.2 +++ b/src/pEp_internal.h	Tue Feb 24 02:19:11 2015 +0100
     2.3 @@ -63,8 +63,6 @@
     2.4  typedef struct _pEpSession {
     2.5      const char *version;
     2.6  #ifndef NO_GPG
     2.7 -    void *gpgme;
     2.8 -    struct gpg_s *gpg;
     2.9      gpgme_ctx_t ctx;
    2.10  #endif
    2.11  
     3.1 --- a/src/pgp_gpg.c	Tue Feb 24 02:06:11 2015 +0100
     3.2 +++ b/src/pgp_gpg.c	Tue Feb 24 02:19:11 2015 +0100
     3.3 @@ -5,6 +5,9 @@
     3.4  
     3.5  #define _GPGERR(X) ((X) & 0xffffL)
     3.6  
     3.7 +void *gpgme;
     3.8 +struct gpg_s gpg;
     3.9 +
    3.10  static bool ensure_keyserver()
    3.11  {
    3.12      static char buf[MAX_LINELENGTH];
    3.13 @@ -57,8 +60,6 @@
    3.14  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
    3.15  {
    3.16      PEP_STATUS status = PEP_STATUS_OK;
    3.17 -    static struct gpg_s gpg;
    3.18 -    static void *gpgme;
    3.19      gpgme_error_t gpgme_error;
    3.20      bool bResult;
    3.21      
    3.22 @@ -241,8 +242,6 @@
    3.23  #endif
    3.24      }
    3.25  
    3.26 -    session->gpg = &gpg;
    3.27 -
    3.28      gpgme_error = gpg.gpgme_new(&session->ctx);
    3.29      gpgme_error = _GPGERR(gpgme_error);
    3.30      if (gpgme_error != GPG_ERR_NO_ERROR) {
    3.31 @@ -267,16 +266,13 @@
    3.32  void pgp_release(PEP_SESSION session, bool out_last)
    3.33  {
    3.34      if (session->ctx) {
    3.35 -        session->gpg->gpgme_release(session->ctx);
    3.36 +        gpg.gpgme_release(session->ctx);
    3.37          session->ctx = NULL;
    3.38      }
    3.39  
    3.40 -    if (out_last) {
    3.41 -        if (session->gpgme) {
    3.42 -            dlclose(session->gpgme);
    3.43 -            session->gpgme = NULL;
    3.44 -        }
    3.45 -    }
    3.46 +    if (out_last)
    3.47 +        if (gpgme)
    3.48 +            dlclose(gpgme);
    3.49  }
    3.50  
    3.51  PEP_STATUS pgp_decrypt_and_verify(
    3.52 @@ -303,7 +299,7 @@
    3.53      *psize = 0;
    3.54      *keylist = NULL;
    3.55  
    3.56 -    gpgme_error = session->gpg->gpgme_data_new_from_mem(&cipher, ctext, csize, 0);
    3.57 +    gpgme_error = gpg.gpgme_data_new_from_mem(&cipher, ctext, csize, 0);
    3.58      gpgme_error = _GPGERR(gpgme_error);
    3.59      assert(gpgme_error == GPG_ERR_NO_ERROR);
    3.60      if (gpgme_error != GPG_ERR_NO_ERROR) {
    3.61 @@ -313,22 +309,22 @@
    3.62              return PEP_UNKNOWN_ERROR;
    3.63      }
    3.64  
    3.65 -    gpgme_error = session->gpg->gpgme_data_new(&plain);
    3.66 +    gpgme_error = gpg.gpgme_data_new(&plain);
    3.67      gpgme_error = _GPGERR(gpgme_error);
    3.68      assert(gpgme_error == GPG_ERR_NO_ERROR);
    3.69      if (gpgme_error != GPG_ERR_NO_ERROR) {
    3.70 -        session->gpg->gpgme_data_release(cipher);
    3.71 +        gpg.gpgme_data_release(cipher);
    3.72          if (gpgme_error == GPG_ERR_ENOMEM)
    3.73              return PEP_OUT_OF_MEMORY;
    3.74          else
    3.75              return PEP_UNKNOWN_ERROR;
    3.76      }
    3.77  
    3.78 -    dt = session->gpg->gpgme_data_identify(cipher);
    3.79 +    dt = gpg.gpgme_data_identify(cipher);
    3.80      switch (dt) {
    3.81      case GPGME_DATA_TYPE_PGP_SIGNED:
    3.82      case GPGME_DATA_TYPE_PGP_OTHER:
    3.83 -        gpgme_error = session->gpg->gpgme_op_decrypt_verify(session->ctx, cipher,
    3.84 +        gpgme_error = gpg.gpgme_op_decrypt_verify(session->ctx, cipher,
    3.85              plain);
    3.86          gpgme_error = _GPGERR(gpgme_error);
    3.87          assert(gpgme_error != GPG_ERR_INV_VALUE);
    3.88 @@ -340,11 +336,11 @@
    3.89              gpgme_verify_result_t gpgme_verify_result;
    3.90              char *_buffer = NULL;
    3.91              size_t reading;
    3.92 -            size_t length = session->gpg->gpgme_data_seek(plain, 0, SEEK_END);
    3.93 +            size_t length = gpg.gpgme_data_seek(plain, 0, SEEK_END);
    3.94              gpgme_signature_t gpgme_signature;
    3.95  
    3.96              assert(length != -1);
    3.97 -            session->gpg->gpgme_data_seek(plain, 0, SEEK_SET);
    3.98 +            gpg.gpgme_data_seek(plain, 0, SEEK_SET);
    3.99  
   3.100              // TODO: make things less memory consuming
   3.101              // the following algorithm allocates memory for the complete
   3.102 @@ -353,16 +349,16 @@
   3.103              _buffer = malloc(length + 1);
   3.104              assert(_buffer);
   3.105              if (_buffer == NULL) {
   3.106 -                session->gpg->gpgme_data_release(plain);
   3.107 -                session->gpg->gpgme_data_release(cipher);
   3.108 +                gpg.gpgme_data_release(plain);
   3.109 +                gpg.gpgme_data_release(cipher);
   3.110                  return PEP_OUT_OF_MEMORY;
   3.111              }
   3.112  
   3.113 -            reading = session->gpg->gpgme_data_read(plain, _buffer, length);
   3.114 +            reading = gpg.gpgme_data_read(plain, _buffer, length);
   3.115              assert(length == reading);
   3.116  
   3.117              gpgme_verify_result =
   3.118 -                session->gpg->gpgme_op_verify_result(session->ctx);
   3.119 +                gpg.gpgme_op_verify_result(session->ctx);
   3.120              assert(gpgme_verify_result);
   3.121              gpgme_signature = gpgme_verify_result->signatures;
   3.122  
   3.123 @@ -371,8 +367,8 @@
   3.124                  _keylist = new_stringlist(NULL);
   3.125                  assert(_keylist);
   3.126                  if (_keylist == NULL) {
   3.127 -                    session->gpg->gpgme_data_release(plain);
   3.128 -                    session->gpg->gpgme_data_release(cipher);
   3.129 +                    gpg.gpgme_data_release(plain);
   3.130 +                    gpg.gpgme_data_release(cipher);
   3.131                      free(_buffer);
   3.132                      return PEP_OUT_OF_MEMORY;
   3.133                  }
   3.134 @@ -428,7 +424,7 @@
   3.135              NOT_IMPLEMENTED;
   3.136          default:
   3.137          {
   3.138 -            gpgme_decrypt_result_t gpgme_decrypt_result = session->gpg->gpgme_op_decrypt_result(session->ctx);
   3.139 +            gpgme_decrypt_result_t gpgme_decrypt_result = gpg.gpgme_op_decrypt_result(session->ctx);
   3.140              result = PEP_DECRYPT_NO_KEY;
   3.141  
   3.142              if (gpgme_decrypt_result != NULL) {
   3.143 @@ -463,8 +459,8 @@
   3.144          result = PEP_DECRYPT_WRONG_FORMAT;
   3.145      }
   3.146  
   3.147 -    session->gpg->gpgme_data_release(plain);
   3.148 -    session->gpg->gpgme_data_release(cipher);
   3.149 +    gpg.gpgme_data_release(plain);
   3.150 +    gpg.gpgme_data_release(cipher);
   3.151      return result;
   3.152  }
   3.153  
   3.154 @@ -487,7 +483,7 @@
   3.155  
   3.156      *keylist = NULL;
   3.157  
   3.158 -    gpgme_error = session->gpg->gpgme_data_new_from_mem(&d_text, text, size, 0);
   3.159 +    gpgme_error = gpg.gpgme_data_new_from_mem(&d_text, text, size, 0);
   3.160      gpgme_error = _GPGERR(gpgme_error);
   3.161      assert(gpgme_error == GPG_ERR_NO_ERROR);
   3.162      if (gpgme_error != GPG_ERR_NO_ERROR) {
   3.163 @@ -497,18 +493,18 @@
   3.164              return PEP_UNKNOWN_ERROR;
   3.165      }
   3.166  
   3.167 -    gpgme_error = session->gpg->gpgme_data_new_from_mem(&d_sig, signature, sig_size, 0);
   3.168 +    gpgme_error = gpg.gpgme_data_new_from_mem(&d_sig, signature, sig_size, 0);
   3.169      gpgme_error = _GPGERR(gpgme_error);
   3.170      assert(gpgme_error == GPG_ERR_NO_ERROR);
   3.171      if (gpgme_error != GPG_ERR_NO_ERROR) {
   3.172 -        session->gpg->gpgme_data_release(d_text);
   3.173 +        gpg.gpgme_data_release(d_text);
   3.174          if (gpgme_error == GPG_ERR_ENOMEM)
   3.175              return PEP_OUT_OF_MEMORY;
   3.176          else
   3.177              return PEP_UNKNOWN_ERROR;
   3.178      }
   3.179  
   3.180 -    gpgme_error = session->gpg->gpgme_op_verify(session->ctx, d_sig, d_text, NULL);
   3.181 +    gpgme_error = gpg.gpgme_op_verify(session->ctx, d_sig, d_text, NULL);
   3.182      gpgme_error = _GPGERR(gpgme_error);
   3.183      assert(gpgme_error != GPG_ERR_INV_VALUE);
   3.184  
   3.185 @@ -519,7 +515,7 @@
   3.186          gpgme_signature_t gpgme_signature;
   3.187  
   3.188          gpgme_verify_result =
   3.189 -            session->gpg->gpgme_op_verify_result(session->ctx);
   3.190 +            gpg.gpgme_op_verify_result(session->ctx);
   3.191          assert(gpgme_verify_result);
   3.192          gpgme_signature = gpgme_verify_result->signatures;
   3.193  
   3.194 @@ -528,8 +524,8 @@
   3.195              _keylist = new_stringlist(NULL);
   3.196              assert(_keylist);
   3.197              if (_keylist == NULL) {
   3.198 -                session->gpg->gpgme_data_release(d_text);
   3.199 -                session->gpg->gpgme_data_release(d_sig);
   3.200 +                gpg.gpgme_data_release(d_text);
   3.201 +                gpg.gpgme_data_release(d_sig);
   3.202                  return PEP_OUT_OF_MEMORY;
   3.203              }
   3.204              k = _keylist;
   3.205 @@ -539,8 +535,8 @@
   3.206                  k = stringlist_add(k, gpgme_signature->fpr);
   3.207                  if (k == NULL) {
   3.208                      free_stringlist(_keylist);
   3.209 -                    session->gpg->gpgme_data_release(d_text);
   3.210 -                    session->gpg->gpgme_data_release(d_sig);
   3.211 +                    gpg.gpgme_data_release(d_text);
   3.212 +                    gpg.gpgme_data_release(d_sig);
   3.213                      return PEP_OUT_OF_MEMORY;
   3.214                  }
   3.215                  if (gpgme_signature->summary & GPGME_SIGSUM_RED) {
   3.216 @@ -593,8 +589,8 @@
   3.217          break;
   3.218      }
   3.219  
   3.220 -    session->gpg->gpgme_data_release(d_text);
   3.221 -    session->gpg->gpgme_data_release(d_sig);
   3.222 +    gpg.gpgme_data_release(d_text);
   3.223 +    gpg.gpgme_data_release(d_sig);
   3.224  
   3.225      return result;
   3.226  }
   3.227 @@ -622,7 +618,7 @@
   3.228      *ctext = NULL;
   3.229      *csize = 0;
   3.230  
   3.231 -    gpgme_error = session->gpg->gpgme_data_new_from_mem(&plain, ptext, psize, 0);
   3.232 +    gpgme_error = gpg.gpgme_data_new_from_mem(&plain, ptext, psize, 0);
   3.233      gpgme_error = _GPGERR(gpgme_error);
   3.234      assert(gpgme_error == GPG_ERR_NO_ERROR);
   3.235      if (gpgme_error != GPG_ERR_NO_ERROR) {
   3.236 @@ -632,11 +628,11 @@
   3.237              return PEP_UNKNOWN_ERROR;
   3.238      }
   3.239  
   3.240 -    gpgme_error = session->gpg->gpgme_data_new(&cipher);
   3.241 +    gpgme_error = gpg.gpgme_data_new(&cipher);
   3.242      gpgme_error = _GPGERR(gpgme_error);
   3.243      assert(gpgme_error == GPG_ERR_NO_ERROR);
   3.244      if (gpgme_error != GPG_ERR_NO_ERROR) {
   3.245 -        session->gpg->gpgme_data_release(plain);
   3.246 +        gpg.gpgme_data_release(plain);
   3.247          if (gpgme_error == GPG_ERR_ENOMEM)
   3.248              return PEP_OUT_OF_MEMORY;
   3.249          else
   3.250 @@ -647,16 +643,16 @@
   3.251          sizeof(gpgme_key_t));
   3.252      assert(rcpt);
   3.253      if (rcpt == NULL) {
   3.254 -        session->gpg->gpgme_data_release(plain);
   3.255 -        session->gpg->gpgme_data_release(cipher);
   3.256 +        gpg.gpgme_data_release(plain);
   3.257 +        gpg.gpgme_data_release(cipher);
   3.258          return PEP_OUT_OF_MEMORY;
   3.259      }
   3.260  
   3.261 -    session->gpg->gpgme_signers_clear(session->ctx);
   3.262 +    gpg.gpgme_signers_clear(session->ctx);
   3.263  
   3.264      for (_keylist = keylist, i = 0; _keylist != NULL; _keylist = _keylist->next, i++) {
   3.265          assert(_keylist->value);
   3.266 -        gpgme_error = session->gpg->gpgme_get_key(session->ctx, _keylist->value,
   3.267 +        gpgme_error = gpg.gpgme_get_key(session->ctx, _keylist->value,
   3.268              &rcpt[i], 0);
   3.269          gpgme_error = _GPGERR(gpgme_error);
   3.270          assert(gpgme_error != GPG_ERR_ENOMEM);
   3.271 @@ -664,39 +660,39 @@
   3.272          switch (gpgme_error) {
   3.273          case GPG_ERR_ENOMEM:
   3.274              for (j = 0; j<i; j++)
   3.275 -                session->gpg->gpgme_key_unref(rcpt[j]);
   3.276 +                gpg.gpgme_key_unref(rcpt[j]);
   3.277              free(rcpt);
   3.278 -            session->gpg->gpgme_data_release(plain);
   3.279 -            session->gpg->gpgme_data_release(cipher);
   3.280 +            gpg.gpgme_data_release(plain);
   3.281 +            gpg.gpgme_data_release(cipher);
   3.282              return PEP_OUT_OF_MEMORY;
   3.283          case GPG_ERR_NO_ERROR:
   3.284              if (i == 0) {
   3.285 -                gpgme_error_t _gpgme_error = session->gpg->gpgme_signers_add(session->ctx, rcpt[0]);
   3.286 +                gpgme_error_t _gpgme_error = gpg.gpgme_signers_add(session->ctx, rcpt[0]);
   3.287                  _gpgme_error = _GPGERR(_gpgme_error);
   3.288                  assert(_gpgme_error == GPG_ERR_NO_ERROR);
   3.289              }
   3.290              break;
   3.291          case GPG_ERR_EOF:
   3.292              for (j = 0; j<i; j++)
   3.293 -                session->gpg->gpgme_key_unref(rcpt[j]);
   3.294 +                gpg.gpgme_key_unref(rcpt[j]);
   3.295              free(rcpt);
   3.296 -            session->gpg->gpgme_data_release(plain);
   3.297 -            session->gpg->gpgme_data_release(cipher);
   3.298 +            gpg.gpgme_data_release(plain);
   3.299 +            gpg.gpgme_data_release(cipher);
   3.300              return PEP_KEY_NOT_FOUND;
   3.301          case GPG_ERR_AMBIGUOUS_NAME:
   3.302              for (j = 0; j<i; j++)
   3.303 -                session->gpg->gpgme_key_unref(rcpt[j]);
   3.304 +                gpg.gpgme_key_unref(rcpt[j]);
   3.305              free(rcpt);
   3.306 -            session->gpg->gpgme_data_release(plain);
   3.307 -            session->gpg->gpgme_data_release(cipher);
   3.308 +            gpg.gpgme_data_release(plain);
   3.309 +            gpg.gpgme_data_release(cipher);
   3.310              return PEP_KEY_HAS_AMBIG_NAME;
   3.311          default: // GPG_ERR_INV_VALUE if CTX or R_KEY is not a valid pointer or
   3.312              // FPR is not a fingerprint or key ID
   3.313              for (j = 0; j<i; j++)
   3.314 -                session->gpg->gpgme_key_unref(rcpt[j]);
   3.315 +                gpg.gpgme_key_unref(rcpt[j]);
   3.316              free(rcpt);
   3.317 -            session->gpg->gpgme_data_release(plain);
   3.318 -            session->gpg->gpgme_data_release(cipher);
   3.319 +            gpg.gpgme_data_release(plain);
   3.320 +            gpg.gpgme_data_release(cipher);
   3.321              return PEP_GET_KEY_FAILED;
   3.322          }
   3.323      }
   3.324 @@ -704,7 +700,7 @@
   3.325      // TODO: remove that and replace with proper key management
   3.326      flags = GPGME_ENCRYPT_ALWAYS_TRUST;
   3.327  
   3.328 -    gpgme_error = session->gpg->gpgme_op_encrypt_sign(session->ctx, rcpt, flags,
   3.329 +    gpgme_error = gpg.gpgme_op_encrypt_sign(session->ctx, rcpt, flags,
   3.330          plain, cipher);
   3.331      gpgme_error = _GPGERR(gpgme_error);
   3.332      switch (gpgme_error) {
   3.333 @@ -712,9 +708,9 @@
   3.334      {
   3.335          char *_buffer = NULL;
   3.336          size_t reading;
   3.337 -        size_t length = session->gpg->gpgme_data_seek(cipher, 0, SEEK_END);
   3.338 +        size_t length = gpg.gpgme_data_seek(cipher, 0, SEEK_END);
   3.339          assert(length != -1);
   3.340 -        session->gpg->gpgme_data_seek(cipher, 0, SEEK_SET);
   3.341 +        gpg.gpgme_data_seek(cipher, 0, SEEK_SET);
   3.342  
   3.343          // TODO: make things less memory consuming
   3.344          // the following algorithm allocates a buffer for the complete text
   3.345 @@ -723,14 +719,14 @@
   3.346          assert(_buffer);
   3.347          if (_buffer == NULL) {
   3.348              for (j = 0; j<stringlist_length(keylist); j++)
   3.349 -                session->gpg->gpgme_key_unref(rcpt[j]);
   3.350 +                gpg.gpgme_key_unref(rcpt[j]);
   3.351              free(rcpt);
   3.352 -            session->gpg->gpgme_data_release(plain);
   3.353 -            session->gpg->gpgme_data_release(cipher);
   3.354 +            gpg.gpgme_data_release(plain);
   3.355 +            gpg.gpgme_data_release(cipher);
   3.356              return PEP_OUT_OF_MEMORY;
   3.357          }
   3.358  
   3.359 -        reading = session->gpg->gpgme_data_read(cipher, _buffer, length);
   3.360 +        reading = gpg.gpgme_data_read(cipher, _buffer, length);
   3.361          assert(length == reading);
   3.362  
   3.363          *ctext = _buffer;
   3.364 @@ -744,10 +740,10 @@
   3.365      }
   3.366  
   3.367      for (j = 0; j<stringlist_length(keylist); j++)
   3.368 -        session->gpg->gpgme_key_unref(rcpt[j]);
   3.369 +        gpg.gpgme_key_unref(rcpt[j]);
   3.370      free(rcpt);
   3.371 -    session->gpg->gpgme_data_release(plain);
   3.372 -    session->gpg->gpgme_data_release(cipher);
   3.373 +    gpg.gpgme_data_release(plain);
   3.374 +    gpg.gpgme_data_release(cipher);
   3.375      return result;
   3.376  }
   3.377  
   3.378 @@ -788,7 +784,7 @@
   3.379          return PEP_BUFFER_TOO_SMALL;
   3.380      }
   3.381  
   3.382 -    gpgme_error = session->gpg->gpgme_op_genkey(session->ctx, parms, NULL, NULL);
   3.383 +    gpgme_error = gpg.gpgme_op_genkey(session->ctx, parms, NULL, NULL);
   3.384      gpgme_error = _GPGERR(gpgme_error);
   3.385      free(parms);
   3.386  
   3.387 @@ -804,7 +800,7 @@
   3.388          return PEP_UNKNOWN_ERROR;
   3.389      }
   3.390  
   3.391 -    gpgme_genkey_result = session->gpg->gpgme_op_genkey_result(session->ctx);
   3.392 +    gpgme_genkey_result = gpg.gpgme_op_genkey_result(session->ctx);
   3.393      assert(gpgme_genkey_result);
   3.394      assert(gpgme_genkey_result->fpr);
   3.395  
   3.396 @@ -821,7 +817,7 @@
   3.397      assert(session);
   3.398      assert(fpr);
   3.399  
   3.400 -    gpgme_error = session->gpg->gpgme_get_key(session->ctx, fpr, &key, 0);
   3.401 +    gpgme_error = gpg.gpgme_get_key(session->ctx, fpr, &key, 0);
   3.402      gpgme_error = _GPGERR(gpgme_error);
   3.403      assert(gpgme_error != GPG_ERR_ENOMEM);
   3.404      switch (gpgme_error) {
   3.405 @@ -840,9 +836,9 @@
   3.406          return PEP_UNKNOWN_ERROR;
   3.407      }
   3.408  
   3.409 -    gpgme_error = session->gpg->gpgme_op_delete(session->ctx, key, 1);
   3.410 +    gpgme_error = gpg.gpgme_op_delete(session->ctx, key, 1);
   3.411      gpgme_error = _GPGERR(gpgme_error);
   3.412 -    session->gpg->gpgme_key_unref(key);
   3.413 +    gpg.gpgme_key_unref(key);
   3.414      switch (gpgme_error) {
   3.415      case GPG_ERR_NO_ERROR:
   3.416          break;
   3.417 @@ -871,7 +867,7 @@
   3.418      assert(session);
   3.419      assert(key_data);
   3.420  
   3.421 -    gpgme_error = session->gpg->gpgme_data_new_from_mem(&dh, key_data, size, 0);
   3.422 +    gpgme_error = gpg.gpgme_data_new_from_mem(&dh, key_data, size, 0);
   3.423      gpgme_error = _GPGERR(gpgme_error);
   3.424      assert(gpgme_error != GPG_ERR_ENOMEM);
   3.425      switch (gpgme_error) {
   3.426 @@ -887,25 +883,25 @@
   3.427          return PEP_UNKNOWN_ERROR;
   3.428      }
   3.429  
   3.430 -    gpgme_error = session->gpg->gpgme_op_import(session->ctx, dh);
   3.431 +    gpgme_error = gpg.gpgme_op_import(session->ctx, dh);
   3.432      gpgme_error = _GPGERR(gpgme_error);
   3.433      switch (gpgme_error) {
   3.434      case GPG_ERR_NO_ERROR:
   3.435          break;
   3.436      case GPG_ERR_INV_VALUE:
   3.437          assert(0);
   3.438 -        session->gpg->gpgme_data_release(dh);
   3.439 +        gpg.gpgme_data_release(dh);
   3.440          return PEP_UNKNOWN_ERROR;
   3.441      case GPG_ERR_NO_DATA:
   3.442 -        session->gpg->gpgme_data_release(dh);
   3.443 +        gpg.gpgme_data_release(dh);
   3.444          return PEP_ILLEGAL_VALUE;
   3.445      default:
   3.446          assert(0);
   3.447 -        session->gpg->gpgme_data_release(dh);
   3.448 +        gpg.gpgme_data_release(dh);
   3.449          return PEP_UNKNOWN_ERROR;
   3.450      }
   3.451  
   3.452 -    session->gpg->gpgme_data_release(dh);
   3.453 +    gpg.gpgme_data_release(dh);
   3.454      return PEP_STATUS_OK;
   3.455  }
   3.456  
   3.457 @@ -924,7 +920,7 @@
   3.458      assert(key_data);
   3.459      assert(size);
   3.460  
   3.461 -    gpgme_error = session->gpg->gpgme_data_new(&dh);
   3.462 +    gpgme_error = gpg.gpgme_data_new(&dh);
   3.463      gpgme_error = _GPGERR(gpgme_error);
   3.464      assert(gpgme_error != GPG_ERR_ENOMEM);
   3.465      switch (gpgme_error) {
   3.466 @@ -940,37 +936,37 @@
   3.467          return PEP_UNKNOWN_ERROR;
   3.468      }
   3.469  
   3.470 -    gpgme_error = session->gpg->gpgme_op_export(session->ctx, fpr,
   3.471 +    gpgme_error = gpg.gpgme_op_export(session->ctx, fpr,
   3.472          GPGME_EXPORT_MODE_MINIMAL, dh);
   3.473      gpgme_error = _GPGERR(gpgme_error);
   3.474      switch (gpgme_error) {
   3.475      case GPG_ERR_NO_ERROR:
   3.476          break;
   3.477      case GPG_ERR_EOF:
   3.478 -        session->gpg->gpgme_data_release(dh);
   3.479 +        gpg.gpgme_data_release(dh);
   3.480          return PEP_KEY_NOT_FOUND;
   3.481      case GPG_ERR_INV_VALUE:
   3.482          assert(0);
   3.483 -        session->gpg->gpgme_data_release(dh);
   3.484 +        gpg.gpgme_data_release(dh);
   3.485          return PEP_UNKNOWN_ERROR;
   3.486      default:
   3.487          assert(0);
   3.488 -        session->gpg->gpgme_data_release(dh);
   3.489 +        gpg.gpgme_data_release(dh);
   3.490          return PEP_UNKNOWN_ERROR;
   3.491      };
   3.492  
   3.493 -    _size = session->gpg->gpgme_data_seek(dh, 0, SEEK_END);
   3.494 +    _size = gpg.gpgme_data_seek(dh, 0, SEEK_END);
   3.495      assert(_size != -1);
   3.496 -    session->gpg->gpgme_data_seek(dh, 0, SEEK_SET);
   3.497 +    gpg.gpgme_data_seek(dh, 0, SEEK_SET);
   3.498  
   3.499      buffer = malloc(_size + 1);
   3.500      assert(buffer);
   3.501      if (buffer == NULL) {
   3.502 -        session->gpg->gpgme_data_release(dh);
   3.503 +        gpg.gpgme_data_release(dh);
   3.504          return PEP_OUT_OF_MEMORY;
   3.505      }
   3.506  
   3.507 -    reading = session->gpg->gpgme_data_read(dh, buffer, _size);
   3.508 +    reading = gpg.gpgme_data_read(dh, buffer, _size);
   3.509      assert(_size == reading);
   3.510  
   3.511      // safeguard for the naive user
   3.512 @@ -979,7 +975,7 @@
   3.513      *key_data = buffer;
   3.514      *size = _size;
   3.515  
   3.516 -    session->gpg->gpgme_data_release(dh);
   3.517 +    gpg.gpgme_data_release(dh);
   3.518      return PEP_STATUS_OK;
   3.519  }
   3.520  
   3.521 @@ -989,12 +985,12 @@
   3.522      gpgme_error_t gpgme_error;
   3.523      gpgme_keylist_mode_t mode;
   3.524  
   3.525 -    mode = session->gpg->gpgme_get_keylist_mode(session->ctx);
   3.526 +    mode = gpg.gpgme_get_keylist_mode(session->ctx);
   3.527  
   3.528      mode &= ~remove_mode;
   3.529      mode |= add_mode;
   3.530  
   3.531 -    gpgme_error = session->gpg->gpgme_set_keylist_mode(session->ctx, mode);
   3.532 +    gpgme_error = gpg.gpgme_set_keylist_mode(session->ctx, mode);
   3.533      gpgme_error = _GPGERR(gpgme_error);
   3.534      assert(gpgme_error == GPG_ERR_NO_ERROR);
   3.535  }
   3.536 @@ -1009,7 +1005,7 @@
   3.537  
   3.538      _switch_mode(session, GPGME_KEYLIST_MODE_LOCAL, GPGME_KEYLIST_MODE_EXTERN);
   3.539  
   3.540 -    gpgme_error = session->gpg->gpgme_op_keylist_start(session->ctx, pattern, 0);
   3.541 +    gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, pattern, 0);
   3.542      gpgme_error = _GPGERR(gpgme_error);
   3.543      switch (gpgme_error) {
   3.544      case GPG_ERR_NO_ERROR:
   3.545 @@ -1024,11 +1020,11 @@
   3.546      };
   3.547  
   3.548      gpgme_ctx_t import_ctx;
   3.549 -    gpgme_error = session->gpg->gpgme_new(&import_ctx);
   3.550 +    gpgme_error = gpg.gpgme_new(&import_ctx);
   3.551      assert(gpgme_error == GPG_ERR_NO_ERROR);
   3.552  
   3.553      do {
   3.554 -        gpgme_error = session->gpg->gpgme_op_keylist_next(session->ctx, &key);
   3.555 +        gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
   3.556          gpgme_error = _GPGERR(gpgme_error);
   3.557          assert(gpgme_error != GPG_ERR_INV_VALUE);
   3.558          switch (gpgme_error) {
   3.559 @@ -1042,28 +1038,28 @@
   3.560              keys[0] = key;
   3.561              keys[1] = NULL;
   3.562  
   3.563 -            gpgme_error = session->gpg->gpgme_op_import_keys(import_ctx, keys);
   3.564 +            gpgme_error = gpg.gpgme_op_import_keys(import_ctx, keys);
   3.565              gpgme_error = _GPGERR(gpgme_error);
   3.566 -            session->gpg->gpgme_key_unref(key);
   3.567 +            gpg.gpgme_key_unref(key);
   3.568              assert(gpgme_error != GPG_ERR_INV_VALUE);
   3.569              assert(gpgme_error != GPG_ERR_CONFLICT);
   3.570          }
   3.571              break;
   3.572          case GPG_ERR_ENOMEM:
   3.573 -            session->gpg->gpgme_op_keylist_end(session->ctx);
   3.574 -            session->gpg->gpgme_release(import_ctx);
   3.575 +            gpg.gpgme_op_keylist_end(session->ctx);
   3.576 +            gpg.gpgme_release(import_ctx);
   3.577              _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
   3.578              return PEP_OUT_OF_MEMORY;
   3.579          default:
   3.580 -            session->gpg->gpgme_op_keylist_end(session->ctx);
   3.581 -            session->gpg->gpgme_release(import_ctx);
   3.582 +            gpg.gpgme_op_keylist_end(session->ctx);
   3.583 +            gpg.gpgme_release(import_ctx);
   3.584              _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
   3.585              return PEP_UNKNOWN_ERROR;
   3.586          };
   3.587      } while (gpgme_error != GPG_ERR_EOF);
   3.588  
   3.589 -    session->gpg->gpgme_op_keylist_end(session->ctx);
   3.590 -    session->gpg->gpgme_release(import_ctx);
   3.591 +    gpg.gpgme_op_keylist_end(session->ctx);
   3.592 +    gpg.gpgme_release(import_ctx);
   3.593      _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
   3.594      return PEP_STATUS_OK;
   3.595  }
   3.596 @@ -1083,7 +1079,7 @@
   3.597  
   3.598      *keylist = NULL;
   3.599  
   3.600 -    gpgme_error = session->gpg->gpgme_op_keylist_start(session->ctx, pattern, 0);
   3.601 +    gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, pattern, 0);
   3.602      gpgme_error = _GPGERR(gpgme_error);
   3.603      switch (gpgme_error) {
   3.604      case GPG_ERR_NO_ERROR:
   3.605 @@ -1092,7 +1088,7 @@
   3.606          assert(0);
   3.607          return PEP_UNKNOWN_ERROR;
   3.608      default:
   3.609 -        session->gpg->gpgme_op_keylist_end(session->ctx);
   3.610 +        gpg.gpgme_op_keylist_end(session->ctx);
   3.611          return PEP_GET_KEY_FAILED;
   3.612      };
   3.613  
   3.614 @@ -1100,7 +1096,7 @@
   3.615      stringlist_t *_k = _keylist;
   3.616  
   3.617      do {
   3.618 -        gpgme_error = session->gpg->gpgme_op_keylist_next(session->ctx, &key);
   3.619 +        gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
   3.620          gpgme_error = _GPGERR(gpgme_error);
   3.621          assert(gpgme_error != GPG_ERR_INV_VALUE);
   3.622          switch (gpgme_error) {
   3.623 @@ -1117,15 +1113,15 @@
   3.624                  break;
   3.625          case GPG_ERR_ENOMEM:
   3.626              free_stringlist(_keylist);
   3.627 -            session->gpg->gpgme_op_keylist_end(session->ctx);
   3.628 +            gpg.gpgme_op_keylist_end(session->ctx);
   3.629              return PEP_OUT_OF_MEMORY;
   3.630          default:
   3.631 -            session->gpg->gpgme_op_keylist_end(session->ctx);
   3.632 +            gpg.gpgme_op_keylist_end(session->ctx);
   3.633              return PEP_UNKNOWN_ERROR;
   3.634          };
   3.635      } while (gpgme_error != GPG_ERR_EOF);
   3.636  
   3.637 -    session->gpg->gpgme_op_keylist_end(session->ctx);
   3.638 +    gpg.gpgme_op_keylist_end(session->ctx);
   3.639      *keylist = _keylist;
   3.640      return PEP_STATUS_OK;
   3.641  }
   3.642 @@ -1137,7 +1133,7 @@
   3.643      assert(session);
   3.644      assert(pattern);
   3.645  
   3.646 -    gpgme_error = session->gpg->gpgme_op_export(session->ctx, pattern,
   3.647 +    gpgme_error = gpg.gpgme_op_export(session->ctx, pattern,
   3.648          GPGME_EXPORT_MODE_EXTERN, NULL);
   3.649      gpgme_error = _GPGERR(gpgme_error);
   3.650      assert(gpgme_error != GPG_ERR_INV_VALUE);
   3.651 @@ -1164,7 +1160,7 @@
   3.652  
   3.653      *comm_type = PEP_ct_unknown;
   3.654  
   3.655 -    gpgme_error = session->gpg->gpgme_op_keylist_start(session->ctx, fpr, 0);
   3.656 +    gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, fpr, 0);
   3.657      gpgme_error = _GPGERR(gpgme_error);
   3.658      switch (gpgme_error) {
   3.659      case GPG_ERR_NO_ERROR:
   3.660 @@ -1176,12 +1172,12 @@
   3.661          return PEP_GET_KEY_FAILED;
   3.662      };
   3.663  
   3.664 -    gpgme_error = session->gpg->gpgme_op_keylist_next(session->ctx, &key);
   3.665 +    gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
   3.666      gpgme_error = _GPGERR(gpgme_error);
   3.667      assert(gpgme_error != GPG_ERR_INV_VALUE);
   3.668  
   3.669      if (key == NULL) {
   3.670 -        session->gpg->gpgme_op_keylist_end(session->ctx);
   3.671 +        gpg.gpgme_op_keylist_end(session->ctx);
   3.672          return PEP_KEY_NOT_FOUND;
   3.673      }
   3.674  
   3.675 @@ -1195,7 +1191,7 @@
   3.676          break;
   3.677      default:
   3.678          *comm_type = PEP_ct_unknown;
   3.679 -        session->gpg->gpgme_op_keylist_end(session->ctx);
   3.680 +        gpg.gpgme_op_keylist_end(session->ctx);
   3.681          return PEP_STATUS_OK;
   3.682      }
   3.683  
   3.684 @@ -1233,15 +1229,15 @@
   3.685          }
   3.686          break;
   3.687      case GPG_ERR_ENOMEM:
   3.688 -        session->gpg->gpgme_op_keylist_end(session->ctx);
   3.689 +        gpg.gpgme_op_keylist_end(session->ctx);
   3.690          *comm_type = PEP_ct_unknown;
   3.691          return PEP_OUT_OF_MEMORY;
   3.692      default:
   3.693 -        session->gpg->gpgme_op_keylist_end(session->ctx);
   3.694 +        gpg.gpgme_op_keylist_end(session->ctx);
   3.695          return PEP_UNKNOWN_ERROR;
   3.696      };
   3.697  
   3.698 -    session->gpg->gpgme_op_keylist_end(session->ctx);
   3.699 +    gpg.gpgme_op_keylist_end(session->ctx);
   3.700  
   3.701      return status;
   3.702  }
     4.1 --- a/src/pgp_gpg.h	Tue Feb 24 02:06:11 2015 +0100
     4.2 +++ b/src/pgp_gpg.h	Tue Feb 24 02:19:11 2015 +0100
     4.3 @@ -35,9 +35,9 @@
     4.4      );
     4.5  
     4.6  PEP_STATUS pgp_get_key_rating(
     4.7 -    PEP_SESSION session,
     4.8 -    const char *fpr,
     4.9 -    PEP_comm_type *comm_type
    4.10 +        PEP_SESSION session,
    4.11 +        const char *fpr,
    4.12 +        PEP_comm_type *comm_type
    4.13      );
    4.14  
    4.15  PEP_STATUS pgp_import_key(PEP_SESSION session, const char *key_data,