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 #include <sm/gen.h> 12 SM_RCSID("@(#)$Id: handler.c,v 8.29 2001/11/15 00:17:15 msk Exp $") 13 14 #include "libmilter.h" 15 16 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 if (pthread_detach(ctx->ctx_id) != 0) 42 return MI_FAILURE; 43 ret = mi_engine(ctx); 44 if (ValidSocket(ctx->ctx_sd)) 45 { 46 (void) closesocket(ctx->ctx_sd); 47 ctx->ctx_sd = INVALID_SOCKET; 48 } 49 if (ctx->ctx_reply != NULL) 50 { 51 free(ctx->ctx_reply); 52 ctx->ctx_reply = NULL; 53 } 54 if (ctx->ctx_privdata != NULL) 55 { 56 smi_log(SMI_LOG_WARN, 57 "%s: private data not NULL", 58 ctx->ctx_smfi->xxfi_name); 59 } 60 mi_clr_macros(ctx, 0); 61 free(ctx); 62 ctx = NULL; 63 return ret; 64 } 65