aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-11-22 00:06:54 -0800
committerGuy Harris <guy@alum.mit.edu>2014-11-22 08:07:24 +0000
commitb19b12a85daa9ec91537c733d05550f5dfafa0eb (patch)
treec97c8158905d05f4f8a29980de89b3e5022352e6
parent6e1214c4df15acba6f55a75256e90dc96640d4b3 (diff)
Get rid of write_headers global variable.
Have write_psml_preamble() and write_csv_preamble() take a capture_file * as an argument, so they can print the column titles themselves, rather than having to defer it to the routine that prints packet data. Change-Id: Ifd1b7a13062be8ad46846315976922a752778153 Reviewed-on: https://code.wireshark.org/review/5438 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--epan/print.c55
-rw-r--r--epan/print.h4
-rw-r--r--file.c4
-rw-r--r--tshark.c2
4 files changed, 27 insertions, 38 deletions
diff --git a/epan/print.c b/epan/print.c
index b0e0f0c7be..4ccc0d0ef4 100644
--- a/epan/print.c
+++ b/epan/print.c
@@ -87,8 +87,6 @@ struct _output_fields {
GHashTable *output_only_tables = NULL;
-static gboolean write_headers = FALSE;
-
static gchar *get_field_hex_value(GSList *src_list, field_info *fi);
static void proto_tree_print_node(proto_node *node, gpointer data);
static void proto_tree_write_node_pdml(proto_node *node, gpointer data);
@@ -587,12 +585,22 @@ write_pdml_finale(FILE *fh)
}
void
-write_psml_preamble(FILE *fh)
+write_psml_preamble(capture_file *cf, FILE *fh)
{
+ gint i;
+
fputs("<?xml version=\"1.0\"?>\n", fh);
fputs("<psml version=\"" PSML_VERSION "\" ", fh);
fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
- write_headers = TRUE;
+ fprintf(fh, "<structure>\n");
+
+ for (i = 0; i < cf->cinfo.num_cols; i++) {
+ fprintf(fh, "<section>");
+ print_escaped_xml(fh, cf->cinfo.col_title[i]);
+ fprintf(fh, "</section>\n");
+ }
+
+ fprintf(fh, "</structure>\n\n");
}
void
@@ -600,21 +608,6 @@ proto_tree_write_psml(epan_dissect_t *edt, FILE *fh)
{
gint i;
- /* if this is the first packet, we have to create the PSML structure output */
- if (write_headers) {
- fprintf(fh, "<structure>\n");
-
- for (i = 0; i < edt->pi.cinfo->num_cols; i++) {
- fprintf(fh, "<section>");
- print_escaped_xml(fh, edt->pi.cinfo->col_title[i]);
- fprintf(fh, "</section>\n");
- }
-
- fprintf(fh, "</structure>\n\n");
-
- write_headers = FALSE;
- }
-
fprintf(fh, "<packet>\n");
for (i = 0; i < edt->pi.cinfo->num_cols; i++) {
@@ -632,12 +625,6 @@ write_psml_finale(FILE *fh)
fputs("</psml>\n", fh);
}
-void
-write_csv_preamble(FILE *fh _U_)
-{
- write_headers = TRUE;
-}
-
static gchar *csv_massage_str(const gchar *source, const gchar *exceptions)
{
gchar *csv_str;
@@ -671,17 +658,19 @@ static void csv_write_str(const char *str, char sep, FILE *fh)
}
void
-proto_tree_write_csv(epan_dissect_t *edt, FILE *fh)
+write_csv_preamble(capture_file *cf, FILE *fh)
{
gint i;
- /* if this is the first packet, we have to write the CSV header */
- if (write_headers) {
- for (i = 0; i < edt->pi.cinfo->num_cols - 1; i++)
- csv_write_str(edt->pi.cinfo->col_title[i], ',', fh);
- csv_write_str(edt->pi.cinfo->col_title[i], '\n', fh);
- write_headers = FALSE;
- }
+ for (i = 0; i < cf->cinfo.num_cols - 1; i++)
+ csv_write_str(cf->cinfo.col_title[i], ',', fh);
+ csv_write_str(cf->cinfo.col_title[i], '\n', fh);
+}
+
+void
+proto_tree_write_csv(epan_dissect_t *edt, FILE *fh)
+{
+ gint i;
for (i = 0; i < edt->pi.cinfo->num_cols - 1; i++)
csv_write_str(edt->pi.cinfo->col_data[i], ',', fh);
diff --git a/epan/print.h b/epan/print.h
index 816c401660..020cce53ac 100644
--- a/epan/print.h
+++ b/epan/print.h
@@ -111,11 +111,11 @@ WS_DLL_PUBLIC void write_pdml_preamble(FILE *fh, const gchar* filename);
WS_DLL_PUBLIC void proto_tree_write_pdml(epan_dissect_t *edt, FILE *fh);
WS_DLL_PUBLIC void write_pdml_finale(FILE *fh);
-WS_DLL_PUBLIC void write_psml_preamble(FILE *fh);
+WS_DLL_PUBLIC void write_psml_preamble(capture_file *cf, FILE *fh);
WS_DLL_PUBLIC void proto_tree_write_psml(epan_dissect_t *edt, FILE *fh);
WS_DLL_PUBLIC void write_psml_finale(FILE *fh);
-WS_DLL_PUBLIC void write_csv_preamble(FILE *fh);
+WS_DLL_PUBLIC void write_csv_preamble(capture_file *cf, FILE *fh);
WS_DLL_PUBLIC void proto_tree_write_csv(epan_dissect_t *edt, FILE *fh);
WS_DLL_PUBLIC void write_csv_finale(FILE *fh);
diff --git a/file.c b/file.c
index ecb42887b5..8606b97a3d 100644
--- a/file.c
+++ b/file.c
@@ -2821,7 +2821,7 @@ cf_write_psml_packets(capture_file *cf, print_args_t *print_args)
if (fh == NULL)
return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
- write_psml_preamble(fh);
+ write_psml_preamble(cf, fh);
if (ferror(fh)) {
fclose(fh);
return CF_PRINT_WRITE_ERROR;
@@ -2902,7 +2902,7 @@ cf_write_csv_packets(capture_file *cf, print_args_t *print_args)
if (fh == NULL)
return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
- write_csv_preamble(fh);
+ write_csv_preamble(cf, fh);
if (ferror(fh)) {
fclose(fh);
return CF_PRINT_WRITE_ERROR;
diff --git a/tshark.c b/tshark.c
index 10dbb5f6d9..7879f296b9 100644
--- a/tshark.c
+++ b/tshark.c
@@ -3596,7 +3596,7 @@ write_preamble(capture_file *cf)
if (print_details)
write_pdml_preamble(stdout, cf ? cf->filename : NULL);
else
- write_psml_preamble(stdout);
+ write_psml_preamble(cf, stdout);
return !ferror(stdout);
case WRITE_FIELDS: