xref: /freebsd/contrib/sendmail/libmilter/handler.c (revision 4026605903c0ab8df33c4ae8c419acdb2b652af8)
106f25ae9SGregory Neil Shapiro /*
206f25ae9SGregory Neil Shapiro  *  Copyright (c) 1999-2000 Sendmail, Inc. and its suppliers.
306f25ae9SGregory Neil Shapiro  *	All rights reserved.
406f25ae9SGregory Neil Shapiro  *
506f25ae9SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
606f25ae9SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
706f25ae9SGregory Neil Shapiro  * the sendmail distribution.
806f25ae9SGregory Neil Shapiro  *
906f25ae9SGregory Neil Shapiro  */
1006f25ae9SGregory Neil Shapiro 
1140266059SGregory Neil Shapiro #include <sm/gen.h>
1240266059SGregory Neil Shapiro SM_RCSID("@(#)$Id: handler.c,v 8.29 2001/11/15 00:17:15 msk Exp $")
1306f25ae9SGregory Neil Shapiro 
1406f25ae9SGregory Neil Shapiro #include "libmilter.h"
1506f25ae9SGregory Neil Shapiro 
1606f25ae9SGregory Neil Shapiro 
1706f25ae9SGregory Neil Shapiro /*
1806f25ae9SGregory Neil Shapiro **  HANDLE_SESSION -- Handle a connected session in its own context
1906f25ae9SGregory Neil Shapiro **
2006f25ae9SGregory Neil Shapiro **	Parameters:
2106f25ae9SGregory Neil Shapiro **		ctx -- context structure
2206f25ae9SGregory Neil Shapiro **
2306f25ae9SGregory Neil Shapiro **	Returns:
2406f25ae9SGregory Neil Shapiro **		MI_SUCCESS/MI_FAILURE
2506f25ae9SGregory Neil Shapiro */
2606f25ae9SGregory Neil Shapiro 
2706f25ae9SGregory Neil Shapiro int
2806f25ae9SGregory Neil Shapiro mi_handle_session(ctx)
2906f25ae9SGregory Neil Shapiro 	SMFICTX_PTR ctx;
3006f25ae9SGregory Neil Shapiro {
3106f25ae9SGregory Neil Shapiro 	int ret;
3206f25ae9SGregory Neil Shapiro 
3306f25ae9SGregory Neil Shapiro 	if (ctx == NULL)
3406f25ae9SGregory Neil Shapiro 		return MI_FAILURE;
3506f25ae9SGregory Neil Shapiro 	ctx->ctx_id = (sthread_t) sthread_get_id();
3606f25ae9SGregory Neil Shapiro 
3706f25ae9SGregory Neil Shapiro 	/*
3806f25ae9SGregory Neil Shapiro 	**  detach so resources are free when the thread returns
3906f25ae9SGregory Neil Shapiro 	**  if we ever "wait" for threads, this call must be removed
4006f25ae9SGregory Neil Shapiro 	*/
4106f25ae9SGregory Neil Shapiro 	if (pthread_detach(ctx->ctx_id) != 0)
4206f25ae9SGregory Neil Shapiro 		return MI_FAILURE;
4306f25ae9SGregory Neil Shapiro 	ret = mi_engine(ctx);
4406f25ae9SGregory Neil Shapiro 	if (ValidSocket(ctx->ctx_sd))
45193538b7SGregory Neil Shapiro 	{
4640266059SGregory Neil Shapiro 		(void) closesocket(ctx->ctx_sd);
47193538b7SGregory Neil Shapiro 		ctx->ctx_sd = INVALID_SOCKET;
48193538b7SGregory Neil Shapiro 	}
4906f25ae9SGregory Neil Shapiro 	if (ctx->ctx_reply != NULL)
50193538b7SGregory Neil Shapiro 	{
5106f25ae9SGregory Neil Shapiro 		free(ctx->ctx_reply);
52193538b7SGregory Neil Shapiro 		ctx->ctx_reply = NULL;
53193538b7SGregory Neil Shapiro 	}
5406f25ae9SGregory Neil Shapiro 	if (ctx->ctx_privdata != NULL)
5506f25ae9SGregory Neil Shapiro 	{
5606f25ae9SGregory Neil Shapiro 		smi_log(SMI_LOG_WARN,
5706f25ae9SGregory Neil Shapiro 			"%s: private data not NULL",
5806f25ae9SGregory Neil Shapiro 			ctx->ctx_smfi->xxfi_name);
5906f25ae9SGregory Neil Shapiro 	}
6006f25ae9SGregory Neil Shapiro 	mi_clr_macros(ctx, 0);
6106f25ae9SGregory Neil Shapiro 	free(ctx);
6206f25ae9SGregory Neil Shapiro 	ctx = NULL;
6306f25ae9SGregory Neil Shapiro 	return ret;
6406f25ae9SGregory Neil Shapiro }
65