Remove RCS keywords, since they no longer work after git migration.
[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_UNKNOWN     0x00
166 #define CHARSET_UNSPECIFIED 0x01  /* only needed when building drafts */
167 #define CHARSET_USASCII     0x01
168 #define CHARSET_LATIN       0x02
169
170 /* Structure for text content */
171 struct text {
172     int tx_charset;             /* flag for character set */
173 };
174
175 /*
176  * MULTIPART content
177  */
178
179 /* Flags for subtypes of MULTIPART */
180 #define MULTI_UNKNOWN   0x00
181 #define MULTI_MIXED     0x01
182 #define MULTI_ALTERNATE 0x02
183 #define MULTI_DIGEST    0x03
184 #define MULTI_PARALLEL  0x04
185
186 /* Structure for subparts of a multipart content */
187 struct part {
188     CT mp_part;                 /* Content structure for subpart     */
189     struct part *mp_next;       /* pointer to next subpart structure */
190 };
191
192 /* Main structure for multipart content */
193 struct multipart {
194     char *mp_start;             /* boundary string separating parts   */
195     char *mp_stop;              /* terminating boundary string        */
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 };
235
236 /*
237  * APPLICATION content
238  */
239
240 /* Flags for subtype of APPLICATION */
241 #define APPLICATION_UNKNOWN     0x00
242 #define APPLICATION_OCTETS      0x01
243 #define APPLICATION_POSTSCRIPT  0x02
244
245
246 /*
247  * Structures for mapping types to their internal flags
248  */
249 struct k2v {
250     char *kv_key;
251     int   kv_value;
252 };
253 extern struct k2v SubText[];
254 extern struct k2v Charset[];
255 extern struct k2v SubMultiPart[];
256 extern struct k2v SubMessage[];
257 extern struct k2v SubApplication[];
258
259 /*
260  * Structures for mapping (content) types to
261  * the functions to handle them.
262  */
263 struct str2init {
264     char *si_key;
265     int   si_val;
266     InitFunc si_init;
267 };
268 extern struct str2init str2cts[];
269 extern struct str2init str2ces[];
270 extern struct str2init str2methods[];
271
272 /*
273  * prototypes
274  */
275 int pidcheck (int);
276 CT parse_mime (char *);
277 int add_header (CT, char *, char *);
278 int get_ctinfo (unsigned char *, CT, int);
279 int params_external (CT, int);
280 int open7Bit (CT, char **);
281 void close_encoding (CT);
282
283 extern int checksw;     /* Add Content-MD5 field */