]> diplodocus.org Git - nmh/blob - h/mhparse.h
Removed a bunch of unreachable break statements found by
[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
113 /* Content-MD5 info */
114 int c_digested; /* have we seen this header before? */
115 unsigned char c_digest[16]; /* decoded MD5 checksum */
116
117 /* pointers to content-specific structures */
118 void *c_ctparams; /* content type specific data */
119 struct exbody *c_ctexbody; /* data for type message/external */
120
121 /* function pointers */
122 InitFunc c_ctinitfnx; /* parse content body */
123 OpenCEFunc c_ceopenfnx; /* get a stream to decoded contents */
124 CloseCEFunc c_ceclosefnx; /* release stream */
125 SizeCEFunc c_cesizefnx; /* size of decoded contents */
126
127 int c_umask; /* associated umask */
128 pid_t c_pid; /* process doing display */
129 int c_rfc934; /* rfc934 compatibility flag */
130
131 char *c_showproc; /* default, if not in profile */
132 char *c_termproc; /* for charset madness... */
133 char *c_storeproc; /* overrides profile entry, if any */
134
135 char *c_storage; /* write contents (file) */
136 char *c_folder; /* write contents (folder) */
137 };
138
139 /*
140 * Flags for Content-Type (Content->c_type)
141 */
142 #define CT_UNKNOWN 0x00
143 #define CT_APPLICATION 0x01
144 #define CT_AUDIO 0x02
145 #define CT_IMAGE 0x03
146 #define CT_MESSAGE 0x04
147 #define CT_MULTIPART 0x05
148 #define CT_TEXT 0x06
149 #define CT_VIDEO 0x07
150 #define CT_EXTENSION 0x08
151
152 /*
153 * Flags for Content-Transfer-Encoding (Content->c_encoding)
154 */
155 #define CE_UNKNOWN 0x00
156 #define CE_BASE64 0x01
157 #define CE_QUOTED 0x02
158 #define CE_8BIT 0x03
159 #define CE_7BIT 0x04
160 #define CE_BINARY 0x05
161 #define CE_EXTENSION 0x06
162 #define CE_EXTERNAL 0x07 /* for external-body */
163
164 /*
165 * TEXT content
166 */
167
168 /* Flags for subtypes of TEXT */
169 #define TEXT_UNKNOWN 0x00
170 #define TEXT_PLAIN 0x01
171 #define TEXT_RICHTEXT 0x02
172 #define TEXT_ENRICHED 0x03
173
174 /* Flags for character sets */
175 #define CHARSET_SPECIFIED 0x00
176 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
177
178 /* Structure for text content */
179 struct text {
180 int tx_charset; /* flag for character set */
181 };
182
183 /*
184 * MULTIPART content
185 */
186
187 /* Flags for subtypes of MULTIPART */
188 #define MULTI_UNKNOWN 0x00
189 #define MULTI_MIXED 0x01
190 #define MULTI_ALTERNATE 0x02
191 #define MULTI_DIGEST 0x03
192 #define MULTI_PARALLEL 0x04
193
194 /* Structure for subparts of a multipart content */
195 struct part {
196 CT mp_part; /* Content structure for subpart */
197 struct part *mp_next; /* pointer to next subpart structure */
198 };
199
200 /* Main structure for multipart content */
201 struct multipart {
202 char *mp_start; /* boundary string separating parts */
203 char *mp_stop; /* terminating boundary string */
204 char *mp_content_before; /* any content before the first subpart */
205 char *mp_content_after; /* any content after the last subpart */
206 struct part *mp_parts; /* pointer to first subpart structure */
207 };
208
209 /*
210 * MESSAGE content
211 */
212
213 /* Flags for subtypes of MESSAGE */
214 #define MESSAGE_UNKNOWN 0x00
215 #define MESSAGE_RFC822 0x01
216 #define MESSAGE_PARTIAL 0x02
217 #define MESSAGE_EXTERNAL 0x03
218
219 /* Structure for message/partial */
220 struct partial {
221 char *pm_partid;
222 int pm_partno;
223 int pm_maxno;
224 int pm_marked;
225 int pm_stored;
226 };
227
228 /* Structure for message/external */
229 struct exbody {
230 CT eb_parent; /* pointer to controlling content structure */
231 CT eb_content; /* pointer to internal content structure */
232 char *eb_partno;
233 char *eb_access;
234 int eb_flags;
235 char *eb_name;
236 char *eb_permission;
237 char *eb_site;
238 char *eb_dir;
239 char *eb_mode;
240 unsigned long eb_size;
241 char *eb_server;
242 char *eb_subject;
243 char *eb_body;
244 char *eb_url;
245 };
246
247 /*
248 * APPLICATION content
249 */
250
251 /* Flags for subtype of APPLICATION */
252 #define APPLICATION_UNKNOWN 0x00
253 #define APPLICATION_OCTETS 0x01
254 #define APPLICATION_POSTSCRIPT 0x02
255
256
257 /*
258 * Structures for mapping types to their internal flags
259 */
260 struct k2v {
261 char *kv_key;
262 int kv_value;
263 };
264 extern struct k2v SubText[];
265 extern struct k2v Charset[];
266 extern struct k2v SubMultiPart[];
267 extern struct k2v SubMessage[];
268 extern struct k2v SubApplication[];
269
270 /*
271 * Structures for mapping (content) types to
272 * the functions to handle them.
273 */
274 struct str2init {
275 char *si_key;
276 int si_val;
277 InitFunc si_init;
278 };
279 extern struct str2init str2cts[];
280 extern struct str2init str2ces[];
281 extern struct str2init str2methods[];
282
283 /*
284 * prototypes
285 */
286 int pidcheck (int);
287 CT parse_mime (char *);
288
289 /*
290 * Translate a composition file into a MIME data structure. Arguments are:
291 *
292 * infile - Name of input filename
293 * directives - A flag to control whether or not build directives are
294 * processed by default.
295 * encoding - The default encoding to use when doing RFC 2047 header
296 * encoding. Must be one of CE_UNKNOWN, CE_BASE64, or
297 * CE_QUOTED;
298 *
299 * Returns a CT structure describing the resulting MIME message.
300 */
301 CT build_mime (char *infile, int directives, int encoding);
302
303 int add_header (CT, char *, char *);
304 int get_ctinfo (char *, CT, int);
305 int params_external (CT, int);
306 int open7Bit (CT, char **);
307 void close_encoding (CT);
308 void free_content (CT);
309 char *ct_type_str (int);
310 char *ct_subtype_str (int, int);
311 const struct str2init *get_ct_init (int);
312 const char *ce_str (int);
313 const struct str2init *get_ce_method (const char *);
314 int parse_header_attrs (const char *, int, char **, CI, int *);
315
316 extern int checksw; /* Add Content-MD5 field */