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.
12 SM_RCSID("@(#)$Id: main.c,v 8.79 2003/10/20 22:25:09 ca Exp $")
15 #include "libmilter.h"
20 static smfiDesc_ptr smfi
= NULL
;
23 ** SMFI_REGISTER -- register a filter description
26 ** smfilter -- description of filter to register
29 ** MI_SUCCESS/MI_FAILURE
33 smfi_register(smfilter
)
34 smfiDesc_str smfilter
;
40 smfi
= (smfiDesc_ptr
) malloc(sizeof *smfi
);
44 (void) memcpy(smfi
, &smfilter
, sizeof *smfi
);
45 if (smfilter
.xxfi_name
== NULL
)
46 smfilter
.xxfi_name
= "Unknown";
48 len
= strlen(smfilter
.xxfi_name
) + 1;
49 smfi
->xxfi_name
= (char *) malloc(len
);
50 if (smfi
->xxfi_name
== NULL
)
52 (void) sm_strlcpy(smfi
->xxfi_name
, smfilter
.xxfi_name
, len
);
54 /* compare milter version with hard coded version */
55 if (smfi
->xxfi_version
!= SMFI_VERSION
)
57 /* hard failure for now! */
59 "%s: smfi_register: version mismatch application: %d != milter: %d",
60 smfi
->xxfi_name
, smfi
->xxfi_version
,
63 /* XXX how about smfi? */
64 free(smfi
->xxfi_name
);
72 ** SMFI_STOP -- stop milter
84 mi_stop_milters(MILTER_STOP
);
89 ** Default values for some variables.
90 ** Most of these can be changed with the functions below.
94 static char *conn
= NULL
;
95 static int timeout
= MI_TIMEOUT
;
96 static int backlog
= MI_SOMAXCONN
;
99 ** SMFI_OPENSOCKET -- try the socket setup to make sure we'll be
103 ** rmsocket -- if true, instructs libmilter to attempt
104 ** to remove the socket before creating it;
105 ** only applies for "local:" or "unix:" sockets
108 ** MI_SUCCESS/MI_FAILURE
112 smfi_opensocket(rmsocket
)
115 if (smfi
== NULL
|| conn
== NULL
)
118 return mi_opensocket(conn
, backlog
, dbg
, rmsocket
, smfi
);
122 ** SMFI_SETDBG -- set debug level.
125 ** odbg -- new debug level.
140 ** SMFI_SETTIMEOUT -- set timeout (for read/write).
143 ** otimeout -- new timeout.
150 smfi_settimeout(otimeout
)
158 ** SMFI_SETCONN -- set connection information (socket description)
161 ** oconn -- new connection information.
164 ** MI_SUCCESS/MI_FAILURE
173 if (oconn
== NULL
|| *oconn
== '\0')
175 l
= strlen(oconn
) + 1;
176 if ((conn
= (char *) malloc(l
)) == NULL
)
178 if (sm_strlcpy(conn
, oconn
, l
) >= l
)
184 ** SMFI_SETBACKLOG -- set backlog
187 ** obacklog -- new backlog.
190 ** MI_SUCCESS/MI_FAILURE
194 smfi_setbacklog(obacklog
)
205 ** SMFI_MAIN -- setup milter connnection and start listener.
211 ** MI_SUCCESS/MI_FAILURE
219 (void) signal(SIGPIPE
, SIG_IGN
);
222 smi_log(SMI_LOG_FATAL
, "%s: missing connection information",
227 (void) atexit(mi_clean_signals
);
228 if (mi_control_startup(smfi
->xxfi_name
) != MI_SUCCESS
)
230 smi_log(SMI_LOG_FATAL
,
231 "%s: Couldn't start signal thread",
237 /* Startup the listener */
238 if (mi_listener(conn
, dbg
, smfi
, timeout
, backlog
) != MI_SUCCESS
)