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