Hints DB interface: convert from macros to inlinable functions.
[exim.git] / src / src / hintsdb_structs.h
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2020 - 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
8
9 /* This header file contains the definitions of the structures used in the
10 various hints databases are also kept in this file, which is used by the
11 maintenance utilities as well as the main Exim binary. */
12
13 #ifndef HINTSDB_STRUCTS_H
14 #define HINTSDB_STRUCTS_H
15
16
17 /* Structure for carrying around an open DBM file, and an open locking file
18 that relates to it. */
19
20 typedef struct {
21   void *        dbptr;
22   int           lockfd;
23 } open_db;
24
25
26 /* Structures for records stored in exim database dbm files. They all
27 start with the same fields, described in the generic type. */
28
29
30 typedef struct {
31   time_t time_stamp;      /* Timestamp of writing */
32 } dbdata_generic;
33
34
35 /* This structure keeps track of retry information for a host or a local
36 address. */
37
38 typedef struct {
39   time_t time_stamp;
40   /*************/
41   time_t first_failed;    /* Time of first failure */
42   time_t last_try;        /* Time of last try */
43   time_t next_try;        /* Time of next try */
44   BOOL   expired;         /* Retry time has expired */
45   int    basic_errno;     /* Errno of last failure */
46   int    more_errno;      /* Additional information */
47   uschar text[1];         /* Text message for last failure */
48 } dbdata_retry;
49
50 /* These structures keep track of addresses that have had callout verification
51 performed on them. There are two groups of records:
52
53 1. keyed by localpart@domain -
54      Full address was tested and record holds result
55
56 2. keyed by domain -
57      Domain response upto MAIL FROM:<>, postmaster, random local part;
58
59 If a record exists, the result field is either ccache_accept or ccache_reject,
60 or, for a domain record only, ccache_reject_mfnull when MAIL FROM:<> was
61 rejected. The other fields, however, (which are only relevant to domain
62 records) may also contain ccache_unknown if that particular test has not been
63 done.
64
65 Originally, there was only one structure, used for both types. However, it got
66 expanded for domain records, so it got split. To make it possible for Exim to
67 handle the old type of record, we retain the old definition. The different
68 kinds of record can be distinguished by their different lengths. */
69
70 typedef struct {
71   time_t time_stamp;
72   /*************/
73   int   result;
74   int   postmaster_result; /* Postmaster is accepted */
75   int   random_result;     /* Random local part was accepted */
76 } dbdata_callout_cache_obs;
77
78 typedef struct {
79   time_t time_stamp;       /* Timestamp of last address check */
80   /*************/
81   int   result;            /* accept or reject */
82 } dbdata_callout_cache_address;
83
84 /* For this new layout, we put the additional fields (the timestamps)
85 last so that if somebody reverts to an older Exim, the new records will
86 still make sense because they match the old layout. */
87
88 typedef struct {
89   time_t time_stamp;       /* Time stamp of last connection */
90   /*************/
91   int   result;            /* Domain reject or accept */
92   int   postmaster_result; /* Postmaster result */
93   int   random_result;     /* Random result */
94   time_t postmaster_stamp; /* Timestamp of postmaster check */
95   time_t random_stamp;     /* Timestamp of random check */
96 } dbdata_callout_cache;
97
98 /* This structure keeps track of messages that are waiting for a particular
99 host for a particular transport. */
100
101 typedef struct {
102   time_t time_stamp;
103   /*************/
104   int    count;           /* Count of message ids */
105   int    sequence;        /* Sequence for continued records */
106   uschar text[1];         /* One long character string */
107 } dbdata_wait;
108
109
110 /* The contents of the "misc" database are a mixture of different kinds of
111 record, as defined below. The keys used for a specific type all start with a
112 given string such as "etrn-" or "host-serialize-". */
113
114
115 /* This structure records a connection to a particular host, for the
116 purpose of serializing access to certain hosts. For possible future extension,
117 a field is defined for holding the count of connections, but it is not
118 at present in use. The same structure is used for recording a running ETRN
119 process. */
120
121 typedef struct {
122   time_t time_stamp;
123   /*************/
124   int    count;           /* Reserved for possible connection count */
125 } dbdata_serialize;
126
127
128 /* This structure records the information required for the ratelimit
129 ACL condition. */
130
131 typedef struct {
132   time_t time_stamp;
133   /*************/
134   int    time_usec;       /* Fractional part of time, from gettimeofday() */
135   double rate;            /* Smoothed sending rate at that time */
136 } dbdata_ratelimit;
137
138 /* Same as above, plus a Bloom filter for uniquifying events. */
139
140 typedef struct {
141   dbdata_ratelimit dbd;
142   time_t   bloom_epoch;   /* When the Bloom filter was last reset */
143   unsigned bloom_size;    /* Number of bytes in the Bloom filter */
144   uschar   bloom[40];     /* Bloom filter which may be larger than this */
145 } dbdata_ratelimit_unique;
146
147
148 /* For "seen" ACL condition */
149 typedef struct {
150   time_t time_stamp;
151 } dbdata_seen;
152
153 #ifndef DISABLE_PIPE_CONNECT
154 /* This structure records the EHLO responses, cleartext and crypted,
155 for an IP, as bitmasks (cf. OPTION_TLS).  For LIMITS, also values
156 advertised for MAILMAX, RCPTMAX and RCPTDOMAINMAX; zero meaning no
157 value advertised. */
158
159 typedef struct {
160   unsigned short cleartext_features;
161   unsigned short crypted_features;
162   unsigned short cleartext_auths;
163   unsigned short crypted_auths;
164
165 # ifdef EXPERIMENTAL_ESMTP_LIMITS
166   unsigned int limit_mail;
167   unsigned int limit_rcpt;
168   unsigned int limit_rcptdom;
169 # endif
170 } ehlo_resp_precis;
171
172 typedef struct {
173   time_t time_stamp;
174   /*************/
175   ehlo_resp_precis data;
176 } dbdata_ehlo_resp;
177 #endif
178
179 typedef struct {
180   time_t time_stamp;
181   /*************/
182   uschar verify_override:1;
183   uschar ocsp:3;
184   uschar session[1];
185 } dbdata_tls_session;
186
187
188 #endif  /* whole file */
189 /* End of hintsdb_structs.h */