aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
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 /wiretap
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>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/file_access.c7
-rw-r--r--wiretap/wtap.c21
-rw-r--r--wiretap/wtap.h6
3 files changed, 19 insertions, 15 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index 8650db1b07..f2a145bb5f 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 ef9d709604..e14953b624 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 63787292ba..5ce3cf436a 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);