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->nexthop_domain = 0; 66 if (var_smtp_cache_conn) { 67 state->dest_label = vstring_alloc(10); 68 state->dest_prop = vstring_alloc(10); 69 state->endp_label = vstring_alloc(10); 70 state->endp_prop = vstring_alloc(10); 71 state->cache_used = htable_create(1); 72 } else { 73 state->dest_label = 0; 74 state->dest_prop = 0; 75 state->endp_label = 0; 76 state->endp_prop = 0; 77 state->cache_used = 0; 78 } 79 state->why = dsb_create(); 80 81 /* 82 * The process name, "smtp" or "lmtp", is also used as the DSN server 83 * reply type and for SASL service information lookup. Since all three 84 * external representations are identical there is no reason to transform 85 * from some external form X to some Postfix-specific canonical internal 86 * form, and then to transform from the internal form to external forms Y 87 * and Z. 88 */ 89 if (strcmp(var_procname, "lmtp") == 0) { 90 state->misc_flags |= SMTP_MISC_FLAG_USE_LMTP; 91 } else if (strcmp(var_procname, "smtp") == 0) { 92 /* void */ 93 } else { 94 msg_fatal("unexpected process name \"%s\" - " 95 "specify \"smtp\" or \"lmtp\"", 96 var_procname); 97 } 98 return (state); 99} 100 101/* smtp_state_free - destroy state */ 102 103void smtp_state_free(SMTP_STATE *state) 104{ 105 if (state->dest_label) 106 vstring_free(state->dest_label); 107 if (state->dest_prop) 108 vstring_free(state->dest_prop); 109 if (state->endp_label) 110 vstring_free(state->endp_label); 111 if (state->endp_prop) 112 vstring_free(state->endp_prop); 113 if (state->cache_used) 114 htable_free(state->cache_used, (void (*) (char *)) 0); 115 if (state->why) 116 dsb_free(state->why); 117 118 myfree((char *) state); 119} 120