summaryrefslogtreecommitdiffstats
path: root/src/qmqpd/qmqpd_state.c
blob: 9bee879a77ffcc28c7dbb3f27a9b291cd3079739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*++
/* NAME
/*	qmqpd_state 3
/* SUMMARY
/*	Postfix QMQP server
/* SYNOPSIS
/*	#include "qmqpd.h"
/*
/*	QMQPD_STATE *qmqpd_state_alloc(stream)
/*	VSTREAM *stream;
/*
/*	void	qmqpd_state_free(state)
/*	QMQPD_STATE *state;
/* DESCRIPTION
/*	qmqpd_state_alloc() creates and initializes session context.
/*
/*	qmqpd_state_free() destroys session context.
/*
/*	Arguments:
/* .IP stream
/*	Stream connected to peer. The stream is not copied.
/* DIAGNOSTICS
/*	All errors are fatal.
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*--*/

/* System library. */

#include <sys_defs.h>
#include <time.h>

/* Utility library. */

#include <mymalloc.h>
#include <vstream.h>
#include <vstring.h>

/* Global library. */

#include <mail_stream.h>
#include <cleanup_user.h>
#include <mail_proto.h>

/* Application-specific. */

#include <qmqpd.h>

/* qmqpd_state_alloc - allocate and initialize session state */

QMQPD_STATE *qmqpd_state_alloc(VSTREAM *stream)
{
    QMQPD_STATE *state;

    state = (QMQPD_STATE *) mymalloc(sizeof(*state));
    state->err = CLEANUP_STAT_OK;
    state->client = stream;
    state->message = vstring_alloc(1000);
    state->buf = vstring_alloc(100);
    GETTIMEOFDAY(&state->arrival_time);
    qmqpd_peer_init(state);
    state->queue_id = 0;
    state->cleanup = 0;
    state->dest = 0;
    state->rcpt_count = 0;
    state->reason = 0;
    state->sender = 0;
    state->recipient = 0;
    state->protocol = MAIL_PROTO_QMQP;
    state->where = "initializing client connection";
    state->why_rejected = vstring_alloc(10);
    return (state);
}

/* qmqpd_state_free - destroy session state */

void    qmqpd_state_free(QMQPD_STATE *state)
{
    vstring_free(state->message);
    vstring_free(state->buf);
    qmqpd_peer_reset(state);
    if (state->queue_id)
	myfree(state->queue_id);
    if (state->dest)
	mail_stream_cleanup(state->dest);
    if (state->sender)
	myfree(state->sender);
    if (state->recipient)
	myfree(state->recipient);
    vstring_free(state->why_rejected);
    myfree((void *) state);
}