summaryrefslogtreecommitdiffstats
path: root/src/macro_predef.c
blob: 1c93a6e038570066fb70b398b08f2927cc21948d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*************************************************
*     Exim - an Internet mail transport agent    *
*************************************************/

/* Copyright (c) Jeremy Harris 1995 - 2018 */
/* Copyright (c) The Exim Maintainers 2020 */
/* See the file NOTICE for conditions of use and distribution. */

/* Create a static data structure with the predefined macros, to be
included in the main Exim build */

#include "exim.h"
#include "macro_predef.h"

unsigned mp_index = 0;

/* Global dummy variables */

void fn_smtp_receive_timeout(const uschar * name, const uschar * str) {}
uschar * syslog_facility_str;

/******************************************************************************/

void
builtin_macro_create_var(const uschar * name, const uschar * val)
{
printf ("static macro_item p%d = { ", mp_index);
if (mp_index == 0)
  printf(".next=NULL,");
else
  printf(".next=&p%d,", mp_index-1);

printf(" .command_line=FALSE, .namelen=%d, .replen=%d,"
	" .name=US\"%s\", .replacement=US\"%s\" };\n",
	Ustrlen(name), Ustrlen(val), CS name, CS val);
mp_index++;
}


void
builtin_macro_create(const uschar * name)
{
builtin_macro_create_var(name, US"y");
}


/* restricted snprintf */
void
spf(uschar * buf, int len, const uschar * fmt, ...)
{
va_list ap;
va_start(ap, fmt);

while (*fmt && len > 1)
  if (*fmt == '%' && fmt[1] == 'T')
    {
    uschar * s = va_arg(ap, uschar *);
    while (*s && len-- > 1)
      *buf++ = toupper(*s++);
    fmt += 2;
    }
  else
    {
    *buf++ = *fmt++; len--;
    }
*buf = '\0';
va_end(ap);
}

void
options_from_list(optionlist * opts, unsigned nopt,
  const uschar * section, uschar * group)
{
const uschar * s;
uschar buf[EXIM_DRIVERNAME_MAX];

/* The 'previously-defined-substring' rule for macros in config file
lines is done thus for these builtin macros: we know that the table
we source from is in strict alpha order, hence the builtins portion
of the macros list is in reverse-alpha (we prepend them) - so longer
macros that have substrings are always discovered first during
expansion. */

for (int i = 0; i < nopt; i++)  if (*(s = US opts[i].name) && *s != '*')
  {
  if (group)
    spf(buf, sizeof(buf), CUS"_OPT_%T_%T_%T", section, group, s);
  else
    spf(buf, sizeof(buf), CUS"_OPT_%T_%T", section, s);
  builtin_macro_create(buf);
  }
}


/******************************************************************************/


/* Create compile-time feature macros */
static void
features(void)
{
/* Probably we could work out a static initialiser for wherever
macros are stored, but this will do for now. Some names are awkward
due to conflicts with other common macros. */

#ifdef SUPPORT_CRYPTEQ
  builtin_macro_create(US"_HAVE_CRYPTEQ");
#endif
#if HAVE_ICONV
  builtin_macro_create(US"_HAVE_ICONV");
#endif
#if HAVE_IPV6
  builtin_macro_create(US"_HAVE_IPV6");
#endif
#ifdef HAVE_SETCLASSRESOURCES
  builtin_macro_create(US"_HAVE_SETCLASSRESOURCES");
#endif
#ifdef SUPPORT_PAM
  builtin_macro_create(US"_HAVE_PAM");
#endif
#ifdef EXIM_PERL
  builtin_macro_create(US"_HAVE_PERL");
#endif
#ifdef EXPAND_DLFUNC
  builtin_macro_create(US"_HAVE_DLFUNC");
#endif
#ifdef USE_TCP_WRAPPERS
  builtin_macro_create(US"_HAVE_TCPWRAPPERS");
#endif
#ifndef DISABLE_TLS
  builtin_macro_create(US"_HAVE_TLS");
# ifdef USE_GNUTLS
  builtin_macro_create(US"_HAVE_GNUTLS");
# else
  builtin_macro_create(US"_HAVE_OPENSSL");
# endif
#endif
#ifdef SUPPORT_TRANSLATE_IP_ADDRESS
  builtin_macro_create(US"_HAVE_TRANSLATE_IP_ADDRESS");
#endif
#ifdef SUPPORT_MOVE_FROZEN_MESSAGES
  builtin_macro_create(US"_HAVE_MOVE_FROZEN_MESSAGES");
#endif
#ifdef WITH_CONTENT_SCAN
  builtin_macro_create(US"_HAVE_CONTENT_SCANNING");
#endif
#ifndef DISABLE_DKIM
  builtin_macro_create(US"_HAVE_DKIM");
#endif
#ifdef SUPPORT_DMARC
  builtin_macro_create(US"_HAVE_DMARC");
#endif
#ifndef DISABLE_DNSSEC
  builtin_macro_create(US"_HAVE_DNSSEC");
#endif
#ifndef DISABLE_EVENT
  builtin_macro_create(US"_HAVE_EVENT");
#endif
#ifdef SUPPORT_I18N
  builtin_macro_create(US"_HAVE_I18N");
#endif
#ifndef DISABLE_OCSP
  builtin_macro_create(US"_HAVE_OCSP");
#endif
#ifndef DISABLE_PIPE_CONNECT
  builtin_macro_create(US"_HAVE_PIPE_CONNECT");
#endif
#ifndef DISABLE_PRDR
  builtin_macro_create(US"_HAVE_PRDR");
#endif
#ifdef SUPPORT_PROXY
  builtin_macro_create(US"_HAVE_PROXY");
#endif
#ifdef SUPPORT_SOCKS
  builtin_macro_create(US"_HAVE_SOCKS");
#endif
#ifdef TCP_FASTOPEN
  builtin_macro_create(US"_HAVE_TCP_FASTOPEN");
#endif
#ifdef EXPERIMENTAL_LMDB
  builtin_macro_create(US"_HAVE_LMDB");
#endif
#ifdef SUPPORT_SPF
  builtin_macro_create(US"_HAVE_SPF");
#endif
#if defined(EXPERIMENTAL_SRS) || defined(EXPERIMENTAL_SRS_NATIVE)
  builtin_macro_create(US"_HAVE_SRS");
#endif
#if defined(EXPERIMENTAL_SRS_NATIVE)
  builtin_macro_create(US"_HAVE_NATIVE_SRS");	/* beware clash with _HAVE_SRS */
#endif
#ifdef EXPERIMENTAL_ARC
  builtin_macro_create(US"_HAVE_ARC");
#endif
#ifdef EXPERIMENTAL_BRIGHTMAIL
  builtin_macro_create(US"_HAVE_BRIGHTMAIL");
#endif
#ifdef SUPPORT_DANE
  builtin_macro_create(US"_HAVE_DANE");
#endif
#ifdef EXPERIMENTAL_DCC
  builtin_macro_create(US"_HAVE_DCC");
#endif
#ifdef EXPERIMENTAL_DSN_INFO
  builtin_macro_create(US"_HAVE_DSN_INFO");
#endif
#ifdef EXPERIMENTAL_TLS_RESUME
  builtin_macro_create(US"_HAVE_TLS_RESUME");
#endif

#ifdef LOOKUP_LSEARCH
  builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH");
#endif
#ifdef LOOKUP_CDB
  builtin_macro_create(US"_HAVE_LOOKUP_CDB");
#endif
#ifdef LOOKUP_DBM
  builtin_macro_create(US"_HAVE_LOOKUP_DBM");
#endif
#ifdef LOOKUP_DNSDB
  builtin_macro_create(US"_HAVE_LOOKUP_DNSDB");
#endif
#ifdef LOOKUP_DSEARCH
  builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH");
#endif
#ifdef LOOKUP_IBASE
  builtin_macro_create(US"_HAVE_LOOKUP_IBASE");
#endif
#ifdef LOOKUP_LDAP
  builtin_macro_create(US"_HAVE_LOOKUP_JSON");
#endif
#ifdef LOOKUP_LDAP
  builtin_macro_create(US"_HAVE_LOOKUP_LDAP");
#endif
#ifdef EXPERIMENTAL_LMDB
  builtin_macro_create(US"_HAVE_LOOKUP_LMDB");
#endif
#ifdef LOOKUP_MYSQL
  builtin_macro_create(US"_HAVE_LOOKUP_MYSQL");
#endif
#ifdef LOOKUP_NIS
  builtin_macro_create(US"_HAVE_LOOKUP_NIS");
#endif
#ifdef LOOKUP_NISPLUS
  builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS");
#endif
#ifdef LOOKUP_ORACLE
  builtin_macro_create(US"_HAVE_LOOKUP_ORACLE");
#endif
#ifdef LOOKUP_PASSWD
  builtin_macro_create(US"_HAVE_LOOKUP_PASSWD");
#endif
#ifdef LOOKUP_PGSQL
  builtin_macro_create(US"_HAVE_LOOKUP_PGSQL");
#endif
#ifdef LOOKUP_REDIS
  builtin_macro_create(US"_HAVE_LOOKUP_REDIS");
#endif
#ifdef LOOKUP_SQLITE
  builtin_macro_create(US"_HAVE_LOOKUP_SQLITE");
#endif
#ifdef LOOKUP_TESTDB
  builtin_macro_create(US"_HAVE_LOOKUP_TESTDB");
#endif
#ifdef LOOKUP_WHOSON
  builtin_macro_create(US"_HAVE_LOOKUP_WHOSON");
#endif

#ifdef TRANSPORT_APPENDFILE
# ifdef SUPPORT_MAILDIR
  builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR");
# endif
# ifdef SUPPORT_MAILSTORE
  builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE");
# endif
# ifdef SUPPORT_MBX
  builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX");
# endif
#endif

#ifdef WITH_CONTENT_SCAN
features_malware();
#endif

features_crypto();
}


static void
options(void)
{
options_main();
options_routers();
options_transports();
options_auths();
options_logging();
#ifndef DISABLE_TLS
options_tls();
#endif
}

static void
params(void)
{
#ifndef DISABLE_DKIM
params_dkim();
#endif
}


int
main(void)
{
printf("#include \"exim.h\"\n");
features();
options();
params();

printf("macro_item * macros = &p%d;\n", mp_index-1);
printf("macro_item * mlast = &p0;\n");
exit(0);
}