Postfix3.3.1
cleanup_state.c
[詳解]
1 /*++
2 /* NAME
3 /* cleanup_state 3
4 /* SUMMARY
5 /* per-message state variables
6 /* SYNOPSIS
7 /* #include "cleanup.h"
8 /*
9 /* CLEANUP_STATE *cleanup_state_alloc(src)
10 /* VSTREAM *src;
11 /*
12 /* void cleanup_state_free(state)
13 /* CLEANUP_STATE *state;
14 /* DESCRIPTION
15 /* This module maintains about two dozen state variables
16 /* that are used by many routines in the course of processing one
17 /* message.
18 /*
19 /* cleanup_state_alloc() initializes the per-message state variables.
20 /*
21 /* cleanup_state_free() cleans up.
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 /* Wietse Venema
33 /* Google, Inc.
34 /* 111 8th Avenue
35 /* New York, NY 10011, USA
36 /*--*/
37 
38 /* System library. */
39 
40 #include <sys_defs.h>
41 
42 /* Utility library. */
43 
44 #include <mymalloc.h>
45 #include <vstring.h>
46 #include <htable.h>
47 
48 /* Global library. */
49 
50 #include <been_here.h>
51 #include <mail_params.h>
52 #include <mime_state.h>
53 #include <mail_proto.h>
54 
55 /* Milter library. */
56 
57 #include <milter.h>
58 
59 /* Application-specific. */
60 
61 #include "cleanup.h"
62 
63 /* cleanup_state_alloc - initialize global state */
64 
66 {
67  CLEANUP_STATE *state = (CLEANUP_STATE *) mymalloc(sizeof(*state));
68 
69  state->attr_buf = vstring_alloc(10);
70  state->temp1 = vstring_alloc(10);
71  state->temp2 = vstring_alloc(10);
73  state->stripped_buf = vstring_alloc(10);
74  state->src = src;
75  state->dst = 0;
76  state->handle = 0;
77  state->queue_name = 0;
78  state->queue_id = 0;
79  state->arrival_time.tv_sec = state->arrival_time.tv_usec = 0;
80  state->fullname = 0;
81  state->sender = 0;
82  state->recip = 0;
83  state->orig_rcpt = 0;
84  state->return_receipt = 0;
85  state->errors_to = 0;
86  state->auto_hdrs = argv_alloc(1);
87  state->hbc_rcpt = 0;
88  state->flags = 0;
89  state->tflags = 0;
90  state->qmgr_opts = 0;
91  state->errs = 0;
92  state->err_mask = 0;
93  state->headers_seen = 0;
94  state->hop_count = 0;
95  state->resent = "";
97  state->action = cleanup_envelope;
98  state->data_offset = -1;
99  state->body_offset = -1;
100  state->xtra_offset = -1;
101  state->cont_length = 0;
102  state->sender_pt_offset = -1;
103  state->sender_pt_target = -1;
104  state->append_rcpt_pt_offset = -1;
105  state->append_rcpt_pt_target = -1;
106  state->append_hdr_pt_offset = -1;
107  state->append_hdr_pt_target = -1;
108  state->append_meta_pt_offset = -1;
109  state->append_meta_pt_target = -1;
110  state->milter_hbc_checks = 0;
111  state->milter_hbc_reply = 0;
112  state->rcpt_count = 0;
113  state->reason = 0;
114  state->smtp_reply = 0;
115  state->attr = nvtable_create(10);
117  state->mime_state = 0;
118  state->mime_errs = 0;
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 
147 {
148  vstring_free(state->attr_buf);
149  vstring_free(state->temp1);
150  vstring_free(state->temp2);
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)
194  if (state->milter_ext_rcpt)
196  if (state->milter_err_text)
198  if (state->milter_dsn_buf)
200  cleanup_region_done(state);
201  myfree((void *) state);
202 }
VSTRING * milter_ext_rcpt
Definition: cleanup.h:118
#define BH_FLAG_FOLD
Definition: been_here.h:29
char * orig_rcpt
Definition: cleanup.h:61
void myfree(void *ptr)
Definition: mymalloc.c:207
int smtputf8
Definition: cleanup.h:134
char * recip
Definition: cleanup.h:60
void cleanup_envelope(CLEANUP_STATE *, int, const char *, ssize_t)
char * queue_name
Definition: cleanup.h:55
char * fullname
Definition: cleanup.h:58
void been_here_free(BH_TABLE *dup_filter)
Definition: been_here.c:116
ARGV * argv_free(ARGV *argvp)
Definition: argv.c:136
off_t body_offset
Definition: cleanup.h:77
NVTABLE_INFO * nvtable_update(NVTABLE *table, const char *key, const char *value)
Definition: nvtable.c:111
VSTRING * milter_err_text
Definition: cleanup.h:119
int tflags
Definition: cleanup.h:67
off_t sender_pt_target
Definition: cleanup.h:81
int mime_errs
Definition: cleanup.h:93
int client_af
Definition: cleanup.h:113
off_t append_rcpt_pt_target
Definition: cleanup.h:83
HBC_CHECKS * milter_hbc_checks
Definition: cleanup.h:120
char * reason
Definition: cleanup.h:89
char * redirect
Definition: cleanup.h:96
MILTERS * milters
Definition: cleanup.h:109
#define MAIL_ATTR_RWR_LOCAL
Definition: mail_proto.h:166
VSTRING * temp2
Definition: cleanup.h:50
char * return_receipt
Definition: cleanup.h:62
struct timeval arrival_time
Definition: cleanup.h:57
ARGV * argv_alloc(ssize_t len)
Definition: argv.c:149
BH_TABLE * been_here_init(int limit, int flags)
Definition: been_here.c:103
off_t xtra_offset
Definition: cleanup.h:78
VSTRING * milter_dsn_buf
Definition: cleanup.h:122
const char * client_port
Definition: cleanup.h:114
char * dsn_envid
Definition: cleanup.h:97
#define MAIL_ATTR_ORG_LOCAL
Definition: mail_proto.h:229
int err_mask
Definition: cleanup.h:70
NVTABLE * attr
Definition: cleanup.h:91
void cleanup_state_free(CLEANUP_STATE *state)
off_t append_meta_pt_offset
Definition: cleanup.h:86
VSTRING * stripped_buf
Definition: cleanup.h:51
const char * server_addr
Definition: cleanup.h:115
int dsn_notify
Definition: cleanup.h:99
#define MAIL_ATTR_LOG_ORIGIN
Definition: mail_proto.h:212
char * errors_to
Definition: cleanup.h:63
VSTRING * milter_hbc_reply
Definition: cleanup.h:121
off_t append_rcpt_pt_offset
Definition: cleanup.h:82
MIME_STATE * mime_state_free(MIME_STATE *state)
Definition: mime_state.c:530
VSTREAM * src
Definition: cleanup.h:52
BH_TABLE * dups
Definition: cleanup.h:74
char * sender
Definition: cleanup.h:59
char * dsn_orcpt
Definition: cleanup.h:100
off_t sender_pt_offset
Definition: cleanup.h:80
const char * reverse_name
Definition: cleanup.h:111
off_t append_hdr_pt_offset
Definition: cleanup.h:84
VSTRING * milter_ext_from
Definition: cleanup.h:117
char * hdr_rewrite_context
Definition: cleanup.h:94
ARGV * hbc_rcpt
Definition: cleanup.h:65
int headers_seen
Definition: cleanup.h:71
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
const char * client_addr
Definition: cleanup.h:112
char * filter
Definition: cleanup.h:95
struct CLEANUP_REGION * curr_body_region
Definition: cleanup.h:129
void cleanup_region_done(CLEANUP_STATE *)
void(* action)(struct CLEANUP_STATE *, int, const char *, ssize_t)
Definition: cleanup.h:75
ARGV * auto_hdrs
Definition: cleanup.h:64
VSTRING * attr_buf
Definition: cleanup.h:48
struct CLEANUP_REGION * body_regions
Definition: cleanup.h:128
char * queue_id
Definition: cleanup.h:56
void milter_free(MILTERS *milters)
Definition: milter.c:733
#define nvtable_free(table)
Definition: nvtable.h:29
int hop_count
Definition: cleanup.h:72
const char * server_port
Definition: cleanup.h:116
CLEANUP_STATE * cleanup_state_alloc(VSTREAM *src)
Definition: cleanup_state.c:65
VSTREAM * dst
Definition: cleanup.h:53
#define nvtable_create(size)
Definition: nvtable.h:23
off_t append_meta_pt_target
Definition: cleanup.h:87
int var_dup_filter_limit
Definition: cleanup_init.c:136
VSTRING * temp1
Definition: cleanup.h:49
int dsn_ret
Definition: cleanup.h:98
off_t cont_length
Definition: cleanup.h:79
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
const char * client_name
Definition: cleanup.h:110
char * verp_delims
Definition: cleanup.h:101
ssize_t rcpt_count
Definition: cleanup.h:88
struct CLEANUP_REGION * free_regions
Definition: cleanup.h:127
off_t append_hdr_pt_target
Definition: cleanup.h:85
MAIL_STREAM * handle
Definition: cleanup.h:54
char * smtp_reply
Definition: cleanup.h:90
off_t data_offset
Definition: cleanup.h:76
int qmgr_opts
Definition: cleanup.h:68
MIME_STATE * mime_state
Definition: cleanup.h:92
char * resent
Definition: cleanup.h:73
VSTRING * cleanup_strip_chars
Definition: cleanup_init.c:269
void * mymalloc(ssize_t len)
Definition: mymalloc.c:150