[PATCH 1/6] cli: new crypto structure to store crypto contexts and parameters
authorJameson Graef Rollins <jrollins@finestructure.net>
Wed, 16 May 2012 21:55:54 +0000 (14:55 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:09 +0000 (09:47 -0800)
ba/f44ad7e7fb25197abd496a57ec0ab999a4f45f [new file with mode: 0644]

diff --git a/ba/f44ad7e7fb25197abd496a57ec0ab999a4f45f b/ba/f44ad7e7fb25197abd496a57ec0ab999a4f45f
new file mode 100644 (file)
index 0000000..61b0b6d
--- /dev/null
@@ -0,0 +1,279 @@
+Return-Path: <jrollins@finestructure.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id C8052431FBC\r
+       for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:11 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id XOxnH2QWlbQ9 for <notmuch@notmuchmail.org>;\r
+       Wed, 16 May 2012 14:56:08 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+       [131.215.239.19])\r
+       by olra.theworths.org (Postfix) with ESMTP id 67A1E431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:08 -0700 (PDT)\r
+Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+       by earth-doxen-postvirus (Postfix) with ESMTP id 4B98466E0189\r
+       for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:06 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
+Received: from finestructure.net (rrcs-184-74-199-219.nyc.biz.rr.com\r
+       [184.74.199.219]) (Authenticated sender: jrollins)\r
+       by earth-doxen-submit (Postfix) with ESMTP id A91CC66E0194\r
+       for <notmuch@notmuchmail.org>; Wed, 16 May 2012 14:56:03 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+       id 150703C4; Wed, 16 May 2012 14:56:02 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH 1/6] cli: new crypto structure to store crypto contexts and\r
+       parameters\r
+Date: Wed, 16 May 2012 14:55:54 -0700\r
+Message-Id: <1337205359-2444-2-git-send-email-jrollins@finestructure.net>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1337205359-2444-1-git-send-email-jrollins@finestructure.net>\r
+References: <1337205359-2444-1-git-send-email-jrollins@finestructure.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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: Wed, 16 May 2012 21:56:12 -0000\r
+\r
+The main point here is to keep track of the crypto stuff together in\r
+one place.  In notmuch-show the crypto struct is a sub structure of\r
+the parameters struct.  In notmuch-reply, which had been using a\r
+notmuch_show_params_t to store the crypto parameters, we can now just\r
+use the general crypto struct.\r
+\r
+I slip in a name change of the crypto context itself to better reflect\r
+what the context is specifically for: it's actually a GPG context,\r
+which is a sub type of Crypto context.  There are other types of\r
+Crypto contexts (Pkcs7 in particular) so we want to be clear.\r
+\r
+The following patches will use this to simplify some function\r
+interfaces.\r
+---\r
+ notmuch-client.h |   16 ++++++++++------\r
+ notmuch-reply.c  |   34 +++++++++++++++++-----------------\r
+ notmuch-show.c   |   22 +++++++++++-----------\r
+ 3 files changed, 38 insertions(+), 34 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 19b7f01..2ad24cf 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -74,17 +74,21 @@ typedef struct notmuch_show_format {\r
+     const char *message_set_end;\r
+ } notmuch_show_format_t;\r
\r
++typedef struct notmuch_crypto {\r
++#ifdef GMIME_ATLEAST_26\r
++    GMimeCryptoContext* gpgctx;\r
++#else\r
++    GMimeCipherContext* gpgctx;\r
++#endif\r
++    notmuch_bool_t decrypt;\r
++} notmuch_crypto_t;\r
++\r
+ typedef struct notmuch_show_params {\r
+     notmuch_bool_t entire_thread;\r
+     notmuch_bool_t omit_excluded;\r
+     notmuch_bool_t raw;\r
+     int part;\r
+-#ifdef GMIME_ATLEAST_26\r
+-    GMimeCryptoContext* cryptoctx;\r
+-#else\r
+-    GMimeCipherContext* cryptoctx;\r
+-#endif\r
+-    notmuch_bool_t decrypt;\r
++    notmuch_crypto_t crypto;\r
+ } notmuch_show_params_t;\r
\r
+ /* There's no point in continuing when we've detected that we've done\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 7184a5d..ed87899 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -515,7 +515,7 @@ static int\r
+ notmuch_reply_format_default(void *ctx,\r
+                            notmuch_config_t *config,\r
+                            notmuch_query_t *query,\r
+-                           notmuch_show_params_t *params,\r
++                           notmuch_crypto_t *crypto,\r
+                            notmuch_bool_t reply_all)\r
+ {\r
+     GMimeMessage *reply;\r
+@@ -544,7 +544,7 @@ notmuch_reply_format_default(void *ctx,\r
+       g_object_unref (G_OBJECT (reply));\r
+       reply = NULL;\r
\r
+-      if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
++      if (mime_node_open (ctx, message, crypto->gpgctx, crypto->decrypt,\r
+                           &root) == NOTMUCH_STATUS_SUCCESS) {\r
+           format_part_reply (root);\r
+           talloc_free (root);\r
+@@ -559,7 +559,7 @@ static int\r
+ notmuch_reply_format_json(void *ctx,\r
+                         notmuch_config_t *config,\r
+                         notmuch_query_t *query,\r
+-                        notmuch_show_params_t *params,\r
++                        notmuch_crypto_t *crypto,\r
+                         notmuch_bool_t reply_all)\r
+ {\r
+     GMimeMessage *reply;\r
+@@ -574,7 +574,7 @@ notmuch_reply_format_json(void *ctx,\r
\r
+     messages = notmuch_query_search_messages (query);\r
+     message = notmuch_messages_get (messages);\r
+-    if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
++    if (mime_node_open (ctx, message, crypto->gpgctx, crypto->decrypt,\r
+                       &node) != NOTMUCH_STATUS_SUCCESS)\r
+       return 1;\r
\r
+@@ -605,7 +605,7 @@ static int\r
+ notmuch_reply_format_headers_only(void *ctx,\r
+                                 notmuch_config_t *config,\r
+                                 notmuch_query_t *query,\r
+-                                unused (notmuch_show_params_t *params),\r
++                                unused (notmuch_crypto_t *crypto),\r
+                                 notmuch_bool_t reply_all)\r
+ {\r
+     GMimeMessage *reply;\r
+@@ -674,8 +674,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+     notmuch_query_t *query;\r
+     char *query_string;\r
+     int opt_index, ret = 0;\r
+-    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
+-    notmuch_show_params_t params = { .part = -1 };\r
++    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_crypto_t *crypto, notmuch_bool_t reply_all);\r
++    notmuch_crypto_t crypto = { .decrypt = FALSE };\r
+     int format = FORMAT_DEFAULT;\r
+     int reply_all = TRUE;\r
\r
+@@ -689,7 +689,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+         (notmuch_keyword_t []){ { "all", TRUE },\r
+                                 { "sender", FALSE },\r
+                                 { 0, 0 } } },\r
+-      { NOTMUCH_OPT_BOOLEAN, &params.decrypt, "decrypt", 'd', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN, &crypto.decrypt, "decrypt", 'd', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
\r
+@@ -706,18 +706,18 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+     else\r
+       reply_format_func = notmuch_reply_format_default;\r
\r
+-    if (params.decrypt) {\r
++    if (crypto.decrypt) {\r
+ #ifdef GMIME_ATLEAST_26\r
+       /* TODO: GMimePasswordRequestFunc */\r
+-      params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
++      crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
+ #else\r
+       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
+-      params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
++      crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
+ #endif\r
+-      if (params.cryptoctx) {\r
+-          g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
++      if (crypto.gpgctx) {\r
++          g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto.gpgctx, FALSE);\r
+       } else {\r
+-          params.decrypt = FALSE;\r
++          crypto.decrypt = FALSE;\r
+           fprintf (stderr, "Failed to construct gpg context.\n");\r
+       }\r
+ #ifndef GMIME_ATLEAST_26\r
+@@ -750,14 +750,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
++    if (reply_format_func (ctx, config, query, &crypto, reply_all) != 0)\r
+       return 1;\r
\r
+     notmuch_query_destroy (query);\r
+     notmuch_database_destroy (notmuch);\r
\r
+-    if (params.cryptoctx)\r
+-      g_object_unref(params.cryptoctx);\r
++    if (crypto.gpgctx)\r
++      g_object_unref(crypto.gpgctx);\r
\r
+     return ret;\r
+ }\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 95427d4..d254179 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -810,8 +810,8 @@ show_message (void *ctx,\r
+     mime_node_t *root, *part;\r
+     notmuch_status_t status;\r
\r
+-    status = mime_node_open (local, message, params->cryptoctx,\r
+-                           params->decrypt, &root);\r
++    status = mime_node_open (local, message, params->crypto.gpgctx,\r
++                           params->crypto.decrypt, &root);\r
+     if (status)\r
+       goto DONE;\r
+     part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));\r
+@@ -1002,7 +1002,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+                                   { 0, 0 } } },\r
+       { NOTMUCH_OPT_INT, &params.part, "part", 'p', 0 },\r
+       { NOTMUCH_OPT_BOOLEAN, &params.entire_thread, "entire-thread", 't', 0 },\r
+-      { NOTMUCH_OPT_BOOLEAN, &params.decrypt, "decrypt", 'd', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },\r
+       { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
+@@ -1047,18 +1047,18 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+       break;\r
+     }\r
\r
+-    if (params.decrypt || verify) {\r
++    if (params.crypto.decrypt || verify) {\r
+ #ifdef GMIME_ATLEAST_26\r
+       /* TODO: GMimePasswordRequestFunc */\r
+-      params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
++      params.crypto.gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
+ #else\r
+       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
+-      params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
++      params.crypto.gpgctx = g_mime_gpg_context_new (session, "gpg");\r
+ #endif\r
+-      if (params.cryptoctx) {\r
+-          g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
++      if (params.crypto.gpgctx) {\r
++          g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.crypto.gpgctx, FALSE);\r
+       } else {\r
+-          params.decrypt = FALSE;\r
++          params.crypto.decrypt = FALSE;\r
+           fprintf (stderr, "Failed to construct gpg context.\n");\r
+       }\r
+ #ifndef GMIME_ATLEAST_26\r
+@@ -1118,8 +1118,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+     notmuch_query_destroy (query);\r
+     notmuch_database_destroy (notmuch);\r
\r
+-    if (params.cryptoctx)\r
+-      g_object_unref(params.cryptoctx);\r
++    if (params.crypto.gpgctx)\r
++      g_object_unref(params.crypto.gpgctx);\r
\r
+     return ret;\r
+ }\r
+-- \r
+1.7.10\r
+\r