Allow "capture info data" to not be a singleton.

It was buried as a static variable in capture_info.c, and functions were refactored to allow a pointer to the info_data_t structure to be passed in. TShark and GTK will have their own single (global) copy of the structure, while it opens up Qt to have multiple instances.

Change-Id: Ic2d7a2ad574de43f457cb18b194d6bc3fffb6120
Reviewed-on: https://code.wireshark.org/review/12691
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2015-12-16 23:15:03 -05:00
parent 7baac67149
commit 444dfda793
15 changed files with 90 additions and 83 deletions

View File

@ -45,7 +45,7 @@ typedef enum {
} capture_state;
struct _capture_file;
struct _info_data;
/*
* State of a capture session.
*/
@ -64,6 +64,7 @@ typedef struct _capture_session {
guint32 count; /**< Total number of frames captured */
capture_options *capture_opts; /**< options for this capture */
struct _capture_file *cf; /**< handle to cfile */
struct _info_data *cap_data_info; /**< stats for this capture */
} capture_session;
extern void

View File

@ -339,7 +339,7 @@ init_pipe_args(int *argc) {
#define ARGV_NUMBER_LEN 24
/* a new capture run: start a new dumpcap task and hand over parameters through command line */
gboolean
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, void (*update_cb)(void))
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void (*update_cb)(void))
{
char ssnap[ARGV_NUMBER_LEN];
char scount[ARGV_NUMBER_LEN];
@ -772,6 +772,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, voi
cap_session->fork_child_status = 0;
cap_session->capture_opts = capture_opts;
cap_session->cap_data_info = cap_data;
/* we might wait for a moment till child is ready, so update screen now */
if (update_cb) update_cb();

View File

@ -36,6 +36,8 @@
extern "C" {
#endif /* __cplusplus */
struct _info_data;
/**
* Start a new capture session.
* Create a capture child which is doing the real capture work.
@ -50,7 +52,7 @@ extern "C" {
* @return TRUE if a capture could be started, FALSE if not
*/
extern gboolean
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void));
sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, struct _info_data* cap_data, void(*update_cb)(void));
/** User wants to stop capturing, gracefully close the capture child */
extern void

View File

@ -27,10 +27,6 @@
#include <glib.h>
#include <epan/packet.h>
/* XXX - try to remove this later */
#include <epan/prefs.h>
/* XXX - try to remove this later */
#include <wiretap/wtap.h>
#include "capture_info.h"
@ -39,38 +35,28 @@
#include <wsutil/filesystem.h>
typedef struct _info_data {
packet_counts counts; /* several packet type counters */
struct wtap* wtap; /* current wtap file */
capture_info ui; /* user interface data */
} info_data_t;
static info_data_t info_data;
/* open the info */
void capture_info_open(capture_session *cap_session)
void capture_info_open(capture_session *cap_session, info_data_t* cap_info)
{
info_data.counts.total = 0;
info_data.counts.sctp = 0;
info_data.counts.tcp = 0;
info_data.counts.udp = 0;
info_data.counts.icmp = 0;
info_data.counts.ospf = 0;
info_data.counts.gre = 0;
info_data.counts.ipx = 0;
info_data.counts.netbios = 0;
info_data.counts.vines = 0;
info_data.counts.other = 0;
info_data.counts.arp = 0;
info_data.counts.i2c_event = 0;
info_data.counts.i2c_data = 0;
cap_info->counts.total = 0;
cap_info->counts.sctp = 0;
cap_info->counts.tcp = 0;
cap_info->counts.udp = 0;
cap_info->counts.icmp = 0;
cap_info->counts.ospf = 0;
cap_info->counts.gre = 0;
cap_info->counts.ipx = 0;
cap_info->counts.netbios = 0;
cap_info->counts.vines = 0;
cap_info->counts.other = 0;
cap_info->counts.arp = 0;
cap_info->counts.i2c_event = 0;
cap_info->counts.i2c_data = 0;
info_data.wtap = NULL;
info_data.ui.counts = &info_data.counts;
cap_info->wtap = NULL;
cap_info->ui.counts = &cap_info->counts;
capture_info_ui_create(&info_data.ui, cap_session);
capture_info_ui_create(&cap_info->ui, cap_session);
}
@ -175,19 +161,19 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
}
/* new file arrived */
gboolean capture_info_new_file(const char *new_filename)
gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info)
{
int err;
gchar *err_info;
gchar *err_msg;
if(info_data.wtap != NULL) {
wtap_close(info_data.wtap);
if(cap_info->wtap != NULL) {
wtap_close(cap_info->wtap);
}
info_data.wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if (!info_data.wtap) {
cap_info->wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if (!cap_info->wtap) {
err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN),
new_filename);
g_warning("capture_info_new_file: %d (%s)", err, err_msg);
@ -211,7 +197,7 @@ capture_info_packet(packet_counts *counts, gint wtap_linktype, const guchar *pd,
}
/* new packets arrived */
void capture_info_new_packets(int to_read)
void capture_info_new_packets(int to_read, info_data_t* cap_info)
{
int err;
gchar *err_info;
@ -222,35 +208,35 @@ void capture_info_new_packets(int to_read)
const guchar *buf;
info_data.ui.new_packets = to_read;
cap_info->ui.new_packets = to_read;
/*g_warning("new packets: %u", to_read);*/
while (to_read > 0) {
wtap_cleareof(info_data.wtap);
if (wtap_read(info_data.wtap, &err, &err_info, &data_offset)) {
phdr = wtap_phdr(info_data.wtap);
wtap_cleareof(cap_info->wtap);
if (wtap_read(cap_info->wtap, &err, &err_info, &data_offset)) {
phdr = wtap_phdr(cap_info->wtap);
pseudo_header = &phdr->pseudo_header;
wtap_linktype = phdr->pkt_encap;
buf = wtap_buf_ptr(info_data.wtap);
buf = wtap_buf_ptr(cap_info->wtap);
capture_info_packet(&info_data.counts, wtap_linktype, buf, phdr->caplen, pseudo_header);
capture_info_packet(&cap_info->counts, wtap_linktype, buf, phdr->caplen, pseudo_header);
/*g_warning("new packet");*/
to_read--;
}
}
capture_info_ui_update(&info_data.ui);
capture_info_ui_update(&cap_info->ui);
}
/* close the info */
void capture_info_close(void)
void capture_info_close(info_data_t* cap_info)
{
capture_info_ui_destroy(&info_data.ui);
if(info_data.wtap)
wtap_close(info_data.wtap);
capture_info_ui_destroy(&cap_info->ui);
if(cap_info->wtap)
wtap_close(cap_info->wtap);
}
#endif /* HAVE_LIBPCAP */

View File

@ -39,24 +39,13 @@
#include "capture_opts.h"
#include <capchild/capture_session.h>
/* XXX - Should be temporary until packet_counts is removed */
#include <epan/packet.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* open the info - init values (wtap, counts), create dialog */
extern void capture_info_open(capture_session *cap_session);
/* new file arrived - (eventually close old wtap), open wtap */
extern gboolean capture_info_new_file(const char *new_filename);
/* new packets arrived - read from wtap, count */
extern void capture_info_new_packets(int to_read);
/* close the info - close wtap, destroy dialog */
extern void capture_info_close(void);
/** Current Capture info. */
typedef struct {
/* handle */
@ -68,6 +57,23 @@ typedef struct {
gint new_packets; /**< packets since last update */
} capture_info;
typedef struct _info_data {
packet_counts counts; /* several packet type counters */
struct wtap* wtap; /* current wtap file */
capture_info ui; /* user interface data */
} info_data_t;
/* open the info - init values (wtap, counts), create dialog */
extern void capture_info_open(capture_session *cap_session, info_data_t* cap_info);
/* new file arrived - (eventually close old wtap), open wtap */
extern gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info);
/* new packets arrived - read from wtap, count */
extern void capture_info_new_packets(int to_read, info_data_t* cap_info);
/* close the info - close wtap, destroy dialog */
extern void capture_info_close(info_data_t* cap_info);
/** Create the capture info dialog */
extern void

View File

@ -113,6 +113,7 @@
#endif /* _WIN32 */
#include <capchild/capture_session.h>
#include <capchild/capture_sync.h>
#include <capture_info.h>
#endif /* HAVE_LIBPCAP */
#include "log.h"
#include <epan/funnel.h>
@ -184,6 +185,7 @@ static gboolean print_packet_counts;
static capture_options global_capture_opts;
static capture_session global_capture_session;
static info_data_t global_info_data;
#ifdef SIGINFO
static gboolean infodelay; /* if TRUE, don't print capture info in SIGINFO handler */
@ -2562,7 +2564,7 @@ capture(void)
fflush(stderr);
g_string_free(str, TRUE);
ret = sync_pipe_start(&global_capture_opts, &global_capture_session, NULL);
ret = sync_pipe_start(&global_capture_opts, &global_capture_session, &global_info_data, NULL);
if (!ret)
return FALSE;

View File

@ -126,7 +126,7 @@ capture_callback_remove(capture_callback_t func, gpointer user_data)
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
gboolean
capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void))
capture_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void(*update_cb)(void))
{
gboolean ret;
GString *source;
@ -138,7 +138,7 @@ capture_start(capture_options *capture_opts, capture_session *cap_session, void(
cf_set_tempfile_source((capture_file *)cap_session->cf, source->str);
g_string_free(source, TRUE);
/* try to start the capture child process */
ret = sync_pipe_start(capture_opts, cap_session, update_cb);
ret = sync_pipe_start(capture_opts, cap_session, cap_data, update_cb);
if(!ret) {
if(capture_opts->save_file != NULL) {
g_free(capture_opts->save_file);
@ -156,7 +156,7 @@ capture_start(capture_options *capture_opts, capture_session *cap_session, void(
capture_callback_invoke(capture_cb_capture_prepared, cap_session);
if(capture_opts->show_info)
capture_info_open(cap_session);
capture_info_open(cap_session, cap_data);
}
return ret;
@ -346,7 +346,7 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
}
if(capture_opts->show_info) {
if (!capture_info_new_file(new_file))
if (!capture_info_new_file(new_file, cap_session->cap_data_info))
return FALSE;
}
@ -403,7 +403,7 @@ capture_input_new_packets(capture_session *cap_session, int to_read)
#endif
if(capture_opts->show_info)
capture_info_new_packets(to_read);
capture_info_new_packets(to_read, cap_session->cap_data_info);
}
@ -594,7 +594,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
}
if(capture_opts->show_info)
capture_info_close();
capture_info_close(cap_session->cap_data_info);
cap_session->state = CAPTURE_STOPPED;
@ -631,7 +631,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
/* close the currently loaded capture file */
cf_close((capture_file *)cap_session->cf);
capture_start(capture_opts, cap_session,NULL); /*XXX is this NULL ok or we need an update_cb???*/
capture_start(capture_opts, cap_session, cap_session->cap_data_info, NULL); /*XXX is this NULL ok or we need an update_cb???*/
} else {
/* We're not doing a capture any more, so we don't have a save file. */
g_free(capture_opts->save_file);

View File

@ -30,6 +30,7 @@
*/
#include "capture_opts.h"
#include "capture_info.h"
#include "capchild/capture_session.h"
#ifdef __cplusplus
@ -66,7 +67,7 @@ capture_callback_remove(capture_callback_t func, gpointer user_data);
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
extern gboolean
capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void));
capture_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void(*update_cb)(void));
/** Stop a capture session (usually from a menu item). */
extern void

View File

@ -23,7 +23,7 @@
#ifndef __CAPTURE_GLOBALS_H__
#define __CAPTURE_GLOBALS_H__
#include <capchild/capture_session.h>
#include "capture_opts.h"
#ifdef __cplusplus
extern "C" {
@ -31,8 +31,6 @@ extern "C" {
extern capture_options global_capture_opts;
extern capture_session global_capture_session;
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -5401,7 +5401,7 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
this capture. */
collect_ifaces(&global_capture_opts);
if (capture_start(&global_capture_opts, &global_capture_session, main_window_update)) {
if (capture_start(&global_capture_opts, &global_capture_session, &global_info_data, main_window_update)) {
/* The capture succeeded, which means the capture filters specified are
valid; add them to the recent capture filter lists for the interfaces.

View File

@ -37,6 +37,9 @@
* GTK global definitions. For example a pointer to the main application window.
*/
#include <capchild/capture_session.h>
#include <capture_info.h>
/** Application window. */
extern GtkWidget *top_level;
@ -49,4 +52,8 @@ extern GtkWidget *byte_nb_ptr_gbl;
/** The filter text entry in the filter toolbar. */
extern GtkWidget *main_display_filter_widget;
extern capture_session global_capture_session;
extern info_data_t global_info_data;
#endif

View File

@ -224,6 +224,7 @@
#ifdef HAVE_LIBPCAP
capture_options global_capture_opts;
capture_session global_capture_session;
info_data_t global_info_data;
#endif
capture_file cfile;
@ -646,7 +647,7 @@ copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E acti
{
case COPY_SELECTED_DESCRIPTION:
if (cfile.finfo_selected->rep &&
strlen (cfile.finfo_selected->rep->representation) > 0) {
strlen(cfile.finfo_selected->rep->representation) > 0) {
g_string_append(gtk_text_str, cfile.finfo_selected->rep->representation);
}
break;
@ -3297,7 +3298,7 @@ main(int argc, char *argv[])
to use for this capture. */
if (global_capture_opts.ifaces->len == 0)
collect_ifaces(&global_capture_opts);
if (capture_start(&global_capture_opts, &global_capture_session,main_window_update)) {
if (capture_start(&global_capture_opts, &global_capture_session, &global_info_data,main_window_update)) {
/* The capture started. Open stat windows; we do so after creating
the main window, to avoid GTK warnings, and after successfully
opening the capture file, so we know we have something to compute

View File

@ -87,6 +87,7 @@ public:
QString getFilter();
#ifdef HAVE_LIBPCAP
capture_session *captureSession() { return &cap_session_; }
info_data_t *captureInfoData() { return &info_data_; }
#endif
virtual QMenu *createPopupMenu();
@ -151,6 +152,7 @@ private:
#ifdef HAVE_LIBPCAP
capture_session cap_session_;
CaptureInterfacesDialog capture_interfaces_dialog_;
info_data_t info_data_;
#endif
// Pipe input

View File

@ -849,7 +849,7 @@ void MainWindow::startCapture() {
collect_ifaces(&global_capture_opts);
CaptureFile::globalCapFile()->window = this;
if (capture_start(&global_capture_opts, &cap_session_, main_window_update)) {
if (capture_start(&global_capture_opts, &cap_session_, &info_data_, main_window_update)) {
capture_options *capture_opts = cap_session_.capture_opts;
GString *interface_names;

View File

@ -1409,7 +1409,7 @@ int main(int argc, char *argv[])
if (global_capture_opts.ifaces->len == 0)
collect_ifaces(&global_capture_opts);
CaptureFile::globalCapFile()->window = main_w;
if (capture_start(&global_capture_opts, main_w->captureSession(), main_window_update)) {
if (capture_start(&global_capture_opts, main_w->captureSession(), main_w->captureInfoData(), main_window_update)) {
/* The capture started. Open stat windows; we do so after creating
the main window, to avoid GTK warnings, and after successfully
opening the capture file, so we know we have something to compute