Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / qmqpd / qmqpd_state.c
blobb3607dff392d958112008ab3eb61deb62f28be9d
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* qmqpd_state 3
6 /* SUMMARY
7 /* Postfix QMQP server
8 /* SYNOPSIS
9 /* #include "qmqpd.h"
11 /* QMQPD_STATE *qmqpd_state_alloc(stream)
12 /* VSTREAM *stream;
14 /* void qmqpd_state_free(state)
15 /* QMQPD_STATE *state;
16 /* DESCRIPTION
17 /* qmqpd_state_alloc() creates and initializes session context.
19 /* qmqpd_state_free() destroys session context.
21 /* Arguments:
22 /* .IP stream
23 /* Stream connected to peer. The stream is not copied.
24 /* DIAGNOSTICS
25 /* All errors are fatal.
26 /* LICENSE
27 /* .ad
28 /* .fi
29 /* The Secure Mailer license must be distributed with this software.
30 /* AUTHOR(S)
31 /* Wietse Venema
32 /* IBM T.J. Watson Research
33 /* P.O. Box 704
34 /* Yorktown Heights, NY 10598, USA
35 /*--*/
37 /* System library. */
39 #include <sys_defs.h>
40 #include <time.h>
42 /* Utility library. */
44 #include <mymalloc.h>
45 #include <vstream.h>
46 #include <vstring.h>
48 /* Global library. */
50 #include <mail_stream.h>
51 #include <cleanup_user.h>
52 #include <mail_proto.h>
54 /* Application-specific. */
56 #include <qmqpd.h>
58 /* qmqpd_state_alloc - allocate and initialize session state */
60 QMQPD_STATE *qmqpd_state_alloc(VSTREAM *stream)
62 QMQPD_STATE *state;
64 state = (QMQPD_STATE *) mymalloc(sizeof(*state));
65 state->err = CLEANUP_STAT_OK;
66 state->client = stream;
67 state->message = vstring_alloc(1000);
68 state->buf = vstring_alloc(100);
69 GETTIMEOFDAY(&state->arrival_time);
70 qmqpd_peer_init(state);
71 state->queue_id = 0;
72 state->cleanup = 0;
73 state->dest = 0;
74 state->rcpt_count = 0;
75 state->reason = 0;
76 state->sender = 0;
77 state->recipient = 0;
78 state->protocol = MAIL_PROTO_QMQP;
79 state->where = "initializing client connection";
80 state->why_rejected = vstring_alloc(10);
81 return (state);
84 /* qmqpd_state_free - destroy session state */
86 void qmqpd_state_free(QMQPD_STATE *state)
88 vstring_free(state->message);
89 vstring_free(state->buf);
90 qmqpd_peer_reset(state);
91 if (state->queue_id)
92 myfree(state->queue_id);
93 if (state->dest)
94 mail_stream_cleanup(state->dest);
95 if (state->sender)
96 myfree(state->sender);
97 if (state->recipient)
98 myfree(state->recipient);
99 vstring_free(state->why_rejected);
100 myfree((char *) state);