Commit d9a9b601 d9a9b601ddbfa36443aa6482c892c5587986dbff by Alain Magloire

attribute.c auth.c header.c io.c locker.c mailbox.c mbx_imap.c

 	mbx_mbox.c mbx_mdir.c mbx_mh.c mbx_mmdf.c mbx_pop.c mbx_unix.c
 	message.c mime.c registrar.c url.c url_file.c url_imap.c
 	url_mail.c url_mbox.c url_mdir.c url_mh.c url_mmdf.c url_pop.c
 	url_unix.c include/private/mailbox0.h
 	include/private/mbx_imap.h include/private/mbx_mbox.h
 	include/private/mbx_mdir.h include/private/mbx_mmdf.h
 	include/private/mbx_pop.h include/private/mbx_unix.h
 	include/private/message0.h include/private/mime0.h
 	include/private/url0.h include/public/attribute.h
 	include/public/auth.h include/public/event.h
 	include/public/header.h include/public/io.h
 	include/public/locker.h include/public/mailbox.h
 	include/public/message.h include/public/mime.h
 	include/public/registrar.h include/public/transcode.h
 	include/public/url.h

changed all the *_init to *_create().
added *_lines() functions
optimisation of the parsing.
1 parent edadcf90
......@@ -15,29 +15,15 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <attribute.h>
#include <attribute0.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define MU_ATTRIBUTE_SEEN ((int)1)
#define MU_ATTRIBUTE_ANSWERED (MU_ATTRIBUTE_SEEN << 1)
#define MU_ATTRIBUTE_FLAGGED (MU_ATTRIBUTE_ANSWERED << 1)
#define MU_ATTRIBUTE_DELETED (MU_ATTRIBUTE_FLAGGED << 1)
#define MU_ATTRIBUTE_DRAFT (MU_ATTRIBUTE_DELETED << 1)
#define MU_ATTRIBUTE_RECENT (MU_ATTRIBUTE_DRAFT << 1)
#define MU_ATTRIBUTE_READ (MU_ATTRIBUTE_RECENT << 1)
struct _attribute
{
size_t flag;
void *owner;
};
int
attribute_init (attribute_t *pattr, void *owner)
attribute_create (attribute_t *pattr, void *owner)
{
attribute_t attr;
if (pattr == NULL || owner == NULL)
......@@ -274,7 +260,7 @@ string_to_attribute (const char *buffer, size_t len,
char *sep;
int status;
status = attribute_init (pattr, owner);
status = attribute_create (pattr, owner);
if (status != 0)
return status;
......
......@@ -32,7 +32,7 @@ struct _auth
};
int
auth_init (auth_t *pauth, void *owner)
auth_create (auth_t *pauth, void *owner)
{
auth_t auth;
if (pauth == NULL)
......
......@@ -57,7 +57,7 @@ struct _header
};
int
header_init (header_t *ph, const char *blurb, size_t len, void *owner)
header_create (header_t *ph, const char *blurb, size_t len, void *owner)
{
header_t h;
int status;
......@@ -66,14 +66,9 @@ header_init (header_t *ph, const char *blurb, size_t len, void *owner)
return ENOMEM;
h->owner = owner;
status = header_parse (h, (char *)blurb, len);
if (status != 0)
{
free (h);
return status;
}
header_parse (h, (char *)blurb, len);
status = stream_init (&(h->stream), h);
status = stream_create (&(h->stream), h);
if (status != 0)
return status;
......@@ -132,7 +127,7 @@ header_parse (header_t header, char *blurb, int len)
return 0;
header->blurb_len = len;
header->blurb = calloc (1, header->blurb_len);
header->blurb = calloc (1, header->blurb_len + 1);
if (header->blurb == NULL)
return ENOMEM;
memcpy (header->blurb, blurb, header->blurb_len);
......@@ -214,6 +209,7 @@ header_parse (header_t header, char *blurb, int len)
header->hdr_count++;
} /* for (header_start ...) */
#if 0
header->blurb_len -= len;
if (header->blurb_len <= 0)
{
......@@ -221,6 +217,10 @@ header_parse (header_t header, char *blurb, int len)
free (header->hdr);
return EINVAL;
}
/* always add the separtor LF */
header->blurb [header->blurb_len] = '\n';
header->blurb_len++;
#endif
return 0;
}
......@@ -305,7 +305,24 @@ header_entry_count (header_t header, size_t *pnum)
}
int
header_get_size (header_t header, size_t *pnum)
header_lines (header_t header, size_t *plines)
{
int n;
size_t t = 0;
if (header == NULL)
return EINVAL;
for (n = header->blurb_len - 1; n >= 0; n--)
{
if (header->blurb[n] == '\n')
t++;
}
if (plines)
*plines = t;
return 0;
}
int
header_size (header_t header, size_t *pnum)
{
if (header == NULL)
return EINVAL;
......
......@@ -42,6 +42,7 @@ struct _mailbox
char *name;
auth_t auth;
locker_t locker;
netinstance_t netinstance;
url_t url;
/* register events */
......@@ -53,7 +54,7 @@ struct _mailbox
/* Public methods */
int (*_init) __P ((mailbox_t *, const char *));
int (*_create) __P ((mailbox_t *, const char *));
void (*_destroy) __P ((mailbox_t *));
int (*_open) __P ((mailbox_t, int flag));
......@@ -75,19 +76,8 @@ struct _mailbox
};
/* private */
extern int mailbox_delete __P ((mailbox_t, size_t msgno));
extern int mailbox_undelete __P ((mailbox_t, size_t msgno));
extern int mailbox_is_deleted __P ((mailbox_t, size_t msgno));
extern int mailbox_num_deleted __P ((mailbox_t, size_t *));
extern int mailbox_get_auth __P ((mailbox_t mbox, auth_t *auth));
extern int mailbox_set_auth __P ((mailbox_t mbox, auth_t auth));
extern int mailbox_get_locker __P ((mailbox_t mbox, locker_t *locker));
extern int mailbox_set_locker __P ((mailbox_t mbox, locker_t locker));
extern int mailbox_get_attribute __P ((mailbox_t mbox, size_t msgno,
attribute_t *attr));
extern int mailbox_set_attribute __P ((mailbox_t mbox, size_t msgno,
attribute_t attr));
extern int mailbox_notification __P ((mailbox_t mbox, size_t type));
......
......@@ -20,7 +20,7 @@
#include <mailbox0.h>
extern int mailbox_imap_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_imap_create __P ((mailbox_t *mbox, const char *name));
extern void mailbox_imap_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_imap_type;
......
......@@ -20,7 +20,7 @@
#include <mailbox.h>
extern int mailbox_mbox_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_mbox_create __P ((mailbox_t *mbox, const char *name));
extern void mailbox_mbox_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_mbox_type;
......
......@@ -20,7 +20,7 @@
#include <mailbox0.h>
extern int mailbox_maildir_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_maildir_create __P ((mailbox_t *mbox, const char *name));
extern void mailbox_maildir_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_maildir_type;
......
......@@ -20,7 +20,7 @@
#include <mailbox0.h>
extern int mailbox_mmdf_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_mmdf_create __P ((mailbox_t *mbox, const char *name));
extern void mailbox_mmdf_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_mmdf_type;
......
......@@ -20,7 +20,7 @@
#include <mailbox0.h>
extern int mailbox_pop_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_pop_create __P ((mailbox_t *mbox, const char *name));
extern void mailbox_pop_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_pop_type;
......
......@@ -24,7 +24,7 @@
extern "C" {
#endif
extern int mailbox_unix_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_unix_create __P ((mailbox_t *mbox, const char *name));
extern void mailbox_unix_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_unix_type;
......
......@@ -39,20 +39,6 @@ extern "C" {
# endif
#endif /*__P */
/* The notion of body_t is not exported outside,
* there was no need for yet another object.
* since only floating messages need them. The functions
* that manipulate those objects are static to message.c
*
*/
struct _body
{
FILE *file;
void *owner;
};
typedef struct _body * body_t;
/* forward declaration */
struct _message
{
......@@ -79,9 +65,9 @@ struct _message
int (*_get_stream) __P ((message_t msg, stream_t *));
int (*_set_stream) __P ((message_t msg, stream_t, void *owner));
int (*_size) __P ((message_t msg, size_t *size));
int (*_from) __P ((message_t msg, char *, size_t, size_t *));
int (*_received) __P ((message_t msg, char *, size_t, size_t *));
int (*_clone) __P ((message_t msg, message_t *cmsg));
};
#ifdef _cplusplus
......
......@@ -81,6 +81,7 @@ struct _mime
struct _mime_part
{
char sig[4];
mime_t mime;
header_t hdr;
message_t msg;
......
......@@ -47,7 +47,7 @@ struct _url
void *data;
int (*_init) __P ((url_t *url, const char *name));
int (*_create) __P ((url_t *url, const char *name));
void (*_destroy) __P ((url_t *url));
/* Methods */
......
......@@ -35,7 +35,7 @@ extern "C" {
struct _attribute;
typedef struct _attribute * attribute_t;
extern int attribute_init __P ((attribute_t *, void *owner));
extern int attribute_create __P ((attribute_t *, void *owner));
extern void attribute_destroy __P ((attribute_t *, void *owner));
extern int attribute_is_seen __P ((attribute_t));
......
......@@ -36,7 +36,7 @@ extern "C" {
struct _auth;
typedef struct _auth *auth_t;
extern int auth_init __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));
......
......@@ -67,7 +67,7 @@ extern "C" {
struct _header;
typedef struct _header * header_t;
extern int header_init __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));
......@@ -81,7 +81,8 @@ extern int header_entry_name __P ((header_t, size_t num, char *buf,
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_get_size __P ((header_t, size_t *size));
extern int header_size __P ((header_t, size_t *size));
extern int header_lines __P ((header_t, size_t *lines));
#ifdef _cplusplus
}
......
......@@ -35,7 +35,7 @@ extern "C" { /*}*/
struct _stream;
typedef struct _stream *stream_t;
extern int stream_init __P ((stream_t *, void *owner));
extern int stream_create __P ((stream_t *, void *owner));
extern void stream_destroy __P ((stream_t *, void *owner));
extern int stream_set_fd __P ((stream_t,
......
......@@ -35,7 +35,7 @@ extern "C" {
struct _locker;
typedef struct _locker *locker_t;
extern int locker_init __P ((locker_t *, char *filename,
extern int locker_create __P ((locker_t *, char *filename,
size_t len, int flags));
extern void locker_destroy __P ((locker_t *));
......
......@@ -18,13 +18,14 @@
#ifndef _MAILBOX_H
# define _MAILBOX_H
#include <sys/types.h>
#include <url.h>
#include <message.h>
#include <attribute.h>
#include <auth.h>
#include <locker.h>
#include <net.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
......@@ -43,7 +44,7 @@ struct _mailbox;
typedef struct _mailbox *mailbox_t;
/* constructor/destructor and possible types */
extern int mailbox_init __P ((mailbox_t *, const char *, int id));
extern int mailbox_create __P ((mailbox_t *, const char *, int id));
extern void mailbox_destroy __P ((mailbox_t *));
/* flags for mailbox_open () */
......@@ -63,6 +64,10 @@ 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));
/* netinstance settings */
extern int mailbox_get_netinstance __P ((mailbox_t, netinstance_t *net));
extern int mailbox_set_netinstance __P ((mailbox_t, netinstance_t net));
/* Lock settings */
extern int mailbox_get_locker __P ((mailbox_t, locker_t *locker));
extern int mailbox_set_locker __P ((mailbox_t, locker_t locker));
......
......@@ -19,6 +19,7 @@
#define _MESSAGE_H
#include <header.h>
#include <body.h>
#include <attribute.h>
#include <io.h>
......@@ -48,24 +49,38 @@ typedef struct _message *message_t;
* was enough.
*/
extern int message_init __P ((message_t *, void *owner));
extern int message_create __P ((message_t *, void *owner));
extern void message_destroy __P ((message_t *, void *owner));
extern int message_get_header __P ((message_t, header_t *));
extern int message_set_header __P ((message_t, header_t, void *owner));
extern int message_get_body __P ((message_t, body_t *));
extern int message_set_body __P ((message_t, body_t, void *owner));
extern int message_get_stream __P ((message_t, stream_t *));
extern int message_set_stream __P ((message_t, stream_t, void *owner));
extern int message_is_multipart __P ((message_t));
extern int message_get_size __P ((message_t, size_t *));
extern int message_set_size __P ((message_t, size_t, void *owner));
extern int message_size __P ((message_t, size_t *));
extern int message_lines __P ((message_t, size_t *));
extern int message_from __P ((message_t, char *, size_t, size_t *));
extern int message_set_from __P ((message_t,
int (*_from) __P ((message_t, char *,
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_get_attribute __P ((message_t, attribute_t *));
extern int message_set_attribute __P ((message_t, attribute_t, void *owner));
extern int message_clone __P ((message_t));
//extern int message_clone __P ((message_t));
/* events */
#define MU_EVT_MSG_DESTROY 32
......
......@@ -41,7 +41,7 @@ extern "C" {
struct _mime;
typedef struct _mime *mime_t;
int mime_init __P ((mime_t *pmime, message_t msg, int flags));
int mime_create __P ((mime_t *pmime, message_t msg, int flags));
void mime_destroy __P ((mime_t *pmime));
int mime_is_multi_part __P ((mime_t mime));
int mime_get_part __P ((mime_t mime, int part, message_t *msg));
......
......@@ -38,14 +38,14 @@ extern "C" {
struct url_registrar
{
const char *scheme;
int (*_init) __P ((url_t *, const char * name));
int (*_create) __P ((url_t *, const char * name));
void (*_destroy) __P ((url_t *));
};
struct mailbox_registrar
{
const char *name;
int (*_init) __P ((mailbox_t *, const char *name));
int (*_create) __P ((mailbox_t *, const char *name));
void (*_destroy) __P ((mailbox_t *));
};
......
......@@ -44,7 +44,7 @@ struct _transcoder
void *tcdata;
};
extern int transcode_init __P ((transcoder_t *, char *encoding));
extern int transcode_create __P ((transcoder_t *, char *encoding));
extern void transcode_destroy __P ((transcoder_t *));
extern int transcode_get_stream __P ((transcoder_t tc, stream_t *pis));
extern int transcode_set_stream __P ((transcoder_t tc, stream_t is));
......
......@@ -36,7 +36,7 @@ extern "C" {
struct _url;
typedef struct _url * url_t;
extern int url_init __P ((url_t *, const char *name));
extern int url_create __P ((url_t *, const char *name));
extern void url_destroy __P ((url_t *));
extern int url_get_id __P ((const url_t, int *id));
......
......@@ -22,7 +22,7 @@
#include <stdio.h>
int
stream_init (stream_t *pstream, void *owner)
stream_create (stream_t *pstream, void *owner)
{
stream_t stream;
if (pstream == NULL || owner == NULL)
......
......@@ -45,7 +45,7 @@ struct _locker
};
int
locker_init (locker_t *plocker, char *filename, size_t len, int flags)
locker_create (locker_t *plocker, char *filename, size_t len, int flags)
{
locker_t l;
......
......@@ -23,6 +23,7 @@
#include <message0.h>
#include <registrar.h>
#include <locker.h>
#include <net.h>
#include <stdlib.h>
#include <string.h>
......@@ -32,23 +33,23 @@
* Point of entry.
* Simple, first check if they ask for something specific; with the ID.
* Then try to discover the type of mailbox with the url(name).
* Then we call the appropriate mailbox_*type*_init() function.
* Then we call the appropriate mailbox_*type*_create() function.
*/
int
mailbox_init (mailbox_t *pmbox, const char *name, int id)
mailbox_create (mailbox_t *pmbox, const char *name, int id)
{
int status = EINVAL;
struct mailbox_registrar *mreg;
url_t url = NULL;
url_init (&url, name);
url_create (&url, name);
/* 1st guest: if an ID is specify, shortcut */
if (id)
{
status = registrar_get (id, NULL, &mreg);
if (status == 0)
status = mreg->_init (pmbox, name);
status = mreg->_create (pmbox, name);
}
/* 2nd fallback: Use the URL */
else if (url != NULL)
......@@ -56,7 +57,7 @@ mailbox_init (mailbox_t *pmbox, const char *name, int id)
url_get_id (url, &id);
status = registrar_get (id, NULL, &mreg);
if (status == 0)
status = mreg->_init (pmbox, name);
status = mreg->_create (pmbox, name);
}
/* set the URL */
......@@ -189,6 +190,24 @@ mailbox_get_auth (mailbox_t mbox, auth_t *pauth)
}
int
mailbox_set_netinstance (mailbox_t mbox, netinstance_t netinstance)
{
if (mbox == NULL)
return EINVAL;
mbox->netinstance = netinstance;
return 0;
}
int
mailbox_get_netinstance (mailbox_t mbox, netinstance_t *pnetinstance)
{
if (mbox == NULL || pnetinstance == NULL)
return EINVAL;
*pnetinstance = mbox->netinstance;
return 0;
}
int
mailbox_register (mailbox_t mbox, size_t type,
int (*action) (size_t type, void *arg),
void *arg)
......
......@@ -20,13 +20,13 @@
#include <errno.h>
static int mailbox_imap_init (mailbox_t *mbox, const char *name);
static int mailbox_imap_create (mailbox_t *mbox, const char *name);
static void mailbox_imap_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_imap_registrar =
{
"IMAP4",
mailbox_imap_init, mailbox_imap_destroy
mailbox_imap_create, mailbox_imap_destroy
};
void
......@@ -37,7 +37,7 @@ mailbox_imap_destroy (mailbox_t *mbox)
}
int
mailbox_imap_init (mailbox_t *mbox, const char *name)
mailbox_imap_create (mailbox_t *mbox, const char *name)
{
(void)mbox; (void)name;
return ENOSYS;
......
......@@ -22,13 +22,13 @@
#include <errno.h>
#include <sys/stat.h>
static int mailbox_mbox_init (mailbox_t *mbox, const char *name);
static int mailbox_mbox_create (mailbox_t *mbox, const char *name);
static void mailbox_mbox_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_mbox_registrar =
{
"UNIX_MBOX/Maildir/MMDF",
mailbox_mbox_init, mailbox_mbox_destroy
mailbox_mbox_create, mailbox_mbox_destroy
};
/*
......@@ -45,7 +45,7 @@ struct mailbox_registrar _mailbox_mbox_registrar =
*/
static int
mailbox_mbox_init (mailbox_t *mbox, const char *name)
mailbox_mbox_create (mailbox_t *mbox, const char *name)
{
struct stat st;
size_t len;
......@@ -69,7 +69,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
* For the default is unix if the file does not exist.
*/
if (stat (name, &st) < 0)
return _mailbox_unix_registrar._init (mbox, name);
return _mailbox_unix_registrar._create (mbox, name);
if (S_ISREG (st.st_mode))
{
......@@ -101,7 +101,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
if (count == 0) /*empty file*/
{
close (fd);
return _mailbox_unix_registrar._init (mbox, name);
return _mailbox_unix_registrar._create (mbox, name);
}
if (count >= 5)
......@@ -110,18 +110,18 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
{
/* This is a Unix Mbox */
close (fd);
return _mailbox_unix_registrar._init (mbox, name);
return _mailbox_unix_registrar._create (mbox, name);
}
}
/* Try MMDF */
close (fd);
#endif
return _mailbox_unix_registrar._init (mbox, name);
return _mailbox_unix_registrar._create (mbox, name);
}
/* Is that true ? Are all directories Maildir ?? */
else if (S_ISDIR (st.st_mode))
return _mailbox_maildir_registrar._init (mbox, name);
return _mailbox_maildir_registrar._create (mbox, name);
/* Why can't a mailbox be FIFO ? or a DOOR/Portal ??? */
return EINVAL;
......
......@@ -19,17 +19,17 @@
#include <registrar0.h>
#include <errno.h>
static int mailbox_maildir_init (mailbox_t *mbox, const char *name);
static int mailbox_maildir_create (mailbox_t *mbox, const char *name);
static void mailbox_maildir_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_maildir_registrar =
{
"MAILDIR",
mailbox_maildir_init, mailbox_maildir_destroy
mailbox_maildir_create, mailbox_maildir_destroy
};
int
mailbox_maildir_init (mailbox_t *mbox, const char *name)
mailbox_maildir_create (mailbox_t *mbox, const char *name)
{
(void)mbox; (void)name;
return ENOSYS;
......
......@@ -27,13 +27,13 @@
#include <stdlib.h>
#include <ctype.h>
static int mailbox_mh_init (mailbox_t *pmbox, const char *name);
static int mailbox_mh_create (mailbox_t *pmbox, const char *name);
static void mailbox_mh_destroy (mailbox_t *pmbox);
struct mailbox_registrar _mailbox_mh_registrar =
{
"MH",
mailbox_mh_init, mailbox_mh_destroy
mailbox_mh_create, mailbox_mh_destroy
};
typedef struct _mh_data
......@@ -43,11 +43,11 @@ typedef struct _mh_data
static int mh_open (mailbox_t mbox, int flags);
static int mh_close (mailbox_t mbox);
static int mh_scan (mailbox_t mbox, size_t *msgs);
static int mh_scan (mailbox_t mbox, size_t msgno, size_t *msgs);
static int mh_sequence(const char *name);
static int
mailbox_mh_init (mailbox_t *pmbox, const char *name)
mailbox_mh_create (mailbox_t *pmbox, const char *name)
{
mailbox_t mbox;
mh_data *data;
......@@ -57,10 +57,11 @@ mailbox_mh_init (mailbox_t *pmbox, const char *name)
mbox->name = malloc(strlen(name) + 1);
strcpy(mbox->name, name);
mbox->data = data;
mbox->_init = mailbox_mh_init;
mbox->_create = mailbox_mh_create;
mbox->_destroy = mailbox_mh_destroy;
mbox->_open = mh_open;
mbox->_close = mh_close;
mbox->_scan = mh_scan;
*pmbox = mbox;
return 0;
......@@ -110,7 +111,7 @@ mh_close (mailbox_t mbox)
}
static int
mh_scan (mailbox_t mbox, size_t *msgs)
mh_scan (mailbox_t mbox, size_t msgno, size_t *msgs)
{
struct stat st;
DIR *maildir;
......@@ -119,6 +120,8 @@ mh_scan (mailbox_t mbox, size_t *msgs)
unsigned int count = 0;
int parse_sequence_file = 0;
(void)msgno;
data = mbox->data;
maildir = opendir(mbox->name);
......
......@@ -20,17 +20,17 @@
#include <errno.h>
static int mailbox_mmdf_init (mailbox_t *mbox, const char *name);
static int mailbox_mmdf_create (mailbox_t *mbox, const char *name);
static void mailbox_mmdf_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_mmdf_registrar =
{
"MMDF",
mailbox_mmdf_init, mailbox_mmdf_destroy
mailbox_mmdf_create, mailbox_mmdf_destroy
};
static int
mailbox_mmdf_init (mailbox_t *mbox, const char *name)
mailbox_mmdf_create (mailbox_t *mbox, const char *name)
{
(void)mbox; (void)name;
return ENOSYS;
......
......@@ -20,13 +20,13 @@
#include <errno.h>
static int mailbox_pop_init (mailbox_t *mbox, const char *name);
static int mailbox_pop_create (mailbox_t *mbox, const char *name);
static void mailbox_pop_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_pop_registrar =
{
"POP3",
mailbox_pop_init, mailbox_pop_destroy
mailbox_pop_create, mailbox_pop_destroy
};
static void
......@@ -37,7 +37,7 @@ mailbox_pop_destroy (mailbox_t *mbox)
}
static int
mailbox_pop_init (mailbox_t *mbox, const char *name)
mailbox_pop_create (mailbox_t *mbox, const char *name)
{
(void)mbox; (void)name;
return ENOSYS;
......
......@@ -19,6 +19,7 @@
#include <message0.h>
#include <mime0.h>
#include <io0.h>
#include <body0.h>
#include <mime.h>
#include <errno.h>
......@@ -37,17 +38,15 @@
* Define mbx i/f for protocols that support mime parsing (IMAP).
*/
static int _mime_append_part( mime_t mime, int body_offset, int body_len, int encap_msg )
static int _mime_append_part(mime_t mime, message_t msg, int body_offset, int body_len, int encap_msg)
{
struct _mime_part *mime_part, **part_arr;
int ret;
if ( ( mime_part = calloc(1, sizeof(*mime_part)) ) == NULL )
return ENOMEM;
if ( ( ret = header_init(&mime_part->hdr, mime->header_buf, mime->header_length, mime_part) ) != 0 ) {
free(mime_part);
return ret;
}
memcpy(mime_part->sig,"MIME", 4);
if ( encap_msg ) {
if ( mime->ncap_msgs >= mime->tmsgs ) {
if ( ( part_arr = realloc(mime->cap_msgs, ( mime->tmsgs + 2 ) * sizeof(mime_part)) ) == NULL ) {
......@@ -70,10 +69,17 @@ static int _mime_append_part( mime_t mime, int body_offset, int body_len, int en
}
mime->mtp_parts[mime->nmtp_parts++] = mime_part;
}
if ( msg == NULL ) {
if ( ( ret = header_create(&mime_part->hdr, mime->header_buf, mime->header_length, mime_part) ) != 0 ) {
free(mime_part);
return ret;
}
mime->header_length = 0;
}
mime_part->body_len = body_len;
mime_part->body_offset = body_offset;
mime_part->msg = msg;
mime_part->mime = mime;
mime->header_length = 0;
return 0;
}
......@@ -247,7 +253,7 @@ static int _mime_parse_mpart_message(mime_t mime)
mime->flags &= ~MIME_PARSER_HAVE_CR;
body_length = mime->cur_offset - body_offset - mime->line_ndx + 1;
if ( mime->header_length ) /* this skips the preamble */
_mime_append_part(mime, body_offset, body_length, FALSE );
_mime_append_part(mime, NULL, body_offset, body_length, FALSE );
if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+2+blength, "--",2) ) ||
!strncasecmp(cp2+blength, "--",2) ) { /* very last boundary */
break;
......@@ -310,7 +316,26 @@ static int _mime_message_read(stream_t stream, char *buf, size_t buflen, off_t o
return stream_read(mime_part->mime->stream, buf, read_len, mime_part->body_offset + off, nbytes );
}
int mime_init(mime_t *pmime, message_t msg, int flags)
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;
if (mime_part == NULL)
return EINVAL;
if (psize)
*psize = mime_part->body_len;
return 0;
}
int mime_create(mime_t *pmime, message_t msg, int flags)
{
mime_t mime = NULL;
int ret = 0;
......@@ -339,14 +364,11 @@ int mime_init(mime_t *pmime, message_t msg, int flags)
}
}
}
else { /* create a floating message to contain this new mime message */
if ( ( ret = message_init( &msg, NULL ) ) == 0 ) {
if ( ( ret = message_get_stream(msg, &(mime->stream)) ) == 0 ) {
msg->owner = mime;
else {
if ( ( ret = message_create( &msg, mime ) ) == 0 ) {
mime->flags |= MIME_NEW_MESSAGE;
}
}
}
if ( ret != 0 ) {
if ( mime->content_type )
free(mime->content_type);
......@@ -413,6 +435,7 @@ int mime_get_part(mime_t mime, int part, message_t *msg)
int nmtp_parts, ret = 0;
size_t hsize = 0;
stream_t stream;
body_t body;
struct _mime_part *mime_part;
if ( ( ret = mime_get_num_parts(mime, &nmtp_parts ) ) == 0 ) {
......@@ -422,19 +445,18 @@ int mime_get_part(mime_t mime, int part, message_t *msg)
*msg = mime->msg;
else {
mime_part = mime->mtp_parts[part-1];
if ( ( ret = message_init(&(mime_part->msg), mime_part) ) == 0 ) {
if ( ( ret = message_create(&(mime_part->msg), mime_part) ) == 0 ) {
message_set_header(mime_part->msg, mime_part->hdr, mime_part);
header_get_size(mime_part->hdr, &hsize);
message_set_size (mime_part->msg, mime_part->body_len + hsize, mime_part);
if ( ( ret = stream_init(&stream, mime_part) ) == 0 ) {
if ( ( ret = stream_set_read(stream, _mime_message_read, mime_part) ) == 0 ) {
if ( ( ret = message_set_stream( mime_part->msg, stream, mime_part) ) == 0 ) {
header_size(mime_part->hdr, &hsize);
if ( ( ret = body_create(&body, mime_part) ) == 0 ) {
if ( ( ret = stream_create(&stream, mime_part) ) == 0 ) {
body_set_size (body, _mime_body_size, mime_part);
stream_set_read(stream, _mime_message_read, mime_part);
body_set_stream(body, stream, mime_part);
*msg = mime_part->msg;
return 0;
}
}
stream_destroy(&stream, mime_part);
}
message_destroy(&mime_part->msg, mime_part);
}
}
......@@ -449,6 +471,7 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg)
char *content_type, *cp;
header_t hdr;
stream_t stream;
body_t body;
struct _mime_part *mime_part;
if ( mime == NULL || msg == NULL || newmsg == NULL || mime->flags & MIME_NEW_MESSAGE )
......@@ -493,20 +516,18 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg)
}
body_length -= mime->cur_offset - body_offset;
body_offset = mime->cur_offset + 1;
if ( ( ret = _mime_append_part( mime, body_offset, body_length, TRUE ) ) == 0 ) {
if ( ( ret = _mime_append_part( mime, NULL, body_offset, body_length, TRUE ) ) == 0 ) {
mime_part = mime->cap_msgs[mime->ncap_msgs - 1];
if ( ( ret = message_init(&(mime_part->msg), mime_part) ) == 0) {
if ( ( ret = message_create(&(mime_part->msg), mime_part) ) == 0) {
message_set_header(mime_part->msg, mime_part->hdr, mime_part);
message_set_size (mime_part->msg, mime_part->body_len, mime_part);
if ( ( ret = stream_init(&stream, mime_part) ) == 0 ) {
if ( ( ret = stream_set_read(stream, _mime_message_read, mime_part) ) == 0 ) {
if ( ( ret = message_set_stream( mime_part->msg, stream, mime_part) ) == 0 ) {
if ( ( ret = body_create(&body, mime_part) ) == 0 ) {
if ( ( ret = stream_create(&stream, mime_part) ) == 0 ) {
stream_set_read(stream, _mime_message_read, mime_part);
body_set_size (body, _mime_body_size, mime_part);
body_set_stream( body, stream, mime_part);
*newmsg = mime_part->msg;
return 0;
}
}
stream_destroy(&stream, mime_part);
}
message_destroy(&mime_part->msg, mime_part);
}
}
......@@ -515,6 +536,7 @@ int mime_unencapsulate(mime_t mime, message_t msg, message_t *newmsg)
}
}
}
}
return ret;
}
......@@ -538,7 +560,7 @@ int mime_add_part(mime_t mime, message_t msg)
{
if ( mime == NULL || msg == NULL || ( mime->flags & MIME_NEW_MESSAGE ) == 0 )
return EINVAL;
return ENOTSUP;
return _mime_append_part(mime, msg, 0, 0, FALSE);
}
int mime_get_message(mime_t mime, message_t *msg)
......@@ -548,3 +570,4 @@ int mime_get_message(mime_t mime, message_t *msg)
*msg = mime->msg;
return 0;
}
......
......@@ -88,7 +88,7 @@ registrar_add (struct url_registrar *new_ureg,
return ENOMEM;
}
}
mreg->_init = new_mreg->_init;
mreg->_create = new_mreg->_create;
mreg->_destroy = new_mreg->_destroy;
/* URL */
......@@ -110,7 +110,7 @@ registrar_add (struct url_registrar *new_ureg,
return ENOMEM;
}
}
ureg->_init = new_ureg->_init;
ureg->_create = new_ureg->_create;
ureg->_destroy = new_ureg->_destroy;
}
......
......@@ -39,7 +39,7 @@ static int get_query (const url_t, char *, size_t, size_t *);
static int get_id (const url_t, int *);
int
url_init (url_t * purl, const char *name)
url_create (url_t * purl, const char *name)
{
int status = EINVAL;
struct url_registrar *ureg;
......@@ -87,7 +87,7 @@ url_init (url_t * purl, const char *name)
/* Found one initialize it */
if (status == 0)
{
status = ureg->_init (purl, name);
status = ureg->_create (purl, name);
if (status == 0)
{
url_t url = *purl;
......
......@@ -23,12 +23,12 @@
#include <string.h>
static void url_file_destroy (url_t *purl);
static int url_file_init (url_t *purl, const char *name);
static int url_file_create (url_t *purl, const char *name);
struct url_registrar _url_file_registrar =
{
"file:",
url_file_init, url_file_destroy
url_file_create, url_file_destroy
};
static void
......@@ -48,7 +48,7 @@ url_file_destroy (url_t *purl)
UNIX box
*/
static int
url_file_init (url_t *purl, const char *name)
url_file_create (url_t *purl, const char *name)
{
url_t url;
struct url_registrar *ureg = &_url_mbox_registrar;
......@@ -64,7 +64,7 @@ url_file_init (url_t *purl, const char *name)
return ENOMEM;
/* TYPE */
url->_init = ureg->_init;
url->_create = ureg->_create;
url->_destroy = ureg->_destroy;
/* SCHEME */
......
......@@ -19,13 +19,13 @@
#include <registrar.h>
#include <errno.h>
static int url_imap_init (url_t *purl, const char *name);
static int url_imap_create (url_t *purl, const char *name);
static void url_imap_destroy (url_t *purl);
struct url_registrar _url_imap_registrar =
{
"imap://",
url_imap_init, url_imap_destroy
url_imap_create, url_imap_destroy
};
static void
......@@ -36,7 +36,7 @@ url_imap_destroy (url_t *purl)
}
static int
url_imap_init (url_t *purl, const char *name)
url_imap_create (url_t *purl, const char *name)
{
(void)purl; (void)name;
return ENOSYS;
......
......@@ -19,13 +19,13 @@
#include <registrar.h>
#include <errno.h>
static int url_mailto_init (url_t *purl, const char *name);
static int url_mailto_create (url_t *purl, const char *name);
static void url_mailto_destroy (url_t *purl);
struct url_registrar _url_mailto_registrar =
{
"mailto:",
url_mailto_init, url_mailto_destroy
url_mailto_create, url_mailto_destroy
};
static void
......@@ -36,7 +36,7 @@ url_mailto_destroy (url_t *purl)
}
static int
url_mailto_init (url_t *purl, const char *name)
url_mailto_create (url_t *purl, const char *name)
{
(void)purl; (void)name;
return ENOSYS;
......
......@@ -23,12 +23,12 @@
#include <string.h>
static void url_mbox_destroy (url_t *purl);
static int url_mbox_init (url_t *purl, const char *name);
static int url_mbox_create (url_t *purl, const char *name);
struct url_registrar _url_mbox_registrar =
{
"/",
url_mbox_init, url_mbox_destroy
url_mbox_create, url_mbox_destroy
};
static void
......@@ -48,7 +48,7 @@ url_mbox_destroy (url_t *purl)
UNIX box
*/
static int
url_mbox_init (url_t *purl, const char *name)
url_mbox_create (url_t *purl, const char *name)
{
url_t url;
struct url_registrar *ureg = &_url_mbox_registrar;
......@@ -64,7 +64,7 @@ url_mbox_init (url_t *purl, const char *name)
return ENOMEM;
/* TYPE */
url->_init = ureg->_init;
url->_create = ureg->_create;
url->_destroy = ureg->_destroy;
/* SCHEME */
......
......@@ -23,12 +23,12 @@
#include <string.h>
static void url_maildir_destroy (url_t *purl);
static int url_maildir_init (url_t *purl, const char *name);
static int url_maildir_create (url_t *purl, const char *name);
struct url_registrar _url_maildir_registrar =
{
"maildir:",
url_maildir_init, url_maildir_destroy
url_maildir_create, url_maildir_destroy
};
static void
......@@ -49,7 +49,7 @@ url_maildir_destroy (url_t *purl)
maildir:
*/
static int
url_maildir_init (url_t *purl, const char *name)
url_maildir_create (url_t *purl, const char *name)
{
url_t url;
struct url_registrar *ureg = &_url_maildir_registrar;
......@@ -67,7 +67,7 @@ url_maildir_init (url_t *purl, const char *name)
return EINVAL;
/* TYPE */
url->_init = ureg->_init;
url->_create = ureg->_create;
url->_destroy = ureg->_destroy;
/* SCHEME */
......
......@@ -23,12 +23,12 @@
#include <string.h>
static void url_mh_destroy (url_t *purl);
static int url_mh_init (url_t *purl, const char *name);
static int url_mh_create (url_t *purl, const char *name);
struct url_registrar _url_mh_registrar =
{
"mh:",
url_mh_init, url_mh_destroy
url_mh_create, url_mh_destroy
};
static void
......@@ -49,7 +49,7 @@ url_mh_destroy (url_t *purl)
mh:
*/
static int
url_mh_init (url_t *purl, const char *name)
url_mh_create (url_t *purl, const char *name)
{
url_t url;
struct url_registrar *ureg = &_url_mh_registrar;
......@@ -67,7 +67,7 @@ url_mh_init (url_t *purl, const char *name)
return ENOMEM;
/* TYPE */
url->_init = ureg->_init;
url->_create = ureg->_create;
url->_destroy = ureg->_destroy;
/* SCHEME */
......
......@@ -23,12 +23,12 @@
#include <string.h>
static void url_mmdf_destroy (url_t *purl);
static int url_mmdf_init (url_t *purl, const char *name);
static int url_mmdf_create (url_t *purl, const char *name);
struct url_registrar _url_mmdf_registrar =
{
"mmdf:",
url_mmdf_init, url_mmdf_destroy
url_mmdf_create, url_mmdf_destroy
};
static void
......@@ -49,7 +49,7 @@ url_mmdf_destroy (url_t *purl)
mmdf:
*/
static int
url_mmdf_init (url_t *purl, const char *name)
url_mmdf_create (url_t *purl, const char *name)
{
url_t url;
struct url_registrar *ureg = &_url_mmdf_registrar;
......@@ -67,7 +67,7 @@ url_mmdf_init (url_t *purl, const char *name)
return ENOMEM;
/* TYPE */
url->_init = ureg->_init;
url->_create = ureg->_create;
url->_destroy = ureg->_destroy;
/* SCHEME */
......
......@@ -25,12 +25,12 @@
#include <errno.h>
static void url_pop_destroy (url_t *purl);
static int url_pop_init (url_t *purl, const char *name);
static int url_pop_create (url_t *purl, const char *name);
struct url_registrar _url_pop_registrar =
{
"pop://",
url_pop_init, url_pop_destroy
url_pop_create, url_pop_destroy
};
static int get_auth (const url_pop_t up, char *s, size_t len, size_t *);
......@@ -80,7 +80,7 @@ url_pop_destroy (url_t *purl)
pop://<user>;AUTH=<auth>@<host>:<port>
*/
static int
url_pop_init (url_t *purl, const char *name)
url_pop_create (url_t *purl, const char *name)
{
const char *host_port, *indexe;
struct url_registrar *ureg = &_url_pop_registrar;
......@@ -101,7 +101,7 @@ url_pop_init (url_t *purl, const char *name)
up->_get_auth = get_auth;
/* TYPE */
url->_init = _url_pop_registrar._init;
url->_create = _url_pop_registrar._create;
url->_destroy = _url_pop_registrar._destroy;
/* SCHEME */
......
......@@ -23,12 +23,12 @@
#include <string.h>
static void url_unix_destroy (url_t *purl);
static int url_unix_init (url_t *purl, const char *name);
static int url_unix_create (url_t *purl, const char *name);
struct url_registrar _url_unix_registrar =
{
"unix:",
url_unix_init, url_unix_destroy
url_unix_create, url_unix_destroy
};
static void
......@@ -49,7 +49,7 @@ url_unix_destroy (url_t *purl)
unix:/path
*/
static int
url_unix_init (url_t *purl, const char *name)
url_unix_create (url_t *purl, const char *name)
{
url_t url;
struct url_registrar *ureg = &_url_unix_registrar;
......@@ -67,7 +67,7 @@ url_unix_init (url_t *purl, const char *name)
return ENOMEM;
/* TYPE */
url->_init = ureg->_init;
url->_create = ureg->_create;
url->_destroy = ureg->_destroy;
/* SCHEME */
......