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