From f0f96bc937011877b72ee0fae5013fd61ed9dfee Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 25 Jul 2012 22:34:48 +2000 Subject: [PATCH] [PATCH 08/13] show: Convert format_part_sigstatus_json to use sprinter --- 07/532a24cccf7af452baddfce5e72ea1f2d42cc1 | 288 ++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 07/532a24cccf7af452baddfce5e72ea1f2d42cc1 diff --git a/07/532a24cccf7af452baddfce5e72ea1f2d42cc1 b/07/532a24cccf7af452baddfce5e72ea1f2d42cc1 new file mode 100644 index 000000000..8b6e6567e --- /dev/null +++ b/07/532a24cccf7af452baddfce5e72ea1f2d42cc1 @@ -0,0 +1,288 @@ +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 5AD7F431FAE + for ; Tue, 24 Jul 2012 19:35:15 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 P9Xawyg0d8BZ for ; + Tue, 24 Jul 2012 19:35:13 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id 8BB74431FDA + for ; Tue, 24 Jul 2012 19:35:06 -0700 (PDT) +X-AuditID: 1209190e-b7fb56d0000008b2-ff-500f5b596f3d +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 73.7F.02226.95B5F005; Tue, 24 Jul 2012 22:35:05 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q6P2Z4Fj008578; + Tue, 24 Jul 2012 22:35:04 -0400 +Received: from drake.dyndns.org + (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [209.6.116.242]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6P2Z26R025127 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 24 Jul 2012 22:35:04 -0400 (EDT) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1StrRG-0004Zz-Js; Tue, 24 Jul 2012 22:35:02 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 08/13] show: Convert format_part_sigstatus_json to use + sprinter +Date: Tue, 24 Jul 2012 22:34:48 -0400 +Message-Id: <1343183693-17134-9-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10 +In-Reply-To: <1343183693-17134-1-git-send-email-amdragon@mit.edu> +References: <1343183693-17134-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsUixG6nrhsZzR9gcOuOtsXehnZGi+s3ZzI7 + MHks3rSfzePZqlvMAUxRXDYpqTmZZalF+nYJXBmbV21gLbhkWjG5YSVLA+NfjS5GTg4JAROJ + uZdeM0LYYhIX7q1n62Lk4hAS2McoceTbaVYIZwOjxPI1G1kgnEdMEh8+rWSEcOYySpza8Qas + n01AQ2Lb/uVgtoiAtMTOu7NZQWxmATOJuT8nsoHYwgL+Ej8WXGMCsVkEVCXmXe4Hi/MKOEhs + evGcHeIOeYmn9/vA4pwCjhLnlywEmykEVNOz+Br7BEb+BYwMqxhlU3KrdHMTM3OKU5N1i5MT + 8/JSi3SN9XIzS/RSU0o3MYKCiVOSbwfj14NKhxgFOBiVeHh/P+ELEGJNLCuuzD3EKMnBpCTK + WxHMHyDEl5SfUpmRWJwRX1Sak1p8iFGCg1lJhLcoDCjHm5JYWZValA+TkuZgURLnvZJy019I + ID2xJDU7NbUgtQgmK8PBoSTB2xoF1ChYlJqeWpGWmVOCkGbi4AQZzgM0fDdIDW9xQWJucWY6 + RP4Uo6KUOO9ckIQASCKjNA+uFxbtrxjFgV4R5m0GqeIBJgq47ldAg5mABj8P4wMZXJKIkJJq + YAyayZCx0NiK77Zk94ziXg9f7taXFa9ElWfc/XpcIGblYhWbhNq2+syPx1Ll4091rjiwJPHG + JvPaywnfVtfkvJ/593V0mG74CofaUK8mZ2nrBx9upWfkTtWzfDTvctk+Yee63Z7vRBpYUv6v + iT41hSP2y9Vnnz6fav/XJuXV+E3QqzMkPazNTYmlOCPRUIu5qDgRALe4W8LRAgAA +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: Wed, 25 Jul 2012 02:35:15 -0000 + +--- + notmuch-show.c | 118 +++++++++++++++++++++++++++++--------------------------- + 1 file changed, 61 insertions(+), 57 deletions(-) + +diff --git a/notmuch-show.c b/notmuch-show.c +index 9852119..3ff32df 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -337,134 +337,138 @@ signer_status_to_string (GMimeSignerStatus x) + + #ifdef GMIME_ATLEAST_26 + static void +-format_part_sigstatus_json (mime_node_t *node) ++format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node) + { + GMimeSignatureList *siglist = node->sig_list; + +- printf ("["); ++ sp->begin_list (sp); + + if (!siglist) { +- printf ("]"); ++ sp->end (sp); + return; + } + +- void *ctx_quote = talloc_new (NULL); + int i; + for (i = 0; i < g_mime_signature_list_length (siglist); i++) { + GMimeSignature *signature = g_mime_signature_list_get_signature (siglist, i); + +- if (i > 0) +- printf (", "); +- +- printf ("{"); ++ sp->begin_map (sp); + + /* status */ + GMimeSignatureStatus status = g_mime_signature_get_status (signature); +- printf ("\"status\": %s", +- json_quote_str (ctx_quote, +- signature_status_to_string (status))); ++ sp->map_key (sp, "status"); ++ sp->string (sp, signature_status_to_string (status)); + + GMimeCertificate *certificate = g_mime_signature_get_certificate (signature); + if (status == GMIME_SIGNATURE_STATUS_GOOD) { +- if (certificate) +- printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, g_mime_certificate_get_fingerprint (certificate))); ++ if (certificate) { ++ sp->map_key (sp, "fingerprint"); ++ sp->string (sp, g_mime_certificate_get_fingerprint (certificate)); ++ } + /* these dates are seconds since the epoch; should we + * provide a more human-readable format string? */ + time_t created = g_mime_signature_get_created (signature); +- if (created != -1) +- printf (", \"created\": %d", (int) created); ++ if (created != -1) { ++ sp->map_key (sp, "created"); ++ sp->integer (sp, created); ++ } + time_t expires = g_mime_signature_get_expires (signature); +- if (expires > 0) +- printf (", \"expires\": %d", (int) expires); ++ if (expires > 0) { ++ sp->map_key (sp, "expires"); ++ sp->integer (sp, expires); ++ } + /* output user id only if validity is FULL or ULTIMATE. */ + /* note that gmime is using the term "trust" here, which + * is WRONG. It's actually user id "validity". */ + if (certificate) { + const char *name = g_mime_certificate_get_name (certificate); + GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate); +- if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) +- printf (", \"userid\": %s", json_quote_str (ctx_quote, name)); ++ if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) { ++ sp->map_key (sp, "userid"); ++ sp->string (sp, name); ++ } + } + } else if (certificate) { + const char *key_id = g_mime_certificate_get_key_id (certificate); +- if (key_id) +- printf (", \"keyid\": %s", json_quote_str (ctx_quote, key_id)); ++ if (key_id) { ++ sp->map_key (sp, "keyid"); ++ sp->string (sp, key_id); ++ } + } + + GMimeSignatureError errors = g_mime_signature_get_errors (signature); + if (errors != GMIME_SIGNATURE_ERROR_NONE) { +- printf (", \"errors\": %d", errors); ++ sp->map_key (sp, "errors"); ++ sp->integer (sp, errors); + } + +- printf ("}"); ++ sp->end (sp); + } + +- printf ("]"); +- +- talloc_free (ctx_quote); ++ sp->end (sp); + } + #else + static void +-format_part_sigstatus_json (mime_node_t *node) ++format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node) + { + const GMimeSignatureValidity* validity = node->sig_validity; + +- printf ("["); ++ sp->begin_list (sp); + + if (!validity) { +- printf ("]"); ++ sp->end (sp); + return; + } + + const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity); +- int first = 1; +- void *ctx_quote = talloc_new (NULL); +- + while (signer) { +- if (first) +- first = 0; +- else +- printf (", "); +- +- printf ("{"); ++ sp->begin_map (sp); + + /* status */ +- printf ("\"status\": %s", +- json_quote_str (ctx_quote, +- signer_status_to_string (signer->status))); ++ sp->map_key (sp, "status"); ++ sp->string (sp, signer_status_to_string (signer->status)); + + if (signer->status == GMIME_SIGNER_STATUS_GOOD) + { +- if (signer->fingerprint) +- printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint)); ++ if (signer->fingerprint) { ++ sp->map_key (sp, "fingerprint"); ++ sp->string (sp, signer->fingerprint); ++ } + /* these dates are seconds since the epoch; should we + * provide a more human-readable format string? */ +- if (signer->created) +- printf (", \"created\": %d", (int) signer->created); +- if (signer->expires) +- printf (", \"expires\": %d", (int) signer->expires); ++ if (signer->created) { ++ sp->map_key (sp, "created"); ++ sp->integer (sp, signer->created); ++ } ++ if (signer->expires) { ++ sp->map_key (sp, "expires"); ++ sp->integer (sp, signer->expires); ++ } + /* output user id only if validity is FULL or ULTIMATE. */ + /* note that gmime is using the term "trust" here, which + * is WRONG. It's actually user id "validity". */ + if ((signer->name) && (signer->trust)) { +- if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) +- printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name)); ++ if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) { ++ sp->map_key (sp, "userid"); ++ sp->string (sp, signer->name); ++ } + } + } else { +- if (signer->keyid) +- printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid)); ++ if (signer->keyid) { ++ sp->map_key (sp, "keyid"); ++ sp->string (sp, signer->keyid); ++ } + } + if (signer->errors != GMIME_SIGNER_ERROR_NONE) { +- printf (", \"errors\": %d", signer->errors); ++ sp->map_key (sp, "errors"); ++ sp->integer (sp, signer->errors); + } + +- printf ("}"); ++ sp->end (sp); + signer = signer->next; + } + +- printf ("]"); +- +- talloc_free (ctx_quote); ++ sp->end (sp); + } + #endif + +@@ -607,7 +611,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, + + if (node->verify_attempted) { + printf (", \"sigstatus\": "); +- format_part_sigstatus_json (node); ++ format_part_sigstatus_json (sp, node); + } + + printf (", \"content-type\": %s", +-- +1.7.10 + -- 2.26.2