Commit fee66fea fee66feabf133a4010dd219ad815d02085108131 by Alain Magloire

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;
1 parent cb48caaf
......@@ -16,6 +16,7 @@ libmailbox_la_SOURCES = \
authority.c \
bstream.c \
dattribute.c \
debug.c \
dotlock.c \
envelope.c \
fdstream.c \
......@@ -35,7 +36,8 @@ libmailbox_la_SOURCES = \
observer.c \
parse822.c \
pticket.c \
refcount.c \
refcount.c \
sdebug.c \
stream.c \
tcpstream.c \
ticket.c
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/sys/debug.h>
#include <mailutils/error.h>
int
mu_debug_ref (mu_debug_t debug)
{
if (debug == NULL || debug->vtable == NULL || debug->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return debug->vtable->ref (debug);
}
void
mu_debug_destroy (mu_debug_t *pdebug)
{
if (pdebug && *pdebug)
{
mu_debug_t debug = *pdebug;
if (debug->vtable && debug->vtable->destroy)
debug->vtable->destroy (pdebug);
*pdebug = NULL;
}
}
int
mu_debug_set_level (mu_debug_t debug, unsigned int level)
{
if (debug == NULL || debug->vtable == NULL
|| debug->vtable->set_level == NULL)
return MU_ERROR_NOT_SUPPORTED;
return debug->vtable->set_level (debug, level);
}
int
mu_debug_get_level (mu_debug_t debug, unsigned int *plevel)
{
if (debug == NULL || debug->vtable == NULL
|| debug->vtable->get_level == NULL)
return MU_ERROR_NOT_SUPPORTED;
return debug->vtable->get_level (debug, plevel);
}
int
mu_debug_print (mu_debug_t debug, unsigned int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_debug_printv (debug, level, fmt, ap);
va_end (ap);
return 0;
}
int
mu_debug_printv (mu_debug_t debug, unsigned int level, const char *fmt,
va_list ap)
{
if (debug == NULL || debug->vtable == NULL || debug->vtable->printv == NULL)
return MU_ERROR_NOT_SUPPORTED;
return debug->vtable->printv (debug, level, fmt, ap);
}
......@@ -267,54 +267,72 @@ static int
_fds_is_readready (stream_t stream, int timeout)
{
struct _fds *fds = (struct _fds *)stream;
int ready;
struct timeval tv;
fd_set fset;
int ready = 0;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
if (fds->fd >= 0)
{
struct timeval tv;
fd_set fset;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (fds->fd + 1, &fset, NULL, NULL, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
ready = select (fds->fd + 1, &fset, NULL, NULL,
(timeout == -1) ? NULL: &tv);
ready = (ready == -1) ? 0 : 1;
}
return ready;
}
static int
_fds_is_writeready (stream_t stream, int timeout)
{
struct _fds *fds = (struct _fds *)stream;
int ready;
struct timeval tv;
fd_set fset;
int ready = 0;
if (fds->fd)
{
struct timeval tv;
fd_set fset;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (fds->fd + 1, NULL, &fset, NULL, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
ready = select (fds->fd + 1, NULL, &fset, NULL,
(timeout == -1) ? NULL: &tv);
ready = (ready == -1) ? 0 : 1;
}
return ready;
}
static int
_fds_is_exceptionpending (stream_t stream, int timeout)
{
struct _fds *fds = (struct _fds *)stream;
int ready;
struct timeval tv;
fd_set fset;
int ready = 0;
if (fds->fd)
{
struct timeval tv;
fd_set fset;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (fds->fd + 1, NULL, NULL, &fset, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
ready = select (fds->fd + 1, NULL, NULL, &fset,
(timeout == -1) ? NULL: &tv);
ready = (ready == -1) ? 0 : 1;
}
return 0;
}
static int
......
......@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#ifndef __P
#ifdef __STDC__
......@@ -33,20 +34,22 @@
extern "C" {
#endif
struct _debug;
typedef struct _debug* mu_debug_t;
struct _mu_debug;
typedef struct _mu_debug* mu_debug_t;
#define MU_DEBUG_TRACE 1
#define MU_DEBUG_PROT 2
extern int mu_debug_ref __P ((mu_debug_t));
extern void mu_debug_destroy __P ((mu_debug_t *));
extern int mu_debug_set_level __P ((mu_debug_t, size_t level));
extern int mu_debug_get_level __P ((mu_debug_t, size_t *plevel));
extern int mu_debug_print __P ((mu_debug_t debug, size_t level,
extern int mu_debug_set_level __P ((mu_debug_t, unsigned int level));
extern int mu_debug_get_level __P ((mu_debug_t, unsigned int *plevel));
extern int mu_debug_print __P ((mu_debug_t debug, unsigned int level,
const char *format, ...));
extern int mu_debug_printv __P ((mu_debug_t debug, size_t level,
extern int mu_debug_printv __P ((mu_debug_t debug, unsigned int level,
const char *format, va_list argp));
extern int mu_debug_stderr_create __P ((mu_debug_t *));
extern int mu_debug_stdio_create __P ((mu_debug_t *, FILE *));
#ifdef __cplusplus
}
......
......@@ -19,6 +19,7 @@
#define _MAILUTILS_POP3_H
#include <mailutils/iterator.h>
#include <mailutils/debug.h>
#include <mailutils/stream.h>
#ifdef __cplusplus
......@@ -42,12 +43,15 @@ extern void pop3_destroy __P ((pop3_t *));
extern int pop3_connect __P ((pop3_t, const char *, unsigned int));
extern int pop3_disconnect __P ((pop3_t));
extern int pop3_set_carrier __P ((pop3_t, stream_t));
extern int pop3_get_carrier __P ((pop3_t, stream_t *));
extern int pop3_set_carrier __P ((pop3_t, stream_t));
extern int pop3_get_carrier __P ((pop3_t, stream_t *));
extern int pop3_set_timeout __P ((pop3_t, int));
extern int pop3_get_timeout __P ((pop3_t, int *));
extern int pop3_set_debug __P ((pop3_t, mu_debug_t));
extern int pop3_get_debug __P ((pop3_t, mu_debug_t *));
extern int pop3_apop __P ((pop3_t, const char *, const char *));
extern int pop3_capa __P ((pop3_t, iterator_t *));
......
......@@ -5,6 +5,7 @@ pkginclude_HEADERS = \
attribute.h \
authority.h \
bstream.h \
debug.h \
envelope.h \
folder.h \
fstream.h \
......@@ -21,6 +22,7 @@ pkginclude_HEADERS = \
observer.h \
pop3.h \
refcount.h \
sdebug.h \
stream.h \
tcpstream.h \
ticket.h \
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MAILUTILS_SYS_DEBUG_H
#define _MAILUTILS_SYS_DEBUG_H
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#include <mailutils/debug.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _mu_debug_vtable
{
int (*ref) __P ((mu_debug_t));
void (*destroy) __P ((mu_debug_t *));
int (*get_level) __P ((mu_debug_t, unsigned int *));
int (*set_level) __P ((mu_debug_t, unsigned int));
int (*printv) __P ((mu_debug_t, unsigned int, const char *, va_list));
};
struct _mu_debug
{
struct _mu_debug_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_DEBUG_H */
......@@ -102,10 +102,13 @@ struct _pop3
enum pop3_state state;
stream_t carrier; /* TCP Connection. */
mu_debug_t debug; /* Send the debug info. */
};
extern int pop3_iterator_create __P ((pop3_t, iterator_t *));
extern int pop3_stream_create __P ((pop3_t, stream_t *));
extern int pop3_debug_cmd __P ((pop3_t));
extern int pop3_debug_ack __P ((pop3_t));
/* Check for non recoverable error. */
#define POP3_CHECK_EAGAIN(pop3, status) \
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MAILUTILS_SYS_SDEBUG_H
#define _MAILUTILS_SYS_SDEBUG_H
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#include <mailutils/refcount.h>
#include <mailutils/sys/debug.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _sdebug
{
struct _mu_debug base;
mu_refcount_t refcount;
int level;
FILE *fp;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_SDEBUG_H */
......@@ -13,6 +13,7 @@ libmailbox_la_SOURCES = \
pop3_carrier.c \
pop3_connect.c \
pop3_create.c \
pop3_debug.c \
pop3_dele.c \
pop3_destroy.c \
pop3_disconnect.c \
......
......@@ -64,6 +64,7 @@ pop3_apop (pop3_t pop3, const char *user, const char *secret)
status = pop3_writeline (pop3, "APOP %s %s\r\n", user, digest);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_APOP;
}
......@@ -76,6 +77,7 @@ pop3_apop (pop3_t pop3, const char *user, const char *secret)
case POP3_APOP_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -37,6 +37,7 @@ pop3_capa (pop3_t pop3, iterator_t *piterator)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "CAPA\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_CAPA;
case POP3_CAPA:
......@@ -48,6 +49,7 @@ pop3_capa (pop3_t pop3, iterator_t *piterator)
case POP3_CAPA_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_CAPA_RX;
......
......@@ -92,6 +92,7 @@ pop3_connect (pop3_t pop3, const char *host, unsigned int port)
char *right, *left;
status = pop3_response (pop3, NULL, 0, &len);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
if (strncasecmp (pop3->ack.buf, "+OK", 3) != 0)
{
stream_close (pop3->carrier);
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#include <mailutils/sys/pop3.h>
int
pop3_get_debug (pop3_t pop3, mu_debug_t *pdebug)
{
if (pop3 == NULL || pdebug == NULL)
return MU_ERROR_INVALID_PARAMETER;
if (pop3->debug == NULL)
{
int status = mu_debug_stdio_create (&pop3->debug, stderr);
if (status != 0)
return status;
}
*pdebug = pop3->debug;
return 0;
}
int
pop3_set_debug (pop3_t pop3, mu_debug_t debug)
{
if (pop3 == NULL)
return MU_ERROR_INVALID_PARAMETER;
if (pop3->debug)
mu_debug_destroy (&pop3->debug);
pop3->debug = debug;
return 0;
}
int
pop3_debug_cmd (pop3_t pop3)
{
if (pop3->debug)
{
mu_debug_print (pop3->debug, MU_DEBUG_PROT, pop3->io.buf);
}
return 0;
}
int
pop3_debug_ack (pop3_t pop3)
{
if (pop3->debug)
{
mu_debug_print (pop3->debug, MU_DEBUG_PROT, pop3->ack.buf);
mu_debug_print (pop3->debug, MU_DEBUG_PROT, "\n");
}
return 0;
}
......@@ -39,6 +39,7 @@ pop3_dele (pop3_t pop3, unsigned msgno)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "DELE %d\r\n", msgno);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_DELE;
case POP3_DELE:
......@@ -50,6 +51,7 @@ pop3_dele (pop3_t pop3, unsigned msgno)
case POP3_DELE_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -41,6 +41,9 @@ pop3_destroy (pop3_t *ppop3)
if (pop3->carrier)
stream_destroy (&pop3->carrier);
if (pop3->debug)
mu_debug_destroy (&pop3->debug);
free (pop3);
*ppop3 = NULL;
}
......
......@@ -43,6 +43,7 @@ pop3_list (pop3_t pop3, unsigned int msgno, size_t *psize)
return MU_ERROR_INVALID_PARAMETER;
status = pop3_writeline (pop3, "LIST %d\r\n", msgno);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_LIST;
case POP3_LIST:
......@@ -53,6 +54,7 @@ pop3_list (pop3_t pop3, unsigned int msgno, size_t *psize)
case POP3_LIST_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
pop3_debug_ack (pop3);
POP3_CHECK_EAGAIN (pop3, status);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
......
......@@ -42,6 +42,7 @@ pop3_list_all (pop3_t pop3, iterator_t *piterator)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "LIST\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_LIST;
case POP3_LIST:
......@@ -53,6 +54,7 @@ pop3_list_all (pop3_t pop3, iterator_t *piterator)
case POP3_LIST_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_cmd (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_LIST_RX;
......
......@@ -40,6 +40,7 @@ pop3_noop (pop3_t pop3)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "NOOP\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_NOOP;
case POP3_NOOP:
......@@ -51,6 +52,7 @@ pop3_noop (pop3_t pop3)
case POP3_NOOP_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -40,6 +40,7 @@ pop3_pass (pop3_t pop3, const char *passwd)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "PASS %s\r\n", passwd);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_PASS;
case POP3_PASS:
......@@ -51,6 +52,7 @@ pop3_pass (pop3_t pop3, const char *passwd)
case POP3_PASS_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -40,6 +40,7 @@ pop3_quit (pop3_t pop3)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "QUIT\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_QUIT;
case POP3_QUIT:
......@@ -51,6 +52,7 @@ pop3_quit (pop3_t pop3)
case POP3_QUIT_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -40,6 +40,7 @@ pop3_retr (pop3_t pop3, unsigned int msgno, stream_t *pstream)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "RETR %d\r\n", msgno);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_RETR;
case POP3_RETR:
......@@ -51,6 +52,7 @@ pop3_retr (pop3_t pop3, unsigned int msgno, stream_t *pstream)
case POP3_RETR_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_RETR_RX;
......
......@@ -40,6 +40,7 @@ pop3_rset (pop3_t pop3)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "RSET\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_RSET;
case POP3_RSET:
......@@ -51,6 +52,7 @@ pop3_rset (pop3_t pop3)
case POP3_RSET_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -41,6 +41,7 @@ pop3_stat (pop3_t pop3, unsigned *msg_count, size_t *size)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "STAT\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_STAT;
case POP3_STAT:
......@@ -52,6 +53,7 @@ pop3_stat (pop3_t pop3, unsigned *msg_count, size_t *size)
case POP3_STAT_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
......
......@@ -41,6 +41,7 @@ pop3_top (pop3_t pop3, unsigned msgno, unsigned int lines, stream_t *pstream)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "TOP %d %d\r\n", msgno, lines);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_TOP;
case POP3_TOP:
......@@ -52,6 +53,7 @@ pop3_top (pop3_t pop3, unsigned msgno, unsigned int lines, stream_t *pstream)
case POP3_TOP_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_TOP_RX;
......
......@@ -41,6 +41,7 @@ pop3_uidl (pop3_t pop3, unsigned msgno, char **uidl)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "UIDL %d\r\n", msgno);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_UIDL;
case POP3_UIDL:
......@@ -52,6 +53,7 @@ pop3_uidl (pop3_t pop3, unsigned msgno, char **uidl)
case POP3_UIDL_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
......
......@@ -41,6 +41,7 @@ pop3_uidl_all (pop3_t pop3, iterator_t *piterator)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "UIDL\r\n");
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_UIDL;
case POP3_UIDL:
......@@ -52,6 +53,7 @@ pop3_uidl_all (pop3_t pop3, iterator_t *piterator)
case POP3_UIDL_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_UIDL_RX;
......
......@@ -40,6 +40,7 @@ pop3_user (pop3_t pop3, const char *user)
case POP3_NO_STATE:
status = pop3_writeline (pop3, "USER %s\r\n", user);
POP3_CHECK_ERROR (pop3, status);
pop3_debug_cmd (pop3);
pop3->state = POP3_USER;
case POP3_USER:
......@@ -51,6 +52,7 @@ pop3_user (pop3_t pop3, const char *user)
case POP3_USER_ACK:
status = pop3_response (pop3, NULL, 0, NULL);
POP3_CHECK_EAGAIN (pop3, status);
pop3_debug_ack (pop3);
POP3_CHECK_OK (pop3);
pop3->state = POP3_NO_STATE;
break;
......
......@@ -119,7 +119,11 @@ main (int argc, char **argv)
char *line, *s;
(void)argc;
progname = argv[0];
progname = strrchr (argv[0], '/');
if (progname)
progname++;
else
progname = argv[0];
initialize_readline (); /* Bind our completer. */
......@@ -300,6 +304,7 @@ command_generator (const char *text, int state)
int
print_response ()
{
#if 0
char response[1024];
if (pop3)
{
......@@ -308,6 +313,7 @@ print_response ()
}
else
fprintf (stderr, "Not connected, try `connect' first\n");
#endif
return 0;
}
......@@ -624,6 +630,9 @@ com_connect (char *arg)
status = pop3_create (&pop3);
if (status == 0)
{
mu_debug_t debug;
pop3_get_debug (pop3, &debug);
mu_debug_set_level (debug, MU_DEBUG_PROT);
pop3_connect (pop3, host, port);
print_response ();
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mailutils/sys/sdebug.h>
#include <mailutils/error.h>
static int
_sdebug_ref (mu_debug_t debug)
{
struct _sdebug *sdebug = (struct _sdebug *)debug;
return mu_refcount_inc (sdebug->refcount);
}
static void
_sdebug_destroy (mu_debug_t *pdebug)
{
if (pdebug && *pdebug)
{
struct _sdebug *sdebug = (struct _sdebug *)*pdebug;
if (mu_refcount_dec (sdebug->refcount) == 0)
{
mu_refcount_destroy (&sdebug->refcount);
free (sdebug);
}
*pdebug = NULL;
}
}
static int
_sdebug_set_level (mu_debug_t debug, size_t level)
{
struct _sdebug *sdebug = (struct _sdebug *)debug;
sdebug->level = level;
return 0;
}
static int
_sdebug_get_level (mu_debug_t debug, size_t *plevel)
{
struct _sdebug *sdebug = (struct _sdebug *)debug;
if (plevel)
*plevel = sdebug->level;
return 0;
}
static int
_sdebug_printv (mu_debug_t debug, size_t level, const char *fmt, va_list ap)
{
struct _sdebug *sdebug = (struct _sdebug *)debug;
if (fmt == NULL)
return MU_ERROR_INVALID_PARAMETER;
if (!(sdebug->level & level))
return 0;
vfprintf (sdebug->fp, fmt, ap);
return 0;
}
struct _mu_debug_vtable _sdebug_vtable =
{
_sdebug_ref,
_sdebug_destroy,
_sdebug_get_level,
_sdebug_set_level,
_sdebug_printv
};
int
mu_debug_stdio_create (mu_debug_t *pdebug, FILE *fp)
{
struct _sdebug *sdebug;
if (pdebug == NULL || fp == NULL)
return MU_ERROR_INVALID_PARAMETER;
sdebug = calloc (sizeof (*sdebug), 1);
if (sdebug == NULL)
return MU_ERROR_NO_MEMORY;
mu_refcount_create (&sdebug->refcount);
if (sdebug->refcount == NULL)
{
free (sdebug);
return MU_ERROR_NO_MEMORY;
}
sdebug->level = 0;
sdebug->fp = fp;
sdebug->base.vtable = &_sdebug_vtable;
*pdebug = &sdebug->base;
return 0;
}
......@@ -339,54 +339,70 @@ static int
_tcp_is_readready (stream_t stream, int timeout)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int ready;
struct timeval tv;
fd_set fds;
int ready = 0;
FD_ZERO (&fds);
FD_SET (tcp->fd, &fds);
if (tcp->fd >= 0)
{
struct timeval tv;
fd_set fds;
FD_ZERO (&fds);
FD_SET (tcp->fd, &fds);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (tcp->fd + 1, &fds, NULL, NULL, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
ready = select (tcp->fd + 1, &fds, NULL, NULL,
(timeout == -1) ? NULL: &tv);
ready = (ready == -1) ? 0 : 1;
}
return ready;
}
static int
_tcp_is_writeready (stream_t stream, int timeout)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int ready;
struct timeval tv;
fd_set fds;
int ready = 0;
if (tcp->fd >= 0)
{
struct timeval tv;
fd_set fds;
FD_ZERO (&fds);
FD_SET (tcp->fd, &fds);
FD_ZERO (&fds);
FD_SET (tcp->fd, &fds);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (tcp->fd + 1, NULL, &fds, NULL, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
ready = select (tcp->fd + 1, NULL, &fds, NULL,
(timeout == -1) ? NULL: &tv);
ready = (ready == -1) ? 0 : 1;
}
return ready;
}
static int
_tcp_is_exceptionpending (stream_t stream, int timeout)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int ready;
struct timeval tv;
fd_set fds;
int ready = 0;
FD_ZERO (&fds);
FD_SET (tcp->fd, &fds);
if (tcp->fd >= 0)
{
struct timeval tv;
fd_set fds;
FD_ZERO (&fds);
FD_SET (tcp->fd, &fds);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (tcp->fd + 1, NULL, NULL, &fds, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
ready = select (tcp->fd + 1, NULL, NULL, &fds,
(timeout == -1) ? NULL: &tv);
ready = (ready == -1) ? 0 : 1;
}
return ready;
}
static int
......