diff options
author | Michael Mann <mmann78@netscape.net> | 2017-02-09 12:28:14 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-02-10 13:26:14 +0000 |
commit | b54c43801112711dcba341f3eb4701678a0e1916 (patch) | |
tree | 49c8f27b4ad96bd35189451addd1ab6941a408a3 /ui/qt | |
parent | 8bbf0341e13b28f76a2e0d9c31bc0912aba36327 (diff) | |
download | wireshark-b54c43801112711dcba341f3eb4701678a0e1916.tar.gz |
Convert conversation hash tables to use wmem.
Simplifies cleanup because wmem can handle the memory cleanup.
Change-Id: Idc6a9bfe5f23c83b59a5278a64b9fb706862342d
Reviewed-on: https://code.wireshark.org/review/20042
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/conversation_hash_tables_dialog.cpp | 49 | ||||
-rw-r--r-- | ui/qt/conversation_hash_tables_dialog.h | 3 |
2 files changed, 33 insertions, 19 deletions
diff --git a/ui/qt/conversation_hash_tables_dialog.cpp b/ui/qt/conversation_hash_tables_dialog.cpp index 713d711bc5..a0f2566da5 100644 --- a/ui/qt/conversation_hash_tables_dialog.cpp +++ b/ui/qt/conversation_hash_tables_dialog.cpp @@ -58,30 +58,43 @@ ConversationHashTablesDialog::~ConversationHashTablesDialog() delete ui; } -const QString ConversationHashTablesDialog::hashTableToHtmlTable(const QString table_name, struct _GHashTable *hash_table) +static void +populate_html_table(gpointer data, gpointer user_data) { - GList *conversation_keys = NULL; - if (hash_table) conversation_keys = g_hash_table_get_keys(hash_table); - int num_keys = g_list_length(conversation_keys); + const conversation_key *conv_key = (const conversation_key *)data; + QString* html_table = (QString*)user_data; - QString html_table = QString("<p>%1, %2 entries</p>").arg(table_name).arg(num_keys); - if (num_keys < 1) return html_table; + // XXX Add a column for the hash value. + (*html_table) += QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>\n") + .arg(address_to_qstring(&conv_key->addr1)) + .arg(conv_key->port1) + .arg(address_to_qstring(&conv_key->addr2)) + .arg(conv_key->port2); +} + +const QString ConversationHashTablesDialog::hashTableToHtmlTable(const QString table_name, wmem_map_t *hash_table) +{ + wmem_list_t *conversation_keys = NULL; + guint num_keys = 0; + if (hash_table) + { + conversation_keys = wmem_map_get_keys(NULL, hash_table); + num_keys = wmem_list_count(conversation_keys); + } - int one_em = fontMetrics().height(); - html_table += QString("<table cellpadding=\"%1\">\n").arg(one_em / 4); + QString html_table = QString("<p>%1, %2 entries</p>").arg(table_name).arg(num_keys); + if (num_keys > 0) + { + int one_em = fontMetrics().height(); + html_table += QString("<table cellpadding=\"%1\">\n").arg(one_em / 4); - html_table += "<tr><th align=\"left\">Address 1</th><th align=\"left\">Port 1</th><th align=\"left\">Address 2</th><th align=\"left\">Port 2</th></tr>\n"; + html_table += "<tr><th align=\"left\">Address 1</th><th align=\"left\">Port 1</th><th align=\"left\">Address 2</th><th align=\"left\">Port 2</th></tr>\n"; - // XXX Add a column for the hash value. - for (GList *ck_entry = conversation_keys; ck_entry; ck_entry = g_list_next(ck_entry)) { - const conversation_key *conv_key = (conversation_key *) ck_entry->data; - html_table += QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>\n") - .arg(address_to_qstring(&conv_key->addr1)) - .arg(conv_key->port1) - .arg(address_to_qstring(&conv_key->addr2)) - .arg(conv_key->port2); + wmem_list_foreach(conversation_keys, populate_html_table, (void*)&html_table); + html_table += "</table>\n"; } - html_table += "</table>\n"; + if (conversation_keys) + wmem_destroy_list(conversation_keys); return html_table; } diff --git a/ui/qt/conversation_hash_tables_dialog.h b/ui/qt/conversation_hash_tables_dialog.h index a0299c428d..4b0d35fa77 100644 --- a/ui/qt/conversation_hash_tables_dialog.h +++ b/ui/qt/conversation_hash_tables_dialog.h @@ -23,6 +23,7 @@ #define CONVERSATION_HASH_TABLES_DIALOG_H #include "geometry_state_dialog.h" +#include <epan/wmem/wmem.h> namespace Ui { class ConversationHashTablesDialog; @@ -39,7 +40,7 @@ public: private: Ui::ConversationHashTablesDialog *ui; - const QString hashTableToHtmlTable(const QString table_name, struct _GHashTable *hash_table); + const QString hashTableToHtmlTable(const QString table_name, wmem_map_t *hash_table); }; #endif // CONVERSATION_HASH_TABLES_DIALOG_H |