Commit 1c94c0a9 1c94c0a932d228a27b7f08c728c807faa97042ee by Alain Magloire

attachment.c file_stream.c header.c io.c mailbox.c mbx_pop.c

 	mbx_unix.c mbx_unixscan.c message.c mime.c trans_stream.c
 	include/private/io0.h include/public/attribute.h
 	include/public/auth.h include/public/body.h
 	include/public/header.h include/public/io.h
 	include/public/locker.h include/public/mailbox.h
 	include/public/message.h

expunge can be call safely, whithout having to close/destroy the mailbox
it will readjust the message_t pointer.

mailbox_t uses stream to now.
1 parent 8e968a03
......@@ -32,7 +32,7 @@ struct _msg_info {
char *header_buf;
int header_len;
int header_size;
header_t hdr;
header_t hdr;
message_t msg;
int ioffset;
int ooffset;
......@@ -51,7 +51,7 @@ int message_create_attachment(const char *content_type, const char *encoding, co
int ret;
if ( ( ret = message_create(newmsg, NULL) ) == 0 ) {
if ( content_type == NULL )
if ( content_type == NULL )
content_type = "text/plain";
if ( encoding == NULL )
encoding = "7bit";
......@@ -61,21 +61,23 @@ int message_create_attachment(const char *content_type, const char *encoding, co
sprintf(header, MSG_HDR, content_type, encoding);
if ( ( ret = header_create( &hdr, header, strlen(header), *newmsg ) ) == 0 ) {
message_get_body(*newmsg, &body);
if ( ( ret = file_stream_create(&fstream, filename, MU_STREAM_READ) ) == 0 ) {
if ( ( ret = file_stream_create(&fstream) ) == 0 ) {
if ( ( ret = stream_open(fstream, filename, 0, MU_STREAM_READ) ) == 0 ) {
if ( ( ret = encoder_stream_create(&tstream, fstream, encoding) ) == 0 ) {
body_set_stream(body, tstream, *newmsg);
message_set_header(*newmsg, hdr, NULL);
}
}
}
}
}
}
if ( ret ) {
if ( *newmsg )
if ( *newmsg )
message_destroy(newmsg, NULL);
if ( hdr )
header_destroy(&hdr, NULL);
if ( fstream )
if ( fstream )
stream_destroy(&fstream, NULL);
}
return ret;
......@@ -87,14 +89,14 @@ static int _attachment_setup(struct _msg_info **info, message_t msg, stream_t *s
int sfl, ret;
body_t body;
if ( ( ret = message_get_body(msg, &body) ) != 0 ||
( ret = body_get_stream(body, stream) ) != 0 )
if ( ( ret = message_get_body(msg, &body) ) != 0 ||
( ret = body_get_stream(body, stream) ) != 0 )
return ret;
stream_get_flags(*stream, &sfl);
if ( data == NULL && (sfl & MU_STREAM_NONBLOCK) )
return EINVAL;
if ( data )
*info = *data;
*info = *data;
if ( *info == NULL ) {
if ( ( *info = calloc(1, sizeof(struct _msg_info)) ) == NULL )
return ENOMEM;
......@@ -107,14 +109,14 @@ static int _attachment_setup(struct _msg_info **info, message_t msg, stream_t *s
}
static void _attachment_free(struct _msg_info *info, int free_message) {
if ( info->buf )
if ( info->buf )
free(info->buf);
if ( info->header_buf )
free(info->header_buf);
if ( free_message ) {
if ( info->msg )
message_destroy(&(info->msg), NULL);
else if ( info->hdr )
else if ( info->hdr )
header_destroy(&(info->hdr), NULL);
}
free(info);
......@@ -128,7 +130,7 @@ int message_save_attachment(message_t msg, const char *filename, void **data)
int ret;
size_t size;
char *content_encoding;
if ( msg == NULL || filename == NULL)
return EINVAL;
......@@ -142,10 +144,10 @@ int message_save_attachment(message_t msg, const char *filename, void **data)
}
if ( ret == 0 && ( ret = _attachment_setup( &info, msg, &stream, data) ) != 0 )
return ret;
if ( ret != EAGAIN && info )
_attachment_free(info, ret);
return ret;
return ret;
}
#if 0
......@@ -158,14 +160,14 @@ int message_encapsulate(message_t msg, message_t *newmsg, void **data)
if ( msg == NULL || newmsg == NULL)
return EINVAL;
if ( ( ret = message_create(&(info->msg), NULL) ) == 0 ) {
header = "Content-Type: message/rfc822\nContent-Transfer-Encoding: 7bit\n\n";
if ( ( ret = header_create( &(info->hdr), header, strlen(header), msg ) ) == 0 ) {
message_set_header(info->msg, info->hdr, NULL);
}
}
return ret;
return ret;
}
#endif
......@@ -183,7 +185,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
if ( msg == NULL || newmsg == NULL)
return EINVAL;
if ( (data == NULL || *data == NULL ) && ( ret = message_get_header(msg, &hdr) ) == 0 ) {
header_get_value(hdr, "Content-Type", NULL, 0, &size);
if ( size ) {
......@@ -218,7 +220,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
info->header_len += info->line_ndx;
memcpy(info->header_buf, info->line, info->line_ndx);
if ( info->line_ndx == 1 ) {
header_done = 1;
header_done = 1;
break;
}
info->line_ndx = 0;
......@@ -233,7 +235,7 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
}
if ( ret == 0 && info->msg == NULL ) {
if ( ( ret = message_create(&(info->msg), NULL) ) == 0)
if ( ( ret = header_create(&(info->hdr), info->header_buf, info->header_len, info->msg) ) == 0 )
if ( ( ret = header_create(&(info->hdr), info->header_buf, info->header_len, info->msg) ) == 0 )
ret = message_set_header(info->msg, hdr, NULL);
}
if ( ret == 0 ) {
......@@ -253,6 +255,6 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data)
}
if ( ret != EAGAIN && info )
_attachment_free(info, ret);
return ret;
return ret;
}
......
......@@ -21,6 +21,11 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <io0.h>
struct _file_stream
......@@ -44,35 +49,76 @@ _file_read (stream_t stream, char *optr, size_t osize,
off_t offset, size_t *nbytes)
{
struct _file_stream *fs = stream->owner;
size_t n;
if (fs->offset != offset)
{
fseek (fs->file, offset, SEEK_SET);
fs->offset = offset;
}
*nbytes = fread (optr, osize, 1, fs->file);
if (*nbytes == 0)
n = fread (optr, sizeof(char), osize, fs->file);
if (n == 0)
{
if (ferror(fs->file))
return errno;
}
else
fs->offset += *nbytes;
fs->offset += n;
if (nbytes)
*nbytes = n;
return 0;
}
static int
_file_readline (stream_t stream, char *optr, size_t osize,
off_t offset, size_t *nbytes)
{
struct _file_stream *fs = stream->owner;
size_t n = 0;
int err = 0;
if (fs->offset != offset)
{
fseek (fs->file, offset, SEEK_SET);
fs->offset = offset;
}
if (fgets (optr, osize, fs->file) != NULL)
{
char *tmp = optr;
while (*tmp) tmp++; /* strlen(optr) */
n = tmp - optr;
fs->offset += n;
}
else
{
if (ferror (fs->file))
err = errno;
}
if (nbytes)
*nbytes = n;
return err;
}
static int
_file_write (stream_t stream, const char *iptr, size_t isize,
off_t offset, size_t *nbytes)
{
struct _file_stream *fs = stream->owner;
size_t n;
if (fs->offset != offset)
{
fseek (fs->file, offset, SEEK_SET);
fs->offset = offset;
}
*nbytes = fwrite (iptr, isize, 1, fs->file);
n = fwrite (iptr, sizeof(char), isize, fs->file);
if (*nbytes == 0)
{
if (ferror (fs->file))
......@@ -80,47 +126,181 @@ _file_write (stream_t stream, const char *iptr, size_t isize,
}
else
fs->offset += *nbytes;
if (nbytes)
*nbytes = n;
return 0;
}
int
file_stream_create (stream_t *stream, const char *filename, int flags)
static int
_file_truncate (stream_t stream, off_t len)
{
struct _file_stream *fs;
struct _file_stream *fs = stream->owner;
if (ftruncate (fileno(fs->file), len) == -1)
return errno;
return 0;
}
static int
_file_size (stream_t stream, off_t *psize)
{
struct _file_stream *fs = stream->owner;
struct stat stbuf;
if (fstat(fileno(fs->file), &stbuf) == -1)
return errno;
if (psize)
*psize = stbuf.st_size;
return 0;
}
static int
_file_flush (stream_t stream)
{
struct _file_stream *fs = stream->owner;
return fflush (fs->file);
}
static int
_file_get_fd (stream_t stream, int *pfd)
{
struct _file_stream *fs = stream->owner;
if (pfd)
*pfd = fileno (fs->file);
return 0;
}
static int
_file_open (stream_t stream, const char *filename, int port, int flags)
{
struct _file_stream *fs = stream->owner;
int flg;
int fd;
const char *mode;
int ret;
if (stream == NULL || filename == NULL)
return EINVAL;
(void)port; /* shutup gcc */
/* map the flags to the system equivalent */
if (flags & MU_STREAM_WRITE)
flg = O_WRONLY;
else if (flags & MU_STREAM_RDWR)
flg = O_RDWR;
else /* default */
flg = O_RDONLY;
if ((fs = calloc(sizeof(struct _file_stream), 1)) == NULL)
return ENOMEM;
/* local folders should not block it is local disk ???
* We simply ignore the O_NONBLOCK flag
* But take care of the APPEND.
*/
if (flags & MU_STREAM_APPEND)
flg |= O_APPEND;
/* handle CREAT with care, not to follow symlinks */
if (flags & MU_STREAM_CREAT)
{
/* first see if the file already exists */
fd = open(filename, flg);
if (fd == -1)
{
/* oops bail out */
if (errno != ENOENT)
return errno;
/* Race condition here when creating the file ?? */
fd = open(filename, flg|O_CREAT|O_EXCL, 0600);
if (fd < 0)
return errno;
}
}
else
{
fd = open (filename, flg);
if (fd < 0)
return errno;
}
/* we have to make sure that We did not open
* a symlink. From Casper D. in bugtraq.
*/
if ((flg & MU_STREAM_CREAT) ||
(flg & MU_STREAM_RDWR) ||
(flg & MU_STREAM_WRITE))
{
struct stat fdbuf, filebuf;
if (flags & MU_STREAM_RDWR)
/* the next two stats should never fail */
if (fstat(fd, &fdbuf) == -1)
return errno;
if (lstat(filename, &filebuf) == -1)
return errno;
/* Now check that: file and fd reference the same file,
file only has one link, file is plain file */
if (fdbuf.st_dev != filebuf.st_dev ||
fdbuf.st_ino != filebuf.st_ino ||
fdbuf.st_nlink != 1 ||
filebuf.st_nlink != 1 ||
(fdbuf.st_mode & S_IFMT) != S_IFREG) {
fprintf(stderr,"%s must be a plain file with one link\n", filename);
return EINVAL;
}
}
/* we use FILE * object */
if (flags & MU_STREAM_APPEND)
mode = "a";
else if (flags & MU_STREAM_RDWR)
mode = "r+b";
else if (flags & MU_STREAM_READ)
mode = "rb";
else if (flags & MU_STREAM_WRITE)
mode = "wb";
else
return EINVAL;
else /* default readonly*/
mode = "rb";
if ((fs->file = fopen (filename, mode)) == NULL)
fs->file = fopen (filename, mode);
if (fs->file == NULL)
{
ret = errno;
int ret = errno;
free (fs);
return ret;
}
if ((ret = stream_create (stream, flags, fs)) != 0)
#if BUFSIZ <= 1024
{
char *iobuffer;
iobuffer = malloc (8192);
if (iobuffer != NULL)
if (setvbuf (file, iobuffer, _IOFBF, 8192) != 0)
free (iobuffer);
}
#endif
stream_set_flags (stream, flags |MU_STREAM_NO_CHECK, fs);
return 0;
}
int
file_stream_create (stream_t *stream)
{
struct _file_stream *fs;
int ret;
if (stream == NULL)
return EINVAL;
fs = calloc (1, sizeof (struct _file_stream));
if (fs == NULL)
return ENOMEM;
ret = stream_create (stream, MU_STREAM_NO_CHECK, fs);
if (ret != 0)
{
fclose (fs->file);
free (fs);
return ret;
}
stream_set_read(*stream, _file_read, fs );
stream_set_write(*stream, _file_write, fs );
stream_set_destroy(*stream, _file_destroy, fs );
stream_set_open (*stream, _file_open, fs);
stream_set_fd (*stream, _file_get_fd, fs);
stream_set_read (*stream, _file_read, fs);
stream_set_readline (*stream, _file_readline, fs);
stream_set_write (*stream, _file_write, fs);
stream_set_truncate (*stream, _file_truncate, fs);
stream_set_size (*stream, _file_size, fs);
stream_set_flush (*stream, _file_flush, fs);
stream_set_destroy (*stream, _file_destroy, fs);
return 0;
}
......
......@@ -273,6 +273,8 @@ header_get_value (header_t header, const char *name, char *buffer,
*buffer = '\0'; /* null terminated */
if (pn)
*pn = total;
if (total == 0)
return ENOENT;
return 0;
}
......@@ -386,13 +388,13 @@ header_read (stream_t is, char *buf, size_t buflen,
off_t off, size_t *pnread)
{
header_t header;
ssize_t len;
int len;
if (is == NULL || (header = (header_t)is->owner) == NULL)
return EINVAL;
len = header->blurb_len - off;
if ((header->blurb_len - off) > 0)
if (len > 0)
{
if (buf)
{
......
......@@ -37,11 +37,15 @@ struct _stream
void *owner;
int flags;
void (*_destroy) __P ((stream_t));
int (*_open) __P ((stream_t, const char *, int port, int flags));
int (*_open) __P ((stream_t, const char *, int port, int flags));
int (*_close) __P ((stream_t));
int (*_get_fd) __P ((stream_t, int *));
int (*_read) __P ((stream_t, char *, size_t, off_t, size_t *));
int (*_readline) __P ((stream_t, char *, size_t, off_t, size_t *));
int (*_write) __P ((stream_t, const char *, size_t, off_t, size_t *));
int (*_truncate) __P ((stream_t, off_t));
int (*_size) __P ((stream_t, off_t *));
int (*_flush) __P ((stream_t));
};
#ifdef __cplusplus
......
......@@ -35,42 +35,42 @@ extern "C" {
struct _attribute;
typedef struct _attribute * attribute_t;
extern int attribute_create __P ((attribute_t *));
extern void attribute_destroy __P ((attribute_t *));
extern int attribute_is_seen __P ((attribute_t));
extern int attribute_is_answered __P ((attribute_t));
extern int attribute_is_flagged __P ((attribute_t));
extern int attribute_is_deleted __P ((attribute_t));
extern int attribute_is_draft __P ((attribute_t));
extern int attribute_is_recent __P ((attribute_t));
extern int attribute_is_read __P ((attribute_t));
extern int attribute_set_seen __P ((attribute_t));
extern int attribute_set_answered __P ((attribute_t));
extern int attribute_set_flagged __P ((attribute_t));
extern int attribute_set_deleted __P ((attribute_t));
extern int attribute_set_draft __P ((attribute_t));
extern int attribute_set_recent __P ((attribute_t));
extern int attribute_set_read __P ((attribute_t));
extern int attribute_unset_seen __P ((attribute_t));
extern int attribute_create __P ((attribute_t *));
extern void attribute_destroy __P ((attribute_t *));
extern int attribute_is_seen __P ((attribute_t));
extern int attribute_is_answered __P ((attribute_t));
extern int attribute_is_flagged __P ((attribute_t));
extern int attribute_is_deleted __P ((attribute_t));
extern int attribute_is_draft __P ((attribute_t));
extern int attribute_is_recent __P ((attribute_t));
extern int attribute_is_read __P ((attribute_t));
extern int attribute_set_seen __P ((attribute_t));
extern int attribute_set_answered __P ((attribute_t));
extern int attribute_set_flagged __P ((attribute_t));
extern int attribute_set_deleted __P ((attribute_t));
extern int attribute_set_draft __P ((attribute_t));
extern int attribute_set_recent __P ((attribute_t));
extern int attribute_set_read __P ((attribute_t));
extern int attribute_unset_seen __P ((attribute_t));
extern int attribute_unset_answered __P ((attribute_t));
extern int attribute_unset_flagged __P ((attribute_t));
extern int attribute_unset_deleted __P ((attribute_t));
extern int attribute_unset_draft __P ((attribute_t));
extern int attribute_unset_recent __P ((attribute_t));
extern int attribute_unset_read __P ((attribute_t));
extern int attribute_unset_flagged __P ((attribute_t));
extern int attribute_unset_deleted __P ((attribute_t));
extern int attribute_unset_draft __P ((attribute_t));
extern int attribute_unset_recent __P ((attribute_t));
extern int attribute_unset_read __P ((attribute_t));
extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2));
extern int attribute_is_equal __P ((attribute_t att1, attribute_t att2));
extern int attribute_copy __P ((attribute_t dst,
attribute_t src));
extern int attribute_copy __P ((attribute_t dst,
attribute_t src));
extern int string_to_attribute __P ((const char *buf,
attribute_t *pattr));
extern int attribute_to_string __P ((attribute_t attr, char *buf,
size_t len, size_t *));
extern int string_to_attribute __P ((const char *buf,
attribute_t *pattr));
extern int attribute_to_string __P ((attribute_t attr, char *buf,
size_t len, size_t *));
#ifdef __cplusplus
}
......
......@@ -36,24 +36,24 @@ extern "C" {
struct _auth;
typedef struct _auth *auth_t;
extern int auth_create __P ((auth_t *, void *owner));
extern void auth_destroy __P ((auth_t *, void *owner));
extern int auth_create __P ((auth_t *, void *owner));
extern void auth_destroy __P ((auth_t *, void *owner));
extern int auth_prologue __P ((auth_t));
extern int auth_set_prologue __P ((auth_t auth,
int (*_prologue) __P ((auth_t)),
void *owner));
extern int auth_prologue __P ((auth_t));
extern int auth_set_prologue __P ((auth_t auth,
int (*_prologue) __P ((auth_t)),
void *owner));
extern int auth_authenticate __P ((auth_t, char **, char **));
extern int auth_authenticate __P ((auth_t, char **, char **));
extern int auth_set_authenticate __P ((auth_t auth,
int (*_authenticate)
__P ((auth_t, char **, char **)),
void *owner));
extern int auth_epilogue __P ((auth_t));
extern int auth_set_epilogue __P ((auth_t auth,
int (*_epilogue) __P ((auth_t)),
void *owner));
extern int auth_epilogue __P ((auth_t));
extern int auth_set_epilogue __P ((auth_t auth,
int (*_epilogue) __P ((auth_t)),
void *owner));
#ifdef _cplusplus
}
......
......@@ -46,14 +46,14 @@ extern int body_set_stream __P ((body_t, stream_t, void *owner));
extern int body_get_filename __P ((body_t, char *, size_t, size_t *));
extern int body_set_filename __P ((body_t, const char*));
extern int body_size __P ((body_t, size_t*));
extern int body_size __P ((body_t, size_t*));
extern int body_set_size __P ((body_t,
int (*_size) __P ((body_t, size_t*)),
void *owner));
extern int body_lines __P ((body_t, size_t *));
extern int body_set_lines __P ((body_t,
int (*_lines) __P ((body_t, size_t*)),
void *owner));
extern int body_lines __P ((body_t, size_t *));
extern int body_set_lines __P ((body_t,
int (*_lines) __P ((body_t, size_t*)),
void *owner));
#ifdef _cplusplus
}
......
......@@ -67,7 +67,7 @@ extern "C" {
struct _header;
typedef struct _header * header_t;
extern int header_create __P ((header_t *, const char *blurb,
extern int header_create __P ((header_t *, const char *blurb,
size_t ln, void *owner));
extern void header_destroy __P ((header_t *, void *owner));
......@@ -80,9 +80,9 @@ extern int header_entry_name __P ((header_t, size_t num, char *buf,
size_t buflen, size_t *total));
extern int header_entry_value __P ((header_t, size_t num, char *buf,
size_t buflen, size_t *total));
extern int header_get_stream __P ((header_t, stream_t *stream));
extern int header_size __P ((header_t, size_t *size));
extern int header_lines __P ((header_t, size_t *lines));
extern int header_get_stream __P ((header_t, stream_t *stream));
extern int header_size __P ((header_t, size_t *size));
extern int header_lines __P ((header_t, size_t *lines));
#ifdef _cplusplus
}
......
......@@ -44,52 +44,68 @@ typedef struct _stream *stream_t;
#define MU_STREAM_NONBLOCK 0x00000020
#define MU_STREAM_NO_CHECK 0x00000040
extern int stream_create __P ((stream_t *, int flags, void *owner));
extern void stream_destroy __P ((stream_t *, void *owner));
extern int stream_set_destroy __P ((stream_t, void (*_destroy) __P ((stream_t)),
void *owner));
extern int stream_open __P ((stream_t, const char *, int, int));
extern int stream_set_open __P ((stream_t,
int (*_open) __P ((stream_t, const char *,
int, int)),
void *owner));
extern int stream_close __P ((stream_t));
extern int stream_set_close __P ((stream_t, int (*_close) __P ((stream_t)),
void *owner));
extern int stream_get_fd __P ((stream_t , int *));
extern int stream_set_fd __P ((stream_t,
int (*_get_fd)(stream_t, int *),
void *owner));
extern int stream_read __P ((stream_t, char *, size_t, off_t, size_t *));
extern int stream_set_read __P ((stream_t,
int (*_read) __P ((stream_t, char *,
size_t, off_t, size_t *)),
void *owner));
extern int stream_write __P ((stream_t, const char *, size_t,
off_t, size_t *));
extern int stream_set_write __P ((stream_t,
int (*_write) __P ((stream_t, const char *,
size_t, off_t,
size_t *)),
void *owner));
extern int stream_get_flags __P ((stream_t, int *pflags));
extern int stream_set_flags __P ((stream_t, int flags, void *owner));
extern int stream_create __P ((stream_t *, int flags, void *owner));
extern void stream_destroy __P ((stream_t *, void *owner));
extern int stream_set_destroy __P ((stream_t, void (*_destroy)
__P ((stream_t)), void *owner));
extern int stream_open __P ((stream_t, const char *, int, int));
extern int stream_set_open __P ((stream_t, int (*_open)
__P ((stream_t, const char *, int, int)),
void *owner));
extern int stream_close __P ((stream_t));
extern int stream_set_close __P ((stream_t, int (*_close) __P ((stream_t)),
void *owner));
extern int stream_get_fd __P ((stream_t , int *));
extern int stream_set_fd __P ((stream_t, int (*_get_fd)(stream_t, int *),
void *owner));
extern int stream_read __P ((stream_t, char *, size_t,
off_t, size_t *));
extern int stream_set_read __P ((stream_t, int (*_read)
__P ((stream_t, char *, size_t,
off_t, size_t *)),
void *owner));
extern int stream_readline __P ((stream_t, char *, size_t,
off_t, size_t *));
extern int stream_set_readline __P ((stream_t, int (*_readline)
__P ((stream_t, char *, size_t,
off_t, size_t *)),
void *owner));
extern int stream_size __P ((stream_t, off_t *));
extern int stream_set_size __P ((stream_t, int (*_size)
__P ((stream_t, off_t *)), void *owner));
extern int stream_truncate __P ((stream_t, off_t));
extern int stream_set_truncate __P ((stream_t, int (*_truncate)
__P ((stream_t, off_t)), void *owner));
extern int stream_write __P ((stream_t, const char *, size_t,
off_t, size_t *));
extern int stream_set_write __P ((stream_t, int (*_write)
__P ((stream_t, const char *,
size_t, off_t, size_t *)),
void *owner));
extern int stream_flush __P ((stream_t));
extern int stream_set_flush __P ((stream_t, int (*_flush)
__P ((stream_t)), void *owner));
extern int stream_get_flags __P ((stream_t, int *pflags));
extern int stream_set_flags __P ((stream_t, int flags, void *owner));
/* misc */
extern int file_stream_create __P ((stream_t *stream, const char *filename,
int flags));
extern int file_stream_create __P ((stream_t *stream));
extern int encoder_stream_create __P ((stream_t *stream, stream_t iostream,
const char *encoding));
extern int decoder_stream_create __P ((stream_t *stream, stream_t iostream,
const char *encoding));
extern int tcp_stream_create __P ((stream_t *stream));
extern int tcp_stream_create __P ((stream_t *stream));
#ifdef __cplusplus
}
......
......@@ -35,9 +35,9 @@ extern "C" {
struct _locker;
typedef struct _locker *locker_t;
extern int locker_create __P ((locker_t *, char *filename,
size_t len, int flags));
extern void locker_destroy __P ((locker_t *));
extern int locker_create __P ((locker_t *, char *filename,
size_t len, int flags));
extern void locker_destroy __P ((locker_t *));
#define MU_LOCKER_RDLOCK 0
#define MU_LOCKER_WRLOCK 1
......
......@@ -47,6 +47,8 @@ typedef struct _mailbox *mailbox_t;
extern int mailbox_create __P ((mailbox_t *, const char *, int id));
extern void mailbox_destroy __P ((mailbox_t *));
extern int mailbox_create_default __P ((mailbox_t *, const char *));
/* flags for mailbox_open () */
#define MU_MAILBOX_RDONLY MU_STREAM_READ
#define MU_MAILBOX_WRONLY MU_STREAM_WRITE
......@@ -55,35 +57,35 @@ extern void mailbox_destroy __P ((mailbox_t *));
#define MU_MAILBOX_CREAT MU_STREAM_CREAT
#define MU_MAILBOX_NONBLOCK MU_STREAM_NONBLOCK
extern int mailbox_open __P ((mailbox_t, int flag));
extern int mailbox_close __P ((mailbox_t));
extern int mailbox_open __P ((mailbox_t, int flag));
extern int mailbox_close __P ((mailbox_t));
/* messages */
extern int mailbox_get_message __P ((mailbox_t, size_t msgno, message_t *msg));
extern int mailbox_append_message __P ((mailbox_t, message_t msg));
extern int mailbox_messages_count __P ((mailbox_t, size_t *num));
extern int mailbox_expunge __P ((mailbox_t));
extern int mailbox_expunge __P ((mailbox_t));
/* stream settings */
extern int mailbox_get_stream __P ((mailbox_t, stream_t *pstream));
extern int mailbox_set_stream __P ((mailbox_t, stream_t stream));
extern int mailbox_get_stream __P ((mailbox_t, stream_t *pstream));
extern int mailbox_set_stream __P ((mailbox_t, stream_t stream));
/* Lock settings */
extern int mailbox_get_locker __P ((mailbox_t, locker_t *locker));
extern int mailbox_set_locker __P ((mailbox_t, locker_t locker));
extern int mailbox_get_locker __P ((mailbox_t, locker_t *locker));
extern int mailbox_set_locker __P ((mailbox_t, locker_t locker));
/* Authentication */
extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth));
extern int mailbox_set_auth __P ((mailbox_t, auth_t auth));
extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth));
extern int mailbox_set_auth __P ((mailbox_t, auth_t auth));
/* update and scanning*/
extern int mailbox_is_updated __P ((mailbox_t));
extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count));
extern int mailbox_is_updated __P ((mailbox_t));
extern int mailbox_scan __P ((mailbox_t, size_t msgno, size_t *count));
/* mailbox size ? */
extern int mailbox_size __P ((mailbox_t, off_t *size));
extern int mailbox_size __P ((mailbox_t, off_t *size));
extern int mailbox_get_url __P ((mailbox_t, url_t *));
extern int mailbox_get_url __P ((mailbox_t, url_t *));
/* events */
#define MU_EVT_MBX_DESTROY 1
......@@ -96,6 +98,7 @@ extern int mailbox_register __P ((mailbox_t mbox, size_t type,
void *arg));
extern int mailbox_deregister __P ((mailbox_t mbox, void *action));
#ifdef __cplusplus
}
#endif
......
......@@ -43,10 +43,6 @@ typedef struct _message *message_t;
/* A message is considered to be a container for:
* header_t, body_t, and its attribute_t.
* The notion of body_t is not visible/exported, since
* they are alway tied to a floating message, there was no
* need to create yet another object, getting the {i,o}stream_t
* was enough.
*/
extern int message_create __P ((message_t *, void *owner));
......@@ -71,20 +67,26 @@ extern int message_set_from __P ((message_t,
size_t, size_t *)),
void *owner));
extern int message_received __P ((message_t, char *, size_t, size_t *));
extern int message_set_received __P ((message_t,
int (*_received) __P ((message_t,
char *, size_t,
size_t *)),
void *owner));
extern int message_set_received __P ((message_t, int (*_received)
__P ((message_t, char *, size_t,
size_t *)), void *owner));
extern int message_get_attribute __P ((message_t, attribute_t *));
extern int message_set_attribute __P ((message_t, attribute_t, void *owner));
extern int message_get_num_parts __P ((message_t, size_t *nparts));
extern int message_set_get_num_parts __P ((message_t, size_t *nparts));
extern int message_get_part __P ((message_t, size_t part, message_t *msg));
extern int message_set_get_part __P ((message_t, size_t part, message_t *msg));
extern int message_add_part __P ((message_t, message_t msg));
extern int message_set_add_part __P ((message_t, message_t msg));
/* events */
#define MU_EVT_MSG_DESTROY 32
extern int message_register __P ((message_t msg, size_t type,
int (*action) (size_t typ, void *arg),
void *arg));
extern int message_register __P ((message_t msg, size_t type, int (*action)
__P ((size_t typ, void *arg)), void *arg));
extern int message_deregister __P ((message_t msg, void *action));
/* misc functions */
......
......@@ -132,9 +132,7 @@ stream_set_read (stream_t stream, int (*_read)
{
if (stream == NULL)
return EINVAL;
if (owner == stream->owner &&
((stream->flags & MU_STREAM_READ) ||
(stream->flags & MU_STREAM_RDWR)))
if (owner == stream->owner)
{
stream->_read = _read;
return 0;
......@@ -143,16 +141,28 @@ stream_set_read (stream_t stream, int (*_read)
}
int
stream_set_readline (stream_t stream, int (*_readline)
(stream_t, char *, size_t, off_t, size_t *),
void *owner)
{
if (stream == NULL)
return EINVAL;
if (owner == stream->owner)
{
stream->_readline = _readline;
return 0;
}
return EACCES;
}
int
stream_set_write (stream_t stream, int (*_write)
__P ((stream_t, const char *, size_t, off_t, size_t *)),
void *owner)
{
if (stream == NULL)
return EINVAL;
if (stream->owner == owner &&
((stream->flags & MU_STREAM_WRITE) ||
(stream->flags & MU_STREAM_RDWR) ||
(stream->flags & MU_STREAM_APPEND)))
if (stream->owner == owner)
{
stream->_write = _write;
return 0;
......@@ -170,6 +180,46 @@ stream_read (stream_t is, char *buf, size_t count,
}
int
stream_readline (stream_t is, char *buf, size_t count,
off_t offset, size_t *pnread)
{
size_t n, nr = 0;
char c;
int status;
if (is == NULL)
return EINVAL;
if (is->_readline != NULL)
return is->_readline (is, buf, count, offset, pnread);
/* grossly inefficient hopefully they override this */
for (n = 1; n < count; n++)
{
status = stream_read (is, &c, 1, offset, &nr);
if (status != 0) /* error */
return status;
else if (nr == 1)
{
*buf++ = c;
offset++;
if (c == '\n') /* newline is stored like fgets() */
break;
}
else if (nr == 0)
{
if (n == 1) /* EOF, no data read */
n = 0;
break; /* EOF, some data was read */
}
}
*buf = '\0';
if (pnread)
*pnread = n;
return 0;
}
int
stream_write (stream_t os, const char *buf, size_t count,
off_t offset, size_t *pnwrite)
{
......@@ -205,3 +255,63 @@ stream_set_flags (stream_t stream, int fl, void *owner)
stream->flags = fl;
return 0;
}
int
stream_size (stream_t stream, off_t *psize)
{
if (stream == NULL || stream->_size == NULL)
return EINVAL;
return stream->_size (stream, psize);
}
int
stream_set_size (stream_t stream, int (*_size)(stream_t, off_t *), void *owner)
{
if (stream == NULL)
return EINVAL;
if (stream->owner != owner)
return EACCES;
stream->_size = _size;
return 0;
}
int
stream_truncate (stream_t stream, off_t len)
{
if (stream == NULL || stream->_truncate == NULL )
return EINVAL;
return stream->_truncate (stream, len);
}
int
stream_set_truncate (stream_t stream, int (*_truncate) (stream_t, off_t),
void *owner)
{
if (stream == NULL)
return EINVAL;
if (stream->owner != owner)
return EACCES;
stream->_truncate = _truncate;
return 0;
}
int
stream_flush (stream_t stream)
{
if (stream == NULL || stream->_flush == NULL)
return EINVAL;
return stream->_flush (stream);
}
int
stream_set_flush (stream_t stream, int (*_flush) (stream_t), void *owner)
{
if (stream == NULL)
return EINVAL;
if (stream->owner != owner)
return EACCES;
stream->_flush = _flush;
return 0;
}
......
......@@ -256,7 +256,7 @@ mailbox_deregister (mailbox_t mbox, void *action)
for (i = 0; i < mbox->event_num; i++)
{
event = &(mbox->event[i]);
if (event->_action == action)
if ((int)event->_action == (int)action)
{
event->type = 0;
event->_action = NULL;
......
......@@ -322,7 +322,7 @@ mailbox_pop_open (mailbox_t mbox, int flags)
mailbox_pop_data_t mpd;
int status;
bio_t bio;
void *func = mailbox_pop_open;
void *func = (void *)mailbox_pop_open;
int fd;
char host[256] ;
long port;
......@@ -395,9 +395,7 @@ mailbox_pop_open (mailbox_t mbox, int flags)
}
/* Dealing whith Authentication */
/* so far only normal user/pass supported */
if (mbox->auth)
auth_authenticate (mbox->auth, &mpd->user, &mpd->passwd);
else
if (mbox->auth == NULL)
{
status = auth_create (&(mbox->auth), mbox);
if (status != 0)
......@@ -494,7 +492,7 @@ static int
mailbox_pop_close (mailbox_t mbox)
{
mailbox_pop_data_t mpd;
void *func = mailbox_pop_close;
void *func = (void *)mailbox_pop_close;
int status;
bio_t bio;
......@@ -543,7 +541,7 @@ mailbox_pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
bio_t bio;
int status;
size_t i;
void *func = mailbox_pop_get_message;
void *func = (void *)mailbox_pop_get_message;
/* sanity */
if (mbox == NULL || pmsg == NULL || (mpd = mbox->data) == NULL)
......@@ -829,7 +827,7 @@ mailbox_pop_messages_count (mailbox_t mbox, size_t *pcount)
{
mailbox_pop_data_t mpd;
int status;
void *func = mailbox_pop_messages_count;
void *func = (void *)mailbox_pop_messages_count;
bio_t bio;
if (mbox == NULL || (mpd = (mailbox_pop_data_t)mbox->data) == NULL)
......@@ -939,7 +937,7 @@ mailbox_pop_expunge (mailbox_t mbox)
attribute_t attr;
bio_t bio;
int status;
void *func = mailbox_pop_expunge;
void *func = (void *)mailbox_pop_expunge;
if (mbox == NULL ||
(mpd = (mailbox_pop_data_t) mbox->data) == NULL)
......@@ -1063,7 +1061,7 @@ mailbox_pop_readstream (stream_t is, char *buffer, size_t buflen,
size_t nread = 0;
bio_t bio;
int status = 0;
void *func = mailbox_pop_readstream;
void *func = (void *)mailbox_pop_readstream;
(void)offset;
if (is == NULL || (mpm = is->owner) == NULL)
......
......@@ -202,7 +202,7 @@ do \
} while (0)
/* notifications ADD_MESG */
#define DISPATCH_ADD_MSG(mbox,mud,file) \
#define DISPATCH_ADD_MSG(mbox,mud) \
do \
{ \
int bailing = 0; \
......@@ -212,7 +212,6 @@ do \
{ \
if (pcount) \
*pcount = (mud)->messages_count; \
fclose (file); \
mailbox_unix_unlock (mbox); \
return EINTR; \
} \
......@@ -230,7 +229,7 @@ do \
* struct incomplete. So we only tell them about
* the complete messages.
*/
#define DISPATCH_PROGRESS(mbox,mud,file) \
#define DISPATCH_PROGRESS(mbox,mud) \
do \
{ \
{ \
......@@ -243,7 +242,6 @@ do \
{ \
if (pcount) \
*pcount = (mud)->messages_count; \
fclose (file); \
mailbox_unix_unlock (mbox); \
return EINTR; \
} \
......@@ -260,7 +258,6 @@ do \
attr = calloc (1, sizeof(*(attr))); \
if ((attr) == NULL) \
{ \
fclose (file); \
mailbox_unix_iunlock (mbox); \
mailbox_unix_unlock (mbox); \
return ENOMEM; \
......@@ -269,7 +266,7 @@ do \
// size_t num = 2 * ((mud)->messages_count) + 10;
/* allocate slots for the new messages */
#define ALLOCATE_MSGS(mbox,mud,file) \
#define ALLOCATE_MSGS(mbox,mud) \
do \
{ \
if ((mud)->messages_count >= (mud)->umessages_count) \
......@@ -279,7 +276,6 @@ do \
m = realloc ((mud)->umessages, num * sizeof (*m)); \
if (m == NULL) \
{ \
fclose (file); \
mailbox_unix_iunlock (mbox); \
mailbox_unix_unlock (mbox); \
return ENOMEM; \
......@@ -288,7 +284,6 @@ do \
(mud)->umessages[num - 1] = calloc (1, sizeof (*(mum))); \
if ((mud)->umessages[num - 1] == NULL) \
{ \
fclose (file); \
mailbox_unix_iunlock (mbox); \
mailbox_unix_unlock (mbox); \
return ENOMEM; \
......@@ -299,19 +294,19 @@ do \
} while (0)
static int
mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
mailbox_unix_scan0 (mailbox_t mbox, size_t msgno, size_t *pcount, int do_notif)
{
#define MSGLINELEN 1024
char buf[MSGLINELEN];
int inheader;
int inbody;
off_t total;
off_t total = 0;
mailbox_unix_data_t mud;
mailbox_unix_message_t mum = NULL;
int status = 0;
size_t lines;
int newline;
FILE *file;
size_t n = 0;
int zn, isfrom = 0;
char *temp;
......@@ -321,69 +316,36 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
(mud = (mailbox_unix_data_t)mbox->data) == NULL)
return EINVAL;
/* the simplest way to deal with reentrancy issues is to
* duplicate the FILE * pointer instead of the orignal.
*
* QnX4(and earlier ?) has a BUFSIZ of about 512 ???
* we use setvbuf () to reset to something sane.
* Really something smaller would be counter productive.
*/
{
file = fopen (mbox->name, "r");
if (file == NULL)
return errno;
#if BUFSIZ <= 1024
{
char *iobuffer;
iobuffer = malloc (8192);
if (iobuffer != NULL)
if (setvbuf (file, iobuffer, _IOFBF, 8192) != 0)
free (iobuffer);
}
#endif
}
/* save the timestamp and size */
status = stream_size (mbox->stream, &(mud->size));
if (status != 0)
return status;
/* grab the locks */
mailbox_unix_ilock (mbox, MU_LOCKER_WRLOCK);
mailbox_unix_lock (mbox, MU_LOCKER_RDLOCK);
/* save the timestamp and size */
{
struct stat st;
if (fstat (fileno (file), &st) != 0)
{
status = errno;
fclose (file);
mailbox_unix_iunlock (mbox);
mailbox_unix_unlock (mbox);
return status;
}
mud->mtime = st.st_mtime;
mud->size = st.st_size;
}
/* seek to the starting point */
if (mud->umessages)
if (mud->umessages && msgno > 0 && mud->messages_count > 0
&& msgno <= mud->messages_count)
{
if (mud->messages_count > 0 &&
msgno != 0 &&
msgno <= mud->messages_count)
{
mum = mud->umessages[msgno - 1];
if (mum)
fseek (file, mum->body_end, SEEK_SET);
mud->messages_count = msgno;
}
mum = mud->umessages[msgno - 1];
if (mum)
total = mum->header_from;
mud->messages_count = msgno - 1;
}
else
mud->messages_count = 0;
newline = 1;
errno = total = lines = inheader = inbody = 0;
errno = lines = inheader = inbody = 0;
while (fgets (buf, sizeof (buf), file))
while ((status = stream_readline (mbox->stream, buf, sizeof (buf),
total, &n)) == 0 && n != 0)
{
int over, nl;
STRLEN (buf, over);
total += over;
int nl;
STRLEN(buf, n);
total += n;
nl = (*buf == '\n') ? 1 : 0;
VALID(buf, temp, isfrom, zn);
......@@ -403,22 +365,23 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
/* signal the end of the body */
if (mum && !mum->body_end)
{
mum->body_end = total - over - newline;
mum->body_end = total - n - newline;
mum->body_lines = --lines - newline;
DISPATCH_ADD_MSG(mbox, mud, file);
if (do_notif)
DISPATCH_ADD_MSG(mbox, mud);
}
/* allocate_msgs will initialize mum */
ALLOCATE_MSGS(mbox, mud, file);
ALLOCATE_MSGS(mbox, mud);
mud->messages_count++;
mum = mud->umessages[mud->messages_count - 1];
mum->file = mud->file;
mum->header_from = total - over;
mum->stream = mbox->stream;
mum->header_from = total - n;
mum->header_from_end = total;
lines = 0;
}
else if ((over > 7) && ISSTATUS(buf))
else if ((n > 7) && ISSTATUS(buf))
{
mum->header_status = total - over;
mum->header_status = total - n;
mum->header_status_end = total;
ATTRIBUTE_SET(buf, mum, 'r', 'R', MU_ATTRIBUTE_READ);
ATTRIBUTE_SET(buf, mum, 'o', 'O', MU_ATTRIBUTE_SEEN);
......@@ -433,7 +396,7 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
/* set the body position */
if (mum && !mum->body)
{
mum->body = total - over + nl;
mum->body = total - n + nl;
mum->header_lines = lines;
lines = 0;
}
......@@ -446,25 +409,19 @@ mailbox_unix_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
mailbox_unix_touchlock (mbox);
/* ping them every 1000 lines */
if (((lines +1) % 1000) == 0)
DISPATCH_PROGRESS(mbox, mud, file);
if (do_notif)
if (((lines +1) % 1000) == 0)
DISPATCH_PROGRESS(mbox, mud);
} /* while */
status = errno;
/* not an error if we reach EOF */
if (feof (file))
status = 0;
clearerr (file);
if (mum)
{
mum->body_end = total - newline;
mum->body_lines = lines - newline;
DISPATCH_ADD_MSG(mbox, mud, file);
if (do_notif)
DISPATCH_ADD_MSG(mbox, mud);
}
fclose (file);
mailbox_unix_iunlock (mbox);
mailbox_unix_unlock (mbox);
if (pcount)
......
......@@ -389,7 +389,7 @@ message_deregister (message_t msg, void *action)
for (i = 0; i < msg->event_num; i++)
{
event = &(msg->event[i]);
if (event->_action == action)
if ((int)event->_action == (int)action)
{
event->type = 0;
event->_action = NULL;
......
......@@ -77,7 +77,7 @@ static int _mime_append_part(mime_t mime, message_t msg, int body_offset, int bo
header_set_value(mime_part->hdr, "Content-Type", "message/rfc822", 0, 0);
else
header_set_value(mime_part->hdr, "Content-Type", "text/plain", 0, 0);
}
}
}
mime_part->body_len = body_len;
mime_part->body_offset = body_offset;
......@@ -122,21 +122,21 @@ static void _mime_munge_content_header(char *field_body )
_strtrim(field_body);
if ( ( e = strchr(str, ';') ) == NULL )
return;
return;
while( *e == ';' ) {
p = e;
e++;
e++;
while ( *e && isspace(*e) ) /* remove space upto param */
e++;
memmove(p+1, e, strlen(e)+1);
e = p+1;
while ( *e && *e != '=' ) /* find end of value */
e++;
e = p = e+1;
while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace(*e) ) ) ) {
if ( *e == '\\' ) { /* escaped */
memmove(e, e+1, strlen(e)+2);
memmove(e, e+1, strlen(e)+2);
} else if ( *e == '\"' )
quoted = ~quoted;
e++;
......@@ -282,12 +282,12 @@ static int _mime_parse_mpart_message(mime_t mime)
nbytes--;
cp++;
}
if ( mime->flags & MIME_INCREAMENTAL_PARSER ) {
/*
* can't really do this since returning EAGAIN will make the MUA think
* it should select on the messages stream fd. re-think this whole
if ( mime->flags & MIME_INCREAMENTAL_PARSER ) {
/*
* can't really do this since returning EAGAIN will make the MUA think
* it should select on the messages stream fd. re-think this whole
* non-blocking thing.....
ret = EAGAIN;
break;
*/
......@@ -328,15 +328,6 @@ static int _mime_message_fd(stream_t stream, int *fd)
return stream_get_fd(mime_part->mime->stream, fd);
}
static int _mime_new_message_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t *nbytes)
{
(void)stream; (void)buf; (void)buflen; (void)off;
if ( nbytes == NULL )
return(EINVAL);
return 0;
}
static int _mime_body_size (body_t body, size_t *psize)
{
struct _mime_part *mime_part = body->owner;
......
......@@ -74,8 +74,6 @@ static int _trans_read(stream_t stream, char *optr, size_t osize, off_t offset,
*nbytes = 0;
if ( offset && ts->offset != offset )
return ESPIPE;
if ( offset == 0 )
ts->cur_offset = 0;
if ( ( iptr = alloca(isize) ) == NULL )
......@@ -89,13 +87,13 @@ static int _trans_read(stream_t stream, char *optr, size_t osize, off_t offset,
if ( ( ret = stream_read(ts->stream, iptr + ts->llen, isize - ts->llen, ts->cur_offset, &osize) ) != 0 )
return ret;
ts->cur_offset += osize;
consumed = ts->transcoder(iptr, isize, optr, nbytes);
if ( ts->llen = (isize - consumed ) ) {
consumed = ts->transcoder(iptr, osize + ts->llen, optr, nbytes);
if ( ( ts->llen = ((osize + ts->llen) - consumed ) ) )
{
if ( ( ts->leftover = malloc(ts->llen) ) == NULL )
return ENOMEM;
memcpy(ts->leftover, iptr + consumed, ts->llen);
}
ts->offset = offset;
return 0;
}
......@@ -112,7 +110,7 @@ static int _trans_write(stream_t stream, const char *iptr, size_t isize, off_t o
*nbytes = 0;
if ( offset && ts->offset != offset )
if ( offset && ts->cur_offset != offset )
return ESPIPE;
if ( offset == 0 )
ts->cur_offset = 0;
......@@ -197,19 +195,19 @@ static int _b64_input(char c)
return -1;
}
static int _b64_output(int index)
static int _b64_output(int idx)
{
const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
if (index < 64)
return table[index];
if (idx < 64)
return table[idx];
return -1;
}
int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
{
int i, tmp = 0;
int consumed = 0;
int i = 0, tmp = 0;
size_t consumed = 0;
char data[4];
while ( consumed < isize ) {
......@@ -227,7 +225,10 @@ int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
(*nbytes) += 3;
}
else // I did not get all the data
{
consumed -= i;
return consumed;
}
i = 0;
}
return consumed;
......@@ -235,7 +236,7 @@ int _base64_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
int _base64_encode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
{
int consumed = 0;
size_t consumed = 0;
while (consumed < (isize - 3) && (*nbytes + 4) < isize) {
*optr++ = _b64_output(*iptr >> 2);
......@@ -270,7 +271,8 @@ static int _ishex(int c)
int _qp_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
{
char c;
int last_char = 0, consumed = 0;
int last_char = 0;
size_t consumed = 0;
while (consumed < isize) {
c = *iptr++;
......@@ -332,8 +334,8 @@ int _qp_decode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
#define QP_LINE_MAX 76
int _qp_encode(const char *iptr, size_t isize, char *optr, size_t *nbytes)
{
int count = 0;
int consumed = 0, c;
int count = 0, c;
size_t consumed = 0;
while (consumed < isize && (*nbytes + 4) < isize) {
if (count == QP_LINE_MAX) {
......