1 /* $NetBSD: smtp_state.c,v 1.1.1.1 2009/06/23 10:08:54 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* smtp_state 3 6 /* SUMMARY 7 /* initialize/cleanup shared state 8 /* SYNOPSIS 9 /* #include "smtp.h" 10 /* 11 /* SMTP_STATE *smtp_state_alloc() 12 /* 13 /* void smtp_state_free(state) 14 /* SMTP_STATE *state; 15 /* DESCRIPTION 16 /* smtp_state_init() initializes the shared state, and allocates 17 /* memory for buffers etc. 18 /* 19 /* smtp_cleanup() destroys memory allocated by smtp_state_init(). 20 /* STANDARDS 21 /* DIAGNOSTICS 22 /* BUGS 23 /* SEE ALSO 24 /* LICENSE 25 /* .ad 26 /* .fi 27 /* The Secure Mailer license must be distributed with this software. 28 /* AUTHOR(S) 29 /* Wietse Venema 30 /* IBM T.J. Watson Research 31 /* P.O. Box 704 32 /* Yorktown Heights, NY 10598, USA 33 /*--*/ 34 35 /* System library. */ 36 37 #include <sys_defs.h> 38 39 /* Utility library. */ 40 41 #include <mymalloc.h> 42 #include <vstring.h> 43 #include <msg.h> 44 45 /* Global library. */ 46 47 #include <mail_params.h> 48 49 /* Application-specific. */ 50 51 #include "smtp.h" 52 #include "smtp_sasl.h" 53 54 /* smtp_state_alloc - initialize */ 55 56 SMTP_STATE *smtp_state_alloc(void) 57 { 58 SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state)); 59 60 state->misc_flags = 0; 61 state->src = 0; 62 state->service = 0; 63 state->request = 0; 64 state->session = 0; 65 state->status = 0; 66 state->space_left = 0; 67 state->nexthop_domain = 0; 68 if (var_smtp_cache_conn) { 69 state->dest_label = vstring_alloc(10); 70 state->dest_prop = vstring_alloc(10); 71 state->endp_label = vstring_alloc(10); 72 state->endp_prop = vstring_alloc(10); 73 state->cache_used = htable_create(1); 74 } else { 75 state->dest_label = 0; 76 state->dest_prop = 0; 77 state->endp_label = 0; 78 state->endp_prop = 0; 79 state->cache_used = 0; 80 } 81 state->why = dsb_create(); 82 83 /* 84 * The process name, "smtp" or "lmtp", is also used as the DSN server 85 * reply type and for SASL service information lookup. Since all three 86 * external representations are identical there is no reason to transform 87 * from some external form X to some Postfix-specific canonical internal 88 * form, and then to transform from the internal form to external forms Y 89 * and Z. 90 */ 91 if (strcmp(var_procname, "lmtp") == 0) { 92 state->misc_flags |= SMTP_MISC_FLAG_USE_LMTP; 93 } else if (strcmp(var_procname, "smtp") == 0) { 94 /* void */ 95 } else { 96 msg_fatal("unexpected process name \"%s\" - " 97 "specify \"smtp\" or \"lmtp\"", 98 var_procname); 99 } 100 return (state); 101 } 102 103 /* smtp_state_free - destroy state */ 104 105 void smtp_state_free(SMTP_STATE *state) 106 { 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 (*) (char *)) 0); 117 if (state->why) 118 dsb_free(state->why); 119 120 myfree((char *) state); 121 } 122