reorga
authorvb
Wed, 11 Mar 2015 11:52:14 +0100
changeset 989e3d28932e7b
parent 97 b855132fb7e3
child 99 0dd18131a6e8
reorga
src/bloblist.c
src/bloblist.h
src/dynamic_api.h
src/identity_list.c
src/identity_list.h
src/mime.c
src/pEpEngine.c
src/pEpEngine.h
src/stringlist.c
src/stringlist.h
src/stringpair.c
src/stringpair.h
src/transport.c
src/transport.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/bloblist.c	Wed Mar 11 11:52:14 2015 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +#include <stdlib.h>
     1.5 +#include <assert.h>
     1.6 +#include <string.h>
     1.7 +
     1.8 +#include "bloblist.h"
     1.9 +
    1.10 +DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
    1.11 +        const char *file_name)
    1.12 +{
    1.13 +    bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
    1.14 +    assert(bloblist);
    1.15 +    if (bloblist == NULL)
    1.16 +        return NULL;
    1.17 +
    1.18 +    if (mime_type) {
    1.19 +        bloblist->mime_type = strdup(mime_type);
    1.20 +        if (bloblist->mime_type == NULL) {
    1.21 +            free(bloblist);
    1.22 +            return NULL;
    1.23 +        }
    1.24 +    }
    1.25 +
    1.26 +    if (file_name) {
    1.27 +        bloblist->file_name = strdup(file_name);
    1.28 +        if (bloblist->file_name == NULL) {
    1.29 +            free(bloblist->mime_type);
    1.30 +            free(bloblist);
    1.31 +            return NULL;
    1.32 +        }
    1.33 +    }
    1.34 +
    1.35 +    bloblist->data = blob;
    1.36 +    bloblist->size = size;
    1.37 +
    1.38 +    return bloblist;
    1.39 +}
    1.40 +
    1.41 +DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
    1.42 +{
    1.43 +    if (bloblist) {
    1.44 +        if (bloblist->next)
    1.45 +            free_bloblist(bloblist->next);
    1.46 +        free(bloblist->data);
    1.47 +        free(bloblist->mime_type);
    1.48 +        free(bloblist->file_name);
    1.49 +        free(bloblist);
    1.50 +    }
    1.51 +}
    1.52 +
    1.53 +DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
    1.54 +{
    1.55 +    bloblist_t *bloblist = NULL;
    1.56 +
    1.57 +    assert(src);
    1.58 +
    1.59 +    bloblist = new_bloblist(src->data, src->size, src->mime_type, src->file_name);
    1.60 +    if (bloblist == NULL)
    1.61 +        goto enomem;
    1.62 +
    1.63 +    if (src->next) {
    1.64 +        bloblist->next = bloblist_dup(src->next);
    1.65 +        if (bloblist->next == NULL)
    1.66 +            goto enomem;
    1.67 +    }
    1.68 +
    1.69 +    return bloblist;
    1.70 +
    1.71 +enomem:
    1.72 +    free_bloblist(bloblist);
    1.73 +    return NULL;
    1.74 +}
    1.75 +
    1.76 +DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    1.77 +        const char *mime_type, const char *file_name)
    1.78 +{
    1.79 +    assert(blob);
    1.80 +
    1.81 +    if (bloblist == NULL)
    1.82 +        return new_bloblist(blob, size, mime_type, file_name);
    1.83 +
    1.84 +    if (bloblist->data == NULL) {
    1.85 +        if (mime_type) {
    1.86 +            bloblist->mime_type = strdup(mime_type);
    1.87 +            if (bloblist->mime_type == NULL) {
    1.88 +                free(bloblist);
    1.89 +                return NULL;
    1.90 +            }
    1.91 +        }
    1.92 +        if (file_name) {
    1.93 +            bloblist->file_name = strdup(file_name);
    1.94 +            if (bloblist->file_name == NULL) {
    1.95 +                free(bloblist->mime_type);
    1.96 +                free(bloblist);
    1.97 +                return NULL;
    1.98 +            }
    1.99 +        }
   1.100 +        bloblist->data = blob;
   1.101 +        bloblist->size = size;
   1.102 +        return bloblist;
   1.103 +    }
   1.104 +
   1.105 +    if (bloblist->next == NULL) {
   1.106 +        bloblist->next = new_bloblist(blob, size, mime_type, file_name);
   1.107 +        return bloblist->next;
   1.108 +    }
   1.109 +
   1.110 +    return bloblist_add(bloblist->next, blob, size, mime_type, file_name);
   1.111 +}
   1.112 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/bloblist.h	Wed Mar 11 11:52:14 2015 +0100
     2.3 @@ -0,0 +1,84 @@
     2.4 +#pragma once
     2.5 +
     2.6 +#include "dynamic_api.h"
     2.7 +
     2.8 +#ifdef __cplusplus
     2.9 +extern "C" {
    2.10 +#endif
    2.11 +
    2.12 +
    2.13 +typedef struct _bloblist_t {
    2.14 +    char *data;                     // blob
    2.15 +    size_t size;                    // size of blob
    2.16 +    char *mime_type;                // UTF-8 string of MIME type of blob or
    2.17 +                                    // NULL if unknown
    2.18 +    char *file_name;                // UTF-8 string of file name of blob or
    2.19 +                                    // NULL if unknown
    2.20 +    struct _bloblist_t *next;
    2.21 +} bloblist_t;
    2.22 +
    2.23 +
    2.24 +// new_bloblist() - allocate a new bloblist
    2.25 +//
    2.26 +//  parameters:
    2.27 +//      blob (in)       blob to add to the list
    2.28 +//      size (in)       size of the blob
    2.29 +//      mime_type (in)  MIME type of the blob data or NULL if unknown
    2.30 +//      file_name (in)  file name of origin of blob data or NULL if unknown
    2.31 +//
    2.32 +//  return value:
    2.33 +//      pointer to new bloblist_t or NULL if out of memory
    2.34 +//
    2.35 +//  caveat:
    2.36 +//      the ownership of the blob goes to the bloblist; mime_type and file_name
    2.37 +//      are being copied, the originals remain in the ownership of the caller
    2.38 +
    2.39 +DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
    2.40 +        const char *file_name);
    2.41 +
    2.42 +
    2.43 +// free_bloblist() - free bloblist
    2.44 +//
    2.45 +//  parameters:
    2.46 +//      bloblist (in)   bloblist to free
    2.47 +
    2.48 +DYNAMIC_API void free_bloblist(bloblist_t *bloblist);
    2.49 +
    2.50 +
    2.51 +// bloblist_dup() - duplicate bloblist
    2.52 +//
    2.53 +//  parameters:
    2.54 +//      src (in)    bloblist to duplicate
    2.55 +//
    2.56 +//  return value:
    2.57 +//      pointer to a new bloblist_t or NULL if out of memory
    2.58 +//
    2.59 +//  caveat:
    2.60 +//      this is an expensive operation because all blobs are copied
    2.61 +
    2.62 +DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src);
    2.63 +
    2.64 +// bloblist_add() - add reference to a blob to bloblist
    2.65 +//
    2.66 +//  parameters:
    2.67 +//      bloblist (in)   bloblist to add to
    2.68 +//      blob (in)       blob
    2.69 +//      size (in)       size of the blob
    2.70 +//      mime_type (in)  MIME type of the blob or NULL if unknown
    2.71 +//      file_name (in)  file name of the blob or NULL if unknown
    2.72 +//
    2.73 +//  return value:
    2.74 +//      pointer to the last element of bloblist or NULL if out of memory
    2.75 +//
    2.76 +//  caveat:
    2.77 +//      the ownership of the blob goes to the bloblist; mime_type and file_name
    2.78 +//      are being copied, the originals remain in the ownership of the caller
    2.79 +
    2.80 +DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    2.81 +        const char *mime_type, const char *file_name);
    2.82 +
    2.83 +
    2.84 +#ifdef __cplusplus
    2.85 +}
    2.86 +#endif
    2.87 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/dynamic_api.h	Wed Mar 11 11:52:14 2015 +0100
     3.3 @@ -0,0 +1,12 @@
     3.4 +#pragma once
     3.5 +
     3.6 +#ifdef WIN32
     3.7 +#ifdef _EXPORT_PEP_ENGINE_DLL
     3.8 +#define DYNAMIC_API __declspec(dllexport)
     3.9 +#else
    3.10 +#define DYNAMIC_API __declspec(dllimport)
    3.11 +#endif
    3.12 +#else
    3.13 +#define DYNAMIC_API
    3.14 +#endif
    3.15 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/identity_list.c	Wed Mar 11 11:52:14 2015 +0100
     4.3 @@ -0,0 +1,67 @@
     4.4 +#include <stdlib.h>
     4.5 +#include <assert.h>
     4.6 +
     4.7 +#include "pEpEngine.h"
     4.8 +#include "identity_list.h"
     4.9 +
    4.10 +DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident)
    4.11 +{
    4.12 +    identity_list *id_list = calloc(1, sizeof(identity_list));
    4.13 +    assert(id_list);
    4.14 +    if (id_list == NULL)
    4.15 +        return NULL;
    4.16 +
    4.17 +    id_list->ident = ident;
    4.18 +
    4.19 +    return id_list;
    4.20 +}
    4.21 +
    4.22 +DYNAMIC_API identity_list *identity_list_dup(const identity_list *src)
    4.23 +{
    4.24 +    assert(src);
    4.25 +
    4.26 +    identity_list *id_list = new_identity_list(identity_dup(src->ident));
    4.27 +    assert(id_list);
    4.28 +    if (id_list == NULL)
    4.29 +        return NULL;
    4.30 +
    4.31 +    if (src->next) {
    4.32 +        id_list->next = identity_list_dup(src->next);
    4.33 +        if (id_list->next == NULL) {
    4.34 +            free_identity_list(id_list);
    4.35 +            return NULL;
    4.36 +        }
    4.37 +    }
    4.38 +
    4.39 +    return id_list;
    4.40 +}
    4.41 +
    4.42 +DYNAMIC_API void free_identity_list(identity_list *id_list)
    4.43 +{
    4.44 +    if (id_list) {
    4.45 +        free_identity_list(id_list->next);
    4.46 +        free_identity(id_list->ident);
    4.47 +        free(id_list);
    4.48 +    }
    4.49 +}
    4.50 +
    4.51 +DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
    4.52 +{
    4.53 +    assert(ident);
    4.54 +
    4.55 +    if (id_list == NULL)
    4.56 +        return new_identity_list(ident);
    4.57 +
    4.58 +    if (id_list->ident == NULL) {
    4.59 +        id_list->ident = ident;
    4.60 +        return id_list;
    4.61 +    }
    4.62 +    else if (id_list->next == NULL) {
    4.63 +        id_list->next = new_identity_list(ident);
    4.64 +        return id_list->next;
    4.65 +    }
    4.66 +    else {
    4.67 +        return identity_list_add(id_list->next, ident);
    4.68 +    }
    4.69 +}
    4.70 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/identity_list.h	Wed Mar 11 11:52:14 2015 +0100
     5.3 @@ -0,0 +1,73 @@
     5.4 +#pragma once
     5.5 +
     5.6 +#include "dynamic_api.h"
     5.7 +
     5.8 +#ifdef __cplusplus
     5.9 +extern "C" {
    5.10 +#endif
    5.11 +
    5.12 +
    5.13 +typedef struct _identity_list {
    5.14 +    pEp_identity *ident;
    5.15 +    struct _identity_list *next;
    5.16 +} identity_list;
    5.17 +
    5.18 +
    5.19 +// new_identity_list() - allocate a new identity list
    5.20 +//
    5.21 +//  parameters:
    5.22 +//      ident (in)          identity to move for first element
    5.23 +//
    5.24 +//  return value:
    5.25 +//      new identity_list or NULL if out of memory
    5.26 +//
    5.27 +//  caveat:
    5.28 +//      ident is being moved if the function succeeds, the caller loses
    5.29 +//      ownership
    5.30 +
    5.31 +DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident);
    5.32 +
    5.33 +
    5.34 +// identity_list_dup() - duplicate identity_list (deep copy)
    5.35 +//
    5.36 +//  parameters:
    5.37 +//      id_list (in)        identity_list to copy
    5.38 +//
    5.39 +//  return value:
    5.40 +//      new identity_list or NULL if out of memory
    5.41 +
    5.42 +DYNAMIC_API identity_list *identity_list_dup(const identity_list *src);
    5.43 +
    5.44 +
    5.45 +// free_identity_list() - free memory allocated by identity_list
    5.46 +//
    5.47 +//  parameters:
    5.48 +//      id_list (in)        identity_list to free
    5.49 +//
    5.50 +//  caveat:
    5.51 +//      this function frees all identities in the list additional to the
    5.52 +//      identity_list itself
    5.53 +
    5.54 +DYNAMIC_API void free_identity_list(identity_list *id_list);
    5.55 +
    5.56 +
    5.57 +// identity_list_add - add identity to an identity_list
    5.58 +//
    5.59 +//  parameters:
    5.60 +//      id_list (in)        identity_list to add to
    5.61 +//      ident (in)          identity being added
    5.62 +//
    5.63 +//  return value:
    5.64 +//      pointer to the last element in identity_list or NULL if out of memory
    5.65 +//
    5.66 +//  caveat:
    5.67 +//      ident is being moved, the caller loses ownership if the function is
    5.68 +//      successful
    5.69 +
    5.70 +DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
    5.71 +
    5.72 +
    5.73 +#ifdef __cplusplus
    5.74 +}
    5.75 +#endif
    5.76 +
     6.1 --- a/src/mime.c	Tue Mar 10 15:45:02 2015 +0100
     6.2 +++ b/src/mime.c	Wed Mar 11 11:52:14 2015 +0100
     6.3 @@ -547,9 +547,11 @@
     6.4          }
     6.5      }
     6.6  
     6.7 -    r = _append_optional_field(fields_list, "X-pEp-Version", PEP_VERSION);
     6.8 -    if (r)
     6.9 -        goto enomem;
    6.10 +    if (msg->opt_fields) {
    6.11 +        r = _append_optional_field(fields_list, "X-pEp-Version", PEP_VERSION);
    6.12 +        if (r)
    6.13 +            goto enomem;
    6.14 +    }
    6.15  
    6.16      fields = mailimf_fields_new(fields_list);
    6.17      assert(fields);
     7.1 --- a/src/pEpEngine.c	Tue Mar 10 15:45:02 2015 +0100
     7.2 +++ b/src/pEpEngine.c	Wed Mar 11 11:52:14 2015 +0100
     7.3 @@ -1,3 +1,4 @@
     7.4 +#include "dynamic_api.h"
     7.5  #include "pEp_internal.h"
     7.6  #include "cryptotech.h"
     7.7  #include "transport.h"
     7.8 @@ -292,109 +293,6 @@
     7.9      }
    7.10  }
    7.11  
    7.12 -stringlist_t *new_stringlist(const char *value)
    7.13 -{
    7.14 -    stringlist_t *result = (stringlist_t *) calloc(1, sizeof(stringlist_t));
    7.15 -    if (result && value) {
    7.16 -        result->value = strdup(value);
    7.17 -        assert(result->value);
    7.18 -        if (result->value == 0) {
    7.19 -            free(result);
    7.20 -            return NULL;
    7.21 -        }
    7.22 -    }
    7.23 -    return result;
    7.24 -}
    7.25 -
    7.26 -DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src)
    7.27 -{
    7.28 -    assert(src);
    7.29 -    if (src == NULL)
    7.30 -        return NULL;
    7.31 -
    7.32 -    stringlist_t *dst = new_stringlist(src->value);
    7.33 -    if (dst == NULL)
    7.34 -        return NULL;
    7.35 -
    7.36 -    if (src->next) {
    7.37 -        dst->next = stringlist_dup(src->next);
    7.38 -        if (dst->next == NULL) {
    7.39 -            free_stringlist(dst);
    7.40 -            return NULL;
    7.41 -        }
    7.42 -    }
    7.43 -
    7.44 -    return dst;
    7.45 -}
    7.46 -
    7.47 -stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value)
    7.48 -{
    7.49 -    assert(value);
    7.50 -
    7.51 -    if (stringlist == NULL)
    7.52 -        return new_stringlist(value);
    7.53 -
    7.54 -    if (stringlist->next != NULL)
    7.55 -        return stringlist_add(stringlist->next, value);
    7.56 -    if (stringlist->value == NULL) {
    7.57 -        stringlist->value = strdup(value);
    7.58 -        assert(stringlist->value);
    7.59 -        if (stringlist->value == NULL)
    7.60 -            return NULL;
    7.61 -        return stringlist;
    7.62 -    }
    7.63 -
    7.64 -    stringlist->next = new_stringlist(value);
    7.65 -    assert(stringlist->next);
    7.66 -    if (stringlist->next == NULL)
    7.67 -        return NULL;
    7.68 -
    7.69 -    return stringlist->next;
    7.70 -}
    7.71 -
    7.72 -DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
    7.73 -        stringlist_t *second)
    7.74 -{
    7.75 -    assert(stringlist);
    7.76 -
    7.77 -    if (second == NULL || second->value == NULL)
    7.78 -        return stringlist;
    7.79 -
    7.80 -    stringlist_t *_s = stringlist;
    7.81 -    stringlist_t *_s2;
    7.82 -    for (_s2 = second; _s2 != NULL; _s2 = _s2->next) {
    7.83 -        _s = stringlist_add(_s, _s2->value);
    7.84 -        if (_s == NULL)
    7.85 -            return NULL;
    7.86 -    }
    7.87 -    return _s;
    7.88 -}
    7.89 -
    7.90 -int stringlist_length(const stringlist_t *stringlist)
    7.91 -{
    7.92 -    int len = 1;
    7.93 -    stringlist_t *_stringlist;
    7.94 -
    7.95 -    assert(stringlist);
    7.96 -
    7.97 -    if (stringlist->value == NULL)
    7.98 -        return 0;
    7.99 -
   7.100 -    for (_stringlist=stringlist->next; _stringlist!=NULL; _stringlist=_stringlist->next)
   7.101 -        len += 1;
   7.102 -
   7.103 -    return len;
   7.104 -}
   7.105 -
   7.106 -void free_stringlist(stringlist_t *stringlist)
   7.107 -{
   7.108 -    if (stringlist) {
   7.109 -        free_stringlist(stringlist->next);
   7.110 -        free(stringlist->value);
   7.111 -        free(stringlist);
   7.112 -    }
   7.113 -}
   7.114 -
   7.115  DYNAMIC_API PEP_STATUS log_event(
   7.116          PEP_SESSION session, const char *title, const char *entity,
   7.117          const char *description, const char *comment
     8.1 --- a/src/pEpEngine.h	Tue Mar 10 15:45:02 2015 +0100
     8.2 +++ b/src/pEpEngine.h	Wed Mar 11 11:52:14 2015 +0100
     8.3 @@ -8,16 +8,8 @@
     8.4  #include <stdint.h>
     8.5  #include <stdbool.h>
     8.6  
     8.7 -#ifdef WIN32
     8.8 -#ifdef _EXPORT_PEP_ENGINE_DLL
     8.9 -#define DYNAMIC_API __declspec(dllexport)
    8.10 -#else
    8.11 -#define DYNAMIC_API __declspec(dllimport)
    8.12 -#endif
    8.13 -#else
    8.14 -#define DYNAMIC_API
    8.15 -#endif
    8.16 -
    8.17 +#include "dynamic_api.h"
    8.18 +#include "stringlist.h"
    8.19  
    8.20  #define PEP_VERSION "1.0"
    8.21  
    8.22 @@ -116,90 +108,6 @@
    8.23  DYNAMIC_API void release(PEP_SESSION session);
    8.24  
    8.25  
    8.26 -typedef struct _stringlist_t {
    8.27 -    char *value;
    8.28 -    struct _stringlist_t *next;
    8.29 -} stringlist_t;
    8.30 -
    8.31 -
    8.32 -// new_stringlist() - allocate a new stringlist
    8.33 -//
    8.34 -//  parameters:
    8.35 -//      value (in)        initial value as C string or NULL for empty list
    8.36 -//
    8.37 -//  return value:
    8.38 -//      pointer to stringlist_t object or NULL if out of memory
    8.39 -//
    8.40 -//  caveat:
    8.41 -//      the value is being copied before being added to the list
    8.42 -//      the original string is still being owned by the caller
    8.43 -
    8.44 -DYNAMIC_API stringlist_t *new_stringlist(const char *value);
    8.45 -
    8.46 -
    8.47 -// stringlist_dup() - duplicate a stringlist
    8.48 -//
    8.49 -//  parameters:
    8.50 -//      src (in)            stringlist to copy
    8.51 -//
    8.52 -//  return value:
    8.53 -//      pointer to stringlist_t object or NULL if out of memory
    8.54 -
    8.55 -DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
    8.56 -
    8.57 -
    8.58 -// stringlist_add() - add key to stringlist
    8.59 -//
    8.60 -//  parameters:
    8.61 -//      stringlist (in)     stringlist struct or NULL to create a new one
    8.62 -//      value (in)          value as C string
    8.63 -//
    8.64 -//  return value:
    8.65 -//      pointer to last element in stringlist or NULL if out of memory
    8.66 -//
    8.67 -//  caveat:
    8.68 -//      the value is being copied before being added to the list
    8.69 -//      the original string is still being owned by the caller
    8.70 -
    8.71 -DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value);
    8.72 -
    8.73 -
    8.74 -// stringlist_append() - append stringlist to stringlist
    8.75 -//
    8.76 -//  parameters:
    8.77 -//      stringlist (in)     stringlist struct to append to
    8.78 -//      second (in)         stringlist struct to append
    8.79 -//
    8.80 -//  return value:
    8.81 -//      pointer to last element in stringlist or NULL if out of memory
    8.82 -//
    8.83 -//  caveat:
    8.84 -//      all values are being copied before being added to the list
    8.85 -//      the original values are still being owned by the caller
    8.86 -
    8.87 -DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
    8.88 -        stringlist_t *second);
    8.89 -
    8.90 -
    8.91 -// stringlist_length() - get length of stringlist
    8.92 -//
    8.93 -//  parameters:
    8.94 -//      stringlist (in)     stringlist struct to determine length of
    8.95 -//
    8.96 -//  return value:
    8.97 -//      length of stringlist in number of elements
    8.98 -
    8.99 -DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
   8.100 -
   8.101 -
   8.102 -// free_stringlist() - free memory occupied by stringlist
   8.103 -//
   8.104 -//  parameters:
   8.105 -//      stringlist (in)    stringlist to free
   8.106 -
   8.107 -DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
   8.108 -
   8.109 -
   8.110  // decrypt_and_verify() - decrypt and/or verify a message
   8.111  //
   8.112  //	parameters:
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/stringlist.c	Wed Mar 11 11:52:14 2015 +0100
     9.3 @@ -0,0 +1,110 @@
     9.4 +#include <stdlib.h>
     9.5 +#include <string.h>
     9.6 +#include <assert.h>
     9.7 +
     9.8 +#include "stringlist.h"
     9.9 +
    9.10 +
    9.11 +DYNAMIC_API stringlist_t *new_stringlist(const char *value)
    9.12 +{
    9.13 +    stringlist_t *result = (stringlist_t *) calloc(1, sizeof(stringlist_t));
    9.14 +    if (result && value) {
    9.15 +        result->value = strdup(value);
    9.16 +        assert(result->value);
    9.17 +        if (result->value == 0) {
    9.18 +            free(result);
    9.19 +            return NULL;
    9.20 +        }
    9.21 +    }
    9.22 +    return result;
    9.23 +}
    9.24 +
    9.25 +DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src)
    9.26 +{
    9.27 +    assert(src);
    9.28 +    if (src == NULL)
    9.29 +        return NULL;
    9.30 +
    9.31 +    stringlist_t *dst = new_stringlist(src->value);
    9.32 +    if (dst == NULL)
    9.33 +        return NULL;
    9.34 +
    9.35 +    if (src->next) {
    9.36 +        dst->next = stringlist_dup(src->next);
    9.37 +        if (dst->next == NULL) {
    9.38 +            free_stringlist(dst);
    9.39 +            return NULL;
    9.40 +        }
    9.41 +    }
    9.42 +
    9.43 +    return dst;
    9.44 +}
    9.45 +
    9.46 +DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value)
    9.47 +{
    9.48 +    assert(value);
    9.49 +
    9.50 +    if (stringlist == NULL)
    9.51 +        return new_stringlist(value);
    9.52 +
    9.53 +    if (stringlist->next != NULL)
    9.54 +        return stringlist_add(stringlist->next, value);
    9.55 +    if (stringlist->value == NULL) {
    9.56 +        stringlist->value = strdup(value);
    9.57 +        assert(stringlist->value);
    9.58 +        if (stringlist->value == NULL)
    9.59 +            return NULL;
    9.60 +        return stringlist;
    9.61 +    }
    9.62 +
    9.63 +    stringlist->next = new_stringlist(value);
    9.64 +    assert(stringlist->next);
    9.65 +    if (stringlist->next == NULL)
    9.66 +        return NULL;
    9.67 +
    9.68 +    return stringlist->next;
    9.69 +}
    9.70 +
    9.71 +DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
    9.72 +        stringlist_t *second)
    9.73 +{
    9.74 +    assert(stringlist);
    9.75 +
    9.76 +    if (second == NULL || second->value == NULL)
    9.77 +        return stringlist;
    9.78 +
    9.79 +    stringlist_t *_s = stringlist;
    9.80 +    stringlist_t *_s2;
    9.81 +    for (_s2 = second; _s2 != NULL; _s2 = _s2->next) {
    9.82 +        _s = stringlist_add(_s, _s2->value);
    9.83 +        if (_s == NULL)
    9.84 +            return NULL;
    9.85 +    }
    9.86 +    return _s;
    9.87 +}
    9.88 +
    9.89 +DYNAMIC_API int stringlist_length(const stringlist_t *stringlist)
    9.90 +{
    9.91 +    int len = 1;
    9.92 +    stringlist_t *_stringlist;
    9.93 +
    9.94 +    assert(stringlist);
    9.95 +
    9.96 +    if (stringlist->value == NULL)
    9.97 +        return 0;
    9.98 +
    9.99 +    for (_stringlist=stringlist->next; _stringlist!=NULL; _stringlist=_stringlist->next)
   9.100 +        len += 1;
   9.101 +
   9.102 +    return len;
   9.103 +}
   9.104 +
   9.105 +DYNAMIC_API void free_stringlist(stringlist_t *stringlist)
   9.106 +{
   9.107 +    if (stringlist) {
   9.108 +        free_stringlist(stringlist->next);
   9.109 +        free(stringlist->value);
   9.110 +        free(stringlist);
   9.111 +    }
   9.112 +}
   9.113 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/stringlist.h	Wed Mar 11 11:52:14 2015 +0100
    10.3 @@ -0,0 +1,97 @@
    10.4 +#pragma once
    10.5 +
    10.6 +#include "dynamic_api.h"
    10.7 +
    10.8 +#ifdef __cplusplus
    10.9 +extern "C" {
   10.10 +#endif
   10.11 +
   10.12 +
   10.13 +typedef struct _stringlist_t {
   10.14 +    char *value;
   10.15 +    struct _stringlist_t *next;
   10.16 +} stringlist_t;
   10.17 +
   10.18 +
   10.19 +// new_stringlist() - allocate a new stringlist
   10.20 +//
   10.21 +//  parameters:
   10.22 +//      value (in)        initial value as C string or NULL for empty list
   10.23 +//
   10.24 +//  return value:
   10.25 +//      pointer to stringlist_t object or NULL if out of memory
   10.26 +//
   10.27 +//  caveat:
   10.28 +//      the value is being copied before being added to the list
   10.29 +//      the original string is still being owned by the caller
   10.30 +
   10.31 +DYNAMIC_API stringlist_t *new_stringlist(const char *value);
   10.32 +
   10.33 +
   10.34 +// stringlist_dup() - duplicate a stringlist
   10.35 +//
   10.36 +//  parameters:
   10.37 +//      src (in)            stringlist to copy
   10.38 +//
   10.39 +//  return value:
   10.40 +//      pointer to stringlist_t object or NULL if out of memory
   10.41 +
   10.42 +DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
   10.43 +
   10.44 +
   10.45 +// stringlist_add() - add key to stringlist
   10.46 +//
   10.47 +//  parameters:
   10.48 +//      stringlist (in)     stringlist struct or NULL to create a new one
   10.49 +//      value (in)          value as C string
   10.50 +//
   10.51 +//  return value:
   10.52 +//      pointer to last element in stringlist or NULL if out of memory
   10.53 +//
   10.54 +//  caveat:
   10.55 +//      the value is being copied before being added to the list
   10.56 +//      the original string is still being owned by the caller
   10.57 +
   10.58 +DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value);
   10.59 +
   10.60 +
   10.61 +// stringlist_append() - append stringlist to stringlist
   10.62 +//
   10.63 +//  parameters:
   10.64 +//      stringlist (in)     stringlist struct to append to
   10.65 +//      second (in)         stringlist struct to append
   10.66 +//
   10.67 +//  return value:
   10.68 +//      pointer to last element in stringlist or NULL if out of memory
   10.69 +//
   10.70 +//  caveat:
   10.71 +//      all values are being copied before being added to the list
   10.72 +//      the original values are still being owned by the caller
   10.73 +
   10.74 +DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
   10.75 +        stringlist_t *second);
   10.76 +
   10.77 +
   10.78 +// stringlist_length() - get length of stringlist
   10.79 +//
   10.80 +//  parameters:
   10.81 +//      stringlist (in)     stringlist struct to determine length of
   10.82 +//
   10.83 +//  return value:
   10.84 +//      length of stringlist in number of elements
   10.85 +
   10.86 +DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
   10.87 +
   10.88 +
   10.89 +// free_stringlist() - free memory occupied by stringlist
   10.90 +//
   10.91 +//  parameters:
   10.92 +//      stringlist (in)    stringlist to free
   10.93 +
   10.94 +DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
   10.95 +
   10.96 +
   10.97 +#ifdef __cplusplus
   10.98 +}
   10.99 +#endif
  10.100 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/stringpair.c	Wed Mar 11 11:52:14 2015 +0100
    11.3 @@ -0,0 +1,177 @@
    11.4 +#include <stdlib.h>
    11.5 +#include <assert.h>
    11.6 +#include <string.h>
    11.7 +
    11.8 +#include "stringpair.h"
    11.9 +
   11.10 +DYNAMIC_API stringpair_t * new_stringpair(const char *key, const char *value)
   11.11 +{
   11.12 +    stringpair_t *pair = NULL;
   11.13 +
   11.14 +    assert(key);
   11.15 +    assert(value),
   11.16 +
   11.17 +    pair = calloc(1, sizeof(stringpair_t));
   11.18 +    assert(pair);
   11.19 +    if (pair == NULL)
   11.20 +        goto enomem;
   11.21 +
   11.22 +    pair->key = strdup(key);
   11.23 +    assert(pair->key);
   11.24 +    if (pair->key == NULL)
   11.25 +        goto enomem;
   11.26 +
   11.27 +    pair->value = strdup(value);
   11.28 +    assert(pair->value);
   11.29 +    if (pair->value == NULL)
   11.30 +        goto enomem;
   11.31 +
   11.32 +    return pair;
   11.33 +
   11.34 +enomem:
   11.35 +    free_stringpair(pair);
   11.36 +    return NULL;
   11.37 +}
   11.38 +
   11.39 +DYNAMIC_API void free_stringpair(stringpair_t * pair)
   11.40 +{
   11.41 +    if (pair) {
   11.42 +        free(pair->key);
   11.43 +        free(pair->value);
   11.44 +        free(pair);
   11.45 +    }
   11.46 +}
   11.47 +
   11.48 +DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src)
   11.49 +{
   11.50 +    assert(src);
   11.51 +    return new_stringpair(src->key, src->value);
   11.52 +}
   11.53 +
   11.54 +DYNAMIC_API stringpair_list_t *new_stringpair_list(const stringpair_t *value)
   11.55 +{
   11.56 +    stringpair_list_t *result = (stringpair_list_t *) calloc(1,
   11.57 +            sizeof(stringpair_list_t));
   11.58 +    if (result && value) {
   11.59 +        result->value = stringpair_dup(value);
   11.60 +        if (result->value == 0) {
   11.61 +            free(result);
   11.62 +            return NULL;
   11.63 +        }
   11.64 +    }
   11.65 +    return result;
   11.66 +}
   11.67 +
   11.68 +DYNAMIC_API stringpair_list_t *stringpair_list_dup(
   11.69 +        const stringpair_list_t *src
   11.70 +    )
   11.71 +{
   11.72 +    assert(src);
   11.73 +    if (src == NULL)
   11.74 +        return NULL;
   11.75 +
   11.76 +    stringpair_list_t *dst = new_stringpair_list(src->value);
   11.77 +    if (dst == NULL)
   11.78 +        return NULL;
   11.79 +
   11.80 +    if (src->next) {
   11.81 +        dst->next = stringpair_list_dup(src->next);
   11.82 +        if (dst->next == NULL) {
   11.83 +            free_stringpair_list(dst);
   11.84 +            return NULL;
   11.85 +        }
   11.86 +    }
   11.87 +
   11.88 +    return dst;
   11.89 +}
   11.90 +
   11.91 +DYNAMIC_API stringpair_list_t *stringpair_list_add(
   11.92 +        stringpair_list_t *stringpair_list,
   11.93 +        const stringpair_t *value
   11.94 +    )
   11.95 +{
   11.96 +    assert(value);
   11.97 +
   11.98 +    if (stringpair_list == NULL)
   11.99 +        return new_stringpair_list(value);
  11.100 +
  11.101 +    if (stringpair_list->next != NULL)
  11.102 +        return stringpair_list_add(stringpair_list->next, value);
  11.103 +    if (stringpair_list->value == NULL) {
  11.104 +        stringpair_list->value = stringpair_dup(value);
  11.105 +        if (stringpair_list->value == NULL)
  11.106 +            return NULL;
  11.107 +        return stringpair_list;
  11.108 +    }
  11.109 +
  11.110 +    stringpair_list->next = new_stringpair_list(value);
  11.111 +    if (stringpair_list->next == NULL)
  11.112 +        return NULL;
  11.113 +
  11.114 +    return stringpair_list->next;
  11.115 +}
  11.116 +
  11.117 +DYNAMIC_API stringpair_list_t *stringpair_list_append(
  11.118 +        stringpair_list_t *stringpair_list,
  11.119 +        stringpair_list_t *second
  11.120 +    )
  11.121 +{
  11.122 +    assert(stringpair_list);
  11.123 +
  11.124 +    if (second == NULL || second->value == NULL)
  11.125 +        return stringpair_list;
  11.126 +
  11.127 +    stringpair_list_t *_s = stringpair_list;
  11.128 +    stringpair_list_t *_s2;
  11.129 +    for (_s2 = second; _s2 != NULL; _s2 = _s2->next) {
  11.130 +        _s = stringpair_list_add(_s, _s2->value);
  11.131 +        if (_s == NULL)
  11.132 +            return NULL;
  11.133 +    }
  11.134 +    return _s;
  11.135 +}
  11.136 +
  11.137 +DYNAMIC_API int stringpair_list_length(
  11.138 +        const stringpair_list_t *stringpair_list
  11.139 +    )
  11.140 +{
  11.141 +    int len = 1;
  11.142 +    stringpair_list_t *_stringpair_list;
  11.143 +
  11.144 +    assert(stringpair_list);
  11.145 +
  11.146 +    if (stringpair_list->value == NULL)
  11.147 +        return 0;
  11.148 +
  11.149 +    for (_stringpair_list=stringpair_list->next; _stringpair_list!=NULL;
  11.150 +            _stringpair_list=_stringpair_list->next)
  11.151 +        len += 1;
  11.152 +
  11.153 +    return len;
  11.154 +}
  11.155 +
  11.156 +DYNAMIC_API void free_stringpair_list(stringpair_list_t *stringpair_list)
  11.157 +{
  11.158 +    if (stringpair_list) {
  11.159 +        free_stringpair_list(stringpair_list->next);
  11.160 +        free_stringpair(stringpair_list->value);
  11.161 +        free(stringpair_list);
  11.162 +    }
  11.163 +}
  11.164 +
  11.165 +DYNAMIC_API stringpair_t *stringpair_list_find(
  11.166 +        stringpair_list_t *stringpair_list,
  11.167 +        const char *key
  11.168 +    )
  11.169 +{
  11.170 +    assert(key);
  11.171 +
  11.172 +    if (stringpair_list == NULL)
  11.173 +        return NULL;
  11.174 +
  11.175 +    if (strcoll(stringpair_list->value->key, key) == 0)
  11.176 +        return stringpair_list->value;
  11.177 +    else
  11.178 +        return stringpair_list_find(stringpair_list->next, key);
  11.179 +}
  11.180 +
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/stringpair.h	Wed Mar 11 11:52:14 2015 +0100
    12.3 @@ -0,0 +1,163 @@
    12.4 +#pragma once
    12.5 +
    12.6 +#include "dynamic_api.h"
    12.7 +
    12.8 +#ifdef __cplusplus
    12.9 +extern "C" {
   12.10 +#endif
   12.11 +
   12.12 +
   12.13 +typedef struct _stringpair_t {
   12.14 +    char * key;
   12.15 +    char * value;
   12.16 +} stringpair_t;
   12.17 +
   12.18 +
   12.19 +// new_stringpair() - allocate new stringpair_t
   12.20 +//
   12.21 +//  parameters:
   12.22 +//      key (in)        utf-8 string used as key
   12.23 +//      value (in)      utf-8 string containing the value
   12.24 +//
   12.25 +//  return value:
   12.26 +//      pointer to stringpair_t or NULL on failure
   12.27 +//
   12.28 +//  caveat:
   12.29 +//      key and value are copied and remain in the ownership of the caller
   12.30 +
   12.31 +DYNAMIC_API stringpair_t * new_stringpair(const char *key, const char *value);
   12.32 +
   12.33 +
   12.34 +// free_stringpair() - free memory allocated by stringpair_t
   12.35 +//
   12.36 +//  parameters:
   12.37 +//      pair (in)       pointer to stringpair_t to free
   12.38 +
   12.39 +DYNAMIC_API void free_stringpair(stringpair_t * pair);
   12.40 +
   12.41 +
   12.42 +// stringpair_dup() - duplicate stringpair_t (deep copy)
   12.43 +//
   12.44 +//  parameters:
   12.45 +//      src (in)        pointer to stringpair_t to duplicate
   12.46 +//
   12.47 +//  return value:
   12.48 +//      pointer to copy of src or NULL on failure
   12.49 +
   12.50 +DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src);
   12.51 +
   12.52 +
   12.53 +typedef struct _stringpair_list_t {
   12.54 +    stringpair_t *value;
   12.55 +    struct _stringpair_list_t *next;
   12.56 +} stringpair_list_t;
   12.57 +
   12.58 +
   12.59 +// new_stringpair_list() - allocate a new stringpair_list
   12.60 +//
   12.61 +//  parameters:
   12.62 +//      value (in)              initial value as C string or NULL for empty
   12.63 +//                              list
   12.64 +//
   12.65 +//  return value:
   12.66 +//      pointer to stringpair_list_t object or NULL if out of memory
   12.67 +//
   12.68 +//  caveat:
   12.69 +//      the value is being copied before being added to the list
   12.70 +//      the original value is still being owned by the caller
   12.71 +
   12.72 +DYNAMIC_API stringpair_list_t *new_stringpair_list(const stringpair_t *value);
   12.73 +
   12.74 +
   12.75 +// stringpair_list_dup() - duplicate a stringpair_list
   12.76 +//
   12.77 +//  parameters:
   12.78 +//      src (in)                stringpair_list to copy
   12.79 +//
   12.80 +//  return value:
   12.81 +//      pointer to stringpair_list_t object or NULL if out of memory
   12.82 +
   12.83 +DYNAMIC_API stringpair_list_t *stringpair_list_dup(
   12.84 +        const stringpair_list_t *src
   12.85 +    );
   12.86 +
   12.87 +
   12.88 +// stringpair_list_add() - add key to stringpair_list
   12.89 +//
   12.90 +//  parameters:
   12.91 +//      stringpair_list (in)    stringpair_list struct or NULL to create a new
   12.92 +//                              one
   12.93 +//      value (in)              value as C string
   12.94 +//
   12.95 +//  return value:
   12.96 +//      pointer to last element in stringpair_list or NULL if out of memory
   12.97 +//
   12.98 +//  caveat:
   12.99 +//      the value is being copied before being added to the list
  12.100 +//      the original value is still being owned by the caller
  12.101 +
  12.102 +DYNAMIC_API stringpair_list_t *stringpair_list_add(
  12.103 +        stringpair_list_t *stringpair_list,
  12.104 +        const stringpair_t *value
  12.105 +    );
  12.106 +
  12.107 +
  12.108 +// stringpair_list_append() - append stringpair_list to stringpair_list
  12.109 +//
  12.110 +//  parameters:
  12.111 +//      stringpair_list (in)    stringpair_list struct to append to
  12.112 +//      second (in)             stringpair_list struct to append
  12.113 +//
  12.114 +//  return value:
  12.115 +//      pointer to last element in stringpair_list or NULL if out of memory
  12.116 +//
  12.117 +//  caveat:
  12.118 +//      all values are being copied before being added to the list
  12.119 +//      the original values are still being owned by the caller
  12.120 +
  12.121 +DYNAMIC_API stringpair_list_t *stringpair_list_append(
  12.122 +        stringpair_list_t *stringpair_list,
  12.123 +        stringpair_list_t *second
  12.124 +    );
  12.125 +
  12.126 +
  12.127 +// stringpair_list_length() - get length of stringpair_list
  12.128 +//
  12.129 +//  parameters:
  12.130 +//      stringpair_list (in)    stringpair_list struct to determine length of
  12.131 +//
  12.132 +//  return value:
  12.133 +//      length of stringpair_list in number of elements
  12.134 +
  12.135 +DYNAMIC_API int stringpair_list_length(
  12.136 +        const stringpair_list_t *stringpair_list
  12.137 +    );
  12.138 +
  12.139 +
  12.140 +// free_stringpair_list() - free memory occupied by stringpair_list
  12.141 +//
  12.142 +//  parameters:
  12.143 +//      stringpair_list (in)    stringpair_list to free
  12.144 +
  12.145 +DYNAMIC_API void free_stringpair_list(stringpair_list_t *stringpair_list);
  12.146 +
  12.147 +
  12.148 +// stringpair_list_find() - find element in list using key
  12.149 +//
  12.150 +//  parameters:
  12.151 +//      stringpair_list (in)    list to search
  12.152 +//      key (in)                key to search for
  12.153 +//
  12.154 +//  return value:
  12.155 +//      stringpair_t if found or NULL if not
  12.156 +
  12.157 +DYNAMIC_API stringpair_t *stringpair_list_find(
  12.158 +        stringpair_list_t *stringpair_list,
  12.159 +        const char *key
  12.160 +    );
  12.161 +
  12.162 +
  12.163 +#ifdef __cplusplus
  12.164 +}
  12.165 +#endif
  12.166 +
    13.1 --- a/src/transport.c	Tue Mar 10 15:45:02 2015 +0100
    13.2 +++ b/src/transport.c	Wed Mar 11 11:52:14 2015 +0100
    13.3 @@ -23,525 +23,12 @@
    13.4      return PEP_STATUS_OK;
    13.5  }
    13.6  
    13.7 -void release_transport_system(PEP_SESSION session, bool out_last)
    13.8 +DYNAMIC_API void release_transport_system(PEP_SESSION session, bool out_last)
    13.9  {
   13.10      assert(session);
   13.11      // nothing yet
   13.12  }
   13.13  
   13.14 -DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident)
   13.15 -{
   13.16 -    identity_list *id_list = calloc(1, sizeof(identity_list));
   13.17 -    assert(id_list);
   13.18 -    if (id_list == NULL)
   13.19 -        return NULL;
   13.20 -
   13.21 -    id_list->ident = ident;
   13.22 -
   13.23 -    return id_list;
   13.24 -}
   13.25 -
   13.26 -DYNAMIC_API identity_list *identity_list_dup(const identity_list *src)
   13.27 -{
   13.28 -    assert(src);
   13.29 -
   13.30 -    identity_list *id_list = new_identity_list(identity_dup(src->ident));
   13.31 -    assert(id_list);
   13.32 -    if (id_list == NULL)
   13.33 -        return NULL;
   13.34 -
   13.35 -    if (src->next) {
   13.36 -        id_list->next = identity_list_dup(src->next);
   13.37 -        if (id_list->next == NULL) {
   13.38 -            free_identity_list(id_list);
   13.39 -            return NULL;
   13.40 -        }
   13.41 -    }
   13.42 -
   13.43 -    return id_list;
   13.44 -}
   13.45 -
   13.46 -DYNAMIC_API void free_identity_list(identity_list *id_list)
   13.47 -{
   13.48 -    if (id_list) {
   13.49 -        free_identity_list(id_list->next);
   13.50 -        free_identity(id_list->ident);
   13.51 -        free(id_list);
   13.52 -    }
   13.53 -}
   13.54 -
   13.55 -DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
   13.56 -{
   13.57 -    assert(ident);
   13.58 -
   13.59 -    if (id_list == NULL)
   13.60 -        return new_identity_list(ident);
   13.61 -
   13.62 -    if (id_list->ident == NULL) {
   13.63 -        id_list->ident = ident;
   13.64 -        return id_list;
   13.65 -    }
   13.66 -    else if (id_list->next == NULL) {
   13.67 -        id_list->next = new_identity_list(ident);
   13.68 -        return id_list->next;
   13.69 -    }
   13.70 -    else {
   13.71 -        return identity_list_add(id_list->next, ident);
   13.72 -    }
   13.73 -}
   13.74 -
   13.75 -DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
   13.76 -        const char *file_name)
   13.77 -{
   13.78 -    bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
   13.79 -    assert(bloblist);
   13.80 -    if (bloblist == NULL)
   13.81 -        return NULL;
   13.82 -
   13.83 -    if (mime_type) {
   13.84 -        bloblist->mime_type = strdup(mime_type);
   13.85 -        if (bloblist->mime_type == NULL) {
   13.86 -            free(bloblist);
   13.87 -            return NULL;
   13.88 -        }
   13.89 -    }
   13.90 -
   13.91 -    if (file_name) {
   13.92 -        bloblist->file_name = strdup(file_name);
   13.93 -        if (bloblist->file_name == NULL) {
   13.94 -            free(bloblist->mime_type);
   13.95 -            free(bloblist);
   13.96 -            return NULL;
   13.97 -        }
   13.98 -    }
   13.99 -
  13.100 -    bloblist->data = blob;
  13.101 -    bloblist->size = size;
  13.102 -
  13.103 -    return bloblist;
  13.104 -}
  13.105 -
  13.106 -DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
  13.107 -{
  13.108 -    if (bloblist) {
  13.109 -        if (bloblist->next)
  13.110 -            free_bloblist(bloblist->next);
  13.111 -        free(bloblist->data);
  13.112 -        free(bloblist->mime_type);
  13.113 -        free(bloblist->file_name);
  13.114 -        free(bloblist);
  13.115 -    }
  13.116 -}
  13.117 -
  13.118 -DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
  13.119 -{
  13.120 -    bloblist_t *bloblist = NULL;
  13.121 -
  13.122 -    assert(src);
  13.123 -
  13.124 -    bloblist = new_bloblist(src->data, src->size, src->mime_type, src->file_name);
  13.125 -    if (bloblist == NULL)
  13.126 -        goto enomem;
  13.127 -
  13.128 -    if (src->next) {
  13.129 -        bloblist->next = bloblist_dup(src->next);
  13.130 -        if (bloblist->next == NULL)
  13.131 -            goto enomem;
  13.132 -    }
  13.133 -
  13.134 -    return bloblist;
  13.135 -
  13.136 -enomem:
  13.137 -    free_bloblist(bloblist);
  13.138 -    return NULL;
  13.139 -}
  13.140 -
  13.141 -DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
  13.142 -        const char *mime_type, const char *file_name)
  13.143 -{
  13.144 -    assert(blob);
  13.145 -
  13.146 -    if (bloblist == NULL)
  13.147 -        return new_bloblist(blob, size, mime_type, file_name);
  13.148 -
  13.149 -    if (bloblist->data == NULL) {
  13.150 -        if (mime_type) {
  13.151 -            bloblist->mime_type = strdup(mime_type);
  13.152 -            if (bloblist->mime_type == NULL) {
  13.153 -                free(bloblist);
  13.154 -                return NULL;
  13.155 -            }
  13.156 -        }
  13.157 -        if (file_name) {
  13.158 -            bloblist->file_name = strdup(file_name);
  13.159 -            if (bloblist->file_name == NULL) {
  13.160 -                free(bloblist->mime_type);
  13.161 -                free(bloblist);
  13.162 -                return NULL;
  13.163 -            }
  13.164 -        }
  13.165 -        bloblist->data = blob;
  13.166 -        bloblist->size = size;
  13.167 -        return bloblist;
  13.168 -    }
  13.169 -
  13.170 -    if (bloblist->next == NULL) {
  13.171 -        bloblist->next = new_bloblist(blob, size, mime_type, file_name);
  13.172 -        return bloblist->next;
  13.173 -    }
  13.174 -
  13.175 -    return bloblist_add(bloblist->next, blob, size, mime_type, file_name);
  13.176 -}
  13.177 -
  13.178 -DYNAMIC_API stringpair_t * new_stringpair(const char *key, const char *value)
  13.179 -{
  13.180 -    stringpair_t *pair = NULL;
  13.181 -
  13.182 -    assert(key);
  13.183 -    assert(value),
  13.184 -
  13.185 -    pair = calloc(1, sizeof(stringpair_t));
  13.186 -    assert(pair);
  13.187 -    if (pair == NULL)
  13.188 -        goto enomem;
  13.189 -
  13.190 -    pair->key = strdup(key);
  13.191 -    assert(pair->key);
  13.192 -    if (pair->key == NULL)
  13.193 -        goto enomem;
  13.194 -
  13.195 -    pair->value = strdup(value);
  13.196 -    assert(pair->value);
  13.197 -    if (pair->value == NULL)
  13.198 -        goto enomem;
  13.199 -
  13.200 -    return pair;
  13.201 -
  13.202 -enomem:
  13.203 -    free_stringpair(pair);
  13.204 -    return NULL;
  13.205 -}
  13.206 -
  13.207 -DYNAMIC_API void free_stringpair(stringpair_t * pair)
  13.208 -{
  13.209 -    if (pair) {
  13.210 -        free(pair->key);
  13.211 -        free(pair->value);
  13.212 -        free(pair);
  13.213 -    }
  13.214 -}
  13.215 -
  13.216 -DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src)
  13.217 -{
  13.218 -    assert(src);
  13.219 -    return new_stringpair(src->key, src->value);
  13.220 -}
  13.221 -
  13.222 -DYNAMIC_API stringpair_map_t * new_stringpair_map(const stringpair_t *pair)
  13.223 -{
  13.224 -    stringpair_map_t *map = NULL;
  13.225 -
  13.226 -    map = calloc(1, sizeof(stringpair_map_t));
  13.227 -    assert(map);
  13.228 -    if (map == NULL)
  13.229 -        goto enomem;
  13.230 -
  13.231 -    if (pair) {
  13.232 -        map->pair = stringpair_dup(pair);
  13.233 -        if (map->pair == NULL)
  13.234 -            goto enomem;
  13.235 -    }
  13.236 -
  13.237 -    return map;
  13.238 -
  13.239 -enomem:
  13.240 -    free_stringpair_map(map);
  13.241 -    return NULL;
  13.242 -}
  13.243 -
  13.244 -DYNAMIC_API void free_stringpair_map(stringpair_map_t *map)
  13.245 -{
  13.246 -    if (map) {
  13.247 -        free_stringpair_map(map->left);
  13.248 -        free_stringpair_map(map->right);
  13.249 -        free_stringpair(map->pair);
  13.250 -        free(map);
  13.251 -    }
  13.252 -}
  13.253 -
  13.254 -static stringpair_map_t * _stringpair_map_dup(
  13.255 -        const stringpair_map_t *src,
  13.256 -        stringpair_map_t *parent
  13.257 -    )
  13.258 -{
  13.259 -    stringpair_map_t *map = NULL;   
  13.260 -
  13.261 -    assert(src);
  13.262 -
  13.263 -    map = new_stringpair_map(src->pair);
  13.264 -    if (map == NULL)
  13.265 -        goto enomem;
  13.266 -
  13.267 -    map->color = src->color;
  13.268 -
  13.269 -    if (src->left) {
  13.270 -        map->left = _stringpair_map_dup(src->left, map);
  13.271 -        if (map->left == NULL)
  13.272 -            goto enomem;
  13.273 -    }
  13.274 -
  13.275 -    if (src->right) {
  13.276 -        map->right = _stringpair_map_dup(src->right, map);
  13.277 -        if (map->right == NULL)
  13.278 -            goto enomem;
  13.279 -    }
  13.280 -
  13.281 -    map->parent_ref = parent;
  13.282 -
  13.283 -    return map;
  13.284 -
  13.285 -enomem:
  13.286 -    free_stringpair_map(map);
  13.287 -    return NULL;
  13.288 -}
  13.289 -
  13.290 -DYNAMIC_API stringpair_map_t * stringpair_map_dup(const stringpair_map_t *src)
  13.291 -{
  13.292 -    return _stringpair_map_dup(src, NULL);
  13.293 -}
  13.294 -
  13.295 -DYNAMIC_API stringpair_map_t * stringpair_map_find(
  13.296 -        stringpair_map_t *map,
  13.297 -        const char *key
  13.298 -    )
  13.299 -{
  13.300 -    int c;
  13.301 -
  13.302 -    assert(key);
  13.303 -
  13.304 -    if (map == NULL || map->pair == NULL) // empty map
  13.305 -        return NULL;
  13.306 -
  13.307 -    c = strcoll(map->pair->key, key);
  13.308 -
  13.309 -    if (c == 0)
  13.310 -        return map;
  13.311 -    else if (c < 0)
  13.312 -        return stringpair_map_find(map->left, key);
  13.313 -    else
  13.314 -        return stringpair_map_find(map->right, key);
  13.315 -}
  13.316 -
  13.317 -static stringpair_map_t * stringpair_map_grandparent(stringpair_map_t *node)
  13.318 -{
  13.319 -    assert(node);
  13.320 -
  13.321 -    if (node->parent_ref == NULL)
  13.322 -        return NULL;
  13.323 -
  13.324 -    return node->parent_ref->parent_ref;
  13.325 -}
  13.326 -
  13.327 -static stringpair_map_t * stringpair_map_uncle(stringpair_map_t *node)
  13.328 -{
  13.329 -    assert(stringpair_map_grandparent(node));
  13.330 -
  13.331 -    if (node->parent_ref == stringpair_map_grandparent(node)->left)
  13.332 -        return stringpair_map_grandparent(node)->right;
  13.333 -    else
  13.334 -        return stringpair_map_grandparent(node)->left;
  13.335 -}
  13.336 -
  13.337 -static stringpair_map_t * _stringpair_map_add(
  13.338 -        stringpair_map_t *map,
  13.339 -        stringpair_t * pair
  13.340 -    )
  13.341 -{
  13.342 -    int c;
  13.343 -
  13.344 -    assert(map);
  13.345 -    assert(pair);
  13.346 -
  13.347 -    if (map->pair == NULL) {
  13.348 -        map->pair = stringpair_dup(pair);
  13.349 -        if (map->pair == NULL)
  13.350 -            return NULL;
  13.351 -        return map;
  13.352 -    }
  13.353 -
  13.354 -    assert(map->pair->key);
  13.355 -    assert(pair->key);
  13.356 -
  13.357 -    c = strcoll(map->pair->key, pair->key);
  13.358 -    if (c == 0) {
  13.359 -        free(map->pair->value);
  13.360 -
  13.361 -        assert(pair->value);
  13.362 -
  13.363 -        map->pair->value = strdup(pair->value);
  13.364 -        assert(map->pair->value);
  13.365 -        if (map->pair->value == NULL)
  13.366 -            return NULL;
  13.367 -    }
  13.368 -    else if (c < 0) {
  13.369 -        if (map->left == NULL) {
  13.370 -            map->left = new_stringpair_map(pair);
  13.371 -            if (map->left)
  13.372 -                return NULL;
  13.373 -            map = map->left;
  13.374 -        }
  13.375 -        else {
  13.376 -            map = _stringpair_map_add(map->left, pair);
  13.377 -        }
  13.378 -    }
  13.379 -    else {
  13.380 -        if (map->right == NULL) {
  13.381 -            map->right = new_stringpair_map(pair);
  13.382 -            if (map->right)
  13.383 -                return NULL;
  13.384 -            map = map->right;
  13.385 -        }
  13.386 -        else {
  13.387 -            map = _stringpair_map_add(map->right, pair);
  13.388 -        }
  13.389 -    }
  13.390 -
  13.391 -    return map;
  13.392 -}
  13.393 -
  13.394 -static void stringpair_map_rotate_left(stringpair_map_t *l)
  13.395 -{
  13.396 -    stringpair_map_t * _parent;
  13.397 -    stringpair_map_t * _r;
  13.398 -
  13.399 -    assert(l);
  13.400 -    assert(l->parent_ref);
  13.401 -    assert(l->right);
  13.402 -
  13.403 -    _parent = l->parent_ref;
  13.404 -    _r = l->right;
  13.405 -
  13.406 -    l->right = _r->left;
  13.407 -    _r->left = l;
  13.408 -
  13.409 -    if (_parent->left == l)
  13.410 -        _parent->left = _r;
  13.411 -    else
  13.412 -        _parent->right = _r;
  13.413 -}
  13.414 -
  13.415 -static void stringpair_map_rotate_right(stringpair_map_t *r)
  13.416 -{
  13.417 -    stringpair_map_t * _parent;
  13.418 -    stringpair_map_t * _l;
  13.419 -
  13.420 -    assert(r);
  13.421 -    assert(r->parent_ref);
  13.422 -    assert(r->left);
  13.423 -
  13.424 -    _parent = r->parent_ref;
  13.425 -    _l = r->left;
  13.426 -
  13.427 -    r->left = _l->right;
  13.428 -    _l->right = r;
  13.429 -
  13.430 -    if (_parent->left == r)
  13.431 -        _parent->left = _l;
  13.432 -    else
  13.433 -        _parent->right = _l;
  13.434 -}
  13.435 -
  13.436 -static void stringpair_map_case5(stringpair_map_t *map)
  13.437 -{
  13.438 -    map->parent_ref->color = rbt_black;
  13.439 -    stringpair_map_grandparent(map)->color = rbt_red;
  13.440 -
  13.441 -    if (map == map->parent_ref->left &&
  13.442 -            map->parent_ref == stringpair_map_grandparent(map)->left) {
  13.443 -        stringpair_map_rotate_right(stringpair_map_grandparent(map));
  13.444 -    }
  13.445 -    else {
  13.446 -        assert(map == map->parent_ref->right &&
  13.447 -                map->parent_ref == stringpair_map_grandparent(map)->right);
  13.448 -        stringpair_map_rotate_left(stringpair_map_grandparent(map));
  13.449 -    }
  13.450 -}
  13.451 -
  13.452 -static void stringpair_map_case4(stringpair_map_t *map)
  13.453 -{
  13.454 -    if (map == map->parent_ref->right &&
  13.455 -            map->parent_ref == stringpair_map_grandparent(map)->left) {
  13.456 -        stringpair_map_rotate_left(map->parent_ref);
  13.457 -        map = map->left;
  13.458 -    }
  13.459 -    else if (map == map->parent_ref->left &&
  13.460 -            map->parent_ref == stringpair_map_grandparent(map)->right) {
  13.461 -        stringpair_map_rotate_right(map->parent_ref);
  13.462 -        map = map->right;
  13.463 -    }
  13.464 -
  13.465 -    stringpair_map_case5(map);
  13.466 -}
  13.467 -
  13.468 -static void stringpair_map_case1(stringpair_map_t *map);
  13.469 -
  13.470 -static void stringpair_map_case3(stringpair_map_t *map)
  13.471 -{
  13.472 -    if (stringpair_map_uncle(map) != NULL &&
  13.473 -            stringpair_map_uncle(map)->color == rbt_red) {
  13.474 -        map->parent_ref->color = rbt_black;
  13.475 -        stringpair_map_uncle(map)->color = rbt_black;
  13.476 -        stringpair_map_grandparent(map)->color = rbt_red;
  13.477 -
  13.478 -        stringpair_map_case1(stringpair_map_grandparent(map));
  13.479 -    }
  13.480 -    else {
  13.481 -        stringpair_map_case4(map);
  13.482 -    }
  13.483 -}
  13.484 -
  13.485 -static void stringpair_map_case2(stringpair_map_t *map)
  13.486 -{
  13.487 -    if (map->parent_ref->color == rbt_black)
  13.488 -        return;
  13.489 -    else
  13.490 -        stringpair_map_case3(map);
  13.491 -}
  13.492 -
  13.493 -static void stringpair_map_case1(stringpair_map_t *map)
  13.494 -{
  13.495 -    assert(map);
  13.496 -
  13.497 -    if (map->parent_ref == NULL)
  13.498 -        map->color = rbt_black;
  13.499 -    else
  13.500 -        stringpair_map_case2(map);
  13.501 -}
  13.502 -
  13.503 -static void stringpair_map_repair(stringpair_map_t *map)
  13.504 -{
  13.505 -    stringpair_map_case1(map);
  13.506 -}
  13.507 -
  13.508 -DYNAMIC_API stringpair_map_t * stringpair_map_add(
  13.509 -        stringpair_map_t *map,
  13.510 -        stringpair_t * pair
  13.511 -    )
  13.512 -{
  13.513 -    stringpair_map_t * _map = NULL;
  13.514 -
  13.515 -    assert(map);
  13.516 -    assert(pair);
  13.517 -
  13.518 -    _map = _stringpair_map_add(map, pair);
  13.519 -    if (_map == NULL)
  13.520 -        return NULL;
  13.521 -
  13.522 -    stringpair_map_repair(_map);
  13.523 -
  13.524 -    return _map;
  13.525 -}
  13.526 -
  13.527  DYNAMIC_API message *new_message(
  13.528          PEP_msg_direction dir,
  13.529          pEp_identity *from,
  13.530 @@ -571,7 +58,7 @@
  13.531      version.key = "X-pEp-Version";
  13.532      version.value = PEP_VERSION;
  13.533  
  13.534 -    msg->opt_fields = new_stringpair_map(&version);
  13.535 +    msg->opt_fields = new_stringpair_list(&version);
  13.536      if (msg->opt_fields == NULL) {
  13.537          free_message(msg);
  13.538          return NULL;
  13.539 @@ -600,7 +87,7 @@
  13.540          free_stringlist(msg->references);
  13.541          free_stringlist(msg->keywords);
  13.542          free(msg->comments);
  13.543 -        free_stringpair_map(msg->opt_fields);
  13.544 +        free_stringpair_list(msg->opt_fields);
  13.545          free(msg);
  13.546      }
  13.547  }
  13.548 @@ -728,7 +215,7 @@
  13.549      }
  13.550  
  13.551      if (src->opt_fields) {
  13.552 -        msg->opt_fields = stringpair_map_dup(src->opt_fields);
  13.553 +        msg->opt_fields = stringpair_list_dup(src->opt_fields);
  13.554          if (msg->opt_fields == NULL)
  13.555              goto enomem;
  13.556      }
    14.1 --- a/src/transport.h	Tue Mar 10 15:45:02 2015 +0100
    14.2 +++ b/src/transport.h	Wed Mar 11 11:52:14 2015 +0100
    14.3 @@ -2,6 +2,9 @@
    14.4  
    14.5  #include <time.h>
    14.6  #include "pEpEngine.h"
    14.7 +#include "identity_list.h"
    14.8 +#include "bloblist.h"
    14.9 +#include "stringpair.h"
   14.10  
   14.11  #ifdef __cplusplus
   14.12  extern "C" {
   14.13 @@ -22,66 +25,6 @@
   14.14  
   14.15  typedef struct _PEP_transport_t PEP_transport_t;
   14.16  
   14.17 -
   14.18 -typedef struct _identity_list {
   14.19 -    pEp_identity *ident;
   14.20 -    struct _identity_list *next;
   14.21 -} identity_list;
   14.22 -
   14.23 -
   14.24 -// new_identity_list() - allocate a new identity list
   14.25 -//
   14.26 -//  parameters:
   14.27 -//      ident (in)          identity to move for first element
   14.28 -//
   14.29 -//  return value:
   14.30 -//      new identity_list or NULL if out of memory
   14.31 -//
   14.32 -//  caveat:
   14.33 -//      ident is being moved if the function succeeds, the caller loses
   14.34 -//      ownership
   14.35 -
   14.36 -DYNAMIC_API identity_list *new_identity_list(pEp_identity *ident);
   14.37 -
   14.38 -
   14.39 -// identity_list_dup() - duplicate identity_list (deep copy)
   14.40 -//
   14.41 -//  parameters:
   14.42 -//      id_list (in)        identity_list to copy
   14.43 -//
   14.44 -//  return value:
   14.45 -//      new identity_list or NULL if out of memory
   14.46 -
   14.47 -DYNAMIC_API identity_list *identity_list_dup(const identity_list *src);
   14.48 -
   14.49 -
   14.50 -// free_identity_list() - free memory allocated by identity_list
   14.51 -//
   14.52 -//  parameters:
   14.53 -//      id_list (in)        identity_list to free
   14.54 -//
   14.55 -//  caveat:
   14.56 -//      this function frees all identities in the list additional to the
   14.57 -//      identity_list itself
   14.58 -
   14.59 -DYNAMIC_API void free_identity_list(identity_list *id_list);
   14.60 -
   14.61 -
   14.62 -// identity_list_add - add identity to an identity_list
   14.63 -//
   14.64 -//  parameters:
   14.65 -//      id_list (in)        identity_list to add to
   14.66 -//      ident (in)          identity being added
   14.67 -//
   14.68 -//  return value:
   14.69 -//      pointer to the last element in identity_list or NULL if out of memory
   14.70 -//
   14.71 -//  caveat:
   14.72 -//      ident is being moved, the caller loses ownership if the function is
   14.73 -//      successful
   14.74 -
   14.75 -DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
   14.76 -
   14.77  typedef enum _PEP_text_format {
   14.78      PEP_text_format_plain = 0,
   14.79      PEP_text_format_html,
   14.80 @@ -93,202 +36,6 @@
   14.81      PEP_dir_outgoing
   14.82  } PEP_msg_direction;
   14.83  
   14.84 -typedef struct _bloblist_t {
   14.85 -    char *data;                     // blob
   14.86 -    size_t size;                    // size of blob
   14.87 -    char *mime_type;                // UTF-8 string of MIME type of blob or
   14.88 -                                    // NULL if unknown
   14.89 -    char *file_name;                // UTF-8 string of file name of blob or
   14.90 -                                    // NULL if unknown
   14.91 -    struct _bloblist_t *next;
   14.92 -} bloblist_t;
   14.93 -
   14.94 -
   14.95 -// new_bloblist() - allocate a new bloblist
   14.96 -//
   14.97 -//  parameters:
   14.98 -//      blob (in)       blob to add to the list
   14.99 -//      size (in)       size of the blob
  14.100 -//      mime_type (in)  MIME type of the blob data or NULL if unknown
  14.101 -//      file_name (in)  file name of origin of blob data or NULL if unknown
  14.102 -//
  14.103 -//  return value:
  14.104 -//      pointer to new bloblist_t or NULL if out of memory
  14.105 -//
  14.106 -//  caveat:
  14.107 -//      the ownership of the blob goes to the bloblist; mime_type and file_name
  14.108 -//      are being copied, the originals remain in the ownership of the caller
  14.109 -
  14.110 -DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
  14.111 -        const char *file_name);
  14.112 -
  14.113 -
  14.114 -// free_bloblist() - free bloblist
  14.115 -//
  14.116 -//  parameters:
  14.117 -//      bloblist (in)   bloblist to free
  14.118 -
  14.119 -DYNAMIC_API void free_bloblist(bloblist_t *bloblist);
  14.120 -
  14.121 -
  14.122 -// bloblist_dup() - duplicate bloblist
  14.123 -//
  14.124 -//  parameters:
  14.125 -//      src (in)    bloblist to duplicate
  14.126 -//
  14.127 -//  return value:
  14.128 -//      pointer to a new bloblist_t or NULL if out of memory
  14.129 -//
  14.130 -//  caveat:
  14.131 -//      this is an expensive operation because all blobs are copied
  14.132 -
  14.133 -DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src);
  14.134 -
  14.135 -// bloblist_add() - add reference to a blob to bloblist
  14.136 -//
  14.137 -//  parameters:
  14.138 -//      bloblist (in)   bloblist to add to
  14.139 -//      blob (in)       blob
  14.140 -//      size (in)       size of the blob
  14.141 -//      mime_type (in)  MIME type of the blob or NULL if unknown
  14.142 -//      file_name (in)  file name of the blob or NULL if unknown
  14.143 -//
  14.144 -//  return value:
  14.145 -//      pointer to the last element of bloblist or NULL if out of memory
  14.146 -//
  14.147 -//  caveat:
  14.148 -//      the ownership of the blob goes to the bloblist; mime_type and file_name
  14.149 -//      are being copied, the originals remain in the ownership of the caller
  14.150 -
  14.151 -DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
  14.152 -        const char *mime_type, const char *file_name);
  14.153 -
  14.154 -
  14.155 -typedef struct _stringpair_t {
  14.156 -    char * key;
  14.157 -    char * value;
  14.158 -} stringpair_t;
  14.159 -
  14.160 -
  14.161 -// new_stringpair() - allocate new stringpair_t
  14.162 -//
  14.163 -//  parameters:
  14.164 -//      key (in)        utf-8 string used as key
  14.165 -//      value (in)      utf-8 string containing the value
  14.166 -//
  14.167 -//  return value:
  14.168 -//      pointer to stringpair_t or NULL on failure
  14.169 -//
  14.170 -//  caveat:
  14.171 -//      key and value are copied and remain in the ownership of the caller
  14.172 -
  14.173 -DYNAMIC_API stringpair_t * new_stringpair(const char *key, const char *value);
  14.174 -
  14.175 -
  14.176 -// free_stringpair() - free memory allocated by stringpair_t
  14.177 -//
  14.178 -//  parameters:
  14.179 -//      pair (in)       pointer to stringpair_t to free
  14.180 -
  14.181 -DYNAMIC_API void free_stringpair(stringpair_t * pair);
  14.182 -
  14.183 -
  14.184 -// stringpair_dup() - duplicate stringpair_t (deep copy)
  14.185 -//
  14.186 -//  parameters:
  14.187 -//      src (in)        pointer to stringpair_t to duplicate
  14.188 -//
  14.189 -//  return value:
  14.190 -//      pointer to copy of src or NULL on failure
  14.191 -
  14.192 -DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src);
  14.193 -
  14.194 -
  14.195 -typedef enum _rbt_color_t {
  14.196 -    rbt_red = 0,
  14.197 -    rbt_black
  14.198 -} rbt_color_t;
  14.199 -
  14.200 -// stringpair_map_t is implemented as red-black-tree
  14.201 -
  14.202 -typedef struct _stringpair_map_t {
  14.203 -    rbt_color_t color;
  14.204 -    struct _stringpair_map_t *parent_ref;
  14.205 -    struct _stringpair_map_t *left;
  14.206 -    struct _stringpair_map_t *right;
  14.207 -
  14.208 -    stringpair_t *pair;
  14.209 -} stringpair_map_t;
  14.210 -
  14.211 -
  14.212 -// new_stringpair_map() - allocate root node of new stringpair_map_t
  14.213 -//
  14.214 -//  parameters:
  14.215 -//      pair (in)       optional pointer to pair for root node or NULL
  14.216 -//
  14.217 -//  return value:
  14.218 -//      pointer to rood node of new stringpair_map_t or NULL on failure
  14.219 -//
  14.220 -//  caveat:
  14.221 -//      if a pair is given it is being copied; the original remains in the
  14.222 -//      ownership of the caller
  14.223 -
  14.224 -DYNAMIC_API stringpair_map_t * new_stringpair_map(const stringpair_t *pair);
  14.225 -
  14.226 -
  14.227 -// free_stringpair_map() - free memory allocated by stringpair_map_t
  14.228 -//
  14.229 -//  parameters:
  14.230 -//      map (in)        pointer to stringpair_map_t to release
  14.231 -
  14.232 -DYNAMIC_API void free_stringpair_map(stringpair_map_t *map);
  14.233 -
  14.234 -
  14.235 -// stringpair_map_dup() - duplicate stringpair_map_t (deep copy)
  14.236 -//
  14.237 -//  parameters:
  14.238 -//      src (in)        pointer to stringpair_map_t to duplicate
  14.239 -//
  14.240 -//  return value:
  14.241 -//      pointer to copy of src of NULL on failure
  14.242 -
  14.243 -DYNAMIC_API stringpair_map_t * stringpair_map_dup(const stringpair_map_t *src);
  14.244 -
  14.245 -
  14.246 -// stringpair_map_find() - find node with key
  14.247 -//
  14.248 -//  parameters:
  14.249 -//      map (in)        pointer to map to search
  14.250 -//      key (in)        pointer to key to search for
  14.251 -//
  14.252 -//  return value:
  14.253 -//      pointer to node with result or NULL if not found
  14.254 -
  14.255 -DYNAMIC_API stringpair_map_t * stringpair_map_find(
  14.256 -        stringpair_map_t *map,
  14.257 -        const char *key
  14.258 -    );
  14.259 -
  14.260 -
  14.261 -// stringpair_map_add() - add stringpair_t to map
  14.262 -//
  14.263 -//  parameters:
  14.264 -//      map (in)        pointer to map to add to
  14.265 -//      pair (in)       pointer to pair to add
  14.266 -//
  14.267 -//  return value:
  14.268 -//      pointer to node with added value
  14.269 -//
  14.270 -//  caveat:
  14.271 -//      a copy of pair is added to the map; the original pair remains in the
  14.272 -//      ownership of the caller
  14.273 -
  14.274 -DYNAMIC_API stringpair_map_t * stringpair_map_add(
  14.275 -        stringpair_map_t *map,
  14.276 -        stringpair_t * pair
  14.277 -    );
  14.278 -
  14.279 -
  14.280  typedef enum _PEP_enc_format {
  14.281      PEP_enc_none = 0,                       // message is in pieces and nor
  14.282                                              // encoded nor encrypted
  14.283 @@ -332,7 +79,7 @@
  14.284                                              // refered
  14.285      stringlist_t *keywords;                 // list of UTF-8 strings with keywords
  14.286      char *comments;                         // UTF-8 string with comments
  14.287 -    stringpair_map_t *opt_fields;           // optional fields
  14.288 +    stringpair_list_t *opt_fields;          // optional fields
  14.289      PEP_enc_format enc_format;              // format of encrypted data
  14.290  } message;
  14.291