Browse Source

blob ownership to bloblist

async_key_management
vb 8 years ago
parent
commit
5c51bfc144
3 changed files with 17 additions and 57 deletions
  1. +2
    -2
      src/message_api.c
  2. +8
    -25
      src/transport.c
  3. +7
    -30
      src/transport.h

+ 2
- 2
src/message_api.c View File

@ -184,9 +184,9 @@ PEP_STATUS encrypt_message(
return PEP_OUT_OF_MEMORY;
}
msg->attachments = _d;
for (_s = src->attachments; _s && _s->data_ref; _s = _s->next) {
for (_s = src->attachments; _s && _s->data; _s = _s->next) {
int psize = _s->size;
ptext = _s->data_ref;
ptext = _s->data;
status = encrypt_and_sign(session, keys, ptext, psize,
&ctext, &csize);
if (ctext) {


+ 8
- 25
src/transport.c View File

@ -93,8 +93,6 @@ bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
if (bloblist == NULL)
return NULL;
bloblist->data_ref = blob;
bloblist->size = size;
if (mime_type) {
bloblist->mime_type = strdup(mime_type);
if (bloblist->mime_type == NULL) {
@ -110,34 +108,19 @@ bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
return NULL;
}
}
bloblist->data = blob;
bloblist->size = size;
return bloblist;
}
bloblist_t *bloblist_dup(const bloblist_t *src)
{
assert(src);
if (src) {
bloblist_t * dst = new_bloblist(src->data_ref, src->size,
src->mime_type, src->file_name);
if (dst == NULL)
return NULL;
dst->next = bloblist_dup(src->next);
return dst;
}
else
return NULL;
}
void free_bloblist(bloblist_t *bloblist)
{
if (bloblist) {
if (bloblist->next)
free_bloblist(bloblist->next);
if (bloblist->mime_type)
free(bloblist->mime_type);
if (bloblist->file_name)
free(bloblist->file_name);
free(bloblist->data);
free(bloblist->mime_type);
free(bloblist->file_name);
free(bloblist);
}
}
@ -150,9 +133,7 @@ bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
if (bloblist == NULL)
return new_bloblist(blob, size, mime_type, file_name);
if (bloblist->data_ref == NULL) {
bloblist->data_ref = blob;
bloblist->size = size;
if (bloblist->data == NULL) {
if (mime_type) {
bloblist->mime_type = strdup(mime_type);
if (bloblist->mime_type == NULL) {
@ -168,6 +149,8 @@ bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
return NULL;
}
}
bloblist->data = blob;
bloblist->size = size;
return bloblist;
}


+ 7
- 30
src/transport.h View File

@ -86,7 +86,7 @@ typedef enum _PEP_msg_direction {
} PEP_msg_direction;
typedef struct _bloblist_t {
char *data_ref; // reference to blob
char *data; // blob
size_t size; // size of blob
char *mime_type; // UTF-8 string of MIME type of blob or
// NULL if unknown
@ -99,7 +99,7 @@ typedef struct _bloblist_t {
// new_bloblist() - allocate a new bloblist
//
// parameters:
// blob pointer to blob to add to the list
// blob blob to add to the list
// size size of the blob
// mime_type MIME type of the blob data or NULL if unknown
// file_name file name of origin of blob data or NULL if unknown
@ -108,39 +108,17 @@ typedef struct _bloblist_t {
// pointer to new bloblist_t or NULL if out of memory
//
// caveat:
// the blob isn't copied, but only a reference is handled; the blob
// remains in the ownership of the caller and must not be deleted until
// the bloblist is deleted first; mime_type and file_name are being
// copied, the originals remain in the ownership of the caller
// the ownership of the blob goes to the bloblist; mime_type and file_name
// are being copied, the originals remain in the ownership of the caller
bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
const char *file_name);
// bloblist_dup() - duplicate bloblist (deep copy)
//
// paramters:
// src bloblist to duplicate
//
// return value:
// new bloblist or NULL if out of memory
//
// caveat:
// the blobs referenced by the lists aren't copied, so both bloblists
// reference the same blob data; mime_types and file_names are duplicated
// as well, though
bloblist_t *bloblist_dup(const bloblist_t *src);
// free_bloblist() - free bloblist
//
// parameters:
// bloblist bloblist to free
//
// caveat:
// the blobs in the bloblist aren't freed and remain in the ownership of
// the caller; all other data is being freed
void free_bloblist(bloblist_t *bloblist);
@ -149,7 +127,7 @@ void free_bloblist(bloblist_t *bloblist);
//
// parameters:
// bloblist bloblist to add to
// blob reference to a blob
// blob blob
// size size of the blob
// mime_type MIME type of the blob or NULL if unknown
// file_name file name of the blob or NULL if unknown
@ -158,9 +136,8 @@ void free_bloblist(bloblist_t *bloblist);
// pointer to the last element of bloblist or NULL if out of memory
//
// caveat:
// the blob isn't copied, instead a reference is added to bloblist;
// mime_type and file_name are copied, the originals remain in the
// ownership of the caller
// the ownership of the blob goes to the bloblist; mime_type and file_name
// are being copied, the originals remain in the ownership of the caller
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
const char *mime_type, const char *file_name);


Loading…
Cancel
Save