Add support for color xml attributes in psml and pdml formats.
authorMichael Mann <mmann78@netscape.net>
Sun, 11 Jun 2017 16:03:13 +0000 (12:03 -0400)
committerAnders Broman <a.broman58@gmail.com>
Mon, 12 Jun 2017 03:23:38 +0000 (03:23 +0000)
Bug: 6682
Change-Id: I19330d06aa3d5692503c61369c3c650d595971f5
Reviewed-on: https://code.wireshark.org/review/22077
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stephen Donnelly <stephen.donnelly@endace.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
doc/README.xml-output
doc/tshark.pod
epan/print.c
epan/print.h
file.c
tfshark.c
tshark.c

index 31fd6e2006a8fb8f88b81a128f386666add3d72e..b3011ae24cf29467b7a7f088fe148dd92a7127ff 100644 (file)
@@ -143,6 +143,8 @@ In PDML, the "Data" protocol would become another field under HTTP:
        </proto>
 </packet>
 
+Note that packet tag may have nonstandard color attributes, "foreground" and "background"
+
 tools/WiresharkXML.py
 ====================
 This is a python module which provides some infrastructure for
index 512ff1c906d45327f476f028a5fe57dda847d4d1..208d6cc44ee2bb4d85f48bf960707dfb2348cd38 100644 (file)
@@ -792,6 +792,8 @@ Example of usage:
 B<pdml> Packet Details Markup Language, an XML-based format for the details of
 a decoded packet.  This information is equivalent to the packet details
 printed with the B<-V> flag.
+Using the --color option will add color attributes to B<pdml> output. These
+attributes are nonstandard.
 
 B<ps> PostScript for a human-readable one-line summary of each of the packets,
 or a multi-line view of the details of each of the packets, depending on
@@ -800,6 +802,8 @@ whether the B<-V> flag was specified.
 B<psml> Packet Summary Markup Language, an XML-based format for the summary
 information of a decoded packet.  This information is equivalent to the
 information shown in the one-line summary printed by default.
+Using the --color option will add color attributes to B<pdml> output. These
+attributes are nonstandard.
 
 B<tabs> Similar to the default B<text> report except the human-readable one-line
 summary of each packet will include an ASCII horizontal tab (0x09) character
index 074621ae0136f40277ada05f36d47f45ca7bb505..d4343aaadb18ce010559fe09a6c30f6f877c1566 100644 (file)
@@ -33,6 +33,7 @@
 #include <epan/to_str.h>
 #include <epan/expert.h>
 #include <epan/column-info.h>
+#include <epan/color_filters.h>
 #include <epan/prefs.h>
 #include <epan/print.h>
 #include <epan/charsets.h>
@@ -298,15 +299,23 @@ 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)
+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_data data;
+    const color_filter_t *cfp = edt->pi.fd->color_filter;
 
     g_assert(edt);
     g_assert(fh);
 
     /* Create the output */
-    fprintf(fh, "<packet>\n");
+    if (use_color && (cfp != NULL)) {
+        fprintf(fh, "<packet foreground='#%02x%02x%02x' background='#%02x%02x%02x'>\n",
+            cfp->fg_color.red, cfp->fg_color.green, cfp->fg_color.blue,
+            cfp->bg_color.red, cfp->bg_color.green, cfp->bg_color.blue);
+    }
+    else {
+        fprintf(fh, "<packet>\n");
+    }
 
     /* Print a "geninfo" protocol as required by PDML */
     print_pdml_geninfo(edt, fh);
@@ -1287,11 +1296,19 @@ write_psml_preamble(column_info *cinfo, FILE *fh)
 }
 
 void
-write_psml_columns(epan_dissect_t *edt, FILE *fh)
+write_psml_columns(epan_dissect_t *edt, FILE *fh, gboolean use_color)
 {
     gint i;
+    const color_filter_t *cfp = edt->pi.fd->color_filter;
 
-    fprintf(fh, "<packet>\n");
+    if (use_color && (cfp != NULL)) {
+        fprintf(fh, "<packet foreground='#%02x%02x%02x' background='#%02x%02x%02x'>\n",
+            cfp->fg_color.red, cfp->fg_color.green, cfp->fg_color.blue,
+            cfp->bg_color.red, cfp->bg_color.green, cfp->bg_color.blue);
+    }
+    else {
+        fprintf(fh, "<packet>\n");
+    }
 
     for (i = 0; i < edt->pi.cinfo->num_cols; i++) {
         fprintf(fh, "<section>");
index 6dedc308787326ba392a1b210641d0d97aaf4bce..bfa2ab482a164b0f36d0f6d5004e12bc98e16bca 100644 (file)
@@ -92,7 +92,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);
+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_finale(FILE *fh);
 
 WS_DLL_PUBLIC void write_json_preamble(FILE *fh);
@@ -111,7 +111,7 @@ WS_DLL_PUBLIC void write_ek_proto_tree(output_fields_t* fields,
                                        epan_dissect_t *edt, 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);
+WS_DLL_PUBLIC void write_psml_columns(epan_dissect_t *edt, FILE *fh, gboolean use_color);
 WS_DLL_PUBLIC void write_psml_finale(FILE *fh);
 
 WS_DLL_PUBLIC void write_csv_column_titles(column_info *cinfo, FILE *fh);
diff --git a/file.c b/file.c
index 7cbab798eed97bf0344e1435065d3a88fa0906aa..a0b47841002020bd753445bb17ea9533d841e901 100644 (file)
--- a/file.c
+++ b/file.c
@@ -2547,7 +2547,7 @@ write_pdml_packet(capture_file *cf, frame_data *fdata,
   epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
 
   /* Write out the information in that tree. */
-  write_pdml_proto_tree(NULL, NULL, PF_NONE, &args->edt, args->fh);
+  write_pdml_proto_tree(NULL, NULL, PF_NONE, &args->edt, args->fh, FALSE);
 
   epan_dissect_reset(&args->edt);
 
@@ -2624,7 +2624,7 @@ write_psml_packet(capture_file *cf, frame_data *fdata,
   epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
 
   /* Write out the column information. */
-  write_psml_columns(&args->edt, args->fh);
+  write_psml_columns(&args->edt, args->fh, FALSE);
 
   epan_dissect_reset(&args->edt);
 
index 551a87bef0dcc580c3a09e7a3d614dd1c380a13a..8eb591654c732f8ea9ff693d531e26156dafc567 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
@@ -1999,7 +1999,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
         break;
 
       case WRITE_XML:
-        write_psml_columns(edt, stdout);
+        write_psml_columns(edt, stdout, FALSE);
         return !ferror(stdout);
       case WRITE_FIELDS: /*No non-verbose "fields" format */
         g_assert_not_reached();
@@ -2022,7 +2022,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
       break;
 
     case WRITE_XML:
-      write_pdml_proto_tree(NULL, NULL, PF_NONE, edt, stdout);
+      write_pdml_proto_tree(NULL, NULL, PF_NONE, edt, stdout, FALSE);
       printf("\n");
       return !ferror(stdout);
     case WRITE_FIELDS:
index 1c4c618a3f690523a36925350faa3e018908def7..eae9acf34e2349a3a88cec72028ff5d543fa3a45 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -444,6 +444,8 @@ print_usage(FILE *output)
   fprintf(output, "                           a directory named \"destdir\"\n");
   fprintf(output, "  --color                  color output text similarly to the Wireshark GUI,\n");
   fprintf(output, "                           requires a terminal with 24-bit color support\n");
+  fprintf(output, "                           Also supplies color attributes to pdml and psml formats\n");
+  fprintf(output, "                           (Note that attributes are nonstandard)\n");
 
   fprintf(output, "\n");
   fprintf(output, "Miscellaneous:\n");
@@ -3863,7 +3865,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
         break;
 
       case WRITE_XML:
-        write_psml_columns(edt, stdout);
+        write_psml_columns(edt, stdout, dissect_color);
         return !ferror(stdout);
       case WRITE_FIELDS: /*No non-verbose "fields" format */
       case WRITE_JSON:
@@ -3889,7 +3891,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
       break;
 
     case WRITE_XML:
-      write_pdml_proto_tree(output_fields, protocolfilter, protocolfilter_flags, edt, stdout);
+      write_pdml_proto_tree(output_fields, protocolfilter, protocolfilter_flags, edt, stdout, dissect_color);
       printf("\n");
       return !ferror(stdout);
     case WRITE_FIELDS: