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 arlo.cworth.org (Postfix) with ESMTP id DB7216DE1B1C
\r
6 for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 05:39:18 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.316 tagged_above=-999 required=5 tests=[AWL=0.235,
\r
12 RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] 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 K8CcWre0O-GB for <notmuch@notmuchmail.org>;
\r
16 Mon, 14 Dec 2015 05:39:13 -0800 (PST)
\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 4EE9D6DE0FF8
\r
19 for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 05:39:11 -0800 (PST)
\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
21 (envelope-from <bremner@tethera.net>)
\r
22 id 1a8TLG-0008Eq-G7; Mon, 14 Dec 2015 08:39:06 -0500
\r
23 Received: (nullmailer pid 31794 invoked by uid 1000);
\r
24 Mon, 14 Dec 2015 13:39:04 -0000
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [Patch v3 1/8] crypto: refactor context creation to facilitate
\r
29 Date: Mon, 14 Dec 2015 09:38:50 -0400
\r
30 Message-Id: <1450100337-31655-2-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.6.2
\r
32 In-Reply-To: <1450100337-31655-1-git-send-email-david@tethera.net>
\r
33 References: <1450100337-31655-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Mon, 14 Dec 2015 13:39:19 -0000
\r
48 From: Jani Nikula <jani@nikula.org>
\r
50 Let the context creation functions decide how to handle multiple calls
\r
51 and cache the crypto context. No functional changes.
\r
53 crypto.c | 19 ++++++++++---------
\r
54 1 file changed, 10 insertions(+), 9 deletions(-)
\r
56 diff --git a/crypto.c b/crypto.c
\r
57 index a6eb27d..1187ad7 100644
\r
62 /* Create a GPG context (GMime 2.6) */
\r
63 static notmuch_crypto_context_t *
\r
64 -create_gpg_context (const char *gpgpath)
\r
65 +create_gpg_context (notmuch_crypto_t *crypto)
\r
67 notmuch_crypto_context_t *gpgctx;
\r
69 + if (crypto->gpgctx)
\r
70 + return crypto->gpgctx;
\r
72 /* TODO: GMimePasswordRequestFunc */
\r
73 - gpgctx = g_mime_gpg_context_new (NULL, gpgpath ? gpgpath : "gpg");
\r
75 + gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");
\r
77 + fprintf (stderr, "Failed to construct gpg context.\n");
\r
80 + crypto->gpgctx = gpgctx;
\r
82 g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);
\r
83 g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);
\r
84 @@ -57,12 +63,7 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)
\r
86 if (strcasecmp (protocol, "application/pgp-signature") == 0 ||
\r
87 strcasecmp (protocol, "application/pgp-encrypted") == 0) {
\r
88 - if (! crypto->gpgctx) {
\r
89 - crypto->gpgctx = create_gpg_context (crypto->gpgpath);
\r
90 - if (! crypto->gpgctx)
\r
91 - fprintf (stderr, "Failed to construct gpg context.\n");
\r
93 - cryptoctx = crypto->gpgctx;
\r
94 + cryptoctx = create_gpg_context (crypto);
\r
96 fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");
\r