From b0eac84840567f2e535faf01816e3c1a87473213 Mon Sep 17 00:00:00 2001 From: Pascal Quantin Date: Mon, 31 Oct 2016 23:02:44 +0100 Subject: Small fixes for JSON output - reinitialize the variable used to insert comma between packets when performing a new export - ensure that escaped ASCII characters are code on 4 digits characters Change-Id: Ib557da4843f6b98f793b60e417260ebb27a38b99 Ping-Bug: 13073 Reviewed-on: https://code.wireshark.org/review/18598 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/print.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'epan/print.c') diff --git a/epan/print.c b/epan/print.c index f365f0ed94..5e82740eeb 100644 --- a/epan/print.c +++ b/epan/print.c @@ -109,6 +109,8 @@ static void print_pdml_geninfo(epan_dissect_t *edt, FILE *fh); static void proto_tree_get_node_field_values(proto_node *node, gpointer data); +static gboolean json_is_first; + /* Cache the protocols and field handles that the print functionality needs This helps break explicit dependency on the dissectors. */ static int proto_data = -1; @@ -274,6 +276,7 @@ void write_json_preamble(FILE *fh) { fputs("[\n", fh); + json_is_first = TRUE; } /* Check if the str match the protocolfilter. json_filter is space @@ -335,7 +338,6 @@ write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar * char ts[30]; time_t t = time(NULL); struct tm * timeinfo; - static gboolean is_first = TRUE; g_assert(edt); g_assert(fh); @@ -347,10 +349,10 @@ write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar * else g_strlcpy(ts, "XXXX-XX-XX", sizeof ts); /* XXX - better way of saying "Not representable"? */ - if (!is_first) + if (!json_is_first) fputs(" ,\n", fh); else - is_first = FALSE; + json_is_first = FALSE; fputs(" {\n", fh); fprintf(fh, " \"_index\": \"packets-%s\",\n", ts); @@ -1477,7 +1479,7 @@ print_escaped_bare(FILE *fh, const char *unescaped_string, gboolean change_dot) if (g_ascii_isprint(*p)) fputc(*p, fh); else { - g_snprintf(temp_str, sizeof(temp_str), "\\u00%u", (guint8)*p); + g_snprintf(temp_str, sizeof(temp_str), "\\u00%02x", (guint8)*p); fputs(temp_str, fh); } } -- cgit v1.2.3