Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / smtp / smtp_state.c
blob7097b45d6c662682d5d238d2bcca82f349a12ea5
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* smtp_state 3
6 /* SUMMARY
7 /* initialize/cleanup shared state
8 /* SYNOPSIS
9 /* #include "smtp.h"
11 /* SMTP_STATE *smtp_state_alloc()
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.
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 /*--*/
35 /* System library. */
37 #include <sys_defs.h>
39 /* Utility library. */
41 #include <mymalloc.h>
42 #include <vstring.h>
43 #include <msg.h>
45 /* Global library. */
47 #include <mail_params.h>
49 /* Application-specific. */
51 #include "smtp.h"
52 #include "smtp_sasl.h"
54 /* smtp_state_alloc - initialize */
56 SMTP_STATE *smtp_state_alloc(void)
58 SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state));
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->nexthop_domain = 0;
68 if (var_smtp_cache_conn) {
69 state->dest_label = vstring_alloc(10);
70 state->dest_prop = vstring_alloc(10);
71 state->endp_label = vstring_alloc(10);
72 state->endp_prop = vstring_alloc(10);
73 state->cache_used = htable_create(1);
74 } else {
75 state->dest_label = 0;
76 state->dest_prop = 0;
77 state->endp_label = 0;
78 state->endp_prop = 0;
79 state->cache_used = 0;
81 state->why = dsb_create();
84 * The process name, "smtp" or "lmtp", is also used as the DSN server
85 * reply type and for SASL service information lookup. Since all three
86 * external representations are identical there is no reason to transform
87 * from some external form X to some Postfix-specific canonical internal
88 * form, and then to transform from the internal form to external forms Y
89 * and Z.
91 if (strcmp(var_procname, "lmtp") == 0) {
92 state->misc_flags |= SMTP_MISC_FLAG_USE_LMTP;
93 } else if (strcmp(var_procname, "smtp") == 0) {
94 /* void */
95 } else {
96 msg_fatal("unexpected process name \"%s\" - "
97 "specify \"smtp\" or \"lmtp\"",
98 var_procname);
100 return (state);
103 /* smtp_state_free - destroy state */
105 void smtp_state_free(SMTP_STATE *state)
107 if (state->dest_label)
108 vstring_free(state->dest_label);
109 if (state->dest_prop)
110 vstring_free(state->dest_prop);
111 if (state->endp_label)
112 vstring_free(state->endp_label);
113 if (state->endp_prop)
114 vstring_free(state->endp_prop);
115 if (state->cache_used)
116 htable_free(state->cache_used, (void (*) (char *)) 0);
117 if (state->why)
118 dsb_free(state->why);
120 myfree((char *) state);