From dc0ac69921e5e3bfdaf293b35a510ecf9d6e72e6 Mon Sep 17 00:00:00 2001 From: Ethan Glasser-Camp Date: Thu, 16 Feb 2012 17:02:03 +1900 Subject: [PATCH] [RFC PATCH 10/13] Introduce concept of mailstore "constructor" --- 54/17d0fd25199e04ed9f5b3593521290e8260e9e | 202 ++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 54/17d0fd25199e04ed9f5b3593521290e8260e9e diff --git a/54/17d0fd25199e04ed9f5b3593521290e8260e9e b/54/17d0fd25199e04ed9f5b3593521290e8260e9e new file mode 100644 index 000000000..8324dd435 --- /dev/null +++ b/54/17d0fd25199e04ed9f5b3593521290e8260e9e @@ -0,0 +1,202 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B360D431E82 + for ; Wed, 15 Feb 2012 14:11:56 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.54 +X-Spam-Level: +X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3, + RCVD_IN_SORBS_WEB=0.614] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id eK-aKk33EcIa for ; + Wed, 15 Feb 2012 14:11:53 -0800 (PST) +Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu + [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS + id 2A8A4431E62 for ; Wed, 15 Feb 2012 14:11:53 -0800 + (PST) +X-Hash: + S|75b965240be746bfacad19b205d46a22056d0830|9287a5b72cd81bc1c234f87490ac0ac1 +X-Countries: Cameroon, United States +X-SMTP-From: accepted [195.24.209.20] [195.24.209.20] + (localhost) {Cameroon} +DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from + :to:cc:subject:date:message-id:in-reply-to:references; s= + default; i=glasse@cs.rpi.edu; t=1329343910; x=1329948710; l=3964; + bh=zz4yDRJU3jsojgqGz6/yGpSO8F4=; b=Qq9w/32EsKCnPttzA5YFswj + Pap4mbRruDvOKA9sWjqbS+rswyKUdcJuvixRyyY4F85+EwfnQ7GV6+C84KMuKJIM + RKbHele65+P09gK+ewgUUZnsUlqEi/N5EmW4kcfF1nZVIbrQIrBGK5slexVfl1yo + +AQTkxrUzrFqC3ZJ2Luo= +DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc + :subject:date:message-id:in-reply-to:references; q=dns; s= + default; b=E3Ea6resbxDmqh0AwLVJUYC5bPXuDMf9DkqY2iHGTNYz+a0J8xKCL + B/Qd8MyPuJFr4Akl0+2X4lsE2RMycJA5diXwOUzuDEC3Tdr4nS+hXUFCNT2hiVhL + aAvEFLwkuaGvxa32zSLvFrCTKebA5qugNptYWHTW98KDsryog7CSys= +X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00 +X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit + 15) +Authentication-Results: cliffclavin.cs.rpi.edu; + DKIM=neutral (none) header.from=glasse@cs.rpi.edu; + SPF=neutral (mfrom; + Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu +X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMBOCB008859 Auth:glasse +X-Virus-Scanned-By: cliffclavin.cs.rpi.edu +Received: from localhost ([195.24.209.20]) (authenticated bits=0) + by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMBOCB008859 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); + Wed, 15 Feb 2012 17:11:37 -0500 (EST) + (envelope-from glasse@cs.rpi.edu) +From: Ethan Glasser-Camp +To: notmuch@notmuchmail.org +Subject: [RFC PATCH 10/13] Introduce concept of mailstore "constructor" +Date: Wed, 15 Feb 2012 17:02:03 -0500 +Message-Id: <1329343326-16410-11-git-send-email-glasse@cs.rpi.edu> +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> +References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> +X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25 +Cc: Ethan Glasser-Camp +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 15 Feb 2012 22:11:56 -0000 + +From: Ethan Glasser-Camp + +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 +--- + 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 ++#include + + #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 + -- 2.26.2