Postfix3.3.1
qmqpd_state.c
[詳解]
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 
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 
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((void *) state);
99 }
void myfree(void *ptr)
Definition: mymalloc.c:207
void mail_stream_cleanup(MAIL_STREAM *info)
Definition: mail_stream.c:151
VSTREAM * client
Definition: qmqpd.h:32
char * where
Definition: qmqpd.h:50
#define CLEANUP_STAT_OK
Definition: cleanup_user.h:56
char * sender
Definition: qmqpd.h:47
VSTRING * message
Definition: qmqpd.h:33
int rcpt_count
Definition: qmqpd.h:45
VSTRING * why_rejected
Definition: qmqpd.h:51
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
struct timeval arrival_time
Definition: qmqpd.h:35
#define MAIL_PROTO_QMQP
Definition: mail_proto.h:32
char * protocol
Definition: qmqpd.h:49
char * reason
Definition: qmqpd.h:46
VSTREAM * cleanup
Definition: qmqpd.h:43
MAIL_STREAM * dest
Definition: qmqpd.h:44
void qmqpd_state_free(QMQPD_STATE *state)
Definition: qmqpd_state.c:84
void qmqpd_peer_init(QMQPD_STATE *)
Definition: qmqpd_peer.c:74
char * recipient
Definition: qmqpd.h:48
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
QMQPD_STATE * qmqpd_state_alloc(VSTREAM *stream)
Definition: qmqpd_state.c:58
void qmqpd_peer_reset(QMQPD_STATE *)
Definition: qmqpd_peer.c:298
VSTRING * buf
Definition: qmqpd.h:34
char * queue_id
Definition: qmqpd.h:42
int err
Definition: qmqpd.h:31
void * mymalloc(ssize_t len)
Definition: mymalloc.c:150