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 /* Wietse Venema 33 /* Google, Inc. 34 /* 111 8th Avenue 35 /* New York, NY 10011, USA 36 /*--*/ 37 38 /* System library. */ 39 40 #include <sys_defs.h> 41 42 /* Utility library. */ 43 44 #include <mymalloc.h> 45 #include <vstring.h> 46 #include <msg.h> 47 48 /* Global library. */ 49 50 #include <mail_params.h> 51 #include <debug_peer.h> 52 53 /* Application-specific. */ 54 55 #include "smtp.h" 56 #include "smtp_sasl.h" 57 58 /* smtp_state_alloc - initialize */ 59 smtp_state_alloc(void)60SMTP_STATE *smtp_state_alloc(void) 61 { 62 SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state)); 63 64 state->misc_flags = 0; 65 state->src = 0; 66 state->service = 0; 67 state->request = 0; 68 state->session = 0; 69 state->status = 0; 70 state->space_left = 0; 71 state->iterator->request_nexthop = vstring_alloc(100); 72 state->iterator->dest = vstring_alloc(100); 73 state->iterator->host = vstring_alloc(100); 74 state->iterator->addr = vstring_alloc(100); 75 state->iterator->saved_dest = vstring_alloc(100); 76 if (var_smtp_cache_conn) { 77 state->dest_label = vstring_alloc(10); 78 state->dest_prop = vstring_alloc(10); 79 state->endp_label = vstring_alloc(10); 80 state->endp_prop = vstring_alloc(10); 81 state->cache_used = htable_create(1); 82 } else { 83 state->dest_label = 0; 84 state->dest_prop = 0; 85 state->endp_label = 0; 86 state->endp_prop = 0; 87 state->cache_used = 0; 88 } 89 state->why = dsb_create(); 90 state->debug_peer_per_nexthop = 0; 91 return (state); 92 } 93 94 /* smtp_state_free - destroy state */ 95 smtp_state_free(SMTP_STATE * state)96void smtp_state_free(SMTP_STATE *state) 97 { 98 #ifdef USE_TLS 99 /* The TLS policy cache lifetime is one delivery. */ 100 smtp_tls_policy_cache_flush(); 101 #endif 102 vstring_free(state->iterator->request_nexthop); 103 vstring_free(state->iterator->dest); 104 vstring_free(state->iterator->host); 105 vstring_free(state->iterator->addr); 106 vstring_free(state->iterator->saved_dest); 107 if (state->dest_label) 108 vstring_free(state->dest_label); 109 if (state->dest_prop) 110 vstring_free(state->dest_prop); 111 if (state->endp_label) 112 vstring_free(state->endp_label); 113 if (state->endp_prop) 114 vstring_free(state->endp_prop); 115 if (state->cache_used) 116 htable_free(state->cache_used, (void (*) (void *)) 0); 117 if (state->why) 118 dsb_free(state->why); 119 if (state->debug_peer_per_nexthop) 120 debug_peer_restore(); 121 122 myfree((void *) state); 123 } 124