blob ownership to bloblist
authorvb
Tue, 30 Dec 2014 23:33:42 +0100
changeset 41b30cc1842d9c
parent 40 3e7aa2f67b7e
child 42 d7263ab3b539
blob ownership to bloblist
src/message_api.c
src/transport.c
src/transport.h
     1.1 --- a/src/message_api.c	Tue Dec 30 18:39:59 2014 +0100
     1.2 +++ b/src/message_api.c	Tue Dec 30 23:33:42 2014 +0100
     1.3 @@ -184,9 +184,9 @@
     1.4                      return PEP_OUT_OF_MEMORY;
     1.5                  }
     1.6                  msg->attachments = _d;
     1.7 -                for (_s = src->attachments; _s && _s->data_ref; _s = _s->next) {
     1.8 +                for (_s = src->attachments; _s && _s->data; _s = _s->next) {
     1.9                      int psize = _s->size;
    1.10 -                    ptext = _s->data_ref;
    1.11 +                    ptext = _s->data;
    1.12                      status = encrypt_and_sign(session, keys, ptext, psize,
    1.13                              &ctext, &csize);
    1.14                      if (ctext) {
     2.1 --- a/src/transport.c	Tue Dec 30 18:39:59 2014 +0100
     2.2 +++ b/src/transport.c	Tue Dec 30 23:33:42 2014 +0100
     2.3 @@ -93,8 +93,6 @@
     2.4      bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
     2.5      if (bloblist == NULL)
     2.6          return NULL;
     2.7 -    bloblist->data_ref = blob;
     2.8 -    bloblist->size = size;
     2.9      if (mime_type) {
    2.10          bloblist->mime_type = strdup(mime_type);
    2.11          if (bloblist->mime_type == NULL) {
    2.12 @@ -110,34 +108,19 @@
    2.13              return NULL;
    2.14          }
    2.15      }
    2.16 +    bloblist->data = blob;
    2.17 +    bloblist->size = size;
    2.18      return bloblist;
    2.19  }
    2.20  
    2.21 -bloblist_t *bloblist_dup(const bloblist_t *src)
    2.22 -{
    2.23 -    assert(src);
    2.24 -
    2.25 -    if (src) {
    2.26 -        bloblist_t * dst = new_bloblist(src->data_ref, src->size,
    2.27 -                src->mime_type, src->file_name);
    2.28 -        if (dst == NULL)
    2.29 -            return NULL;
    2.30 -        dst->next = bloblist_dup(src->next);
    2.31 -        return dst;
    2.32 -    }
    2.33 -    else
    2.34 -        return NULL;
    2.35 -}
    2.36 -
    2.37  void free_bloblist(bloblist_t *bloblist)
    2.38  {
    2.39      if (bloblist) {
    2.40          if (bloblist->next)
    2.41              free_bloblist(bloblist->next);
    2.42 -        if (bloblist->mime_type)
    2.43 -            free(bloblist->mime_type);
    2.44 -        if (bloblist->file_name)
    2.45 -            free(bloblist->file_name);
    2.46 +        free(bloblist->data);
    2.47 +        free(bloblist->mime_type);
    2.48 +        free(bloblist->file_name);
    2.49          free(bloblist);
    2.50      }
    2.51  }
    2.52 @@ -150,9 +133,7 @@
    2.53      if (bloblist == NULL)
    2.54          return new_bloblist(blob, size, mime_type, file_name);
    2.55  
    2.56 -    if (bloblist->data_ref == NULL) {
    2.57 -        bloblist->data_ref = blob;
    2.58 -        bloblist->size = size;
    2.59 +    if (bloblist->data == NULL) {
    2.60          if (mime_type) {
    2.61              bloblist->mime_type = strdup(mime_type);
    2.62              if (bloblist->mime_type == NULL) {
    2.63 @@ -168,6 +149,8 @@
    2.64                  return NULL;
    2.65              }
    2.66          }
    2.67 +        bloblist->data = blob;
    2.68 +        bloblist->size = size;
    2.69          return bloblist;
    2.70      }
    2.71  
     3.1 --- a/src/transport.h	Tue Dec 30 18:39:59 2014 +0100
     3.2 +++ b/src/transport.h	Tue Dec 30 23:33:42 2014 +0100
     3.3 @@ -86,7 +86,7 @@
     3.4  } PEP_msg_direction;
     3.5  
     3.6  typedef struct _bloblist_t {
     3.7 -    char *data_ref;                 // reference to blob
     3.8 +    char *data;                     // blob
     3.9      size_t size;                    // size of blob
    3.10      char *mime_type;                // UTF-8 string of MIME type of blob or
    3.11                                      // NULL if unknown
    3.12 @@ -99,7 +99,7 @@
    3.13  // new_bloblist() - allocate a new bloblist
    3.14  //
    3.15  //  parameters:
    3.16 -//      blob            pointer to blob to add to the list
    3.17 +//      blob            blob to add to the list
    3.18  //      size            size of the blob
    3.19  //      mime_type       MIME type of the blob data or NULL if unknown
    3.20  //      file_name       file name of origin of blob data or NULL if unknown
    3.21 @@ -108,39 +108,17 @@
    3.22  //      pointer to new bloblist_t or NULL if out of memory
    3.23  //
    3.24  //  caveat:
    3.25 -//      the blob isn't copied, but only a reference is handled; the blob
    3.26 -//      remains in the ownership of the caller and must not be deleted until
    3.27 -//      the bloblist is deleted first; mime_type and file_name are being
    3.28 -//      copied, the originals remain in the ownership of the caller
    3.29 +//      the ownership of the blob goes to the bloblist; mime_type and file_name
    3.30 +//      are being copied, the originals remain in the ownership of the caller
    3.31  
    3.32  bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
    3.33          const char *file_name);
    3.34  
    3.35  
    3.36 -// bloblist_dup() - duplicate bloblist (deep copy)
    3.37 -//
    3.38 -//  paramters:
    3.39 -//      src             bloblist to duplicate
    3.40 -//
    3.41 -//  return value:
    3.42 -//      new bloblist or NULL if out of memory
    3.43 -//
    3.44 -//  caveat:
    3.45 -//      the blobs referenced by the lists aren't copied, so both bloblists
    3.46 -//      reference the same blob data; mime_types and file_names are duplicated
    3.47 -//      as well, though
    3.48 -
    3.49 -bloblist_t *bloblist_dup(const bloblist_t *src);
    3.50 -
    3.51 -
    3.52  // free_bloblist() - free bloblist
    3.53  //
    3.54  //  parameters:
    3.55  //      bloblist        bloblist to free
    3.56 -//
    3.57 -//  caveat:
    3.58 -//      the blobs in the bloblist aren't freed and remain in the ownership of
    3.59 -//      the caller; all other data is being freed
    3.60  
    3.61  void free_bloblist(bloblist_t *bloblist);
    3.62  
    3.63 @@ -149,7 +127,7 @@
    3.64  //
    3.65  //  parameters:
    3.66  //      bloblist        bloblist to add to
    3.67 -//      blob            reference to a blob
    3.68 +//      blob            blob
    3.69  //      size            size of the blob
    3.70  //      mime_type       MIME type of the blob or NULL if unknown
    3.71  //      file_name       file name of the blob or NULL if unknown
    3.72 @@ -158,9 +136,8 @@
    3.73  //      pointer to the last element of bloblist or NULL if out of memory
    3.74  //
    3.75  //  caveat:
    3.76 -//      the blob isn't copied, instead a reference is added to bloblist;
    3.77 -//      mime_type and file_name are copied, the originals remain in the
    3.78 -//      ownership of the caller
    3.79 +//      the ownership of the blob goes to the bloblist; mime_type and file_name
    3.80 +//      are being copied, the originals remain in the ownership of the caller
    3.81  
    3.82  bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    3.83          const char *mime_type, const char *file_name);