From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
To: notmuch@notmuchmail.org
Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
Subject: [RFC PATCH 10/13] Introduce concept of mailstore "constructor"
Date: Wed, 15 Feb 2012 17:02:03 -0500 [thread overview]
Message-ID: <1329343326-16410-11-git-send-email-glasse@cs.rpi.edu> (raw)
In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
From: Ethan Glasser-Camp <ethan@betacantrips.com>
Right now this is a fancy no-op because maildir doesn't need any
special data, but getting the API right is good. A constructor can
fail, so return a notmuch_status_t.
Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
---
lib/mailstore.c | 36 +++++++++++++++++++++++++++++++++---
lib/notmuch.h | 7 +++++++
notmuch-config.c | 8 +++++++-
3 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/lib/mailstore.c b/lib/mailstore.c
index 2c6beab..b4d512d 100644
--- a/lib/mailstore.c
+++ b/lib/mailstore.c
@@ -17,15 +17,25 @@
*/
#include <stdio.h>
+#include <stdarg.h>
#include "notmuch-private.h"
typedef struct _notmuch_mailstore {
+ notmuch_status_t (*constructor) (void **data, va_list args);
FILE *(*open) (struct _notmuch_mailstore *mailstore, const char *filename);
int (*rename) (struct _notmuch_mailstore *mailstore, const char *old_filename,
const char *new_filename);
+ void *data;
} _notmuch_mailstore;
+static notmuch_status_t
+_maildir_constructor (void **data, unused (va_list ap))
+{
+ (*data) = NULL;
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
static FILE *
_maildir_open_function (unused (notmuch_mailstore_t *mailstore),
const char *filename)
@@ -48,12 +58,18 @@ _maildir_rename_function (unused (notmuch_mailstore_t *mailstore),
* - A function to "rename" a mail message, which is currently only
* used in tags_to_maildir_flags.
*
- * - TODO: A way to scan for new messages?
+ * - A "constructor" that creates a mailstore object of the requisite
+ * type. Arguments are passed via va_args.
*
- * - TODO: A "constructor"?
+ * A mailstore also has a "data" field that can be used to store
+ * instance-specific information about this mailstore -- for example,
+ * a CouchDB URL or a path. FIXME: mailstores are all statically
+ * allocated, so maybe we shouldn't do this.
*/
_notmuch_mailstore
-notmuch_mailstore_maildir = { _maildir_open_function, _maildir_rename_function };
+notmuch_mailstore_maildir = { _maildir_constructor,
+ _maildir_open_function, _maildir_rename_function,
+ NULL };
_notmuch_mailstore *
notmuch_mailstore_get_by_name (const char *name)
@@ -76,3 +92,17 @@ notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filena
{
return mailstore->rename (mailstore, old_filename, new_filename);
}
+
+notmuch_status_t
+notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...)
+{
+ va_list va_args;
+ notmuch_status_t status;
+
+ va_start (va_args, mailstore);
+
+ status = mailstore->constructor (&mailstore->data, va_args);
+
+ va_end (va_args);
+ return status;
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index b6e66a9..7f48507 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -430,6 +430,13 @@ int
notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,
const char *new_filename);
+/* Initialize the mailstore.
+ *
+ * Arguments are dependent on the mailstore.
+ */
+notmuch_status_t
+notmuch_mailstore_construct (notmuch_mailstore_t *mailstore, ...);
+
/* Create a new query for 'database'.
*
* Here, 'database' should be an open database, (see
diff --git a/notmuch-config.c b/notmuch-config.c
index f611b26..99f872d 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -592,8 +592,14 @@ notmuch_config_get_mailstore (notmuch_config_t *config)
* When there are multiple mailstore types and "constructors" for
* them, this may have to be much more complicated.
*/
+ notmuch_status_t status;
const char *type = notmuch_config_get_database_type (config);
- return notmuch_mailstore_get_by_name (type);
+ notmuch_mailstore_t *mailstore = notmuch_mailstore_get_by_name (type);
+ status = notmuch_mailstore_construct (mailstore);
+ if (status != NOTMUCH_STATUS_SUCCESS) {
+ /* abort messily? */
+ }
+ return mailstore;
}
const char *
--
1.7.5.4
next prev parent reply other threads:[~2012-02-15 22:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 22:01 [RFC PATCH 00/13] Modular message store code Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 01/13] Create configuration paramater database.type Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 02/13] Add the concept of a mailstore in its absolute minimal sense Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 03/13] Introduce mailstore in the python bindings Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 04/13] Replace remaining places where fopen occurs Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 05/13] notmuch_database_add_message calculates sha1 of messages using mailstore Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 06/13] Pass mailstore to _notmuch_message_index_file Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 07/13] notmuch-new: pull out useful bits of add_files_recursive Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 08/13] count_files and add_files shall be generic Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 09/13] Mailstore also provides a "rename" function Ethan Glasser-Camp
2012-02-15 22:02 ` Ethan Glasser-Camp [this message]
2012-02-15 22:02 ` [RFC PATCH 11/13] Add a close function to mailstore Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead of fclose Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 13/13] First crack at a CouchDB mailstore Ethan Glasser-Camp
2012-02-16 0:56 ` [RFC PATCH 00/13] Modular message store code Mark Walters
2012-03-01 13:51 ` Ethan Glasser-Camp
2012-02-16 7:47 ` Stewart Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1329343326-16410-11-git-send-email-glasse@cs.rpi.edu \
--to=glasse@cs.rpi.edu \
--cc=ethan@betacantrips.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).