1/*++
2/* NAME
3/*	qmqpd_state 3
4/* SUMMARY
5/*	Postfix QMQP server
6/* SYNOPSIS
7/*	#include "qmqpd.h"
8/*
9/*	QMQPD_STATE *qmqpd_state_alloc(stream)
10/*	VSTREAM *stream;
11/*
12/*	void	qmqpd_state_free(state)
13/*	QMQPD_STATE *state;
14/* DESCRIPTION
15/*	qmqpd_state_alloc() creates and initializes session context.
16/*
17/*	qmqpd_state_free() destroys session context.
18/*
19/*	Arguments:
20/* .IP stream
21/*	Stream connected to peer. The stream is not copied.
22/* DIAGNOSTICS
23/*	All errors are fatal.
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#include <time.h>
39
40/* Utility library. */
41
42#include <mymalloc.h>
43#include <vstream.h>
44#include <vstring.h>
45
46/* Global library. */
47
48#include <mail_stream.h>
49#include <cleanup_user.h>
50#include <mail_proto.h>
51
52/* Application-specific. */
53
54#include <qmqpd.h>
55
56/* qmqpd_state_alloc - allocate and initialize session state */
57
58QMQPD_STATE *qmqpd_state_alloc(VSTREAM *stream)
59{
60    QMQPD_STATE *state;
61
62    state = (QMQPD_STATE *) mymalloc(sizeof(*state));
63    state->err = CLEANUP_STAT_OK;
64    state->client = stream;
65    state->message = vstring_alloc(1000);
66    state->buf = vstring_alloc(100);
67    GETTIMEOFDAY(&state->arrival_time);
68    qmqpd_peer_init(state);
69    state->queue_id = 0;
70    state->cleanup = 0;
71    state->dest = 0;
72    state->rcpt_count = 0;
73    state->reason = 0;
74    state->sender = 0;
75    state->recipient = 0;
76    state->protocol = MAIL_PROTO_QMQP;
77    state->where = "initializing client connection";
78    state->why_rejected = vstring_alloc(10);
79    return (state);
80}
81
82/* qmqpd_state_free - destroy session state */
83
84void qmqpd_state_free(QMQPD_STATE *state)
85{
86    vstring_free(state->message);
87    vstring_free(state->buf);
88    qmqpd_peer_reset(state);
89    if (state->queue_id)
90	myfree(state->queue_id);
91    if (state->dest)
92	mail_stream_cleanup(state->dest);
93    if (state->sender)
94	myfree(state->sender);
95    if (state->recipient)
96	myfree(state->recipient);
97    vstring_free(state->why_rejected);
98    myfree((char *) state);
99}
100