def.h revision 1.21 1 /* $NetBSD: def.h,v 1.21 2006/10/31 20:07:32 christos Exp $ */
2 /*
3 * Copyright (c) 1980, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * @(#)def.h 8.4 (Berkeley) 4/20/95
31 * $NetBSD: def.h,v 1.21 2006/10/31 20:07:32 christos Exp $
32 */
33
34 /*
35 * Mail -- a mail program
36 *
37 * Author: Kurt Shoens (UCB) March 25, 1978
38 */
39
40 #ifndef __DEF_H__
41 #define __DEF_H__
42
43 #include <sys/types.h>
44 #include <sys/file.h>
45 #include <sys/ioctl.h>
46 #include <sys/stat.h>
47 #include <sys/param.h>
48 #include <sys/time.h>
49 #include <sys/wait.h>
50
51 #include <ctype.h>
52 #include <err.h>
53 #include <errno.h>
54 #include <fcntl.h>
55 #include <paths.h>
56 #include <pwd.h>
57 #include <signal.h>
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <string.h>
61 #include <termios.h>
62 #include <time.h>
63 #include <unistd.h>
64 #include "pathnames.h"
65
66 #define APPEND /* New mail goes to end of mailbox */
67
68 #define COMMENT_CHAR '#' /* Comment character when sourcing */
69 #define ESCAPE '~' /* Default escape for sending */
70 #define NMLSIZE 1024 /* max names in a message list */
71 #define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */
72 #define HSHSIZE 59 /* Hash size for aliases and vars */
73 #define LINESIZE BUFSIZ /* max readable line width */
74 #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
75 #define MAXARGC 1024 /* Maximum list of raw strings */
76 #define MAXEXP 25 /* Maximum expansion of aliases */
77
78 /*
79 * User environment variable names.
80 * (See complete.h and mime.h for names specific to those modules.)
81 */
82 #ifdef SMOPTS_CMD
83 #define ENAME_SMOPTS_VERIFY "smopts-verify"
84 #endif
85 #define ENAME_RECORD "record"
86
87 #define sizeofarray(a) (sizeof(a)/sizeof(*a))
88 #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
89
90 #define readline mail_readline
91
92 struct message {
93 short m_flag; /* flags, see below */
94 short m_offset; /* offset in block of message */
95 long m_block; /* block number of this message */
96 long m_lines; /* Lines in the message */
97 off_t m_size; /* Bytes in the message */
98 long m_blines; /* Body (non-header) lines */
99 };
100 typedef struct mime_info mime_info_t; /* phantom structure only to attach.c */
101
102 /*
103 * flag bits.
104 */
105
106 #define MUSED (1<<0) /* entry is used, but this bit isn't */
107 #define MDELETED (1<<1) /* entry has been deleted */
108 #define MSAVED (1<<2) /* entry has been saved */
109 #define MTOUCH (1<<3) /* entry has been noticed */
110 #define MPRESERVE (1<<4) /* keep entry in sys mailbox */
111 #define MMARK (1<<5) /* message is marked! */
112 #define MODIFY (1<<6) /* message has been modified */
113 #define MNEW (1<<7) /* message has never been seen */
114 #define MREAD (1<<8) /* message has been read sometime. */
115 #define MSTATUS (1<<9) /* message status has changed */
116 #define MBOX (1<<10) /* Send this to mbox, regardless */
117
118 /*
119 * Given a file address, determine the block number it represents.
120 */
121 #define blockof(off) ((int) ((off) / 4096))
122 #define offsetof(off) ((int) ((off) % 4096))
123 #define positionof(block, offset) ((off_t)(block) * 4096 + (offset))
124
125 /*
126 * Format of the command description table.
127 * The actual table is declared and initialized
128 * in lex.c
129 */
130 struct cmd {
131 const char *c_name; /* Name of command */
132 int (*c_func)(void *); /* Implementor of the command */
133 #ifdef USE_EDITLINE
134 const char *c_complete; /* String describing completion */
135 #endif
136 short c_argtype; /* Type of arglist (see below) */
137 short c_msgflag; /* Required flags of messages */
138 short c_msgmask; /* Relevant flags of messages */
139 };
140
141 /* Yechh, can't initialize unions */
142
143 #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
144 #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
145
146 /*
147 * Argument types.
148 */
149
150 #define MSGLIST 0 /* Message list type */
151 #define STRLIST 1 /* A pure string */
152 #define RAWLIST 2 /* Shell string list */
153 #define NOLIST 3 /* Just plain 0 */
154 #define NDMLIST 4 /* Message list, no defaults */
155
156 #define P 040 /* Autoprint dot after command */
157 #define I 0100 /* Interactive command bit */
158 #define M 0200 /* Legal from send mode bit */
159 #define W 0400 /* Illegal when read only bit */
160 #define F 01000 /* Is a conditional command */
161 #define T 02000 /* Is a transparent command */
162 #define R 04000 /* Cannot be called from collect */
163
164 /*
165 * Oft-used mask values
166 */
167
168 #define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */
169 #define MMNDEL MDELETED /* Look only at deleted bit */
170
171 /*
172 * Structure used to return a break down of a head
173 * line (hats off to Bill Joy!)
174 */
175
176 struct headline {
177 char *l_from; /* The name of the sender */
178 char *l_tty; /* His tty string (if any) */
179 char *l_date; /* The entire date string */
180 };
181
182 #define GTO 0x001 /* Grab To: line */
183 #define GSUBJECT 0x002 /* Likewise, Subject: line */
184 #define GCC 0x004 /* And the Cc: line */
185 #define GBCC 0x008 /* And also the Bcc: line */
186 #define GSMOPTS 0x010 /* Grab the sendmail options */
187 #ifdef MIME_SUPPORT
188 #define GMIME 0x020 /* mime flag */
189 #endif
190 #define GMASK (GTO|GSUBJECT|GCC|GBCC|GSMOPTS)
191 /* Mask of places from whence */
192
193 #define GNL 0x100 /* Print blank line after */
194 #define GDEL 0x200 /* Entity removed from list */
195 #define GCOMMA 0x400 /* detract puts in commas */
196
197 #ifdef MIME_SUPPORT
198 /*
199 * Structure of MIME content.
200 */
201 struct Content {
202 const char *C_type; /* content type */
203 const char *C_encoding; /* content transfer encoding */
204 const char *C_disposition; /* content disposition */
205 const char *C_description; /* content description */
206 const char *C_id; /* content id */
207 };
208 /* Header strings corresponding to the above Content fields. */
209 #define MIME_HDR_TYPE "Content-Type"
210 #define MIME_HDR_ENCODING "Content-Transfer-Encoding"
211 #define MIME_HDR_DISPOSITION "Content-Disposition"
212 #define MIME_HDR_ID "Content-ID"
213 #define MIME_HDR_DESCRIPTION "Content-Description"
214 #define MIME_HDR_VERSION "MIME-Version"
215 /* the value of the MIME-Version field */
216 #define MIME_VERSION "1.0"
217
218 typedef enum {
219 ATTACH_INVALID = 0, /* do not use! */
220 ATTACH_FNAME = 1,
221 ATTACH_MSG = 2,
222 ATTACH_FILENO = 3
223 } attach_t;
224
225 /*
226 * Structure of a MIME attachment.
227 */
228 struct attachment {
229 struct attachment *a_flink; /* Forward link in list. */
230 struct attachment *a_blink; /* Backward list link */
231
232 attach_t a_type; /* attachment type */
233 #if 1
234 union {
235 char *u_name; /* file name */
236 struct message *u_msg; /* message */
237 int u_fileno; /* file number */
238 } a_u;
239
240 #define a_name a_u.u_name
241 #define a_msg a_u.u_msg
242 #define a_fileno a_u.u_fileno
243 #else
244 char *a_name; /* file name */
245 struct message *a_msg; /* message */
246 int a_fileno; /* file number */
247 #endif
248
249 struct Content a_Content; /* MIME content strings */
250 };
251 #endif /* MIME_SUPPORT */
252
253 /*
254 * Structure used to pass about the current
255 * state of the user-typed message header.
256 */
257
258 struct header {
259 struct name *h_to; /* Dynamic "To:" string */
260 char *h_subject; /* Subject string */
261 struct name *h_cc; /* Carbon copies string */
262 struct name *h_bcc; /* Blind carbon copies */
263 struct name *h_smopts; /* Sendmail options */
264 #ifdef MIME_SUPPORT
265 char *h_mime_boundary; /* MIME multipart boundary string */
266 struct Content h_Content; /* MIME content for message */
267 struct attachment *h_attach; /* MIME attachments */
268 #endif
269 };
270
271 /*
272 * Structure of namelist nodes used in processing
273 * the recipients of mail and aliases and all that
274 * kind of stuff.
275 */
276
277 struct name {
278 struct name *n_flink; /* Forward link in list. */
279 struct name *n_blink; /* Backward list link */
280 short n_type; /* From which list it came */
281 char *n_name; /* This fella's name */
282 };
283
284 /*
285 * Structure of a variable node. All variables are
286 * kept on a singly-linked list of these, rooted by
287 * "variables"
288 */
289
290 struct var {
291 struct var *v_link; /* Forward link to next variable */
292 char *v_name; /* The variable's name */
293 char *v_value; /* And it's current value */
294 };
295
296 struct group {
297 struct group *ge_link; /* Next person in this group */
298 char *ge_name; /* This person's user name */
299 };
300
301 struct grouphead {
302 struct grouphead *g_link; /* Next grouphead in list */
303 char *g_name; /* Name of this group */
304 struct group *g_list; /* Users in group. */
305 };
306
307 #ifdef SMOPTS_CMD
308 struct smopts_s {
309 struct smopts_s *s_link; /* Link to next smopts_s in list */
310 char *s_name; /* Name of this smopts_s */
311 struct name *s_smopts; /* sendmail options name list */
312 };
313 #endif /* SMOPTS_CMD */
314
315
316 /*
317 * Structure of the hash table of ignored header fields
318 */
319 struct ignoretab {
320 size_t i_count; /* Number of entries */
321 struct ignore {
322 struct ignore *i_link; /* Next ignored field in bucket */
323 char *i_field; /* This ignored field */
324 } *i_head[HSHSIZE];
325 };
326
327 /*
328 * Token values returned by the scanner used for argument lists.
329 * Also, sizes of scanner-related things.
330 */
331
332 #define TEOL 0 /* End of the command line */
333 #define TNUMBER 1 /* A message number */
334 #define TDASH 2 /* A simple dash */
335 #define TSTRING 3 /* A string (possibly containing -) */
336 #define TDOT 4 /* A "." */
337 #define TUP 5 /* An "^" */
338 #define TDOLLAR 6 /* A "$" */
339 #define TSTAR 7 /* A "*" */
340 #define TOPEN 8 /* An '(' */
341 #define TCLOSE 9 /* A ')' */
342 #define TPLUS 10 /* A '+' */
343 #define TERROR 11 /* A lexical error */
344
345 #define REGDEP 2 /* Maximum regret depth. */
346 #define STRINGLEN 1024 /* Maximum length of string token */
347
348 /*
349 * Constants for conditional commands. These describe whether
350 * we should be executing stuff or not.
351 */
352
353 #define CANY 0 /* Execute in send or receive mode */
354 #define CRCV 1 /* Execute in receive mode only */
355 #define CSEND 2 /* Execute in send mode only */
356
357 /*
358 * Kludges to handle the change from setexit / reset to setjmp / longjmp
359 */
360
361 #define setexit() (void)setjmp(srbuf)
362 #define reset(x) longjmp(srbuf, x)
363
364 /*
365 * Truncate a file to the last character written. This is
366 * useful just before closing an old file that was opened
367 * for read/write.
368 */
369 #define trunc(stream) { \
370 (void)fflush(stream); \
371 (void)ftruncate(fileno(stream), (off_t)ftell(stream)); \
372 }
373
374 /*
375 * Make this static inline available everywhere.
376 */
377 static inline char*
378 skip_white(char *cp)
379 {
380 while (isblank((unsigned char)*cp))
381 cp++;
382 return cp;
383 }
384
385 #endif /* __DEF_H__ */
386