2 * Copyright (c) 1999-2004 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
10 * $Id: mfapi.h,v 8.60 2004/08/20 21:24:14 ca Exp $
14 ** MFAPI.H -- Global definitions for mail filter library and mail filters.
17 #ifndef _LIBMILTER_MFAPI_H
18 # define _LIBMILTER_MFAPI_H 1
21 # define SMFI_VERSION 2 /* version number */
22 #endif /* ! SMFI_VERSION */
24 # include <sys/types.h>
25 # include <sys/socket.h>
27 #include "libmilter/mfdef.h"
29 # define LIBMILTER_API extern
32 /* Only need to export C interface if used by C++ source code */
35 #endif /* __cplusplus */
38 # define _SOCK_ADDR struct sockaddr
39 #endif /* ! _SOCK_ADDR */
42 ** libmilter functions return one of the following to indicate
47 #define MI_FAILURE (-1)
49 /* "forward" declarations */
50 typedef struct smfi_str SMFICTX;
51 typedef struct smfi_str *SMFICTX_PTR;
53 typedef struct smfiDesc smfiDesc_str;
54 typedef struct smfiDesc *smfiDesc_ptr;
57 ** Type which callbacks should return to indicate message status.
58 ** This may take on one of the SMFIS_* values listed below.
63 #if defined(__linux__) && defined(__GNUC__) && defined(__cplusplus) && __GNUC_MINOR__ >= 8
64 # define SM__P(X) __PMT(X)
65 #else /* __linux__ && __GNUC__ && __cplusplus && _GNUC_MINOR__ >= 8 */
66 # define SM__P(X) __P(X)
67 #endif /* __linux__ && __GNUC__ && __cplusplus && _GNUC_MINOR__ >= 8 */
69 /* Some platforms don't define __P -- do it for them here: */
75 # endif /* __STDC__ */
80 #else /* SM_CONF_STDBOOL_H */
83 # ifndef __bool_true_false_are_defined
85 # define __bool_true_false_are_defined 1
86 # endif /* ! __bool_true_false_are_defined */
88 # endif /* ! __cplusplus */
89 #endif /* SM_CONF_STDBOOL_H */
92 ** structure describing one milter
97 char *xxfi_name; /* filter name */
98 int xxfi_version; /* version code -- do not change */
99 unsigned long xxfi_flags; /* flags */
101 /* connection info filter */
102 sfsistat (*xxfi_connect) SM__P((SMFICTX *, char *, _SOCK_ADDR *));
104 /* SMTP HELO command filter */
105 sfsistat (*xxfi_helo) SM__P((SMFICTX *, char *));
107 /* envelope sender filter */
108 sfsistat (*xxfi_envfrom) SM__P((SMFICTX *, char **));
110 /* envelope recipient filter */
111 sfsistat (*xxfi_envrcpt) SM__P((SMFICTX *, char **));
114 sfsistat (*xxfi_header) SM__P((SMFICTX *, char *, char *));
117 sfsistat (*xxfi_eoh) SM__P((SMFICTX *));
120 sfsistat (*xxfi_body) SM__P((SMFICTX *, unsigned char *, size_t));
123 sfsistat (*xxfi_eom) SM__P((SMFICTX *));
125 /* message aborted */
126 sfsistat (*xxfi_abort) SM__P((SMFICTX *));
128 /* connection cleanup */
129 sfsistat (*xxfi_close) SM__P((SMFICTX *));
132 /* any unrecognized or unimplemented command filter */
133 sfsistat (*xxfi_unknown) SM__P((SMFICTX *, char *));
134 #endif /* SMFI_VERSION > 2 */
137 /* any unrecognized or unimplemented command filter */
138 sfsistat (*xxfi_data) SM__P((SMFICTX *));
139 #endif /* SMFI_VERSION > 3 */
142 LIBMILTER_API int smfi_opensocket __P((bool));
143 LIBMILTER_API int smfi_register __P((struct smfiDesc));
144 LIBMILTER_API int smfi_main __P((void));
145 LIBMILTER_API int smfi_setbacklog __P((int));
146 LIBMILTER_API int smfi_setdbg __P((int));
147 LIBMILTER_API int smfi_settimeout __P((int));
148 LIBMILTER_API int smfi_setconn __P((char *));
149 LIBMILTER_API int smfi_stop __P((void));
151 LIBMILTER_API size_t smfi_setmaxdatasize __P((size_t));
152 #endif /* _FFR_MAXDATASIZE */
155 ** What the filter might do -- values to be ORed together for
156 ** smfiDesc.xxfi_flags.
159 #define SMFIF_NONE 0x00000000L /* no flags */
160 #define SMFIF_ADDHDRS 0x00000001L /* filter may add headers */
161 #define SMFIF_CHGBODY 0x00000002L /* filter may replace body */
162 #define SMFIF_MODBODY SMFIF_CHGBODY /* backwards compatible */
163 #define SMFIF_ADDRCPT 0x00000004L /* filter may add recipients */
164 #define SMFIF_DELRCPT 0x00000008L /* filter may delete recipients */
165 #define SMFIF_CHGHDRS 0x00000010L /* filter may change/delete headers */
166 #define SMFIF_QUARANTINE 0x00000020L /* filter may quarantine envelope */
169 ** Continue processing message/connection.
172 #define SMFIS_CONTINUE 0
175 ** Reject the message/connection.
176 ** No further routines will be called for this message
177 ** (or connection, if returned from a connection-oriented routine).
180 #define SMFIS_REJECT 1
183 ** Accept the message,
184 ** but silently discard the message.
185 ** No further routines will be called for this message.
186 ** This is only meaningful from message-oriented routines.
189 #define SMFIS_DISCARD 2
192 ** Accept the message/connection.
193 ** No further routines will be called for this message
194 ** (or connection, if returned from a connection-oriented routine;
195 ** in this case, it causes all messages on this connection
196 ** to be accepted without filtering).
199 #define SMFIS_ACCEPT 3
202 ** Return a temporary failure, i.e.,
203 ** the corresponding SMTP command will return a 4xx status code.
204 ** In some cases this may prevent further routines from
205 ** being called on this message or connection,
206 ** although in other cases (e.g., when processing an envelope
207 ** recipient) processing of the message will continue.
210 #define SMFIS_TEMPFAIL 4
214 ** Filter Routine Details
217 /* connection info filter */
218 extern sfsistat xxfi_connect __P((SMFICTX *, char *, _SOCK_ADDR *));
221 ** xxfi_connect(ctx, hostname, hostaddr) Invoked on each connection
223 ** char *hostname; Host domain name, as determined by a reverse lookup
224 ** on the host address.
225 ** _SOCK_ADDR *hostaddr; Host address, as determined by a getpeername
226 ** call on the SMTP socket.
229 /* SMTP HELO command filter */
230 extern sfsistat xxfi_helo __P((SMFICTX *, char *));
233 ** xxfi_helo(ctx, helohost) Invoked on SMTP HELO/EHLO command
235 ** char *helohost; Value passed to HELO/EHLO command, which should be
236 ** the domain name of the sending host (but is, in practice,
237 ** anything the sending host wants to send).
240 /* envelope sender filter */
241 extern sfsistat xxfi_envfrom __P((SMFICTX *, char **));
244 ** xxfi_envfrom(ctx, argv) Invoked on envelope from
246 ** char **argv; Null-terminated SMTP command arguments;
247 ** argv[0] is guaranteed to be the sender address.
248 ** Later arguments are the ESMTP arguments.
251 /* envelope recipient filter */
252 extern sfsistat xxfi_envrcpt __P((SMFICTX *, char **));
255 ** xxfi_envrcpt(ctx, argv) Invoked on each envelope recipient
257 ** char **argv; Null-terminated SMTP command arguments;
258 ** argv[0] is guaranteed to be the recipient address.
259 ** Later arguments are the ESMTP arguments.
262 /* unknown command filter */
264 extern sfsistat *xxfi_unknown __P((SMFICTX *, char *));
267 ** xxfi_unknown(ctx, arg) Invoked when SMTP command is not recognized or not
269 ** char *arg; Null-terminated SMTP command
273 extern sfsistat xxfi_header __P((SMFICTX *, char *, char *));
276 ** xxfi_header(ctx, headerf, headerv) Invoked on each message header. The
277 ** content of the header may have folded white space (that is, multiple
278 ** lines with following white space) included.
280 ** char *headerf; Header field name
281 ** char *headerv; Header field value
285 extern sfsistat xxfi_eoh __P((SMFICTX *));
288 ** xxfi_eoh(ctx) Invoked at end of header
292 extern sfsistat xxfi_body __P((SMFICTX *, unsigned char *, size_t));
295 ** xxfi_body(ctx, bodyp, bodylen) Invoked for each body chunk. There may
296 ** be multiple body chunks passed to the filter. End-of-lines are
297 ** represented as received from SMTP (normally Carriage-Return/Line-Feed).
299 ** unsigned char *bodyp; Pointer to body data
300 ** size_t bodylen; Length of body data
304 extern sfsistat xxfi_eom __P((SMFICTX *));
307 ** xxfi_eom(ctx) Invoked at end of message. This routine can perform
308 ** special operations such as modifying the message header, body, or
312 /* message aborted */
313 extern sfsistat xxfi_abort __P((SMFICTX *));
316 ** xxfi_abort(ctx) Invoked if message is aborted outside of the control of
317 ** the filter, for example, if the SMTP sender issues an RSET command. If
318 ** xxfi_abort is called, xxfi_eom will not be called and vice versa.
321 /* connection cleanup */
322 extern sfsistat xxfi_close __P((SMFICTX *));
325 ** xxfi_close(ctx) Invoked at end of the connection. This is called on
326 ** close even if the previous mail transaction was aborted.
331 ** Additional information is passed in to the vendor filter routines using
332 ** symbols. Symbols correspond closely to sendmail macros. The symbols
333 ** defined depend on the context. The value of a symbol is accessed using:
336 /* Return the value of a symbol. */
337 LIBMILTER_API char * smfi_getsymval __P((SMFICTX *, char *));
340 ** Return the value of a symbol.
342 ** SMFICTX *ctx; Opaque context structure
343 ** char *symname; The name of the symbol to access.
347 ** Vendor filter routines that want to pass additional information back to
348 ** the MTA for use in SMTP replies may call smfi_setreply before returning.
351 LIBMILTER_API int smfi_setreply __P((SMFICTX *, char *, char *, char *));
354 ** Alternatively, smfi_setmlreply can be called if a multi-line SMTP reply
358 LIBMILTER_API int smfi_setmlreply __P((SMFICTX *, const char *, const char *, ...));
361 ** Set the specific reply code to be used in response to the active
362 ** command. If not specified, a generic reply code is used.
364 ** SMFICTX *ctx; Opaque context structure
365 ** char *rcode; The three-digit (RFC 821) SMTP reply code to be
366 ** returned, e.g., ``551''.
367 ** char *xcode; The extended (RFC 2034) reply code, e.g., ``5.7.6''.
368 ** char *message; The text part of the SMTP reply.
372 ** The xxfi_eom routine is called at the end of a message (essentially,
373 ** after the final DATA dot). This routine can call some special routines
374 ** to modify the envelope, header, or body of the message before the
375 ** message is enqueued. These routines must not be called from any vendor
376 ** routine other than xxfi_eom.
379 LIBMILTER_API int smfi_addheader __P((SMFICTX *, char *, char *));
382 ** Add a header to the message. It is not checked for standards
383 ** compliance; the mail filter must ensure that no protocols are violated
384 ** as a result of adding this header.
386 ** SMFICTX *ctx; Opaque context structure
387 ** char *headerf; Header field name
388 ** char *headerv; Header field value
391 LIBMILTER_API int smfi_chgheader __P((SMFICTX *, char *, int, char *));
394 ** Change/delete a header in the message. It is not checked for standards
395 ** compliance; the mail filter must ensure that no protocols are violated
396 ** as a result of adding this header.
398 ** SMFICTX *ctx; Opaque context structure
399 ** char *headerf; Header field name
400 ** int index; The Nth occurence of header field name
401 ** char *headerv; New header field value (empty for delete header)
404 LIBMILTER_API int smfi_insheader __P((SMFICTX *, int, char *, char *));
407 ** Insert a header into the message. It is not checked for standards
408 ** compliance; the mail filter must ensure that no protocols are violated
409 ** as a result of adding this header.
411 ** SMFICTX *ctx; Opaque context structure
412 ** int idx; index into the header list where the insertion should happen
413 ** char *headerh; Header field name
414 ** char *headerv; Header field value
417 LIBMILTER_API int smfi_addrcpt __P((SMFICTX *, char *));
420 ** Add a recipient to the envelope
422 ** SMFICTX *ctx; Opaque context structure
423 ** char *rcpt; Recipient to be added
426 LIBMILTER_API int smfi_delrcpt __P((SMFICTX *, char *));
429 ** Send a "no-op" up to the MTA to tell it we're still alive, so long
430 ** milter-side operations don't time out.
432 ** SMFICTX *ctx; Opaque context structure
435 LIBMILTER_API int smfi_progress __P((SMFICTX *));
438 ** Delete a recipient from the envelope
440 ** SMFICTX *ctx; Opaque context structure
441 ** char *rcpt; Envelope recipient to be deleted. This should be in
442 ** exactly the form passed to xxfi_envrcpt or the address may
446 LIBMILTER_API int smfi_replacebody __P((SMFICTX *, unsigned char *, int));
449 ** Replace the body of the message. This routine may be called multiple
450 ** times if the body is longer than convenient to send in one call. End of
451 ** line should be represented as Carriage-Return/Line Feed.
453 ** char *bodyp; Pointer to block of body information to insert
454 ** int bodylen; Length of data pointed at by bodyp
458 ** If the message is aborted (for example, if the SMTP sender sends the
459 ** envelope but then does a QUIT or RSET before the data is sent),
460 ** xxfi_abort is called. This can be used to reset state.
464 ** Quarantine an envelope
466 ** SMFICTX *ctx; Opaque context structure
467 ** char *reason: explanation
470 LIBMILTER_API int smfi_quarantine __P((SMFICTX *ctx, char *reason));
473 ** Connection-private data (specific to an SMTP connection) can be
474 ** allocated using the smfi_setpriv routine; routines can access private
475 ** data using smfi_getpriv.
478 LIBMILTER_API int smfi_setpriv __P((SMFICTX *, void *));
481 ** Set the private data pointer
483 ** SMFICTX *ctx; Opaque context structure
484 ** void *privatedata; Pointer to private data area
487 LIBMILTER_API void *smfi_getpriv __P((SMFICTX *));
491 #endif /* __cplusplus */
493 #endif /* ! _LIBMILTER_MFAPI_H */