Commit 9dde33c3 9dde33c3c9cdfcd3f531f5a83d8a5679cdde037f by Alain Magloire

Snow storm, good took the opportunity to rewrite one time to many

the registrar/record code, still fuzzy.  Implemented the folder for Mbox.
and various cleaning.
1 parent ed63b7f6
......@@ -23,6 +23,7 @@ envelope.c \
file_stream.c \
folder.c \
folder_mbox.c \
folder_pop.c \
header.c \
iterator.c \
list.c \
......
......@@ -55,7 +55,8 @@ folder_create (folder_t *pfolder, const char *name)
{
int status = EINVAL;
record_t record = NULL;
folder_entry_t entry = NULL;
int (*f_init) __P ((folder_t)) = NULL;
int (*u_init) __P ((url_t)) = NULL;
iterator_t iterator;
list_t list;
int found = 0;
......@@ -74,8 +75,9 @@ folder_create (folder_t *pfolder, const char *name)
iterator_current (iterator, (void **)&record);
if (record_is_scheme (record, name))
{
record_get_folder (record, &entry);
if (entry)
record_get_folder (record, &f_init);
record_get_url (record, &u_init);
if (f_init && u_init)
{
found = 1;
break;
......@@ -92,7 +94,7 @@ folder_create (folder_t *pfolder, const char *name)
/* Parse the url, it may be a bad one and we should bailout if this
failed. */
if ((status = url_create (&url, name) != 0)
|| (status = entry->_url_init (url)) != 0)
|| (status = u_init (url)) != 0)
return status;
monitor_wrlock (&folder_lock);
......@@ -122,7 +124,7 @@ folder_create (folder_t *pfolder, const char *name)
if (status == 0)
{
/* Create the concrete folder type. */
status = entry->_folder_init (folder);
status = f_init (folder);
if (status == 0)
{
*pfolder = folder;
......@@ -350,11 +352,19 @@ folder_list_destroy (struct folder_list ***pflist, size_t count)
}
int
folder_delete_mailbox (folder_t folder, const char *name)
folder_delete (folder_t folder, const char *name)
{
if (folder == NULL || folder->_delete_mailbox == NULL)
if (folder == NULL || folder->_delete == NULL)
return ENOSYS;
return folder->_delete_mailbox (folder, name);
return folder->_delete (folder, name);
}
int
folder_rename (folder_t folder, const char *oldname, const char *newname)
{
if (folder == NULL || folder->_rename == NULL)
return ENOSYS;
return folder->_rename (folder, oldname, newname);
}
int
......
......@@ -24,30 +24,73 @@
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <glob.h>
#include <stdio.h>
#include <folder0.h>
#include <registrar0.h>
/* We export url parsing and the initialisation of
the mailbox, via the register entry/record. */
static int fmbox_init (folder_t);
static struct _record _mbox_record =
{
MU_MBOX_SCHEME,
_url_mbox_init, /* Mailbox init. */
_mailbox_mbox_init, /* Mailbox init. */
NULL, /* Mailer init. */
_folder_mbox_init, /* Folder init. */
NULL, /* No need for an back pointer. */
NULL, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
NULL, /* _get_mailer method. */
NULL /* _get_folder method. */
};
record_t mbox_record = &_mbox_record;
struct folder_entry _fmbox_entry =
static struct _record _file_record =
{
url_path_init, fmbox_init
MU_FILE_SCHEME,
_url_file_init, /* Mailbox init. */
_mailbox_file_init, /* Mailbox init. */
NULL, /* Mailer init. */
_folder_mbox_init, /* Folder init. */
NULL, /* No need for an owner. */
NULL, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
NULL, /* _get_mailer method. */
NULL /* _get_folder method. */
};
record_t file_record = &_file_record;
/* We export two functions: url parsing and the initialisation of
the mailbox, via the register entry/record. */
folder_entry_t fmbox_entry = &_fmbox_entry;
static struct _record _path_record =
{
MU_PATH_SCHEME,
_url_path_init, /* Mailbox init. */
_mailbox_file_init, /* Mailbox init. */
NULL, /* Mailer init. */
_folder_mbox_init, /* Folder init. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_url method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
};
record_t path_record = &_path_record;
static void fmbox_destroy (folder_t);
static int fmbox_open (folder_t, int);
static int fmbox_close (folder_t);
static int fmbox_delete (folder_t, const char *);
static int fmbox_list (folder_t, const char *,
/* lsub/subscribe/unsubscribe are not needed. */
static void folder_mbox_destroy (folder_t);
static int folder_mbox_open (folder_t, int);
static int folder_mbox_close (folder_t);
static int folder_mbox_delete (folder_t, const char *);
static int folder_mbox_rename (folder_t , const char *, const char *);
static int folder_mbox_list (folder_t, const char *,
struct folder_list ***, size_t *);
static int fmbox_list0 (const char *, struct folder_list ***, size_t *, int);
static char *get_pathname (const char *, const char *);
struct _fmbox
{
......@@ -56,11 +99,10 @@ struct _fmbox
typedef struct _fmbox *fmbox_t;
static int
fmbox_init (folder_t folder)
int
_folder_mbox_init (folder_t folder)
{
fmbox_t dfolder;
//char *dirname;
size_t name_len = 0;
dfolder = folder->data = calloc (1, sizeof (dfolder));
......@@ -77,20 +119,20 @@ fmbox_init (folder_t folder)
}
url_get_path (folder->url, dfolder->dirname, name_len + 1, NULL);
folder->_init = fmbox_init;
folder->_destroy = fmbox_destroy;
folder->_destroy = folder_mbox_destroy;
folder->_open = fmbox_open;
folder->_close = fmbox_close;
folder->_open = folder_mbox_open;
folder->_close = folder_mbox_close;
folder->_list = fmbox_list;
folder->_delete_mailbox = fmbox_delete;
folder->_list = folder_mbox_list;
folder->_delete = folder_mbox_delete;
folder->_rename = folder_mbox_rename;
return 0;
}
void
fmbox_destroy (folder_t folder)
folder_mbox_destroy (folder_t folder)
{
if (folder->data)
{
......@@ -102,104 +144,160 @@ fmbox_destroy (folder_t folder)
}
}
/* Noop. */
static int
fmbox_open (folder_t folder, int flags)
folder_mbox_open (folder_t folder, int flags)
{
(void)(folder);
(void)(flags);
return 0;
}
/* Noop. */
static int
fmbox_close (folder_t folder)
folder_mbox_close (folder_t folder)
{
(void)(folder);
return 0;
}
static int
fmbox_delete (folder_t folder, const char *dirname)
folder_mbox_delete (folder_t folder, const char *filename)
{
(void)(folder);
(void)dirname;
return 0;
fmbox_t fmbox = folder->data;
if (filename)
{
int status = 0;
char *pathname = get_pathname (fmbox->dirname, filename);
if (pathname)
{
if (remove (pathname) != 0)
status = errno;
free (pathname);
}
else
status = ENOMEM;
return status;
}
return EINVAL;
}
static int
fmbox_list (folder_t folder, const char *pattern,
struct folder_list ***pflist, size_t *pnum)
folder_mbox_rename (folder_t folder, const char *oldpath, const char *newpath)
{
fmbox_t fmbox = folder->data;
struct folder_list **list = NULL;
char *dirname = NULL;
int status;
size_t num = 0;
if (pattern == NULL)
if (oldpath && newpath)
{
dirname = strdup (fmbox->dirname);
}
else if (pattern[0] != '/')
int status = 0;
char *pathold = get_pathname (fmbox->dirname, oldpath);
if (pathold)
{
size_t len = strlen (pattern);
dirname = calloc (strlen (fmbox->dirname) + len + 2, sizeof (char));
if (dirname)
sprintf (dirname, "%s/%s", fmbox->dirname, pattern);
char *pathnew = get_pathname (fmbox->dirname, newpath);
if (pathnew)
{
if (rename (pathold, pathnew) != 0)
status = errno;
free (pathnew);
}
else
dirname = strdup (pattern);
if (dirname == NULL)
return errno;
status = fmbox_list0 (dirname, &list, &num, (strchr (dirname, '*') != NULL));
if (status == 0)
{
if (pflist)
*pflist = list;
if (pnum)
*pnum = num;
status = ENOMEM;
free (pathold);
}
else
status = ENOMEM;
return status;
}
return EINVAL;
}
/* The listing is not recursif and we use glob() some expansion for us.
Unfortunately glov() does not expand the '~'. We also return
The full pathname so it can be use to create other folders. */
static int
fmbox_list0 (const char *dirname, struct folder_list ***pflist,
size_t *pnum, int recurse)
folder_mbox_list (folder_t folder, const char *pattern,
struct folder_list ***pflist, size_t *pnum)
{
DIR *dp;
struct dirent *rp;
struct stat stbuf;
struct folder_list **flist = *pflist;
char buf[512];
dp = opendir (dirname);
if (dp == NULL)
fmbox_t fmbox = folder->data;
char *pathname = NULL;
int status;
size_t num = 0;
glob_t gl;
pathname = get_pathname (fmbox->dirname, pattern);
if (pathname)
{
return errno;
memset(&gl, 0, sizeof(gl));
status = glob (pathname, 0, NULL, &gl);
free (pathname);
num = gl.gl_pathc;
}
while ((rp = readdir (dp)) != NULL)
else
status = ENOMEM;
/* Build the folder list from glob. */
if (status == 0)
{
if (pflist)
{
struct folder_list **flist;
flist = calloc (num, sizeof (*flist));
if (flist)
{
if (rp->d_name[0] == '.')
continue;
flist = realloc (flist, (*pnum + 1) * sizeof (*flist));
flist[*pnum] = calloc (1, sizeof (**flist));
sprintf (buf, "%s/%s", dirname, rp->d_name);
if (stat (buf, &stbuf) == 0)
size_t i;
struct stat stbuf;
for (i = 0; i < num; i++)
{
flist[i] = calloc (1, sizeof (**flist));
if (flist[i] == NULL
|| (flist[i]->name = strdup (gl.gl_pathv[i])) == NULL)
{
int isdir = S_ISDIR(stbuf.st_mode);
if (isdir)
flist[*pnum]->attribute |= MU_FOLDER_ATTRIBUTE_NOSELECT;
flist[*pnum]->name = strdup (buf);
(*pnum)++;
if (isdir && recurse)
num = i;
break;
}
if (stat (gl.gl_pathv[i], &stbuf) == 0)
{
fmbox_list0 (buf, &flist, pnum, recurse);
if (S_ISDIR(stbuf.st_mode))
flist[i]->type = MU_FOLDER_ATTRIBUTE_DIRECTORY;
if (S_ISREG(stbuf.st_mode))
flist[i]->type = MU_FOLDER_ATTRIBUTE_FILE;
}
flist[i]->separator = '/';
}
else
(*pnum)++;
}
closedir (dp);
else
status = ENOMEM;
*pflist = flist;
return 0;
}
globfree (&gl);
}
else
{
status = (status == GLOB_NOSPACE) ? ENOMEM :
((status == GLOB_NOMATCH) ? ENOENT : EINVAL);
}
if (pnum)
*pnum = num;
return status;
}
static char *
get_pathname (const char *dirname, const char *basename)
{
char *pathname = NULL;
/* null basename gives dirname. */
if (basename == NULL)
pathname = (dirname) ? strdup (dirname) : strdup (".");
/* Absolute. */
else if (basename[0] == '/')
pathname = strdup (basename);
/* Relative. */
else
{
size_t len = strlen (basename);
pathname = calloc (strlen (dirname) + len + 2, sizeof (char));
if (pathname)
sprintf (pathname, "%s/%s", dirname, basename);
}
return pathname;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General 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 <folder0.h>
#include <registrar0.h>
/* We export url parsing and the initialisation of
the mailbox, via the register entry/record. */
static struct _record _pop_record =
{
MU_POP_SCHEME,
_url_pop_init, /* Mailbox init. */
_mailbox_pop_init, /* Mailbox init. */
NULL, /* Mailer init. */
_folder_pop_init, /* Folder init. */
NULL, /* No need for an back pointer. */
NULL, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
NULL, /* _get_mailer method. */
NULL /* _get_folder method. */
};
record_t pop_record = &_pop_record;
int
_folder_pop_init (folder_t folder)
{
(void)folder;
return 0;
}
......@@ -59,14 +59,18 @@ struct _folder
/* Public methods */
int (*_init) __P ((folder_t));
void (*_destroy) __P ((folder_t));
int (*_open) __P ((folder_t, int flag));
int (*_close) __P ((folder_t));
int (*_list) __P ((folder_t, const char *,
struct folder_list ***, size_t *));
int (*_delete_mailbox) __P ((folder_t, const char *));
int (*_lsub) __P ((folder_t, const char *,
struct folder_list ***, size_t *));
int (*_delete) __P ((folder_t, const char *));
int (*_rename) __P ((folder_t, const char *, const char *));
int (*_subscribe) __P ((folder_t, const char *));
int (*_unsubscribe) __P ((folder_t, const char *));
};
......
......@@ -65,7 +65,6 @@ struct _mailbox
/* Public methods */
int (*_init) __P ((mailbox_t));
void (*_destroy) __P ((mailbox_t));
int (*_open) __P ((mailbox_t, int flag));
......
......@@ -65,7 +65,6 @@ struct _mailer
void *data;
/* Public methods. */
int (*_init) __P ((mailer_t));
void (*_destroy) __P ((mailer_t));
int (*_open) __P ((mailer_t, int flags));
int (*_close) __P ((mailer_t));
......
......@@ -36,19 +36,48 @@ extern "C" {
# endif
#endif /*__P */
struct _record
{
const char *scheme;
mailbox_entry_t mailbox;
mailer_entry_t mailer;
folder_entry_t folder;
int is_allocated;
void *onwer;
int (*_is_scheme) __P ((record_t, const char *));
int (*_get_mailbox) __P ((record_t, mailbox_entry_t *_mailbox));
int (*_get_mailer) __P ((record_t, mailer_entry_t *_mailer));
int (*_get_folder) __P ((record_t, folder_entry_t *_mailer));
};
#define MU_POP_PORT 110
#define MU_POP_SCHEME "pop://"
#define MU_POP_SCHEME_LEN 6
extern int _url_pop_init __P ((url_t));
extern int _mailbox_pop_init __P ((mailbox_t));
extern int _folder_pop_init __P ((folder_t));
#define MU_IMAP_PORT 143
#define MU_IMAP_SCHEME "imap://"
#define MU_IMAP_SCHEME_LEN 7
extern int _url_imap_init __P ((url_t));
extern int _mailbox_imap_init __P ((mailbox_t));
extern int _folder_imap_init __P ((folder_t));
#define MU_MBOX_SCHEME "mbox:"
#define MU_MBOX_SCHEME_LEN 5
extern int _url_mbox_init __P ((url_t));
extern int _mailbox_mbox_init __P ((mailbox_t));
extern int _folder_mbox_init __P ((folder_t));
#define MU_FILE_SCHEME "file:"
#define MU_FILE_SCHEME_LEN 5
extern int _url_file_init __P ((url_t));
extern int _mailbox_file_init __P ((mailbox_t));
extern int _folder_file_init __P ((folder_t));
#define MU_PATH_SCHEME "/"
#define MU_PATH_SCHEME_LEN 1
extern int _url_path_init __P ((url_t));
extern int _mailbox_path_init __P ((mailbox_t));
extern int _folder_path_init __P ((folder_t));
#define MU_SMTP_SCHEME "smtp://"
#define MU_SMTP_SCHEME_LEN 7
#define MU_SMTP_PORT 25
extern int _url_smtp_init __P ((url_t));
extern int _mailer_smtp_init __P ((mailer_t));
#define MU_SENDMAIL_SCHEME "sendmail:"
#define MU_SENDMAIL_SCHEME_LEN 9
extern int _url_sendmail_init __P ((url_t));
extern int _mailer_sendmail_init __P ((mailer_t));
#ifdef __cplusplus
}
......
......@@ -52,7 +52,6 @@ struct _url
void *data;
int (*_init) __P ((url_t url));
void (*_destroy) __P ((url_t url));
/* Methods */
......
......@@ -36,7 +36,8 @@ mailbox_create (mailbox_t *pmbox, const char *name)
{
int status = EINVAL;
record_t record = NULL;
mailbox_entry_t entry = NULL;
int (*m_init) __P ((mailbox_t)) = NULL;
int (*u_init) __P ((url_t)) = NULL;
iterator_t iterator;
list_t list;
int found = 0;
......@@ -55,8 +56,9 @@ mailbox_create (mailbox_t *pmbox, const char *name)
iterator_current (iterator, (void **)&record);
if (record_is_scheme (record, name))
{
record_get_mailbox (record, &entry);
if (entry)
record_get_mailbox (record, &m_init);
record_get_url (record, &u_init);
if (m_init && u_init)
{
found = 1;
break;
......@@ -87,7 +89,7 @@ mailbox_create (mailbox_t *pmbox, const char *name)
/* Parse the url, it may be a bad one and we should bailout if this
failed. */
if ((status = url_create (&url, name)) != 0
|| (status = entry->_url_init (url)) != 0)
|| (status = u_init (url)) != 0)
{
mailbox_destroy (&mbox);
return status;
......@@ -95,7 +97,7 @@ mailbox_create (mailbox_t *pmbox, const char *name)
mbox->url = url;
/* Create the concrete mailbox type. */
status = entry->_mailbox_init (mbox);
status = m_init (mbox);
if (status != 0)
{
mailbox_destroy (&mbox);
......
......@@ -36,7 +36,8 @@ mailer_create (mailer_t *pmailer, const char *name, int id)
{
int status = EINVAL;
record_t record = NULL;
mailer_entry_t entry = NULL;
int (*m_init) __P ((mailer_t)) = NULL;
int (*u_init) __P ((url_t)) = NULL;
list_t list = NULL;
iterator_t iterator;
int found = 0;
......@@ -55,12 +56,15 @@ mailer_create (mailer_t *pmailer, const char *name, int id)
iterator_current (iterator, (void **)&record);
if (record_is_scheme (record, name))
{
status = record_get_mailer (record, &entry);
if (status == 0)
record_get_mailer (record, &m_init);
record_get_url (record, &u_init);
if (m_init && u_init)
{
found = 1;
break;
}
}
}
iterator_destroy (&iterator);
if (found)
......@@ -83,14 +87,14 @@ mailer_create (mailer_t *pmailer, const char *name, int id)
/* Parse the url, it may be a bad one and we should bailout if this
failed. */
if ((status = url_create (&url, name)) != 0
|| (status = entry->_url_init (url)) != 0)
|| (status = u_init (url)) != 0)
{
mailer_destroy (&mailer);
return status;
}
mailer->url = url;
status = entry->_mailer_init (mailer);
status = m_init (mailer);
if (status != 0)
{
mailer_destroy (&mailer);
......
......@@ -27,53 +27,6 @@
#include <mailbox0.h>
#include <registrar0.h>
static int mailbox_file_init (mailbox_t mbox);
/* Register variables. */
static struct mailbox_entry _file_entry =
{
url_file_init, mailbox_file_init
};
mailbox_entry_t file_entry = &_file_entry;
extern struct folder_entry _fmbox_entry;
static struct _record _file_record =
{
MU_FILE_SCHEME,
&_file_entry, /* Mailbox entry. */
NULL, /* Mailer entry. */
&_fmbox_entry, /* Folder entry. */
0, /* Not malloc()ed. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
};
record_t file_record = &_file_record;
/* Register variables. */
static struct mailbox_entry _path_entry =
{
url_path_init, mailbox_file_init
};
mailbox_entry_t path_entry = &_path_entry;
static struct _record _path_record =
{
MU_PATH_SCHEME,
&_path_entry, /* Mailbox entry. */
NULL, /* Mailer entry. */
&_fmbox_entry, /* Folder entry. */
0, /* Not malloc()ed. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
};
record_t path_record = &_path_record;
/*
Caveat there is no specific URL for file mailbox or simple path name,
<path_name>
......@@ -87,8 +40,8 @@ record_t path_record = &_path_record;
out to be wrong.
*/
static int
mailbox_file_init (mailbox_t mbox)
int
_mailbox_file_init (mailbox_t mbox)
{
struct stat st;
size_t len = 0;
......@@ -113,7 +66,7 @@ mailbox_file_init (mailbox_t mbox)
file does not exist. */
if (stat (path, &st) < 0)
{
status = mbox_entry->_mailbox_init (mbox);
status = _mailbox_mbox_init (mbox);
}
else if (S_ISREG (st.st_mode))
{
......@@ -121,12 +74,12 @@ mailbox_file_init (mailbox_t mbox)
FIXME: We should do an open() and try
to do a better reconnaissance of the type,
maybe MMDF. For now assume Unix MBox */
status = mbox_entry->_mailbox_init (mbox);
status = _mailbox_mbox_init (mbox);
}
/* Is that true ? Are all directories Maildir ?? */
else if (S_ISDIR (st.st_mode))
{
/*status = maildir_entry._mailbox_init (mbox);*/
/*status = _mailbox_maildir_init (mbox);*/
status = EINVAL;
}
......
......@@ -49,31 +49,6 @@
#define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED)
#define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2)
static int mbox_init (mailbox_t mailbox);
/* Registrar variables. */
static struct mailbox_entry _mbox_entry =
{
url_mbox_init, mbox_init
};
mailbox_entry_t mbox_entry = &_mbox_entry;
extern struct folder_entry _fmbox_entry;
static struct _record _mbox_record =
{
MU_MBOX_SCHEME,
&_mbox_entry, /* Mailbox entry. */
NULL, /* Mailer entry. */
&_fmbox_entry, /* Folder entry. */
0, /* Not malloc()ed. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
};
record_t mbox_record = &_mbox_record;
static void mbox_destroy (mailbox_t);
struct _mbox_message;
......@@ -170,8 +145,8 @@ static void mbox_cleanup (void *);
/* We allocate the mbox_data_t struct, but don't do any parsing on the name or
even test for existence. However we do strip any leading "mbox:" part of
the name, this is suppose to be the protocol/scheme name. */
static int
mbox_init (mailbox_t mailbox)
int
_mailbox_mbox_init (mailbox_t mailbox)
{
mbox_data_t mud;
size_t name_len;
......@@ -208,7 +183,6 @@ mbox_init (mailbox_t mailbox)
mud->state = MBOX_NO_STATE;
/* Overloading the default. */
mailbox->_init = mbox_init;
mailbox->_destroy = mbox_destroy;
mailbox->_open = mbox_open;
......@@ -1189,6 +1163,7 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg)
return 0;
}
/* FIXME: We have to generate a Message-ID: if the message have none. */
static int
mbox_append_message (mailbox_t mailbox, message_t msg)
{
......
......@@ -39,31 +39,6 @@
#include <registrar0.h>
#include <bio.h>
static int pop_init (mailbox_t);
static struct mailbox_entry _pop_entry =
{
url_pop_init, pop_init
};
static struct _record _pop_record =
{
MU_POP_SCHEME,
&_pop_entry, /* Mailbox entry. */
NULL, /* Mailer entry. */
NULL, /* folder entry. */
0, /* Not malloc()ed. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
};
/* We export two functions: url parsing and the initialisation of
the mailbox, via the register entry/record. */
record_t pop_record = &_pop_record;
mailbox_entry_t pop_entry = &_pop_entry;
/* Advance declarations. */
struct _pop_data;
struct _pop_message;
......@@ -259,8 +234,8 @@ while (0)
/* Parse the url, allocate mailbox_t, allocate pop internal structures. */
static int
pop_init (mailbox_t mbox)
int
_mailbox_pop_init (mailbox_t mbox)
{
pop_data_t mpd;
......@@ -274,7 +249,6 @@ pop_init (mailbox_t mbox)
mpd->state = POP_NO_STATE; /* Init with no state. */
/* Initialize the structure. */
mbox->_init = pop_init;
mbox->_destroy = pop_destroy;
mbox->_open = pop_open;
......
......@@ -28,7 +28,7 @@
#include <registrar0.h>
/* NOTE: We will leak here since the monitor and the registrar will never
be release. */
be release. That's ok we can leave with this, it's only done once. */
static list_t registrar_list;
struct _monitor registrar_monitor = MU_MONITOR_INITIALIZER;
......@@ -82,43 +82,144 @@ record_is_scheme (record_t record, const char *scheme)
}
int
record_get_mailbox (record_t record, mailbox_entry_t *pmbox)
record_set_scheme (record_t record, const char *scheme)
{
if (record == NULL || pmbox == NULL)
if (record == NULL)
return EINVAL;
record->scheme = scheme;
return 0;
}
int
record_set_is_scheme (record_t record, int (*_is_scheme)
__P ((record_t, const char *)))
{
if (record == NULL)
return EINVAL;
record->_is_scheme = _is_scheme;
return 0;
}
int
record_get_url (record_t record, int (*(*_purl)) __P ((url_t)))
{
if (record == NULL || _purl == NULL)
return EINVAL;
/* Overload. */
if (record->_get_url)
return record->_get_url (record, _purl);
*_purl = record->_url;
return 0;
}
int
record_set_url (record_t record, int (*_url) __P ((url_t)))
{
if (record == NULL)
return EINVAL;
record->_url = _url;
return 0;
}
int
record_set_get_url (record_t record, int (*_get_url)
__P ((record_t, int (*(*)) __P ((url_t)))))
{
if (record == NULL)
return EINVAL;
record->_get_url = _get_url;
return 0;
}
int
record_get_mailbox (record_t record, int (*(*_pmailbox)) __P ((mailbox_t)))
{
if (record == NULL || _pmailbox == NULL)
return EINVAL;
/* Overload. */
if (record->_get_mailbox)
return record->_get_mailbox (record, pmbox);
return record->_get_mailbox (record, _pmailbox);
*_pmailbox = record->_mailbox;
return 0;
}
*pmbox = record->mailbox;
int
record_set_mailbox (record_t record, int (*_mailbox) __P ((mailbox_t)))
{
if (record)
return EINVAL;
record->_mailbox = _mailbox;
return 0;
}
int
record_get_mailer (record_t record, mailer_entry_t *pml)
record_set_get_mailbox (record_t record, int (*_get_mailbox)
__P ((record_t, int (*(*)) __P((mailbox_t)))))
{
if (record == NULL || pml == NULL)
if (record)
return EINVAL;
record->_get_mailbox = _get_mailbox;
return 0;
}
int
record_get_mailer (record_t record, int (*(*_pmailer)) __P ((mailer_t)))
{
if (record == NULL || _pmailer == NULL)
return EINVAL;
/* Overload. */
if (record->_get_mailer)
return record->_get_mailer (record, pml);
return record->_get_mailer (record, _pmailer);
*_pmailer = record->_mailer;
return 0;
}
*pml = record->mailer;
int
record_set_mailer (record_t record, int (*_mailer) __P ((mailer_t)))
{
if (record)
return EINVAL;
record->_mailer = _mailer;
return 0;
}
int
record_get_folder (record_t record, folder_entry_t *pfolder)
record_set_get_mailer (record_t record, int (*_get_mailer)
__P ((record_t, int (*(*)) __P ((mailer_t)))))
{
if (record == NULL || pfolder == NULL)
if (record == NULL)
return EINVAL;
record->_get_mailer = _get_mailer;
return 0;
}
int
record_get_folder (record_t record, int (*(*_pfolder)) __P ((folder_t)))
{
if (record == NULL || _pfolder == NULL)
return EINVAL;
/* Overload. */
if (record->_get_folder)
return record->_get_folder (record, pfolder);
return record->_get_folder (record, _pfolder);
*_pfolder = record->_folder;
return 0;
}
*pfolder = record->folder;
int
record_set_folder (record_t record, int (*_folder) __P ((folder_t)))
{
if (record == NULL)
return EINVAL;
record->_folder = _folder;
return 0;
}
int
record_set_get_folder (record_t record, int (*_get_folder)
__P ((record_t, int (*(*)) __P ((folder_t)))))
{
if (record == NULL)
return EINVAL;
record->_get_folder = _get_folder;
return 0;
}
......
......@@ -31,30 +31,23 @@
#include <mailer0.h>
#include <registrar0.h>
static int sendmail_init (mailer_t);
static struct mailer_entry _sendmail_entry =
{
url_sendmail_init, sendmail_init
};
static struct _record _sendmail_record =
{
MU_SENDMAIL_SCHEME,
_url_sendmail_init, /* url init. */
NULL, /* Mailbox entry. */
&_sendmail_entry, /* Mailer entry. */
_mailer_sendmail_init, /* Mailer entry. */
NULL, /* Folder entry. */
0, /* Not malloc()ed. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
NULL, /* No need for a back pointer. */
NULL, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
NULL, /* _get_mailer method. */
NULL /* _get_folder method. */
};
/* We export two functions: url parsing and the initialisation of
/* We export, url parsing and the initialisation of
the mailbox, via the register entry/record. */
record_t sendmail_record = &_sendmail_record;
mailer_entry_t sendmail_entry = &_sendmail_entry;
struct _sendmail
{
......@@ -74,7 +67,7 @@ static int sendmail_close (mailer_t);
static int sendmail_send_message (mailer_t, message_t);
int
sendmail_init (mailer_t mailer)
_mailer_sendmail_init (mailer_t mailer)
{
sendmail_t sendmail;
......@@ -83,9 +76,7 @@ sendmail_init (mailer_t mailer)
if (mailer->data == NULL)
return ENOMEM;
sendmail->state = SENDMAIL_NO_STATE;
mailer->_init = sendmail_init;
mailer->_destroy = sendmail_destroy;
mailer->_open = sendmail_open;
mailer->_close = sendmail_close;
mailer->_send_message = sendmail_send_message;
......
......@@ -34,30 +34,23 @@
#include <registrar0.h>
#include <bio.h>
static int smtp_init (mailer_t);
static struct mailer_entry _smtp_entry =
{
url_smtp_init, smtp_init
};
static struct _record _smtp_record =
{
MU_SMTP_SCHEME,
NULL, /* Mailbox entry. */
&_smtp_entry, /* Mailer entry. */
NULL, /* Mailer entry. */
0, /* Not malloc()ed. */
NULL, /* No need for an owner. */
NULL, /* is_scheme method. */
NULL, /* get_mailbox method. */
NULL, /* get_mailer method. */
NULL /* get_folder method. */
_url_smtp_init, /* url init. */
NULL, /* Mailbox init. */
&_mailer_smtp_init, /* Mailer init. */
NULL, /* Folder init. */
NULL, /* No need for a back pointer. */
NULL, /* _is_scheme method. */
NULL, /* _get_url method. */
NULL, /* _get_mailbox method. */
NULL, /* _get_mailer method. */
NULL /* _get_folder method. */
};
/* We export two functions: url parsing and the initialisation of
/* We export : url parsing and the initialisation of
the mailbox, via the register entry/record. */
record_t smtp_record = &_smtp_record;
mailer_entry_t smtp_entry = &_smtp_entry;
struct _smtp
{
......@@ -144,7 +137,7 @@ static int get_rcpt (message_t , address_t *);
static int get_from (message_t , char *, address_t *);
int
smtp_init (mailer_t mailer)
_mailer_smtp_init (mailer_t mailer)
{
smtp_t smtp;
......@@ -152,10 +145,7 @@ smtp_init (mailer_t mailer)
smtp = mailer->data = calloc (1, sizeof (*smtp));
if (mailer->data == NULL)
return ENOMEM;
mailer->_init = smtp_init;
mailer->_destroy = smtp_destroy;
mailer->_open = smtp_open;
mailer->_close = smtp_close;
mailer->_send_message = smtp_send_message;
......
......@@ -23,10 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <mailutils/registrar.h>
#include <url0.h>
#include <registrar0.h>
int url_file_init (url_t purl);
static void url_file_destroy (url_t purl);
static void
......@@ -40,7 +39,7 @@ url_file_destroy (url_t url)
file:path
*/
int
url_file_init (url_t url)
_url_file_init (url_t url)
{
const char *name = url_to_string (url);
size_t len = strlen (name);
......@@ -53,7 +52,6 @@ url_file_init (url_t url)
/* do I need to decode url encoding '% hex hex' ? */
/* TYPE */
url->_init = url_file_init;
url->_destroy = url_file_destroy;
/* SCHEME */
......
......@@ -23,10 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <mailutils/registrar.h>
#include <registrar0.h>
#include <url0.h>
int url_mbox_init (url_t purl);
static void url_mbox_destroy (url_t purl);
static void
......@@ -40,7 +39,7 @@ url_mbox_destroy (url_t url)
mbox:path
*/
int
url_mbox_init (url_t url)
_url_mbox_init (url_t url)
{
const char *name = url_to_string (url);
size_t len = strlen (name);
......@@ -53,7 +52,6 @@ url_mbox_init (url_t url)
/* do I need to decode url encoding '% hex hex' ? */
/* TYPE */
url->_init = url_mbox_init;
url->_destroy = url_mbox_destroy;
/* SCHEME */
......
......@@ -23,11 +23,10 @@
#include <stdlib.h>
#include <string.h>
#include <mailutils/registrar.h>
#include <registrar0.h>
#include <url0.h>
static void url_path_destroy (url_t);
int url_path_init (url_t);
static void
url_path_destroy (url_t url)
......@@ -36,7 +35,7 @@ url_path_destroy (url_t url)
}
int
url_path_init (url_t url)
_url_path_init (url_t url)
{
const char *name = url_to_string (url);
/* reject the obvious */
......@@ -46,7 +45,6 @@ url_path_init (url_t url)
/* FIXME: do I need to decode url encoding '% hex hex' ? */
/* TYPE */
url->_init = url_path_init;
url->_destroy = url_path_destroy;
/* SCHEME */
......
......@@ -24,8 +24,8 @@
#include <string.h>
#include <errno.h>
#include <mailutils/registrar.h>
#include <url0.h>
#include <registrar0.h>
static void url_pop_destroy (url_t url);
......@@ -40,7 +40,7 @@ url_pop_destroy (url_t url)
pop://[<user>;AUTH=<auth>@]<host>[:<port>]
*/
int
url_pop_init (url_t url)
_url_pop_init (url_t url)
{
const char *host_port, *indexe;
char *name = url->name;
......@@ -52,7 +52,6 @@ url_pop_init (url_t url)
/* do I need to decode url encoding '% hex hex' ? */
/* TYPE */
url->_init = url_pop_init;
url->_destroy = url_pop_destroy;
/* SCHEME */
......
......@@ -23,10 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <mailutils/registrar.h>
#include <registrar0.h>
#include <url0.h>
int url_sendmail_init (url_t purl);
static void url_sendmail_destroy (url_t purl);
static void
......@@ -40,7 +39,7 @@ url_sendmail_destroy (url_t url)
sendmail:path
*/
int
url_sendmail_init (url_t url)
_url_sendmail_init (url_t url)
{
const char *name = url_to_string (url);
size_t len = strlen (name);
......@@ -53,7 +52,6 @@ url_sendmail_init (url_t url)
/* do I need to decode url encoding '% hex hex' ? */
/* TYPE */
url->_init = url_sendmail_init;
url->_destroy = url_sendmail_destroy;
/* SCHEME */
......
......@@ -23,10 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <mailutils/registrar.h>
#include <registrar0.h>
#include <url0.h>
int url_smtp_init (url_t purl);
static void url_smtp_destroy (url_t purl);
static void
......@@ -40,7 +39,7 @@ url_smtp_destroy (url_t url)
file:path
*/
int
url_smtp_init (url_t url)
_url_smtp_init (url_t url)
{
const char *name = url_to_string (url);
size_t len = strlen (name);
......@@ -53,7 +52,6 @@ url_smtp_init (url_t url)
/* do I need to decode url encoding '% hex hex' ? */
/* TYPE */
url->_init = url_smtp_init;
url->_destroy = url_smtp_destroy;
/* SCHEME */
......