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