Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / ehlo_mask.c
blob024200dbc50520d32215d6b79a4643d67ee3b6d6
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* ehlo_mask 3
6 /* SUMMARY
7 /* map EHLO keywords to bit mask
8 /* SYNOPSIS
9 /* #include <ehlo_mask.h>
11 /* #define EHLO_MASK_8BITMIME (1<<0)
12 /* #define EHLO_MASK_PIPELINING (1<<1)
13 /* #define EHLO_MASK_SIZE (1<<2)
14 /* #define EHLO_MASK_VRFY (1<<3)
15 /* #define EHLO_MASK_ETRN (1<<4)
16 /* #define EHLO_MASK_AUTH (1<<5)
17 /* #define EHLO_MASK_VERP (1<<6)
18 /* #define EHLO_MASK_STARTTLS (1<<7)
19 /* #define EHLO_MASK_XCLIENT (1<<8)
20 /* #define EHLO_MASK_XFORWARD (1<<9)
21 /* #define EHLO_MASK_ENHANCEDSTATUSCODES (1<<10)
22 /* #define EHLO_MASK_DSN (1<<11)
23 /* #define EHLO_MASK_SILENT (1<<15)
25 /* int ehlo_mask(keyword_list)
26 /* const char *keyword_list;
28 /* const char *str_ehlo_mask(bitmask)
29 /* int bitmask;
30 /* DESCRIPTION
31 /* ehlo_mask() computes the bit-wise OR of the masks that correspond
32 /* to the names listed in the \fIkeyword_list\fR argument, separated by
33 /* comma and/or whitespace characters. Undefined names are silently
34 /* ignored.
36 /* str_ehlo_mask() translates a mask into its equivalent names.
37 /* The result is written to a static buffer that is overwritten
38 /* upon each call. Undefined bits cause a fatal run-time error.
39 /* DIAGNOSTICS
40 /* Fatal: str_ehlo_mask() found an undefined bit.
41 /* LICENSE
42 /* .ad
43 /* .fi
44 /* The Secure Mailer license must be distributed with this software.
45 /* AUTHOR(S)
46 /* Wietse Venema
47 /* IBM T.J. Watson Research
48 /* P.O. Box 704
49 /* Yorktown Heights, NY 10598, USA
50 /*--*/
52 /* System library.*/
54 #include <sys_defs.h>
56 /* Utility library. */
58 #include <name_mask.h>
60 /* Global library. */
62 #include <ehlo_mask.h>
65 * The lookup table.
67 static const NAME_MASK ehlo_mask_table[] = {
68 "8BITMIME", EHLO_MASK_8BITMIME,
69 "AUTH", EHLO_MASK_AUTH,
70 "ETRN", EHLO_MASK_ETRN,
71 "PIPELINING", EHLO_MASK_PIPELINING,
72 "SIZE", EHLO_MASK_SIZE,
73 "VERP", EHLO_MASK_VERP,
74 "VRFY", EHLO_MASK_VRFY,
75 "XCLIENT", EHLO_MASK_XCLIENT,
76 "XFORWARD", EHLO_MASK_XFORWARD,
77 "STARTTLS", EHLO_MASK_STARTTLS,
78 "ENHANCEDSTATUSCODES", EHLO_MASK_ENHANCEDSTATUSCODES,
79 "DSN", EHLO_MASK_DSN,
80 "SILENT-DISCARD", EHLO_MASK_SILENT, /* XXX In-band signaling */
84 /* ehlo_mask - string to bit mask */
86 int ehlo_mask(const char *mask_str)
90 * We allow "STARTTLS" besides "starttls, because EHLO keywords are often
91 * spelled in uppercase. We ignore non-existent EHLO keywords so people
92 * can switch between Postfix versions without trouble.
94 return (name_mask_opt("ehlo string mask", ehlo_mask_table,
95 mask_str, NAME_MASK_ANY_CASE));
98 /* str_ehlo_mask - mask to string */
100 const char *str_ehlo_mask(int mask_bits)
104 * We don't allow non-existent bits. Doing so makes no sense at this
105 * time.
107 return (str_name_mask("ehlo bitmask", ehlo_mask_table, mask_bits));
110 #ifdef TEST
113 * Stand-alone test program.
115 #include <stdlib.h>
116 #include <vstream.h>
117 #include <vstring.h>
118 #include <vstring_vstream.h>
120 int main(int unused_argc, char **unused_argv)
122 int mask_bits;
123 VSTRING *buf = vstring_alloc(1);
124 const char *mask_string;
126 while (vstring_get_nonl(buf, VSTREAM_IN) != VSTREAM_EOF) {
127 mask_bits = ehlo_mask(vstring_str(buf));
128 mask_string = str_ehlo_mask(mask_bits);
129 vstream_printf("%s -> 0x%x -> %s\n", vstring_str(buf), mask_bits,
130 mask_string);
131 vstream_fflush(VSTREAM_OUT);
133 vstring_free(buf);
134 exit(0);
137 #endif