1 /* $NetBSD: cleanup_state.c,v 1.3 2020/03/18 19:05:15 christos Exp $ */ 2 3 /*++ 4 /* NAME 5 /* cleanup_state 3 6 /* SUMMARY 7 /* per-message state variables 8 /* SYNOPSIS 9 /* #include "cleanup.h" 10 /* 11 /* CLEANUP_STATE *cleanup_state_alloc(src) 12 /* VSTREAM *src; 13 /* 14 /* void cleanup_state_free(state) 15 /* CLEANUP_STATE *state; 16 /* DESCRIPTION 17 /* This module maintains about two dozen state variables 18 /* that are used by many routines in the course of processing one 19 /* message. 20 /* 21 /* cleanup_state_alloc() initializes the per-message state variables. 22 /* 23 /* cleanup_state_free() cleans up. 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 /* Wietse Venema 35 /* Google, Inc. 36 /* 111 8th Avenue 37 /* New York, NY 10011, USA 38 /*--*/ 39 40 /* System library. */ 41 42 #include <sys_defs.h> 43 44 /* Utility library. */ 45 46 #include <mymalloc.h> 47 #include <vstring.h> 48 #include <htable.h> 49 50 /* Global library. */ 51 52 #include <been_here.h> 53 #include <mail_params.h> 54 #include <mime_state.h> 55 #include <mail_proto.h> 56 57 /* Milter library. */ 58 59 #include <milter.h> 60 61 /* Application-specific. */ 62 63 #include "cleanup.h" 64 65 /* cleanup_state_alloc - initialize global state */ 66 67 CLEANUP_STATE *cleanup_state_alloc(VSTREAM *src) 68 { 69 CLEANUP_STATE *state = (CLEANUP_STATE *) mymalloc(sizeof(*state)); 70 71 state->attr_buf = vstring_alloc(10); 72 state->temp1 = vstring_alloc(10); 73 state->temp2 = vstring_alloc(10); 74 if (cleanup_strip_chars) 75 state->stripped_buf = vstring_alloc(10); 76 state->src = src; 77 state->dst = 0; 78 state->handle = 0; 79 state->queue_name = 0; 80 state->queue_id = 0; 81 state->arrival_time.tv_sec = state->arrival_time.tv_usec = 0; 82 state->fullname = 0; 83 state->sender = 0; 84 state->recip = 0; 85 state->orig_rcpt = 0; 86 state->return_receipt = 0; 87 state->errors_to = 0; 88 state->auto_hdrs = argv_alloc(1); 89 state->hbc_rcpt = 0; 90 state->flags = 0; 91 state->tflags = 0; 92 state->qmgr_opts = 0; 93 state->errs = 0; 94 state->err_mask = 0; 95 state->headers_seen = 0; 96 state->hop_count = 0; 97 state->resent = ""; 98 state->dups = been_here_init(var_dup_filter_limit, BH_FLAG_FOLD); 99 state->action = cleanup_envelope; 100 state->data_offset = -1; 101 state->body_offset = -1; 102 state->xtra_offset = -1; 103 state->cont_length = 0; 104 state->sender_pt_offset = -1; 105 state->sender_pt_target = -1; 106 state->append_rcpt_pt_offset = -1; 107 state->append_rcpt_pt_target = -1; 108 state->append_hdr_pt_offset = -1; 109 state->append_hdr_pt_target = -1; 110 state->append_meta_pt_offset = -1; 111 state->append_meta_pt_target = -1; 112 state->milter_hbc_checks = 0; 113 state->milter_hbc_reply = 0; 114 state->rcpt_count = 0; 115 state->reason = 0; 116 state->smtp_reply = 0; 117 state->attr = nvtable_create(10); 118 nvtable_update(state->attr, MAIL_ATTR_LOG_ORIGIN, MAIL_ATTR_ORG_LOCAL); 119 state->mime_state = 0; 120 state->mime_errs = 0; 121 state->hdr_rewrite_context = MAIL_ATTR_RWR_LOCAL; 122 state->filter = 0; 123 state->redirect = 0; 124 state->dsn_envid = 0; 125 state->dsn_ret = 0; 126 state->dsn_notify = 0; 127 state->dsn_orcpt = 0; 128 state->verp_delims = 0; 129 state->milters = 0; 130 state->client_name = 0; 131 state->reverse_name = 0; 132 state->client_addr = 0; 133 state->client_af = 0; 134 state->client_port = 0; 135 state->server_addr = 0; 136 state->server_port = 0; 137 state->milter_ext_from = 0; 138 state->milter_ext_rcpt = 0; 139 state->milter_err_text = 0; 140 state->milter_dsn_buf = 0; 141 state->free_regions = state->body_regions = state->curr_body_region = 0; 142 state->smtputf8 = 0; 143 return (state); 144 } 145 146 /* cleanup_state_free - destroy global state */ 147 148 void cleanup_state_free(CLEANUP_STATE *state) 149 { 150 vstring_free(state->attr_buf); 151 vstring_free(state->temp1); 152 vstring_free(state->temp2); 153 if (cleanup_strip_chars) 154 vstring_free(state->stripped_buf); 155 if (state->fullname) 156 myfree(state->fullname); 157 if (state->sender) 158 myfree(state->sender); 159 if (state->recip) 160 myfree(state->recip); 161 if (state->orig_rcpt) 162 myfree(state->orig_rcpt); 163 if (state->return_receipt) 164 myfree(state->return_receipt); 165 if (state->errors_to) 166 myfree(state->errors_to); 167 argv_free(state->auto_hdrs); 168 if (state->hbc_rcpt) 169 argv_free(state->hbc_rcpt); 170 if (state->queue_name) 171 myfree(state->queue_name); 172 if (state->queue_id) 173 myfree(state->queue_id); 174 been_here_free(state->dups); 175 if (state->reason) 176 myfree(state->reason); 177 if (state->smtp_reply) 178 myfree(state->smtp_reply); 179 nvtable_free(state->attr); 180 if (state->mime_state) 181 mime_state_free(state->mime_state); 182 if (state->filter) 183 myfree(state->filter); 184 if (state->redirect) 185 myfree(state->redirect); 186 if (state->dsn_envid) 187 myfree(state->dsn_envid); 188 if (state->dsn_orcpt) 189 myfree(state->dsn_orcpt); 190 if (state->verp_delims) 191 myfree(state->verp_delims); 192 if (state->milters) 193 milter_free(state->milters); 194 if (state->milter_ext_from) 195 vstring_free(state->milter_ext_from); 196 if (state->milter_ext_rcpt) 197 vstring_free(state->milter_ext_rcpt); 198 if (state->milter_err_text) 199 vstring_free(state->milter_err_text); 200 if (state->milter_dsn_buf) 201 vstring_free(state->milter_dsn_buf); 202 cleanup_region_done(state); 203 myfree((void *) state); 204 } 205