From: David Bremner Date: Sun, 16 Aug 2015 17:41:10 +0000 (+0200) Subject: [PATCH 2/8] crypto: make crypto ctx initialization an array X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c008b09d6a8ccb2011b9b3872c8f404dc045dc8a;p=notmuch-archives.git [PATCH 2/8] crypto: make crypto ctx initialization an array --- diff --git a/37/a39ec0f4ccaa5ddd7203e93ac4a65297d11227 b/37/a39ec0f4ccaa5ddd7203e93ac4a65297d11227 new file mode 100644 index 000000000..6a4393d8a --- /dev/null +++ b/37/a39ec0f4ccaa5ddd7203e93ac4a65297d11227 @@ -0,0 +1,91 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 912DC6DE14D1 + for ; Sun, 16 Aug 2015 10:44:06 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.125 +X-Spam-Level: +X-Spam-Status: No, score=0.125 tagged_above=-999 required=5 tests=[AWL=0.115, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] 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 nII8wBD91_0S for ; + Sun, 16 Aug 2015 10:44:05 -0700 (PDT) +Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id C74E86DE0B26 + for ; Sun, 16 Aug 2015 10:44:04 -0700 (PDT) +Received: from remotemail by gitolite.debian.net with local (Exim 4.80) + (envelope-from ) + id 1ZR1x3-0003cg-23; Sun, 16 Aug 2015 17:42:33 +0000 +Received: (nullmailer pid 26309 invoked by uid 1000); Sun, 16 Aug 2015 + 17:41:28 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 2/8] crypto: make crypto ctx initialization an array +Date: Sun, 16 Aug 2015 19:41:10 +0200 +Message-Id: <1439746876-23654-3-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.5.0 +In-Reply-To: <1439746876-23654-1-git-send-email-david@tethera.net> +References: <54CA467B.30408@gnome.org> + <1439746876-23654-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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: Sun, 16 Aug 2015 17:44:06 -0000 + +From: Jani Nikula + +Make it trivial to add handlers for new protocols without duplicating +code. No functional changes. +--- + crypto.c | 13 +++++++------ + 1 file changed, 7 insertions(+), 6 deletions(-) + +diff --git a/crypto.c b/crypto.c +index 1187ad7..f415abd 100644 +--- a/crypto.c ++++ b/crypto.c +@@ -49,6 +49,7 @@ notmuch_crypto_context_t * + notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) + { + notmuch_crypto_context_t *cryptoctx = NULL; ++ size_t i; + + if (! protocol) { + fprintf (stderr, "Cryptographic protocol is empty.\n"); +@@ -61,14 +62,14 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) + * parameter names as defined in this document are + * case-insensitive." Thus, we use strcasecmp for the protocol. + */ +- if (strcasecmp (protocol, "application/pgp-signature") == 0 || +- strcasecmp (protocol, "application/pgp-encrypted") == 0) { +- cryptoctx = create_gpg_context (crypto); +- } else { +- fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n"); ++ for (i = 0; i < ARRAY_SIZE (protocols); i++) { ++ if (strcasecmp (protocol, protocols[i].protocol) == 0) ++ return protocols[i].get_context (crypto); + } + +- return cryptoctx; ++ fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n"); ++ ++ return NULL; + } + + int +-- +2.5.0 +