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 <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Pascal Quantin 2016-10-31 23:02:44 +01:00 committed by Michael Mann
parent 9ff6bb28d2
commit b0eac84840
1 changed files with 6 additions and 4 deletions

View File

@ -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);
}
}