mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
show: Convert format_part_sigstatus_json to use sprinter
This commit is contained in:
parent
7018fc58b4
commit
85b326f13c
1 changed files with 61 additions and 57 deletions
118
notmuch-show.c
118
notmuch-show.c
|
@ -337,134 +337,138 @@ signer_status_to_string (GMimeSignerStatus x)
|
||||||
|
|
||||||
#ifdef GMIME_ATLEAST_26
|
#ifdef GMIME_ATLEAST_26
|
||||||
static void
|
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;
|
GMimeSignatureList *siglist = node->sig_list;
|
||||||
|
|
||||||
printf ("[");
|
sp->begin_list (sp);
|
||||||
|
|
||||||
if (!siglist) {
|
if (!siglist) {
|
||||||
printf ("]");
|
sp->end (sp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ctx_quote = talloc_new (NULL);
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < g_mime_signature_list_length (siglist); i++) {
|
for (i = 0; i < g_mime_signature_list_length (siglist); i++) {
|
||||||
GMimeSignature *signature = g_mime_signature_list_get_signature (siglist, i);
|
GMimeSignature *signature = g_mime_signature_list_get_signature (siglist, i);
|
||||||
|
|
||||||
if (i > 0)
|
sp->begin_map (sp);
|
||||||
printf (", ");
|
|
||||||
|
|
||||||
printf ("{");
|
|
||||||
|
|
||||||
/* status */
|
/* status */
|
||||||
GMimeSignatureStatus status = g_mime_signature_get_status (signature);
|
GMimeSignatureStatus status = g_mime_signature_get_status (signature);
|
||||||
printf ("\"status\": %s",
|
sp->map_key (sp, "status");
|
||||||
json_quote_str (ctx_quote,
|
sp->string (sp, signature_status_to_string (status));
|
||||||
signature_status_to_string (status)));
|
|
||||||
|
|
||||||
GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
|
GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
|
||||||
if (status == GMIME_SIGNATURE_STATUS_GOOD) {
|
if (status == GMIME_SIGNATURE_STATUS_GOOD) {
|
||||||
if (certificate)
|
if (certificate) {
|
||||||
printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, g_mime_certificate_get_fingerprint (certificate)));
|
sp->map_key (sp, "fingerprint");
|
||||||
|
sp->string (sp, g_mime_certificate_get_fingerprint (certificate));
|
||||||
|
}
|
||||||
/* these dates are seconds since the epoch; should we
|
/* these dates are seconds since the epoch; should we
|
||||||
* provide a more human-readable format string? */
|
* provide a more human-readable format string? */
|
||||||
time_t created = g_mime_signature_get_created (signature);
|
time_t created = g_mime_signature_get_created (signature);
|
||||||
if (created != -1)
|
if (created != -1) {
|
||||||
printf (", \"created\": %d", (int) created);
|
sp->map_key (sp, "created");
|
||||||
|
sp->integer (sp, created);
|
||||||
|
}
|
||||||
time_t expires = g_mime_signature_get_expires (signature);
|
time_t expires = g_mime_signature_get_expires (signature);
|
||||||
if (expires > 0)
|
if (expires > 0) {
|
||||||
printf (", \"expires\": %d", (int) expires);
|
sp->map_key (sp, "expires");
|
||||||
|
sp->integer (sp, expires);
|
||||||
|
}
|
||||||
/* output user id only if validity is FULL or ULTIMATE. */
|
/* output user id only if validity is FULL or ULTIMATE. */
|
||||||
/* note that gmime is using the term "trust" here, which
|
/* note that gmime is using the term "trust" here, which
|
||||||
* is WRONG. It's actually user id "validity". */
|
* is WRONG. It's actually user id "validity". */
|
||||||
if (certificate) {
|
if (certificate) {
|
||||||
const char *name = g_mime_certificate_get_name (certificate);
|
const char *name = g_mime_certificate_get_name (certificate);
|
||||||
GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate);
|
GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate);
|
||||||
if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE))
|
if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) {
|
||||||
printf (", \"userid\": %s", json_quote_str (ctx_quote, name));
|
sp->map_key (sp, "userid");
|
||||||
|
sp->string (sp, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (certificate) {
|
} else if (certificate) {
|
||||||
const char *key_id = g_mime_certificate_get_key_id (certificate);
|
const char *key_id = g_mime_certificate_get_key_id (certificate);
|
||||||
if (key_id)
|
if (key_id) {
|
||||||
printf (", \"keyid\": %s", json_quote_str (ctx_quote, key_id));
|
sp->map_key (sp, "keyid");
|
||||||
|
sp->string (sp, key_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GMimeSignatureError errors = g_mime_signature_get_errors (signature);
|
GMimeSignatureError errors = g_mime_signature_get_errors (signature);
|
||||||
if (errors != GMIME_SIGNATURE_ERROR_NONE) {
|
if (errors != GMIME_SIGNATURE_ERROR_NONE) {
|
||||||
printf (", \"errors\": %d", errors);
|
sp->map_key (sp, "errors");
|
||||||
|
sp->integer (sp, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("}");
|
sp->end (sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("]");
|
sp->end (sp);
|
||||||
|
|
||||||
talloc_free (ctx_quote);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void
|
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;
|
const GMimeSignatureValidity* validity = node->sig_validity;
|
||||||
|
|
||||||
printf ("[");
|
sp->begin_list (sp);
|
||||||
|
|
||||||
if (!validity) {
|
if (!validity) {
|
||||||
printf ("]");
|
sp->end (sp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
|
const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
|
||||||
int first = 1;
|
|
||||||
void *ctx_quote = talloc_new (NULL);
|
|
||||||
|
|
||||||
while (signer) {
|
while (signer) {
|
||||||
if (first)
|
sp->begin_map (sp);
|
||||||
first = 0;
|
|
||||||
else
|
|
||||||
printf (", ");
|
|
||||||
|
|
||||||
printf ("{");
|
|
||||||
|
|
||||||
/* status */
|
/* status */
|
||||||
printf ("\"status\": %s",
|
sp->map_key (sp, "status");
|
||||||
json_quote_str (ctx_quote,
|
sp->string (sp, signer_status_to_string (signer->status));
|
||||||
signer_status_to_string (signer->status)));
|
|
||||||
|
|
||||||
if (signer->status == GMIME_SIGNER_STATUS_GOOD)
|
if (signer->status == GMIME_SIGNER_STATUS_GOOD)
|
||||||
{
|
{
|
||||||
if (signer->fingerprint)
|
if (signer->fingerprint) {
|
||||||
printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint));
|
sp->map_key (sp, "fingerprint");
|
||||||
|
sp->string (sp, signer->fingerprint);
|
||||||
|
}
|
||||||
/* these dates are seconds since the epoch; should we
|
/* these dates are seconds since the epoch; should we
|
||||||
* provide a more human-readable format string? */
|
* provide a more human-readable format string? */
|
||||||
if (signer->created)
|
if (signer->created) {
|
||||||
printf (", \"created\": %d", (int) signer->created);
|
sp->map_key (sp, "created");
|
||||||
if (signer->expires)
|
sp->integer (sp, signer->created);
|
||||||
printf (", \"expires\": %d", (int) signer->expires);
|
}
|
||||||
|
if (signer->expires) {
|
||||||
|
sp->map_key (sp, "expires");
|
||||||
|
sp->integer (sp, signer->expires);
|
||||||
|
}
|
||||||
/* output user id only if validity is FULL or ULTIMATE. */
|
/* output user id only if validity is FULL or ULTIMATE. */
|
||||||
/* note that gmime is using the term "trust" here, which
|
/* note that gmime is using the term "trust" here, which
|
||||||
* is WRONG. It's actually user id "validity". */
|
* is WRONG. It's actually user id "validity". */
|
||||||
if ((signer->name) && (signer->trust)) {
|
if ((signer->name) && (signer->trust)) {
|
||||||
if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE))
|
if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) {
|
||||||
printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name));
|
sp->map_key (sp, "userid");
|
||||||
|
sp->string (sp, signer->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (signer->keyid)
|
if (signer->keyid) {
|
||||||
printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid));
|
sp->map_key (sp, "keyid");
|
||||||
|
sp->string (sp, signer->keyid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
|
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;
|
signer = signer->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("]");
|
sp->end (sp);
|
||||||
|
|
||||||
talloc_free (ctx_quote);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -607,7 +611,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
|
||||||
|
|
||||||
if (node->verify_attempted) {
|
if (node->verify_attempted) {
|
||||||
printf (", \"sigstatus\": ");
|
printf (", \"sigstatus\": ");
|
||||||
format_part_sigstatus_json (node);
|
format_part_sigstatus_json (sp, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf (", \"content-type\": %s",
|
printf (", \"content-type\": %s",
|
||||||
|
|
Loading…
Reference in a new issue