libmilter.h revision 058561cbaa119a6f2659bc27ef343e1b47266bb2
/*
* Copyright (c) 1999-2003, 2006 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*/
/*
** LIBMILTER.H -- include file for mail filter library functions
*/
#ifndef _LIBMILTER_H
# define _LIBMILTER_H 1
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef _DEFINE
# define EXTERN
# define INIT(x) = x
#else /* _DEFINE */
# define EXTERN extern
# define INIT(x)
#endif /* _DEFINE */
#define NOT_SENDMAIL 1
#define _SOCK_ADDR union bigsockaddr
#include "sendmail.h"
#ifdef SM_ASSERT
#endif
#ifndef SM_ASSERT
#include <assert.h>
#endif
typedef struct smfi_str smfi_str_S;
/*
** Context for one milter session.
**
** Notes:
** There is a 1-1 correlation between a sendmail SMTP server process,
** an SMTP session, and an milter context. Due to the nature of SMTP
** session handling in sendmail 8, this libmilter implementation deals
** only with a single SMTP session per MTA - libmilter connection.
**
** There is no "global" context for libmilter, global variables are
** just that (they are not "collected" in a context).
**
** Implementation hint:
** macros are stored in mac_buf[] as sequence of:
** macro_name \0 macro_value
** (just as read from the MTA)
** mac_ptr is a list of pointers into mac_buf to the beginning of each
** entry, i.e., macro_name, macro_value, ...
*/
struct smfi_str
{
int ctx_dbg; /* debug level */
int ctx_state; /* state */
int ctx_prot_vers; /* libmilter protocol version */
unsigned long ctx_aflags; /* milter action flags */
unsigned long ctx_pflags; /* milter protocol flags */
/*
** milter protocol flags that are sent to the MTA;
** this is the same as ctx_pflags except for those flags that
** are not offered by the MTA but emulated in libmilter.
*/
unsigned long ctx_pflags2mta;
/*
** milter protocol version that is sent to the MTA;
** this is the same as ctx_prot_vers unless the
** MTA protocol version (ctx_mta_prot_vers) is smaller
** but still "acceptable".
*/
int ctx_prot_vers2mta;
char **ctx_mac_ptr[MAX_MACROS_ENTRIES];
char *ctx_mac_buf[MAX_MACROS_ENTRIES];
char *ctx_mac_list[MAX_MACROS_ENTRIES];
char *ctx_reply; /* reply code */
void *ctx_privdata; /* private data */
int ctx_mta_prot_vers; /* MTA protocol version */
unsigned long ctx_mta_pflags; /* MTA protocol flags */
unsigned long ctx_mta_aflags; /* MTA action flags */
#endif /* _FFR_THREAD_MONITOR */
long ctx_sid; /* session identifier */
int ctx_wstate; /* state of the session (worker pool) */
int ctx_wait; /* elapsed time waiting for sm cmd */
#endif /* _FFR_WORKERS_POOL */
};
# define INVALID_SOCKET (-1)
# define closesocket close
# define MI_SOCK_READ(s, b, l) read(s, b, l)
# define MI_SOCK_READ_FAIL(x) ((x) < 0)
# define MI_SOCK_WRITE(s, b, l) write(s, b, l)
# define sthread_get_id() pthread_self()
typedef pthread_mutex_t smutex_t;
/* SM_CONF_POLL shall be defined with _FFR_WORKERS_POOL */
# if !SM_CONF_POLL
# define SM_CONF_POLL 1
# endif /* SM_CONF_POLL */
#endif /* _FFR_WORKERS_POOL */
typedef pthread_cond_t scond_t;
do \
{ \
if (r != 0 && r != ETIMEDOUT) \
"pthread_cond_timedwait error %d", r); \
} while (0)
#if SM_CONF_POLL
# include <poll.h>
# define MI_POLLSELECT "poll"
# define MI_POLL_WR_FLAGS (POLLOUT)
#else /* SM_CONF_POLL */
# define MI_POLLSELECT "select"
#endif /* SM_CONF_POLL */
/* some defaults */
#ifndef MI_SOMAXCONN
# if SOMAXCONN > 20
# define MI_SOMAXCONN SOMAXCONN
# else /* SOMAXCONN */
# define MI_SOMAXCONN 20
# endif /* SOMAXCONN */
#endif /* ! MI_SOMAXCONN */
/* maximum number of repeated failures in mi_listener() */
/* internal "commands", i.e., error codes */
/* hack */
#define sm_dprintf (void) printf
#define milter_ret int
#define SMI_LOG_ERR LOG_ERR
#define SMI_LOG_FATAL LOG_ERR
#define SMI_LOG_WARN LOG_WARNING
#define SMI_LOG_INFO LOG_INFO
#define SMI_LOG_DEBUG LOG_DEBUG
/* stop? */
#define MILTER_CONT 0
#define MILTER_STOP 1
#define MILTER_ABRT 2
/* functions */
extern int mi_control_startup __P((char *));
extern void mi_stop_milters __P((int));
extern void mi_clean_signals __P((void));
extern int mi_inet_pton __P((int, const char *, void *));
extern void mi_closener __P((void));
/* communication functions */
extern bool Monitor;
#define MI_MONITOR_INIT() mi_monitor_init()
do \
{ \
if (Monitor) \
} while (0)
do \
{ \
if (Monitor) \
} while (0)
int mi_monitor_init __P((void));
#else /* _FFR_THREAD_MONITOR */
#define MI_MONITOR_INIT() MI_SUCCESS
#endif /* _FFR_THREAD_MONITOR */
extern int mi_pool_manager_init __P((void));
extern int mi_pool_controller_init __P((void));
#endif /* _FFR_WORKERS_POOL */
#endif /* ! _LIBMILTER_H */