1 Return-Path: <bremner@tesseract.cs.unb.ca>
\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 arlo.cworth.org (Postfix) with ESMTP id 4C90B6DE17FE
\r
6 for <notmuch@notmuchmail.org>; Sun, 16 Aug 2015 10:43:13 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0.127 tagged_above=-999 required=5 tests=[AWL=0.117,
\r
12 T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id EWjEn69vO-gy for <notmuch@notmuchmail.org>;
\r
16 Sun, 16 Aug 2015 10:43:11 -0700 (PDT)
\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 76C0E6DE17FA
\r
19 for <notmuch@notmuchmail.org>; Sun, 16 Aug 2015 10:43:11 -0700 (PDT)
\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)
\r
21 (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
22 id 1ZR1wB-0003bp-LC; Sun, 16 Aug 2015 17:41:39 +0000
\r
23 Received: (nullmailer pid 26307 invoked by uid 1000); Sun, 16 Aug 2015
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [PATCH 1/8] crypto: refactor context creation to facilitate further
\r
29 Date: Sun, 16 Aug 2015 19:41:09 +0200
\r
30 Message-Id: <1439746876-23654-2-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.5.0
\r
32 In-Reply-To: <1439746876-23654-1-git-send-email-david@tethera.net>
\r
33 References: <54CA467B.30408@gnome.org>
\r
34 <1439746876-23654-1-git-send-email-david@tethera.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.18
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Sun, 16 Aug 2015 17:43:13 -0000
\r
49 From: Jani Nikula <jani@nikula.org>
\r
51 Let the context creation functions decide how to handle multiple calls
\r
52 and cache the crypto context. No functional changes.
\r
54 crypto.c | 19 ++++++++++---------
\r
55 1 file changed, 10 insertions(+), 9 deletions(-)
\r
57 diff --git a/crypto.c b/crypto.c
\r
58 index a6eb27d..1187ad7 100644
\r
63 /* Create a GPG context (GMime 2.6) */
\r
64 static notmuch_crypto_context_t *
\r
65 -create_gpg_context (const char *gpgpath)
\r
66 +create_gpg_context (notmuch_crypto_t *crypto)
\r
68 notmuch_crypto_context_t *gpgctx;
\r
70 + if (crypto->gpgctx)
\r
71 + return crypto->gpgctx;
\r
73 /* TODO: GMimePasswordRequestFunc */
\r
74 - gpgctx = g_mime_gpg_context_new (NULL, gpgpath ? gpgpath : "gpg");
\r
76 + gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");
\r
78 + fprintf (stderr, "Failed to construct gpg context.\n");
\r
81 + crypto->gpgctx = gpgctx;
\r
83 g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);
\r
84 g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);
\r
85 @@ -57,12 +63,7 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)
\r
87 if (strcasecmp (protocol, "application/pgp-signature") == 0 ||
\r
88 strcasecmp (protocol, "application/pgp-encrypted") == 0) {
\r
89 - if (! crypto->gpgctx) {
\r
90 - crypto->gpgctx = create_gpg_context (crypto->gpgpath);
\r
91 - if (! crypto->gpgctx)
\r
92 - fprintf (stderr, "Failed to construct gpg context.\n");
\r
94 - cryptoctx = crypto->gpgctx;
\r
95 + cryptoctx = create_gpg_context (crypto);
\r
97 fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");
\r