trace.c
2.31 KB
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
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2011-2012, 2014 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <errno.h>
#include <mailutils/types.h>
#include <mailutils/imapio.h>
#include <mailutils/stream.h>
#include <mailutils/errno.h>
#include <mailutils/error.h>
#include <mailutils/nls.h>
#include <mailutils/sys/imapio.h>
static const char *imapio_prefix[] = {
"S: ", "C: "
};
int
mu_imapio_trace_enable (mu_imapio_t io)
{
int rc = 0;
mu_stream_t dstr, xstr;
if (io->_imap_transcript)
return MU_ERR_OPEN;
rc = mu_dbgstream_create (&dstr, MU_DIAG_DEBUG);
if (rc)
mu_error (_("cannot create debug stream; transcript disabled: %s"),
mu_strerror (rc));
else
{
rc = mu_xscript_stream_create (&xstr, io->_imap_stream, dstr,
imapio_prefix);
if (rc)
mu_error (_("cannot create transcript stream: %s"),
mu_strerror (rc));
else
{
mu_stream_unref (io->_imap_stream);
io->_imap_stream = xstr;
io->_imap_transcript = 1;
}
}
return rc;
}
int
mu_imapio_trace_disable (mu_imapio_t io)
{
mu_stream_t xstr = io->_imap_stream;
mu_stream_t stream[2];
int rc;
if (!io->_imap_transcript)
return MU_ERR_NOT_OPEN;
rc = mu_stream_ioctl (xstr, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET, stream);
if (rc)
return rc;
io->_imap_stream = stream[0];
mu_stream_destroy (&xstr);
io->_imap_transcript = 0;
return 0;
}
int
mu_imapio_get_trace (mu_imapio_t io)
{
return io ? io->_imap_transcript : 0;
}
void
mu_imapio_trace_payload (mu_imapio_t io, int val)
{
io->_imap_trace_payload = !!val;
}
int
mu_imapio_get_trace_payload (mu_imapio_t io)
{
return io ? io->_imap_trace_payload : 0;
}