1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id CF0C2429E25
\r
6 for <notmuch@notmuchmail.org>; Sun, 11 Dec 2011 08:09:06 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id LxrvtkzHCyyA for <notmuch@notmuchmail.org>;
\r
16 Sun, 11 Dec 2011 08:09:06 -0800 (PST)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 25609431FB6
\r
21 for <notmuch@notmuchmail.org>; Sun, 11 Dec 2011 08:09:06 -0800 (PST)
\r
22 Received: from zancas.localnet
\r
23 (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net
\r
24 [156.34.79.193]) (authenticated bits=0)
\r
25 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pBBG91Mv019365
\r
26 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
27 Sun, 11 Dec 2011 12:09:02 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.77)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1RZlxV-0003g9-0W; Sun, 11 Dec 2011 12:09:01 -0400
\r
31 From: David Bremner <david@tethera.net>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH] cli: factor out config handling code to get/set lists.
\r
34 Date: Sun, 11 Dec 2011 12:07:51 -0400
\r
35 Message-Id: <1323619671-14111-1-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.7.3
\r
37 In-Reply-To: <87sjkstbiu.fsf@zancas.localnet>
\r
38 References: <87sjkstbiu.fsf@zancas.localnet>
\r
39 Cc: David Bremner <bremner@debian.org>
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Sun, 11 Dec 2011 16:09:06 -0000
\r
54 From: David Bremner <bremner@debian.org>
\r
56 Two new internal routines are created _config_get_list and
\r
57 _config_set_list; the notmuch_config_get_* functions that deal with
\r
58 lists are simply wrappers for these functions.
\r
60 notmuch-config.c | 130 +++++++++++++++++++++++++++--------------------------
\r
61 1 files changed, 66 insertions(+), 64 deletions(-)
\r
63 diff --git a/notmuch-config.c b/notmuch-config.c
\r
64 index 1a7ed58..e98b6a3 100644
\r
65 --- a/notmuch-config.c
\r
66 +++ b/notmuch-config.c
\r
67 @@ -520,92 +520,94 @@ notmuch_config_set_user_primary_email (notmuch_config_t *config,
\r
68 config->user_primary_email = NULL;
\r
72 -notmuch_config_get_user_other_email (notmuch_config_t *config,
\r
74 +static const char **
\r
75 +_config_get_list (notmuch_config_t *config,
\r
76 + const char *section, const char *key,
\r
77 + const char ***outlist, size_t *list_length, size_t *ret_length)
\r
80 - size_t emails_length;
\r
84 - if (config->user_other_email == NULL) {
\r
85 - emails = g_key_file_get_string_list (config->key_file,
\r
86 - "user", "other_email",
\r
87 - &emails_length, NULL);
\r
89 - config->user_other_email = talloc_size (config,
\r
91 - (emails_length + 1));
\r
92 - for (i = 0; i < emails_length; i++)
\r
93 - config->user_other_email[i] = talloc_strdup (config->user_other_email,
\r
95 - config->user_other_email[i] = NULL;
\r
97 - g_strfreev (emails);
\r
99 - config->user_other_email_length = emails_length;
\r
100 + if (*outlist == NULL) {
\r
101 + inlist = g_key_file_get_string_list (config->key_file,
\r
103 + list_length, NULL);
\r
105 + *outlist = talloc_size (config, sizeof (char *) *
\r
106 + (*list_length + 1));
\r
107 + for (i = 0; i < *list_length; i++)
\r
108 + (*outlist)[i] = talloc_strdup (*outlist, inlist[i]);
\r
109 + (*outlist)[i] = NULL;
\r
111 + g_strfreev (inlist);
\r
115 - *length = config->user_other_email_length;
\r
116 - return config->user_other_email;
\r
117 + if (ret_length) *ret_length = *list_length;
\r
122 -notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
123 - const char *other_email[],
\r
126 +notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length)
\r
128 - g_key_file_set_string_list (config->key_file,
\r
129 - "user", "other_email",
\r
130 - other_email, length);
\r
131 + return _config_get_list (config, "user", "other_email",
\r
132 + &(config->user_other_email),
\r
133 + &(config->user_other_email_length), length);
\r
136 - talloc_free (config->user_other_email);
\r
137 - config->user_other_email = NULL;
\r
139 +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
141 + return _config_get_list (config, "new", "tags",
\r
142 + &(config->new_tags),
\r
143 + &(config->new_tags_length), length);
\r
147 -notmuch_config_get_new_tags (notmuch_config_t *config,
\r
149 +notmuch_config_get_log_subscribers (notmuch_config_t *config, size_t *length)
\r
152 - size_t tags_length;
\r
154 + return _config_get_list (config, "log", "subscribers",
\r
155 + &(config->new_tags),
\r
156 + &(config->new_tags_length), length);
\r
159 - if (config->new_tags == NULL) {
\r
160 - tags = g_key_file_get_string_list (config->key_file,
\r
162 - &tags_length, NULL);
\r
164 - config->new_tags = talloc_size (config,
\r
165 - sizeof (char *) *
\r
166 - (tags_length + 1));
\r
167 - for (i = 0; i < tags_length; i++)
\r
168 - config->new_tags[i] = talloc_strdup (config->new_tags,
\r
170 - config->new_tags[i] = NULL;
\r
172 - g_strfreev (tags);
\r
174 - config->new_tags_length = tags_length;
\r
178 - *length = config->new_tags_length;
\r
179 - return config->new_tags;
\r
181 +_config_set_list (notmuch_config_t *config,
\r
182 + const char *group, const char *name,
\r
183 + const char *list[],
\r
184 + size_t length, const char ***config_var )
\r
186 + g_key_file_set_string_list (config->key_file, group, name, list, length);
\r
187 + talloc_free (*config_var);
\r
188 + *config_var = NULL;
\r
192 +notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
193 + const char *list[],
\r
196 + _config_set_list (config, "user", "other_email", list, length,
\r
197 + &(config->user_other_email));
\r
201 notmuch_config_set_new_tags (notmuch_config_t *config,
\r
202 - const char *new_tags[],
\r
204 + const char *list[],
\r
207 - g_key_file_set_string_list (config->key_file,
\r
209 - new_tags, length);
\r
210 + _config_set_list (config, "new", "tags", list, length,
\r
211 + &(config->new_tags));
\r
214 - talloc_free (config->new_tags);
\r
215 - config->new_tags = NULL;
\r
217 +notmuch_config_set_log_subscribers (notmuch_config_t *config,
\r
218 + const char *list[],
\r
221 + _config_set_list (config, "log", "subscribers", list, length,
\r
222 + &(config->log_subscribers));
\r
225 /* Given a configuration item of the form <group>.<key> return the
\r