summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libmilter/libmilter.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/sendmail/libmilter/libmilter.h')
-rw-r--r--contrib/sendmail/libmilter/libmilter.h157
1 files changed, 152 insertions, 5 deletions
diff --git a/contrib/sendmail/libmilter/libmilter.h b/contrib/sendmail/libmilter/libmilter.h
index 9cebdc2..5a12409 100644
--- a/contrib/sendmail/libmilter/libmilter.h
+++ b/contrib/sendmail/libmilter/libmilter.h
@@ -19,19 +19,108 @@
#ifdef _DEFINE
# define EXTERN
# define INIT(x) = x
-SM_IDSTR(MilterlId, "@(#)$Id: libmilter.h,v 8.51 2006/01/04 02:24:37 ca Exp $")
+SM_IDSTR(MilterlId, "@(#)$Id: libmilter.h,v 8.74 2006/12/19 18:19:52 ca Exp $")
#else /* _DEFINE */
# define EXTERN extern
# define INIT(x)
#endif /* _DEFINE */
+#include "sm/tailq.h"
+
#define NOT_SENDMAIL 1
#define _SOCK_ADDR union bigsockaddr
#include "sendmail.h"
+#ifdef SM_ASSERT
+#undef SM_ASSERT
+#endif
+#ifndef SM_ASSERT
+#include <assert.h>
+#define SM_ASSERT(x) assert(x)
+#endif
+
#include "libmilter/milter.h"
+#define MAX_MACROS_ENTRIES 7 /* max size of macro pointer array */
+
+typedef SM_TAILQ_HEAD(, smfi_str) smfi_hd_T;
+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
+{
+ sthread_t ctx_id; /* thread id */
+ socket_t ctx_sd; /* socket descriptor */
+ int ctx_dbg; /* debug level */
+ time_t ctx_timeout; /* timeout */
+ int ctx_state; /* state */
+ smfiDesc_ptr ctx_smfi; /* filter description */
+
+ 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 */
+
+#if _FFR_THREAD_MONITOR
+ time_t ctx_start; /* start time of thread */
+ SM_TAILQ_ENTRY(smfi_str) ctx_mon_link;
+#endif /* _FFR_THREAD_MONITOR */
+
+#if _FFR_WORKERS_POOL
+ long ctx_sid; /* session identifier */
+ int ctx_wstate; /* state of the session (worker pool) */
+ int ctx_wait; /* elapsed time waiting for sm cmd */
+ SM_TAILQ_ENTRY(smfi_str) ctx_link;
+#endif /* _FFR_WORKERS_POOL */
+};
+
# define ValidSocket(sd) ((sd) >= 0)
# define INVALID_SOCKET (-1)
# define closesocket close
@@ -49,6 +138,34 @@ typedef pthread_mutex_t smutex_t;
# define smutex_unlock(mp) (pthread_mutex_unlock(mp) == 0)
# define smutex_trylock(mp) (pthread_mutex_trylock(mp) == 0)
+#if _FFR_WORKERS_POOL
+/* 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;
+#define scond_init(cp) pthread_cond_init(cp, NULL)
+#define scond_destroy(cp) pthread_cond_destroy(cp)
+#define scond_wait(cp, mp) pthread_cond_wait(cp, mp)
+#define scond_signal(cp) pthread_cond_signal(cp)
+#define scond_broadcast(cp) pthread_cond_broadcast(cp)
+#define scond_timedwait(cp, mp, to) \
+ do \
+ { \
+ struct timespec timeout; \
+ struct timeval now; \
+ gettimeofday(&now, NULL); \
+ timeout.tv_sec = now.tv_sec + to; \
+ timeout.tv_nsec = now.tv_usec / 1000; \
+ r = pthread_cond_timedwait(cp,mp,&timeout); \
+ if (r != 0 && r != ETIMEDOUT) \
+ smi_log(SMI_LOG_ERR, \
+ "pthread_cond_timedwait error %d", r); \
+ } while (0)
+
+
#if SM_CONF_POLL
# include <poll.h>
@@ -117,10 +234,6 @@ typedef pthread_mutex_t smutex_t;
#include <sys/time.h>
-/* version info */
-#define MILTER_PRODUCT_NAME "libmilter"
-#define MILTER_VERSION 100
-
/* some defaults */
#define MI_TIMEOUT 7210 /* default timeout for read/write */
#define MI_CHK_TIME 5 /* checking whether to terminate */
@@ -184,4 +297,38 @@ extern int mi_wr_cmd __P((socket_t, struct timeval *, int, char *, size_t));
extern bool mi_sendok __P((SMFICTX_PTR, int));
+#if _FFR_THREAD_MONITOR
+extern bool Monitor;
+
+#define MI_MONITOR_INIT() mi_monitor_init()
+#define MI_MONITOR_BEGIN(ctx, cmd) \
+ do \
+ { \
+ if (Monitor) \
+ mi_monitor_work_begin(ctx, cmd);\
+ } while (0)
+
+#define MI_MONITOR_END(ctx, cmd) \
+ do \
+ { \
+ if (Monitor) \
+ mi_monitor_work_end(ctx, cmd); \
+ } while (0)
+
+int mi_monitor_init __P((void));
+int mi_monitor_work_begin __P((SMFICTX_PTR, int));
+int mi_monitor_work_end __P((SMFICTX_PTR, int));
+
+#else /* _FFR_THREAD_MONITOR */
+#define MI_MONITOR_INIT() MI_SUCCESS
+#define MI_MONITOR_BEGIN(ctx, cmd)
+#define MI_MONITOR_END(ctx, cmd)
+#endif /* _FFR_THREAD_MONITOR */
+
+#if _FFR_WORKERS_POOL
+extern int mi_pool_manager_init __P((void));
+extern int mi_pool_controller_init __P((void));
+extern int mi_start_session __P((SMFICTX_PTR));
+#endif /* _FFR_WORKERS_POOL */
+
#endif /* ! _LIBMILTER_H */
OpenPOWER on IntegriCloud