summaryrefslogtreecommitdiffstats
path: root/src/cleanup/cleanup_state.c
blob: 99adf84b9863f9fd21c4a4a6a55997a8d79ea6a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*++
/* NAME
/*	cleanup_state 3
/* SUMMARY
/*	per-message state variables
/* SYNOPSIS
/*	#include "cleanup.h"
/*
/*	CLEANUP_STATE *cleanup_state_alloc(src)
/*	VSTREAM	*src;
/*
/*	void	cleanup_state_free(state)
/*	CLEANUP_STATE *state;
/* DESCRIPTION
/*	This module maintains about two dozen state variables
/*	that are used by many routines in the course of processing one
/*	message.
/*
/*	cleanup_state_alloc() initializes the per-message state variables.
/*
/*	cleanup_state_free() cleans up.
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*
/*	Wietse Venema
/*	Google, Inc.
/*	111 8th Avenue
/*	New York, NY 10011, USA
/*--*/

/* System library. */

#include <sys_defs.h>

/* Utility library. */

#include <mymalloc.h>
#include <vstring.h>
#include <htable.h>

/* Global library. */

#include <been_here.h>
#include <mail_params.h>
#include <mime_state.h>
#include <mail_proto.h>

/* Milter library. */

#include <milter.h>

/* Application-specific. */

#include "cleanup.h"

/* cleanup_state_alloc - initialize global state */

CLEANUP_STATE *cleanup_state_alloc(VSTREAM *src)
{
    CLEANUP_STATE *state = (CLEANUP_STATE *) mymalloc(sizeof(*state));

    state->attr_buf = vstring_alloc(10);
    state->temp1 = vstring_alloc(10);
    state->temp2 = vstring_alloc(10);
    if (cleanup_strip_chars)
	state->stripped_buf = vstring_alloc(10);
    state->src = src;
    state->dst = 0;
    state->handle = 0;
    state->queue_name = 0;
    state->queue_id = 0;
    state->arrival_time.tv_sec = state->arrival_time.tv_usec = 0;
    state->fullname = 0;
    state->sender = 0;
    state->recip = 0;
    state->orig_rcpt = 0;
    state->return_receipt = 0;
    state->errors_to = 0;
    state->auto_hdrs = argv_alloc(1);
    state->hbc_rcpt = 0;
    state->flags = 0;
    state->tflags = 0;
    state->qmgr_opts = 0;
    state->errs = 0;
    state->err_mask = 0;
    state->headers_seen = 0;
    state->hop_count = 0;
    state->resent = "";
    state->dups = been_here_init(var_dup_filter_limit, BH_FLAG_FOLD);
    state->action = cleanup_envelope;
    state->data_offset = -1;
    state->body_offset = -1;
    state->xtra_offset = -1;
    state->cont_length = 0;
    state->sender_pt_offset = -1;
    state->sender_pt_target = -1;
    state->append_rcpt_pt_offset = -1;
    state->append_rcpt_pt_target = -1;
    state->append_hdr_pt_offset = -1;
    state->append_hdr_pt_target = -1;
    state->append_meta_pt_offset = -1;
    state->append_meta_pt_target = -1;
    state->rcpt_count = 0;
    state->reason = 0;
    state->smtp_reply = 0;
    state->attr = nvtable_create(10);
    nvtable_update(state->attr, MAIL_ATTR_LOG_ORIGIN, MAIL_ATTR_ORG_LOCAL);
    state->mime_state = 0;
    state->mime_errs = 0;
    state->hdr_rewrite_context = MAIL_ATTR_RWR_LOCAL;
    state->filter = 0;
    state->redirect = 0;
    state->dsn_envid = 0;
    state->dsn_ret = 0;
    state->dsn_notify = 0;
    state->dsn_orcpt = 0;
    state->verp_delims = 0;
    state->milters = 0;
    state->client_name = 0;
    state->reverse_name = 0;
    state->client_addr = 0;
    state->client_af = 0;
    state->client_port = 0;
    state->server_addr = 0;
    state->server_port = 0;
    state->milter_ext_from = 0;
    state->milter_ext_rcpt = 0;
    state->milter_err_text = 0;
    state->milter_dsn_buf = 0;
    state->free_regions = state->body_regions = state->curr_body_region = 0;
    state->smtputf8 = 0;
    return (state);
}

/* cleanup_state_free - destroy global state */

void    cleanup_state_free(CLEANUP_STATE *state)
{
    vstring_free(state->attr_buf);
    vstring_free(state->temp1);
    vstring_free(state->temp2);
    if (cleanup_strip_chars)
	vstring_free(state->stripped_buf);
    if (state->fullname)
	myfree(state->fullname);
    if (state->sender)
	myfree(state->sender);
    if (state->recip)
	myfree(state->recip);
    if (state->orig_rcpt)
	myfree(state->orig_rcpt);
    if (state->return_receipt)
	myfree(state->return_receipt);
    if (state->errors_to)
	myfree(state->errors_to);
    argv_free(state->auto_hdrs);
    if (state->hbc_rcpt)
	argv_free(state->hbc_rcpt);
    if (state->queue_name)
	myfree(state->queue_name);
    if (state->queue_id)
	myfree(state->queue_id);
    been_here_free(state->dups);
    if (state->reason)
	myfree(state->reason);
    if (state->smtp_reply)
	myfree(state->smtp_reply);
    nvtable_free(state->attr);
    if (state->mime_state)
	mime_state_free(state->mime_state);
    if (state->filter)
	myfree(state->filter);
    if (state->redirect)
	myfree(state->redirect);
    if (state->dsn_envid)
	myfree(state->dsn_envid);
    if (state->dsn_orcpt)
	myfree(state->dsn_orcpt);
    if (state->verp_delims)
	myfree(state->verp_delims);
    if (state->milters)
	milter_free(state->milters);
    if (state->milter_ext_from)
	vstring_free(state->milter_ext_from);
    if (state->milter_ext_rcpt)
	vstring_free(state->milter_ext_rcpt);
    if (state->milter_err_text)
	vstring_free(state->milter_err_text);
    if (state->milter_dsn_buf)
	vstring_free(state->milter_dsn_buf);
    cleanup_region_done(state);
    myfree((void *) state);
}