1 /* 2 * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 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. 8 */ 9 10 /* 11 ** LIBMILTER.H -- include file for mail filter library functions 12 */ 13 14 #ifndef _LIBMILTER_H 15 # define _LIBMILTER_H 1 16 #ifdef _DEFINE 17 # define EXTERN 18 # define INIT(x) = x 19 # ifndef lint 20 static char MilterlId[] = "@(#)$Id: libmilter.h,v 8.3.6.14 2001/05/27 14:31:12 ca Exp $"; 21 # endif /* ! lint */ 22 #else /* _DEFINE */ 23 # define EXTERN extern 24 # define INIT(x) 25 #endif /* _DEFINE */ 26 27 28 #define NOT_SENDMAIL 1 29 #define _SOCK_ADDR union bigsockaddr 30 #include "sendmail.h" 31 32 #include "libmilter/milter.h" 33 34 #ifndef __P 35 # include "sendmail/cdefs.h" 36 #endif /* ! __P */ 37 #include "sendmail/useful.h" 38 39 # define ValidSocket(sd) ((sd) >= 0) 40 # define INVALID_SOCKET -1 41 # define MI_SOCK_READ(s, b, l) (read(s, b, l)) 42 # define MI_SOCK_WRITE(s, b, l) (write(s, b, l)) 43 44 # define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg) 45 # define sthread_get_id() pthread_self() 46 47 typedef pthread_mutex_t smutex_t; 48 # define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0) 49 # define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0) 50 # define smutex_lock(mp) (pthread_mutex_lock(mp) == 0) 51 # define smutex_unlock(mp) (pthread_mutex_unlock(mp) == 0) 52 # define smutex_trylock(mp) (pthread_mutex_trylock(mp) == 0) 53 54 #include <sys/time.h> 55 56 /* version info */ 57 #define MILTER_PRODUCT_NAME "libmilter" 58 #define MILTER_VERSION 100 59 60 /* some defaults */ 61 #define MI_TIMEOUT 7210 /* default timeout for read/write */ 62 #define MI_CHK_TIME 5 /* checking whether to terminate */ 63 64 #if SOMAXCONN > 20 65 # define MI_SOMAXCONN SOMAXCONN 66 #else /* SOMAXCONN */ 67 # define MI_SOMAXCONN 20 68 #endif /* SOMAXCONN */ 69 70 /* maximum number of repeated failures in mi_listener() */ 71 #define MAX_FAILS_M 16 /* malloc() */ 72 #define MAX_FAILS_T 16 /* thread creation */ 73 #define MAX_FAILS_A 16 /* accept() */ 74 75 /* internal "commands", i.e., error codes */ 76 #define SMFIC_TIMEOUT ((char) 1) /* timeout */ 77 #define SMFIC_SELECT ((char) 2) /* select error */ 78 #define SMFIC_MALLOC ((char) 3) /* malloc error */ 79 #define SMFIC_RECVERR ((char) 4) /* recv() error */ 80 #define SMFIC_EOF ((char) 5) /* eof */ 81 #define SMFIC_UNKNERR ((char) 6) /* unknown error */ 82 #define SMFIC_TOOBIG ((char) 7) /* body chunk too big */ 83 #define SMFIC_VALIDCMD ' ' /* first valid command */ 84 85 /* hack */ 86 #define smi_log syslog 87 #define milter_ret int 88 #define SMI_LOG_ERR LOG_ERR 89 #define SMI_LOG_FATAL LOG_ERR 90 #define SMI_LOG_WARN LOG_WARNING 91 #define SMI_LOG_INFO LOG_INFO 92 #define SMI_LOG_DEBUG LOG_DEBUG 93 94 /* stop? */ 95 #define MILTER_CONT 0 96 #define MILTER_STOP 1 97 #define MILTER_ABRT 2 98 99 /* functions */ 100 extern int mi_handle_session __P((SMFICTX_PTR)); 101 extern int mi_engine __P((SMFICTX_PTR)); 102 extern int mi_listener __P((char *, int, smfiDesc_ptr, time_t, int)); 103 extern void mi_clr_macros __P((SMFICTX_PTR, int)); 104 extern int mi_stop __P((void)); 105 extern int mi_control_startup __P((char *)); 106 extern void mi_stop_milters __P((int)); 107 extern void mi_clean_signals __P((void)); 108 extern struct hostent *mi_gethostbyname __P((char *, int)); 109 extern void mi_closener __P((void)); 110 111 /* communication functions */ 112 extern char *mi_rd_cmd __P((socket_t, struct timeval *, char *, size_t *, char *)); 113 extern int mi_wr_cmd __P((socket_t, struct timeval *, int, char *, size_t)); 114 extern bool mi_sendok __P((SMFICTX_PTR, int)); 115 116 #endif /* !_LIBMILTER_H */ 117