Added docs/contrib/vpick.
[mmh] / 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     CE 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     struct part *mp_parts;      /* pointer to first subpart structure */
195 };
196
197 /*
198  * MESSAGE content
199  */
200
201 /* Flags for subtypes of MESSAGE */
202 #define MESSAGE_UNKNOWN  0x00
203 #define MESSAGE_RFC822   0x01
204 #define MESSAGE_PARTIAL  0x02
205 #define MESSAGE_EXTERNAL 0x03
206
207 /* Structure for message/partial */
208 struct partial {
209     char *pm_partid;
210     int pm_partno;
211     int pm_maxno;
212     int pm_marked;
213     int pm_stored;
214 };
215
216 /* Structure for message/external */
217 struct exbody {
218     CT eb_parent;       /* pointer to controlling content structure */
219     CT eb_content;      /* pointer to internal content structure    */
220     char *eb_partno;
221     char *eb_access;
222     int eb_flags;
223     char *eb_name;
224     char *eb_permission;
225     char *eb_site;
226     char *eb_dir;
227     char *eb_mode;
228     unsigned long eb_size;
229     char *eb_server;
230     char *eb_subject;
231     char *eb_body;
232 };
233
234 /*
235  * APPLICATION content
236  */
237
238 /* Flags for subtype of APPLICATION */
239 #define APPLICATION_UNKNOWN     0x00
240 #define APPLICATION_OCTETS      0x01
241 #define APPLICATION_POSTSCRIPT  0x02
242
243
244 /*
245  * Structures for mapping types to their internal flags
246  */
247 struct k2v {
248     char *kv_key;
249     int   kv_value;
250 };
251 extern struct k2v SubText[];
252 extern struct k2v Charset[];
253 extern struct k2v SubMultiPart[];
254 extern struct k2v SubMessage[];
255 extern struct k2v SubApplication[];
256
257 /*
258  * Structures for mapping (content) types to
259  * the functions to handle them.
260  */
261 struct str2init {
262     char *si_key;
263     int   si_val;
264     InitFunc si_init;
265 };
266 extern struct str2init str2cts[];
267 extern struct str2init str2ces[];
268 extern struct str2init str2methods[];
269
270 /*
271  * prototypes
272  */
273 int pidcheck (int);
274 CT parse_mime (char *);
275 int add_header (CT, char *, char *);
276 int get_ctinfo (unsigned char *, CT, int);
277 int params_external (CT, int);
278 int open7Bit (CT, char **);
279 void close_encoding (CT);
280
281 extern int checksw;     /* Add Content-MD5 field */