diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2016-10-26 17:07:47 +0100 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-10-28 17:39:04 +0000 |
commit | d47551982b343664cafa3ddfa3b3bb960ed9f34a (patch) | |
tree | 8c88e54355d399d3b43a57098c3ad76276cd5112 /epan/capture_dissectors.c | |
parent | 01147f8369e76927d7a90cfa0b592457a1878839 (diff) |
Implement registration of capture dissectors by name
Mirror it after protocol dissector API.
Change-Id: I7985bcfa9e07654c7cf005efec94efc205d7a304
Reviewed-on: https://code.wireshark.org/review/18496
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/capture_dissectors.c')
-rw-r--r-- | epan/capture_dissectors.c | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/epan/capture_dissectors.c b/epan/capture_dissectors.c index 69c3584795..c837461082 100644 --- a/epan/capture_dissectors.c +++ b/epan/capture_dissectors.c @@ -36,7 +36,7 @@ struct capture_dissector_table { struct capture_dissector_handle { - guint32 pattern; + const char *name; capture_dissector_t dissector; protocol_t* protocol; }; @@ -46,6 +46,8 @@ typedef struct capture_dissector_count guint32 count; } capture_dissector_count_t; +static GHashTable *registered_dissectors = NULL; + static GHashTable *capture_dissector_tables = NULL; static void @@ -59,12 +61,14 @@ destroy_capture_dissector_table(void *data) void capture_dissector_init(void) { + registered_dissectors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); capture_dissector_tables = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, destroy_capture_dissector_table); } void capture_dissector_cleanup(void) { g_hash_table_destroy(capture_dissector_tables); + g_hash_table_destroy(registered_dissectors); } void register_capture_dissector_table(const char *name, const char *ui_name) @@ -84,10 +88,47 @@ void register_capture_dissector_table(const char *name, const char *ui_name) } -void register_capture_dissector(const char* name, const guint32 pattern, capture_dissector_t dissector, const int proto) +static capture_dissector_handle_t +new_capture_dissector_handle(capture_dissector_t dissector, int proto, const char *name) +{ + struct capture_dissector_handle* handle; + + handle = wmem_new(wmem_epan_scope(), struct capture_dissector_handle); + handle->name = name; + handle->dissector = dissector; + handle->protocol = find_protocol_by_id(proto); + return handle; +} + +capture_dissector_handle_t +create_capture_dissector_handle(capture_dissector_t dissector, const int proto) +{ + return new_capture_dissector_handle(dissector, proto, NULL); +} + +capture_dissector_handle_t find_capture_dissector(const char *name) +{ + return (capture_dissector_handle_t)g_hash_table_lookup(registered_dissectors, name); +} + +capture_dissector_handle_t register_capture_dissector(const char *name, capture_dissector_t dissector, int proto) +{ + capture_dissector_handle_t handle; + + /* Make sure the registration is unique */ + g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL); + + handle = new_capture_dissector_handle(dissector, proto, name); + g_hash_table_insert(registered_dissectors, (gpointer)name, handle); + return handle; +} + +void capture_dissector_add_uint(const char *name, const guint32 pattern, capture_dissector_handle_t handle) { struct capture_dissector_table* sub_dissectors; - struct capture_dissector_handle *handle; + + if (handle == NULL) + return; /* Make sure table exists */ sub_dissectors = (struct capture_dissector_table*)g_hash_table_lookup( capture_dissector_tables, name ); @@ -102,18 +143,13 @@ void register_capture_dissector(const char* name, const guint32 pattern, capture /* Make sure the registration is unique */ g_assert(g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern)) == NULL); - handle = wmem_new(wmem_epan_scope(), struct capture_dissector_handle); - handle->pattern = pattern; - handle->dissector = dissector; - handle->protocol = find_protocol_by_id(proto); - g_hash_table_insert(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern), (gpointer) handle); } gboolean try_capture_dissector(const char* name, const guint32 pattern, const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header) { struct capture_dissector_table* sub_dissectors; - struct capture_dissector_handle* handle; + capture_dissector_handle_t handle; sub_dissectors = (struct capture_dissector_table*)g_hash_table_lookup( capture_dissector_tables, name ); if (sub_dissectors == NULL) @@ -122,13 +158,20 @@ gboolean try_capture_dissector(const char* name, const guint32 pattern, const gu return FALSE; } - handle = (struct capture_dissector_handle *)g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern)); + handle = (capture_dissector_handle_t)g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern)); if (handle == NULL) return FALSE; return handle->dissector(pd, offset, len, cpinfo, pseudo_header); } +gboolean call_capture_dissector(capture_dissector_handle_t handle, const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header) +{ + if (handle == NULL) + return FALSE; + return handle->dissector(pd, offset, len, cpinfo, pseudo_header); +} + guint32 capture_dissector_get_count(packet_counts* counts, const int proto) { capture_dissector_count_t* hash_count = (capture_dissector_count_t*)g_hash_table_lookup(counts->counts_hash, GUINT_TO_POINTER(proto)); |