summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorPascal Quantin <pascal.quantin@gmail.com>2016-11-04 07:45:09 +0100
committerPascal Quantin <pascal.quantin@gmail.com>2016-11-07 19:59:21 +0000
commit1b91475e0da15e58a9df7cd0cee6a463a8e0c97e (patch)
tree795f97b3cbe9fc710c704a05ce0d7d5bcc7da1ee /epan
parent3814eee112070b43eaf9dc39e7b19b2349ac6957 (diff)
downloadwireshark-1b91475e0da15e58a9df7cd0cee6a463a8e0c97e.tar.gz
JSON: print field value for an item containing a subtree
For fields that contain both a value and a subtree, print the value and then create a new item with a _tree suffix for the subtree content Bug: 13086 Change-Id: I5a3c96bf9895d87faff3925d439bb54b73769a3e Reviewed-on: https://code.wireshark.org/review/18663 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Martin Kacer <kacer.martin@gmail.com> Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r--epan/print.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/epan/print.c b/epan/print.c
index 5e82740eeb..a2da37516a 100644
--- a/epan/print.c
+++ b/epan/print.c
@@ -378,7 +378,7 @@ write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar *
fputs(" }\n", fh);
fputs(" }\n", fh);
- fputs(" }", fh);
+ fputs(" }\n", fh);
}
@@ -831,11 +831,17 @@ proto_tree_write_node_json(proto_node *node, gpointer data)
default:
dfilter_string = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
if (dfilter_string != NULL) {
- if (node->first_child == NULL) {
- fputs("\": \"", pdata->fh);
- print_escaped_json(pdata->fh, dfilter_string);
- } else {
- fputs("\": {\n", pdata->fh);
+ fputs("\": \"", pdata->fh);
+ print_escaped_json(pdata->fh, dfilter_string);
+ if (node->first_child != NULL) {
+ fputs("\",\n", pdata->fh);
+ /* Indent to the correct level */
+ for (i = -3; i < pdata->level; i++) {
+ fputs(" ", pdata->fh);
+ }
+ fputs("\"", pdata->fh);
+ print_escaped_json(pdata->fh, fi->hfinfo->abbrev);
+ fputs("_tree\": {\n", pdata->fh);
}
}
wmem_free(NULL, dfilter_string);
@@ -1036,21 +1042,15 @@ proto_tree_write_node_ek(proto_node *node, gpointer data)
default:
dfilter_string = fvalue_to_string_repr(NULL, &fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
if (dfilter_string != NULL) {
- if (node->first_child == NULL) {
- fputs("\": \"", pdata->fh);
- print_escaped_json(pdata->fh, dfilter_string);
- } else {
- fputs("\": \"\",", pdata->fh);
- }
+ fputs("\": \"", pdata->fh);
+ print_escaped_json(pdata->fh, dfilter_string);
}
wmem_free(NULL, dfilter_string);
- if (node->first_child == NULL) {
- if (node->next == NULL) {
- fputs("\"", pdata->fh);
- } else {
- fputs("\",", pdata->fh);
- }
+ if (node->next == NULL) {
+ fputs("\"", pdata->fh);
+ } else {
+ fputs("\",", pdata->fh);
}
}