From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 5669C6DE1F59 for ; Fri, 14 Jul 2017 06:12:16 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.000] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EwQ9NKxZVQHo for ; Fri, 14 Jul 2017 06:12:15 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTP id 90FCB6DE2B57 for ; Fri, 14 Jul 2017 06:12:15 -0700 (PDT) Received: from fifthhorseman.net (38.200.broadband6.iol.cz [88.101.200.38]) by che.mayfirst.org (Postfix) with ESMTPSA id DEC90F99B for ; Fri, 14 Jul 2017 09:12:13 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id E09CB20558; Fri, 14 Jul 2017 15:12:02 +0200 (CEST) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 3/3] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3.0 Date: Fri, 14 Jul 2017 15:12:02 +0200 Message-Id: <20170714131202.24966-3-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170714131202.24966-1-dkg@fifthhorseman.net> References: <20170603174754.16911-24-david@tethera.net> <20170714131202.24966-1-dkg@fifthhorseman.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Fri, 14 Jul 2017 13:12:16 -0000 gmime 3.0 knows how to select the correct GMimeCryptoContext automatically, so a bunch of the code in notmuch can be dropped in that case. The #ifdef removal of the crypto stuff is better than #define aliasing in gmime-extra.h for this stuff. When built against gmime 3.0: * it reduces compiled code, * it avoids initializing unused gpgme contexts, and * it avoids compiled-time warnings about passing unnecessary notmuch_cryptoctx_t*s. --- crypto.c | 2 ++ mime-node.c | 28 ++++++++++++++++++++++++---- notmuch-client.h | 8 ++++++-- notmuch-reply.c | 2 ++ notmuch-show.c | 2 ++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/crypto.c b/crypto.c index 3e8ce7ca..ab1fb77a 100644 --- a/crypto.c +++ b/crypto.c @@ -20,6 +20,7 @@ #include "notmuch-client.h" +#if (GMIME_MAJOR_VERSION < 3) /* Create a GPG context (GMime 2.6) */ static notmuch_crypto_context_t * create_gpg_context (notmuch_crypto_t *crypto) @@ -132,3 +133,4 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto) return 0; } +#endif diff --git a/mime-node.c b/mime-node.c index f719422e..226e9c2f 100644 --- a/mime-node.c +++ b/mime-node.c @@ -150,8 +150,11 @@ set_signature_list_destructor (mime_node_t *node) /* Verify a signed mime node (GMime 2.6) */ static void -node_verify (mime_node_t *node, GMimeObject *part, - notmuch_crypto_context_t *cryptoctx) +node_verify (mime_node_t *node, GMimeObject *part +#if (GMIME_MAJOR_VERSION < 3) + , notmuch_crypto_context_t *cryptoctx +#endif + ) { GError *err = NULL; @@ -171,8 +174,11 @@ node_verify (mime_node_t *node, GMimeObject *part, /* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */ static void -node_decrypt_and_verify (mime_node_t *node, GMimeObject *part, - notmuch_crypto_context_t *cryptoctx) +node_decrypt_and_verify (mime_node_t *node, GMimeObject *part +#if (GMIME_MAJOR_VERSION < 3) + , notmuch_crypto_context_t *cryptoctx +#endif + ) { GError *err = NULL; GMimeDecryptResult *decrypt_result = NULL; @@ -207,7 +213,11 @@ static mime_node_t * _mime_node_create (mime_node_t *parent, GMimeObject *part) { mime_node_t *node = talloc_zero (parent, mime_node_t); +#if (GMIME_MAJOR_VERSION < 3) notmuch_crypto_context_t *cryptoctx = NULL; +#else + notmuch_bool_t cryptoctx = TRUE; +#endif /* Set basic node properties */ node->part = part; @@ -240,12 +250,14 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part) return NULL; } +#if (GMIME_MAJOR_VERSION < 3) if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt) || (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) { GMimeContentType *content_type = g_mime_object_get_content_type (part); const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol"); cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol); } +#endif /* Handle PGP/MIME parts */ if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) { @@ -255,7 +267,11 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part) "message (must be exactly 2)\n", node->nchildren); } else { +#if (GMIME_MAJOR_VERSION < 3) node_decrypt_and_verify (node, part, cryptoctx); +#else + node_decrypt_and_verify (node, part); +#endif } } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) { if (node->nchildren != 2) { @@ -264,7 +280,11 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part) "(must be exactly 2)\n", node->nchildren); } else { +#if (GMIME_MAJOR_VERSION < 3) node_verify (node, part, cryptoctx); +#else + node_verify (node, part); +#endif } } diff --git a/notmuch-client.h b/notmuch-client.h index 11aefbb4..c520089e 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -31,7 +31,9 @@ #include "gmime-extra.h" +#if (GMIME_MAJOR_VERSION < 3) typedef GMimeCryptoContext notmuch_crypto_context_t; +#endif /* This is automatically included only since gmime 2.6.10 */ #include @@ -72,11 +74,11 @@ typedef struct notmuch_show_format { } notmuch_show_format_t; typedef struct notmuch_crypto { - notmuch_crypto_context_t* gpgctx; - notmuch_crypto_context_t* pkcs7ctx; notmuch_bool_t verify; notmuch_bool_t decrypt; #if (GMIME_MAJOR_VERSION < 3) + notmuch_crypto_context_t* gpgctx; + notmuch_crypto_context_t* pkcs7ctx; const char *gpgpath; #endif } notmuch_crypto_t; @@ -180,11 +182,13 @@ typedef struct _notmuch_config notmuch_config_t; void notmuch_exit_if_unsupported_format (void); +#if (GMIME_MAJOR_VERSION < 3) notmuch_crypto_context_t * notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol); int notmuch_crypto_cleanup (notmuch_crypto_t *crypto); +#endif int notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]); diff --git a/notmuch-reply.c b/notmuch-reply.c index b4a55362..69c26359 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -759,7 +759,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) if (do_reply (config, query, ¶ms, format, reply_all) != 0) return EXIT_FAILURE; +#if (GMIME_MAJOR_VERSION < 3) notmuch_crypto_cleanup (¶ms.crypto); +#endif notmuch_query_destroy (query); notmuch_database_destroy (notmuch); diff --git a/notmuch-show.c b/notmuch-show.c index 6c135278..626bca80 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1257,7 +1257,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) g_mime_stream_flush (params.out_stream); g_object_unref (params.out_stream); +#if (GMIME_MAJOR_VERSION < 3) notmuch_crypto_cleanup (¶ms.crypto); +#endif notmuch_query_destroy (query); notmuch_database_destroy (notmuch); -- 2.13.2