libmilter.h revision 77349
164562Sgshapiro/*
277349Sgshapiro * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
364562Sgshapiro *	All rights reserved.
464562Sgshapiro *
564562Sgshapiro * By using this file, you agree to the terms and conditions set
664562Sgshapiro * forth in the LICENSE file which can be found at the top level of
764562Sgshapiro * the sendmail distribution.
864562Sgshapiro */
964562Sgshapiro
1064562Sgshapiro/*
1164562Sgshapiro**  LIBMILTER.H -- include file for mail filter library functions
1264562Sgshapiro*/
1364562Sgshapiro
1464562Sgshapiro#ifndef _LIBMILTER_H
1564562Sgshapiro# define _LIBMILTER_H	1
1664562Sgshapiro#ifdef _DEFINE
1764562Sgshapiro# define EXTERN
1864562Sgshapiro# define INIT(x)	= x
1964562Sgshapiro# ifndef lint
2077349Sgshapirostatic char MilterlId[] = "@(#)$Id: libmilter.h,v 8.3.6.14 2001/05/27 14:31:12 ca Exp $";
2164562Sgshapiro# endif /* ! lint */
2264562Sgshapiro#else /* _DEFINE */
2364562Sgshapiro# define EXTERN extern
2464562Sgshapiro# define INIT(x)
2564562Sgshapiro#endif /* _DEFINE */
2664562Sgshapiro
2764562Sgshapiro
2864562Sgshapiro#define NOT_SENDMAIL	1
2964562Sgshapiro#define _SOCK_ADDR	union bigsockaddr
3064562Sgshapiro#include "sendmail.h"
3164562Sgshapiro
3264562Sgshapiro#include "libmilter/milter.h"
3364562Sgshapiro
3464562Sgshapiro#ifndef __P
3564562Sgshapiro# include "sendmail/cdefs.h"
3664562Sgshapiro#endif /* ! __P */
3764562Sgshapiro#include "sendmail/useful.h"
3864562Sgshapiro
3964562Sgshapiro# define ValidSocket(sd)	((sd) >= 0)
4066494Sgshapiro# define INVALID_SOCKET		-1
4166494Sgshapiro# define MI_SOCK_READ(s, b, l)	(read(s, b, l))
4266494Sgshapiro# define MI_SOCK_WRITE(s, b, l)	(write(s, b, l))
4364562Sgshapiro
4464562Sgshapiro# define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg)
4564562Sgshapiro# define sthread_get_id()	pthread_self()
4664562Sgshapiro
4771345Sgshapirotypedef pthread_mutex_t smutex_t;
4871345Sgshapiro# define smutex_init(mp)	(pthread_mutex_init(mp, NULL) == 0)
4971345Sgshapiro# define smutex_destroy(mp)	(pthread_mutex_destroy(mp) == 0)
5071345Sgshapiro# define smutex_lock(mp)	(pthread_mutex_lock(mp) == 0)
5171345Sgshapiro# define smutex_unlock(mp)	(pthread_mutex_unlock(mp) == 0)
5271345Sgshapiro# define smutex_trylock(mp)	(pthread_mutex_trylock(mp) == 0)
5371345Sgshapiro
5464562Sgshapiro#include <sys/time.h>
5564562Sgshapiro
5664562Sgshapiro/* version info */
5764562Sgshapiro#define MILTER_PRODUCT_NAME	"libmilter"
5864562Sgshapiro#define MILTER_VERSION		100
5964562Sgshapiro
6064562Sgshapiro/* some defaults */
6177349Sgshapiro#define MI_TIMEOUT	7210		/* default timeout for read/write */
6264562Sgshapiro#define MI_CHK_TIME	5		/* checking whether to terminate */
6364562Sgshapiro
6466494Sgshapiro#if SOMAXCONN > 20
6566494Sgshapiro# define MI_SOMAXCONN	SOMAXCONN
6666494Sgshapiro#else /* SOMAXCONN */
6766494Sgshapiro# define MI_SOMAXCONN	20
6866494Sgshapiro#endif /* SOMAXCONN */
6966494Sgshapiro
7064562Sgshapiro/* maximum number of repeated failures in mi_listener() */
7164562Sgshapiro#define MAX_FAILS_M	16	/* malloc() */
7264562Sgshapiro#define MAX_FAILS_T	16	/* thread creation */
7377349Sgshapiro#define MAX_FAILS_A	16	/* accept() */
7464562Sgshapiro
7564562Sgshapiro/* internal "commands", i.e., error codes */
7664562Sgshapiro#define SMFIC_TIMEOUT	((char) 1)	/* timeout */
7764562Sgshapiro#define SMFIC_SELECT	((char) 2)	/* select error */
7864562Sgshapiro#define SMFIC_MALLOC	((char) 3)	/* malloc error */
7964562Sgshapiro#define SMFIC_RECVERR	((char) 4)	/* recv() error */
8064562Sgshapiro#define SMFIC_EOF	((char) 5)	/* eof */
8164562Sgshapiro#define SMFIC_UNKNERR	((char) 6)	/* unknown error */
8264562Sgshapiro#define SMFIC_TOOBIG	((char) 7)	/* body chunk too big */
8364562Sgshapiro#define SMFIC_VALIDCMD	' '		/* first valid command */
8464562Sgshapiro
8564562Sgshapiro/* hack */
8664562Sgshapiro#define smi_log		syslog
8764562Sgshapiro#define milter_ret	int
8864562Sgshapiro#define SMI_LOG_ERR	LOG_ERR
8964562Sgshapiro#define SMI_LOG_FATAL	LOG_ERR
9064562Sgshapiro#define SMI_LOG_WARN	LOG_WARNING
9164562Sgshapiro#define SMI_LOG_INFO	LOG_INFO
9264562Sgshapiro#define SMI_LOG_DEBUG	LOG_DEBUG
9364562Sgshapiro
9464562Sgshapiro/* stop? */
9564562Sgshapiro#define MILTER_CONT	0
9664562Sgshapiro#define MILTER_STOP	1
9764562Sgshapiro#define MILTER_ABRT	2
9864562Sgshapiro
9964562Sgshapiro/* functions */
10064562Sgshapiroextern int	mi_handle_session __P((SMFICTX_PTR));
10164562Sgshapiroextern int	mi_engine __P((SMFICTX_PTR));
10266494Sgshapiroextern int	mi_listener __P((char *, int, smfiDesc_ptr, time_t, int));
10364562Sgshapiroextern void	mi_clr_macros __P((SMFICTX_PTR, int));
10464562Sgshapiroextern int	mi_stop __P((void));
10564562Sgshapiroextern int	mi_control_startup __P((char *));
10664562Sgshapiroextern void	mi_stop_milters __P((int));
10764562Sgshapiroextern void	mi_clean_signals __P((void));
10864562Sgshapiroextern struct hostent *mi_gethostbyname __P((char *, int));
10966494Sgshapiroextern void	mi_closener __P((void));
11064562Sgshapiro
11164562Sgshapiro/* communication functions */
11264562Sgshapiroextern char	*mi_rd_cmd __P((socket_t, struct timeval *, char *, size_t *, char *));
11364562Sgshapiroextern int	mi_wr_cmd __P((socket_t, struct timeval *, int, char *, size_t));
11464562Sgshapiroextern bool	mi_sendok __P((SMFICTX_PTR, int));
11564562Sgshapiro
11664562Sgshapiro#endif /* !_LIBMILTER_H */
117