]> diplodocus.org Git - nmh/blob - h/mhparse.h
Remove mhbuild backup files at end of a couple of tests, if successful.
[nmh] / h / mhparse.h
1
2 /*
3 * mhparse.h -- definitions for parsing/building of MIME content
4 * -- (mhparse.c/mhbuildsbr.c)
5 */
6
7 #define NPARTS 50
8 #define NTYPES 20
9 #define NPARMS 10
10
11 /*
12 * Abstract type for header fields
13 */
14 typedef struct hfield *HF;
15
16 /*
17 * Abstract types for MIME parsing/building
18 */
19 typedef struct cefile *CE;
20 typedef struct CTinfo *CI;
21 typedef struct Content *CT;
22
23 /*
24 * type for Init function (both type and transfer encoding)
25 */
26 typedef int (*InitFunc) (CT);
27
28 /*
29 * types for various transfer encoding access functions
30 */
31 typedef int (*OpenCEFunc) (CT, char **);
32 typedef void (*CloseCEFunc) (CT);
33 typedef unsigned long (*SizeCEFunc) (CT);
34
35 /*
36 * Structure for storing/encoding/decoding
37 * a header field and its value.
38 */
39 struct hfield {
40 char *name; /* field name */
41 char *value; /* field body */
42 int hf_encoding; /* internal flag for transfer encoding to use */
43 HF next; /* link to next header field */
44 };
45
46 /*
47 * Structure for storing parsed elements
48 * of the Content-Type component.
49 */
50 struct CTinfo {
51 char *ci_type; /* content type */
52 char *ci_subtype; /* content subtype */
53 char *ci_attrs[NPARMS + 2]; /* attribute names */
54 char *ci_values[NPARMS]; /* attribute values */
55 char *ci_comment; /* RFC-822 comments */
56 char *ci_magic;
57 };
58
59 /*
60 * Structure for storing decoded contents after
61 * removing Content-Transfer-Encoding.
62 */
63 struct cefile {
64 char *ce_file; /* decoded content (file) */
65 FILE *ce_fp; /* decoded content (stream) */
66 int ce_unlink; /* remove file when done? */
67 };
68
69 /*
70 * Primary structure for handling Content (Entity)
71 *
72 * Some more explanation of this:
73 *
74 * This structure recursively describes a complete MIME message.
75 * At the top level, the c_first_hf list has a list of all message
76 * headers. If the content-type is multipart (c_type == CT_MULTIPART)
77 * then c_ctparams will contain a pointer to a struct multipart.
78 * A struct multipart contains (among other trhings) a linked list
79 * of struct part elements, and THOSE contain a pointer to the sub-part's
80 * Content structure.
81 */
82 struct Content {
83 /* source (read) file */
84 char *c_file; /* read contents (file) */
85 FILE *c_fp; /* read contents (stream) */
86 int c_unlink; /* remove file when done? */
87
88 long c_begin; /* where content body starts in file */
89 long c_end; /* where content body ends in file */
90
91 /* linked list of header fields */
92 HF c_first_hf; /* pointer to first header field */
93 HF c_last_hf; /* pointer to last header field */
94
95 /* copies of MIME related header fields */
96 char *c_vrsn; /* MIME-Version: */
97 char *c_ctline; /* Content-Type: */
98 char *c_celine; /* Content-Transfer-Encoding: */
99 char *c_id; /* Content-ID: */
100 char *c_descr; /* Content-Description: */
101 char *c_dispo; /* Content-Disposition: */
102 char *c_partno; /* within multipart content */
103
104 /* Content-Type info */
105 struct CTinfo c_ctinfo; /* parsed elements of Content-Type */
106 int c_type; /* internal flag for content type */
107 int c_subtype; /* internal flag for content subtype */
108
109 /* Content-Transfer-Encoding info (decoded contents) */
110 struct cefile c_cefile; /* structure holding decoded content */
111 int c_encoding; /* internal flag for encoding type */
112 int c_reqencoding; /* Requested encoding (by mhbuild) */
113
114 /* Content-MD5 info */
115 int c_digested; /* have we seen this header before? */
116 unsigned char c_digest[16]; /* decoded MD5 checksum */
117
118 /* pointers to content-specific structures */
119 void *c_ctparams; /* content type specific data */
120 struct exbody *c_ctexbody; /* data for type message/external */
121
122 /* function pointers */
123 InitFunc c_ctinitfnx; /* parse content body */
124 OpenCEFunc c_ceopenfnx; /* get a stream to decoded contents */
125 CloseCEFunc c_ceclosefnx; /* release stream */
126 SizeCEFunc c_cesizefnx; /* size of decoded contents */
127
128 int c_umask; /* associated umask */
129 pid_t c_pid; /* process doing display */
130 int c_rfc934; /* rfc934 compatibility flag */
131
132 char *c_showproc; /* default, if not in profile */
133 char *c_termproc; /* for charset madness... */
134 char *c_storeproc; /* overrides profile entry, if any */
135
136 char *c_storage; /* write contents (file) */
137 char *c_folder; /* write contents (folder) */
138 };
139
140 /*
141 * Flags for Content-Type (Content->c_type)
142 */
143 #define CT_UNKNOWN 0x00
144 #define CT_APPLICATION 0x01
145 #define CT_AUDIO 0x02
146 #define CT_IMAGE 0x03
147 #define CT_MESSAGE 0x04
148 #define CT_MULTIPART 0x05
149 #define CT_TEXT 0x06
150 #define CT_VIDEO 0x07
151 #define CT_EXTENSION 0x08
152
153 /*
154 * Flags for Content-Transfer-Encoding (Content->c_encoding)
155 */
156 #define CE_UNKNOWN 0x00
157 #define CE_BASE64 0x01
158 #define CE_QUOTED 0x02
159 #define CE_8BIT 0x03
160 #define CE_7BIT 0x04
161 #define CE_BINARY 0x05
162 #define CE_EXTENSION 0x06
163 #define CE_EXTERNAL 0x07 /* for external-body */
164
165 /*
166 * TEXT content
167 */
168
169 /* Flags for subtypes of TEXT */
170 #define TEXT_UNKNOWN 0x00
171 #define TEXT_PLAIN 0x01
172 #define TEXT_RICHTEXT 0x02
173 #define TEXT_ENRICHED 0x03
174
175 /* Flags for character sets */
176 #define CHARSET_SPECIFIED 0x00
177 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
178
179 /* Structure for text content */
180 struct text {
181 int tx_charset; /* flag for character set */
182 };
183
184 /*
185 * MULTIPART content
186 */
187
188 /* Flags for subtypes of MULTIPART */
189 #define MULTI_UNKNOWN 0x00
190 #define MULTI_MIXED 0x01
191 #define MULTI_ALTERNATE 0x02
192 #define MULTI_DIGEST 0x03
193 #define MULTI_PARALLEL 0x04
194
195 /* Structure for subparts of a multipart content */
196 struct part {
197 CT mp_part; /* Content structure for subpart */
198 struct part *mp_next; /* pointer to next subpart structure */
199 };
200
201 /* Main structure for multipart content */
202 struct multipart {
203 char *mp_start; /* boundary string separating parts */
204 char *mp_stop; /* terminating boundary string */
205 char *mp_content_before; /* any content before the first subpart */
206 char *mp_content_after; /* any content after the last subpart */
207 struct part *mp_parts; /* pointer to first subpart structure */
208 };
209
210 /*
211 * MESSAGE content
212 */
213
214 /* Flags for subtypes of MESSAGE */
215 #define MESSAGE_UNKNOWN 0x00
216 #define MESSAGE_RFC822 0x01
217 #define MESSAGE_PARTIAL 0x02
218 #define MESSAGE_EXTERNAL 0x03
219
220 /* Structure for message/partial */
221 struct partial {
222 char *pm_partid;
223 int pm_partno;
224 int pm_maxno;
225 int pm_marked;
226 int pm_stored;
227 };
228
229 /* Structure for message/external */
230 struct exbody {
231 CT eb_parent; /* pointer to controlling content structure */
232 CT eb_content; /* pointer to internal content structure */
233 char *eb_partno;
234 char *eb_access;
235 int eb_flags;
236 char *eb_name;
237 char *eb_permission;
238 char *eb_site;
239 char *eb_dir;
240 char *eb_mode;
241 unsigned long eb_size;
242 char *eb_server;
243 char *eb_subject;
244 char *eb_body;
245 char *eb_url;
246 };
247
248 /*
249 * APPLICATION content
250 */
251
252 /* Flags for subtype of APPLICATION */
253 #define APPLICATION_UNKNOWN 0x00
254 #define APPLICATION_OCTETS 0x01
255 #define APPLICATION_POSTSCRIPT 0x02
256
257
258 /*
259 * Structures for mapping types to their internal flags
260 */
261 struct k2v {
262 char *kv_key;
263 int kv_value;
264 };
265 extern struct k2v SubText[];
266 extern struct k2v Charset[];
267 extern struct k2v SubMultiPart[];
268 extern struct k2v SubMessage[];
269 extern struct k2v SubApplication[];
270
271 /*
272 * Structures for mapping (content) types to
273 * the functions to handle them.
274 */
275 struct str2init {
276 char *si_key;
277 int si_val;
278 InitFunc si_init;
279 };
280 extern struct str2init str2cts[];
281 extern struct str2init str2ces[];
282 extern struct str2init str2methods[];
283
284 /*
285 * prototypes
286 */
287 int pidcheck (int);
288 CT parse_mime (char *);
289
290 /*
291 * Translate a composition file into a MIME data structure. Arguments are:
292 *
293 * infile - Name of input filename
294 * autobuild - A flag to indicate if the composition file parser is
295 * being run in automatic mode or not. In auto mode,
296 * if a MIME-Version header is encountered it is assumed
297 * that the composition file is already in MIME format
298 * and will not be processed further. Otherwise, an
299 * error is generated.
300 * dist - A flag to indicate if we are being run by "dist". In
301 * that case, add no MIME headers to the message. Existing
302 * headers will still be encoded by RFC 2047.
303 * directives - A flag to control whether or not build directives are
304 * processed by default.
305 * encoding - The default encoding to use when doing RFC 2047 header
306 * encoding. Must be one of CE_UNKNOWN, CE_BASE64, or
307 * CE_QUOTED.
308 * maxunencoded - The maximum line length before the default encoding for
309 * text parts is quoted-printable.
310 *
311 * Returns a CT structure describing the resulting MIME message. If the
312 * -auto flag is set and a MIME-Version header is encountered, the return
313 * value is NULL.
314 */
315 CT build_mime (char *infile, int autobuild, int dist, int directives,
316 int encoding, size_t maxunencoded);
317
318 int add_header (CT, char *, char *);
319 int get_ctinfo (char *, CT, int);
320 int params_external (CT, int);
321 int open7Bit (CT, char **);
322 void close_encoding (CT);
323 void free_content (CT);
324 char *ct_type_str (int);
325 char *ct_subtype_str (int, int);
326 const struct str2init *get_ct_init (int);
327 const char *ce_str (int);
328 const struct str2init *get_ce_method (const char *);
329 int parse_header_attrs (const char *, int, char **, CI, int *);
330 char *update_attr (char *, const char *, const char *e);
331 char *content_charset (CT);
332 int convert_charset (CT, char *, int *);
333
334 extern int checksw; /* Add Content-MD5 field */