xref: /netbsd-src/external/ibm-public/postfix/dist/src/smtp/smtp_state.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: smtp_state.c,v 1.2 2017/02/14 01:16:48 christos Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	smtp_state 3
6 /* SUMMARY
7 /*	initialize/cleanup shared state
8 /* SYNOPSIS
9 /*	#include "smtp.h"
10 /*
11 /*	SMTP_STATE *smtp_state_alloc()
12 /*
13 /*	void	smtp_state_free(state)
14 /*	SMTP_STATE *state;
15 /* DESCRIPTION
16 /*	smtp_state_init() initializes the shared state, and allocates
17 /*	memory for buffers etc.
18 /*
19 /*	smtp_cleanup() destroys memory allocated by smtp_state_init().
20 /* STANDARDS
21 /* DIAGNOSTICS
22 /* BUGS
23 /* SEE ALSO
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 
35 /* System library. */
36 
37 #include <sys_defs.h>
38 
39 /* Utility library. */
40 
41 #include <mymalloc.h>
42 #include <vstring.h>
43 #include <msg.h>
44 
45 /* Global library. */
46 
47 #include <mail_params.h>
48 
49 /* Application-specific. */
50 
51 #include "smtp.h"
52 #include "smtp_sasl.h"
53 
54 /* smtp_state_alloc - initialize */
55 
56 SMTP_STATE *smtp_state_alloc(void)
57 {
58     SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state));
59 
60     state->misc_flags = 0;
61     state->src = 0;
62     state->service = 0;
63     state->request = 0;
64     state->session = 0;
65     state->status = 0;
66     state->space_left = 0;
67     state->iterator->request_nexthop = vstring_alloc(100);
68     state->iterator->dest = vstring_alloc(100);
69     state->iterator->host = vstring_alloc(100);
70     state->iterator->addr = vstring_alloc(100);
71     state->iterator->saved_dest = vstring_alloc(100);
72     if (var_smtp_cache_conn) {
73 	state->dest_label = vstring_alloc(10);
74 	state->dest_prop = vstring_alloc(10);
75 	state->endp_label = vstring_alloc(10);
76 	state->endp_prop = vstring_alloc(10);
77 	state->cache_used = htable_create(1);
78     } else {
79 	state->dest_label = 0;
80 	state->dest_prop = 0;
81 	state->endp_label = 0;
82 	state->endp_prop = 0;
83 	state->cache_used = 0;
84     }
85     state->why = dsb_create();
86     return (state);
87 }
88 
89 /* smtp_state_free - destroy state */
90 
91 void    smtp_state_free(SMTP_STATE *state)
92 {
93 #ifdef USE_TLS
94     /* The TLS policy cache lifetime is one delivery. */
95     smtp_tls_policy_cache_flush();
96 #endif
97     vstring_free(state->iterator->request_nexthop);
98     vstring_free(state->iterator->dest);
99     vstring_free(state->iterator->host);
100     vstring_free(state->iterator->addr);
101     vstring_free(state->iterator->saved_dest);
102     if (state->dest_label)
103 	vstring_free(state->dest_label);
104     if (state->dest_prop)
105 	vstring_free(state->dest_prop);
106     if (state->endp_label)
107 	vstring_free(state->endp_label);
108     if (state->endp_prop)
109 	vstring_free(state->endp_prop);
110     if (state->cache_used)
111 	htable_free(state->cache_used, (void (*) (void *)) 0);
112     if (state->why)
113 	dsb_free(state->why);
114 
115     myfree((void *) state);
116 }
117