From 1f4486fc378c92f7002aa9f97530a74af492e411 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sun, 18 Jan 2015 12:45:51 +0200 Subject: [PATCH] [PATCH 1/3] crypto: refactor context creation to facilitate further work --- 73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 | 147 ++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 diff --git a/73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 b/73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 new file mode 100644 index 000000000..5cf7bcd9b --- /dev/null +++ b/73/aaed0b94ab2b1ecbf4811824d0bbf3691e5ba0 @@ -0,0 +1,147 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id A3902431FDD + for ; Sun, 18 Jan 2015 02:45:48 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: 1.738 +X-Spam-Level: * +X-Spam-Status: No, score=1.738 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id VVjYkxWf2gXE for ; + Sun, 18 Jan 2015 02:45:45 -0800 (PST) +Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com + [209.85.212.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id E2A6F431FB6 + for ; Sun, 18 Jan 2015 02:45:44 -0800 (PST) +Received: by mail-wi0-f180.google.com with SMTP id bs8so11170668wib.1 + for ; Sun, 18 Jan 2015 02:45:43 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=uBZu6WMShVr+8R9ONNtyHu8Edtyja5mRtLal+cUwoDA=; + b=i+E3QpXBK1xKvlp2JfDJ/Uyv2vksHOr7hp/7cpfU2SVsNs/qNP3PUiSuM03VNF3dmD + +8DlsxzYQuocdPC4zaT1bS1gpahcusDnyR/XP7fsoxFLBI/2WerRmE0Ty58PTBlRHLKd + m5stb1ISE9M+BwDRvkdCT93rPXHNwY0wUol0B/FI7lnz43f4M4bdcDTjremBjJbVK8+c + Ri0O6l5VTFODYzg1Gg6uJVw1R+EU/+Dh82QAbw7b1zEi/nHp5x4PwxC4kmrv3C7bjFYH + 34GNnVWiOUO04OMRXX+ezHaLvsP0VT8pNNw8MauXqN4QaB0X6hd1KdKddY62LBD2ddY3 + p1ZQ== +X-Gm-Message-State: + ALoCoQkt1wtb0YEhZ/k7iy6NWzFeHiIxoyxxB6S/cd7YVMLXKSTqJs9hAIs7HOcxAJ0YAYQRGoPj +X-Received: by 10.194.88.131 with SMTP id bg3mr45711384wjb.99.1421577943654; + Sun, 18 Jan 2015 02:45:43 -0800 (PST) +Received: from localhost (mobile-internet-bcee14-89.dhcp.inet.fi. + [188.238.20.89]) by mx.google.com with ESMTPSA id + ww4sm12903629wjc.47.2015.01.18.02.45.42 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sun, 18 Jan 2015 02:45:43 -0800 (PST) +From: Jani Nikula +To: david@tethera.net, + notmuch@notmuchmail.org +Subject: [PATCH 1/3] crypto: refactor context creation to facilitate further + work +Date: Sun, 18 Jan 2015 12:45:51 +0200 +Message-Id: + <760fe8048f9f3a641297a40ed129abc6695b6b94.1421577605.git.jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: <1421568167-18683-3-git-send-email-david@tethera.net> + +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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, 18 Jan 2015 10:45:48 -0000 + +--- + crypto.c | 27 +++++++++++++++++---------- + 1 file changed, 17 insertions(+), 10 deletions(-) + +diff --git a/crypto.c b/crypto.c +index 6f4a6db9d0f1..7cd7b69d1221 100644 +--- a/crypto.c ++++ b/crypto.c +@@ -24,14 +24,20 @@ + + /* Create a GPG context (GMime 2.6) */ + static notmuch_crypto_context_t * +-create_gpg_context (void) ++create_gpg_context (notmuch_crypto_t *crypto) + { + notmuch_crypto_context_t *gpgctx; + ++ if (crypto->gpgctx) ++ return crypto->gpgctx; ++ + /* TODO: GMimePasswordRequestFunc */ + gpgctx = g_mime_gpg_context_new (NULL, "gpg"); +- if (! gpgctx) ++ if (! gpgctx) { ++ fprintf (stderr, "Failed to construct gpg context.\n"); + return NULL; ++ } ++ crypto->gpgctx = gpgctx; + + g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE); + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE); +@@ -43,17 +49,23 @@ create_gpg_context (void) + + /* Create a GPG context (GMime 2.4) */ + static notmuch_crypto_context_t * +-create_gpg_context (void) ++create_gpg_context (notmuch_crypto_t *crypto) + { + GMimeSession *session; + notmuch_crypto_context_t *gpgctx; + ++ if (crypto->gpgctx) ++ return crypto->gpgctx; ++ + session = g_object_new (g_mime_session_get_type (), NULL); + gpgctx = g_mime_gpg_context_new (session, "gpg"); + g_object_unref (session); + +- if (! gpgctx) ++ if (! gpgctx) { ++ fprintf (stderr, "Failed to construct gpg context.\n"); + return NULL; ++ } ++ crypto->gpgctx = gpgctx; + + g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE); + +@@ -82,12 +94,7 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) + */ + if (strcasecmp (protocol, "application/pgp-signature") == 0 || + strcasecmp (protocol, "application/pgp-encrypted") == 0) { +- if (! crypto->gpgctx) { +- crypto->gpgctx = create_gpg_context (); +- if (! crypto->gpgctx) +- fprintf (stderr, "Failed to construct gpg context.\n"); +- } +- cryptoctx = crypto->gpgctx; ++ cryptoctx = create_gpg_context (crypto); + } else { + fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n"); + } +-- +2.1.4 + -- 2.26.2