1/* $NetBSD: qmqpd_state.c,v 1.2 2017/02/14 01:16:47 christos Exp $ */ 2 3/*++ 4/* NAME 5/* qmqpd_state 3 6/* SUMMARY 7/* Postfix QMQP server 8/* SYNOPSIS 9/* #include "qmqpd.h" 10/* 11/* QMQPD_STATE *qmqpd_state_alloc(stream) 12/* VSTREAM *stream; 13/* 14/* void qmqpd_state_free(state) 15/* QMQPD_STATE *state; 16/* DESCRIPTION 17/* qmqpd_state_alloc() creates and initializes session context. 18/* 19/* qmqpd_state_free() destroys session context. 20/* 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/*--*/ 36 37/* System library. */ 38 39#include <sys_defs.h> 40#include <time.h> 41 42/* Utility library. */ 43 44#include <mymalloc.h> 45#include <vstream.h> 46#include <vstring.h> 47 48/* Global library. */ 49 50#include <mail_stream.h> 51#include <cleanup_user.h> 52#include <mail_proto.h> 53 54/* Application-specific. */ 55 56#include <qmqpd.h> 57 58/* qmqpd_state_alloc - allocate and initialize session state */ 59 60QMQPD_STATE *qmqpd_state_alloc(VSTREAM *stream) 61{ 62 QMQPD_STATE *state; 63 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); 82} 83 84/* qmqpd_state_free - destroy session state */ 85 86void qmqpd_state_free(QMQPD_STATE *state) 87{ 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((void *) state); 101} 102