diff options
-rw-r--r-- | epan/print.c | 55 | ||||
-rw-r--r-- | epan/print.h | 4 | ||||
-rw-r--r-- | file.c | 4 | ||||
-rw-r--r-- | tshark.c | 2 |
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); @@ -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; @@ -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: |