xref: /freebsd/contrib/sendmail/libmilter/handler.c (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
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.2 2000/07/14 06:16:57 msk 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 		(void) close(ctx->ctx_sd);
48 	if (ctx->ctx_reply != NULL)
49 		free(ctx->ctx_reply);
50 	if (ctx->ctx_privdata != NULL)
51 	{
52 		smi_log(SMI_LOG_WARN,
53 			"%s: private data not NULL",
54 			ctx->ctx_smfi->xxfi_name);
55 	}
56 	mi_clr_macros(ctx, 0);
57 	free(ctx);
58 	ctx = NULL;
59 	return ret;
60 }
61 #endif /* _FFR_MILTER */
62