Add support for color xml attributes in psml and pdml formats.

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>
This commit is contained in:
Michael Mann 2017-06-11 12:03:13 -04:00 committed by Anders Broman
parent f4dd096afb
commit 585d17ae7f
7 changed files with 37 additions and 12 deletions

View 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

View 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

View 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>");

View 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);

4
file.c
View File

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

View File

@ -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:

View File

@ -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: