Move the TLS resumption support from Experimental to mainline
[exim.git] / src / src / macro_predef.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) Jeremy Harris 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2020 */
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[64];
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 EXPERIMENTAL_LMDB
184   builtin_macro_create(US"_HAVE_LMDB");
185 #endif
186 #ifdef SUPPORT_SPF
187   builtin_macro_create(US"_HAVE_SPF");
188 #endif
189 #if defined(EXPERIMENTAL_SRS_ALT) || defined(SUPPORT_SRS)
190   builtin_macro_create(US"_HAVE_SRS");
191 #endif
192 #ifdef EXPERIMENTAL_ARC
193   builtin_macro_create(US"_HAVE_ARC");
194 #endif
195 #ifdef EXPERIMENTAL_BRIGHTMAIL
196   builtin_macro_create(US"_HAVE_BRIGHTMAIL");
197 #endif
198 #ifdef SUPPORT_DANE
199   builtin_macro_create(US"_HAVE_DANE");
200 #endif
201 #ifdef EXPERIMENTAL_DCC
202   builtin_macro_create(US"_HAVE_DCC");
203 #endif
204 #ifdef EXPERIMENTAL_DSN_INFO
205   builtin_macro_create(US"_HAVE_DSN_INFO");
206 #endif
207 #ifndef DISABLE_TLS_RESUME
208   builtin_macro_create(US"_HAVE_TLS_RESUME");
209 #endif
210
211 #ifdef LOOKUP_LSEARCH
212   builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH");
213 #endif
214 #ifdef LOOKUP_CDB
215   builtin_macro_create(US"_HAVE_LOOKUP_CDB");
216 #endif
217 #ifdef LOOKUP_DBM
218   builtin_macro_create(US"_HAVE_LOOKUP_DBM");
219 #endif
220 #ifdef LOOKUP_DNSDB
221   builtin_macro_create(US"_HAVE_LOOKUP_DNSDB");
222 #endif
223 #ifdef LOOKUP_DSEARCH
224   builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH");
225 #endif
226 #ifdef LOOKUP_IBASE
227   builtin_macro_create(US"_HAVE_LOOKUP_IBASE");
228 #endif
229 #ifdef LOOKUP_LDAP
230   builtin_macro_create(US"_HAVE_LOOKUP_JSON");
231 #endif
232 #ifdef LOOKUP_LDAP
233   builtin_macro_create(US"_HAVE_LOOKUP_LDAP");
234 #endif
235 #ifdef EXPERIMENTAL_LMDB
236   builtin_macro_create(US"_HAVE_LOOKUP_LMDB");
237 #endif
238 #ifdef LOOKUP_MYSQL
239   builtin_macro_create(US"_HAVE_LOOKUP_MYSQL");
240 #endif
241 #ifdef LOOKUP_NIS
242   builtin_macro_create(US"_HAVE_LOOKUP_NIS");
243 #endif
244 #ifdef LOOKUP_NISPLUS
245   builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS");
246 #endif
247 #ifdef LOOKUP_ORACLE
248   builtin_macro_create(US"_HAVE_LOOKUP_ORACLE");
249 #endif
250 #ifdef LOOKUP_PASSWD
251   builtin_macro_create(US"_HAVE_LOOKUP_PASSWD");
252 #endif
253 #ifdef LOOKUP_PGSQL
254   builtin_macro_create(US"_HAVE_LOOKUP_PGSQL");
255 #endif
256 #ifdef LOOKUP_REDIS
257   builtin_macro_create(US"_HAVE_LOOKUP_REDIS");
258 #endif
259 #ifdef LOOKUP_SQLITE
260   builtin_macro_create(US"_HAVE_LOOKUP_SQLITE");
261 #endif
262 #ifdef LOOKUP_TESTDB
263   builtin_macro_create(US"_HAVE_LOOKUP_TESTDB");
264 #endif
265 #ifdef LOOKUP_WHOSON
266   builtin_macro_create(US"_HAVE_LOOKUP_WHOSON");
267 #endif
268
269 #ifdef TRANSPORT_APPENDFILE
270 # ifdef SUPPORT_MAILDIR
271   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR");
272 # endif
273 # ifdef SUPPORT_MAILSTORE
274   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE");
275 # endif
276 # ifdef SUPPORT_MBX
277   builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX");
278 # endif
279 #endif
280
281 #ifdef WITH_CONTENT_SCAN
282 features_malware();
283 #endif
284
285 features_crypto();
286 }
287
288
289 static void
290 options(void)
291 {
292 options_main();
293 options_routers();
294 options_transports();
295 options_auths();
296 options_logging();
297 #ifndef DISABLE_TLS
298 options_tls();
299 #endif
300 }
301
302 static void
303 params(void)
304 {
305 #ifndef DISABLE_DKIM
306 params_dkim();
307 #endif
308 }
309
310
311 int
312 main(void)
313 {
314 printf("#include \"exim.h\"\n");
315 features();
316 options();
317 params();
318
319 printf("macro_item * macros = &p%d;\n", mp_index-1);
320 printf("macro_item * mlast = &p0;\n");
321 exit(0);
322 }