xref: /freebsd/contrib/sendmail/libmilter/handler.c (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
1 /*
2  *  Copyright (c) 1999-2000 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 #ifndef lint
12 static char id[] = "@(#)$Id: handler.c,v 8.19.4.3 2000/12/29 19:45:39 gshapiro Exp $";
13 #endif /* ! lint */
14 
15 #if _FFR_MILTER
16 #include "libmilter.h"
17 
18 
19 /*
20 **  HANDLE_SESSION -- Handle a connected session in its own context
21 **
22 **	Parameters:
23 **		ctx -- context structure
24 **
25 **	Returns:
26 **		MI_SUCCESS/MI_FAILURE
27 */
28 
29 int
30 mi_handle_session(ctx)
31 	SMFICTX_PTR ctx;
32 {
33 	int ret;
34 
35 	if (ctx == NULL)
36 		return MI_FAILURE;
37 	ctx->ctx_id = (sthread_t) sthread_get_id();
38 
39 	/*
40 	**  detach so resources are free when the thread returns
41 	**  if we ever "wait" for threads, this call must be removed
42 	*/
43 	if (pthread_detach(ctx->ctx_id) != 0)
44 		return MI_FAILURE;
45 	ret = mi_engine(ctx);
46 	if (ValidSocket(ctx->ctx_sd))
47 	{
48 		(void) close(ctx->ctx_sd);
49 		ctx->ctx_sd = INVALID_SOCKET;
50 	}
51 	if (ctx->ctx_reply != NULL)
52 	{
53 		free(ctx->ctx_reply);
54 		ctx->ctx_reply = NULL;
55 	}
56 	if (ctx->ctx_privdata != NULL)
57 	{
58 		smi_log(SMI_LOG_WARN,
59 			"%s: private data not NULL",
60 			ctx->ctx_smfi->xxfi_name);
61 	}
62 	mi_clr_macros(ctx, 0);
63 	free(ctx);
64 	ctx = NULL;
65 	return ret;
66 }
67 #endif /* _FFR_MILTER */
68