1 /* conversation_hash_tables_dialog.cpp
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "conversation_hash_tables_dialog.h"
11 #include <ui_conversation_hash_tables_dialog.h>
12
13 #include "config.h"
14
15 #include <glib.h>
16
17 #include <epan/conversation.h>
18 #include <epan/conversation_debug.h>
19
20 #include <ui/qt/utils/qt_ui_utils.h>
AssertNotMainThread()21 #include "wireshark_application.h"
22
23 ConversationHashTablesDialog::ConversationHashTablesDialog(QWidget *parent) :
24 GeometryStateDialog(parent),
25 ui(new Ui::ConversationHashTablesDialog)
26 {
27 ui->setupUi(this);
28 if (parent) loadGeometry(parent->width() * 3 / 4, parent->height() * 3 / 4);
29 setAttribute(Qt::WA_DeleteOnClose, true);
30 setWindowTitle(wsApp->windowTitleString(tr("Conversation Hash Tables")));
31
32 QString html;
33
34 html += "<h3>Conversation Hash Tables</h3>\n";
35
36 html += hashTableToHtmlTable("conversation_hashtable_exact", get_conversation_hashtable_exact());
37 html += hashTableToHtmlTable("conversation_hashtable_no_addr2", get_conversation_hashtable_no_addr2());
38 html += hashTableToHtmlTable("conversation_hashtable_no_port2", get_conversation_hashtable_no_port2());
39 html += hashTableToHtmlTable("conversation_hashtable_no_addr2_or_port2", get_conversation_hashtable_no_addr2_or_port2());
40
41 ui->conversationTextEdit->setHtml(html);
42 }
OpenParent(TestOpensOpenedParent * aParent,Transport * aTransport,base::ProcessId aOtherPid)43
44 ConversationHashTablesDialog::~ConversationHashTablesDialog()
45 {
46 delete ui;
47 }
48
49 static void
50 populate_html_table(gpointer data, gpointer user_data)
51 {
52 const conversation_key_t conv_key = (conversation_key_t)data;
53 QString* html_table = (QString*)user_data;
54 gchar* tmp = conversation_get_html_hash(conv_key);
55
56 // XXX Add a column for the hash value.
AllocPTestOpensOpenedParent(Transport * transport,ProcessId otherPid)57 (*html_table) += QString(tmp);
58 wmem_free(NULL, tmp);
59 }
60
61 const QString ConversationHashTablesDialog::hashTableToHtmlTable(const QString table_name, wmem_map_t *hash_table)
62 {
63 wmem_list_t *conversation_keys = NULL;
64 guint num_keys = 0;
65 if (hash_table)
66 {
67 conversation_keys = wmem_map_get_keys(NULL, hash_table);
68 num_keys = wmem_list_count(conversation_keys);
69 }
70
71 QString html_table = QString("<p>%1, %2 entries</p>").arg(table_name).arg(num_keys);
72 if (num_keys > 0)
73 {
ActorDestroy(ActorDestroyReason why)74 int one_em = fontMetrics().height();
75 html_table += QString("<table cellpadding=\"%1\">\n").arg(one_em / 4);
76
77 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";
78
79 wmem_list_foreach(conversation_keys, populate_html_table, (void*)&html_table);
80 html_table += "</table>\n";
81 }
82 if (conversation_keys)
83 wmem_destroy_list(conversation_keys);
84 return html_table;
85 }
RecvHello()86