]> diplodocus.org Git - nmh/blob - h/mhparse.h
Remove SYNOPSIS from nmh(7).
[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 struct Content {
73 /* source (read) file */
74 char *c_file; /* read contents (file) */
75 FILE *c_fp; /* read contents (stream) */
76 int c_unlink; /* remove file when done? */
77
78 long c_begin; /* where content body starts in file */
79 long c_end; /* where content body ends in file */
80
81 /* linked list of header fields */
82 HF c_first_hf; /* pointer to first header field */
83 HF c_last_hf; /* pointer to last header field */
84
85 /* copies of MIME related header fields */
86 char *c_vrsn; /* MIME-Version: */
87 char *c_ctline; /* Content-Type: */
88 char *c_celine; /* Content-Transfer-Encoding: */
89 char *c_id; /* Content-ID: */
90 char *c_descr; /* Content-Description: */
91 char *c_dispo; /* Content-Disposition: */
92 char *c_partno; /* within multipart content */
93
94 /* Content-Type info */
95 struct CTinfo c_ctinfo; /* parsed elements of Content-Type */
96 int c_type; /* internal flag for content type */
97 int c_subtype; /* internal flag for content subtype */
98
99 /* Content-Transfer-Encoding info (decoded contents) */
100 struct cefile c_cefile; /* structure holding decoded content */
101 int c_encoding; /* internal flag for encoding type */
102
103 /* Content-MD5 info */
104 int c_digested; /* have we seen this header before? */
105 unsigned char c_digest[16]; /* decoded MD5 checksum */
106
107 /* pointers to content-specific structures */
108 void *c_ctparams; /* content type specific data */
109 struct exbody *c_ctexbody; /* data for type message/external */
110
111 /* function pointers */
112 InitFunc c_ctinitfnx; /* parse content body */
113 OpenCEFunc c_ceopenfnx; /* get a stream to decoded contents */
114 CloseCEFunc c_ceclosefnx; /* release stream */
115 SizeCEFunc c_cesizefnx; /* size of decoded contents */
116
117 int c_umask; /* associated umask */
118 pid_t c_pid; /* process doing display */
119 int c_rfc934; /* rfc934 compatibility flag */
120
121 char *c_showproc; /* default, if not in profile */
122 char *c_termproc; /* for charset madness... */
123 char *c_storeproc; /* overrides profile entry, if any */
124
125 char *c_storage; /* write contents (file) */
126 char *c_folder; /* write contents (folder) */
127 };
128
129 /*
130 * Flags for Content-Type (Content->c_type)
131 */
132 #define CT_UNKNOWN 0x00
133 #define CT_APPLICATION 0x01
134 #define CT_AUDIO 0x02
135 #define CT_IMAGE 0x03
136 #define CT_MESSAGE 0x04
137 #define CT_MULTIPART 0x05
138 #define CT_TEXT 0x06
139 #define CT_VIDEO 0x07
140 #define CT_EXTENSION 0x08
141
142 /*
143 * Flags for Content-Transfer-Encoding (Content->c_encoding)
144 */
145 #define CE_UNKNOWN 0x00
146 #define CE_BASE64 0x01
147 #define CE_QUOTED 0x02
148 #define CE_8BIT 0x03
149 #define CE_7BIT 0x04
150 #define CE_BINARY 0x05
151 #define CE_EXTENSION 0x06
152 #define CE_EXTERNAL 0x07 /* for external-body */
153
154 /*
155 * TEXT content
156 */
157
158 /* Flags for subtypes of TEXT */
159 #define TEXT_UNKNOWN 0x00
160 #define TEXT_PLAIN 0x01
161 #define TEXT_RICHTEXT 0x02
162 #define TEXT_ENRICHED 0x03
163
164 /* Flags for character sets */
165 #define CHARSET_SPECIFIED 0x00
166 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */
167
168 /* Structure for text content */
169 struct text {
170 int tx_charset; /* flag for character set */
171 };
172
173 /*
174 * MULTIPART content
175 */
176
177 /* Flags for subtypes of MULTIPART */
178 #define MULTI_UNKNOWN 0x00
179 #define MULTI_MIXED 0x01
180 #define MULTI_ALTERNATE 0x02
181 #define MULTI_DIGEST 0x03
182 #define MULTI_PARALLEL 0x04
183
184 /* Structure for subparts of a multipart content */
185 struct part {
186 CT mp_part; /* Content structure for subpart */
187 struct part *mp_next; /* pointer to next subpart structure */
188 };
189
190 /* Main structure for multipart content */
191 struct multipart {
192 char *mp_start; /* boundary string separating parts */
193 char *mp_stop; /* terminating boundary string */
194 char *mp_content_before; /* any content before the first subpart */
195 char *mp_content_after; /* any content after the last subpart */
196 struct part *mp_parts; /* pointer to first subpart structure */
197 };
198
199 /*
200 * MESSAGE content
201 */
202
203 /* Flags for subtypes of MESSAGE */
204 #define MESSAGE_UNKNOWN 0x00
205 #define MESSAGE_RFC822 0x01
206 #define MESSAGE_PARTIAL 0x02
207 #define MESSAGE_EXTERNAL 0x03
208
209 /* Structure for message/partial */
210 struct partial {
211 char *pm_partid;
212 int pm_partno;
213 int pm_maxno;
214 int pm_marked;
215 int pm_stored;
216 };
217
218 /* Structure for message/external */
219 struct exbody {
220 CT eb_parent; /* pointer to controlling content structure */
221 CT eb_content; /* pointer to internal content structure */
222 char *eb_partno;
223 char *eb_access;
224 int eb_flags;
225 char *eb_name;
226 char *eb_permission;
227 char *eb_site;
228 char *eb_dir;
229 char *eb_mode;
230 unsigned long eb_size;
231 char *eb_server;
232 char *eb_subject;
233 char *eb_body;
234 char *eb_url;
235 };
236
237 /*
238 * APPLICATION content
239 */
240
241 /* Flags for subtype of APPLICATION */
242 #define APPLICATION_UNKNOWN 0x00
243 #define APPLICATION_OCTETS 0x01
244 #define APPLICATION_POSTSCRIPT 0x02
245
246
247 /*
248 * Structures for mapping types to their internal flags
249 */
250 struct k2v {
251 char *kv_key;
252 int kv_value;
253 };
254 extern struct k2v SubText[];
255 extern struct k2v Charset[];
256 extern struct k2v SubMultiPart[];
257 extern struct k2v SubMessage[];
258 extern struct k2v SubApplication[];
259
260 /*
261 * Structures for mapping (content) types to
262 * the functions to handle them.
263 */
264 struct str2init {
265 char *si_key;
266 int si_val;
267 InitFunc si_init;
268 };
269 extern struct str2init str2cts[];
270 extern struct str2init str2ces[];
271 extern struct str2init str2methods[];
272
273 /*
274 * prototypes
275 */
276 int pidcheck (int);
277 CT parse_mime (char *);
278 int add_header (CT, char *, char *);
279 int get_ctinfo (char *, CT, int);
280 int params_external (CT, int);
281 int open7Bit (CT, char **);
282 void close_encoding (CT);
283 void free_content (CT);
284 char *ct_type_str (int);
285 char *ct_subtype_str (int, int);
286 const struct str2init *get_ct_init (int);
287 const char *ce_str (int);
288 const struct str2init *get_ce_method (const char *);
289 int parse_header_attrs (const char *, int, char **, CI, int *);
290
291 extern int checksw; /* Add Content-MD5 field */