static void newline(state_t *state) { state_printf(state, "\n"); for (int i = 0; i < state->depth; i++) { state_printf(state, " "); } }
static int print_internal_func(bithenge_node_t *key, bithenge_node_t *value, void *data) { state_t *state = (state_t *)data; int rc = EOK; if (!state->first) state_printf(state, ","); newline(state); state->first = false; bool add_quotes = state->type == BITHENGE_PRINT_JSON && bithenge_node_type(key) != BITHENGE_NODE_STRING; if (add_quotes) state_printf(state, "\""); rc = print_node(state, key); if (rc != EOK) goto end; if (add_quotes) state_printf(state, "\""); state_printf(state, ": "); rc = print_node(state, value); if (rc != EOK) goto end; end: bithenge_node_dec_ref(key); bithenge_node_dec_ref(value); return rc; }
static int print_boolean(state_t *state, bithenge_node_t *node) { bool value = bithenge_boolean_node_value(node); switch (state->type) { case BITHENGE_PRINT_PYTHON: state_printf(state, value ? "True" : "False"); break; case BITHENGE_PRINT_JSON: state_printf(state, value ? "true" : "false"); break; } return EOK; }
static int print_internal(state_t *state, bithenge_node_t *node) { int rc; state_printf(state, "{"); increase_depth(state); state->first = true; rc = bithenge_node_for_each(node, print_internal_func, state); if (rc != EOK) return rc; decrease_depth(state); if (!state->first) newline(state); state->first = false; state_printf(state, "}"); return EOK; }
static int print_string(state_t *state, bithenge_node_t *node) { const char *value = bithenge_string_node_value(node); state_printf(state, "\""); for (string_iterator_t i = string_iterator(value); !string_iterator_done(&i); ) { wchar_t ch; int rc = string_iterator_next(&i, &ch); if (rc != EOK) return rc; if (ch == '"' || ch == '\\') { state_printf(state, "\\%lc", (wint_t) ch); } else if (ch <= 0x1f) { state_printf(state, "\\u%04x", (unsigned int) ch); } else { state_printf(state, "%lc", (wint_t) ch); } } state_printf(state, "\""); return EOK; }
static int print_blob(state_t *state, bithenge_node_t *node) { bithenge_blob_t *blob = bithenge_node_as_blob(node); aoff64_t pos = 0; uint8_t buffer[1024]; aoff64_t size = sizeof(buffer); int rc; state_printf(state, state->type == BITHENGE_PRINT_PYTHON ? "b\"" : "\""); do { rc = bithenge_blob_read(blob, pos, (char *)buffer, &size); if (rc != EOK) return rc; for (aoff64_t i = 0; i < size; i++) state_printf(state, "\\x%02x", (unsigned int)buffer[i]); pos += size; } while (size == sizeof(buffer)); state_printf(state, "\""); return EOK; }
/** * mutt_signed_handler - Verify a "multipart/signed" body - Implements ::handler_t */ int mutt_signed_handler(struct Body *a, struct State *s) { bool inconsistent = false; struct Body *b = a; struct Body **signatures = NULL; int sigcnt = 0; int rc = 0; if (!WithCrypto) return -1; a = a->parts; SecurityFlags signed_type = mutt_is_multipart_signed(b); if (signed_type == SEC_NO_FLAGS) { /* A null protocol value is already checked for in mutt_body_handler() */ state_printf(s, _("[-- Error: " "Unknown multipart/signed protocol %s --]\n\n"), mutt_param_get(&b->parameter, "protocol")); return mutt_body_handler(a, s); } if (!(a && a->next)) inconsistent = true; else { switch (signed_type) { case SEC_SIGN: if ((a->next->type != TYPE_MULTIPART) || (mutt_str_strcasecmp(a->next->subtype, "mixed") != 0)) { inconsistent = true; } break; case PGP_SIGN: if ((a->next->type != TYPE_APPLICATION) || (mutt_str_strcasecmp(a->next->subtype, "pgp-signature") != 0)) { inconsistent = true; } break; case SMIME_SIGN: if ((a->next->type != TYPE_APPLICATION) || ((mutt_str_strcasecmp(a->next->subtype, "x-pkcs7-signature") != 0) && (mutt_str_strcasecmp(a->next->subtype, "pkcs7-signature") != 0))) { inconsistent = true; } break; default: inconsistent = true; } } if (inconsistent) { state_attach_puts(_("[-- Error: " "Missing or bad-format multipart/signed signature" " --]\n\n"), s); return mutt_body_handler(a, s); } if (s->flags & MUTT_DISPLAY) { crypt_fetch_signatures(&signatures, a->next, &sigcnt); if (sigcnt) { char tempfile[PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); bool goodsig = true; if (crypt_write_signed(a, s, tempfile) == 0) { for (int i = 0; i < sigcnt; i++) { if (((WithCrypto & APPLICATION_PGP) != 0) && (signatures[i]->type == TYPE_APPLICATION) && (mutt_str_strcasecmp(signatures[i]->subtype, "pgp-signature") == 0)) { if (crypt_pgp_verify_one(signatures[i], s, tempfile) != 0) goodsig = false; continue; } if (((WithCrypto & APPLICATION_SMIME) != 0) && (signatures[i]->type == TYPE_APPLICATION) && ((mutt_str_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature") == 0) || (mutt_str_strcasecmp(signatures[i]->subtype, "pkcs7-signature") == 0))) { if (crypt_smime_verify_one(signatures[i], s, tempfile) != 0) goodsig = false; continue; } state_printf(s, _("[-- Warning: " "We can't verify %s/%s signatures. --]\n\n"), TYPE(signatures[i]), signatures[i]->subtype); } } mutt_file_unlink(tempfile); b->goodsig = goodsig; b->badsig = !goodsig; /* Now display the signed body */ state_attach_puts(_("[-- The following data is signed --]\n\n"), s); mutt_protected_headers_handler(a, s); FREE(&signatures); } else state_attach_puts(_("[-- Warning: Can't find any signatures. --]\n\n"), s); } rc = mutt_body_handler(a, s); if (s->flags & MUTT_DISPLAY && sigcnt) state_attach_puts(_("\n[-- End of signed data --]\n"), s); return rc; }
static int print_integer(state_t *state, bithenge_node_t *node) { bithenge_int_t value = bithenge_integer_node_value(node); state_printf(state, "%" BITHENGE_PRId, value); return EOK; }