forked from osmocom/wireshark
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>
This commit is contained in:
parent
6e1214c4df
commit
b19b12a85d
55
epan/print.c
55
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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
4
file.c
4
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;
|
||||
|
|
Loading…
Reference in New Issue