aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2017-11-21 18:38:44 +0000
committerJoão Valverde <j@v6e.pt>2017-11-21 20:21:50 +0000
commit7540ac69381518661065b33096bd448d1b4100e5 (patch)
tree9e6c883e2d360ad6d84fcf928a4561b0c9de4106 /epan
parent4e63ec305bd7e8196561be58d12ee99f54eca371 (diff)
Move the protocol registration routines back into libwireshark
Follow-up to b695b3e2f72998d66ca4b7a6826d4ce1688060c8. Change-Id: I7e36519f2c3806c1205d05437671325080974257 Reviewed-on: https://code.wireshark.org/review/24524 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'epan')
-rw-r--r--epan/CMakeLists.txt2
-rw-r--r--epan/Makefile.am2
-rw-r--r--epan/register.c123
-rw-r--r--epan/register.h87
-rw-r--r--epan/wslua/init_wslua.h2
5 files changed, 215 insertions, 1 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index 984b062c20..b0fd8d7eb1 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -139,6 +139,7 @@ set(LIBWIRESHARK_PUBLIC_HEADERS
range.h
reassemble.h
reedsolomon.h
+ register.h
req_resp_hdrs.h
rtd_table.h
rtp_pt.h
@@ -228,6 +229,7 @@ set(LIBWIRESHARK_FILES
range.c
reassemble.c
reedsolomon.c
+ register.c
req_resp_hdrs.c
rtd_table.c
sequence_analysis.c
diff --git a/epan/Makefile.am b/epan/Makefile.am
index 945c7b4803..52be37fea6 100644
--- a/epan/Makefile.am
+++ b/epan/Makefile.am
@@ -93,6 +93,7 @@ LIBWIRESHARK_SRC = \
reassemble.c \
reedsolomon.c \
req_resp_hdrs.c \
+ register.c \
rtd_table.c \
sequence_analysis.c \
show_exception.c \
@@ -246,6 +247,7 @@ LIBWIRESHARK_INCLUDES_PUBLIC = \
range.h \
reassemble.h \
reedsolomon.h \
+ register.h \
req_resp_hdrs.h \
rtd_table.h \
rtp_pt.h \
diff --git a/epan/register.c b/epan/register.c
new file mode 100644
index 0000000000..63973c684a
--- /dev/null
+++ b/epan/register.c
@@ -0,0 +1,123 @@
+/* register.c
+ * Definitions for protocol registration
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "register.h"
+#include "ws_attributes.h"
+
+#include <glib.h>
+#include "epan/dissectors/dissectors.h"
+
+static const char *cur_cb_name = NULL;
+//static GMutex register_cb_mtx;
+static GAsyncQueue *register_cb_done_q;
+
+#define CB_WAIT_TIME (150 * 1000) // microseconds
+
+static void set_cb_name(const char *proto) {
+ // g_mutex_lock(register_cb_mtx);
+ cur_cb_name = proto;
+ // g_mutex_unlock(register_cb_mtx);
+}
+
+static void *
+register_all_protocols_worker(void *arg _U_)
+{
+ for (gulong i = 0; i < dissector_reg_proto_count; i++) {
+ set_cb_name(dissector_reg_proto[i].cb_name);
+ dissector_reg_proto[i].cb_func();
+ }
+
+ g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
+ return NULL;
+}
+
+void
+register_all_protocols(register_cb cb, gpointer cb_data)
+{
+ const char *cb_name;
+ register_cb_done_q = g_async_queue_new();
+ gboolean called_back = FALSE;
+
+#if GLIB_CHECK_VERSION(2,31,0)
+ g_thread_new("register_all_protocols_worker", &register_all_protocols_worker, NULL);
+#else
+ g_thread_create(&register_all_protocols_worker, TRUE, FALSE, NULL);
+#endif
+ while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) {
+ // g_mutex_lock(register_cb_mtx);
+ cb_name = cur_cb_name;
+ // g_mutex_unlock(register_cb_mtx);
+ if (cb && cb_name) {
+ cb(RA_REGISTER, cb_name, cb_data);
+ called_back = TRUE;
+ }
+ }
+ if (cb && !called_back) {
+ cb(RA_REGISTER, "Registration finished", cb_data);
+ }
+}
+
+static void *
+register_all_protocol_handoffs_worker(void *arg _U_)
+{
+ for (gulong i = 0; i < dissector_reg_handoff_count; i++) {
+ set_cb_name(dissector_reg_handoff[i].cb_name);
+ dissector_reg_handoff[i].cb_func();
+ }
+
+ g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
+ return NULL;
+}
+
+void
+register_all_protocol_handoffs(register_cb cb, gpointer cb_data)
+{
+ cur_cb_name = NULL;
+ const char *cb_name;
+ gboolean called_back = FALSE;
+
+#if GLIB_CHECK_VERSION(2,31,0)
+ g_thread_new("register_all_protocol_handoffs_worker", &register_all_protocol_handoffs_worker, NULL);
+#else
+ g_thread_create(&register_all_protocol_handoffs_worker, TRUE, FALSE, NULL);
+#endif
+ while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) {
+ // g_mutex_lock(register_cb_mtx);
+ cb_name = cur_cb_name;
+ // g_mutex_unlock(register_cb_mtx);
+ if (cb && cb_name) {
+ cb(RA_HANDOFF, cb_name, cb_data);
+ called_back = TRUE;
+ }
+ }
+ if (cb && !called_back) {
+ cb(RA_HANDOFF, "Registration finished", cb_data);
+ }
+
+ g_async_queue_unref(register_cb_done_q);
+}
+
+gulong register_count(void)
+{
+ return dissector_reg_proto_count + dissector_reg_handoff_count;
+}
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/epan/register.h b/epan/register.h
new file mode 100644
index 0000000000..55c72c2464
--- /dev/null
+++ b/epan/register.h
@@ -0,0 +1,87 @@
+/* register.h
+ * Definitions for protocol registration
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __REGISTER_H__
+#define __REGISTER_H__
+
+#include "ws_symbol_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <glib.h>
+
+typedef enum {
+ RA_NONE, /* For initialization */
+ RA_DISSECTORS, /* Initializing dissectors */
+ RA_LISTENERS, /* Tap listeners */
+ RA_EXTCAP, /* extcap register preferences */
+ RA_REGISTER, /* Built-in dissector registration */
+ RA_PLUGIN_REGISTER, /* Plugin dissector registration */
+ RA_HANDOFF, /* Built-in dissector handoff */
+ RA_PLUGIN_HANDOFF, /* Plugin dissector handoff */
+ RA_LUA_PLUGINS, /* Lua plugin register */
+ RA_LUA_DEREGISTER, /* Lua plugin deregister */
+ RA_PREFERENCES, /* Module preferences */
+ RA_INTERFACES /* Local interfaces */
+} register_action_e;
+
+#define RA_BASE_COUNT (RA_INTERFACES - 3) // RA_EXTCAP, RA_LUA_PLUGINS, RA_LUA_DEREGISTER
+
+typedef void (*register_cb)(register_action_e action, const char *message, gpointer client_data);
+
+/** Call each dissector's protocol registration routine.
+ *
+ * Each routine is called in alphabetical order from a worker thread.
+ * Registration routines might call any number of routines which are not
+ * thread safe, such as wmem_alloc. Callbacks should handle themselves
+ * accordingly.
+ *
+ * @param cb Callback routine which is called for each protocol.
+ * Messages have the format "proto_register_XXX".
+ * @param client_data Data pointer for the callback.
+ */
+WS_DLL_PUBLIC void register_all_protocols(register_cb cb, gpointer client_data);
+
+/** Call each dissector's protocol handoff routine.
+ *
+ * Each routine is called from a worker thread. Registration routines
+ * might call any number of routines which are not thread safe, such as
+ * wmem_alloc. Callbacks should handle themselves accordingly.
+ *
+ * @param cb Callback routine which is called for each protocol.
+ * Messages have the format "proto_reg_handoff_XXX".
+ * @param client_data Data pointer for the callback.
+ */
+WS_DLL_PUBLIC void register_all_protocol_handoffs(register_cb cb, gpointer client_data);
+
+WS_DLL_LOCAL void register_all_tap_listeners(void);
+
+WS_DLL_PUBLIC gulong register_count(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __REGISTER_H__ */
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/epan/wslua/init_wslua.h b/epan/wslua/init_wslua.h
index 850cc2e9e8..1c6d9624ea 100644
--- a/epan/wslua/init_wslua.h
+++ b/epan/wslua/init_wslua.h
@@ -27,7 +27,7 @@
extern "C" {
#endif /* __cplusplus */
-#include "register.h"
+#include "epan/register.h"
#include "ws_symbol_export.h"
WS_DLL_PUBLIC int wslua_count_plugins(void);