src/bloblist.h
author Dirk Zimmermann <dz@pep.security>
Thu, 11 Apr 2019 10:46:46 +0200
branchIOS-1482
changeset 3505 3fe4b41696d3
parent 2462 48b526a0daac
child 3965 9a59d1fa3d09
permissions -rw-r--r--
IOS-1482 close branch
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@98
     4
#pragma once
vb@98
     5
vb@98
     6
#include "dynamic_api.h"
krista@1987
     7
#include "stringpair.h"
vb@98
     8
vb@98
     9
#ifdef __cplusplus
vb@98
    10
extern "C" {
vb@98
    11
#endif
vb@98
    12
krista@1987
    13
typedef enum {
krista@1987
    14
    PEP_CONTENT_DISP_ATTACHMENT = 0,
krista@1987
    15
    PEP_CONTENT_DISP_INLINE = 1,
krista@2010
    16
    PEP_CONTENT_DISP_OTHER = -1      // must be affirmatively set
krista@1987
    17
} content_disposition_type;
vb@98
    18
vb@98
    19
typedef struct _bloblist_t {
krista@2461
    20
    char *value;                        // blob
krista@2461
    21
    size_t size;                        // size of blob
krista@2461
    22
    char *mime_type;                    // UTF-8 string of MIME type of blob or
krista@2461
    23
                                        // NULL if unknown
krista@2461
    24
    char *filename;                     // UTF-8 string of file name of blob or
krista@2461
    25
                                        // NULL if unknown
krista@2461
    26
    content_disposition_type disposition;
krista@2461
    27
                                        // default is attachment when allocated
krista@2461
    28
                                        // (see mime.h and RFC2183)
krista@2461
    29
    struct _bloblist_t *next;           // this is a single linked list
krista@2461
    30
    void (*release_value)(char *);      // pointer to release function;
krista@2461
    31
                                        // pEp_free() if not set
vb@98
    32
} bloblist_t;
vb@98
    33
vb@98
    34
vb@98
    35
// new_bloblist() - allocate a new bloblist
vb@98
    36
//
vb@98
    37
//  parameters:
krista@1871
    38
//      blob (in)       blob to add to the list
krista@1871
    39
//      size (in)       size of the blob
krista@1871
    40
//      mime_type (in)  MIME type of the blob data or NULL if unknown
krista@1871
    41
//      filename (in)  file name of origin of blob data or NULL if unknown
vb@98
    42
//
vb@98
    43
//  return value:
vb@98
    44
//      pointer to new bloblist_t or NULL if out of memory
vb@98
    45
//
vb@98
    46
//  caveat:
vb@113
    47
//      the ownership of the blob goes to the bloblist; mime_type and filename
vb@98
    48
//      are being copied, the originals remain in the ownership of the caller
krista@2461
    49
//
krista@2461
    50
//      if blob is on a different heap then after the call release_value has to
krista@2461
    51
//      be set by the adapter; this is relevant on operating systems with
krista@2461
    52
//      multiple heaps like Microsoft Windows
vb@98
    53
vb@98
    54
DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
krista@1871
    55
        const char *filename);
vb@98
    56
vb@98
    57
vb@98
    58
// free_bloblist() - free bloblist
vb@98
    59
//
vb@98
    60
//  parameters:
vb@98
    61
//      bloblist (in)   bloblist to free
vb@98
    62
vb@98
    63
DYNAMIC_API void free_bloblist(bloblist_t *bloblist);
vb@98
    64
vb@98
    65
vb@98
    66
// bloblist_dup() - duplicate bloblist
vb@98
    67
//
vb@98
    68
//  parameters:
vb@98
    69
//      src (in)    bloblist to duplicate
vb@98
    70
//
vb@98
    71
//  return value:
vb@98
    72
//      pointer to a new bloblist_t or NULL if out of memory
vb@98
    73
//
vb@98
    74
//  caveat:
vb@98
    75
//      this is an expensive operation because all blobs are copied
vb@98
    76
vb@98
    77
DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src);
vb@98
    78
krista@2461
    79
vb@98
    80
// bloblist_add() - add reference to a blob to bloblist
vb@98
    81
//
vb@98
    82
//  parameters:
krista@1871
    83
//      bloblist (in)   bloblist to add to
krista@1871
    84
//      blob (in)       blob
krista@1871
    85
//      size (in)       size of the blob
krista@1871
    86
//      mime_type (in)  MIME type of the blob or NULL if unknown
krista@1871
    87
//      filename (in)  file name of the blob or NULL if unknown
vb@98
    88
//
vb@98
    89
//  return value:
krista@900
    90
//      pointer to the last element of bloblist or NULL if out of memory or
krista@900
    91
//      NULL passed in as blob value
vb@98
    92
//
vb@98
    93
//  caveat:
vb@113
    94
//      the ownership of the blob goes to the bloblist; mime_type and filename
krista@900
    95
//      are being copied, the originals remain in the ownership of the caller.
krista@900
    96
//      bloblist input parameter equal to NULL or with value == NULL is a valid
krista@900
    97
//      empty input list.
krista@2461
    98
//
krista@2461
    99
//      If there is release_value set in bloblist it is copied to the added
krista@2461
   100
//      leaf
vb@98
   101
vb@98
   102
DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
krista@1871
   103
        const char *mime_type, const char *filename);
vb@98
   104
vb@98
   105
vb@230
   106
// bloblist_length() - get length of bloblist
vb@230
   107
//
vb@230
   108
//  parameters:
vb@230
   109
//      bloblist (in)   bloblist struct to determine length of
vb@230
   110
//
vb@230
   111
//  return value:
vb@230
   112
//      length of bloblist in number of elements
vb@230
   113
vb@230
   114
DYNAMIC_API int bloblist_length(const bloblist_t *bloblist);
vb@230
   115
krista@2461
   116
krista@1987
   117
// set_blob_content_disposition() - set blob content disposition and parameters
krista@1987
   118
//                                  when necessary
krista@1987
   119
//
krista@1987
   120
//  parameters:
krista@1987
   121
//      blob (in)               bloblist struct to change disposition for
krista@1987
   122
//      disposition (in)        disposition type (see enum)
krista@1987
   123
krista@2011
   124
DYNAMIC_API void set_blob_disposition(bloblist_t* blob, 
krista@2461
   125
        content_disposition_type disposition);
krista@1987
   126
krista@1987
   127
vb@98
   128
#ifdef __cplusplus
vb@98
   129
}
vb@98
   130
#endif