Testsuite: munge for non-WITH_CONTENT_SCAN builds
[exim.git] / src / src / macro_predef.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2023 */
6 /* Copyright (c) Jeremy Harris 1995 - 2018 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
9
10 /* Create a static data structure with the predefined macros, to be
11 included in the main Exim build */
12
13 #include "exim.h"
14 #include "macro_predef.h"
15
16 unsigned mp_index = 0;
17
18 /* Global dummy variables */
19
20 void fn_smtp_receive_timeout(const uschar * name, const uschar * str) {}
21 uschar * syslog_facility_str;
22
23 /******************************************************************************/
24
25 void
26 builtin_macro_create_var(const uschar * name, const uschar * val)
27 {
28 printf ("static macro_item p%d = { ", mp_index);
29 if (mp_index == 0)
30   printf(".next=NULL,");
31 else
32   printf(".next=&p%d,", mp_index-1);
33
34 printf(" .command_line=FALSE, .namelen=%d, .replen=%d,"
35         " .name=US\"%s\", .replacement=US\"%s\" };\n",
36         Ustrlen(name), Ustrlen(val), CS name, CS val);
37 mp_index++;
38 }
39
40
41 void
42 builtin_macro_create(const uschar * name)
43 {
44 builtin_macro_create_var(name, US"y");
45 }
46
47
48 /* restricted snprintf */
49 void
50 spf(uschar * buf, int len, const uschar * fmt, ...)
51 {
52 va_list ap;
53 va_start(ap, fmt);
54
55 while (*fmt && len > 1)
56   if (*fmt == '%' && fmt[1] == 'T')
57     {
58     uschar * s = va_arg(ap, uschar *);
59     while (*s && len-- > 1)
60       *buf++ = toupper(*s++);
61     fmt += 2;
62     }
63   else
64     {
65     *buf++ = *fmt++; len--;
66     }
67 *buf = '\0';
68 va_end(ap);
69 }
70
71 void
72 options_from_list(optionlist * opts, unsigned nopt,
73   const uschar * section, uschar * group)
74 {
75 const uschar * s;
76 uschar buf[EXIM_DRIVERNAME_MAX];
77
78 /* The 'previously-defined-substring' rule for macros in config file
79 lines is done thus for these builtin macros: we know that the table
80 we source from is in strict alpha order, hence the builtins portion
81 of the macros list is in reverse-alpha (we prepend them) - so longer
82 macros that have substrings are always discovered first during
83 expansion. */
84
85 for (int i = 0; i < nopt; i++)  if (*(s = US opts[i].name) && *s != '*')
86   {
87   if (group)
88     spf(buf, sizeof(buf), CUS"_OPT_%T_%T_%T", section, group, s);
89   else
90     spf(buf, sizeof(buf), CUS"_OPT_%T_%T", section, s);
91   builtin_macro_create(buf);
92   }
93 }
94
95
96 /******************************************************************************/
97
98
99 /* Create compile-time feature macros */
100 static void
101 features(void)
102 {
103 /* Probably we could work out a static initialiser for wherever
104 macros are stored, but this will do for now. Some names are awkward
105 due to conflicts with other common macros. */
106
107 #ifdef SUPPORT_CRYPTEQ
108   builtin_macro_create(US"_HAVE_CRYPTEQ");
109 #endif
110 #if HAVE_ICONV
111   builtin_macro_create(US"_HAVE_ICONV");
112 #endif
113 #if HAVE_IPV6
114   builtin_macro_create(US"_HAVE_IPV6");
115 #endif
116 #ifdef HAVE_SETCLASSRESOURCES
117   builtin_macro_create(US"_HAVE_SETCLASSRESOURCES");
118 #endif
119 #ifdef SUPPORT_PAM
120   builtin_macro_create(US"_HAVE_PAM");
121 #endif
122 #ifdef RADIUS_CONFIG_FILE
123   builtin_macro_create(US"_HAVE_RADIUS");
124 #endif
125 #ifdef CYRUS_PWCHECK_SOCKET
126   builtin_macro_create(US"_HAVE_PWCHECK");
127 #endif
128 #ifdef EXIM_PERL
129   builtin_macro_create(US"_HAVE_PERL");
130 #endif
131 #ifdef EXPAND_DLFUNC
132   builtin_macro_create(US"_HAVE_DLFUNC");
133 #endif
134 #ifdef USE_TCP_WRAPPERS
135   builtin_macro_create(US"_HAVE_TCPWRAPPERS");
136 #endif
137 #ifndef DISABLE_TLS
138   builtin_macro_create(US"_HAVE_TLS");
139 # ifdef USE_GNUTLS
140   builtin_macro_create(US"_HAVE_GNUTLS");
141 # else
142   builtin_macro_create(US"_HAVE_OPENSSL");
143 # endif
144 #endif
145 #ifdef SUPPORT_TRANSLATE_IP_ADDRESS
146   builtin_macro_create(US"_HAVE_TRANSLATE_IP_ADDRESS");
147 #endif
148 #ifdef SUPPORT_MOVE_FROZEN_MESSAGES
149   builtin_macro_create(US"_HAVE_MOVE_FROZEN_MESSAGES");
150 #endif
151 #ifdef WITH_CONTENT_SCAN
152   builtin_macro_create(US"_HAVE_CONTENT_SCANNING");
153 #endif
154 #ifndef DISABLE_DKIM
155   builtin_macro_create(US"_HAVE_DKIM");
156 #endif
157 #ifdef SUPPORT_DMARC
158   builtin_macro_create(US"_HAVE_DMARC");
159 #endif
160 #ifndef DISABLE_DNSSEC
161   builtin_macro_create(US"_HAVE_DNSSEC");
162 #endif
163 #ifndef DISABLE_ESMTP_LIMITS
164   builtin_macro_create(US"_HAVE_ESMTP_LIMITS");
165 #endif
166 #ifndef DISABLE_EVENT
167   builtin_macro_create(US"_HAVE_EVENT");
168 #endif
169 #ifdef SUPPORT_I18N
170   builtin_macro_create(US"_HAVE_I18N");
171 #endif
172 #ifndef DISABLE_OCSP
173   builtin_macro_create(US"_HAVE_OCSP");
174 #endif
175 #ifndef DISABLE_PIPE_CONNECT
176   builtin_macro_create(US"_HAVE_PIPE_CONNECT");
177 #endif
178 #ifndef DISABLE_PRDR
179   builtin_macro_create(US"_HAVE_PRDR");
180 #endif
181 #ifdef SUPPORT_PROXY
182   builtin_macro_create(US"_HAVE_PROXY");
183 #endif
184 #ifdef SUPPORT_SOCKS
185   builtin_macro_create(US"_HAVE_SOCKS");
186 #endif
187 #if defined(SUPPORT_SRS)
188   builtin_macro_create(US"_HAVE_NATIVE_SRS");   /* beware clash with _HAVE_SRS */
189 #endif
190 #ifdef TCP_FASTOPEN
191   builtin_macro_create(US"_HAVE_TCP_FASTOPEN");
192 #endif
193 #ifdef SUPPORT_SPF
194   builtin_macro_create(US"_HAVE_SPF");
195 #endif
196 #ifdef SUPPORT_SRS
197   builtin_macro_create(US"_HAVE_SRS");
198 #endif
199 #ifdef EXPERIMENTAL_ARC
200   builtin_macro_create(US"_HAVE_ARC");
201 #endif
202 #ifdef EXPERIMENTAL_BRIGHTMAIL
203   builtin_macro_create(US"_HAVE_BRIGHTMAIL");
204 #endif
205 #ifdef SUPPORT_DANE
206   builtin_macro_create(US"_HAVE_DANE");
207 #endif
208 #ifdef EXPERIMENTAL_DCC
209   builtin_macro_create(US"_HAVE_DCC");
210 #endif
211 #ifdef EXPERIMENTAL_DSN_INFO
212   builtin_macro_create(US"_HAVE_DSN_INFO");
213 #endif
214 #ifndef DISABLE_TLS_RESUME
215   builtin_macro_create(US"_HAVE_TLS_RESUME");
216 #endif
217 #ifdef EXPERIMENTAL_XCLIENT
218   builtin_macro_create(US"_HAVE_XCLIENT");
219 #endif
220
221 #ifdef LOOKUP_LSEARCH
222   builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH");
223 #endif
224 #ifdef LOOKUP_CDB
225   builtin_macro_create(US"_HAVE_LOOKUP_CDB");
226 #endif
227 #ifdef LOOKUP_DBM
228   builtin_macro_create(US"_HAVE_LOOKUP_DBM");
229 #endif
230 #ifdef LOOKUP_DNSDB
231   builtin_macro_create(US"_HAVE_LOOKUP_DNSDB");
232 #endif
233 #ifdef LOOKUP_DSEARCH
234   builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH");
235 #endif
236 #ifdef LOOKUP_IBASE
237   builtin_macro_create(US"_HAVE_LOOKUP_IBASE");
238 #endif
239 #ifdef LOOKUP_LMDB
240   builtin_macro_create(US"_HAVE_LMDB");
241   builtin_macro_create(US"_HAVE_LOOKUP_LMDB");
242 #endif
243 #ifdef LOOKUP_LDAP
244   builtin_macro_create(US"_HAVE_LOOKUP_JSON");
245 #endif
246 #ifdef LOOKUP_LDAP
247   builtin_macro_create(US"_HAVE_LOOKUP_LDAP");
248 #endif
249 #ifdef LOOKUP_MYSQL
250   builtin_macro_create(US"_HAVE_LOOKUP_MYSQL");
251 #endif
252 #ifdef LOOKUP_NIS
253   builtin_macro_create(US"_HAVE_LOOKUP_NIS");
254 #endif
255 #ifdef LOOKUP_NISPLUS
256   builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS");
257 #endif
258 #ifdef LOOKUP_ORACLE
259   builtin_macro_create(US"_HAVE_LOOKUP_ORACLE");
260 #endif
261 #ifdef LOOKUP_PASSWD
262   builtin_macro_create(US"_HAVE_LOOKUP_PASSWD");
263 #endif
264 #ifdef LOOKUP_PGSQL
265   builtin_macro_create(US"_HAVE_LOOKUP_PGSQL");
266 #endif
267 #ifdef LOOKUP_REDIS
268   builtin_macro_create(US"_HAVE_LOOKUP_REDIS");
269 #endif
270 #ifdef LOOKUP_SQLITE
271   builtin_macro_create(US"_HAVE_LOOKUP_SQLITE");
272 #endif
273 #ifdef LOOKUP_TESTDB
274   builtin_macro_create(US"_HAVE_LOOKUP_TESTDB");
275 #endif
276 #ifdef LOOKUP_WHOSON
277   builtin_macro_create(US"_HAVE_LOOKUP_WHOSON");
278 #endif
279
280 #ifdef TRANSPORT_APPENDFILE
281 # ifdef SUPPORT_MAILDIR
282   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR");
283 # endif
284 # ifdef SUPPORT_MAILSTORE
285   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE");
286 # endif
287 # ifdef SUPPORT_MBX
288   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX");
289 # endif
290 #endif
291
292 features_acl();
293 features_crypto();
294
295 #ifdef WITH_CONTENT_SCAN
296 features_malware();
297 #endif
298 }
299
300 static void
301 exp_features(void)
302 {
303 #ifdef EXPERIMENTAL_ARC
304   builtin_macro_create(US"_EXP_ARC");
305 #endif
306 #ifdef EXPERIMENTAL_BRIGHTMAIL
307   builtin_macro_create(US"_EXP_BMI");
308 #endif
309 #ifdef EXPERIMENTAL_DCC
310   builtin_macro_create(US"_EXP_DCC");
311 #endif
312 #ifdef EXPERIMENTAL_DSN_INFO
313   builtin_macro_create(US"_EXP_DSNI");
314 #endif
315 #ifdef EXPERIMENTAL_QUEUEFILE
316   builtin_macro_create(US"_EXP_QUEUEFILE");
317 #endif
318 }
319
320
321 static void
322 options(void)
323 {
324 options_main();
325 options_routers();
326 options_transports();
327 options_auths();
328 options_logging();
329 #ifndef DISABLE_TLS
330 options_tls();
331 #endif
332 }
333
334 static void
335 params(void)
336 {
337 #ifndef DISABLE_DKIM
338 params_dkim();
339 #endif
340 }
341
342
343 int
344 main(void)
345 {
346 printf("#include \"exim.h\"\n");
347 features();
348 exp_features();
349 options();
350 expansions();
351 params();
352
353 printf("macro_item * macros = &p%d;\n", mp_index-1);
354 printf("macro_item * mlast = &p0;\n");
355 exit(0);
356 }