Commit | Line | Data |
---|---|---|
d185889f JH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
5 | /* Copyright (c) Jeremy Harris 2017 */ | |
6 | /* See the file NOTICE for conditions of use and distribution. */ | |
7 | ||
8 | /* Create a static data structure with the predefined macros, to be | |
9 | included in the main Exim build */ | |
10 | ||
11 | #include "exim.h" | |
12 | #include "macro_predef.h" | |
13 | ||
14 | unsigned mp_index = 0; | |
15 | ||
16 | /* Global dummy variables */ | |
17 | ||
18 | void fn_smtp_receive_timeout(const uschar * name, const uschar * str) {} | |
19 | uschar * syslog_facility_str; | |
20 | ||
21 | /******************************************************************************/ | |
22 | ||
23 | void | |
24 | builtin_macro_create(const uschar * name) | |
25 | { | |
26 | printf ("static macro_item p%d = { ", mp_index); | |
27 | if (mp_index == 0) | |
28 | printf("NULL,"); | |
29 | else | |
30 | printf("&p%d,", mp_index-1); | |
31 | ||
32 | printf(" FALSE, %d, \"%s\", \"y\" };\n", Ustrlen(name), name); | |
33 | mp_index++; | |
34 | } | |
35 | ||
36 | static void | |
37 | spf(uschar * buf, int len, const uschar * fmt, ...) | |
38 | { | |
39 | va_list ap; | |
40 | va_start(ap, fmt); | |
41 | ||
42 | while (*fmt && len > 1) | |
43 | if (*fmt == '%' && fmt[1] == 'T') | |
44 | { | |
45 | uschar * s = va_arg(ap, uschar *); | |
46 | while (*s && len-- > 1) | |
47 | *buf++ = toupper(*s++); | |
48 | fmt += 2; | |
49 | } | |
50 | else | |
51 | { | |
52 | *buf++ = *fmt++; len--; | |
53 | } | |
54 | *buf = '\0'; | |
55 | va_end(ap); | |
56 | } | |
57 | ||
58 | void | |
59 | options_from_list(optionlist * opts, unsigned nopt, | |
60 | const uschar * section, uschar * group) | |
61 | { | |
62 | int i; | |
63 | const uschar * s; | |
64 | uschar buf[64]; | |
65 | ||
66 | /* The 'previously-defined-substring' rule for macros in config file | |
67 | lines is done thus for these builtin macros: we know that the table | |
68 | we source from is in strict alpha order, hence the builtins portion | |
69 | of the macros list is in reverse-alpha (we prepend them) - so longer | |
70 | macros that have substrings are always discovered first during | |
71 | expansion. */ | |
72 | ||
73 | for (i = 0; i < nopt; i++) if (*(s = US opts[i].name) && *s != '*') | |
74 | { | |
75 | if (group) | |
76 | spf(buf, sizeof(buf), "_OPT_%T_%T_%T", section, group, s); | |
77 | else | |
78 | spf(buf, sizeof(buf), "_OPT_%T_%T", section, s); | |
79 | builtin_macro_create(buf); | |
80 | } | |
81 | } | |
82 | ||
83 | ||
84 | /******************************************************************************/ | |
85 | ||
86 | ||
87 | /* Create compile-time feature macros */ | |
88 | static void | |
89 | features(void) | |
90 | { | |
91 | /* Probably we could work out a static initialiser for wherever | |
92 | macros are stored, but this will do for now. Some names are awkward | |
93 | due to conflicts with other common macros. */ | |
94 | ||
95 | #ifdef SUPPORT_CRYPTEQ | |
96 | builtin_macro_create(US"_HAVE_CRYPTEQ"); | |
97 | #endif | |
98 | #if HAVE_ICONV | |
99 | builtin_macro_create(US"_HAVE_ICONV"); | |
100 | #endif | |
101 | #if HAVE_IPV6 | |
102 | builtin_macro_create(US"_HAVE_IPV6"); | |
103 | #endif | |
104 | #ifdef HAVE_SETCLASSRESOURCES | |
105 | builtin_macro_create(US"_HAVE_SETCLASSRESOURCES"); | |
106 | #endif | |
107 | #ifdef SUPPORT_PAM | |
108 | builtin_macro_create(US"_HAVE_PAM"); | |
109 | #endif | |
110 | #ifdef EXIM_PERL | |
111 | builtin_macro_create(US"_HAVE_PERL"); | |
112 | #endif | |
113 | #ifdef EXPAND_DLFUNC | |
114 | builtin_macro_create(US"_HAVE_DLFUNC"); | |
115 | #endif | |
116 | #ifdef USE_TCP_WRAPPERS | |
117 | builtin_macro_create(US"_HAVE_TCPWRAPPERS"); | |
118 | #endif | |
119 | #ifdef SUPPORT_TLS | |
120 | builtin_macro_create(US"_HAVE_TLS"); | |
121 | # ifdef USE_GNUTLS | |
122 | builtin_macro_create(US"_HAVE_GNUTLS"); | |
123 | # else | |
124 | builtin_macro_create(US"_HAVE_OPENSSL"); | |
125 | # endif | |
126 | #endif | |
127 | #ifdef SUPPORT_TRANSLATE_IP_ADDRESS | |
128 | builtin_macro_create(US"_HAVE_TRANSLATE_IP_ADDRESS"); | |
129 | #endif | |
130 | #ifdef SUPPORT_MOVE_FROZEN_MESSAGES | |
131 | builtin_macro_create(US"_HAVE_MOVE_FROZEN_MESSAGES"); | |
132 | #endif | |
133 | #ifdef WITH_CONTENT_SCAN | |
134 | builtin_macro_create(US"_HAVE_CONTENT_SCANNING"); | |
135 | #endif | |
136 | #ifndef DISABLE_DKIM | |
137 | builtin_macro_create(US"_HAVE_DKIM"); | |
138 | #endif | |
139 | #ifndef DISABLE_DNSSEC | |
140 | builtin_macro_create(US"_HAVE_DNSSEC"); | |
141 | #endif | |
142 | #ifndef DISABLE_EVENT | |
143 | builtin_macro_create(US"_HAVE_EVENT"); | |
144 | #endif | |
145 | #ifdef SUPPORT_I18N | |
146 | builtin_macro_create(US"_HAVE_I18N"); | |
147 | #endif | |
148 | #ifndef DISABLE_OCSP | |
149 | builtin_macro_create(US"_HAVE_OCSP"); | |
150 | #endif | |
151 | #ifndef DISABLE_PRDR | |
152 | builtin_macro_create(US"_HAVE_PRDR"); | |
153 | #endif | |
154 | #ifdef SUPPORT_PROXY | |
155 | builtin_macro_create(US"_HAVE_PROXY"); | |
156 | #endif | |
157 | #ifdef SUPPORT_SOCKS | |
158 | builtin_macro_create(US"_HAVE_SOCKS"); | |
159 | #endif | |
160 | #ifdef TCP_FASTOPEN | |
161 | builtin_macro_create(US"_HAVE_TCP_FASTOPEN"); | |
162 | #endif | |
163 | #ifdef EXPERIMENTAL_LMDB | |
164 | builtin_macro_create(US"_HAVE_LMDB"); | |
165 | #endif | |
166 | #ifdef EXPERIMENTAL_SPF | |
167 | builtin_macro_create(US"_HAVE_SPF"); | |
168 | #endif | |
169 | #ifdef EXPERIMENTAL_SRS | |
170 | builtin_macro_create(US"_HAVE_SRS"); | |
171 | #endif | |
172 | #ifdef EXPERIMENTAL_BRIGHTMAIL | |
173 | builtin_macro_create(US"_HAVE_BRIGHTMAIL"); | |
174 | #endif | |
175 | #ifdef EXPERIMENTAL_DANE | |
176 | builtin_macro_create(US"_HAVE_DANE"); | |
177 | #endif | |
178 | #ifdef EXPERIMENTAL_DCC | |
179 | builtin_macro_create(US"_HAVE_DCC"); | |
180 | #endif | |
181 | #ifdef EXPERIMENTAL_DMARC | |
182 | builtin_macro_create(US"_HAVE_DMARC"); | |
183 | #endif | |
184 | #ifdef EXPERIMENTAL_DSN_INFO | |
185 | builtin_macro_create(US"_HAVE_DSN_INFO"); | |
186 | #endif | |
187 | ||
188 | #ifdef LOOKUP_LSEARCH | |
189 | builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH"); | |
190 | #endif | |
191 | #ifdef LOOKUP_CDB | |
192 | builtin_macro_create(US"_HAVE_LOOKUP_CDB"); | |
193 | #endif | |
194 | #ifdef LOOKUP_DBM | |
195 | builtin_macro_create(US"_HAVE_LOOKUP_DBM"); | |
196 | #endif | |
197 | #ifdef LOOKUP_DNSDB | |
198 | builtin_macro_create(US"_HAVE_LOOKUP_DNSDB"); | |
199 | #endif | |
200 | #ifdef LOOKUP_DSEARCH | |
201 | builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH"); | |
202 | #endif | |
203 | #ifdef LOOKUP_IBASE | |
204 | builtin_macro_create(US"_HAVE_LOOKUP_IBASE"); | |
205 | #endif | |
206 | #ifdef LOOKUP_LDAP | |
207 | builtin_macro_create(US"_HAVE_LOOKUP_LDAP"); | |
208 | #endif | |
209 | #ifdef EXPERIMENTAL_LMDB | |
210 | builtin_macro_create(US"_HAVE_LOOKUP_LMDB"); | |
211 | #endif | |
212 | #ifdef LOOKUP_MYSQL | |
213 | builtin_macro_create(US"_HAVE_LOOKUP_MYSQL"); | |
214 | #endif | |
215 | #ifdef LOOKUP_NIS | |
216 | builtin_macro_create(US"_HAVE_LOOKUP_NIS"); | |
217 | #endif | |
218 | #ifdef LOOKUP_NISPLUS | |
219 | builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS"); | |
220 | #endif | |
221 | #ifdef LOOKUP_ORACLE | |
222 | builtin_macro_create(US"_HAVE_LOOKUP_ORACLE"); | |
223 | #endif | |
224 | #ifdef LOOKUP_PASSWD | |
225 | builtin_macro_create(US"_HAVE_LOOKUP_PASSWD"); | |
226 | #endif | |
227 | #ifdef LOOKUP_PGSQL | |
228 | builtin_macro_create(US"_HAVE_LOOKUP_PGSQL"); | |
229 | #endif | |
230 | #ifdef LOOKUP_REDIS | |
231 | builtin_macro_create(US"_HAVE_LOOKUP_REDIS"); | |
232 | #endif | |
233 | #ifdef LOOKUP_SQLITE | |
234 | builtin_macro_create(US"_HAVE_LOOKUP_SQLITE"); | |
235 | #endif | |
236 | #ifdef LOOKUP_TESTDB | |
237 | builtin_macro_create(US"_HAVE_LOOKUP_TESTDB"); | |
238 | #endif | |
239 | #ifdef LOOKUP_WHOSON | |
240 | builtin_macro_create(US"_HAVE_LOOKUP_WHOSON"); | |
241 | #endif | |
242 | ||
243 | #ifdef TRANSPORT_APPENDFILE | |
244 | # ifdef SUPPORT_MAILDIR | |
245 | builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR"); | |
246 | # endif | |
247 | # ifdef SUPPORT_MAILSTORE | |
248 | builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE"); | |
249 | # endif | |
250 | # ifdef SUPPORT_MBX | |
251 | builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX"); | |
252 | # endif | |
253 | #endif | |
254 | } | |
255 | ||
256 | ||
257 | static void | |
258 | options(void) | |
259 | { | |
260 | options_main(); | |
261 | options_routers(); | |
262 | options_transports(); | |
263 | options_auths(); | |
264 | } | |
265 | ||
266 | ||
267 | int | |
268 | main(void) | |
269 | { | |
270 | printf("#include \"exim.h\"\n"); | |
271 | features(); | |
272 | options(); | |
273 | ||
274 | printf("macro_item * macros = &p%d;\n", mp_index-1); | |
275 | printf("macro_item * mlast = &p0;\n"); | |
276 | } |