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