2 * Copyright (c) 1999-2003 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.
11 ** LIBMILTER.H -- include file for mail filter library functions
15 # define _LIBMILTER_H 1
22 SM_IDSTR(MilterlId
, "@(#)$Id: libmilter.h,v 8.33.2.12 2003/09/08 21:39:55 yuri Exp $")
24 # define EXTERN extern
29 #define NOT_SENDMAIL 1
30 #define _SOCK_ADDR union bigsockaddr
33 #include "libmilter/milter.h"
35 # define ValidSocket(sd) ((sd) >= 0)
36 # define INVALID_SOCKET (-1)
37 # define closesocket close
38 # define MI_SOCK_READ(s, b, l) read(s, b, l)
39 # define MI_SOCK_READ_FAIL(x) ((x) < 0)
40 # define MI_SOCK_WRITE(s, b, l) write(s, b, l)
42 # define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg)
43 # define sthread_get_id() pthread_self()
45 typedef pthread_mutex_t smutex_t
;
46 # define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0)
47 # define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0)
48 # define smutex_lock(mp) (pthread_mutex_lock(mp) == 0)
49 # define smutex_unlock(mp) (pthread_mutex_unlock(mp) == 0)
50 # define smutex_trylock(mp) (pthread_mutex_trylock(mp) == 0)
55 # define MI_POLLSELECT "poll"
57 # define MI_POLL_RD_FLAGS (POLLIN | POLLPRI)
58 # define MI_POLL_WR_FLAGS (POLLOUT)
59 # define MI_MS(timeout) (((timeout)->tv_sec * 1000) + (timeout)->tv_usec)
61 # define FD_RD_VAR(rds, excs) struct pollfd rds
62 # define FD_WR_VAR(wrs) struct pollfd wrs
64 # define FD_RD_INIT(sd, rds, excs) \
66 (rds).events = MI_POLL_RD_FLAGS; \
69 # define FD_WR_INIT(sd, wrs) \
71 (wrs).events = MI_POLL_WR_FLAGS; \
74 # define FD_IS_RD_EXC(sd, rds, excs) \
75 (((rds).revents & (POLLERR | POLLHUP | POLLNVAL)) != 0)
77 # define FD_IS_WR_RDY(sd, wrs) \
78 (((wrs).revents & MI_POLL_WR_FLAGS) != 0)
80 # define FD_IS_RD_RDY(sd, rds, excs) \
81 (((rds).revents & MI_POLL_RD_FLAGS) != 0)
83 # define FD_WR_READY(sd, excs, timeout) \
84 poll(&(wrs), 1, MI_MS(timeout))
86 # define FD_RD_READY(sd, rds, excs, timeout) \
87 poll(&(rds), 1, MI_MS(timeout))
89 #else /* _FFR_USE_POLL */
91 # include <sm/fdset.h>
92 # define MI_POLLSELECT "select"
94 # define FD_RD_VAR(rds, excs) fd_set rds, excs
95 # define FD_WR_VAR(wrs) fd_set wrs
97 # define FD_RD_INIT(sd, rds, excs) \
99 FD_SET((unsigned int) (sd), &(rds)); \
101 FD_SET((unsigned int) (sd), &(excs))
103 # define FD_WR_INIT(sd, wrs) \
105 FD_SET((unsigned int) (sd), &(wrs)); \
107 # define FD_IS_RD_EXC(sd, rds, excs) FD_ISSET(sd, &(excs))
108 # define FD_IS_WR_RDY(sd, wrs) FD_ISSET((sd), &(wrs))
109 # define FD_IS_RD_RDY(sd, rds, excs) FD_ISSET((sd), &(rds))
111 # define FD_WR_READY(sd, wrs, timeout) \
112 select((sd) + 1, NULL, &(wrs), NULL, (timeout))
113 # define FD_RD_READY(sd, rds, excs, timeout) \
114 select((sd) + 1, &(rds), NULL, &(excs), (timeout))
116 #endif /* _FFR_USE_POLL */
118 #include <sys/time.h>
121 #define MILTER_PRODUCT_NAME "libmilter"
122 #define MILTER_VERSION 100
125 #define MI_TIMEOUT 7210 /* default timeout for read/write */
126 #define MI_CHK_TIME 5 /* checking whether to terminate */
130 # define MI_SOMAXCONN SOMAXCONN
131 # else /* SOMAXCONN */
132 # define MI_SOMAXCONN 20
133 # endif /* SOMAXCONN */
134 #endif /* ! MI_SOMAXCONN */
136 /* maximum number of repeated failures in mi_listener() */
137 #define MAX_FAILS_M 16 /* malloc() */
138 #define MAX_FAILS_T 16 /* thread creation */
139 #define MAX_FAILS_A 16 /* accept() */
140 #define MAX_FAILS_S 16 /* select() */
142 /* internal "commands", i.e., error codes */
143 #define SMFIC_TIMEOUT ((char) 1) /* timeout */
144 #define SMFIC_SELECT ((char) 2) /* select error */
145 #define SMFIC_MALLOC ((char) 3) /* malloc error */
146 #define SMFIC_RECVERR ((char) 4) /* recv() error */
147 #define SMFIC_EOF ((char) 5) /* eof */
148 #define SMFIC_UNKNERR ((char) 6) /* unknown error */
149 #define SMFIC_TOOBIG ((char) 7) /* body chunk too big */
150 #define SMFIC_VALIDCMD ' ' /* first valid command */
153 #define smi_log syslog
154 #define sm_dprintf (void) printf
155 #define milter_ret int
156 #define SMI_LOG_ERR LOG_ERR
157 #define SMI_LOG_FATAL LOG_ERR
158 #define SMI_LOG_WARN LOG_WARNING
159 #define SMI_LOG_INFO LOG_INFO
160 #define SMI_LOG_DEBUG LOG_DEBUG
163 #define MILTER_CONT 0
164 #define MILTER_STOP 1
165 #define MILTER_ABRT 2
168 extern int mi_handle_session
__P((SMFICTX_PTR
));
169 extern int mi_engine
__P((SMFICTX_PTR
));
170 extern int mi_listener
__P((char *, int, smfiDesc_ptr
, time_t, int));
171 extern void mi_clr_macros
__P((SMFICTX_PTR
, int));
172 extern int mi_stop
__P((void));
173 extern int mi_control_startup
__P((char *));
174 extern void mi_stop_milters
__P((int));
175 extern void mi_clean_signals
__P((void));
176 extern struct hostent
*mi_gethostbyname
__P((char *, int));
177 extern int mi_inet_pton
__P((int, const char *, void *));
178 extern void mi_closener
__P((void));
179 extern int mi_opensocket
__P((char *, int, int, smfiDesc_ptr
));
181 /* communication functions */
182 extern char *mi_rd_cmd
__P((socket_t
, struct timeval
*, char *, size_t *, char *));
183 extern int mi_wr_cmd
__P((socket_t
, struct timeval
*, int, char *, size_t));
184 extern bool mi_sendok
__P((SMFICTX_PTR
, int));
187 #endif /* ! _LIBMILTER_H */