1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2003 Sendmail, Inc. and its suppliers. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 6*7c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 7*7c478bd9Sstevel@tonic-gate * the sendmail distribution. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate */ 10*7c478bd9Sstevel@tonic-gate 11*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 12*7c478bd9Sstevel@tonic-gate 13*7c478bd9Sstevel@tonic-gate #include <sm/gen.h> 14*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: handler.c,v 8.30.2.4 2003/01/23 22:28:36 ca Exp $") 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #include "libmilter.h" 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate 19*7c478bd9Sstevel@tonic-gate /* 20*7c478bd9Sstevel@tonic-gate ** HANDLE_SESSION -- Handle a connected session in its own context 21*7c478bd9Sstevel@tonic-gate ** 22*7c478bd9Sstevel@tonic-gate ** Parameters: 23*7c478bd9Sstevel@tonic-gate ** ctx -- context structure 24*7c478bd9Sstevel@tonic-gate ** 25*7c478bd9Sstevel@tonic-gate ** Returns: 26*7c478bd9Sstevel@tonic-gate ** MI_SUCCESS/MI_FAILURE 27*7c478bd9Sstevel@tonic-gate */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate int 30*7c478bd9Sstevel@tonic-gate mi_handle_session(ctx) 31*7c478bd9Sstevel@tonic-gate SMFICTX_PTR ctx; 32*7c478bd9Sstevel@tonic-gate { 33*7c478bd9Sstevel@tonic-gate int ret; 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate if (ctx == NULL) 36*7c478bd9Sstevel@tonic-gate return MI_FAILURE; 37*7c478bd9Sstevel@tonic-gate ctx->ctx_id = (sthread_t) sthread_get_id(); 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* 40*7c478bd9Sstevel@tonic-gate ** Detach so resources are free when the thread returns. 41*7c478bd9Sstevel@tonic-gate ** If we ever "wait" for threads, this call must be removed. 42*7c478bd9Sstevel@tonic-gate */ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate if (pthread_detach(ctx->ctx_id) != 0) 45*7c478bd9Sstevel@tonic-gate ret = MI_FAILURE; 46*7c478bd9Sstevel@tonic-gate else 47*7c478bd9Sstevel@tonic-gate ret = mi_engine(ctx); 48*7c478bd9Sstevel@tonic-gate if (ValidSocket(ctx->ctx_sd)) 49*7c478bd9Sstevel@tonic-gate { 50*7c478bd9Sstevel@tonic-gate (void) closesocket(ctx->ctx_sd); 51*7c478bd9Sstevel@tonic-gate ctx->ctx_sd = INVALID_SOCKET; 52*7c478bd9Sstevel@tonic-gate } 53*7c478bd9Sstevel@tonic-gate if (ctx->ctx_reply != NULL) 54*7c478bd9Sstevel@tonic-gate { 55*7c478bd9Sstevel@tonic-gate free(ctx->ctx_reply); 56*7c478bd9Sstevel@tonic-gate ctx->ctx_reply = NULL; 57*7c478bd9Sstevel@tonic-gate } 58*7c478bd9Sstevel@tonic-gate if (ctx->ctx_privdata != NULL) 59*7c478bd9Sstevel@tonic-gate { 60*7c478bd9Sstevel@tonic-gate smi_log(SMI_LOG_WARN, 61*7c478bd9Sstevel@tonic-gate "%s: private data not NULL", 62*7c478bd9Sstevel@tonic-gate ctx->ctx_smfi->xxfi_name); 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate mi_clr_macros(ctx, 0); 65*7c478bd9Sstevel@tonic-gate free(ctx); 66*7c478bd9Sstevel@tonic-gate ctx = NULL; 67*7c478bd9Sstevel@tonic-gate return ret; 68*7c478bd9Sstevel@tonic-gate } 69