Move UI-only stuff out of libwireshark.

Packet ranges are used only in the UI; move the packet range stuff into
libui.

Don't pass a print_args_t structure to libwireshark packet-printing
routines, just pass the few parameters they need.  Move the declaration
of print_args_t into file.h.

Change-Id: Icff5991eea7d7d56f33b4716105895263d275bcf
Reviewed-on: https://code.wireshark.org/review/21308
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2017-04-23 16:48:17 -07:00
parent 751e078d2b
commit e52c95c6c8
16 changed files with 86 additions and 99 deletions

View File

@ -924,12 +924,6 @@ libwireshark.so.0 libwireshark0 #MINVER#
p_add_proto_data@Base 1.9.1 p_add_proto_data@Base 1.9.1
p_get_proto_data@Base 1.9.1 p_get_proto_data@Base 1.9.1
p_remove_proto_data@Base 1.12.0~rc1 p_remove_proto_data@Base 1.12.0~rc1
packet_range_check@Base 1.12.0~rc1
packet_range_convert_str@Base 1.12.0~rc1
packet_range_init@Base 1.12.0~rc1
packet_range_process_all@Base 1.12.0~rc1
packet_range_process_init@Base 1.12.0~rc1
packet_range_process_packet@Base 1.12.0~rc1
parse_key_string@Base 1.9.1 parse_key_string@Base 1.9.1
pfilter_expression_head@Base 1.9.1 pfilter_expression_head@Base 1.9.1
plugin_if_apply_filter@Base 1.99.8 plugin_if_apply_filter@Base 1.99.8

View File

@ -132,7 +132,6 @@ set(LIBWIRESHARK_FILES
oids.c oids.c
osi-utils.c osi-utils.c
oui.c oui.c
packet_range.c
packet.c packet.c
print.c print.c
print_stream.c print_stream.c

View File

@ -95,7 +95,6 @@ LIBWIRESHARK_SRC = \
oids.c \ oids.c \
osi-utils.c \ osi-utils.c \
oui.c \ oui.c \
packet_range.c \
packet.c \ packet.c \
prefs.c \ prefs.c \
print.c \ print.c \
@ -247,7 +246,6 @@ LIBWIRESHARK_INCLUDES = \
oids.h \ oids.h \
osi-utils.h \ osi-utils.h \
oui.h \ oui.h \
packet_range.h \
packet.h \ packet.h \
packet_info.h \ packet_info.h \
params.h \ params.h \

View File

@ -32,7 +32,7 @@
#include <epan/epan_dissect.h> #include <epan/epan_dissect.h>
#include <epan/to_str.h> #include <epan/to_str.h>
#include <epan/expert.h> #include <epan/expert.h>
#include <epan/packet_range.h> #include <epan/column-info.h>
#include <epan/prefs.h> #include <epan/prefs.h>
#include <epan/print.h> #include <epan/print.h>
#include <epan/charsets.h> #include <epan/charsets.h>
@ -135,8 +135,9 @@ void print_cache_field_handles(void)
} }
gboolean gboolean
proto_tree_print(print_args_t *print_args, epan_dissect_t *edt, proto_tree_print(print_dissections_e print_dissections, gboolean print_hex_data,
GHashTable *output_only_tables, print_stream_t *stream) epan_dissect_t *edt, GHashTable *output_only_tables,
print_stream_t *stream)
{ {
print_data data; print_data data;
@ -146,10 +147,10 @@ proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
data.success = TRUE; data.success = TRUE;
data.src_list = edt->pi.data_src; data.src_list = edt->pi.data_src;
data.encoding = (packet_char_enc)edt->pi.fd->flags.encoding; data.encoding = (packet_char_enc)edt->pi.fd->flags.encoding;
data.print_dissections = print_args->print_dissections; data.print_dissections = print_dissections;
/* If we're printing the entire packet in hex, don't /* If we're printing the entire packet in hex, don't
print uninterpreted data fields in hex as well. */ print uninterpreted data fields in hex as well. */
data.print_hex_for_data = !print_args->print_hex; data.print_hex_for_data = !print_hex_data;
data.output_only_tables = output_only_tables; data.output_only_tables = output_only_tables;
proto_tree_children_foreach(edt->tree, proto_tree_print_node, &data); proto_tree_children_foreach(edt->tree, proto_tree_print_node, &data);
@ -337,7 +338,11 @@ write_pdml_proto_tree(output_fields_t* fields, gchar **protocolfilter, pf_flags
} }
void void
write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, FILE *fh) write_json_proto_tree(output_fields_t* fields,
print_dissections_e print_dissections,
gboolean print_hex_data, gchar **protocolfilter,
pf_flags protocolfilter_flags, epan_dissect_t *edt,
FILE *fh)
{ {
write_json_data data; write_json_data data;
char ts[30]; char ts[30];
@ -373,9 +378,9 @@ write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar *
data.src_list = edt->pi.data_src; data.src_list = edt->pi.data_src;
data.filter = protocolfilter; data.filter = protocolfilter;
data.filter_flags = protocolfilter_flags; data.filter_flags = protocolfilter_flags;
data.print_hex = print_args->print_hex; data.print_hex = print_hex_data;
data.print_text = TRUE; data.print_text = TRUE;
if (print_args->print_dissections == print_dissections_none) { if (print_dissections == print_dissections_none) {
data.print_text = FALSE; data.print_text = FALSE;
} }
@ -393,7 +398,10 @@ write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar *
} }
void void
write_ek_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, FILE *fh) write_ek_proto_tree(output_fields_t* fields,
gboolean print_hex_data, gchar **protocolfilter,
pf_flags protocolfilter_flags, epan_dissect_t *edt,
FILE *fh)
{ {
write_json_data data; write_json_data data;
char ts[30]; char ts[30];
@ -421,7 +429,7 @@ write_ek_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar **p
data.src_list = edt->pi.data_src; data.src_list = edt->pi.data_src;
data.filter = protocolfilter; data.filter = protocolfilter;
data.filter_flags = protocolfilter_flags; data.filter_flags = protocolfilter_flags;
data.print_hex = print_args->print_hex; data.print_hex = print_hex_data;
proto_tree_children_foreach(edt->tree, proto_tree_write_node_ek, proto_tree_children_foreach(edt->tree, proto_tree_write_node_ek,
&data); &data);

View File

@ -32,8 +32,6 @@
#include <epan/print_stream.h> #include <epan/print_stream.h>
#include <epan/packet_range.h>
#include "ws_symbol_export.h" #include "ws_symbol_export.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -46,14 +44,6 @@ typedef enum {
PR_FMT_PS /* postscript */ PR_FMT_PS /* postscript */
} print_format_e; } print_format_e;
/* print_range, enum which frames should be printed */
typedef enum {
print_range_selected_only, /* selected frame(s) only (currently only one) */
print_range_marked_only, /* marked frames only */
print_range_all_displayed, /* all frames currently displayed */
print_range_all_captured /* all frames in capture */
} print_range_e;
/* print_dissections, enum how the dissections should be printed */ /* print_dissections, enum how the dissections should be printed */
typedef enum { typedef enum {
print_dissections_none, /* no dissections at all */ print_dissections_none, /* no dissections at all */
@ -62,22 +52,6 @@ typedef enum {
print_dissections_expanded /* all dissection details */ print_dissections_expanded /* all dissection details */
} print_dissections_e; } print_dissections_e;
typedef struct {
print_stream_t *stream; /* the stream to which we're printing */
print_format_e format; /* plain text or PostScript */
gboolean to_file; /* TRUE if we're printing to a file */
char *file; /* file output pathname */
char *cmd; /* print command string (not win32) */
packet_range_t range;
gboolean print_summary; /* TRUE if we should print summary line. */
gboolean print_col_headings; /* TRUE if we should print column headings */
print_dissections_e print_dissections;
gboolean print_hex; /* TRUE if we should print hex data;
* FALSE if we should print only if not dissected. */
gboolean print_formfeed; /* TRUE if a formfeed should be printed before
* each new packet */
} print_args_t;
typedef enum { typedef enum {
FORMAT_CSV, /* CSV */ FORMAT_CSV, /* CSV */
@ -110,7 +84,8 @@ WS_DLL_PUBLIC gboolean output_fields_has_cols(output_fields_t* info);
* Higher-level packet-printing code. * Higher-level packet-printing code.
*/ */
WS_DLL_PUBLIC gboolean proto_tree_print(print_args_t *print_args, WS_DLL_PUBLIC gboolean proto_tree_print(print_dissections_e print_dissections,
gboolean print_hex_data,
epan_dissect_t *edt, epan_dissect_t *edt,
GHashTable *output_only_tables, GHashTable *output_only_tables,
print_stream_t *stream); print_stream_t *stream);
@ -121,10 +96,19 @@ WS_DLL_PUBLIC void write_pdml_proto_tree(output_fields_t* fields, gchar **protoc
WS_DLL_PUBLIC void write_pdml_finale(FILE *fh); WS_DLL_PUBLIC void write_pdml_finale(FILE *fh);
WS_DLL_PUBLIC void write_json_preamble(FILE *fh); WS_DLL_PUBLIC void write_json_preamble(FILE *fh);
WS_DLL_PUBLIC void write_json_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, FILE *fh); WS_DLL_PUBLIC void write_json_proto_tree(output_fields_t* fields,
print_dissections_e print_dissections,
gboolean print_hex_data,
gchar **protocolfilter,
pf_flags protocolfilter_flags,
epan_dissect_t *edt, FILE *fh);
WS_DLL_PUBLIC void write_json_finale(FILE *fh); WS_DLL_PUBLIC void write_json_finale(FILE *fh);
WS_DLL_PUBLIC void write_ek_proto_tree(output_fields_t* fields, print_args_t *print_args, gchar **protocolfilter, pf_flags protocolfilter_flags, epan_dissect_t *edt, FILE *fh); WS_DLL_PUBLIC void write_ek_proto_tree(output_fields_t* fields,
gboolean print_hex_data,
gchar **protocolfilter,
pf_flags protocolfilter_flags,
epan_dissect_t *edt, FILE *fh);
WS_DLL_PUBLIC void write_psml_preamble(column_info *cinfo, 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);

8
file.c
View File

@ -2321,7 +2321,9 @@ print_packet(capture_file *cf, frame_data *fdata,
} }
/* Print the information in that tree. */ /* Print the information in that tree. */
if (!proto_tree_print(args->print_args, &args->edt, NULL, args->print_args->stream)) if (!proto_tree_print(args->print_args->print_dissections,
args->print_args->print_hex, &args->edt, NULL,
args->print_args->stream))
goto fail; goto fail;
/* Print a blank line if we print anything after this (aka more than one packet). */ /* Print a blank line if we print anything after this (aka more than one packet). */
@ -2848,7 +2850,9 @@ write_json_packet(capture_file *cf, frame_data *fdata,
epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL); epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
/* Write out the information in that tree. */ /* Write out the information in that tree. */
write_json_proto_tree(NULL, args->print_args, NULL, PF_NONE, &args->edt, args->fh); write_json_proto_tree(NULL, args->print_args->print_dissections,
args->print_args->print_hex, NULL, PF_NONE,
&args->edt, args->fh);
epan_dissect_reset(&args->edt); epan_dissect_reset(&args->edt);

27
file.h
View File

@ -28,7 +28,7 @@
#include <epan/epan.h> #include <epan/epan.h>
#include <epan/print.h> #include <epan/print.h>
#include <epan/packet_range.h> #include <ui/packet_range.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -417,6 +417,31 @@ cf_read_status_t cf_retap_packets(capture_file *cf);
*/ */
void cf_timestamp_auto_precision(capture_file *cf); void cf_timestamp_auto_precision(capture_file *cf);
/* print_range, enum which frames should be printed */
typedef enum {
print_range_selected_only, /* selected frame(s) only (currently only one) */
print_range_marked_only, /* marked frames only */
print_range_all_displayed, /* all frames currently displayed */
print_range_all_captured /* all frames in capture */
} print_range_e;
typedef struct {
print_stream_t *stream; /* the stream to which we're printing */
print_format_e format; /* plain text or PostScript */
gboolean to_file; /* TRUE if we're printing to a file */
char *file; /* file output pathname */
char *cmd; /* print command string (not win32) */
packet_range_t range;
gboolean print_summary; /* TRUE if we should print summary line. */
gboolean print_col_headings; /* TRUE if we should print column headings */
print_dissections_e print_dissections;
gboolean print_hex; /* TRUE if we should print hex data;
* FALSE if we should print only if not dissected. */
gboolean print_formfeed; /* TRUE if a formfeed should be printed before
* each new packet */
} print_args_t;
/** /**
* Print the capture file. * Print the capture file.
* *

View File

@ -1979,8 +1979,6 @@ print_columns(capture_file *cf)
static gboolean static gboolean
print_packet(capture_file *cf, epan_dissect_t *edt) print_packet(capture_file *cf, epan_dissect_t *edt)
{ {
print_args_t print_args;
if (print_summary || output_fields_has_cols(output_fields)) { if (print_summary || output_fields_has_cols(output_fields)) {
/* Just fill in the columns. */ /* Just fill in the columns. */
epan_dissect_fill_in_columns(edt, FALSE, TRUE); epan_dissect_fill_in_columns(edt, FALSE, TRUE);
@ -2008,19 +2006,8 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
switch (output_action) { switch (output_action) {
case WRITE_TEXT: case WRITE_TEXT:
/* Only initialize the fields that are actually used in proto_tree_print. if (!proto_tree_print(print_details ? print_dissections_expanded : print_dissections_none,
* This is particularly important for .range, as that's heap memory which print_hex, edt, output_only_tables, print_stream))
* we would otherwise have to g_free().
print_args.to_file = TRUE;
print_args.format = print_format;
print_args.print_summary = print_summary;
print_args.print_formfeed = FALSE;
packet_range_init(&print_args.range, &cfile);
*/
print_args.print_hex = print_hex;
print_args.print_dissections = print_details ? print_dissections_expanded : print_dissections_none;
if (!proto_tree_print(&print_args, edt, output_only_tables, print_stream))
return FALSE; return FALSE;
if (!print_hex) { if (!print_hex) {
if (!print_line(print_stream, 0, separator)) if (!print_line(print_stream, 0, separator))

View File

@ -3779,8 +3779,6 @@ print_columns(capture_file *cf)
static gboolean static gboolean
print_packet(capture_file *cf, epan_dissect_t *edt) print_packet(capture_file *cf, epan_dissect_t *edt)
{ {
print_args_t print_args;
if (print_summary || output_fields_has_cols(output_fields)) { if (print_summary || output_fields_has_cols(output_fields)) {
/* Just fill in the columns. */ /* Just fill in the columns. */
epan_dissect_fill_in_columns(edt, FALSE, TRUE); epan_dissect_fill_in_columns(edt, FALSE, TRUE);
@ -3811,19 +3809,8 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
switch (output_action) { switch (output_action) {
case WRITE_TEXT: case WRITE_TEXT:
/* Only initialize the fields that are actually used in proto_tree_print. if (!proto_tree_print(print_details ? print_dissections_expanded : print_dissections_none,
* This is particularly important for .range, as that's heap memory which print_hex, edt, output_only_tables, print_stream))
* we would otherwise have to g_free().
print_args.to_file = TRUE;
print_args.format = print_format;
print_args.print_summary = print_summary;
print_args.print_formfeed = FALSE;
packet_range_init(&print_args.range, &cfile);
*/
print_args.print_hex = print_hex;
print_args.print_dissections = print_details ? print_dissections_expanded : print_dissections_none;
if (!proto_tree_print(&print_args, edt, output_only_tables, print_stream))
return FALSE; return FALSE;
if (!print_hex) { if (!print_hex) {
if (!print_line(print_stream, 0, separator)) if (!print_line(print_stream, 0, separator))
@ -3840,20 +3827,19 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
printf("\n"); printf("\n");
return !ferror(stdout); return !ferror(stdout);
case WRITE_JSON: case WRITE_JSON:
print_args.print_dissections = print_dissections_expanded; write_json_proto_tree(output_fields, print_dissections_expanded,
print_args.print_hex = print_hex; print_hex, protocolfilter, protocolfilter_flags,
write_json_proto_tree(output_fields, &print_args, protocolfilter, protocolfilter_flags, edt, stdout); edt, stdout);
printf("\n"); printf("\n");
return !ferror(stdout); return !ferror(stdout);
case WRITE_JSON_RAW: case WRITE_JSON_RAW:
print_args.print_dissections = print_dissections_none; write_json_proto_tree(output_fields, print_dissections_none, TRUE,
print_args.print_hex = TRUE; protocolfilter, protocolfilter_flags, edt, stdout);
write_json_proto_tree(output_fields, &print_args, protocolfilter, protocolfilter_flags, edt, stdout);
printf("\n"); printf("\n");
return !ferror(stdout); return !ferror(stdout);
case WRITE_EK: case WRITE_EK:
print_args.print_hex = print_hex; write_ek_proto_tree(output_fields, print_hex, protocolfilter,
write_ek_proto_tree(output_fields, &print_args, protocolfilter, protocolfilter_flags, edt, stdout); protocolfilter_flags, edt, stdout);
return !ferror(stdout); return !ferror(stdout);
} }
} }

View File

@ -39,6 +39,7 @@ set(COMMON_UI_SRC
language.c language.c
mcast_stream.c mcast_stream.c
packet_list_utils.c packet_list_utils.c
packet_range.c
persfilepath_opt.c persfilepath_opt.c
preference_utils.c preference_utils.c
profile.c profile.c

View File

@ -66,6 +66,7 @@ WIRESHARK_UI_SRC = \
help_url.c \ help_url.c \
mcast_stream.c \ mcast_stream.c \
packet_list_utils.c \ packet_list_utils.c \
packet_range.c \
persfilepath_opt.c \ persfilepath_opt.c \
preference_utils.c \ preference_utils.c \
profile.c \ profile.c \
@ -113,6 +114,7 @@ WIRESHARK_UI_INCLUDES = \
language.h \ language.h \
mcast_stream.h \ mcast_stream.h \
main_statusbar.h \ main_statusbar.h \
packet_range.h \
persfilepath_opt.h \ persfilepath_opt.h \
preference_utils.h \ preference_utils.h \
profile.h \ profile.h \

View File

@ -36,7 +36,6 @@ extern "C" {
#include "cfile.h" #include "cfile.h"
extern guint32 curr_selected_frame; extern guint32 curr_selected_frame;
typedef enum { typedef enum {
@ -94,22 +93,22 @@ typedef enum {
} range_process_e; } range_process_e;
/* init the range structure */ /* init the range structure */
WS_DLL_PUBLIC void packet_range_init(packet_range_t *range, capture_file *cf); extern void packet_range_init(packet_range_t *range, capture_file *cf);
/* check whether the packet range is OK */ /* check whether the packet range is OK */
WS_DLL_PUBLIC convert_ret_t packet_range_check(packet_range_t *range); extern convert_ret_t packet_range_check(packet_range_t *range);
/* init the processing run */ /* init the processing run */
WS_DLL_PUBLIC void packet_range_process_init(packet_range_t *range); extern void packet_range_process_init(packet_range_t *range);
/* do we have to process all packets? */ /* do we have to process all packets? */
WS_DLL_PUBLIC gboolean packet_range_process_all(packet_range_t *range); extern gboolean packet_range_process_all(packet_range_t *range);
/* do we have to process this packet? */ /* do we have to process this packet? */
WS_DLL_PUBLIC range_process_e packet_range_process_packet(packet_range_t *range, frame_data *fdata); extern range_process_e packet_range_process_packet(packet_range_t *range, frame_data *fdata);
/* convert user given string to the internal user specified range representation */ /* convert user given string to the internal user specified range representation */
WS_DLL_PUBLIC void packet_range_convert_str(packet_range_t *range, const gchar *es); extern void packet_range_convert_str(packet_range_t *range, const gchar *es);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,7 +26,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#include "epan/packet_range.h" #include "ui/packet_range.h"
#include "ui/win32/file_dlg_win32.h" #include "ui/win32/file_dlg_win32.h"
#else // Q_OS_WIN #else // Q_OS_WIN

View File

@ -23,7 +23,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#include "epan/packet_range.h" #include "ui/packet_range.h"
#include "ui/win32/file_dlg_win32.h" #include "ui/win32/file_dlg_win32.h"
#else // Q_OS_WIN #else // Q_OS_WIN

View File

@ -26,7 +26,7 @@
#include <glib.h> #include <glib.h>
#include "epan/packet_range.h" #include "ui/packet_range.h"
#include "syntax_line_edit.h" #include "syntax_line_edit.h"
#include <QGroupBox> #include <QGroupBox>