src/bloblist.h
author Krista Bennett <krista@pep-project.org>
Tue, 22 Aug 2017 14:41:11 +0200
branchENGINE-233
changeset 1987 313073d93cd9
parent 1984 06e6c0f1d8fc
child 2010 26671a7b16cb
permissions -rw-r--r--
ENGINE-233: passes tests
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@1987
    16
    PEP_CONTENT_DISP_EXTENSION = 2,
krista@1987
    17
    PEP_CONTENT_DISP_NONE = -1      // must be affirmatively set
krista@1987
    18
} content_disposition_type;
vb@98
    19
vb@98
    20
typedef struct _bloblist_t {
vb@301
    21
    char *value;                    // blob
vb@98
    22
    size_t size;                    // size of blob
vb@98
    23
    char *mime_type;                // UTF-8 string of MIME type of blob or
vb@98
    24
                                    // NULL if unknown
vb@113
    25
    char *filename;                // UTF-8 string of file name of blob or
vb@98
    26
                                    // NULL if unknown
krista@1984
    27
    content_disposition_type disposition; // default is attachment when allocated
krista@1984
    28
                                          // (see mime.h and RFC2183)
krista@1984
    29
    char* disposition_extention_type;     // NULL unless the disposition type is
krista@1984
    30
                                          // PEP_CONTENT_DISP_EXTENSION - then this
krista@1984
    31
                                          // is the type name
krista@1984
    32
    stringpair_list_t* disposition_parms;  // default: NULL (see RFC2183))
vb@98
    33
    struct _bloblist_t *next;
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
vb@98
    51
vb@98
    52
DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
krista@1871
    53
        const char *filename);
vb@98
    54
vb@98
    55
vb@98
    56
// free_bloblist() - free bloblist
vb@98
    57
//
vb@98
    58
//  parameters:
vb@98
    59
//      bloblist (in)   bloblist to free
vb@98
    60
vb@98
    61
DYNAMIC_API void free_bloblist(bloblist_t *bloblist);
vb@98
    62
vb@98
    63
vb@98
    64
// bloblist_dup() - duplicate bloblist
vb@98
    65
//
vb@98
    66
//  parameters:
vb@98
    67
//      src (in)    bloblist to duplicate
vb@98
    68
//
vb@98
    69
//  return value:
vb@98
    70
//      pointer to a new bloblist_t or NULL if out of memory
vb@98
    71
//
vb@98
    72
//  caveat:
vb@98
    73
//      this is an expensive operation because all blobs are copied
vb@98
    74
vb@98
    75
DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src);
vb@98
    76
vb@98
    77
// bloblist_add() - add reference to a blob to bloblist
vb@98
    78
//
vb@98
    79
//  parameters:
krista@1871
    80
//      bloblist (in)   bloblist to add to
krista@1871
    81
//      blob (in)       blob
krista@1871
    82
//      size (in)       size of the blob
krista@1871
    83
//      mime_type (in)  MIME type of the blob or NULL if unknown
krista@1871
    84
//      filename (in)  file name of the blob or NULL if unknown
vb@98
    85
//
vb@98
    86
//  return value:
krista@900
    87
//      pointer to the last element of bloblist or NULL if out of memory or
krista@900
    88
//      NULL passed in as blob value
vb@98
    89
//
vb@98
    90
//  caveat:
vb@113
    91
//      the ownership of the blob goes to the bloblist; mime_type and filename
krista@900
    92
//      are being copied, the originals remain in the ownership of the caller.
krista@900
    93
//      bloblist input parameter equal to NULL or with value == NULL is a valid
krista@900
    94
//      empty input list.
vb@98
    95
vb@98
    96
DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
krista@1871
    97
        const char *mime_type, const char *filename);
vb@98
    98
vb@98
    99
vb@230
   100
// bloblist_length() - get length of bloblist
vb@230
   101
//
vb@230
   102
//  parameters:
vb@230
   103
//      bloblist (in)   bloblist struct to determine length of
vb@230
   104
//
vb@230
   105
//  return value:
vb@230
   106
//      length of bloblist in number of elements
vb@230
   107
vb@230
   108
DYNAMIC_API int bloblist_length(const bloblist_t *bloblist);
vb@230
   109
krista@1987
   110
// set_blob_content_disposition() - set blob content disposition and parameters
krista@1987
   111
//                                  when necessary
krista@1987
   112
//
krista@1987
   113
//  parameters:
krista@1987
   114
//      blob (in)               bloblist struct to change disposition for
krista@1987
   115
//      disposition (in)        disposition type (see enum)
krista@1987
   116
//      extension_typename      if disposition type is an extension type,
krista@1987
   117
//                              the name for the type goes here, NULL otherwise
krista@1987
   118
//                              OWNERSHIP GOES TO BLOBLIST
krista@1987
   119
//      dispo_params(in)        type/value pairs for disposition parameters,
krista@1987
   120
//                              if any exist, otherwise NULL.
krista@1987
   121
//                              OWNERSHIP GOES TO BLOBLIST
krista@1987
   122
krista@1987
   123
DYNAMIC_API void set_blob_content_disposition(bloblist_t* blob, 
krista@1987
   124
                                              content_disposition_type disposition,
krista@1987
   125
                                              char* extension_typename,
krista@1987
   126
                                              stringpair_list_t* dispo_params);
krista@1987
   127
krista@1987
   128
krista@1987
   129
krista@1987
   130
vb@98
   131
#ifdef __cplusplus
vb@98
   132
}
vb@98
   133
#endif