Pop3 now has a debug object, mu_debug_t, to follow the protocol
exchanges between the library and the server. * mailbox2/pop3/*: Add debug prints in all. * mailbox2/sdebug.c: New entry. * mailbox2/debug.c: New entry. * mailbox2/Makefile.am: Add debug object * mailbox2/include/mailutils/Makefile.am: Add debug.h * mailbox2/include/mailutils/sys/Makefile.am: Add debug.h and sdebug.h * mailbox2/include/mailutils/debug.h: New file. * mailbox2/include/mailutils/sys/debug.h: New file. * mailbox2/include/mailutils/sys/sdebug.h: New file. * mailbox2/fdstream.c: Bug in fdstream do not call FD_SET if the file descriptor is -1; * mailbox2/tcpstream.c: Bug in fdstream do not call FD_SET if the file descriptor is -1;
Showing
31 changed files
with
541 additions
and
65 deletions
... | @@ -16,6 +16,7 @@ libmailbox_la_SOURCES = \ | ... | @@ -16,6 +16,7 @@ libmailbox_la_SOURCES = \ |
16 | authority.c \ | 16 | authority.c \ |
17 | bstream.c \ | 17 | bstream.c \ |
18 | dattribute.c \ | 18 | dattribute.c \ |
19 | debug.c \ | ||
19 | dotlock.c \ | 20 | dotlock.c \ |
20 | envelope.c \ | 21 | envelope.c \ |
21 | fdstream.c \ | 22 | fdstream.c \ |
... | @@ -35,7 +36,8 @@ libmailbox_la_SOURCES = \ | ... | @@ -35,7 +36,8 @@ libmailbox_la_SOURCES = \ |
35 | observer.c \ | 36 | observer.c \ |
36 | parse822.c \ | 37 | parse822.c \ |
37 | pticket.c \ | 38 | pticket.c \ |
38 | refcount.c \ | 39 | refcount.c \ |
40 | sdebug.c \ | ||
39 | stream.c \ | 41 | stream.c \ |
40 | tcpstream.c \ | 42 | tcpstream.c \ |
41 | ticket.c | 43 | ticket.c | ... | ... |
mailbox2/debug.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <stdlib.h> | ||
23 | |||
24 | #include <mailutils/sys/debug.h> | ||
25 | #include <mailutils/error.h> | ||
26 | |||
27 | int | ||
28 | mu_debug_ref (mu_debug_t debug) | ||
29 | { | ||
30 | if (debug == NULL || debug->vtable == NULL || debug->vtable->ref == NULL) | ||
31 | return MU_ERROR_NOT_SUPPORTED; | ||
32 | return debug->vtable->ref (debug); | ||
33 | } | ||
34 | |||
35 | void | ||
36 | mu_debug_destroy (mu_debug_t *pdebug) | ||
37 | { | ||
38 | if (pdebug && *pdebug) | ||
39 | { | ||
40 | mu_debug_t debug = *pdebug; | ||
41 | if (debug->vtable && debug->vtable->destroy) | ||
42 | debug->vtable->destroy (pdebug); | ||
43 | *pdebug = NULL; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | int | ||
48 | mu_debug_set_level (mu_debug_t debug, unsigned int level) | ||
49 | { | ||
50 | if (debug == NULL || debug->vtable == NULL | ||
51 | || debug->vtable->set_level == NULL) | ||
52 | return MU_ERROR_NOT_SUPPORTED; | ||
53 | return debug->vtable->set_level (debug, level); | ||
54 | } | ||
55 | |||
56 | int | ||
57 | mu_debug_get_level (mu_debug_t debug, unsigned int *plevel) | ||
58 | { | ||
59 | if (debug == NULL || debug->vtable == NULL | ||
60 | || debug->vtable->get_level == NULL) | ||
61 | return MU_ERROR_NOT_SUPPORTED; | ||
62 | return debug->vtable->get_level (debug, plevel); | ||
63 | } | ||
64 | |||
65 | int | ||
66 | mu_debug_print (mu_debug_t debug, unsigned int level, const char *fmt, ...) | ||
67 | { | ||
68 | va_list ap; | ||
69 | va_start (ap, fmt); | ||
70 | mu_debug_printv (debug, level, fmt, ap); | ||
71 | va_end (ap); | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | int | ||
76 | mu_debug_printv (mu_debug_t debug, unsigned int level, const char *fmt, | ||
77 | va_list ap) | ||
78 | { | ||
79 | if (debug == NULL || debug->vtable == NULL || debug->vtable->printv == NULL) | ||
80 | return MU_ERROR_NOT_SUPPORTED; | ||
81 | return debug->vtable->printv (debug, level, fmt, ap); | ||
82 | } |
... | @@ -267,54 +267,72 @@ static int | ... | @@ -267,54 +267,72 @@ static int |
267 | _fds_is_readready (stream_t stream, int timeout) | 267 | _fds_is_readready (stream_t stream, int timeout) |
268 | { | 268 | { |
269 | struct _fds *fds = (struct _fds *)stream; | 269 | struct _fds *fds = (struct _fds *)stream; |
270 | int ready; | 270 | int ready = 0; |
271 | struct timeval tv; | ||
272 | fd_set fset; | ||
273 | 271 | ||
274 | FD_ZERO (&fset); | 272 | if (fds->fd >= 0) |
275 | FD_SET (fds->fd, &fset); | 273 | { |
274 | struct timeval tv; | ||
275 | fd_set fset; | ||
276 | |||
277 | FD_ZERO (&fset); | ||
278 | FD_SET (fds->fd, &fset); | ||
276 | 279 | ||
277 | tv.tv_sec = timeout / 100; | 280 | tv.tv_sec = timeout / 100; |
278 | tv.tv_usec = (timeout % 1000) * 1000; | 281 | tv.tv_usec = (timeout % 1000) * 1000; |
279 | 282 | ||
280 | ready = select (fds->fd + 1, &fset, NULL, NULL, (timeout == -1) ? NULL: &tv); | 283 | ready = select (fds->fd + 1, &fset, NULL, NULL, |
281 | return (ready == -1) ? 0 : 1; | 284 | (timeout == -1) ? NULL: &tv); |
285 | ready = (ready == -1) ? 0 : 1; | ||
286 | } | ||
287 | return ready; | ||
282 | } | 288 | } |
283 | 289 | ||
284 | static int | 290 | static int |
285 | _fds_is_writeready (stream_t stream, int timeout) | 291 | _fds_is_writeready (stream_t stream, int timeout) |
286 | { | 292 | { |
287 | struct _fds *fds = (struct _fds *)stream; | 293 | struct _fds *fds = (struct _fds *)stream; |
288 | int ready; | 294 | int ready = 0; |
289 | struct timeval tv; | 295 | |
290 | fd_set fset; | 296 | if (fds->fd) |
297 | { | ||
298 | struct timeval tv; | ||
299 | fd_set fset; | ||
291 | 300 | ||
292 | FD_ZERO (&fset); | 301 | FD_ZERO (&fset); |
293 | FD_SET (fds->fd, &fset); | 302 | FD_SET (fds->fd, &fset); |
294 | 303 | ||
295 | tv.tv_sec = timeout / 100; | 304 | tv.tv_sec = timeout / 100; |
296 | tv.tv_usec = (timeout % 1000) * 1000; | 305 | tv.tv_usec = (timeout % 1000) * 1000; |
297 | 306 | ||
298 | ready = select (fds->fd + 1, NULL, &fset, NULL, (timeout == -1) ? NULL: &tv); | 307 | ready = select (fds->fd + 1, NULL, &fset, NULL, |
299 | return (ready == -1) ? 0 : 1; | 308 | (timeout == -1) ? NULL: &tv); |
309 | ready = (ready == -1) ? 0 : 1; | ||
310 | } | ||
311 | return ready; | ||
300 | } | 312 | } |
301 | 313 | ||
302 | static int | 314 | static int |
303 | _fds_is_exceptionpending (stream_t stream, int timeout) | 315 | _fds_is_exceptionpending (stream_t stream, int timeout) |
304 | { | 316 | { |
305 | struct _fds *fds = (struct _fds *)stream; | 317 | struct _fds *fds = (struct _fds *)stream; |
306 | int ready; | 318 | int ready = 0; |
307 | struct timeval tv; | 319 | |
308 | fd_set fset; | 320 | if (fds->fd) |
321 | { | ||
322 | struct timeval tv; | ||
323 | fd_set fset; | ||
309 | 324 | ||
310 | FD_ZERO (&fset); | 325 | FD_ZERO (&fset); |
311 | FD_SET (fds->fd, &fset); | 326 | FD_SET (fds->fd, &fset); |
312 | 327 | ||
313 | tv.tv_sec = timeout / 100; | 328 | tv.tv_sec = timeout / 100; |
314 | tv.tv_usec = (timeout % 1000) * 1000; | 329 | tv.tv_usec = (timeout % 1000) * 1000; |
315 | 330 | ||
316 | ready = select (fds->fd + 1, NULL, NULL, &fset, (timeout == -1) ? NULL: &tv); | 331 | ready = select (fds->fd + 1, NULL, NULL, &fset, |
317 | return (ready == -1) ? 0 : 1; | 332 | (timeout == -1) ? NULL: &tv); |
333 | ready = (ready == -1) ? 0 : 1; | ||
334 | } | ||
335 | return 0; | ||
318 | } | 336 | } |
319 | 337 | ||
320 | static int | 338 | static int | ... | ... |
... | @@ -20,6 +20,7 @@ | ... | @@ -20,6 +20,7 @@ |
20 | 20 | ||
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | #include <stdarg.h> | 22 | #include <stdarg.h> |
23 | #include <stdio.h> | ||
23 | 24 | ||
24 | #ifndef __P | 25 | #ifndef __P |
25 | #ifdef __STDC__ | 26 | #ifdef __STDC__ |
... | @@ -33,20 +34,22 @@ | ... | @@ -33,20 +34,22 @@ |
33 | extern "C" { | 34 | extern "C" { |
34 | #endif | 35 | #endif |
35 | 36 | ||
36 | struct _debug; | 37 | struct _mu_debug; |
37 | typedef struct _debug* mu_debug_t; | 38 | typedef struct _mu_debug* mu_debug_t; |
38 | 39 | ||
39 | #define MU_DEBUG_TRACE 1 | 40 | #define MU_DEBUG_TRACE 1 |
40 | #define MU_DEBUG_PROT 2 | 41 | #define MU_DEBUG_PROT 2 |
42 | |||
41 | extern int mu_debug_ref __P ((mu_debug_t)); | 43 | extern int mu_debug_ref __P ((mu_debug_t)); |
42 | extern void mu_debug_destroy __P ((mu_debug_t *)); | 44 | extern void mu_debug_destroy __P ((mu_debug_t *)); |
43 | extern int mu_debug_set_level __P ((mu_debug_t, size_t level)); | 45 | extern int mu_debug_set_level __P ((mu_debug_t, unsigned int level)); |
44 | extern int mu_debug_get_level __P ((mu_debug_t, size_t *plevel)); | 46 | extern int mu_debug_get_level __P ((mu_debug_t, unsigned int *plevel)); |
45 | extern int mu_debug_print __P ((mu_debug_t debug, size_t level, | 47 | extern int mu_debug_print __P ((mu_debug_t debug, unsigned int level, |
46 | const char *format, ...)); | 48 | const char *format, ...)); |
47 | extern int mu_debug_printv __P ((mu_debug_t debug, size_t level, | 49 | extern int mu_debug_printv __P ((mu_debug_t debug, unsigned int level, |
48 | const char *format, va_list argp)); | 50 | const char *format, va_list argp)); |
49 | extern int mu_debug_stderr_create __P ((mu_debug_t *)); | 51 | |
52 | extern int mu_debug_stdio_create __P ((mu_debug_t *, FILE *)); | ||
50 | 53 | ||
51 | #ifdef __cplusplus | 54 | #ifdef __cplusplus |
52 | } | 55 | } | ... | ... |
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | #define _MAILUTILS_POP3_H | 19 | #define _MAILUTILS_POP3_H |
20 | 20 | ||
21 | #include <mailutils/iterator.h> | 21 | #include <mailutils/iterator.h> |
22 | #include <mailutils/debug.h> | ||
22 | #include <mailutils/stream.h> | 23 | #include <mailutils/stream.h> |
23 | 24 | ||
24 | #ifdef __cplusplus | 25 | #ifdef __cplusplus |
... | @@ -42,12 +43,15 @@ extern void pop3_destroy __P ((pop3_t *)); | ... | @@ -42,12 +43,15 @@ extern void pop3_destroy __P ((pop3_t *)); |
42 | extern int pop3_connect __P ((pop3_t, const char *, unsigned int)); | 43 | extern int pop3_connect __P ((pop3_t, const char *, unsigned int)); |
43 | extern int pop3_disconnect __P ((pop3_t)); | 44 | extern int pop3_disconnect __P ((pop3_t)); |
44 | 45 | ||
45 | extern int pop3_set_carrier __P ((pop3_t, stream_t)); | 46 | extern int pop3_set_carrier __P ((pop3_t, stream_t)); |
46 | extern int pop3_get_carrier __P ((pop3_t, stream_t *)); | 47 | extern int pop3_get_carrier __P ((pop3_t, stream_t *)); |
47 | 48 | ||
48 | extern int pop3_set_timeout __P ((pop3_t, int)); | 49 | extern int pop3_set_timeout __P ((pop3_t, int)); |
49 | extern int pop3_get_timeout __P ((pop3_t, int *)); | 50 | extern int pop3_get_timeout __P ((pop3_t, int *)); |
50 | 51 | ||
52 | extern int pop3_set_debug __P ((pop3_t, mu_debug_t)); | ||
53 | extern int pop3_get_debug __P ((pop3_t, mu_debug_t *)); | ||
54 | |||
51 | extern int pop3_apop __P ((pop3_t, const char *, const char *)); | 55 | extern int pop3_apop __P ((pop3_t, const char *, const char *)); |
52 | 56 | ||
53 | extern int pop3_capa __P ((pop3_t, iterator_t *)); | 57 | extern int pop3_capa __P ((pop3_t, iterator_t *)); | ... | ... |
... | @@ -5,6 +5,7 @@ pkginclude_HEADERS = \ | ... | @@ -5,6 +5,7 @@ pkginclude_HEADERS = \ |
5 | attribute.h \ | 5 | attribute.h \ |
6 | authority.h \ | 6 | authority.h \ |
7 | bstream.h \ | 7 | bstream.h \ |
8 | debug.h \ | ||
8 | envelope.h \ | 9 | envelope.h \ |
9 | folder.h \ | 10 | folder.h \ |
10 | fstream.h \ | 11 | fstream.h \ |
... | @@ -21,6 +22,7 @@ pkginclude_HEADERS = \ | ... | @@ -21,6 +22,7 @@ pkginclude_HEADERS = \ |
21 | observer.h \ | 22 | observer.h \ |
22 | pop3.h \ | 23 | pop3.h \ |
23 | refcount.h \ | 24 | refcount.h \ |
25 | sdebug.h \ | ||
24 | stream.h \ | 26 | stream.h \ |
25 | tcpstream.h \ | 27 | tcpstream.h \ |
26 | ticket.h \ | 28 | ticket.h \ | ... | ... |
mailbox2/include/mailutils/sys/debug.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_SYS_DEBUG_H | ||
19 | #define _MAILUTILS_SYS_DEBUG_H | ||
20 | |||
21 | #ifdef DMALLOC | ||
22 | #include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
25 | #include <mailutils/debug.h> | ||
26 | |||
27 | #ifdef __cplusplus | ||
28 | extern "C" { | ||
29 | #endif | ||
30 | |||
31 | #ifndef __P | ||
32 | # ifdef __STDC__ | ||
33 | # define __P(args) args | ||
34 | # else | ||
35 | # define __P(args) () | ||
36 | # endif | ||
37 | #endif /*__P */ | ||
38 | |||
39 | struct _mu_debug_vtable | ||
40 | { | ||
41 | int (*ref) __P ((mu_debug_t)); | ||
42 | void (*destroy) __P ((mu_debug_t *)); | ||
43 | |||
44 | int (*get_level) __P ((mu_debug_t, unsigned int *)); | ||
45 | int (*set_level) __P ((mu_debug_t, unsigned int)); | ||
46 | int (*printv) __P ((mu_debug_t, unsigned int, const char *, va_list)); | ||
47 | }; | ||
48 | |||
49 | struct _mu_debug | ||
50 | { | ||
51 | struct _mu_debug_vtable *vtable; | ||
52 | }; | ||
53 | |||
54 | #ifdef __cplusplus | ||
55 | } | ||
56 | #endif | ||
57 | |||
58 | #endif /* _MAILUTILS_SYS_DEBUG_H */ |
... | @@ -102,10 +102,13 @@ struct _pop3 | ... | @@ -102,10 +102,13 @@ struct _pop3 |
102 | 102 | ||
103 | enum pop3_state state; | 103 | enum pop3_state state; |
104 | stream_t carrier; /* TCP Connection. */ | 104 | stream_t carrier; /* TCP Connection. */ |
105 | mu_debug_t debug; /* Send the debug info. */ | ||
105 | }; | 106 | }; |
106 | 107 | ||
107 | extern int pop3_iterator_create __P ((pop3_t, iterator_t *)); | 108 | extern int pop3_iterator_create __P ((pop3_t, iterator_t *)); |
108 | extern int pop3_stream_create __P ((pop3_t, stream_t *)); | 109 | extern int pop3_stream_create __P ((pop3_t, stream_t *)); |
110 | extern int pop3_debug_cmd __P ((pop3_t)); | ||
111 | extern int pop3_debug_ack __P ((pop3_t)); | ||
109 | 112 | ||
110 | /* Check for non recoverable error. */ | 113 | /* Check for non recoverable error. */ |
111 | #define POP3_CHECK_EAGAIN(pop3, status) \ | 114 | #define POP3_CHECK_EAGAIN(pop3, status) \ | ... | ... |
mailbox2/include/mailutils/sys/sdebug.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_SYS_SDEBUG_H | ||
19 | #define _MAILUTILS_SYS_SDEBUG_H | ||
20 | |||
21 | #ifdef DMALLOC | ||
22 | #include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
25 | #include <mailutils/refcount.h> | ||
26 | #include <mailutils/sys/debug.h> | ||
27 | |||
28 | #ifdef __cplusplus | ||
29 | extern "C" { | ||
30 | #endif | ||
31 | |||
32 | #ifndef __P | ||
33 | # ifdef __STDC__ | ||
34 | # define __P(args) args | ||
35 | # else | ||
36 | # define __P(args) () | ||
37 | # endif | ||
38 | #endif /*__P */ | ||
39 | |||
40 | struct _sdebug | ||
41 | { | ||
42 | struct _mu_debug base; | ||
43 | mu_refcount_t refcount; | ||
44 | int level; | ||
45 | FILE *fp; | ||
46 | }; | ||
47 | |||
48 | #ifdef __cplusplus | ||
49 | } | ||
50 | #endif | ||
51 | |||
52 | #endif /* _MAILUTILS_SYS_SDEBUG_H */ |
... | @@ -13,6 +13,7 @@ libmailbox_la_SOURCES = \ | ... | @@ -13,6 +13,7 @@ libmailbox_la_SOURCES = \ |
13 | pop3_carrier.c \ | 13 | pop3_carrier.c \ |
14 | pop3_connect.c \ | 14 | pop3_connect.c \ |
15 | pop3_create.c \ | 15 | pop3_create.c \ |
16 | pop3_debug.c \ | ||
16 | pop3_dele.c \ | 17 | pop3_dele.c \ |
17 | pop3_destroy.c \ | 18 | pop3_destroy.c \ |
18 | pop3_disconnect.c \ | 19 | pop3_disconnect.c \ | ... | ... |
... | @@ -64,6 +64,7 @@ pop3_apop (pop3_t pop3, const char *user, const char *secret) | ... | @@ -64,6 +64,7 @@ pop3_apop (pop3_t pop3, const char *user, const char *secret) |
64 | 64 | ||
65 | status = pop3_writeline (pop3, "APOP %s %s\r\n", user, digest); | 65 | status = pop3_writeline (pop3, "APOP %s %s\r\n", user, digest); |
66 | POP3_CHECK_ERROR (pop3, status); | 66 | POP3_CHECK_ERROR (pop3, status); |
67 | pop3_debug_cmd (pop3); | ||
67 | pop3->state = POP3_APOP; | 68 | pop3->state = POP3_APOP; |
68 | } | 69 | } |
69 | 70 | ||
... | @@ -76,6 +77,7 @@ pop3_apop (pop3_t pop3, const char *user, const char *secret) | ... | @@ -76,6 +77,7 @@ pop3_apop (pop3_t pop3, const char *user, const char *secret) |
76 | case POP3_APOP_ACK: | 77 | case POP3_APOP_ACK: |
77 | status = pop3_response (pop3, NULL, 0, NULL); | 78 | status = pop3_response (pop3, NULL, 0, NULL); |
78 | POP3_CHECK_EAGAIN (pop3, status); | 79 | POP3_CHECK_EAGAIN (pop3, status); |
80 | pop3_debug_ack (pop3); | ||
79 | POP3_CHECK_OK (pop3); | 81 | POP3_CHECK_OK (pop3); |
80 | pop3->state = POP3_NO_STATE; | 82 | pop3->state = POP3_NO_STATE; |
81 | break; | 83 | break; | ... | ... |
... | @@ -37,6 +37,7 @@ pop3_capa (pop3_t pop3, iterator_t *piterator) | ... | @@ -37,6 +37,7 @@ pop3_capa (pop3_t pop3, iterator_t *piterator) |
37 | case POP3_NO_STATE: | 37 | case POP3_NO_STATE: |
38 | status = pop3_writeline (pop3, "CAPA\r\n"); | 38 | status = pop3_writeline (pop3, "CAPA\r\n"); |
39 | POP3_CHECK_ERROR (pop3, status); | 39 | POP3_CHECK_ERROR (pop3, status); |
40 | pop3_debug_cmd (pop3); | ||
40 | pop3->state = POP3_CAPA; | 41 | pop3->state = POP3_CAPA; |
41 | 42 | ||
42 | case POP3_CAPA: | 43 | case POP3_CAPA: |
... | @@ -48,6 +49,7 @@ pop3_capa (pop3_t pop3, iterator_t *piterator) | ... | @@ -48,6 +49,7 @@ pop3_capa (pop3_t pop3, iterator_t *piterator) |
48 | case POP3_CAPA_ACK: | 49 | case POP3_CAPA_ACK: |
49 | status = pop3_response (pop3, NULL, 0, NULL); | 50 | status = pop3_response (pop3, NULL, 0, NULL); |
50 | POP3_CHECK_EAGAIN (pop3, status); | 51 | POP3_CHECK_EAGAIN (pop3, status); |
52 | pop3_debug_ack (pop3); | ||
51 | POP3_CHECK_OK (pop3); | 53 | POP3_CHECK_OK (pop3); |
52 | pop3->state = POP3_CAPA_RX; | 54 | pop3->state = POP3_CAPA_RX; |
53 | 55 | ... | ... |
... | @@ -92,6 +92,7 @@ pop3_connect (pop3_t pop3, const char *host, unsigned int port) | ... | @@ -92,6 +92,7 @@ pop3_connect (pop3_t pop3, const char *host, unsigned int port) |
92 | char *right, *left; | 92 | char *right, *left; |
93 | status = pop3_response (pop3, NULL, 0, &len); | 93 | status = pop3_response (pop3, NULL, 0, &len); |
94 | POP3_CHECK_EAGAIN (pop3, status); | 94 | POP3_CHECK_EAGAIN (pop3, status); |
95 | pop3_debug_ack (pop3); | ||
95 | if (strncasecmp (pop3->ack.buf, "+OK", 3) != 0) | 96 | if (strncasecmp (pop3->ack.buf, "+OK", 3) != 0) |
96 | { | 97 | { |
97 | stream_close (pop3->carrier); | 98 | stream_close (pop3->carrier); | ... | ... |
mailbox2/pop3/pop3_debug.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #ifdef HAVE_STRING_H | ||
23 | # include <string.h> | ||
24 | #else | ||
25 | # include <strings.h> | ||
26 | #endif | ||
27 | |||
28 | #include <mailutils/sys/pop3.h> | ||
29 | |||
30 | int | ||
31 | pop3_get_debug (pop3_t pop3, mu_debug_t *pdebug) | ||
32 | { | ||
33 | if (pop3 == NULL || pdebug == NULL) | ||
34 | return MU_ERROR_INVALID_PARAMETER; | ||
35 | |||
36 | |||
37 | if (pop3->debug == NULL) | ||
38 | { | ||
39 | int status = mu_debug_stdio_create (&pop3->debug, stderr); | ||
40 | if (status != 0) | ||
41 | return status; | ||
42 | } | ||
43 | *pdebug = pop3->debug; | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | int | ||
48 | pop3_set_debug (pop3_t pop3, mu_debug_t debug) | ||
49 | { | ||
50 | if (pop3 == NULL) | ||
51 | return MU_ERROR_INVALID_PARAMETER; | ||
52 | |||
53 | if (pop3->debug) | ||
54 | mu_debug_destroy (&pop3->debug); | ||
55 | pop3->debug = debug; | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | int | ||
60 | pop3_debug_cmd (pop3_t pop3) | ||
61 | { | ||
62 | if (pop3->debug) | ||
63 | { | ||
64 | mu_debug_print (pop3->debug, MU_DEBUG_PROT, pop3->io.buf); | ||
65 | } | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | int | ||
70 | pop3_debug_ack (pop3_t pop3) | ||
71 | { | ||
72 | if (pop3->debug) | ||
73 | { | ||
74 | mu_debug_print (pop3->debug, MU_DEBUG_PROT, pop3->ack.buf); | ||
75 | mu_debug_print (pop3->debug, MU_DEBUG_PROT, "\n"); | ||
76 | } | ||
77 | return 0; | ||
78 | } |
... | @@ -39,6 +39,7 @@ pop3_dele (pop3_t pop3, unsigned msgno) | ... | @@ -39,6 +39,7 @@ pop3_dele (pop3_t pop3, unsigned msgno) |
39 | case POP3_NO_STATE: | 39 | case POP3_NO_STATE: |
40 | status = pop3_writeline (pop3, "DELE %d\r\n", msgno); | 40 | status = pop3_writeline (pop3, "DELE %d\r\n", msgno); |
41 | POP3_CHECK_ERROR (pop3, status); | 41 | POP3_CHECK_ERROR (pop3, status); |
42 | pop3_debug_cmd (pop3); | ||
42 | pop3->state = POP3_DELE; | 43 | pop3->state = POP3_DELE; |
43 | 44 | ||
44 | case POP3_DELE: | 45 | case POP3_DELE: |
... | @@ -50,6 +51,7 @@ pop3_dele (pop3_t pop3, unsigned msgno) | ... | @@ -50,6 +51,7 @@ pop3_dele (pop3_t pop3, unsigned msgno) |
50 | case POP3_DELE_ACK: | 51 | case POP3_DELE_ACK: |
51 | status = pop3_response (pop3, NULL, 0, NULL); | 52 | status = pop3_response (pop3, NULL, 0, NULL); |
52 | POP3_CHECK_EAGAIN (pop3, status); | 53 | POP3_CHECK_EAGAIN (pop3, status); |
54 | pop3_debug_ack (pop3); | ||
53 | POP3_CHECK_OK (pop3); | 55 | POP3_CHECK_OK (pop3); |
54 | pop3->state = POP3_NO_STATE; | 56 | pop3->state = POP3_NO_STATE; |
55 | break; | 57 | break; | ... | ... |
... | @@ -41,6 +41,9 @@ pop3_destroy (pop3_t *ppop3) | ... | @@ -41,6 +41,9 @@ pop3_destroy (pop3_t *ppop3) |
41 | if (pop3->carrier) | 41 | if (pop3->carrier) |
42 | stream_destroy (&pop3->carrier); | 42 | stream_destroy (&pop3->carrier); |
43 | 43 | ||
44 | if (pop3->debug) | ||
45 | mu_debug_destroy (&pop3->debug); | ||
46 | |||
44 | free (pop3); | 47 | free (pop3); |
45 | *ppop3 = NULL; | 48 | *ppop3 = NULL; |
46 | } | 49 | } | ... | ... |
... | @@ -43,6 +43,7 @@ pop3_list (pop3_t pop3, unsigned int msgno, size_t *psize) | ... | @@ -43,6 +43,7 @@ pop3_list (pop3_t pop3, unsigned int msgno, size_t *psize) |
43 | return MU_ERROR_INVALID_PARAMETER; | 43 | return MU_ERROR_INVALID_PARAMETER; |
44 | status = pop3_writeline (pop3, "LIST %d\r\n", msgno); | 44 | status = pop3_writeline (pop3, "LIST %d\r\n", msgno); |
45 | POP3_CHECK_ERROR (pop3, status); | 45 | POP3_CHECK_ERROR (pop3, status); |
46 | pop3_debug_cmd (pop3); | ||
46 | pop3->state = POP3_LIST; | 47 | pop3->state = POP3_LIST; |
47 | 48 | ||
48 | case POP3_LIST: | 49 | case POP3_LIST: |
... | @@ -53,6 +54,7 @@ pop3_list (pop3_t pop3, unsigned int msgno, size_t *psize) | ... | @@ -53,6 +54,7 @@ pop3_list (pop3_t pop3, unsigned int msgno, size_t *psize) |
53 | 54 | ||
54 | case POP3_LIST_ACK: | 55 | case POP3_LIST_ACK: |
55 | status = pop3_response (pop3, NULL, 0, NULL); | 56 | status = pop3_response (pop3, NULL, 0, NULL); |
57 | pop3_debug_ack (pop3); | ||
56 | POP3_CHECK_EAGAIN (pop3, status); | 58 | POP3_CHECK_EAGAIN (pop3, status); |
57 | POP3_CHECK_OK (pop3); | 59 | POP3_CHECK_OK (pop3); |
58 | pop3->state = POP3_NO_STATE; | 60 | pop3->state = POP3_NO_STATE; | ... | ... |
... | @@ -42,6 +42,7 @@ pop3_list_all (pop3_t pop3, iterator_t *piterator) | ... | @@ -42,6 +42,7 @@ pop3_list_all (pop3_t pop3, iterator_t *piterator) |
42 | case POP3_NO_STATE: | 42 | case POP3_NO_STATE: |
43 | status = pop3_writeline (pop3, "LIST\r\n"); | 43 | status = pop3_writeline (pop3, "LIST\r\n"); |
44 | POP3_CHECK_ERROR (pop3, status); | 44 | POP3_CHECK_ERROR (pop3, status); |
45 | pop3_debug_cmd (pop3); | ||
45 | pop3->state = POP3_LIST; | 46 | pop3->state = POP3_LIST; |
46 | 47 | ||
47 | case POP3_LIST: | 48 | case POP3_LIST: |
... | @@ -53,6 +54,7 @@ pop3_list_all (pop3_t pop3, iterator_t *piterator) | ... | @@ -53,6 +54,7 @@ pop3_list_all (pop3_t pop3, iterator_t *piterator) |
53 | case POP3_LIST_ACK: | 54 | case POP3_LIST_ACK: |
54 | status = pop3_response (pop3, NULL, 0, NULL); | 55 | status = pop3_response (pop3, NULL, 0, NULL); |
55 | POP3_CHECK_EAGAIN (pop3, status); | 56 | POP3_CHECK_EAGAIN (pop3, status); |
57 | pop3_debug_cmd (pop3); | ||
56 | POP3_CHECK_OK (pop3); | 58 | POP3_CHECK_OK (pop3); |
57 | pop3->state = POP3_LIST_RX; | 59 | pop3->state = POP3_LIST_RX; |
58 | 60 | ... | ... |
... | @@ -40,6 +40,7 @@ pop3_noop (pop3_t pop3) | ... | @@ -40,6 +40,7 @@ pop3_noop (pop3_t pop3) |
40 | case POP3_NO_STATE: | 40 | case POP3_NO_STATE: |
41 | status = pop3_writeline (pop3, "NOOP\r\n"); | 41 | status = pop3_writeline (pop3, "NOOP\r\n"); |
42 | POP3_CHECK_ERROR (pop3, status); | 42 | POP3_CHECK_ERROR (pop3, status); |
43 | pop3_debug_cmd (pop3); | ||
43 | pop3->state = POP3_NOOP; | 44 | pop3->state = POP3_NOOP; |
44 | 45 | ||
45 | case POP3_NOOP: | 46 | case POP3_NOOP: |
... | @@ -51,6 +52,7 @@ pop3_noop (pop3_t pop3) | ... | @@ -51,6 +52,7 @@ pop3_noop (pop3_t pop3) |
51 | case POP3_NOOP_ACK: | 52 | case POP3_NOOP_ACK: |
52 | status = pop3_response (pop3, NULL, 0, NULL); | 53 | status = pop3_response (pop3, NULL, 0, NULL); |
53 | POP3_CHECK_EAGAIN (pop3, status); | 54 | POP3_CHECK_EAGAIN (pop3, status); |
55 | pop3_debug_ack (pop3); | ||
54 | POP3_CHECK_OK (pop3); | 56 | POP3_CHECK_OK (pop3); |
55 | pop3->state = POP3_NO_STATE; | 57 | pop3->state = POP3_NO_STATE; |
56 | break; | 58 | break; | ... | ... |
... | @@ -40,6 +40,7 @@ pop3_pass (pop3_t pop3, const char *passwd) | ... | @@ -40,6 +40,7 @@ pop3_pass (pop3_t pop3, const char *passwd) |
40 | case POP3_NO_STATE: | 40 | case POP3_NO_STATE: |
41 | status = pop3_writeline (pop3, "PASS %s\r\n", passwd); | 41 | status = pop3_writeline (pop3, "PASS %s\r\n", passwd); |
42 | POP3_CHECK_ERROR (pop3, status); | 42 | POP3_CHECK_ERROR (pop3, status); |
43 | pop3_debug_cmd (pop3); | ||
43 | pop3->state = POP3_PASS; | 44 | pop3->state = POP3_PASS; |
44 | 45 | ||
45 | case POP3_PASS: | 46 | case POP3_PASS: |
... | @@ -51,6 +52,7 @@ pop3_pass (pop3_t pop3, const char *passwd) | ... | @@ -51,6 +52,7 @@ pop3_pass (pop3_t pop3, const char *passwd) |
51 | case POP3_PASS_ACK: | 52 | case POP3_PASS_ACK: |
52 | status = pop3_response (pop3, NULL, 0, NULL); | 53 | status = pop3_response (pop3, NULL, 0, NULL); |
53 | POP3_CHECK_EAGAIN (pop3, status); | 54 | POP3_CHECK_EAGAIN (pop3, status); |
55 | pop3_debug_ack (pop3); | ||
54 | POP3_CHECK_OK (pop3); | 56 | POP3_CHECK_OK (pop3); |
55 | pop3->state = POP3_NO_STATE; | 57 | pop3->state = POP3_NO_STATE; |
56 | break; | 58 | break; | ... | ... |
... | @@ -40,6 +40,7 @@ pop3_quit (pop3_t pop3) | ... | @@ -40,6 +40,7 @@ pop3_quit (pop3_t pop3) |
40 | case POP3_NO_STATE: | 40 | case POP3_NO_STATE: |
41 | status = pop3_writeline (pop3, "QUIT\r\n"); | 41 | status = pop3_writeline (pop3, "QUIT\r\n"); |
42 | POP3_CHECK_ERROR (pop3, status); | 42 | POP3_CHECK_ERROR (pop3, status); |
43 | pop3_debug_cmd (pop3); | ||
43 | pop3->state = POP3_QUIT; | 44 | pop3->state = POP3_QUIT; |
44 | 45 | ||
45 | case POP3_QUIT: | 46 | case POP3_QUIT: |
... | @@ -51,6 +52,7 @@ pop3_quit (pop3_t pop3) | ... | @@ -51,6 +52,7 @@ pop3_quit (pop3_t pop3) |
51 | case POP3_QUIT_ACK: | 52 | case POP3_QUIT_ACK: |
52 | status = pop3_response (pop3, NULL, 0, NULL); | 53 | status = pop3_response (pop3, NULL, 0, NULL); |
53 | POP3_CHECK_EAGAIN (pop3, status); | 54 | POP3_CHECK_EAGAIN (pop3, status); |
55 | pop3_debug_ack (pop3); | ||
54 | POP3_CHECK_OK (pop3); | 56 | POP3_CHECK_OK (pop3); |
55 | pop3->state = POP3_NO_STATE; | 57 | pop3->state = POP3_NO_STATE; |
56 | break; | 58 | break; | ... | ... |
... | @@ -40,6 +40,7 @@ pop3_retr (pop3_t pop3, unsigned int msgno, stream_t *pstream) | ... | @@ -40,6 +40,7 @@ pop3_retr (pop3_t pop3, unsigned int msgno, stream_t *pstream) |
40 | case POP3_NO_STATE: | 40 | case POP3_NO_STATE: |
41 | status = pop3_writeline (pop3, "RETR %d\r\n", msgno); | 41 | status = pop3_writeline (pop3, "RETR %d\r\n", msgno); |
42 | POP3_CHECK_ERROR (pop3, status); | 42 | POP3_CHECK_ERROR (pop3, status); |
43 | pop3_debug_cmd (pop3); | ||
43 | pop3->state = POP3_RETR; | 44 | pop3->state = POP3_RETR; |
44 | 45 | ||
45 | case POP3_RETR: | 46 | case POP3_RETR: |
... | @@ -51,6 +52,7 @@ pop3_retr (pop3_t pop3, unsigned int msgno, stream_t *pstream) | ... | @@ -51,6 +52,7 @@ pop3_retr (pop3_t pop3, unsigned int msgno, stream_t *pstream) |
51 | case POP3_RETR_ACK: | 52 | case POP3_RETR_ACK: |
52 | status = pop3_response (pop3, NULL, 0, NULL); | 53 | status = pop3_response (pop3, NULL, 0, NULL); |
53 | POP3_CHECK_EAGAIN (pop3, status); | 54 | POP3_CHECK_EAGAIN (pop3, status); |
55 | pop3_debug_ack (pop3); | ||
54 | POP3_CHECK_OK (pop3); | 56 | POP3_CHECK_OK (pop3); |
55 | pop3->state = POP3_RETR_RX; | 57 | pop3->state = POP3_RETR_RX; |
56 | 58 | ... | ... |
... | @@ -40,6 +40,7 @@ pop3_rset (pop3_t pop3) | ... | @@ -40,6 +40,7 @@ pop3_rset (pop3_t pop3) |
40 | case POP3_NO_STATE: | 40 | case POP3_NO_STATE: |
41 | status = pop3_writeline (pop3, "RSET\r\n"); | 41 | status = pop3_writeline (pop3, "RSET\r\n"); |
42 | POP3_CHECK_ERROR (pop3, status); | 42 | POP3_CHECK_ERROR (pop3, status); |
43 | pop3_debug_cmd (pop3); | ||
43 | pop3->state = POP3_RSET; | 44 | pop3->state = POP3_RSET; |
44 | 45 | ||
45 | case POP3_RSET: | 46 | case POP3_RSET: |
... | @@ -51,6 +52,7 @@ pop3_rset (pop3_t pop3) | ... | @@ -51,6 +52,7 @@ pop3_rset (pop3_t pop3) |
51 | case POP3_RSET_ACK: | 52 | case POP3_RSET_ACK: |
52 | status = pop3_response (pop3, NULL, 0, NULL); | 53 | status = pop3_response (pop3, NULL, 0, NULL); |
53 | POP3_CHECK_EAGAIN (pop3, status); | 54 | POP3_CHECK_EAGAIN (pop3, status); |
55 | pop3_debug_ack (pop3); | ||
54 | POP3_CHECK_OK (pop3); | 56 | POP3_CHECK_OK (pop3); |
55 | pop3->state = POP3_NO_STATE; | 57 | pop3->state = POP3_NO_STATE; |
56 | break; | 58 | break; | ... | ... |
... | @@ -41,6 +41,7 @@ pop3_stat (pop3_t pop3, unsigned *msg_count, size_t *size) | ... | @@ -41,6 +41,7 @@ pop3_stat (pop3_t pop3, unsigned *msg_count, size_t *size) |
41 | case POP3_NO_STATE: | 41 | case POP3_NO_STATE: |
42 | status = pop3_writeline (pop3, "STAT\r\n"); | 42 | status = pop3_writeline (pop3, "STAT\r\n"); |
43 | POP3_CHECK_ERROR (pop3, status); | 43 | POP3_CHECK_ERROR (pop3, status); |
44 | pop3_debug_cmd (pop3); | ||
44 | pop3->state = POP3_STAT; | 45 | pop3->state = POP3_STAT; |
45 | 46 | ||
46 | case POP3_STAT: | 47 | case POP3_STAT: |
... | @@ -52,6 +53,7 @@ pop3_stat (pop3_t pop3, unsigned *msg_count, size_t *size) | ... | @@ -52,6 +53,7 @@ pop3_stat (pop3_t pop3, unsigned *msg_count, size_t *size) |
52 | case POP3_STAT_ACK: | 53 | case POP3_STAT_ACK: |
53 | status = pop3_response (pop3, NULL, 0, NULL); | 54 | status = pop3_response (pop3, NULL, 0, NULL); |
54 | POP3_CHECK_EAGAIN (pop3, status); | 55 | POP3_CHECK_EAGAIN (pop3, status); |
56 | pop3_debug_ack (pop3); | ||
55 | POP3_CHECK_OK (pop3); | 57 | POP3_CHECK_OK (pop3); |
56 | pop3->state = POP3_NO_STATE; | 58 | pop3->state = POP3_NO_STATE; |
57 | 59 | ... | ... |
... | @@ -41,6 +41,7 @@ pop3_top (pop3_t pop3, unsigned msgno, unsigned int lines, stream_t *pstream) | ... | @@ -41,6 +41,7 @@ pop3_top (pop3_t pop3, unsigned msgno, unsigned int lines, stream_t *pstream) |
41 | case POP3_NO_STATE: | 41 | case POP3_NO_STATE: |
42 | status = pop3_writeline (pop3, "TOP %d %d\r\n", msgno, lines); | 42 | status = pop3_writeline (pop3, "TOP %d %d\r\n", msgno, lines); |
43 | POP3_CHECK_ERROR (pop3, status); | 43 | POP3_CHECK_ERROR (pop3, status); |
44 | pop3_debug_cmd (pop3); | ||
44 | pop3->state = POP3_TOP; | 45 | pop3->state = POP3_TOP; |
45 | 46 | ||
46 | case POP3_TOP: | 47 | case POP3_TOP: |
... | @@ -52,6 +53,7 @@ pop3_top (pop3_t pop3, unsigned msgno, unsigned int lines, stream_t *pstream) | ... | @@ -52,6 +53,7 @@ pop3_top (pop3_t pop3, unsigned msgno, unsigned int lines, stream_t *pstream) |
52 | case POP3_TOP_ACK: | 53 | case POP3_TOP_ACK: |
53 | status = pop3_response (pop3, NULL, 0, NULL); | 54 | status = pop3_response (pop3, NULL, 0, NULL); |
54 | POP3_CHECK_EAGAIN (pop3, status); | 55 | POP3_CHECK_EAGAIN (pop3, status); |
56 | pop3_debug_ack (pop3); | ||
55 | POP3_CHECK_OK (pop3); | 57 | POP3_CHECK_OK (pop3); |
56 | pop3->state = POP3_TOP_RX; | 58 | pop3->state = POP3_TOP_RX; |
57 | 59 | ... | ... |
... | @@ -41,6 +41,7 @@ pop3_uidl (pop3_t pop3, unsigned msgno, char **uidl) | ... | @@ -41,6 +41,7 @@ pop3_uidl (pop3_t pop3, unsigned msgno, char **uidl) |
41 | case POP3_NO_STATE: | 41 | case POP3_NO_STATE: |
42 | status = pop3_writeline (pop3, "UIDL %d\r\n", msgno); | 42 | status = pop3_writeline (pop3, "UIDL %d\r\n", msgno); |
43 | POP3_CHECK_ERROR (pop3, status); | 43 | POP3_CHECK_ERROR (pop3, status); |
44 | pop3_debug_cmd (pop3); | ||
44 | pop3->state = POP3_UIDL; | 45 | pop3->state = POP3_UIDL; |
45 | 46 | ||
46 | case POP3_UIDL: | 47 | case POP3_UIDL: |
... | @@ -52,6 +53,7 @@ pop3_uidl (pop3_t pop3, unsigned msgno, char **uidl) | ... | @@ -52,6 +53,7 @@ pop3_uidl (pop3_t pop3, unsigned msgno, char **uidl) |
52 | case POP3_UIDL_ACK: | 53 | case POP3_UIDL_ACK: |
53 | status = pop3_response (pop3, NULL, 0, NULL); | 54 | status = pop3_response (pop3, NULL, 0, NULL); |
54 | POP3_CHECK_EAGAIN (pop3, status); | 55 | POP3_CHECK_EAGAIN (pop3, status); |
56 | pop3_debug_ack (pop3); | ||
55 | POP3_CHECK_OK (pop3); | 57 | POP3_CHECK_OK (pop3); |
56 | pop3->state = POP3_NO_STATE; | 58 | pop3->state = POP3_NO_STATE; |
57 | 59 | ... | ... |
... | @@ -41,6 +41,7 @@ pop3_uidl_all (pop3_t pop3, iterator_t *piterator) | ... | @@ -41,6 +41,7 @@ pop3_uidl_all (pop3_t pop3, iterator_t *piterator) |
41 | case POP3_NO_STATE: | 41 | case POP3_NO_STATE: |
42 | status = pop3_writeline (pop3, "UIDL\r\n"); | 42 | status = pop3_writeline (pop3, "UIDL\r\n"); |
43 | POP3_CHECK_ERROR (pop3, status); | 43 | POP3_CHECK_ERROR (pop3, status); |
44 | pop3_debug_cmd (pop3); | ||
44 | pop3->state = POP3_UIDL; | 45 | pop3->state = POP3_UIDL; |
45 | 46 | ||
46 | case POP3_UIDL: | 47 | case POP3_UIDL: |
... | @@ -52,6 +53,7 @@ pop3_uidl_all (pop3_t pop3, iterator_t *piterator) | ... | @@ -52,6 +53,7 @@ pop3_uidl_all (pop3_t pop3, iterator_t *piterator) |
52 | case POP3_UIDL_ACK: | 53 | case POP3_UIDL_ACK: |
53 | status = pop3_response (pop3, NULL, 0, NULL); | 54 | status = pop3_response (pop3, NULL, 0, NULL); |
54 | POP3_CHECK_EAGAIN (pop3, status); | 55 | POP3_CHECK_EAGAIN (pop3, status); |
56 | pop3_debug_ack (pop3); | ||
55 | POP3_CHECK_OK (pop3); | 57 | POP3_CHECK_OK (pop3); |
56 | pop3->state = POP3_UIDL_RX; | 58 | pop3->state = POP3_UIDL_RX; |
57 | 59 | ... | ... |
... | @@ -40,6 +40,7 @@ pop3_user (pop3_t pop3, const char *user) | ... | @@ -40,6 +40,7 @@ pop3_user (pop3_t pop3, const char *user) |
40 | case POP3_NO_STATE: | 40 | case POP3_NO_STATE: |
41 | status = pop3_writeline (pop3, "USER %s\r\n", user); | 41 | status = pop3_writeline (pop3, "USER %s\r\n", user); |
42 | POP3_CHECK_ERROR (pop3, status); | 42 | POP3_CHECK_ERROR (pop3, status); |
43 | pop3_debug_cmd (pop3); | ||
43 | pop3->state = POP3_USER; | 44 | pop3->state = POP3_USER; |
44 | 45 | ||
45 | case POP3_USER: | 46 | case POP3_USER: |
... | @@ -51,6 +52,7 @@ pop3_user (pop3_t pop3, const char *user) | ... | @@ -51,6 +52,7 @@ pop3_user (pop3_t pop3, const char *user) |
51 | case POP3_USER_ACK: | 52 | case POP3_USER_ACK: |
52 | status = pop3_response (pop3, NULL, 0, NULL); | 53 | status = pop3_response (pop3, NULL, 0, NULL); |
53 | POP3_CHECK_EAGAIN (pop3, status); | 54 | POP3_CHECK_EAGAIN (pop3, status); |
55 | pop3_debug_ack (pop3); | ||
54 | POP3_CHECK_OK (pop3); | 56 | POP3_CHECK_OK (pop3); |
55 | pop3->state = POP3_NO_STATE; | 57 | pop3->state = POP3_NO_STATE; |
56 | break; | 58 | break; | ... | ... |
... | @@ -119,7 +119,11 @@ main (int argc, char **argv) | ... | @@ -119,7 +119,11 @@ main (int argc, char **argv) |
119 | char *line, *s; | 119 | char *line, *s; |
120 | 120 | ||
121 | (void)argc; | 121 | (void)argc; |
122 | progname = argv[0]; | 122 | progname = strrchr (argv[0], '/'); |
123 | if (progname) | ||
124 | progname++; | ||
125 | else | ||
126 | progname = argv[0]; | ||
123 | 127 | ||
124 | initialize_readline (); /* Bind our completer. */ | 128 | initialize_readline (); /* Bind our completer. */ |
125 | 129 | ||
... | @@ -300,6 +304,7 @@ command_generator (const char *text, int state) | ... | @@ -300,6 +304,7 @@ command_generator (const char *text, int state) |
300 | int | 304 | int |
301 | print_response () | 305 | print_response () |
302 | { | 306 | { |
307 | #if 0 | ||
303 | char response[1024]; | 308 | char response[1024]; |
304 | if (pop3) | 309 | if (pop3) |
305 | { | 310 | { |
... | @@ -308,6 +313,7 @@ print_response () | ... | @@ -308,6 +313,7 @@ print_response () |
308 | } | 313 | } |
309 | else | 314 | else |
310 | fprintf (stderr, "Not connected, try `connect' first\n"); | 315 | fprintf (stderr, "Not connected, try `connect' first\n"); |
316 | #endif | ||
311 | return 0; | 317 | return 0; |
312 | } | 318 | } |
313 | 319 | ||
... | @@ -624,6 +630,9 @@ com_connect (char *arg) | ... | @@ -624,6 +630,9 @@ com_connect (char *arg) |
624 | status = pop3_create (&pop3); | 630 | status = pop3_create (&pop3); |
625 | if (status == 0) | 631 | if (status == 0) |
626 | { | 632 | { |
633 | mu_debug_t debug; | ||
634 | pop3_get_debug (pop3, &debug); | ||
635 | mu_debug_set_level (debug, MU_DEBUG_PROT); | ||
627 | pop3_connect (pop3, host, port); | 636 | pop3_connect (pop3, host, port); |
628 | print_response (); | 637 | print_response (); |
629 | } | 638 | } | ... | ... |
mailbox2/sdebug.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <errno.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include <mailutils/sys/sdebug.h> | ||
28 | #include <mailutils/error.h> | ||
29 | |||
30 | static int | ||
31 | _sdebug_ref (mu_debug_t debug) | ||
32 | { | ||
33 | struct _sdebug *sdebug = (struct _sdebug *)debug; | ||
34 | return mu_refcount_inc (sdebug->refcount); | ||
35 | } | ||
36 | |||
37 | static void | ||
38 | _sdebug_destroy (mu_debug_t *pdebug) | ||
39 | { | ||
40 | if (pdebug && *pdebug) | ||
41 | { | ||
42 | struct _sdebug *sdebug = (struct _sdebug *)*pdebug; | ||
43 | if (mu_refcount_dec (sdebug->refcount) == 0) | ||
44 | { | ||
45 | mu_refcount_destroy (&sdebug->refcount); | ||
46 | free (sdebug); | ||
47 | } | ||
48 | *pdebug = NULL; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | static int | ||
53 | _sdebug_set_level (mu_debug_t debug, size_t level) | ||
54 | { | ||
55 | struct _sdebug *sdebug = (struct _sdebug *)debug; | ||
56 | sdebug->level = level; | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static int | ||
61 | _sdebug_get_level (mu_debug_t debug, size_t *plevel) | ||
62 | { | ||
63 | struct _sdebug *sdebug = (struct _sdebug *)debug; | ||
64 | if (plevel) | ||
65 | *plevel = sdebug->level; | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static int | ||
70 | _sdebug_printv (mu_debug_t debug, size_t level, const char *fmt, va_list ap) | ||
71 | { | ||
72 | struct _sdebug *sdebug = (struct _sdebug *)debug; | ||
73 | |||
74 | if (fmt == NULL) | ||
75 | return MU_ERROR_INVALID_PARAMETER; | ||
76 | |||
77 | if (!(sdebug->level & level)) | ||
78 | return 0; | ||
79 | |||
80 | vfprintf (sdebug->fp, fmt, ap); | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | struct _mu_debug_vtable _sdebug_vtable = | ||
85 | { | ||
86 | _sdebug_ref, | ||
87 | _sdebug_destroy, | ||
88 | |||
89 | _sdebug_get_level, | ||
90 | _sdebug_set_level, | ||
91 | _sdebug_printv | ||
92 | }; | ||
93 | |||
94 | int | ||
95 | mu_debug_stdio_create (mu_debug_t *pdebug, FILE *fp) | ||
96 | { | ||
97 | struct _sdebug *sdebug; | ||
98 | if (pdebug == NULL || fp == NULL) | ||
99 | return MU_ERROR_INVALID_PARAMETER; | ||
100 | sdebug = calloc (sizeof (*sdebug), 1); | ||
101 | if (sdebug == NULL) | ||
102 | return MU_ERROR_NO_MEMORY; | ||
103 | mu_refcount_create (&sdebug->refcount); | ||
104 | if (sdebug->refcount == NULL) | ||
105 | { | ||
106 | free (sdebug); | ||
107 | return MU_ERROR_NO_MEMORY; | ||
108 | } | ||
109 | sdebug->level = 0; | ||
110 | sdebug->fp = fp; | ||
111 | sdebug->base.vtable = &_sdebug_vtable; | ||
112 | *pdebug = &sdebug->base; | ||
113 | return 0; | ||
114 | } |
... | @@ -339,54 +339,70 @@ static int | ... | @@ -339,54 +339,70 @@ static int |
339 | _tcp_is_readready (stream_t stream, int timeout) | 339 | _tcp_is_readready (stream_t stream, int timeout) |
340 | { | 340 | { |
341 | struct _tcp_instance *tcp = (struct _tcp_instance *)stream; | 341 | struct _tcp_instance *tcp = (struct _tcp_instance *)stream; |
342 | int ready; | 342 | int ready = 0; |
343 | struct timeval tv; | ||
344 | fd_set fds; | ||
345 | 343 | ||
346 | FD_ZERO (&fds); | 344 | if (tcp->fd >= 0) |
347 | FD_SET (tcp->fd, &fds); | 345 | { |
346 | struct timeval tv; | ||
347 | fd_set fds; | ||
348 | FD_ZERO (&fds); | ||
349 | FD_SET (tcp->fd, &fds); | ||
348 | 350 | ||
349 | tv.tv_sec = timeout / 100; | 351 | tv.tv_sec = timeout / 100; |
350 | tv.tv_usec = (timeout % 1000) * 1000; | 352 | tv.tv_usec = (timeout % 1000) * 1000; |
351 | 353 | ||
352 | ready = select (tcp->fd + 1, &fds, NULL, NULL, (timeout == -1) ? NULL: &tv); | 354 | ready = select (tcp->fd + 1, &fds, NULL, NULL, |
353 | return (ready == -1) ? 0 : 1; | 355 | (timeout == -1) ? NULL: &tv); |
356 | ready = (ready == -1) ? 0 : 1; | ||
357 | } | ||
358 | return ready; | ||
354 | } | 359 | } |
355 | 360 | ||
356 | static int | 361 | static int |
357 | _tcp_is_writeready (stream_t stream, int timeout) | 362 | _tcp_is_writeready (stream_t stream, int timeout) |
358 | { | 363 | { |
359 | struct _tcp_instance *tcp = (struct _tcp_instance *)stream; | 364 | struct _tcp_instance *tcp = (struct _tcp_instance *)stream; |
360 | int ready; | 365 | int ready = 0; |
361 | struct timeval tv; | 366 | |
362 | fd_set fds; | 367 | if (tcp->fd >= 0) |
368 | { | ||
369 | struct timeval tv; | ||
370 | fd_set fds; | ||
363 | 371 | ||
364 | FD_ZERO (&fds); | 372 | FD_ZERO (&fds); |
365 | FD_SET (tcp->fd, &fds); | 373 | FD_SET (tcp->fd, &fds); |
366 | 374 | ||
367 | tv.tv_sec = timeout / 100; | 375 | tv.tv_sec = timeout / 100; |
368 | tv.tv_usec = (timeout % 1000) * 1000; | 376 | tv.tv_usec = (timeout % 1000) * 1000; |
369 | 377 | ||
370 | ready = select (tcp->fd + 1, NULL, &fds, NULL, (timeout == -1) ? NULL: &tv); | 378 | ready = select (tcp->fd + 1, NULL, &fds, NULL, |
371 | return (ready == -1) ? 0 : 1; | 379 | (timeout == -1) ? NULL: &tv); |
380 | ready = (ready == -1) ? 0 : 1; | ||
381 | } | ||
382 | return ready; | ||
372 | } | 383 | } |
373 | 384 | ||
374 | static int | 385 | static int |
375 | _tcp_is_exceptionpending (stream_t stream, int timeout) | 386 | _tcp_is_exceptionpending (stream_t stream, int timeout) |
376 | { | 387 | { |
377 | struct _tcp_instance *tcp = (struct _tcp_instance *)stream; | 388 | struct _tcp_instance *tcp = (struct _tcp_instance *)stream; |
378 | int ready; | 389 | int ready = 0; |
379 | struct timeval tv; | ||
380 | fd_set fds; | ||
381 | 390 | ||
382 | FD_ZERO (&fds); | 391 | if (tcp->fd >= 0) |
383 | FD_SET (tcp->fd, &fds); | 392 | { |
393 | struct timeval tv; | ||
394 | fd_set fds; | ||
395 | FD_ZERO (&fds); | ||
396 | FD_SET (tcp->fd, &fds); | ||
384 | 397 | ||
385 | tv.tv_sec = timeout / 100; | 398 | tv.tv_sec = timeout / 100; |
386 | tv.tv_usec = (timeout % 1000) * 1000; | 399 | tv.tv_usec = (timeout % 1000) * 1000; |
387 | 400 | ||
388 | ready = select (tcp->fd + 1, NULL, NULL, &fds, (timeout == -1) ? NULL: &tv); | 401 | ready = select (tcp->fd + 1, NULL, NULL, &fds, |
389 | return (ready == -1) ? 0 : 1; | 402 | (timeout == -1) ? NULL: &tv); |
403 | ready = (ready == -1) ? 0 : 1; | ||
404 | } | ||
405 | return ready; | ||
390 | } | 406 | } |
391 | 407 | ||
392 | static int | 408 | static int | ... | ... |
-
Please register or sign in to post a comment