merge "default" into my branch rok-mac
authorRoker <roker@pep-project.org>
Thu, 14 Jul 2016 10:23:05 +0200
branchrok-mac
changeset 874c88b2d6f23cd
parent 860 1f469b5b459a
parent 871 f0c1582416e3
child 906 8988b8816f6b
merge "default" into my branch
     1.1 --- a/src/message_api.c	Wed Jul 13 18:05:35 2016 +0200
     1.2 +++ b/src/message_api.c	Thu Jul 14 10:23:05 2016 +0200
     1.3 @@ -562,12 +562,15 @@
     1.4  
     1.5                      char *_ctext = malloc(csize);
     1.6                      assert(_ctext);
     1.7 -                    if (_ctext == NULL)
     1.8 +                    if (_ctext == NULL) {
     1.9 +                        free(filename);
    1.10                          goto enomem;
    1.11 +                    }
    1.12                      memcpy(_ctext, ctext, csize);
    1.13  
    1.14                      _d = bloblist_add(_d, _ctext, csize, "application/octet-stream",
    1.15                          filename);
    1.16 +                    free(filename);
    1.17                      if (_d == NULL)
    1.18                          goto enomem;
    1.19                  }
    1.20 @@ -751,13 +754,11 @@
    1.21  
    1.22  static char * without_double_ending(const char *filename)
    1.23  {
    1.24 -    char *ext;
    1.25 -
    1.26      assert(filename);
    1.27      if (filename == NULL)
    1.28          return NULL;
    1.29      
    1.30 -    ext = strrchr(filename, '.');
    1.31 +    char *ext = strrchr(filename, '.');
    1.32      if (ext == NULL)
    1.33          return NULL;
    1.34  
    1.35 @@ -1366,11 +1367,8 @@
    1.36                      }
    1.37                      else if (is_encrypted_attachment(_s)) {
    1.38                          stringlist_t *_keylist = NULL;
    1.39 -                        char *attctext;
    1.40 -                        size_t attcsize;
    1.41 -
    1.42 -                        attctext = _s->value;
    1.43 -                        attcsize = _s->size;
    1.44 +                        char *attctext  = _s->value;
    1.45 +                        size_t attcsize = _s->size;
    1.46  
    1.47                          free(ptext);
    1.48                          ptext = NULL;
    1.49 @@ -1387,8 +1385,8 @@
    1.50                                      goto pep_error;
    1.51                              }
    1.52                              else {
    1.53 -                                char * mime_type = "application/octet-stream";
    1.54 -                                char * filename =
    1.55 +                                static const char * const mime_type = "application/octet-stream";
    1.56 +                                char * const filename =
    1.57                                      without_double_ending(_s->filename);
    1.58                                  if (filename == NULL)
    1.59                                      goto enomem;
    1.60 @@ -1401,6 +1399,7 @@
    1.61  
    1.62                                  _m = bloblist_add(_m, _ptext, psize, mime_type,
    1.63                                      filename);
    1.64 +                                free(filename);
    1.65                                  if (_m == NULL)
    1.66                                      goto enomem;
    1.67  
    1.68 @@ -1500,7 +1499,7 @@
    1.69              // Update msg->from in case we just imported a key
    1.70              // we would need to check signature
    1.71  
    1.72 -            _update_identity_for_incoming_message(session, src);
    1.73 +            status = _update_identity_for_incoming_message(session, src);
    1.74              if(status != PEP_STATUS_OK)
    1.75                  goto pep_error;
    1.76              
     2.1 --- a/src/mime.c	Wed Jul 13 18:05:35 2016 +0200
     2.2 +++ b/src/mime.c	Thu Jul 14 10:23:05 2016 +0200
     2.3 @@ -888,10 +888,7 @@
     2.4  
     2.5  static pEp_identity *mailbox_to_identity(const struct mailimf_mailbox * mb)
     2.6  {
     2.7 -    pEp_identity *ident;
     2.8      char *username = NULL;
     2.9 -    size_t index;
    2.10 -    int r;
    2.11  
    2.12      assert(mb);
    2.13      assert(mb->mb_addr_spec);
    2.14 @@ -900,14 +897,14 @@
    2.15          return NULL;
    2.16  
    2.17      if (mb->mb_display_name) {
    2.18 -        index = 0;
    2.19 -        r = mailmime_encoded_phrase_parse("utf-8", mb->mb_display_name,
    2.20 +        size_t index = 0;
    2.21 +        const int r = mailmime_encoded_phrase_parse("utf-8", mb->mb_display_name,
    2.22                  strlen(mb->mb_display_name), &index, "utf-8", &username);
    2.23          if (r)
    2.24              goto enomem;
    2.25      }
    2.26  
    2.27 -    ident = new_identity(mb->mb_addr_spec, NULL, NULL, username);
    2.28 +    pEp_identity *ident = new_identity(mb->mb_addr_spec, NULL, NULL, username);
    2.29      if (ident == NULL)
    2.30          goto enomem;
    2.31      free(username);
    2.32 @@ -916,7 +913,6 @@
    2.33  
    2.34  enomem:
    2.35      free(username);
    2.36 -
    2.37      return NULL;
    2.38  }
    2.39  
    2.40 @@ -930,22 +926,18 @@
    2.41          const struct mailimf_address_list *mal
    2.42      )
    2.43  {
    2.44 -    identity_list *il = NULL;
    2.45 +    assert(mal);
    2.46      clist *list = mal->ad_list;
    2.47 -    struct mailimf_address * addr = NULL;
    2.48 -    clistiter *cur;
    2.49  
    2.50 -    assert(mal);
    2.51 -
    2.52 -    il = new_identity_list(NULL);
    2.53 +    identity_list *il = new_identity_list(NULL);
    2.54      if (il == NULL)
    2.55          goto enomem;
    2.56  
    2.57      identity_list *_il = il;
    2.58 -    for (cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
    2.59 +    for (clistiter *cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
    2.60          pEp_identity *ident;
    2.61  
    2.62 -        addr = clist_content(cur);
    2.63 +        struct mailimf_address *addr = clist_content(cur);
    2.64          switch(addr->ad_type) {
    2.65              case MAILIMF_ADDRESS_MAILBOX:
    2.66                  ident = mailbox_to_identity(addr->ad_data.ad_mailbox);
    2.67 @@ -958,10 +950,9 @@
    2.68  
    2.69              case MAILIMF_ADDRESS_GROUP:
    2.70                  {
    2.71 -                    clistiter *cur2;
    2.72                      struct mailimf_mailbox_list * mbl =
    2.73                              addr->ad_data.ad_group->grp_mb_list;
    2.74 -                    for (cur2 = clist_begin(mbl->mb_list); cur2 != NULL;
    2.75 +                    for (clistiter *cur2 = clist_begin(mbl->mb_list); cur2 != NULL;
    2.76                              cur2 = clist_next(cur2)) {
    2.77                          ident = mailbox_to_identity(clist_content(cur));
    2.78                          if (ident == NULL)
    2.79 @@ -983,7 +974,6 @@
    2.80  
    2.81  enomem:
    2.82      free_identity_list(il);
    2.83 -
    2.84      return NULL;
    2.85  }
    2.86  
    2.87 @@ -994,15 +984,12 @@
    2.88      if (sl == NULL)
    2.89          return NULL;
    2.90  
    2.91 -    clistiter *cur;
    2.92      stringlist_t *_sl = sl;
    2.93 -    for (cur = clist_begin(list); cur != NULL; cur = clist_next(cur)) {
    2.94 +    for (clistiter *cur = clist_begin(list); cur != NULL; cur = clist_next(cur)) {
    2.95          char *phrase = clist_content(cur);
    2.96 -        size_t index;
    2.97 -        int r;
    2.98 -
    2.99 -        index = 0;
   2.100 -        r = mailmime_encoded_phrase_parse("utf-8", phrase, strlen(phrase),
   2.101 +        size_t index = 0;
   2.102 +        
   2.103 +        const int r = mailmime_encoded_phrase_parse("utf-8", phrase, strlen(phrase),
   2.104                  &index, "utf-8", &text);
   2.105          if (r)
   2.106              goto enomem;
     3.1 --- a/src/pgp_netpgp.c	Wed Jul 13 18:05:35 2016 +0200
     3.2 +++ b/src/pgp_netpgp.c	Thu Jul 14 10:23:05 2016 +0200
     3.3 @@ -1170,8 +1170,8 @@
     3.4      } else { 
     3.5  
     3.6          *keylist = stringlist_add(*keylist, newfprstr);
     3.7 +        free(newfprstr);
     3.8          if (*keylist == NULL) {
     3.9 -            free(newfprstr);
    3.10              return PEP_OUT_OF_MEMORY;
    3.11          }
    3.12      }
    3.13 @@ -1239,18 +1239,14 @@
    3.14      result = _export_keydata(key, &buffer, &buflen);
    3.15      
    3.16      if(result == PEP_STATUS_OK){
    3.17 -        char *encoded_key;
    3.18 -        char *request;
    3.19 -        size_t encoded_key_len;
    3.20 -
    3.21 -        encoded_key = curl_escape(buffer, (int)buflen);
    3.22 +        char *encoded_key = curl_escape(buffer, (int)buflen);
    3.23          if(!encoded_key){
    3.24              result = PEP_OUT_OF_MEMORY;
    3.25              goto free_buffer;
    3.26          }
    3.27 -        encoded_key_len = strlen(encoded_key);
    3.28 +        size_t encoded_key_len = strlen(encoded_key);
    3.29  
    3.30 -        request = calloc(1, HKP_REQ_PREFIX_LEN + encoded_key_len + 1);
    3.31 +        char *request = calloc(1, HKP_REQ_PREFIX_LEN + encoded_key_len + 1);
    3.32          if(!request){
    3.33              result = PEP_OUT_OF_MEMORY;
    3.34              goto free_encoded_key;
    3.35 @@ -1261,6 +1257,7 @@
    3.36          request[HKP_REQ_PREFIX_LEN + encoded_key_len] = '\0';
    3.37  
    3.38          if(!stringlist_add(encoded_keys, request)){
    3.39 +            free(request);
    3.40              result = PEP_OUT_OF_MEMORY;
    3.41          }
    3.42  
    3.43 @@ -1280,12 +1277,8 @@
    3.44  {
    3.45      static const char *ks_cmd = HKP_SERVER "/pks/add";
    3.46  
    3.47 -    stringlist_t *encoded_keys;
    3.48 -    const stringlist_t *post;
    3.49 -
    3.50      PEP_STATUS result;
    3.51 -
    3.52 -    CURL *curl;
    3.53 +    CURL *curl = NULL;
    3.54  
    3.55      assert(session);
    3.56      assert(pattern);
    3.57 @@ -1293,7 +1286,7 @@
    3.58      if (!session || !pattern )
    3.59          return PEP_ILLEGAL_VALUE;
    3.60  
    3.61 -    encoded_keys = new_stringlist(NULL);
    3.62 +    stringlist_t *encoded_keys = new_stringlist(NULL);
    3.63      assert(encoded_keys);
    3.64      if (encoded_keys == NULL) {
    3.65          return PEP_OUT_OF_MEMORY;
    3.66 @@ -1325,7 +1318,7 @@
    3.67      if(result == PEP_STATUS_OK){
    3.68          CURLcode curlres;
    3.69  
    3.70 -        for (post = encoded_keys; post != NULL; post = post->next) {
    3.71 +        for (const stringlist_t *post = encoded_keys; post != NULL; post = post->next) {
    3.72              assert(post->value);
    3.73  
    3.74              curl_easy_setopt(curl, CURLOPT_URL, ks_cmd);
    3.75 @@ -1535,8 +1528,6 @@
    3.76          const char *reason
    3.77      )
    3.78  {
    3.79 -    pgp_key_t *pkey;
    3.80 -    pgp_key_t *skey;
    3.81      uint8_t fpr[PGP_FINGERPRINT_SIZE];
    3.82      size_t length;
    3.83      unsigned from = 0;
    3.84 @@ -1559,7 +1550,7 @@
    3.85          goto unlock_netpgp;
    3.86      }
    3.87      
    3.88 -    pkey = pgp_getkeybyfpr(
    3.89 +    pgp_key_t *pkey = pgp_getkeybyfpr(
    3.90                             netpgp.io,
    3.91                             netpgp.pubring,
    3.92                             fpr, length, &from, NULL,
    3.93 @@ -1572,7 +1563,7 @@
    3.94      }
    3.95      
    3.96      from = 0;
    3.97 -    skey = pgp_getkeybyfpr(
    3.98 +    pgp_key_t *skey = pgp_getkeybyfpr(
    3.99                             netpgp.io,
   3.100                             netpgp.secring,
   3.101                             fpr, length, &from, NULL,