]> diplodocus.org Git - nmh/blob - h/mh.h
Added NMH_ADDL_CPPFLAGS macro in new m4/cppflags.m4, to remove
[nmh] / h / mh.h
1 /*
2 * mh.h -- main header file for all of nmh
3 */
4
5 #include <h/nmh.h>
6
7 /*
8 * Well-used constants
9 */
10 #define NOTOK (-1) /* syscall()s return this on error */
11 #define OK 0 /* ditto on success */
12 #define DONE 1 /* trinary logic */
13 #define ALL ""
14 #define Nbby 8 /* number of bits/byte */
15
16 #define MAXARGS 1000 /* max arguments to exec */
17 #define NFOLDERS 1000 /* max folder arguments on command line */
18 #define DMAXFOLDER 4 /* typical number of digits */
19 #define MAXFOLDER 1000 /* message increment */
20
21 /*
22 * This macro is for use by scan, for example, so that platforms with
23 * a small BUFSIZ can easily allocate larger buffers.
24 */
25 #define NMH_BUFSIZ (BUFSIZ>=8192 ? BUFSIZ : 8192)
26
27 #ifndef FALSE
28 #define FALSE 0
29 #endif
30 #ifndef TRUE
31 #define TRUE 1
32 #endif
33 typedef unsigned char boolean; /* not int so we can pack in a structure */
34
35 /* If we're using gcc then give it some information about
36 * functions that abort.
37 */
38 #if __GNUC__ > 2
39 #define NORETURN __attribute__((__noreturn__))
40 #define NMH_UNUSED(i) (void) i
41 #else
42 #define NORETURN
43 #define NMH_UNUSED(i) i
44 #endif
45
46 /*
47 * char array that keeps track of size in both bytes and characters
48 * Usage note:
49 * Don't store return value of charstring_buffer() and use later
50 * after intervening push_back's; use charstring_buffer_copy()
51 * instead.
52 */
53 typedef struct charstring *charstring_t;
54
55 charstring_t charstring_create (size_t);
56 charstring_t charstring_copy (const charstring_t);
57 void charstring_free (charstring_t);
58 /* Append a single-byte character: */
59 void charstring_push_back (charstring_t, const char);
60 /* Append possibly multi-byte character(s): */
61 void charstring_push_back_chars (charstring_t, const char [], size_t, size_t);
62 void charstring_append (charstring_t, const charstring_t);
63 void charstring_append_cstring (charstring_t, const char []);
64 void charstring_clear (charstring_t);
65 /* Don't store return value of charstring_buffer() and use later after
66 intervening push_back's; use charstring_buffer_copy() instead. */
67 const char *charstring_buffer (const charstring_t);
68 /* User is responsible for free'ing result of buffer copy. */
69 char *charstring_buffer_copy (const charstring_t);
70 size_t charstring_bytes (const charstring_t);
71 size_t charstring_chars (const charstring_t);
72 /* Length of the last character in the charstring. */
73 int charstring_last_char_len (const charstring_t);
74
75 /*
76 * user context/profile structure
77 */
78 struct node {
79 char *n_name; /* key */
80 char *n_field; /* value */
81 char n_context; /* context, not profile */
82 struct node *n_next; /* next entry */
83 };
84
85 /*
86 * switches structure
87 */
88 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
89 #define UNKWNSW (-1) /* from smatch() on unknown switch */
90
91 struct swit {
92
93 /*
94 * Switch name
95 */
96
97 char *sw;
98
99 /* The minchars field is apparently used like this:
100
101 -# : Switch can be abbreviated to # characters; switch hidden in -help.
102 0 : Switch can't be abbreviated; switch shown in -help.
103 # : Switch can be abbreviated to # characters; switch shown in -help. */
104 int minchars;
105
106 /*
107 * If we pick this switch, return this value from smatch
108 */
109
110 int swret;
111 };
112
113 /*
114 * Macros to use when declaring struct swit arrays.
115 *
116 * These macros use a technique known as X-Macros. In your source code you
117 * use them like this:
118 *
119 * #define FOO_SWITCHES \
120 * X("switch1", 0, SWITCHSW) \
121 * X("switch2", 0, SWITCH2SW) \
122 * X("thirdswitch", 2, SWITCH3SW) \
123 *
124 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
125 * the minchars field (see above) and the return value for this switch.
126 * Note that the last entry in the above definition must either omit the
127 * continuation backslash, or be followed by a blank line. In the nmh
128 * code the style is to have every line include a backslash and follow
129 * the SWITCHES macro definition by a blank line.
130 *
131 * After you define FOO_SWITCHES, you instantiate it as follows:
132 *
133 * #define X(sw, minchars, id) id,
134 * DEFINE_SWITCH_ENUM(FOO);
135 * #undef X
136 *
137 * #define X(sw, minchars, id) { sw, minchars, id },
138 * DEFINE_SWITCH_ARRAY(FOO);
139 * #undef X
140 *
141 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
142 * LEN_FOO.
143 */
144
145 #define DEFINE_SWITCH_ENUM(name) \
146 enum { \
147 name ## _SWITCHES \
148 LEN_ ## name \
149 }
150
151 #define DEFINE_SWITCH_ARRAY(name, array) \
152 static struct swit array[] = { \
153 name ## _SWITCHES \
154 { NULL, 0, 0 } \
155 }
156
157 extern struct swit anoyes[]; /* standard yes/no switches */
158
159 /*
160 * general folder attributes
161 */
162 #define READONLY (1<<0) /* No write access to folder */
163 #define SEQMOD (1<<1) /* folder's sequences modified */
164 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
165 #define OTHERS (1<<3) /* folder has other files */
166 #define MODIFIED (1<<4) /* msh in-core folder modified */
167
168 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
169
170 /*
171 * first free slot for user defined sequences
172 * and attributes
173 */
174 #define FFATTRSLOT 5
175
176 /*
177 * internal messages attributes (sequences)
178 */
179 #define EXISTS (0) /* exists */
180 #define DELETED (1) /* deleted */
181 #define SELECTED (2) /* selected for use */
182 #define SELECT_EMPTY (3) /* "new" message */
183 #define SELECT_UNSEEN (4) /* inc/show "unseen" */
184
185 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
186
187 /*
188 * type for holding the sequence set of a message
189 */
190 typedef struct bvector *bvector_t;
191
192 bvector_t bvector_create (size_t /* initial size in bits, can be 0 */);
193 void bvector_copy (bvector_t, bvector_t);
194 void bvector_free (bvector_t);
195 void bvector_clear (bvector_t, size_t);
196 void bvector_clear_all (bvector_t);
197 void bvector_set (bvector_t, size_t);
198 unsigned int bvector_at (bvector_t, size_t);
199 const unsigned long *bvector_bits (bvector_t);
200 size_t bvector_maxsize (bvector_t);
201
202 typedef struct svector *svector_t;
203
204 svector_t svector_create (size_t);
205 void svector_free (svector_t);
206 char *svector_push_back (svector_t, char *);
207 char *svector_at (svector_t, size_t);
208 char **svector_find(svector_t, const char *);
209 char **svector_strs (svector_t);
210 size_t svector_size (svector_t);
211
212 typedef struct ivector *ivector_t;
213
214 ivector_t ivector_create (size_t);
215 void ivector_free (ivector_t);
216 int ivector_push_back (ivector_t, int);
217 int ivector_at (ivector_t, size_t);
218 int *ivector_atp (ivector_t, size_t);
219 size_t ivector_size (ivector_t);
220
221 /*
222 * Primary structure of folder/message information
223 */
224 struct msgs {
225 int lowmsg; /* Lowest msg number */
226 int hghmsg; /* Highest msg number */
227 int nummsg; /* Actual Number of msgs */
228
229 int lowsel; /* Lowest selected msg number */
230 int hghsel; /* Highest selected msg number */
231 int numsel; /* Number of msgs selected */
232
233 int curmsg; /* Number of current msg if any */
234
235 int msgflags; /* Folder attributes (READONLY, etc) */
236 char *foldpath; /* Pathname of folder */
237
238 /*
239 * Name of sequences in this folder.
240 */
241 svector_t msgattrs;
242
243 /*
244 * bit flags for whether sequence
245 * is public (0), or private (1)
246 */
247 bvector_t attrstats;
248
249 /*
250 * These represent the lowest and highest possible
251 * message numbers we can put in the message status
252 * area, without calling folder_realloc().
253 */
254 int lowoff;
255 int hghoff;
256
257 /*
258 * This is an array of bvector_t which we allocate dynamically.
259 * Each bvector_t is a set of bits flags for a particular message.
260 * These bit flags represent general attributes such as
261 * EXISTS, SELECTED, etc. as well as track if message is
262 * in a particular sequence.
263 */
264 size_t num_msgstats;
265 bvector_t *msgstats; /* msg status */
266
267 /*
268 * A FILE handle containing an open filehandle for the sequence file
269 * for this folder. If non-NULL, use it when the sequence file is
270 * written.
271 */
272 FILE *seqhandle;
273
274 /*
275 * The name of the public sequence file; required by lkfclose()
276 */
277 char *seqname;
278 };
279
280 /*
281 * Amount of space to allocate for msgstats. Allocate
282 * the array to have space for messages numbered lo to hi.
283 * Use MSGSTATNUM to load mp->num_msgstats first.
284 */
285 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
286 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
287
288 /*
289 * macros for message and sequence manipulation
290 */
291 #define msgstat(mp,n) (mp)->msgstats[(n) - mp->lowoff]
292 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
293 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
294 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
295 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
296
297 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
298 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
299 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
300
301 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
302 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
303 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
304
305 #define is_select_empty(mp,msgnum) \
306 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
307 #define set_select_empty(mp,msgnum) \
308 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
309
310 #define is_unseen(mp,msgnum) \
311 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
312 #define unset_unseen(mp,msgnum) \
313 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
314 #define set_unseen(mp,msgnum) \
315 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
316
317 /* for msh only */
318 #define set_deleted(mp,msgnum) bvector_set (msgstat(mp, msgnum), DELETED)
319
320 #define in_sequence(mp,seqnum,msgnum) \
321 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
322 #define clear_sequence(mp,seqnum,msgnum) \
323 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
324 #define add_sequence(mp,seqnum,msgnum) \
325 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
326
327 #define is_seq_private(mp,seqnum) \
328 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
329 #define make_seq_public(mp,seqnum) \
330 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
331 #define make_seq_private(mp,seqnum) \
332 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
333 #define make_all_public(mp) \
334 mp->attrstats = bvector_create(0); bvector_clear_all (mp->attrstats)
335
336 /*
337 * macros for folder attributes
338 */
339 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
340
341 #define is_readonly(mp) ((mp)->msgflags & READONLY)
342 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
343
344 #define other_files(mp) ((mp)->msgflags & OTHERS)
345 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
346
347 #define NULLMP ((struct msgs *) 0)
348
349 /*
350 * m_getfld() message parsing
351 */
352
353 #define NAMESZ 999 /* Limit on component name size.
354 RFC 2822 limits line lengths to
355 998 characters, so a header name
356 can be at most that long.
357 m_getfld limits header names to 2
358 less than NAMESZ, which is fine,
359 because header names must be
360 followed by a colon. Add one for
361 terminating NULL. */
362
363 #define LENERR (-2) /* Name too long error from getfld */
364 #define FMTERR (-3) /* Message Format error */
365 #define FLD 0 /* Field returned */
366 #define FLDPLUS 1 /* Field returned with more to come */
367 #define BODY 3 /* Body returned with more to come */
368 #define FILEEOF 5 /* Reached end of input file */
369
370 struct m_getfld_state;
371 typedef struct m_getfld_state *m_getfld_state_t;
372
373 /*
374 * Maildrop styles
375 */
376 #define MS_DEFAULT 0 /* default (one msg per file) */
377 #define MS_UNKNOWN 1 /* type not known yet */
378 #define MS_MBOX 2 /* Unix-style "from" lines */
379 #define MS_MMDF 3 /* string mmdlm2 */
380
381 #define NOUSE 0 /* draft being re-used */
382
383 #define TFOLDER 0 /* path() given a +folder */
384 #define TFILE 1 /* path() given a file */
385 #define TSUBCWF 2 /* path() given a @folder */
386
387 #define OUTPUTLINELEN 72 /* default line length for headers */
388
389 #define LINK "@" /* Name of link to file to which you are */
390 /* replying. */
391
392 /*
393 * credentials management
394 */
395 struct nmh_creds {
396 char *host;
397 char *user;
398 char *password;
399 };
400
401 typedef struct nmh_creds *nmh_creds_t;
402
403 /*
404 * miscellaneous macros
405 */
406 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
407
408 #ifndef max
409 # define max(a,b) ((a) > (b) ? (a) : (b))
410 #endif
411
412 #ifndef min
413 # define min(a,b) ((a) < (b) ? (a) : (b))
414 #endif
415
416 #ifndef abs
417 # define abs(a) ((a) > 0 ? (a) : -(a))
418 #endif
419
420 /*
421 * GLOBAL VARIABLES
422 */
423 #define CTXMOD 0x01 /* context information modified */
424 #define DBITS "\020\01CTXMOD"
425 extern char ctxflags;
426
427 extern char *invo_name; /* command invocation name */
428 extern char *mypath; /* user's $HOME */
429 extern char *defpath; /* pathname of user's profile */
430 extern char *ctxpath; /* pathname of user's context */
431 extern struct node *m_defs; /* list of profile/context entries */
432
433 /* What style to use for generated Message-ID and Content-ID header
434 fields. The localname style is pid.time@localname, where time is
435 in seconds. The random style replaces the localname with some
436 (pseudo)random bytes and uses microsecond-resolution time. */
437 int save_message_id_style (const char *);
438 char *message_id (time_t, int);
439
440 /*
441 * These standard strings are defined in config.c. They are the
442 * only system-dependent parameters in nmh, and thus by redefining
443 * their values and reloading the various modules, nmh will run
444 * on any system.
445 */
446 extern char *buildmimeproc;
447 extern char *catproc;
448 extern char *components;
449 extern char *context;
450 extern char *current;
451 extern char *credentials_file;
452 extern int credentials_no_perm_check;
453 extern char *defaultfolder;
454 extern char *digestcomps;
455 extern char *distcomps;
456 extern char *draft;
457 extern char *fileproc;
458 extern char *foldprot;
459 extern char *formatproc;
460 extern char *forwcomps;
461 extern char *inbox;
462 extern char *incproc;
463 extern char *lproc;
464 extern char *mailproc;
465 extern char *mh_defaults;
466 extern char *mh_profile;
467 extern char *mh_seq;
468 extern char *mhlformat;
469 extern char *mhlforward;
470 extern char *mhlproc;
471 extern char *mhlreply;
472 extern char *moreproc;
473 extern char *msgprot;
474 extern char *nmhaccessftp;
475 extern char *nmhaccessurl;
476 extern char *nmhstorage;
477 extern char *nmhcache;
478 extern char *nmhprivcache;
479 extern char *nsequence;
480 extern char *packproc;
481 extern char *postproc;
482 extern char *pfolder;
483 extern char *psequence;
484 extern char *rcvdistcomps;
485 extern char *rcvstoreproc;
486 extern char *replcomps;
487 extern char *replgroupcomps;
488 extern char *rmmproc;
489 extern char *sendproc;
490 extern char *showmimeproc;
491 extern char *showproc;
492 extern char *usequence;
493 extern char *user_agent;
494 extern char *version_num;
495 extern char *version_str;
496 extern char *whatnowproc;
497 extern char *whomproc;
498
499 extern void (*done) (int) NORETURN;
500
501 #include <h/prototypes.h>
502