Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin cleanup of make-dissector-reg.py
Move registration code to a new register.c file so it is readable. Dissector load points are stored in a generated function pointer array instead. Simplify python script somewhat by not interleaving the plugin and dissector logic. Change-Id: I5ec21270f4e1550a5c911efa7f0dc4fc7fcb13a5 Reviewed-on: https://code.wireshark.org/review/24474 Reviewed-by: João Valverde <j@v6e.pt> Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann <mmann78@netscape.net>
- Loading branch information
Showing
9 changed files
with
255 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* dissectors.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 __DISSECTOR_REGISTER_H__ | ||
#define __DISSECTOR_REGISTER_H__ | ||
|
||
#include "ws_symbol_export.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif /* __cplusplus */ | ||
|
||
#include <glib.h> | ||
|
||
typedef struct _dissector_reg { | ||
const char *cb_name; | ||
void (*cb_func)(void); | ||
} dissector_reg_t; | ||
|
||
WS_DLL_PUBLIC dissector_reg_t dissector_reg_proto[]; | ||
WS_DLL_PUBLIC dissector_reg_t dissector_reg_handoff[]; | ||
|
||
WS_DLL_PUBLIC gulong dissector_reg_proto_count(void); | ||
|
||
WS_DLL_PUBLIC gulong dissector_reg_handoff_count(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif /* __cplusplus */ | ||
|
||
#endif /* __DISSECTOR_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=2 tabstop=8 expandtab: | ||
* :indentSize=2:tabSize=8:noTabs=true: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", ®ister_all_protocols_worker, NULL); | ||
#else | ||
g_thread_create(®ister_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", ®ister_all_protocol_handoffs_worker, NULL); | ||
#else | ||
g_thread_create(®ister_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: 2 | ||
* tab-width: 8 | ||
* indent-tabs-mode: nil | ||
* End: | ||
* | ||
* vi: set shiftwidth=2 tabstop=8 expandtab: | ||
* :indentSize=2:tabSize=8:noTabs=true: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.