1/*++ 2/* NAME 3/* smtp_state 3 4/* SUMMARY 5/* initialize/cleanup shared state 6/* SYNOPSIS 7/* #include "smtp.h" 8/* 9/* SMTP_STATE *smtp_state_alloc() 10/* 11/* void smtp_state_free(state) 12/* SMTP_STATE *state; 13/* DESCRIPTION 14/* smtp_state_init() initializes the shared state, and allocates 15/* memory for buffers etc. 16/* 17/* smtp_cleanup() destroys memory allocated by smtp_state_init(). 18/* STANDARDS 19/* DIAGNOSTICS 20/* BUGS 21/* SEE ALSO 22/* LICENSE 23/* .ad 24/* .fi 25/* The Secure Mailer license must be distributed with this software. 26/* AUTHOR(S) 27/* Wietse Venema 28/* IBM T.J. Watson Research 29/* P.O. Box 704 30/* Yorktown Heights, NY 10598, USA 31/*--*/ 32 33/* System library. */ 34 35#include <sys_defs.h> 36 37/* Utility library. */ 38 39#include <mymalloc.h> 40#include <vstring.h> 41#include <msg.h> 42 43/* Global library. */ 44 45#include <mail_params.h> 46 47/* Application-specific. */ 48 49#include "smtp.h" 50#include "smtp_sasl.h" 51 52/* smtp_state_alloc - initialize */ 53 54SMTP_STATE *smtp_state_alloc(void) 55{ 56 SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state)); 57 58 state->misc_flags = 0; 59 state->src = 0; 60 state->service = 0; 61 state->request = 0; 62 state->session = 0; 63 state->status = 0; 64 state->space_left = 0; 65 state->iterator->request_nexthop = vstring_alloc(100); 66 state->iterator->dest = vstring_alloc(100); 67 state->iterator->host = vstring_alloc(100); 68 state->iterator->addr = vstring_alloc(100); 69 state->iterator->saved_dest = vstring_alloc(100); 70 if (var_smtp_cache_conn) { 71 state->dest_label = vstring_alloc(10); 72 state->dest_prop = vstring_alloc(10); 73 state->endp_label = vstring_alloc(10); 74 state->endp_prop = vstring_alloc(10); 75 state->cache_used = htable_create(1); 76 } else { 77 state->dest_label = 0; 78 state->dest_prop = 0; 79 state->endp_label = 0; 80 state->endp_prop = 0; 81 state->cache_used = 0; 82 } 83 state->why = dsb_create(); 84 return (state); 85} 86 87/* smtp_state_free - destroy state */ 88 89void smtp_state_free(SMTP_STATE *state) 90{ 91#ifdef USE_TLS 92 /* The TLS policy cache lifetime is one delivery. */ 93 smtp_tls_policy_cache_flush(); 94#endif 95 vstring_free(state->iterator->request_nexthop); 96 vstring_free(state->iterator->dest); 97 vstring_free(state->iterator->host); 98 vstring_free(state->iterator->addr); 99 vstring_free(state->iterator->saved_dest); 100 if (state->dest_label) 101 vstring_free(state->dest_label); 102 if (state->dest_prop) 103 vstring_free(state->dest_prop); 104 if (state->endp_label) 105 vstring_free(state->endp_label); 106 if (state->endp_prop) 107 vstring_free(state->endp_prop); 108 if (state->cache_used) 109 htable_free(state->cache_used, (void (*) (char *)) 0); 110 if (state->why) 111 dsb_free(state->why); 112 113 myfree((char *) state); 114} 115