aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-12-04 13:42:07 -0800
committerGuy Harris <guy@alum.mit.edu>2016-12-04 21:42:44 +0000
commitab07f8e0f89eb1bb2c2c61c71e44e3fd0e31cc52 (patch)
tree20210444e46c0c198c62d47fa6619ce8cfd832f0
parent51d23c6959edfbf45033ba26237820fa2914ff77 (diff)
Have a routine to do all the work of initializing libwiretap.
Have programs that use libwiretap call that routine rather than separately calling some or all of init_open_routines(), wtap_register_plugin_types(), and wtap_opttypes_initialize(). Also don't have routines internal to libwiretap call those. Yes, this means doing some initialization work when it isn't necessary, but scattering on-demand calls throughout the code is a great way to forget to make those calls. Change-Id: I5828e1c5591c9d94fbb3eb0a0e54591e8fc61710 Reviewed-on: https://code.wireshark.org/review/19069 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--capinfos.c6
-rw-r--r--captype.c6
-rw-r--r--editcap.c6
-rw-r--r--extcap/androiddump.c3
-rw-r--r--mergecap.c6
-rw-r--r--randpkt.c6
-rw-r--r--randpkt_core/randpkt_core.c2
-rw-r--r--reordercap.c6
-rw-r--r--tfshark.c2
-rw-r--r--tshark.c3
-rw-r--r--ui/gtk/main.c3
-rw-r--r--wireshark-qt.cpp3
-rw-r--r--wiretap/file_access.c7
-rw-r--r--wiretap/wtap.c21
-rw-r--r--wiretap/wtap.h6
15 files changed, 37 insertions, 49 deletions
diff --git a/capinfos.c b/capinfos.c
index 048f546..d177311 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -1458,16 +1458,14 @@ main(int argc, char *argv[])
* Get credential information for later use.
*/
init_process_policies();
- init_open_routines();
+
+ wtap_init();
#ifdef HAVE_PLUGINS
if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
- /* Register all the plugin types we have. */
- wtap_register_plugin_types(); /* Types known to libwiretap */
-
init_report_err(failure_message, NULL, NULL, NULL);
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/captype.c b/captype.c
index 87e4f92..6926df0 100644
--- a/captype.c
+++ b/captype.c
@@ -130,16 +130,14 @@ main(int argc, char *argv[])
* Get credential information for later use.
*/
init_process_policies();
- init_open_routines();
+
+ wtap_init();
#ifdef HAVE_PLUGINS
if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
- /* Register all the plugin types we have. */
- wtap_register_plugin_types(); /* Types known to libwiretap */
-
init_report_err(failure_message,NULL,NULL,NULL);
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/editcap.c b/editcap.c
index 40a6a81..6b6e27a 100644
--- a/editcap.c
+++ b/editcap.c
@@ -1013,7 +1013,8 @@ main(int argc, char *argv[])
* Get credential information for later use.
*/
init_process_policies();
- init_open_routines();
+
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register wiretap plugins */
@@ -1021,9 +1022,6 @@ main(int argc, char *argv[])
g_warning("editcap: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
- /* Register all the plugin types we have. */
- wtap_register_plugin_types(); /* Types known to libwiretap */
-
init_report_err(failure_message,NULL,NULL,NULL);
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/extcap/androiddump.c b/extcap/androiddump.c
index 89dd6ec..7a61cd8 100644
--- a/extcap/androiddump.c
+++ b/extcap/androiddump.c
@@ -296,9 +296,8 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
#else
int err = 0;
- init_open_routines();
+ wtap_init();
#ifdef HAVE_PLUGINS
- wtap_register_plugin_types();
register_all_wiretap_modules();
#endif
diff --git a/mergecap.c b/mergecap.c
index c64341d..f3cf922 100644
--- a/mergecap.c
+++ b/mergecap.c
@@ -297,7 +297,8 @@ main(int argc, char *argv[])
* Get credential information for later use.
*/
init_process_policies();
- init_open_routines();
+
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register wiretap plugins */
@@ -305,9 +306,6 @@ main(int argc, char *argv[])
g_warning("mergecap: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
- /* Register all the plugin types we have. */
- wtap_register_plugin_types(); /* Types known to libwiretap */
-
init_report_err(failure_message,NULL,NULL,NULL);
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/randpkt.c b/randpkt.c
index 4f90231..854e5c6 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -132,7 +132,8 @@ main(int argc, char **argv)
* Get credential information for later use.
*/
init_process_policies();
- init_open_routines();
+
+ wtap_init();
cmdarg_err_init(failure_message, failure_message_cont);
@@ -147,9 +148,6 @@ main(int argc, char **argv)
g_warning("randpkt: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
- /* Register all the plugin types we have. */
- wtap_register_plugin_types(); /* Types known to libwiretap */
-
init_report_err(failure_message,NULL,NULL,NULL);
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c
index 44a54f1..e84cb39 100644
--- a/randpkt_core/randpkt_core.c
+++ b/randpkt_core/randpkt_core.c
@@ -704,7 +704,7 @@ void randpkt_example_init(randpkt_example* example, char* produce_filename, int
pkt_rand = g_rand_new();
}
- wtap_opttypes_initialize();
+ wtap_init();
if (strcmp(produce_filename, "-") == 0) {
/* Write to the standard output. */
diff --git a/reordercap.c b/reordercap.c
index 812825c..004cb15 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -219,7 +219,8 @@ main(int argc, char *argv[])
* Get credential information for later use.
*/
init_process_policies();
- init_open_routines();
+
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register wiretap plugins */
@@ -227,9 +228,6 @@ main(int argc, char *argv[])
g_warning("reordercap: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
- /* Register all the plugin types we have. */
- wtap_register_plugin_types(); /* Types known to libwiretap */
-
init_report_err(failure_message,NULL,NULL,NULL);
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/tfshark.c b/tfshark.c
index 292158e..a1be81b 100644
--- a/tfshark.c
+++ b/tfshark.c
@@ -499,7 +499,7 @@ main(int argc, char *argv[])
timestamp_set_precision(TS_PREC_AUTO);
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
- init_open_routines();
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register all the plugin types we have. */
diff --git a/tshark.c b/tshark.c
index 89756d3..0e90434 100644
--- a/tshark.c
+++ b/tshark.c
@@ -876,12 +876,11 @@ main(int argc, char *argv[])
timestamp_set_precision(TS_PREC_AUTO);
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
- init_open_routines();
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register all the plugin types we have. */
epan_register_plugin_types(); /* Types known to libwireshark */
- wtap_register_plugin_types(); /* Types known to libwiretap */
/* Scan for plugins. This does *not* call their registration routines;
that's done later. */
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 0414280..4cb793f 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -2287,12 +2287,11 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
- init_open_routines();
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register all the plugin types we have. */
epan_register_plugin_types(); /* Types known to libwireshark */
- wtap_register_plugin_types(); /* Types known to libwiretap */
codec_register_plugin_types(); /* Types known to libwscodecs */
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp
index 0cc8664..504ff0a 100644
--- a/wireshark-qt.cpp
+++ b/wireshark-qt.cpp
@@ -537,12 +537,11 @@ int main(int argc, char *qt_argv[])
init_report_err(vfailure_alert_box, open_failure_alert_box,
read_failure_alert_box, write_failure_alert_box);
- init_open_routines();
+ wtap_init();
#ifdef HAVE_PLUGINS
/* Register all the plugin types we have. */
epan_register_plugin_types(); /* Types known to libwireshark */
- wtap_register_plugin_types(); /* Types known to libwiretap */
codec_register_plugin_types(); /* Types known to libwscodecs */
/* Scan for plugins. This does *not* call their registration routines;
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 8650db1..f2a145b 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -478,8 +478,6 @@ init_open_routines(void)
void
wtap_register_open_info(struct open_info *oi, const gboolean first_routine)
{
- init_open_routines();
-
if (!oi || !oi->name) {
g_error("No open_info name given to register");
return;
@@ -517,7 +515,6 @@ void
wtap_deregister_open_info(const gchar *name)
{
guint i;
- init_open_routines();
if (!name) {
g_error("Missing open_info name to de-register");
@@ -543,7 +540,6 @@ gboolean
wtap_has_open_info(const gchar *name)
{
guint i;
- init_open_routines();
if (!name) {
g_error("No name given to wtap_has_open_info!");
@@ -587,7 +583,6 @@ unsigned int
open_info_name_to_type(const char *name)
{
unsigned int i;
- init_open_routines();
if (!name)
return WTAP_TYPE_AUTO;
@@ -735,8 +730,6 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
*err = 0;
*err_info = NULL;
- init_open_routines();
-
/* open standard input if filename is '-' */
if (strcmp(filename, "-") == 0)
use_stdin = TRUE;
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index ef9d709..e14953b 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -77,12 +77,9 @@ DIAG_ON(pedantic)
return TRUE;
}
-void
+static void
wtap_register_plugin_types(void)
{
- /* Piggyback the initialization here for now */
- wtap_opttypes_initialize();
-
add_plugin_type("libwiretap", check_for_wtap_plugin);
}
@@ -940,14 +937,12 @@ static void wtap_init_encap_types(void) {
}
int wtap_get_num_encap_types(void) {
- wtap_init_encap_types();
return wtap_num_encap_types;
}
int wtap_register_encap_type(const char* name, const char* short_name) {
struct encap_type_info e;
- wtap_init_encap_types();
e.name = g_strdup(name);
e.short_name = g_strdup(short_name);
@@ -1420,6 +1415,20 @@ wtap_seek_read(wtap *wth, gint64 seek_off,
}
/*
+ * Initialize the library.
+ */
+void
+wtap_init(void)
+{
+ init_open_routines();
+ wtap_opttypes_initialize();
+ wtap_init_encap_types();
+#ifdef HAVE_PLUGINS
+ wtap_register_plugin_types();
+#endif
+}
+
+/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 6378729..5ce3cf4 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1509,6 +1509,10 @@ struct file_type_subtype_info {
#define WTAP_TYPE_AUTO 0
+/** Initialize the Wiretap library. */
+WS_DLL_PUBLIC
+void wtap_init(void);
+
/** On failure, "wtap_open_offline()" returns NULL, and puts into the
* "int" pointed to by its second argument:
*
@@ -1947,8 +1951,6 @@ GSList *wtap_get_file_extension_type_extensions(guint extension_type);
/*** dynamically register new file types and encapsulations ***/
WS_DLL_PUBLIC
-void wtap_register_plugin_types(void);
-WS_DLL_PUBLIC
void register_all_wiretap_modules(void);
WS_DLL_PUBLIC
void wtap_register_file_type_extension(const struct file_extension_info *ei);