tidying
[exim.git] / src / src / macro_predef.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2024 */
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 #ifndef DISABLE_WELLKNOWN
218   builtin_macro_create(US"_HAVE_WELLKNOWN");
219 #endif
220 #ifdef EXPERIMENTAL_XCLIENT
221   builtin_macro_create(US"_HAVE_XCLIENT");
222 #endif
223
224 #ifdef USE_SQLITE
225   builtin_macro_create(US"_HAVE_HINTS_SQLITE");
226 #elif defined(USE_TDB)
227   builtin_macro_create(US"_HAVE_HINTS_TDB");
228 #elif defined(USE_DB)
229   builtin_macro_create(US"_HAVE_HINTS_BDB");
230 #elif defined(USE_GDBM)
231   builtin_macro_create(US"_HAVE_HINTS_GDBM");
232 #else
233   builtin_macro_create(US"_HAVE_HINTS_NDBM");
234 #endif
235
236 #ifdef LOOKUP_LSEARCH
237   builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH");
238 #endif
239 #ifdef LOOKUP_CDB
240   builtin_macro_create(US"_HAVE_LOOKUP_CDB");
241 #endif
242 #ifdef LOOKUP_DBM
243   builtin_macro_create(US"_HAVE_LOOKUP_DBM");
244 #endif
245 #ifdef LOOKUP_DNSDB
246   builtin_macro_create(US"_HAVE_LOOKUP_DNSDB");
247 #endif
248 #ifdef LOOKUP_DSEARCH
249   builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH");
250 #endif
251 #ifdef LOOKUP_IBASE
252   builtin_macro_create(US"_HAVE_LOOKUP_IBASE");
253 #endif
254 #ifdef LOOKUP_LMDB
255   builtin_macro_create(US"_HAVE_LMDB");
256   builtin_macro_create(US"_HAVE_LOOKUP_LMDB");
257 #endif
258 #ifdef LOOKUP_LDAP
259   builtin_macro_create(US"_HAVE_LOOKUP_JSON");
260 #endif
261 #ifdef LOOKUP_LDAP
262   builtin_macro_create(US"_HAVE_LOOKUP_LDAP");
263 #endif
264 #ifdef LOOKUP_MYSQL
265   builtin_macro_create(US"_HAVE_LOOKUP_MYSQL");
266 #endif
267 #ifdef LOOKUP_NIS
268   builtin_macro_create(US"_HAVE_LOOKUP_NIS");
269 #endif
270 #ifdef LOOKUP_NISPLUS
271   builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS");
272 #endif
273 #ifdef LOOKUP_ORACLE
274   builtin_macro_create(US"_HAVE_LOOKUP_ORACLE");
275 #endif
276 #ifdef LOOKUP_PASSWD
277   builtin_macro_create(US"_HAVE_LOOKUP_PASSWD");
278 #endif
279 #ifdef LOOKUP_PGSQL
280   builtin_macro_create(US"_HAVE_LOOKUP_PGSQL");
281 #endif
282 #ifdef LOOKUP_REDIS
283   builtin_macro_create(US"_HAVE_LOOKUP_REDIS");
284 #endif
285 #ifdef LOOKUP_SQLITE
286   builtin_macro_create(US"_HAVE_LOOKUP_SQLITE");
287 #endif
288 #ifdef LOOKUP_TESTDB
289   builtin_macro_create(US"_HAVE_LOOKUP_TESTDB");
290 #endif
291 #ifdef LOOKUP_WHOSON
292   builtin_macro_create(US"_HAVE_LOOKUP_WHOSON");
293 #endif
294
295 #ifdef TRANSPORT_APPENDFILE
296 # ifdef SUPPORT_MAILDIR
297   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR");
298 # endif
299 # ifdef SUPPORT_MAILSTORE
300   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE");
301 # endif
302 # ifdef SUPPORT_MBX
303   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX");
304 # endif
305 #endif
306
307 features_acl();
308 features_crypto();
309
310 #ifdef WITH_CONTENT_SCAN
311 features_malware();
312 #endif
313 }
314
315 static void
316 exp_features(void)
317 {
318 #ifdef EXPERIMENTAL_ARC
319   builtin_macro_create(US"_EXP_ARC");
320 #endif
321 #ifdef EXPERIMENTAL_BRIGHTMAIL
322   builtin_macro_create(US"_EXP_BMI");
323 #endif
324 #ifdef EXPERIMENTAL_DCC
325   builtin_macro_create(US"_EXP_DCC");
326 #endif
327 #ifdef EXPERIMENTAL_DSN_INFO
328   builtin_macro_create(US"_EXP_DSNI");
329 #endif
330 #ifdef EXPERIMENTAL_QUEUEFILE
331   builtin_macro_create(US"_EXP_QUEUEFILE");
332 #endif
333 }
334
335
336 static void
337 options(void)
338 {
339 options_main();
340 options_routers();
341 options_transports();
342 options_auths();
343 options_logging();
344 #ifndef DISABLE_TLS
345 options_tls();
346 #endif
347 }
348
349 static void
350 params(void)
351 {
352 #ifndef DISABLE_DKIM
353 params_dkim();
354 #endif
355 }
356
357
358 int
359 main(void)
360 {
361 printf("#include \"exim.h\"\n");
362 features();
363 exp_features();
364 options();
365 expansions();
366 params();
367
368 printf("macro_item * macros = &p%d;\n", mp_index-1);
369 printf("macro_item * mlast = &p0;\n");
370 exit(0);
371 }