1 /* 2 * Copyright (c) 1999-2002 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 17 #include <sm/gen.h> 18 19 #ifdef _DEFINE 20 # define EXTERN 21 # define INIT(x) = x 22 SM_IDSTR(MilterlId, "@(#)$Id: libmilter.h,v 8.33.2.7 2002/12/18 23:15:35 ca Exp $") 23 #else /* _DEFINE */ 24 # define EXTERN extern 25 # define INIT(x) 26 #endif /* _DEFINE */ 27 28 29 #define NOT_SENDMAIL 1 30 #define _SOCK_ADDR union bigsockaddr 31 #include "sendmail.h" 32 33 #include "libmilter/milter.h" 34 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) 41 42 # define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg) 43 # define sthread_get_id() pthread_self() 44 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) 51 52 #include <sys/time.h> 53 54 /* version info */ 55 #define MILTER_PRODUCT_NAME "libmilter" 56 #define MILTER_VERSION 100 57 58 /* some defaults */ 59 #define MI_TIMEOUT 7210 /* default timeout for read/write */ 60 #define MI_CHK_TIME 5 /* checking whether to terminate */ 61 62 #ifndef MI_SOMAXCONN 63 # if SOMAXCONN > 20 64 # define MI_SOMAXCONN SOMAXCONN 65 # else /* SOMAXCONN */ 66 # define MI_SOMAXCONN 20 67 # endif /* SOMAXCONN */ 68 #endif /* ! MI_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 #define MAX_FAILS_S 16 /* select() */ 75 76 /* internal "commands", i.e., error codes */ 77 #define SMFIC_TIMEOUT ((char) 1) /* timeout */ 78 #define SMFIC_SELECT ((char) 2) /* select error */ 79 #define SMFIC_MALLOC ((char) 3) /* malloc error */ 80 #define SMFIC_RECVERR ((char) 4) /* recv() error */ 81 #define SMFIC_EOF ((char) 5) /* eof */ 82 #define SMFIC_UNKNERR ((char) 6) /* unknown error */ 83 #define SMFIC_TOOBIG ((char) 7) /* body chunk too big */ 84 #define SMFIC_VALIDCMD ' ' /* first valid command */ 85 86 /* hack */ 87 #define smi_log syslog 88 #define sm_dprintf printf 89 #define milter_ret int 90 #define SMI_LOG_ERR LOG_ERR 91 #define SMI_LOG_FATAL LOG_ERR 92 #define SMI_LOG_WARN LOG_WARNING 93 #define SMI_LOG_INFO LOG_INFO 94 #define SMI_LOG_DEBUG LOG_DEBUG 95 96 /* stop? */ 97 #define MILTER_CONT 0 98 #define MILTER_STOP 1 99 #define MILTER_ABRT 2 100 101 /* functions */ 102 extern int mi_handle_session __P((SMFICTX_PTR)); 103 extern int mi_engine __P((SMFICTX_PTR)); 104 extern int mi_listener __P((char *, int, smfiDesc_ptr, time_t, int)); 105 extern void mi_clr_macros __P((SMFICTX_PTR, int)); 106 extern int mi_stop __P((void)); 107 extern int mi_control_startup __P((char *)); 108 extern void mi_stop_milters __P((int)); 109 extern void mi_clean_signals __P((void)); 110 extern struct hostent *mi_gethostbyname __P((char *, int)); 111 extern int mi_inet_pton __P((int, const char *, void *)); 112 extern void mi_closener __P((void)); 113 extern int mi_opensocket __P((char *, int, int, smfiDesc_ptr)); 114 115 /* communication functions */ 116 extern char *mi_rd_cmd __P((socket_t, struct timeval *, char *, size_t *, char *)); 117 extern int mi_wr_cmd __P((socket_t, struct timeval *, int, char *, size_t)); 118 extern bool mi_sendok __P((SMFICTX_PTR, int)); 119 120 121 #endif /* ! _LIBMILTER_H */ 122