1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) Jeremy Harris 2017 */
6 /* See the file NOTICE for conditions of use and distribution. */
8 /* Create a static data structure with the predefined macros, to be
9 included in the main Exim build */
12 #include "macro_predef.h"
14 tree_node * tree_macros = NULL;
15 unsigned m_number = 1;
17 /* Global dummy variables */
19 void fn_smtp_receive_timeout(const uschar * name, const uschar * str) {}
20 uschar * syslog_facility_str;
22 /******************************************************************************/
25 builtin_macro_create_var(const uschar * name, const uschar * val)
27 macro_create(name, val, FALSE);
32 builtin_macro_create(const uschar * name)
34 builtin_macro_create_var(name, US"y");
38 /* restricted snprintf */
40 spf(uschar * buf, int len, const uschar * fmt, ...)
45 while (*fmt && len > 1)
46 if (*fmt == '%' && fmt[1] == 'T')
48 uschar * s = va_arg(ap, uschar *);
49 while (*s && len-- > 1)
50 *buf++ = toupper(*s++);
55 *buf++ = *fmt++; len--;
62 options_from_list(optionlist * opts, unsigned nopt,
63 const uschar * section, uschar * group)
69 /* The 'previously-defined-substring' rule for macros in config file
70 lines is done thus for these builtin macros: we know that the table
71 we source from is in strict alpha order, hence the builtins portion
72 of the macros list is in reverse-alpha (we prepend them) - so longer
73 macros that have substrings are always discovered first during
76 for (i = 0; i < nopt; i++) if (*(s = US opts[i].name) && *s != '*')
79 spf(buf, sizeof(buf), CUS"_OPT_%T_%T_%T", section, group, s);
81 spf(buf, sizeof(buf), CUS"_OPT_%T_%T", section, s);
82 builtin_macro_create(buf);
87 /******************************************************************************/
90 /* Create compile-time feature macros */
94 /* Probably we could work out a static initialiser for wherever
95 macros are stored, but this will do for now. Some names are awkward
96 due to conflicts with other common macros. */
98 #ifdef SUPPORT_CRYPTEQ
99 builtin_macro_create(US"_HAVE_CRYPTEQ");
102 builtin_macro_create(US"_HAVE_ICONV");
105 builtin_macro_create(US"_HAVE_IPV6");
107 #ifdef HAVE_SETCLASSRESOURCES
108 builtin_macro_create(US"_HAVE_SETCLASSRESOURCES");
111 builtin_macro_create(US"_HAVE_PAM");
114 builtin_macro_create(US"_HAVE_PERL");
117 builtin_macro_create(US"_HAVE_DLFUNC");
119 #ifdef USE_TCP_WRAPPERS
120 builtin_macro_create(US"_HAVE_TCPWRAPPERS");
123 builtin_macro_create(US"_HAVE_TLS");
125 builtin_macro_create(US"_HAVE_GNUTLS");
127 builtin_macro_create(US"_HAVE_OPENSSL");
130 #ifdef SUPPORT_TRANSLATE_IP_ADDRESS
131 builtin_macro_create(US"_HAVE_TRANSLATE_IP_ADDRESS");
133 #ifdef SUPPORT_MOVE_FROZEN_MESSAGES
134 builtin_macro_create(US"_HAVE_MOVE_FROZEN_MESSAGES");
136 #ifdef WITH_CONTENT_SCAN
137 builtin_macro_create(US"_HAVE_CONTENT_SCANNING");
140 builtin_macro_create(US"_HAVE_DKIM");
142 #ifndef DISABLE_DNSSEC
143 builtin_macro_create(US"_HAVE_DNSSEC");
145 #ifndef DISABLE_EVENT
146 builtin_macro_create(US"_HAVE_EVENT");
149 builtin_macro_create(US"_HAVE_I18N");
152 builtin_macro_create(US"_HAVE_OCSP");
155 builtin_macro_create(US"_HAVE_PRDR");
158 builtin_macro_create(US"_HAVE_PROXY");
161 builtin_macro_create(US"_HAVE_SOCKS");
164 builtin_macro_create(US"_HAVE_TCP_FASTOPEN");
166 #ifdef EXPERIMENTAL_LMDB
167 builtin_macro_create(US"_HAVE_LMDB");
170 builtin_macro_create(US"_HAVE_SPF");
172 #ifdef EXPERIMENTAL_SRS
173 builtin_macro_create(US"_HAVE_SRS");
175 #ifdef EXPERIMENTAL_BRIGHTMAIL
176 builtin_macro_create(US"_HAVE_BRIGHTMAIL");
178 #ifdef EXPERIMENTAL_DANE
179 builtin_macro_create(US"_HAVE_DANE");
181 #ifdef EXPERIMENTAL_DCC
182 builtin_macro_create(US"_HAVE_DCC");
184 #ifdef EXPERIMENTAL_DMARC
185 builtin_macro_create(US"_HAVE_DMARC");
187 #ifdef EXPERIMENTAL_DSN_INFO
188 builtin_macro_create(US"_HAVE_DSN_INFO");
191 #ifdef LOOKUP_LSEARCH
192 builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH");
195 builtin_macro_create(US"_HAVE_LOOKUP_CDB");
198 builtin_macro_create(US"_HAVE_LOOKUP_DBM");
201 builtin_macro_create(US"_HAVE_LOOKUP_DNSDB");
203 #ifdef LOOKUP_DSEARCH
204 builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH");
207 builtin_macro_create(US"_HAVE_LOOKUP_IBASE");
210 builtin_macro_create(US"_HAVE_LOOKUP_LDAP");
212 #ifdef EXPERIMENTAL_LMDB
213 builtin_macro_create(US"_HAVE_LOOKUP_LMDB");
216 builtin_macro_create(US"_HAVE_LOOKUP_MYSQL");
219 builtin_macro_create(US"_HAVE_LOOKUP_NIS");
221 #ifdef LOOKUP_NISPLUS
222 builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS");
225 builtin_macro_create(US"_HAVE_LOOKUP_ORACLE");
228 builtin_macro_create(US"_HAVE_LOOKUP_PASSWD");
231 builtin_macro_create(US"_HAVE_LOOKUP_PGSQL");
234 builtin_macro_create(US"_HAVE_LOOKUP_REDIS");
237 builtin_macro_create(US"_HAVE_LOOKUP_SQLITE");
240 builtin_macro_create(US"_HAVE_LOOKUP_TESTDB");
243 builtin_macro_create(US"_HAVE_LOOKUP_WHOSON");
246 #ifdef TRANSPORT_APPENDFILE
247 # ifdef SUPPORT_MAILDIR
248 builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR");
250 # ifdef SUPPORT_MAILSTORE
251 builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE");
254 builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX");
258 #ifdef WITH_CONTENT_SCAN
271 options_transports();
285 macro_dump(macro_item * m)
287 int left = 0, right = 0;
291 /* fprintf(stderr, "%s %p\n", __FUNCTION__, m); */
294 /* fprintf(stderr, "%s '%s' l %p r %p\n", __FUNCTION__, m->tnode.name, m->tnode.left, m->tnode.left); */
295 if ((t = m->tnode.left)) left = macro_dump(tnode_to_mitem(m->tnode.left));
296 if ((t = m->tnode.right)) right = macro_dump(tnode_to_mitem(m->tnode.right));
298 printf ("static macro_item_64 p%u = { ", m->m_number);
299 printf(" .command_line=FALSE,"
304 Ustrlen(m->tnode.name), Ustrlen(m->tnode.data.ptr), m->m_number);
305 printf(left ? " .left=&p%d.tnode," : " .left=NULL,", left);
306 printf(right ? " .right=&p%d.tnode," : " .right=NULL,", right);
310 " .name=\"%s\"}};\n",
311 CS m->tnode.data.ptr,
315 if (Ustrlen(m->tnode.name) +1 > sizeof(m64->tnode.name))
317 printf("#error macro name too long for macro_item_64\n");
330 printf("#include \"exim.h\"\n");
335 idx = macro_dump(tnode_to_mitem(tree_macros));
336 printf("tree_node * tree_macros = (tree_node *) &p%u.tnode;\n", idx);
337 printf("unsigned m_number = %u;\n", m_number);