HACK: 1. try to match RowsetProperties
[wireshark-wip.git] / ui / gtk / conversation_hastables_dlg.c
blob6b9f245765424c20eb625495b59e3ce2de7b099e
1 /* conversation_hastables_dlg.c
2 * Show conversation hastable info
4 * Copyright 2013 Anders Broman <anders.broman@ericsson.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "config.h"
29 #include <string.h>
31 #include <gtk/gtk.h>
33 #include <epan/epan.h>
34 #include <epan/filesystem.h>
35 #include <epan/conversation.h>
37 #include "ui/main_statusbar.h"
39 #include "ui/gtk/dlg_utils.h"
40 #include "ui/gtk/expert_comp_dlg.h"
41 #include "ui/gtk/font_utils.h"
42 #include "ui/gtk/gui_utils.h"
43 #include "ui/gtk/help_dlg.h"
44 #include "ui/gtk/main.h"
45 #include "ui/gtk/packet_list.h"
46 #include "ui/gtk/conversation_hastables_dlg.h"
47 #include "ui/gtk/old-gtk-compat.h"
49 static GtkWidget *conversation_hastables_dlg_w = NULL;
51 #define CONV_STR_BUF_MAX 1024
54 * Compute the hash value for two given address/port pairs if the match
55 * is to be exact.
57 /* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx#existing
58 * One-at-a-Time hash
60 static guint
61 conversation_hash_exact(gconstpointer v)
63 const conversation_key *key = (const conversation_key *)v;
64 guint hash_val;
65 int i;
66 const guint8 *ADD_ADDRESS_TO_HASH_data;
68 hash_val = 0;
69 #if 0
70 ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
71 hash_val += key->port1;
72 ADD_ADDRESS_TO_HASH(hash_val, &key->addr2);
73 hash_val += key->port2;
75 return hash_val;
76 #endif
77 for ( i = 0; i < key->addr1.len; i++ ) {
78 ADD_ADDRESS_TO_HASH_data = (const guint8 *)((&key->addr1)->data);
79 hash_val += ADD_ADDRESS_TO_HASH_data[i];
80 hash_val += ( hash_val << 10 );
81 hash_val ^= ( hash_val >> 6 );
84 for ( i = 0; i < 4; i++ ) {
85 ADD_ADDRESS_TO_HASH_data = (const guint8 *)(&key->port1);
86 hash_val += ADD_ADDRESS_TO_HASH_data[i];
87 hash_val += ( hash_val << 10 );
88 hash_val ^= ( hash_val >> 6 );
91 for ( i = 0; i < key->addr2.len; i++ ) {
92 ADD_ADDRESS_TO_HASH_data = (const guint8 *)((&key->addr2)->data);
93 hash_val += ADD_ADDRESS_TO_HASH_data[i];
94 hash_val += ( hash_val << 10 );
95 hash_val ^= ( hash_val >> 6 );
98 for ( i = 0; i < 4; i++ ) {
99 ADD_ADDRESS_TO_HASH_data = (const guint8 *)(&key->port2);
100 hash_val += ADD_ADDRESS_TO_HASH_data[i];
101 hash_val += ( hash_val << 10 );
102 hash_val ^= ( hash_val >> 6 );
105 hash_val += ( hash_val << 3 );
106 hash_val ^= ( hash_val >> 11 );
107 hash_val += ( hash_val << 15 );
109 return hash_val;
112 static guint
113 conversation_hash_exact_old(gconstpointer v)
115 const conversation_key *key = (const conversation_key *)v;
116 guint hash_val;
118 hash_val = 0;
119 ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
120 hash_val += key->port1;
121 ADD_ADDRESS_TO_HASH(hash_val, &key->addr2);
122 hash_val += key->port2;
124 return hash_val;
127 static void
128 conversation_hashtable_exact_to_texbuff(gpointer key, gpointer value _U_, gpointer user_data)
130 gchar string_buff[CONV_STR_BUF_MAX];
131 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
132 /*conversation_t *conversation = (conversation_t *)value;*/
133 conversation_key *conv_key = (conversation_key*)key;
135 g_snprintf(string_buff, CONV_STR_BUF_MAX, "Key:0x%x old key:0x%x\n",conversation_hash_exact(conv_key),conversation_hash_exact_old(conv_key));
137 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
141 static void
142 conversation_info_to_texbuff(GtkTextBuffer *buffer)
144 gchar string_buff[CONV_STR_BUF_MAX];
145 GHashTable *conversation_hashtable_exact;
146 GHashTable *conversation_hashtable_no_addr2;
147 GHashTable *conversation_hashtable_no_port2;
148 GHashTable *conversation_hashtable_no_addr2_or_port2;
150 g_snprintf(string_buff, CONV_STR_BUF_MAX, "Conversation hastables info:\n");
151 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
153 conversation_hashtable_exact = get_conversation_hashtable_exact();
154 if(conversation_hashtable_exact){
155 g_snprintf(string_buff, CONV_STR_BUF_MAX, "conversation_hashtable_exact %i entries\n#\n",
156 g_hash_table_size(conversation_hashtable_exact));
157 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
158 g_hash_table_foreach( conversation_hashtable_exact, conversation_hashtable_exact_to_texbuff, buffer);
161 conversation_hashtable_no_addr2 = get_conversation_hashtable_no_addr2();
162 if(conversation_hashtable_no_addr2){
163 g_snprintf(string_buff, CONV_STR_BUF_MAX, "conversation_hashtable_no_addr2 %i entries\n#\n",
164 g_hash_table_size(conversation_hashtable_no_addr2));
165 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
169 conversation_hashtable_no_port2 = get_conversation_hashtable_no_port2();
170 if(conversation_hashtable_no_port2){
171 g_snprintf(string_buff, CONV_STR_BUF_MAX, "conversation_hashtable_no_port2 %i entries\n#\n",
172 g_hash_table_size(conversation_hashtable_no_port2));
173 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
177 conversation_hashtable_no_addr2_or_port2 = get_conversation_hashtable_no_addr2_or_port2();
178 if(conversation_hashtable_no_addr2_or_port2){
179 g_snprintf(string_buff, CONV_STR_BUF_MAX, "conversation_hashtable_no_addr2_or_port2 %i entries\n#\n",
180 g_hash_table_size(conversation_hashtable_no_addr2_or_port2));
181 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
187 void
188 conversation_hastables_dlg (GtkAction *action _U_, gpointer data _U_)
191 GtkWidget *vbox;
192 GtkWidget *view;
193 GtkWidget *scroll;
194 GtkWidget *bbox;
195 GtkWidget *ok_bt, *cancel_bt, *help_bt;
196 GtkTextBuffer *buffer;
198 conversation_hastables_dlg_w = dlg_window_new ("Conversation hastables");
199 gtk_widget_set_size_request (conversation_hastables_dlg_w, 750, 350);
200 gtk_window_set_resizable (GTK_WINDOW (conversation_hastables_dlg_w), TRUE);
201 gtk_container_set_border_width (GTK_CONTAINER (conversation_hastables_dlg_w), DLG_OUTER_MARGIN);
203 vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, DLG_UNRELATED_SPACING, FALSE);
204 gtk_container_add (GTK_CONTAINER (conversation_hastables_dlg_w), vbox);
205 gtk_widget_show (vbox);
207 view = gtk_text_view_new ();
208 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
209 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
210 #if GTK_CHECK_VERSION(3, 0, 0)
211 gtk_widget_override_font(view, user_font_get_regular());
212 #else
213 gtk_widget_modify_font(view, user_font_get_regular());
214 #endif
215 gtk_widget_show (view);
217 scroll = gtk_scrolled_window_new(NULL, NULL);
218 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
219 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
220 gtk_container_add(GTK_CONTAINER(scroll), view);
221 gtk_widget_show(scroll);
222 gtk_box_pack_start(GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
224 /* Get the address list */
225 conversation_info_to_texbuff(buffer);
227 /* Button row. */
228 bbox = dlg_button_row_new (GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
229 gtk_box_pack_end (GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
231 ok_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_OK);
232 /*g_signal_connect (ok_bt, "clicked", G_CALLBACK(pkt_comment_text_buff_ok_cb), view);*/
233 gtk_widget_set_sensitive (ok_bt, TRUE);
235 cancel_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_CANCEL);
236 window_set_cancel_button (conversation_hastables_dlg_w, cancel_bt, window_cancel_button_cb);
238 help_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_HELP);
239 #if 0
240 g_signal_connect (help_bt, "clicked",/* G_CALLBACK(topic_cb)*/NULL, /*(gpointer)HELP_MANUAL_ADDR_RESOLVE_DIALOG*/NULL);
241 #endif
242 gtk_widget_set_sensitive (help_bt, FALSE);
244 gtk_widget_grab_default (ok_bt);
245 /*g_signal_connect (conversation_hastables_dlg_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);*/
248 gtk_widget_show (conversation_hastables_dlg_w);
252 * Editor modelines
254 * Local Variables:
255 * c-basic-offset: 4
256 * tab-width: 8
257 * indent-tabs-mode: nil
258 * End:
260 * ex: set shiftwidth=4 tabstop=8 expandtab:
261 * :indentSize=4:tabSize=8:noTabs=true: