Use dedicated union member for option offsets
[exim.git] / src / src / local_scan.h
CommitLineData
059ec3d9
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
13a4b4c1 5/* Copyright (c) University of Cambridge 1995 - 2020 */
059ec3d9
PH
6/* See the file NOTICE for conditions of use and distribution. */
7
8/* This file is the header that is the only Exim header to be included in the
9source for the local_scan.c() function. It contains definitions that are made
9b230009
JH
10available for use in that function, and which are documented. That source
11should first #define LOCAL_SCAN
1a46a8c5 12
f0ed88da 13This API is also used for functions called by the ${dlfunc expansion item.
9b230009 14Source for those should first #define DLFUNC_IMPL and then include this file.
f0ed88da
JH
15Coders of dlfunc routines should read the notes on tainting at the start of
16store.c
17*/
059ec3d9
PH
18
19
750af86e
PH
20/* Some basic types that make some things easier, the Exim configuration
21settings, and the store functions. */
059ec3d9 22
ce552449 23#include <stdarg.h>
059ec3d9 24#include <sys/types.h>
750af86e 25#include "config.h"
059ec3d9
PH
26#include "mytypes.h"
27#include "store.h"
28
29
30/* The function and its return codes. */
31
32extern int local_scan(int, uschar **);
33
34enum {
35 LOCAL_SCAN_ACCEPT, /* Accept */
36 LOCAL_SCAN_ACCEPT_FREEZE, /* Accept, but freeze */
37 LOCAL_SCAN_ACCEPT_QUEUE, /* Accept, but no immediate delivery */
38 LOCAL_SCAN_REJECT, /* Permanent rejection */
39 LOCAL_SCAN_REJECT_NOLOGHDR, /* Permanent rejection, no log header */
40 LOCAL_SCAN_TEMPREJECT, /* Temporary rejection */
41 LOCAL_SCAN_TEMPREJECT_NOLOGHDR /* Temporary rejection, no log header */
42};
43
44
1a46a8c5
PH
45/* Functions called by ${dlfunc{file}{func}{arg}...} return one of the five
46status codes defined immediately below. The function's first argument is either
47the result of expansion, or the error message in case of failure. The second
48and third arguments are standard argument count and vector, comprising the
49{arg} values specified in the expansion item. */
50
51typedef int exim_dlfunc_t(uschar **yield, int argc, uschar *argv[]);
52
53
54/* Return codes from the support functions lss_match_xxx(). These are also the
55codes that dynamically-loaded ${dlfunc functions must return. */
059ec3d9
PH
56
57#define OK 0 /* Successful match */
58#define DEFER 1 /* Defer - some problem */
59#define FAIL 2 /* Matching failed */
60#define ERROR 3 /* Internal or config error */
61
1a46a8c5
PH
62/* Extra return code for ${dlfunc functions */
63
64#define FAIL_FORCED 4 /* "Forced" failure */
65
059ec3d9
PH
66
67/* Available logging destinations */
68
69#define LOG_MAIN 1 /* Write to the main log */
70#define LOG_PANIC 2 /* Write to the panic log */
71#define LOG_REJECT 16 /* Write to the reject log, with headers */
72
73
74/* Accessible debugging bits */
75
76#define D_v 0x00000001
77#define D_local_scan 0x00000002
78
79
80/* Option types that can be used for local_scan_options. The boolean ones
81MUST be last so that they are contiguous with the internal boolean specials. */
82
83enum { opt_stringptr, opt_int, opt_octint, opt_mkint, opt_Kint, opt_fixed,
84 opt_time, opt_bool };
85
86
87/* The length of message identification strings. This is the id used internally
88by exim. The external version for use in Received: strings has a leading 'E'
89added to ensure it starts with a letter. */
90
91#define MESSAGE_ID_LENGTH 16
92
93/* The offset to the start of the data in the data file - this allows for
94the name of the data file to be present in the first line. */
95
96#define SPOOL_DATA_START_OFFSET (MESSAGE_ID_LENGTH+3)
97
98/* Some people (Marc Merlin et al) are maintaining a patch that allows for
99dynamic local_scan() libraries. This code is not yet in Exim proper, but it
100helps the maintainers if we keep their ABI version numbers here. This may
101mutate into more general support later. The major number is increased when the
102ABI is changed in a non backward compatible way. The minor number is increased
103each time a new feature is added (in a way that doesn't break backward
104compatibility). */
105
13a4b4c1
JH
106#define LOCAL_SCAN_ABI_VERSION_MAJOR 4
107#define LOCAL_SCAN_ABI_VERSION_MINOR 0
e57faad2
MH
108#define LOCAL_SCAN_ABI_VERSION \
109 LOCAL_SCAN_ABI_VERSION_MAJOR.LOCAL_SCAN_ABI_VERSION_MINOR
059ec3d9
PH
110
111/* Structure definitions that are documented as visible in the function. */
112
113typedef struct header_line {
114 struct header_line *next;
115 int type;
116 int slen;
117 uschar *text;
118} header_line;
119
120/* Entries in lists options are in this form. */
121
122typedef struct {
a73f0547
JH
123 const char * name; /* should have been uschar but too late now */
124 int type;
125 union {
126 void * value;
13a4b4c1 127 long offset;
a73f0547
JH
128 void (* fn)();
129 } v;
059ec3d9 130} optionlist;
13a4b4c1 131#define OPT_OFF(s, field) {.offset = offsetof(s, field)}
059ec3d9 132
d81d33cf 133/* Structure for holding information about an envelope address. The errors_to
059ec3d9
PH
134field is always NULL except for one_time aliases that had errors_to on the
135routers that generated them. */
136
137typedef struct recipient_item {
138 uschar *address; /* the recipient address */
139 int pno; /* parent number for "one_time" alias, or -1 */
140 uschar *errors_to; /* the errors_to address or NULL */
6c1c3d1d
WB
141 uschar *orcpt; /* DSN orcpt */
142 int dsn_flags; /* DSN flags */
8523533c
TK
143#ifdef EXPERIMENTAL_BRIGHTMAIL
144 uschar *bmi_optin;
145#endif
059ec3d9
PH
146} recipient_item;
147
148
149/* Global variables that are documented as visible in the function. */
150
151extern unsigned int debug_selector; /* Debugging bits */
152
2b85bce7
PH
153extern int body_linecount; /* Line count in body */
154extern int body_zerocount; /* Binary zero count in body */
059ec3d9
PH
155extern uschar *expand_string_message; /* Error info for failing expansion */
156extern uschar *headers_charset; /* Charset for RFC 2047 decoding */
157extern header_line *header_last; /* Final header */
158extern header_line *header_list; /* First header */
159extern BOOL host_checking; /* Set when checking a host */
160extern uschar *interface_address; /* Interface for incoming call */
161extern int interface_port; /* Port number for incoming call */
162extern uschar *message_id; /* Internal id of message being handled */
163extern uschar *received_protocol; /* Name of incoming protocol */
164extern int recipients_count; /* Number of recipients */
165extern recipient_item *recipients_list;/* List of recipient addresses */
166extern unsigned char *sender_address; /* Sender address */
167extern uschar *sender_host_address; /* IP address of sender, as chars */
168extern uschar *sender_host_authenticated; /* Name of authentication mechanism */
169extern uschar *sender_host_name; /* Host name from lookup */
170extern int sender_host_port; /* Port number of sender */
171extern BOOL smtp_batched_input; /* TRUE if SMTP batch (no interaction) */
172extern BOOL smtp_input; /* TRUE if input is via SMTP */
173
174
175/* Functions that are documented as visible in local_scan(). */
176
177extern int child_close(pid_t, int);
178extern pid_t child_open(uschar **, uschar **, int, int *, int *, BOOL);
179extern pid_t child_open_exim(int *);
5977a0b3 180extern pid_t child_open_exim2(int *, uschar *, uschar *);
1ba28e2b 181extern void debug_printf(const char *, ...) PRINTF_FUNCTION(1,2);
059ec3d9 182extern uschar *expand_string(uschar *);
1ba28e2b
PP
183extern void header_add(int, const char *, ...);
184extern void header_add_at_position(BOOL, uschar *, BOOL, int, const char *, ...);
185extern void header_remove(int, const uschar *);
186extern BOOL header_testname(header_line *, const uschar *, int, BOOL);
187extern BOOL header_testname_incomplete(header_line *, const uschar *, int, BOOL);
e0df1c83 188extern void log_write(unsigned int, int, const char *format, ...) PRINTF_FUNCTION(3,4);
059ec3d9
PH
189extern int lss_b64decode(uschar *, uschar **);
190extern uschar *lss_b64encode(uschar *, int);
191extern int lss_match_domain(uschar *, uschar *);
192extern int lss_match_local_part(uschar *, uschar *, BOOL);
193extern int lss_match_address(uschar *, uschar *, BOOL);
194extern int lss_match_host(uschar *, uschar *, uschar *);
195extern void receive_add_recipient(uschar *, int);
196extern BOOL receive_remove_recipient(uschar *);
197extern uschar *rfc2047_decode(uschar *, BOOL, uschar *, int, int *, uschar **);
198extern int smtp_fflush(void);
925ac8e4
JH
199extern void smtp_printf(const char *, BOOL, ...) PRINTF_FUNCTION(1,3);
200extern void smtp_vprintf(const char *, BOOL, va_list);
f3ebb786
JH
201
202#define string_sprintf(fmt, ...) \
c4efe382 203 string_sprintf_trc(fmt, US __FUNCTION__, __LINE__, __VA_ARGS__)
f3ebb786 204extern uschar *string_sprintf_trc(const char *, const uschar *, unsigned, ...) ALMOST_PRINTF(1,4);
059ec3d9 205
4ec0fcb6
JH
206#define store_get(size, tainted) \
207 store_get_3(size, tainted, __FUNCTION__, __LINE__)
208extern void *store_get_3(int, BOOL, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
209#define store_get_perm(size, tainted) \
210 store_get_perm_3(size, tainted, __FUNCTION__, __LINE__)
211extern void *store_get_perm_3(int, BOOL, const char *, int) ALLOC ALLOC_SIZE(1) WARN_UNUSED_RESULT;
212
213
8b5d88d2 214#if defined(LOCAL_SCAN) || defined(DLFUNC_IMPL)
e59797e3
JH
215/* When compiling a local_scan() file we want to rename a published API, so that
216we can use an inlined implementation in the compiles of the main Exim files,
217with the original name. */
218
219# define string_copy(s) string_copy_function(s)
d48326c0
JH
220# define string_copyn(s, n) string_copyn_function((s), (n))
221# define string_copy_taint(s, t) string_copy_taint_function((s), (t))
e59797e3
JH
222
223extern uschar * string_copy_function(const uschar *);
b4a15239
JH
224extern uschar * string_copyn_function(const uschar *, int n);
225extern uschar * string_copy_taint_function(const uschar *, BOOL tainted);
e59797e3
JH
226#endif
227
059ec3d9 228/* End of local_scan.h */