xref: /titanic_51/usr/src/cmd/sendmail/libmilter/handler.c (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
1 /*
2  *  Copyright (c) 1999-2003, 2006 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
12 
13 #include <sm/gen.h>
14 SM_RCSID("@(#)$Id: handler.c,v 8.38 2006/11/02 02:38:22 ca Exp $")
15 
16 #include "libmilter.h"
17 
18 #if !_FFR_WORKERS_POOL
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 
44 	if (pthread_detach(ctx->ctx_id) != 0)
45 		ret = MI_FAILURE;
46 	else
47 		ret = mi_engine(ctx);
48 	if (ValidSocket(ctx->ctx_sd))
49 	{
50 		(void) closesocket(ctx->ctx_sd);
51 		ctx->ctx_sd = INVALID_SOCKET;
52 	}
53 	if (ctx->ctx_reply != NULL)
54 	{
55 		free(ctx->ctx_reply);
56 		ctx->ctx_reply = NULL;
57 	}
58 	if (ctx->ctx_privdata != NULL)
59 	{
60 		smi_log(SMI_LOG_WARN,
61 			"%s: private data not NULL",
62 			ctx->ctx_smfi->xxfi_name);
63 	}
64 	mi_clr_macros(ctx, 0);
65 	free(ctx);
66 	ctx = NULL;
67 	return ret;
68 }
69 #endif /* !_FFR_WORKERS_POOL */
70