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