Commit 8ddbdeb8 8ddbdeb82af8a53849a66ada6faf33acfe0afeb1 by Alain Magloire

Implemetation of POP3 low level call.

1 parent b2313466
2001-06-09 Alain Magloire
* mailbox/tcp.c (_tcp_get_fd): Buglet, comparing fd against EINVAL
instead of -1.
* mailbox2/pop3/pop3_apop.c: New.
* mailbox2/pop3/pop3_capa.c: New.
* mailbox2/pop3/pop3_close.c: New.
* mailbox2/pop3/pop3_create.c: New.
* mailbox2/pop3/pop3_dele.c: New.
* mailbox2/pop3/pop3_destroy.c: New.
* mailbox2/pop3/pop3_iterator.c: New.
* mailbox2/pop3/pop3_list.c: New.
* mailbox2/pop3/pop3_lista.c: New.
* mailbox2/pop3/pop3_noop.c: New.
* mailbox2/pop3/pop3_open.c: New.
* mailbox2/pop3/pop3_pass.c: New.
* mailbox2/pop3/pop3_quit.c: New.
* mailbox2/pop3/pop3_readline.c: New.
* mailbox2/pop3/pop3_response.c: New.
* mailbox2/pop3/pop3_retr.c: New.
* mailbox2/pop3/pop3_rset.c: New.
* mailbox2/pop3/pop3_sendline.c: New.
* mailbox2/pop3/pop3_stat.c: New.
* mailbox2/pop3/pop3_stream.c: New.
* mailbox2/pop3/pop3_timeout.c: New.
* mailbox2/pop3/pop3_top.c: New.
* mailbox2/pop3/pop3_uidl.c: New.
* mailbox2/pop3/pop3_uidla.c: New.
* mailbox2/pop3/pop3_user.c: New.
* mailbox2/tcp.c: New.
* mailbox2/iterator.c: New.
* mailbox2/stream.c: New.
* mailbox2/pop3/pop3client.c: Test case should probably somewhere else
in example/ perhaps?
2001-06-09 Alain Magloire
* mailbox2/*: First attempt to define the new API.
POP3 was implemented.
......
......@@ -126,7 +126,7 @@ static int _tcp_get_fd(stream_t stream, int *fd)
{
struct _tcp_instance *tcp = stream_get_owner(stream);
if ( fd == NULL || tcp->fd == EINVAL )
if ( fd == NULL || tcp->fd == -1 )
return EINVAL;
*fd = tcp->fd;
......
......@@ -44,5 +44,7 @@ pop3_close (pop3_t pop3)
free (pop3->timestamp);
pop3->timestamp = NULL;
}
return stream_close (pop3->stream);
if (pop3->stream)
return stream_close (pop3->stream);
return 0;
}
......
......@@ -55,6 +55,9 @@ pop3_getline (pop3_t pop3)
if (status != 0)
return status;
if (fd == -1)
return MU_ERROR_IO;
FD_ZERO (&rfds);
FD_SET (fd, &rfds);
tv.tv_sec = pop3->timeout;
......@@ -139,7 +142,7 @@ pop3_readline (pop3_t pop3, char *buffer, size_t buflen, size_t *pnread)
int status;
/* Do we need to fill up? Yes if no NL or the buffer is empty. */
if (pop3->io.nl == NULL || pop3->io.ptr == pop3->io.buf)
if (pop3->stream && (pop3->io.nl == NULL || pop3->io.ptr == pop3->io.buf))
{
status = pop3_getline (pop3);
if (status != 0)
......
......@@ -30,6 +30,9 @@ pop3_response (pop3_t pop3, char *buffer, size_t buflen, size_t *pnread)
size_t n = 0;
int status = 0;
if (pop3 == NULL)
return MU_ERROR_INVALID_PARAMETER;
if (!pop3->acknowledge)
{
size_t len = pop3->ack.len - (pop3->ack.ptr - pop3->ack.buf);
......@@ -37,6 +40,9 @@ pop3_response (pop3_t pop3, char *buffer, size_t buflen, size_t *pnread)
pop3->ack.ptr += n;
if (status != 0)
return status;
len = pop3->ack.ptr - pop3->ack.buf;
if (len && pop3->ack.buf[len - 1] == '\n')
pop3->ack.buf[len - 1] = '\0';
pop3->acknowledge = 1; /* Flag that we have the ack. */
pop3->ack.ptr = pop3->ack.buf;
}
......
......@@ -40,7 +40,7 @@ int
pop3_send (pop3_t pop3)
{
int status = 0;
if (pop3->io.ptr > pop3->io.buf)
if (pop3->stream && (pop3->io.ptr > pop3->io.buf))
{
size_t n = 0;
size_t len = pop3->io.ptr - pop3->io.buf;
......
......@@ -24,7 +24,7 @@
#include <errno.h>
#include <netdb.h>
#include <fcntl.h>
#define __USE_BSD
//#define __USE_BSD
#include <string.h>
#include <strings.h>
#include <sys/types.h>
......@@ -178,7 +178,7 @@ _tcp_get_fd (stream_t stream, int *fd)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
if (fd == NULL || tcp->fd == EINVAL)
if (fd == NULL || tcp->fd == -1)
return MU_ERROR_INVALID_PARAMETER;
*fd = tcp->fd;
......