also drop the stupid mx_*_reg functions, rather use exter const mx_t's.
Signed-off-by: Pierre Habouzit <madcoder@madism.org>
return (0);
}
-mx_t* compress_reg_mx (void) {
- mx_t* fmt = p_new(mx_t, 1);
- fmt->type = M_COMPRESSED;
- fmt->local = 1;
- fmt->mx_is_magic = mbox_is_magic;
- fmt->mx_check_empty = mbox_check_empty;
- fmt->mx_access = access;
- fmt->mx_open_mailbox = mutt_open_read_compressed;
- return (fmt);
-}
+mx_t const compress_mx = {
+ M_COMPRESSED,
+ 1,
+ mbox_is_magic,
+ mbox_check_empty,
+ access,
+ mutt_open_read_compressed,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+};
int mutt_check_mailbox_compressed (CONTEXT *);
void mutt_fast_close_compressed (CONTEXT *);
-mx_t* compress_reg_mx (void);
+extern mx_t const compress_mx;
#endif /* _COMPRESS_H */
return (r);
}
-mx_t* imap_reg_mx (void) {
- mx_t* fmt = p_new(mx_t, 1);
-
- /* make up mx_t record... */
- fmt->type = M_IMAP;
- fmt->mx_is_magic = imap_is_magic;
- fmt->mx_access = imap_access;
- fmt->mx_open_mailbox = imap_open_mailbox;
- fmt->mx_open_new_message = imap_open_new_message;
- fmt->mx_acl_check = acl_check_imap;
- fmt->mx_fastclose_mailbox = imap_close_mailbox;
- fmt->mx_sync_mailbox = imap_sync_mailbox;
- fmt->mx_check_mailbox = _imap_check_mailbox;
- fmt->mx_commit_message = imap_commit_message;
- return (fmt);
-}
+mx_t const imap_mx = {
+ M_IMAP,
+ 0,
+ imap_is_magic,
+ NULL,
+ imap_access,
+ imap_open_mailbox,
+ imap_open_new_message,
+ acl_check_imap,
+ _imap_check_mailbox,
+ imap_close_mailbox,
+ imap_sync_mailbox,
+ imap_commit_message,
+};
#include "mx.h"
-int imap_is_magic (const char*, struct stat*);
-mx_t* imap_reg_mx (void);
+extern mx_t const imap_mx;
+
+int imap_is_magic(const char*, struct stat*);
#endif /* !_IMAP_MX_H */
start_curses ();
/* set defaults and read init files */
- mx_init ();
mutt_init (flags & M_NOSYSRC, commands);
string_list_wipe(&commands);
return (commit_message (msg, ctx, 0));
}
-static mx_t* reg_mx (void) {
- mx_t* fmt = p_new(mx_t, 1);
- fmt->local = 1;
- fmt->mx_check_empty = mbox_check_empty;
- fmt->mx_is_magic = mbox_is_magic;
- fmt->mx_access = access;
- fmt->mx_open_mailbox = mbox_open_mailbox;
- fmt->mx_open_new_message = mbox_open_new_message;
- fmt->mx_sync_mailbox = mbox_sync_mailbox;
- fmt->mx_check_mailbox = mbox_check_mailbox;
- return (fmt);
-}
+mx_t const mbox_mx = {
+ M_MBOX,
+ 1,
+ mbox_is_magic,
+ mbox_check_empty,
+ access,
+ mbox_open_mailbox,
+ mbox_open_new_message,
+ NULL,
+ mbox_check_mailbox,
+ NULL,
+ mbox_sync_mailbox,
+ mbox_commit_message,
+};
-mx_t* mbox_reg_mx (void) {
- mx_t* fmt = reg_mx ();
- fmt->type = M_MBOX;
- fmt->mx_commit_message = mbox_commit_message;
- return (fmt);
-}
-mx_t* mmdf_reg_mx (void) {
- mx_t* fmt = reg_mx ();
- fmt->type = M_MMDF;
- fmt->mx_commit_message = mmdf_commit_message;
- return (fmt);
-}
+mx_t const mmdf_mx = {
+ M_MMDF,
+ 1,
+ mbox_is_magic,
+ mbox_check_empty,
+ access,
+ mbox_open_mailbox,
+ mbox_open_new_message,
+ NULL,
+ mbox_check_mailbox,
+ NULL,
+ mbox_sync_mailbox,
+ mmdf_commit_message,
+};
#include "mx.h"
+extern mx_t const mbox_mx;
+extern mx_t const mmdf_mx;
+
/* TODO all of these must disappear to achieve good information hiding */
#define MMDF_SEP "\001\001\001\001\n"
int mbox_check_empty (const char*);
int mbox_is_magic (const char*, struct stat*);
-mx_t* mbox_reg_mx (void);
-mx_t* mmdf_reg_mx (void);
-
#endif
return (-1);
}
-/* routines common to maildir and mh */
-static mx_t* reg_mx (void) {
- mx_t* fmt = p_new(mx_t, 1);
- fmt->local = 1;
- fmt->mx_access = access;
- fmt->mx_sync_mailbox = mh_sync_mailbox;
- return (fmt);
-}
-
static int mh_commit (MESSAGE* msg, CONTEXT* ctx) {
return (mh_commit_message (msg, ctx, NULL));
}
return (maildir_commit_message (msg, ctx, NULL));
}
-mx_t* mh_reg_mx (void) {
- mx_t* fmt = reg_mx ();
- fmt->type = M_MH;
- fmt->mx_check_empty = mh_check_empty;
- fmt->mx_is_magic = mh_is_magic;
- fmt->mx_open_mailbox = mh_read_dir;
- fmt->mx_open_new_message = mh_open_new_message;
- fmt->mx_check_mailbox = mh_check_mailbox;
- fmt->mx_commit_message = mh_commit;
- return (fmt);
-}
+mx_t const maildir_mx = {
+ M_MAILDIR,
+ 1,
+ maildir_is_magic,
+ maildir_check_empty,
+ access,
+ maildir_read_dir,
+ maildir_open_new_message,
+ NULL,
+ maildir_check_mailbox,
+ NULL,
+ mh_sync_mailbox,
+ maildir_commit
+};
-mx_t* maildir_reg_mx (void) {
- mx_t* fmt = reg_mx ();
- fmt->type = M_MAILDIR;
- fmt->mx_check_empty = maildir_check_empty;
- fmt->mx_is_magic = maildir_is_magic;
- fmt->mx_open_mailbox = maildir_read_dir;
- fmt->mx_open_new_message = maildir_open_new_message;
- fmt->mx_check_mailbox = maildir_check_mailbox;
- fmt->mx_commit_message = maildir_commit;
- return (fmt);
-}
+mx_t const mh_mx = {
+ M_MH,
+ 1,
+ mh_is_magic,
+ mh_check_empty,
+ access,
+ mh_read_dir,
+ mh_open_new_message,
+ NULL,
+ mh_check_mailbox,
+ NULL,
+ mh_sync_mailbox,
+ mh_commit
+};
#include "mx.h"
+extern mx_t const maildir_mx;
+extern mx_t const mh_mx;
+
/* TODO all of these must disappear to achieve good information hiding */
int mh_buffy (const char *);
FILE *maildir_open_find_message (const char *, const char *);
int mh_valid_message (const char *);
-/* these are the only publicly visible for usage */
-
-mx_t* maildir_reg_mx (void);
-mx_t* mh_reg_mx (void);
-
#endif /* !_MH_H */
#include "lib/list.h"
-static list2_t* MailboxFormats = NULL;
-#define MX_COMMAND(idx,cmd) ((mx_t*) MailboxFormats->data[idx])->cmd
-#define MX_IDX(idx) (idx >= 0 && idx < MailboxFormats->length)
+static mx_t const *mxfmts[] = {
+ &mbox_mx,
+ &mmdf_mx,
+ &mh_mx,
+ &maildir_mx,
+ &imap_mx,
+ &pop_mx,
+#ifdef USE_NNTP
+ &nntp_mx,
+#endif
+ &compress_mx,
+};
-#define mutt_is_spool(s) (m_strcmp(Spoolfile, s) == 0)
+#define MX_IDX(idx) (idx >= 0 && idx < countof(mxfmts))
+#define mutt_is_spool(s) (m_strcmp(Spoolfile, s) == 0)
#ifdef USE_DOTLOCK
/* parameters:
#endif /* USE_DOTLOCK */
-/* looks up index of type for path in MailboxFormats */
+/* looks up index of type for path in mxfmts */
static int mx_get_idx (const char* path) {
- int i = 0, t = 0;
- struct stat st;
-
- /* first, test all non-local folders to avoid stat() call */
- for (i = 0; i < MailboxFormats->length; i++) {
- if (!MX_COMMAND(i,local))
- t = MX_COMMAND(i,mx_is_magic)(path, NULL);
- if (t >= 1)
- return (t-1);
- }
- if (stat (path, &st) == 0) {
- /* if stat() succeeded, keep testing until success and
- * pass stat() info so that we only need to do it once */
- for (i = 0; i < MailboxFormats->length; i++) {
- if (MX_COMMAND(i,local))
- t = MX_COMMAND(i,mx_is_magic)(path, &st);
- if (t >= 1)
- return (t-1);
+ int i = 0, t = 0;
+ struct stat st;
+
+ /* first, test all non-local folders to avoid stat() call */
+ for (i = 0; i < countof(mxfmts); i++) {
+ if (!mxfmts[i]->local)
+ t = mxfmts[i]->mx_is_magic(path, NULL);
+ if (t >= 1)
+ return (t-1);
}
- }
- return (-1);
+ if (stat (path, &st) == 0) {
+ /* if stat() succeeded, keep testing until success and
+ * pass stat() info so that we only need to do it once */
+ for (i = 0; i < countof(mxfmts); i++) {
+ if (mxfmts[i]->local)
+ t = mxfmts[i]->mx_is_magic(path, &st);
+ if (t >= 1)
+ return (t-1);
+ }
+ }
+ return (-1);
}
/* Args:
if (m_strlen(path) == 0)
return (-1);
if ((i = mx_get_idx (path)) >= 0)
- return (MX_COMMAND(i,type));
+ return (mxfmts[i]->type);
return (-1);
}
int mx_is_local (int m) {
if (!MX_IDX(m))
return (0);
- return (MX_COMMAND(m,local));
+ return (mxfmts[m]->local);
}
/*
{
int i = 0;
- if ((i = mx_get_idx (path)) >= 0 && MX_COMMAND(i,mx_access))
- return (MX_COMMAND(i,mx_access)(path,flags));
+ if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_access)
+ return (mxfmts[i]->mx_access(path,flags));
return (0);
}
if (!ctx->quiet)
mutt_message (_("Reading %s..."), ctx->path);
- rc = MX_COMMAND(ctx->magic-1,mx_open_mailbox)(ctx);
+ rc = mxfmts[ctx->magic-1]->mx_open_mailbox(ctx);
if (rc == 0) {
if ((flags & M_NOSORT) == 0) {
if (!ctx)
return;
- if (MX_IDX(ctx->magic-1) && MX_COMMAND(ctx->magic-1,mx_fastclose_mailbox))
- MX_COMMAND(ctx->magic-1,mx_fastclose_mailbox(ctx));
+ if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_fastclose_mailbox)
+ mxfmts[ctx->magic-1]->mx_fastclose_mailbox(ctx);
if (ctx->subj_hash)
hash_destroy (&ctx->subj_hash, NULL);
if (ctx->id_hash)
if (MX_IDX(ctx->magic-1))
/* the 1 is only of interest for IMAP and means EXPUNGE */
- rc = MX_COMMAND(ctx->magic-1,mx_sync_mailbox(ctx,1,index_hint));
+ rc = mxfmts[ctx->magic-1]->mx_sync_mailbox(ctx,1,index_hint);
if (rc == 0 && ctx->compressinfo)
return mutt_sync_compressed (ctx);
if (msg->received == 0)
time (&msg->received);
- if (MX_COMMAND(dest->magic-1,mx_open_new_message)(msg, dest, hdr) == 0) {
+ if (mxfmts[dest->magic-1]->mx_open_new_message(msg, dest, hdr) == 0) {
if (dest->magic == M_MMDF)
fputs (MMDF_SEP, msg->fp);
if (ctx) {
if (ctx->locked)
lock = 0;
- if (MX_IDX(ctx->magic-1) && MX_COMMAND(ctx->magic-1,mx_check_mailbox))
- return (MX_COMMAND(ctx->magic-1,mx_check_mailbox)(ctx, index_hint, lock));
+ if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_check_mailbox)
+ return (mxfmts[ctx->magic-1]->mx_check_mailbox(ctx, index_hint, lock));
}
return (-1);
if (!(msg->write && ctx->append)) {
return -1;
}
- if (!ctx || !MX_IDX(ctx->magic-1) || !MX_COMMAND(ctx->magic-1,mx_commit_message))
+ if (!ctx || !MX_IDX(ctx->magic-1) || !mxfmts[ctx->magic-1]->mx_commit_message)
return (-1);
- return (MX_COMMAND(ctx->magic-1,mx_commit_message) (msg, ctx));
+ return (mxfmts[ctx->magic-1]->mx_commit_message (msg, ctx));
}
/* close a pointer to a message */
int mx_check_empty (const char *path)
{
int i = 0;
- if ((i = mx_get_idx (path)) >= 0 && MX_COMMAND(i,mx_check_empty))
- return (MX_COMMAND(i,mx_check_empty)(path));
+ if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_check_empty)
+ return (mxfmts[i]->mx_check_empty(path));
errno = EINVAL;
return (-1);
}
if (!ctx || !MX_IDX(ctx->magic-1))
return (0);
/* if no acl_check defined for module, assume permission is granted */
- if (!MX_COMMAND(ctx->magic-1,mx_acl_check))
+ if (!mxfmts[ctx->magic-1]->mx_acl_check)
return (1);
- return (MX_COMMAND(ctx->magic-1,mx_acl_check)(ctx,flag));
-}
-
-void mx_init (void) {
- list_push_back (&MailboxFormats, (void*) mbox_reg_mx ());
- list_push_back (&MailboxFormats, (void*) mmdf_reg_mx ());
- list_push_back (&MailboxFormats, (void*) mh_reg_mx ());
- list_push_back (&MailboxFormats, (void*) maildir_reg_mx ());
- list_push_back (&MailboxFormats, (void*) imap_reg_mx ());
- list_push_back (&MailboxFormats, (void*) pop_reg_mx ());
-#ifdef USE_NNTP
- list_push_back (&MailboxFormats, (void*) nntp_reg_mx ());
-#endif
- list_push_back (&MailboxFormats, (void*) compress_reg_mx ());
+ return (mxfmts[ctx->magic-1]->mx_acl_check(ctx,flag));
}
int mx_rebuild_cache (void) {
#include <utime.h>
#include "mutt.h"
-/*
- * supported mailbox formats
- * in mx_init() the registration order must be exactly as given here!!!1!
- */
+/* supported mailbox formats
+ XXX: has to be in the same order than mxfmts in mx.c */
enum {
M_MBOX = 1,
M_MMDF,
time_t received; /* the time at which this message was received */
} MESSAGE;
-typedef struct {
+typedef struct mx_t {
/* folder magic */
int type;
/* may we stat() it? */
int (*mx_commit_message) (MESSAGE*, CONTEXT*);
} mx_t;
-/* called from main: init all folder types */
-void mx_init (void);
-
/* flags for mx_open_mailbox() */
#define M_NOSORT (1<<0) /* do not sort the mailbox after opening it */
#define M_APPEND (1<<1) /* open mailbox for appending messages */
}
}
-/* called by nntp_init(); don't call elsewhere */
-mx_t* nntp_reg_mx (void) {
- mx_t* fmt = p_new(mx_t, 1);
-
- /* make up mx_t record... */
- fmt->type = M_NNTP;
- fmt->mx_is_magic = nntp_is_magic;
- fmt->mx_open_mailbox = nntp_open_mailbox;
- fmt->mx_acl_check = acl_check_nntp;
- fmt->mx_fastclose_mailbox = nntp_fastclose_mailbox;
- fmt->mx_sync_mailbox = nntp_sync_mailbox;
- fmt->mx_check_mailbox = nntp_check_mailbox;
- return (fmt);
-}
+mx_t const nntp_mx = {
+ M_NNTP,
+ 0,
+ nntp_is_magic,
+ NULL,
+ NULL,
+ nntp_open_mailbox,
+ NULL,
+ acl_check_nntp,
+ nntp_check_mailbox,
+ nntp_fastclose_mailbox,
+ nntp_sync_mailbox,
+ NULL,
+};
#include "mx.h"
-mx_t* nntp_reg_mx (void);
+extern mx_t const nntp_mx;
#endif /* !_NNTP_MX_H */
}
}
-mx_t* pop_reg_mx (void) {
- mx_t* fmt = p_new(mx_t, 1);
-
- /* make up mx_t record... */
- fmt->type = M_POP;
- fmt->mx_is_magic = pop_is_magic;
- fmt->mx_open_mailbox = pop_open_mailbox;
- fmt->mx_acl_check = acl_check_pop;
- fmt->mx_fastclose_mailbox = pop_close_mailbox;
- fmt->mx_sync_mailbox = pop_sync_mailbox;
- fmt->mx_check_mailbox = pop_check_mailbox;
- return (fmt);
-}
+mx_t const pop_mx = {
+ M_POP,
+ 0,
+ pop_is_magic,
+ NULL,
+ NULL,
+ pop_open_mailbox,
+ NULL,
+ acl_check_pop,
+ pop_check_mailbox,
+ pop_close_mailbox,
+ pop_sync_mailbox,
+ NULL,
+};
#include "mx.h"
-mx_t* pop_reg_mx (void);
+extern mx_t const pop_mx;
#endif /* !_POP_MX_H */