diff options
-rw-r--r-- | debian/libwireshark0.symbols | 2 | ||||
-rw-r--r-- | epan/conversation_table.c | 80 | ||||
-rw-r--r-- | epan/conversation_table.h | 18 | ||||
-rw-r--r-- | epan/epan.c | 1 | ||||
-rw-r--r-- | sharkd_session.c | 26 | ||||
-rw-r--r-- | ui/gtk/conversations_table.c | 9 | ||||
-rw-r--r-- | ui/gtk/hostlist_table.c | 10 | ||||
-rw-r--r-- | ui/gtk/main_menubar.c | 22 | ||||
-rw-r--r-- | ui/qt/conversation_dialog.cpp | 2 | ||||
-rw-r--r-- | ui/qt/endpoint_dialog.cpp | 2 | ||||
-rw-r--r-- | ui/qt/traffic_table_dialog.cpp | 47 | ||||
-rw-r--r-- | ui/qt/traffic_table_dialog.h | 1 |
12 files changed, 94 insertions, 126 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 35ae0cbb5c..ed43473c56 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -699,7 +699,6 @@ libwireshark.so.0 libwireshark0 #MINVER# get_conversation_packet_func@Base 1.99.0 get_conversation_port@Base 1.99.0 get_conversation_proto_id@Base 1.99.0 - get_conversation_table_by_num@Base 1.99.0 get_data_source_name@Base 1.9.1 get_data_source_tvb@Base 1.9.1 get_data_source_tvb_by_name@Base 2.3.0 @@ -1821,6 +1820,7 @@ libwireshark.so.0 libwireshark0 #MINVER# wmem_strndup@Base 1.9.1 wmem_strong_hash@Base 1.12.0~rc1 wmem_strsplit@Base 1.12.0~rc1 + wmem_tree_count@Base 2.3.0 wmem_tree_foreach@Base 1.12.0~rc1 wmem_tree_insert32@Base 1.12.0~rc1 wmem_tree_insert32_array@Base 1.12.0~rc1 diff --git a/epan/conversation_table.c b/epan/conversation_table.c index 2cfd7a032f..e758db4b5c 100644 --- a/epan/conversation_table.c +++ b/epan/conversation_table.c @@ -65,7 +65,7 @@ tap_packet_cb get_hostlist_packet_func(register_ct_t* ct) return ct->host_func; } -static GSList *registered_ct_tables = NULL; +static wmem_tree_t *registered_ct_tables = NULL; void dissector_conversation_init(const char *opt_arg, void* userdata) @@ -114,25 +114,7 @@ dissector_hostlist_init(const char *opt_arg, void* userdata) */ register_ct_t* get_conversation_by_proto_id(int proto_id) { - GSList *ct; - register_ct_t *table; - - for(ct = registered_ct_tables; ct != NULL; ct = g_slist_next(ct)){ - table = (register_ct_t*)ct->data; - if ((table) && (table->proto_id == proto_id)) - return table; - } - - return NULL; -} - -static gint -insert_sorted_by_table_name(gconstpointer aparam, gconstpointer bparam) -{ - const register_ct_t *a = (const register_ct_t *)aparam; - const register_ct_t *b = (const register_ct_t *)bparam; - - return g_ascii_strcasecmp(proto_get_protocol_short_name(find_protocol_by_id(a->proto_id)), proto_get_protocol_short_name(find_protocol_by_id(b->proto_id))); + return (register_ct_t*)wmem_tree_lookup_string(registered_ct_tables, proto_get_protocol_short_name(find_protocol_by_id(proto_id)), 0); } void @@ -140,7 +122,7 @@ register_conversation_table(const int proto_id, gboolean hide_ports, tap_packet_ { register_ct_t *table; - table = g_new(register_ct_t,1); + table = wmem_new(wmem_epan_scope(), register_ct_t); table->hide_ports = hide_ports; table->proto_id = proto_id; @@ -149,18 +131,21 @@ register_conversation_table(const int proto_id, gboolean hide_ports, tap_packet_ table->conv_gui_init = NULL; table->host_gui_init = NULL; - registered_ct_tables = g_slist_insert_sorted(registered_ct_tables, table, insert_sorted_by_table_name); + if (registered_ct_tables == NULL) + registered_ct_tables = wmem_tree_new(wmem_epan_scope()); + + wmem_tree_insert_string(registered_ct_tables, proto_get_protocol_short_name(find_protocol_by_id(proto_id)), table, 0); } /* Set GUI fields for register_ct list */ -static void -set_conv_gui_data(gpointer data, gpointer user_data) +static gboolean +set_conv_gui_data(const void *key _U_, void *value, void *userdata) { GString *conv_cmd_str = g_string_new("conv,"); stat_tap_ui ui_info; - register_ct_t *table = (register_ct_t*)data; + register_ct_t *table = (register_ct_t*)value; - table->conv_gui_init = (conv_gui_init_cb)user_data; + table->conv_gui_init = (conv_gui_init_cb)userdata; g_string_append(conv_cmd_str, proto_get_protocol_filter_name(table->proto_id)); ui_info.group = REGISTER_STAT_GROUP_CONVERSATION_LIST; @@ -171,50 +156,46 @@ set_conv_gui_data(gpointer data, gpointer user_data) ui_info.params = NULL; register_stat_tap_ui(&ui_info, table); g_free((char*)ui_info.cli_string); + return FALSE; } void conversation_table_set_gui_info(conv_gui_init_cb init_cb) { - g_slist_foreach(registered_ct_tables, set_conv_gui_data, (gpointer)init_cb); + wmem_tree_foreach(registered_ct_tables, set_conv_gui_data, (void*)init_cb); } -static void -set_host_gui_data(gpointer data, gpointer user_data) +static gboolean +set_host_gui_data(const void *key _U_, void *value, void *userdata) { stat_tap_ui ui_info; - register_ct_t *table = (register_ct_t*)data; + register_ct_t *table = (register_ct_t*)value; - table->host_gui_init = (host_gui_init_cb)user_data; + table->host_gui_init = (host_gui_init_cb)userdata; ui_info.group = REGISTER_STAT_GROUP_ENDPOINT_LIST; ui_info.title = NULL; /* construct this from the protocol info? */ - ui_info.cli_string = wmem_strdup_printf(wmem_epan_scope(), "%s,%s", - HOSTLIST_TAP_PREFIX, proto_get_protocol_filter_name(table->proto_id)); + ui_info.cli_string = g_strdup_printf("%s,%s", HOSTLIST_TAP_PREFIX, proto_get_protocol_filter_name(table->proto_id)); ui_info.tap_init_cb = dissector_hostlist_init; ui_info.nparams = 0; ui_info.params = NULL; register_stat_tap_ui(&ui_info, table); + g_free((char*)ui_info.cli_string); + return FALSE; } void hostlist_table_set_gui_info(host_gui_init_cb init_cb) { - g_slist_foreach(registered_ct_tables, set_host_gui_data, (gpointer)init_cb); + wmem_tree_foreach(registered_ct_tables, set_host_gui_data, (void*)init_cb); } -void conversation_table_iterate_tables(GFunc func, gpointer user_data) +void conversation_table_iterate_tables(wmem_foreach_func func, void* user_data) { - g_slist_foreach(registered_ct_tables, func, user_data); + wmem_tree_foreach(registered_ct_tables, func, user_data); } guint conversation_table_get_num(void) { - return g_slist_length(registered_ct_tables); -} - - -register_ct_t *get_conversation_table_by_num(guint table_num) -{ - return (register_ct_t *) g_slist_nth_data(registered_ct_tables, table_num); + return wmem_tree_count(registered_ct_tables); } /** Compute the hash value for two given address/port pairs. @@ -828,19 +809,6 @@ add_hostlist_table_data(conv_hash_t *ch, const address *addr, guint32 port, gboo } } -static void -ct_table_free(gpointer p, gpointer user_data _U_) -{ - g_free(p); -} - -void -conversation_table_cleanup(void) -{ - g_slist_foreach(registered_ct_tables, ct_table_free, NULL); - g_slist_free(registered_ct_tables); -} - /* * Editor modelines * diff --git a/epan/conversation_table.h b/epan/conversation_table.h index ba94029bd9..741936cae1 100644 --- a/epan/conversation_table.h +++ b/epan/conversation_table.h @@ -26,6 +26,7 @@ #include "conv_id.h" #include "tap.h" +#include "wmem/wmem.h" #ifdef __cplusplus extern "C" { @@ -205,26 +206,17 @@ WS_DLL_PUBLIC void conversation_table_set_gui_info(conv_gui_init_cb init_cb); */ WS_DLL_PUBLIC void hostlist_table_set_gui_info(host_gui_init_cb init_cb); -/** Interator to walk converation tables and execute func - * a GUI menu (only used in GTK) +/** Iterator to walk converation tables and execute func * * @param func action to be performed on all converation tables * @param user_data any data needed to help perform function */ -WS_DLL_PUBLIC void conversation_table_iterate_tables(GFunc func, gpointer user_data); +WS_DLL_PUBLIC void conversation_table_iterate_tables(wmem_foreach_func func, void* user_data); /** Total number of converation tables */ WS_DLL_PUBLIC guint conversation_table_get_num(void); -/** Get conversation table by its number - * Tables are ordered alphabetically by title. - * - * @param table_num Item to fetch. - * @return table pointer or NULL. - */ -WS_DLL_PUBLIC register_ct_t* get_conversation_table_by_num(guint table_num); - /** Remove all entries from the conversation table. * * @param ch the table to reset @@ -340,10 +332,6 @@ add_conversation_table_data_with_conv_id(conv_hash_t *ch, const address *src, co void add_hostlist_table_data(conv_hash_t *ch, const address *addr, guint32 port, gboolean sender, int num_frames, int num_bytes, hostlist_dissector_info_t *host_info, port_type port_type_val); -/** Cleanup internal structures - */ -void conversation_table_cleanup(void); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/epan/epan.c b/epan/epan.c index ff65ebf86b..0d1d257fed 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -216,7 +216,6 @@ epan_cleanup(void) proto_cleanup(); prefs_cleanup(); decode_clear_all(); - conversation_table_cleanup(); conversation_filters_cleanup(); reassembly_table_cleanup(); tap_cleanup(); diff --git a/sharkd_session.c b/sharkd_session.c index 20cd23a9ec..ba06184e3e 100644 --- a/sharkd_session.c +++ b/sharkd_session.c @@ -67,20 +67,7 @@ static struct register_ct * _get_conversation_table_by_name(const char *name) { - guint count = conversation_table_get_num(); - guint i; - - /* XXX, wow O(n^2), move to libwireshark */ - for (i = 0; i < count; i++) - { - struct register_ct *table = get_conversation_table_by_num(i); - const char *label = proto_get_protocol_short_name(find_protocol_by_id(get_conversation_proto_id(table))); - - if (!strcmp(label, name)) - return table; - } - - return NULL; + return get_conversation_by_proto_id(proto_get_id_by_short_name(name)); } static void @@ -226,13 +213,13 @@ sharkd_session_filter_data(const char *filter) } } -static void -sharkd_session_process_info_conv_cb(gpointer data, gpointer user_data) +static gboolean +sharkd_session_process_info_conv_cb(const void* key, void* value, void* userdata) { - struct register_ct *table = (struct register_ct *) data; - int *pi = (int *) user_data; + struct register_ct *table = (struct register_ct *) value; + int *pi = (int *) userdata; - const char *label = proto_get_protocol_short_name(find_protocol_by_id(get_conversation_proto_id(table))); + const char *label = (const char*)key; if (get_conversation_packet_func(table)) { @@ -253,6 +240,7 @@ sharkd_session_process_info_conv_cb(gpointer data, gpointer user_data) *pi = *pi + 1; } + return FALSE; } /** diff --git a/ui/gtk/conversations_table.c b/ui/gtk/conversations_table.c index 588b05bc1f..044be7a133 100644 --- a/ui/gtk/conversations_table.c +++ b/ui/gtk/conversations_table.c @@ -2435,11 +2435,11 @@ typedef struct _init_ct_page_data { GtkWidget *win; } init_ct_page_data; -static void -init_ct_page(gpointer data, gpointer user_data) +static gboolean +init_ct_page(const void *key _U_, void *value, void *userdata) { - register_ct_t *table = (register_ct_t*)data; - init_ct_page_data* ct_page_data = (init_ct_page_data*)user_data; + register_ct_t *table = (register_ct_t*)value; + init_ct_page_data* ct_page_data = (init_ct_page_data*)userdata; conversations_table *conversations; GtkWidget *page_lb; @@ -2454,6 +2454,7 @@ init_ct_page(gpointer data, gpointer user_data) conversations->page_lb = page_lb; ct_page_data->pages[++ct_page_data->page] = conversations; } + return FALSE; } void diff --git a/ui/gtk/hostlist_table.c b/ui/gtk/hostlist_table.c index e65f227392..b1302455c9 100644 --- a/ui/gtk/hostlist_table.c +++ b/ui/gtk/hostlist_table.c @@ -1230,11 +1230,11 @@ typedef struct _init_host_page_data { GtkWidget *win; } init_host_page_data; -static void -init_host_page(gpointer data, gpointer user_data) +static gboolean +init_host_page(const void *key _U_, void *value, void *userdata) { - register_ct_t *table = (register_ct_t*)data; - init_host_page_data* host_page_data = (init_host_page_data*)user_data; + register_ct_t *table = (register_ct_t*)value; + init_host_page_data* host_page_data = (init_host_page_data*)userdata; hostlist_table *hosttable; GtkWidget *page_lb; @@ -1248,6 +1248,8 @@ init_host_page(gpointer data, gpointer user_data) hosttable->page_lb = page_lb; host_page_data->pages[++host_page_data->page] = hosttable; } + + return FALSE; } void diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c index 1ced34fece..a9b981b3ca 100644 --- a/ui/gtk/main_menubar.c +++ b/ui/gtk/main_menubar.c @@ -2688,11 +2688,11 @@ typedef struct { int counter; } conv_menu_t; -static void -add_conversation_menuitem(gpointer data, gpointer user_data) +static gboolean +add_conversation_menuitem(const void *key, void *value, void *userdata) { - register_ct_t *table = (register_ct_t*)data; - conv_menu_t *conv = (conv_menu_t*)user_data; + register_ct_t *table = (register_ct_t*)value; + conv_menu_t *conv = (conv_menu_t*)userdata; gchar *action_name; GtkAction *action; @@ -2700,7 +2700,7 @@ add_conversation_menuitem(gpointer data, gpointer user_data) /*g_warning("action_name %s, filter_entry->name %s",action_name,filter_entry->name);*/ action = (GtkAction *)g_object_new (GTK_TYPE_ACTION, "name", action_name, - "label", proto_get_protocol_short_name(find_protocol_by_id(get_conversation_proto_id(table))), + "label", key, "sensitive", TRUE, NULL); g_signal_connect (action, "activate", @@ -2716,6 +2716,7 @@ add_conversation_menuitem(gpointer data, gpointer user_data) FALSE); g_free(action_name); conv->counter++; + return FALSE; } static void @@ -2750,11 +2751,11 @@ menu_hostlist_cb(GtkAction *action _U_, gpointer user_data) hostlist_endpoint_cb(table); } -static void -add_hostlist_menuitem(gpointer data, gpointer user_data) +static gboolean +add_hostlist_menuitem(const void *key, void *value, void *userdata) { - register_ct_t *table = (register_ct_t*)data; - conv_menu_t *conv = (conv_menu_t*)user_data; + register_ct_t *table = (register_ct_t*)value; + conv_menu_t *conv = (conv_menu_t*)userdata; gchar *action_name; GtkAction *action; @@ -2762,7 +2763,7 @@ add_hostlist_menuitem(gpointer data, gpointer user_data) /*g_warning("action_name %s, filter_entry->name %s",action_name,filter_entry->name);*/ action = (GtkAction *)g_object_new (GTK_TYPE_ACTION, "name", action_name, - "label", proto_get_protocol_short_name(find_protocol_by_id(get_conversation_proto_id(table))), + "label", key, "sensitive", TRUE, NULL); g_signal_connect (action, "activate", @@ -2778,6 +2779,7 @@ add_hostlist_menuitem(gpointer data, gpointer user_data) FALSE); g_free(action_name); conv->counter++; + return FALSE; } static void diff --git a/ui/qt/conversation_dialog.cpp b/ui/qt/conversation_dialog.cpp index be43a2e04b..cf712f9f0d 100644 --- a/ui/qt/conversation_dialog.cpp +++ b/ui/qt/conversation_dialog.cpp @@ -92,7 +92,7 @@ ConversationDialog::ConversationDialog(QWidget &parent, CaptureFile &cf, int cli } // Bring the command-line specified type to the front. - if (get_conversation_by_proto_id(cli_proto_id)) { + if ((cli_proto_id > 0) && (get_conversation_by_proto_id(cli_proto_id))) { conv_protos.removeAll(cli_proto_id); conv_protos.prepend(cli_proto_id); } diff --git a/ui/qt/endpoint_dialog.cpp b/ui/qt/endpoint_dialog.cpp index 952f2f1820..dd7f5ba556 100644 --- a/ui/qt/endpoint_dialog.cpp +++ b/ui/qt/endpoint_dialog.cpp @@ -71,7 +71,7 @@ EndpointDialog::EndpointDialog(QWidget &parent, CaptureFile &cf, int cli_proto_i } // Bring the command-line specified type to the front. - if (get_conversation_by_proto_id(cli_proto_id)) { + if ((cli_proto_id > 0) && (get_conversation_by_proto_id(cli_proto_id))) { endp_protos.removeAll(cli_proto_id); endp_protos.prepend(cli_proto_id); } diff --git a/ui/qt/traffic_table_dialog.cpp b/ui/qt/traffic_table_dialog.cpp index c81fc1bf2f..261531f019 100644 --- a/ui/qt/traffic_table_dialog.cpp +++ b/ui/qt/traffic_table_dialog.cpp @@ -112,22 +112,41 @@ const QList<int> TrafficTableDialog::defaultProtos() const << proto_get_id_by_filter_name("udp"); } -void TrafficTableDialog::fillTypeMenu(QList<int> &enabled_protos) +class fillTypeMenuData { - for (guint i = 0; i < conversation_table_get_num(); i++) { - int proto_id = get_conversation_proto_id(get_conversation_table_by_num(i)); - if (proto_id < 0) { - continue; - } - QString title = proto_get_protocol_short_name(find_protocol_by_id(proto_id)); - - QAction *endp_action = new QAction(title, this); - endp_action->setData(qVariantFromValue(proto_id)); - endp_action->setCheckable(true); - endp_action->setChecked(enabled_protos.contains(proto_id)); - connect(endp_action, SIGNAL(triggered()), this, SLOT(toggleTable())); - traffic_type_menu_.addAction(endp_action); +public: + fillTypeMenuData(TrafficTableDialog* dialog, QList<int> &enabled_protos) + : dialog_(dialog), + enabled_protos_(enabled_protos) + { } + + TrafficTableDialog* dialog_; + QList<int> &enabled_protos_; +}; + +gboolean TrafficTableDialog::fillTypeMenuFunc(const void *key, void *value, void *userdata) +{ + register_ct_t* ct = (register_ct_t*)value; + QString title = (gchar*)key; + fillTypeMenuData* data = (fillTypeMenuData*)userdata; + int proto_id = get_conversation_proto_id(ct); + + QAction *endp_action = new QAction(title, data->dialog_); + endp_action->setData(qVariantFromValue(proto_id)); + endp_action->setCheckable(true); + endp_action->setChecked(data->enabled_protos_.contains(proto_id)); + data->dialog_->connect(endp_action, SIGNAL(triggered()), data->dialog_, SLOT(data->dialog_->toggleTable())); + data->dialog_->traffic_type_menu_.addAction(endp_action); + + return FALSE; +} + +void TrafficTableDialog::fillTypeMenu(QList<int> &enabled_protos) +{ + fillTypeMenuData data(this, enabled_protos); + + conversation_table_iterate_tables(fillTypeMenuFunc, &data); } void TrafficTableDialog::addProgressFrame(QObject *parent) diff --git a/ui/qt/traffic_table_dialog.h b/ui/qt/traffic_table_dialog.h index 9d46c77906..e650d53ec1 100644 --- a/ui/qt/traffic_table_dialog.h +++ b/ui/qt/traffic_table_dialog.h @@ -145,6 +145,7 @@ protected: QMap<int, TrafficTableTreeWidget *> proto_id_to_tree_; const QList<int> defaultProtos() const; + static gboolean fillTypeMenuFunc(const void *key, void *value, void *userdata); void fillTypeMenu(QList<int> &enabled_protos); // Adds a conversation tree. Returns true if the tree was freshly created, false if it was cached. virtual bool addTrafficTable(register_ct_t*) { return false; } |