xref: /netbsd-src/external/ibm-public/postfix/dist/src/cleanup/cleanup_state.c (revision 67b9b338a7386232ac596b5fd0cd5a9cc8a03c71)
1 /*	$NetBSD: cleanup_state.c,v 1.4 2022/10/08 16:12:45 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 
cleanup_state_alloc(VSTREAM * src)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->rcpt_count = 0;
113     state->reason = 0;
114     state->smtp_reply = 0;
115     state->attr = nvtable_create(10);
116     nvtable_update(state->attr, MAIL_ATTR_LOG_ORIGIN, MAIL_ATTR_ORG_LOCAL);
117     state->mime_state = 0;
118     state->mime_errs = 0;
119     state->hdr_rewrite_context = MAIL_ATTR_RWR_LOCAL;
120     state->filter = 0;
121     state->redirect = 0;
122     state->dsn_envid = 0;
123     state->dsn_ret = 0;
124     state->dsn_notify = 0;
125     state->dsn_orcpt = 0;
126     state->verp_delims = 0;
127     state->milters = 0;
128     state->client_name = 0;
129     state->reverse_name = 0;
130     state->client_addr = 0;
131     state->client_af = 0;
132     state->client_port = 0;
133     state->server_addr = 0;
134     state->server_port = 0;
135     state->milter_ext_from = 0;
136     state->milter_ext_rcpt = 0;
137     state->milter_err_text = 0;
138     state->milter_dsn_buf = 0;
139     state->free_regions = state->body_regions = state->curr_body_region = 0;
140     state->smtputf8 = 0;
141     return (state);
142 }
143 
144 /* cleanup_state_free - destroy global state */
145 
cleanup_state_free(CLEANUP_STATE * state)146 void    cleanup_state_free(CLEANUP_STATE *state)
147 {
148     vstring_free(state->attr_buf);
149     vstring_free(state->temp1);
150     vstring_free(state->temp2);
151     if (cleanup_strip_chars)
152 	vstring_free(state->stripped_buf);
153     if (state->fullname)
154 	myfree(state->fullname);
155     if (state->sender)
156 	myfree(state->sender);
157     if (state->recip)
158 	myfree(state->recip);
159     if (state->orig_rcpt)
160 	myfree(state->orig_rcpt);
161     if (state->return_receipt)
162 	myfree(state->return_receipt);
163     if (state->errors_to)
164 	myfree(state->errors_to);
165     argv_free(state->auto_hdrs);
166     if (state->hbc_rcpt)
167 	argv_free(state->hbc_rcpt);
168     if (state->queue_name)
169 	myfree(state->queue_name);
170     if (state->queue_id)
171 	myfree(state->queue_id);
172     been_here_free(state->dups);
173     if (state->reason)
174 	myfree(state->reason);
175     if (state->smtp_reply)
176 	myfree(state->smtp_reply);
177     nvtable_free(state->attr);
178     if (state->mime_state)
179 	mime_state_free(state->mime_state);
180     if (state->filter)
181 	myfree(state->filter);
182     if (state->redirect)
183 	myfree(state->redirect);
184     if (state->dsn_envid)
185 	myfree(state->dsn_envid);
186     if (state->dsn_orcpt)
187 	myfree(state->dsn_orcpt);
188     if (state->verp_delims)
189 	myfree(state->verp_delims);
190     if (state->milters)
191 	milter_free(state->milters);
192     if (state->milter_ext_from)
193 	vstring_free(state->milter_ext_from);
194     if (state->milter_ext_rcpt)
195 	vstring_free(state->milter_ext_rcpt);
196     if (state->milter_err_text)
197 	vstring_free(state->milter_err_text);
198     if (state->milter_dsn_buf)
199 	vstring_free(state->milter_dsn_buf);
200     cleanup_region_done(state);
201     myfree((void *) state);
202 }
203