streamline
authorVolker Birk <vb@pep-project.org>
Sun, 31 May 2015 13:22:22 +0200
changeset 301d8b44dc4b0c8
parent 300 55e8daedd030
child 302 1d1a2e776631
streamline
src/bloblist.c
src/bloblist.h
src/message_api.c
src/mime.c
src/stringlist.c
src/stringpair.c
     1.1 --- a/src/bloblist.c	Sat May 30 12:47:37 2015 +0200
     1.2 +++ b/src/bloblist.c	Sun May 31 13:22:22 2015 +0200
     1.3 @@ -38,7 +38,7 @@
     1.4              return NULL;
     1.5          }
     1.6  
     1.7 -        bloblist->data = blob;
     1.8 +        bloblist->value = blob;
     1.9          bloblist->size = size;
    1.10      }
    1.11  
    1.12 @@ -50,7 +50,7 @@
    1.13      if (bloblist) {
    1.14          if (bloblist->next)
    1.15              free_bloblist(bloblist->next);
    1.16 -        free(bloblist->data);
    1.17 +        free(bloblist->value);
    1.18          free(bloblist->mime_type);
    1.19          free(bloblist->filename);
    1.20          free(bloblist);
    1.21 @@ -68,7 +68,7 @@
    1.22      if (blob2 == NULL)
    1.23          goto enomem;
    1.24  
    1.25 -    memcpy(blob2, src->data, src->size);
    1.26 +    memcpy(blob2, src->value, src->size);
    1.27      blob2[src->size] = 0; // safeguard
    1.28  
    1.29      bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
    1.30 @@ -98,7 +98,7 @@
    1.31      if (bloblist == NULL)
    1.32          return new_bloblist(blob, size, mime_type, filename);
    1.33  
    1.34 -    if (bloblist->data == NULL) {
    1.35 +    if (bloblist->value == NULL) {
    1.36          if (mime_type) {
    1.37              bloblist->mime_type = strdup(mime_type);
    1.38              if (bloblist->mime_type == NULL) {
    1.39 @@ -124,7 +124,7 @@
    1.40          }
    1.41          blob[size] = 0; // safeguard
    1.42  
    1.43 -        bloblist->data = blob;
    1.44 +        bloblist->value = blob;
    1.45          bloblist->size = size;
    1.46  
    1.47          return bloblist;
    1.48 @@ -140,17 +140,10 @@
    1.49  
    1.50  DYNAMIC_API int bloblist_length(const bloblist_t *bloblist)
    1.51  {
    1.52 -    int len = 1;
    1.53 -    bloblist_t *_bloblist;
    1.54 +    int len = 0;
    1.55  
    1.56 -    assert(bloblist);
    1.57 -
    1.58 -    if (bloblist->data == NULL)
    1.59 -        return 0;
    1.60 -
    1.61 -    for (_bloblist = bloblist->next; _bloblist != NULL;
    1.62 -        _bloblist = _bloblist->next)
    1.63 -        len += 1;
    1.64 +    for (bloblist_t *_bl = bloblist; _bl && _bl->value; _bl = _bl->next)
    1.65 +        len++;
    1.66  
    1.67      return len;
    1.68  }
     2.1 --- a/src/bloblist.h	Sat May 30 12:47:37 2015 +0200
     2.2 +++ b/src/bloblist.h	Sun May 31 13:22:22 2015 +0200
     2.3 @@ -8,7 +8,7 @@
     2.4  
     2.5  
     2.6  typedef struct _bloblist_t {
     2.7 -    char *data;                     // blob
     2.8 +    char *value;                    // blob
     2.9      size_t size;                    // size of blob
    2.10      char *mime_type;                // UTF-8 string of MIME type of blob or
    2.11                                      // NULL if unknown
     3.1 --- a/src/message_api.c	Sat May 30 12:47:37 2015 +0200
     3.2 +++ b/src/message_api.c	Sun May 31 13:22:22 2015 +0200
     3.3 @@ -59,23 +59,23 @@
     3.4      assert(msg);
     3.5  
     3.6      bloblist_t *bl;
     3.7 -    for (bl = msg->attachments; bl && bl->data; bl = bl->next) {
     3.8 -        assert(bl && bl->data && bl->size);
     3.9 +    for (bl = msg->attachments; bl && bl->value; bl = bl->next) {
    3.10 +        assert(bl && bl->value && bl->size);
    3.11  
    3.12          if (bl->mime_type == NULL ||
    3.13                      is_mime_type(bl, "application/octet-stream")) {
    3.14              if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
    3.15                      is_fileending(bl, ".key") ||
    3.16                      string_equality(bl->filename, "key.asc"))
    3.17 -                import_key(session, bl->data, bl->size);
    3.18 +                import_key(session, bl->value, bl->size);
    3.19          }
    3.20          else if (is_mime_type(bl, "application/pgp-keys")) {
    3.21 -            import_key(session, bl->data, bl->size);
    3.22 +            import_key(session, bl->value, bl->size);
    3.23          }
    3.24          else if (is_mime_type(bl, "text/plain")) {
    3.25              if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
    3.26                      is_fileending(bl, ".key") || is_fileending(bl, ".asc"))
    3.27 -                import_key(session, bl->data, bl->size);
    3.28 +                import_key(session, bl->value, bl->size);
    3.29          }
    3.30      }
    3.31  }
    3.32 @@ -136,7 +136,7 @@
    3.33      }
    3.34      else if (msg->attachments && msg->attachments->next &&
    3.35              is_mime_type(msg->attachments, "application/pgp-encrypted") &&
    3.36 -            is_PGP_message_text(msg->attachments->next->data)
    3.37 +            is_PGP_message_text(msg->attachments->next->value)
    3.38          ) {
    3.39          msg->enc_format = PEP_enc_PGP_MIME;
    3.40          return PEP_crypt_OpenPGP;
    3.41 @@ -540,9 +540,9 @@
    3.42          bloblist_t *_s = src->attachments;
    3.43          bloblist_t *_d = dst->attachments;
    3.44  
    3.45 -        for (int n = 0; _s && _s->data; _s = _s->next) {
    3.46 +        for (int n = 0; _s && _s->value; _s = _s->next) {
    3.47              int psize = _s->size;
    3.48 -            char *ptext = _s->data;
    3.49 +            char *ptext = _s->value;
    3.50              status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
    3.51                      &csize);
    3.52              if (ctext) {
    3.53 @@ -675,7 +675,12 @@
    3.54          }
    3.55      }
    3.56  
    3.57 -    if (dest_keys_found) {
    3.58 +    if (!dest_keys_found) {
    3.59 +        free_stringlist(keys);
    3.60 +        attach_own_key(session, src);
    3.61 +        return PEP_UNENCRYPTED;
    3.62 +    }
    3.63 +    else {
    3.64          msg = clone_to_empty_message(src);
    3.65          if (msg == NULL)
    3.66              goto enomem;
    3.67 @@ -704,9 +709,6 @@
    3.68              goto pep_error;
    3.69          }
    3.70      }
    3.71 -    else {
    3.72 -        attach_own_key(session, src);
    3.73 -    }
    3.74  
    3.75      free_stringlist(keys);
    3.76  
    3.77 @@ -981,11 +983,12 @@
    3.78   
    3.79      switch (src->enc_format) {
    3.80          case PEP_enc_none:
    3.81 -            status = PEP_UNENCRYPTED;
    3.82 -            break;
    3.83 +            import_attached_keys(session, src);
    3.84 +            *color = PEP_rating_unencrypted;
    3.85 +            return PEP_UNENCRYPTED;
    3.86  
    3.87          case PEP_enc_PGP_MIME:
    3.88 -            ctext = src->attachments->next->data;
    3.89 +            ctext = src->attachments->next->value;
    3.90              csize = src->attachments->next->size;
    3.91  
    3.92              status = cryptotech[crypto].decrypt_and_verify(session, ctext,
    3.93 @@ -1052,7 +1055,7 @@
    3.94                  for (_s = src->attachments; _s; _s = _s->next) {
    3.95                      if (is_encrypted_attachment(_s)) {
    3.96                          stringlist_t *_keylist = NULL;
    3.97 -                        ctext = _s->data;
    3.98 +                        ctext = _s->value;
    3.99                          csize = _s->size;
   3.100  
   3.101                          status = decrypt_and_verify(session, ctext, csize,
     4.1 --- a/src/mime.c	Sat May 30 12:47:37 2015 +0200
     4.2 +++ b/src/mime.c	Sun May 31 13:22:22 2015 +0200
     4.3 @@ -218,7 +218,7 @@
     4.4      else
     4.5          mime_type = blob->mime_type;
     4.6  
     4.7 -    mime = get_file_part(blob->filename, mime_type, blob->data, blob->size);
     4.8 +    mime = get_file_part(blob->filename, mime_type, blob->value, blob->size);
     4.9      assert(mime);
    4.10      if (mime == NULL)
    4.11          goto enomem;
    4.12 @@ -647,7 +647,7 @@
    4.13  
    4.14          bloblist_t *_a;
    4.15          for (_a = msg->attachments; _a != NULL; _a = _a->next) {
    4.16 -            assert(_a->data);
    4.17 +            assert(_a->value);
    4.18              assert(_a->size);
    4.19  
    4.20              status = mime_attachment(_a, &submime);
    4.21 @@ -697,10 +697,10 @@
    4.22      char *plaintext;
    4.23  
    4.24      assert(msg->attachments && msg->attachments->next &&
    4.25 -            msg->attachments->next->data);
    4.26 +            msg->attachments->next->value);
    4.27  
    4.28      subject = (msg->shortmsg) ? msg->shortmsg : "pEp";
    4.29 -    plaintext = msg->attachments->next->data;
    4.30 +    plaintext = msg->attachments->next->value;
    4.31  
    4.32      mime = part_multiple_new("multipart/encrypted");
    4.33      assert(mime);
     5.1 --- a/src/stringlist.c	Sat May 30 12:47:37 2015 +0200
     5.2 +++ b/src/stringlist.c	Sun May 31 13:22:22 2015 +0200
     5.3 @@ -95,17 +95,11 @@
     5.4  
     5.5  DYNAMIC_API int stringlist_length(const stringlist_t *stringlist)
     5.6  {
     5.7 -    int len = 1;
     5.8 -    stringlist_t *_stringlist;
     5.9 +    int len = 0;
    5.10  
    5.11 -    assert(stringlist);
    5.12 -
    5.13 -    if (stringlist->value == NULL)
    5.14 -        return 0;
    5.15 -
    5.16 -    for (_stringlist=stringlist->next; _stringlist!=NULL;
    5.17 -            _stringlist=_stringlist->next)
    5.18 -        len += 1;
    5.19 +    const stringlist_t *_sl;
    5.20 +    for (_sl = stringlist; _sl && _sl->value; _sl = _sl->next)
    5.21 +        len++;
    5.22  
    5.23      return len;
    5.24  }
     6.1 --- a/src/stringpair.c	Sat May 30 12:47:37 2015 +0200
     6.2 +++ b/src/stringpair.c	Sun May 31 13:22:22 2015 +0200
     6.3 @@ -133,17 +133,11 @@
     6.4          const stringpair_list_t *stringpair_list
     6.5      )
     6.6  {
     6.7 -    int len = 1;
     6.8 -    stringpair_list_t *_stringpair_list;
     6.9 +    int len = 0;
    6.10  
    6.11 -    assert(stringpair_list);
    6.12 -
    6.13 -    if (stringpair_list->value == NULL)
    6.14 -        return 0;
    6.15 -
    6.16 -    for (_stringpair_list=stringpair_list->next; _stringpair_list!=NULL;
    6.17 -            _stringpair_list=_stringpair_list->next)
    6.18 -        len += 1;
    6.19 +    stringpair_list_t *_sl;
    6.20 +    for (_sl = stringpair_list; _sl && _sl->value; _sl = _sl->next)
    6.21 +        len++;
    6.22  
    6.23      return len;
    6.24  }