bef3f4f8d5e58fa8eb3dddad752a160c2b2af461
[mmh] / h / mhparse.h
1 /*
2 ** mhparse.h -- definitions for parsing/building of MIME content
3 **           -- (mhparse.c/mhbuildsbr.c)
4 */
5
6 #define NPARTS  50
7 #define NTYPES  20
8 #define NPARMS  10
9
10 /*
11 ** Abstract type for header fields
12 */
13 typedef struct hfield *HF;
14
15 /*
16 ** Abstract types for MIME parsing/building
17 */
18 typedef struct cefile  *CE;
19 typedef struct CTinfo  *CI;
20 typedef struct Content *CT;
21
22 /*
23 ** type for Init function (both type and transfer encoding)
24 */
25 typedef int (*InitFunc) (CT);
26
27 /*
28 ** types for various transfer encoding access functions
29 */
30 typedef int (*OpenCEFunc) (CT, char **);
31 typedef void (*CloseCEFunc) (CT);
32 typedef unsigned long (*SizeCEFunc) (CT);
33
34 /*
35 ** Structure for storing/encoding/decoding
36 ** a header field and its value.
37 */
38 struct hfield {
39         char *name;       /* field name */
40         char *value;      /* field body */
41         int hf_encoding;  /* internal flag for transfer encoding to use */
42         HF next;          /* link to next header field */
43 };
44
45 /*
46 ** Structure for storing parsed elements
47 ** of the Content-Type component.
48 */
49 struct CTinfo {
50         char *ci_type;               /* content type     */
51         char *ci_subtype;            /* content subtype  */
52         char *ci_attrs[NPARMS + 2];  /* attribute names  */
53         char *ci_values[NPARMS];     /* attribute values */
54         char *ci_comment;            /* RFC-822 comments */
55         char *ci_magic;
56 };
57
58 /*
59 ** Structure for storing decoded contents after
60 ** removing Content-Transfer-Encoding.
61 */
62 struct cefile {
63         char *ce_file;   /* decoded content (file)   */
64         FILE *ce_fp;     /* decoded content (stream) */
65         int ce_unlink;   /* remove file when done?   */
66 };
67
68 /*
69 ** Primary structure for handling Content (Entity)
70 */
71 struct Content {
72         /* source (read) file */
73         char *c_file;                /* read contents (file)              */
74         FILE *c_fp;                  /* read contents (stream)            */
75         int c_unlink;                /* remove file when done?            */
76
77         long c_begin;                /* where content body starts in file */
78         long c_end;                  /* where content body ends in file   */
79
80         /* linked list of header fields */
81         HF c_first_hf;               /* pointer to first header field     */
82         HF c_last_hf;                /* pointer to last header field      */
83
84         /* copies of MIME related header fields */
85         char *c_vrsn;                /* MIME-Version:                     */
86         char *c_ctline;              /* Content-Type:                     */
87         char *c_celine;              /* Content-Transfer-Encoding:        */
88         char *c_id;                  /* Content-ID:                       */
89         char *c_descr;               /* Content-Description:              */
90         char *c_dispo;               /* Content-Disposition:              */
91         char *c_partno;              /* within multipart content          */
92
93         /* Content-Type info */
94         struct CTinfo c_ctinfo;      /* parsed elements of Content-Type   */
95         int c_type;                  /* internal flag for content type    */
96         int c_subtype;               /* internal flag for content subtype */
97
98         /* Content-Transfer-Encoding info (decoded contents) */
99         CE c_cefile;                 /* structure holding decoded content */
100         int c_encoding;              /* internal flag for encoding type   */
101
102         /* Content-MD5 info */
103         int c_digested;              /* have we seen this header before?  */
104         unsigned char c_digest[16];  /* decoded MD5 checksum              */
105
106         /* pointers to content-specific structures */
107         void *c_ctparams;            /* content type specific data        */
108         struct exbody *c_ctexbody;   /* data for type message/external    */
109
110         /* function pointers */
111         InitFunc    c_ctinitfnx;     /* parse content body                */
112         OpenCEFunc  c_ceopenfnx;     /* get a stream to decoded contents  */
113         CloseCEFunc c_ceclosefnx;    /* release stream                    */
114         SizeCEFunc  c_cesizefnx;     /* size of decoded contents          */
115
116         int c_umask;                 /* associated umask                  */
117         pid_t c_pid;                 /* process doing display             */
118         int c_rfc934;                /* rfc934 compatibility flag         */
119
120         char *c_showproc;            /* default, if not in profile        */
121         char *c_termproc;            /* for charset madness...            */
122         char *c_storeproc;           /* overrides profile entry, if any   */
123
124         char *c_storage;             /* write contents (file)             */
125         char *c_folder;              /* write contents (folder)           */
126 };
127
128 /*
129 ** Flags for Content-Type (Content->c_type)
130 */
131 #define CT_UNKNOWN      0x00
132 #define CT_APPLICATION  0x01
133 #define CT_AUDIO        0x02
134 #define CT_IMAGE        0x03
135 #define CT_MESSAGE      0x04
136 #define CT_MULTIPART    0x05
137 #define CT_TEXT         0x06
138 #define CT_VIDEO        0x07
139 #define CT_EXTENSION    0x08
140
141 /*
142 ** Flags for Content-Transfer-Encoding (Content->c_encoding)
143 */
144 #define CE_UNKNOWN      0x00
145 #define CE_BASE64       0x01
146 #define CE_QUOTED       0x02
147 #define CE_8BIT         0x03
148 #define CE_7BIT         0x04
149 #define CE_BINARY       0x05
150 #define CE_EXTENSION    0x06
151 #define CE_EXTERNAL     0x07    /* for external-body */
152
153 /*
154 ** TEXT content
155 */
156
157 /* Flags for subtypes of TEXT */
158 #define TEXT_UNKNOWN    0x00
159 #define TEXT_PLAIN      0x01
160 #define TEXT_RICHTEXT   0x02
161 #define TEXT_ENRICHED   0x03
162
163 /* Flags for character sets */
164 #define CHARSET_UNKNOWN      0x00
165 #define CHARSET_UNSPECIFIED  0x01  /* only needed when building drafts */
166 #define CHARSET_USASCII      0x01
167 #define CHARSET_LATIN        0x02
168
169 /* Structure for text content */
170 struct text {
171         int tx_charset;    /* flag for character set */
172 };
173
174 /*
175 ** MULTIPART content
176 */
177
178 /* Flags for subtypes of MULTIPART */
179 #define MULTI_UNKNOWN    0x00
180 #define MULTI_MIXED      0x01
181 #define MULTI_ALTERNATE  0x02
182 #define MULTI_DIGEST     0x03
183 #define MULTI_PARALLEL   0x04
184
185 /* Structure for subparts of a multipart content */
186 struct part {
187         CT mp_part;             /* Content structure for subpart     */
188         struct part *mp_next;   /* pointer to next subpart structure */
189 };
190
191 /* Main structure for multipart content */
192 struct multipart {
193         char *mp_start;         /* boundary string separating parts   */
194         char *mp_stop;          /* terminating boundary string        */
195         struct part *mp_parts;  /* pointer to first subpart structure */
196 };
197
198 /*
199 ** MESSAGE content
200 */
201
202 /* Flags for subtypes of MESSAGE */
203 #define MESSAGE_UNKNOWN   0x00
204 #define MESSAGE_RFC822    0x01
205 #define MESSAGE_PARTIAL   0x02
206 #define MESSAGE_EXTERNAL  0x03
207
208 /* Structure for message/partial */
209 struct partial {
210         char *pm_partid;
211         int pm_partno;
212         int pm_maxno;
213         int pm_marked;
214         int pm_stored;
215 };
216
217 /* Structure for message/external */
218 struct exbody {
219         CT eb_parent;        /* pointer to controlling content structure */
220         CT eb_content;       /* pointer to internal content structure    */
221         char *eb_partno;
222         char *eb_access;
223         int eb_flags;
224         char *eb_name;
225         char *eb_permission;
226         char *eb_site;
227         char *eb_dir;
228         char *eb_mode;
229         unsigned long eb_size;
230         char *eb_server;
231         char *eb_subject;
232         char *eb_body;
233 };
234
235 /*
236 ** APPLICATION content
237 */
238
239 /* Flags for subtype of APPLICATION */
240 #define APPLICATION_UNKNOWN     0x00
241 #define APPLICATION_OCTETS      0x01
242 #define APPLICATION_POSTSCRIPT  0x02
243
244
245 /*
246 ** Structures for mapping types to their internal flags
247 */
248 struct k2v {
249         char *kv_key;
250         int kv_value;
251 };
252 extern struct k2v SubText[];
253 extern struct k2v Charset[];
254 extern struct k2v SubMultiPart[];
255 extern struct k2v SubMessage[];
256 extern struct k2v SubApplication[];
257
258 /*
259 ** Structures for mapping (content) types to
260 ** the functions to handle them.
261 */
262 struct str2init {
263         char *si_key;
264         int si_val;
265         InitFunc si_init;
266 };
267 extern struct str2init str2cts[];
268 extern struct str2init str2ces[];
269 extern struct str2init str2methods[];
270
271 /*
272 ** prototypes
273 */
274 int pidcheck (int);
275 CT parse_mime (char *);
276 int add_header (CT, char *, char *);
277 int get_ctinfo (unsigned char *, CT, int);
278 int params_external (CT, int);
279 int open7Bit (CT, char **);
280 void close_encoding (CT);
281
282 extern int checksw;    /* Add Content-MD5 field */