xref: /freebsd/contrib/sendmail/libmilter/handler.c (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
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 #include <sm/gen.h>
12 SM_RCSID("@(#)$Id: handler.c,v 8.38 2006/11/02 02:38:22 ca Exp $")
13 
14 #include "libmilter.h"
15 
16 #if !_FFR_WORKERS_POOL
17 /*
18 **  HANDLE_SESSION -- Handle a connected session in its own context
19 **
20 **	Parameters:
21 **		ctx -- context structure
22 **
23 **	Returns:
24 **		MI_SUCCESS/MI_FAILURE
25 */
26 
27 int
28 mi_handle_session(ctx)
29 	SMFICTX_PTR ctx;
30 {
31 	int ret;
32 
33 	if (ctx == NULL)
34 		return MI_FAILURE;
35 	ctx->ctx_id = (sthread_t) sthread_get_id();
36 
37 	/*
38 	**  Detach so resources are free when the thread returns.
39 	**  If we ever "wait" for threads, this call must be removed.
40 	*/
41 
42 	if (pthread_detach(ctx->ctx_id) != 0)
43 		ret = MI_FAILURE;
44 	else
45 		ret = mi_engine(ctx);
46 	if (ValidSocket(ctx->ctx_sd))
47 	{
48 		(void) closesocket(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_WORKERS_POOL */
68