Postfix3.3.1
smtp_state.c
[詳解]
1 /*++
2 /* NAME
3 /* smtp_state 3
4 /* SUMMARY
5 /* initialize/cleanup shared state
6 /* SYNOPSIS
7 /* #include "smtp.h"
8 /*
9 /* SMTP_STATE *smtp_state_alloc()
10 /*
11 /* void smtp_state_free(state)
12 /* SMTP_STATE *state;
13 /* DESCRIPTION
14 /* smtp_state_init() initializes the shared state, and allocates
15 /* memory for buffers etc.
16 /*
17 /* smtp_cleanup() destroys memory allocated by smtp_state_init().
18 /* STANDARDS
19 /* DIAGNOSTICS
20 /* BUGS
21 /* SEE ALSO
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 
33 /* System library. */
34 
35 #include <sys_defs.h>
36 
37 /* Utility library. */
38 
39 #include <mymalloc.h>
40 #include <vstring.h>
41 #include <msg.h>
42 
43 /* Global library. */
44 
45 #include <mail_params.h>
46 
47 /* Application-specific. */
48 
49 #include "smtp.h"
50 #include "smtp_sasl.h"
51 
52 /* smtp_state_alloc - initialize */
53 
55 {
56  SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state));
57 
58  state->misc_flags = 0;
59  state->src = 0;
60  state->service = 0;
61  state->request = 0;
62  state->session = 0;
63  state->status = 0;
64  state->space_left = 0;
65  state->iterator->request_nexthop = vstring_alloc(100);
66  state->iterator->dest = vstring_alloc(100);
67  state->iterator->host = vstring_alloc(100);
68  state->iterator->addr = vstring_alloc(100);
69  state->iterator->saved_dest = vstring_alloc(100);
70  if (var_smtp_cache_conn) {
71  state->dest_label = vstring_alloc(10);
72  state->dest_prop = vstring_alloc(10);
73  state->endp_label = vstring_alloc(10);
74  state->endp_prop = vstring_alloc(10);
75  state->cache_used = htable_create(1);
76  } else {
77  state->dest_label = 0;
78  state->dest_prop = 0;
79  state->endp_label = 0;
80  state->endp_prop = 0;
81  state->cache_used = 0;
82  }
83  state->why = dsb_create();
84  return (state);
85 }
86 
87 /* smtp_state_free - destroy state */
88 
90 {
91 #ifdef USE_TLS
92  /* The TLS policy cache lifetime is one delivery. */
93  smtp_tls_policy_cache_flush();
94 #endif
96  vstring_free(state->iterator->dest);
97  vstring_free(state->iterator->host);
98  vstring_free(state->iterator->addr);
100  if (state->dest_label)
101  vstring_free(state->dest_label);
102  if (state->dest_prop)
103  vstring_free(state->dest_prop);
104  if (state->endp_label)
105  vstring_free(state->endp_label);
106  if (state->endp_prop)
107  vstring_free(state->endp_prop);
108  if (state->cache_used)
109  htable_free(state->cache_used, (void (*) (void *)) 0);
110  if (state->why)
111  dsb_free(state->why);
112 
113  myfree((void *) state);
114 }
void htable_free(HTABLE *table, void(*free_fn)(void *))
Definition: htable.c:287
VSTRING * endp_prop
Definition: smtp.h:170
ssize_t space_left
Definition: smtp.h:149
int status
Definition: smtp.h:148
void myfree(void *ptr)
Definition: mymalloc.c:207
SMTP_ITERATOR iterator[1]
Definition: smtp.h:154
struct SMTP_SESSION * session
Definition: smtp.h:147
DSN_BUF * dsb_create(void)
Definition: dsn_buf.c:169
VSTREAM * src
Definition: smtp.h:144
VSTRING * request_nexthop
Definition: smtp.h:52
DSN_BUF * why
Definition: smtp.h:184
HTABLE * cache_used
Definition: smtp.h:166
DELIVER_REQUEST * request
Definition: smtp.h:146
VSTRING * saved_dest
Definition: smtp.h:60
void dsb_free(DSN_BUF *dsb)
Definition: dsn_buf.c:190
int misc_flags
Definition: smtp.h:143
VSTRING * dest
Definition: smtp.h:53
void smtp_state_free(SMTP_STATE *state)
Definition: smtp_state.c:89
HTABLE * htable_create(ssize_t size)
Definition: htable.c:179
SMTP_STATE * smtp_state_alloc(void)
Definition: smtp_state.c:54
VSTRING * host
Definition: smtp.h:54
VSTRING * addr
Definition: smtp.h:55
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
VSTRING * endp_label
Definition: smtp.h:169
const char * service
Definition: smtp.h:145
int var_smtp_cache_conn
Definition: smtp.c:882
VSTRING * dest_prop
Definition: smtp.h:168
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
VSTRING * dest_label
Definition: smtp.h:167
void * mymalloc(ssize_t len)
Definition: mymalloc.c:150