[PATCH 1/8] crypto: refactor context creation to facilitate further work
authorDavid Bremner <david@tethera.net>
Sun, 16 Aug 2015 17:41:09 +0000 (19:41 +0200)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:49:22 +0000 (14:49 -0700)
f1/2943391ecb2cef8fcc29e19e2b59eec8d0801e [new file with mode: 0644]

diff --git a/f1/2943391ecb2cef8fcc29e19e2b59eec8d0801e b/f1/2943391ecb2cef8fcc29e19e2b59eec8d0801e
new file mode 100644 (file)
index 0000000..8146d6f
--- /dev/null
@@ -0,0 +1,101 @@
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 4C90B6DE17FE\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Aug 2015 10:43:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.127\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.127 tagged_above=-999 required=5 tests=[AWL=0.117, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id EWjEn69vO-gy for <notmuch@notmuchmail.org>;\r
+ Sun, 16 Aug 2015 10:43:11 -0700 (PDT)\r
+Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 76C0E6DE17FA\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Aug 2015 10:43:11 -0700 (PDT)\r
+Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1ZR1wB-0003bp-LC; Sun, 16 Aug 2015 17:41:39 +0000\r
+Received: (nullmailer pid 26307 invoked by uid 1000); Sun, 16 Aug 2015\r
+ 17:41:28 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/8] crypto: refactor context creation to facilitate further\r
+ work\r
+Date: Sun, 16 Aug 2015 19:41:09 +0200\r
+Message-Id: <1439746876-23654-2-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.0\r
+In-Reply-To: <1439746876-23654-1-git-send-email-david@tethera.net>\r
+References: <54CA467B.30408@gnome.org>\r
+ <1439746876-23654-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 16 Aug 2015 17:43:13 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+Let the context creation functions decide how to handle multiple calls\r
+and cache the crypto context. No functional changes.\r
+---\r
+ crypto.c | 19 ++++++++++---------\r
+ 1 file changed, 10 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/crypto.c b/crypto.c\r
+index a6eb27d..1187ad7 100644\r
+--- a/crypto.c\r
++++ b/crypto.c\r
+@@ -22,14 +22,20 @@\r
\r
+ /* Create a GPG context (GMime 2.6) */\r
+ static notmuch_crypto_context_t *\r
+-create_gpg_context (const char *gpgpath)\r
++create_gpg_context (notmuch_crypto_t *crypto)\r
+ {\r
+     notmuch_crypto_context_t *gpgctx;\r
\r
++    if (crypto->gpgctx)\r
++      return crypto->gpgctx;\r
++\r
+     /* TODO: GMimePasswordRequestFunc */\r
+-    gpgctx = g_mime_gpg_context_new (NULL, gpgpath ? gpgpath : "gpg");\r
+-    if (! gpgctx)\r
++    gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");\r
++    if (! gpgctx) {\r
++      fprintf (stderr, "Failed to construct gpg context.\n");\r
+       return NULL;\r
++    }\r
++    crypto->gpgctx = gpgctx;\r
\r
+     g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);\r
+     g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
+@@ -57,12 +63,7 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
+      */\r
+     if (strcasecmp (protocol, "application/pgp-signature") == 0 ||\r
+       strcasecmp (protocol, "application/pgp-encrypted") == 0) {\r
+-      if (! crypto->gpgctx) {\r
+-          crypto->gpgctx = create_gpg_context (crypto->gpgpath);\r
+-          if (! crypto->gpgctx)\r
+-              fprintf (stderr, "Failed to construct gpg context.\n");\r
+-      }\r
+-      cryptoctx = crypto->gpgctx;\r
++      cryptoctx = create_gpg_context (crypto);\r
+     } else {\r
+       fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
+     }\r
+-- \r
+2.5.0\r
+\r