Add columns (_ws.col) to output formats json, ek, pdml
authorMerlin Chlosta <merlin.chlosta+gnuradio@ruhr-uni-bochum.de>
Thu, 21 Dec 2017 13:58:07 +0000 (14:58 +0100)
committerAnders Broman <a.broman58@gmail.com>
Tue, 2 Jan 2018 05:27:51 +0000 (05:27 +0000)
Bug: 13020
Change-Id: Ia83797a4e390be7cc59a9718735edc1c7f9a5712
Reviewed-on: https://code.wireshark.org/review/24928
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
epan/print.c
epan/print.h
file.c
tshark.c

index 09f5a334c2c3e9584906932e5b862fa061098434..27c810546c687c48835cb8e3e71a0ddcfde48e48 100755 (executable)
@@ -310,7 +310,7 @@ static gboolean check_protocolfilter(gchar **protocolfilter, const char *str)
 }
 
 void
-write_pdml_proto_tree(output_fields_t* fields, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, FILE *fh, gboolean use_color)
+write_pdml_proto_tree(output_fields_t* fields, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, column_info *cinfo, FILE *fh, gboolean use_color)
 {
     write_pdml_data data;
     const color_filter_t *cfp;
@@ -345,7 +345,7 @@ write_pdml_proto_tree(output_fields_t* fields, gchar **protocolfilter, pf_flags
                                     &data);
     } else {
         /* Write out specified fields */
-        write_specified_fields(FORMAT_XML, fields, edt, NULL, fh);
+        write_specified_fields(FORMAT_XML, fields, edt, cinfo, fh);
     }
 
     fprintf(fh, "</packet>\n\n");
@@ -356,6 +356,7 @@ write_ek_proto_tree(output_fields_t* fields,
                     gboolean print_summary, gboolean print_hex,
                     gchar **protocolfilter,
                     pf_flags protocolfilter_flags, epan_dissect_t *edt,
+                    column_info *cinfo,
                     FILE *fh)
 {
     write_json_data data;
@@ -395,7 +396,7 @@ write_ek_proto_tree(output_fields_t* fields,
             proto_tree_write_node_ek(edt->tree, &data);
         } else {
             /* Write out specified fields */
-            write_specified_fields(FORMAT_EK, fields, edt, NULL, fh);
+            write_specified_fields(FORMAT_EK, fields, edt, cinfo, fh);
         }
 
         fputs("}", fh);
@@ -703,6 +704,7 @@ write_json_proto_tree(output_fields_t* fields,
                       print_dissections_e print_dissections,
                       gboolean print_hex, gchar **protocolfilter,
                       pf_flags protocolfilter_flags, epan_dissect_t *edt,
+                      column_info *cinfo,
                       proto_node_children_grouper_func node_children_grouper,
                       FILE *fh)
 {
@@ -747,7 +749,7 @@ write_json_proto_tree(output_fields_t* fields,
 
         write_json_proto_node_children(edt->tree, &data);
     } else {
-        write_specified_fields(FORMAT_JSON, fields, edt, NULL, fh);
+        write_specified_fields(FORMAT_JSON, fields, edt, cinfo, fh);
     }
 
     fputs("\n", fh);
@@ -2437,21 +2439,22 @@ static void write_specified_fields(fields_format format, output_fields_t *fields
     proto_tree_children_foreach(edt->tree, proto_tree_get_node_field_values,
                                 &data);
 
-    switch (format) {
-    case FORMAT_CSV:
-        if (fields->includes_col_fields) {
-            for (col = 0; col < cinfo->num_cols; col++) {
-                /* Prepend COLUMN_FIELD_FILTER as the field name */
-                col_name = g_strdup_printf("%s%s", COLUMN_FIELD_FILTER, cinfo->columns[col].col_title);
-                field_index = g_hash_table_lookup(fields->field_indicies, col_name);
-                g_free(col_name);
-
-                if (NULL != field_index) {
-                    format_field_values(fields, field_index, g_strdup(cinfo->columns[col].col_data));
-                }
+    /* Add columns to fields */
+    if (fields->includes_col_fields) {
+        for (col = 0; col < cinfo->num_cols; col++) {
+            /* Prepend COLUMN_FIELD_FILTER as the field name */
+            col_name = g_strdup_printf("%s%s", COLUMN_FIELD_FILTER, cinfo->columns[col].col_title);
+            field_index = g_hash_table_lookup(fields->field_indicies, col_name);
+            g_free(col_name);
+
+            if (NULL != field_index) {
+                format_field_values(fields, field_index, g_strdup(cinfo->columns[col].col_data));
             }
         }
+    }
 
+    switch (format) {
+    case FORMAT_CSV:
         for(i = 0; i < fields->fields->len; ++i) {
             if (0 != i) {
                 fputc(fields->separator, fh);
index c815698b61c5aa3f8daa115042a749f6869c97bd..9d0e0ff45e53f6a0a1a22bdcbdb711b54d42532b 100644 (file)
@@ -94,7 +94,7 @@ WS_DLL_PUBLIC gboolean proto_tree_print(print_dissections_e print_dissections,
 WS_DLL_PUBLIC gboolean print_hex_data(print_stream_t *stream, epan_dissect_t *edt);
 
 WS_DLL_PUBLIC void write_pdml_preamble(FILE *fh, const gchar* filename);
-WS_DLL_PUBLIC void write_pdml_proto_tree(output_fields_t* fields, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, FILE *fh, gboolean use_color);
+WS_DLL_PUBLIC void write_pdml_proto_tree(output_fields_t* fields, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, column_info *cinfo, FILE *fh, gboolean use_color);
 WS_DLL_PUBLIC void write_pdml_finale(FILE *fh);
 
 // Implementations of proto_node_children_grouper_func
@@ -110,6 +110,7 @@ WS_DLL_PUBLIC void write_json_proto_tree(output_fields_t* fields,
                                          gchar **protocolfilter,
                                          pf_flags protocolfilter_flags,
                                          epan_dissect_t *edt,
+                                         column_info *cinfo,
                                          proto_node_children_grouper_func node_children_grouper,
                                          FILE *fh);
 WS_DLL_PUBLIC void write_json_finale(FILE *fh);
@@ -119,7 +120,8 @@ WS_DLL_PUBLIC void write_ek_proto_tree(output_fields_t* fields,
                                        gboolean print_hex_data,
                                        gchar **protocolfilter,
                                        pf_flags protocolfilter_flags,
-                                       epan_dissect_t *edt, FILE *fh);
+                                       epan_dissect_t *edt,
+                                       column_info *cinfo, FILE *fh);
 
 WS_DLL_PUBLIC void write_psml_preamble(column_info *cinfo, FILE *fh);
 WS_DLL_PUBLIC void write_psml_columns(epan_dissect_t *edt, FILE *fh, gboolean use_color);
diff --git a/file.c b/file.c
index ac6fce2a68eead529af079e5795684a8bd2f35cb..54172f6e895706e79f81f6c71d1af94b99791b15 100644 (file)
--- a/file.c
+++ b/file.c
@@ -2514,7 +2514,7 @@ write_pdml_packet(capture_file *cf, frame_data *fdata,
                    frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL);
 
   /* Write out the information in that tree. */
-  write_pdml_proto_tree(NULL, NULL, PF_NONE, &args->edt, args->fh, FALSE);
+  write_pdml_proto_tree(NULL, NULL, PF_NONE, &args->edt, &cf->cinfo, args->fh, FALSE);
 
   epan_dissect_reset(&args->edt);
 
@@ -2816,7 +2816,7 @@ write_json_packet(capture_file *cf, frame_data *fdata,
   /* Write out the information in that tree. */
   write_json_proto_tree(NULL, args->print_args->print_dissections,
                         args->print_args->print_hex, NULL, PF_NONE,
-                        &args->edt, proto_node_group_children_by_unique, args->fh);
+                        &args->edt, &cf->cinfo, proto_node_group_children_by_unique, args->fh);
 
   epan_dissect_reset(&args->edt);
 
index affd4885b6057a0a2de6dd495c47148acaeb0eee..687b6c14d553e4bda781c6bcb93ce8dd23e31aed 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -3910,7 +3910,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
       return !ferror(stdout);
     }
     if (print_details) {
-      write_pdml_proto_tree(output_fields, protocolfilter, protocolfilter_flags, edt, stdout, dissect_color);
+      write_pdml_proto_tree(output_fields, protocolfilter, protocolfilter_flags, edt, &cf->cinfo, stdout, dissect_color);
       printf("\n");
       return !ferror(stdout);
     }
@@ -3934,7 +3934,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
     if (print_details) {
       write_json_proto_tree(output_fields, print_dissections_expanded,
                             print_hex, protocolfilter, protocolfilter_flags,
-                            edt, node_children_grouper, stdout);
+                            edt, &cf->cinfo, node_children_grouper, stdout);
       return !ferror(stdout);
     }
     break;
@@ -3945,14 +3945,14 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
     if (print_details) {
       write_json_proto_tree(output_fields, print_dissections_none, TRUE,
                             protocolfilter, protocolfilter_flags,
-                            edt, node_children_grouper, stdout);
+                            edt, &cf->cinfo, node_children_grouper, stdout);
       return !ferror(stdout);
     }
     break;
 
   case WRITE_EK:
     write_ek_proto_tree(output_fields, print_summary, print_hex, protocolfilter,
-                        protocolfilter_flags, edt, stdout);
+                        protocolfilter_flags, edt, &cf->cinfo, stdout);
     return !ferror(stdout);
   }