add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / ui / gtk / proto_dlg.c
blob983893f3cab4f251f3761214a035bffc3cec0d9d
1 /* proto_dlg.c
3 * $Id$
5 * Laurent Deniel <laurent.deniel@free.fr>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 2000 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
27 #include <string.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #if GTK_CHECK_VERSION(3,0,0)
32 # include <gdk/gdkkeysyms-compat.h>
33 #endif
35 #include <epan/prefs.h>
36 #include <epan/filesystem.h>
37 #include <epan/disabled_protos.h>
39 #include "ui/util.h"
41 #include "ui/simple_dialog.h"
43 #include "ui/gtk/main.h"
44 #include "ui/gtk/gui_utils.h"
45 #include "ui/gtk/dlg_utils.h"
46 #include "ui/gtk/proto_dlg.h"
47 #include "ui/gtk/help_dlg.h"
49 static gboolean proto_delete_event_cb(GtkWidget *, GdkEvent *, gpointer);
50 static void proto_ok_cb(GtkWidget *, gpointer);
51 static void proto_apply_cb(GtkWidget *, gpointer);
52 static void proto_save_cb(GtkWidget *, gpointer);
53 static void proto_cancel_cb(GtkWidget *, gpointer);
54 static void proto_destroy_cb(GtkWidget *, gpointer);
55 #if defined(HEUR_DISSECTOR_LIST)
56 static void heur_proto_destroy_cb(GtkWidget *, gpointer);
57 #endif
59 static void show_proto_selection(GtkListStore *proto_store);
60 #if defined(HEUR_DISSECTOR_LIST)
61 static void show_heur_selection(GtkListStore *proto_store);
62 #endif
63 static gboolean set_proto_selection(GtkWidget *);
64 static gboolean revert_proto_selection(void);
66 static void proto_col_clicked_cb(GtkWidget *col _U_, GtkWidget *proto_list);
68 static void toggle_all_cb(GtkWidget *button, gpointer parent_w);
69 static void enable_all_cb(GtkWidget *button, gpointer parent_w);
70 static void disable_all_cb(GtkWidget *button, gpointer parent_w);
71 static void status_toggled(GtkCellRendererToggle *, gchar *, gpointer);
73 static GtkWidget *proto_w = NULL;
75 /* list of protocols */
76 static GSList *protocol_list = NULL;
78 #if defined(HEUR_DISSECTOR_LIST)
79 /* list of heuristic protocols */
80 static GSList *heur_protocol_list = NULL;
81 #endif
83 typedef struct protocol_data {
84 const char *name;
85 const char *abbrev;
86 int hfinfo_index;
87 gboolean enabled;
88 gboolean was_enabled;
89 GtkTreeIter iter;
90 } protocol_data_t;
92 #define DISABLED "Disabled"
93 #define STATUS_TXT(x) ((x) ? "" : DISABLED)
96 #if defined(HEUR_DISSECTOR_LIST)
97 static GtkWidget *
98 build_heur_dissectors_treeview(void)
100 GtkWidget *bbox, *proto_list, *label, *proto_sw, *proto_vb, *button,
101 *ok_bt, *save_bt, *cancel_bt;
103 static const gchar *titles[] = { "Status", "Heuristic Protocol", "Description" };
104 GtkListStore *proto_store;
105 GtkCellRenderer *proto_rend;
106 GtkTreeViewColumn *proto_col;
108 /* Protocol list */
109 proto_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
110 gtk_widget_show(proto_vb);
112 proto_sw = scrolled_window_new(NULL, NULL);
113 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(proto_sw),
114 GTK_SHADOW_IN);
115 gtk_box_pack_start(GTK_BOX(proto_vb), proto_sw, TRUE, TRUE, 0);
116 gtk_widget_show(proto_sw);
118 proto_store = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_STRING,
119 G_TYPE_STRING, G_TYPE_POINTER);
120 show_heur_selection(proto_store);
121 /* default sort on "abbrev" column */
122 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(proto_store), 1,
123 GTK_SORT_ASCENDING);
125 proto_list = tree_view_new(GTK_TREE_MODEL(proto_store));
126 gtk_container_add(GTK_CONTAINER(proto_sw), proto_list);
128 proto_rend = gtk_cell_renderer_toggle_new();
129 g_signal_connect(proto_rend, "toggled", G_CALLBACK(status_toggled), proto_store);
130 proto_col = gtk_tree_view_column_new_with_attributes(titles[0], proto_rend, "active", 0, NULL);
131 gtk_tree_view_column_set_sort_column_id(proto_col, 0);
132 g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
133 gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
135 proto_rend = gtk_cell_renderer_text_new();
136 proto_col = gtk_tree_view_column_new_with_attributes(titles[1], proto_rend, "text", 1, NULL);
137 gtk_tree_view_column_set_sort_column_id(proto_col, 1);
138 g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
139 gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
141 proto_rend = gtk_cell_renderer_text_new();
142 proto_col = gtk_tree_view_column_new_with_attributes(titles[2], proto_rend, "text", 2, NULL);
143 gtk_tree_view_column_set_sort_column_id(proto_col, 2);
144 g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
145 gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
147 gtk_tree_view_set_search_column(GTK_TREE_VIEW(proto_list), 1); /* col 1 in the *model* */
148 g_object_unref(G_OBJECT(proto_store));
149 gtk_widget_show(proto_list);
151 label = gtk_label_new("Disabling a heuristic dissector prevents higher "
152 "layer protocols from being displayed");
153 gtk_misc_set_alignment(GTK_MISC(label), 0.5f, 0.5f);
154 gtk_widget_show(label);
155 gtk_box_pack_start(GTK_BOX(proto_vb), label, FALSE, FALSE, 5);
157 bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
158 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
159 gtk_box_set_spacing(GTK_BOX(bbox), 5);
160 gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
161 gtk_widget_show(bbox);
163 /* Enable All */
164 button = gtk_button_new_with_label("Enable All");
165 g_signal_connect(button, "clicked", G_CALLBACK(enable_all_cb), proto_list);
166 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
167 gtk_widget_show(button);
169 /* Disable All */
170 button = gtk_button_new_with_label("Disable All");
171 g_signal_connect(button, "clicked", G_CALLBACK(disable_all_cb), proto_list);
172 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
173 gtk_widget_show(button);
175 /* Invert */
176 button = gtk_button_new_with_label("Invert");
177 g_signal_connect(button, "clicked", G_CALLBACK(toggle_all_cb), proto_list);
178 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
179 gtk_widget_show(button);
182 /* Button row */
183 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
184 gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
185 gtk_widget_show(bbox);
187 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
188 /*g_signal_connect(ok_bt, "clicked", G_CALLBACK(proto_ok_cb), proto_w);*/
189 gtk_widget_grab_default(ok_bt);
191 /*apply_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_APPLY);*/
192 /* g_signal_connect(apply_bt, "clicked", G_CALLBACK(proto_apply_cb), proto_w);*/
194 save_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_SAVE);
195 /* g_signal_connect(save_bt, "clicked", G_CALLBACK(proto_save_cb), proto_w);*/
197 cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
198 window_set_cancel_button(proto_w, cancel_bt, proto_cancel_cb);
200 /*help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);*/
201 /*g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_ENABLED_PROTOCOLS_DIALOG);*/
203 /*g_signal_connect(proto_w, "delete_event", G_CALLBACK(proto_delete_event_cb), NULL);*/
204 g_signal_connect(proto_w, "destroy", G_CALLBACK(heur_proto_destroy_cb), NULL);
206 gtk_widget_show(proto_w);
208 gtk_widget_grab_focus(proto_list); /* XXX: force focus to the tree_view. This hack req'd so "type-ahead find"
209 * will be effective after the window is displayed. The issue is
210 * that any call to gtk_tree_view_column_set_sort_column_id above
211 * apparently sets the focus to the column header button and thus
212 * type-ahead find is, in effect, disabled on the column.
213 * Also required: a grab_focus whenever the column header is
214 * clicked to change the column sort order since the click
215 * also changes the focus to the column header button.
216 * Is there a better way to do this ?
219 /* hide the Save button if the user uses implicit save */
220 if(!prefs.gui_use_pref_save) {
221 gtk_widget_hide(save_bt);
224 return proto_vb;
227 #endif
229 static GtkWidget *
230 build_protocols_treeview(void)
232 GtkWidget *bbox, *proto_list, *label, *proto_sw, *proto_vb, *button,
233 *ok_bt, *apply_bt, *save_bt, *cancel_bt, *help_bt;
235 static const gchar *titles[] = { "Status", "Protocol", "Description" };
236 GtkListStore *proto_store;
237 GtkCellRenderer *proto_rend;
238 GtkTreeViewColumn *proto_col;
240 /* Protocol list */
241 proto_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
242 gtk_widget_show(proto_vb);
244 proto_sw = scrolled_window_new(NULL, NULL);
245 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(proto_sw),
246 GTK_SHADOW_IN);
247 gtk_box_pack_start(GTK_BOX(proto_vb), proto_sw, TRUE, TRUE, 0);
248 gtk_widget_show(proto_sw);
250 proto_store = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_STRING,
251 G_TYPE_STRING, G_TYPE_POINTER);
252 show_proto_selection(proto_store);
253 /* default sort on "abbrev" column */
254 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(proto_store), 1,
255 GTK_SORT_ASCENDING);
257 proto_list = tree_view_new(GTK_TREE_MODEL(proto_store));
258 gtk_container_add(GTK_CONTAINER(proto_sw), proto_list);
260 proto_rend = gtk_cell_renderer_toggle_new();
261 g_signal_connect(proto_rend, "toggled", G_CALLBACK(status_toggled), proto_store);
262 proto_col = gtk_tree_view_column_new_with_attributes(titles[0], proto_rend, "active", 0, NULL);
263 gtk_tree_view_column_set_sort_column_id(proto_col, 0);
264 g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
265 gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
267 proto_rend = gtk_cell_renderer_text_new();
268 proto_col = gtk_tree_view_column_new_with_attributes(titles[1], proto_rend, "text", 1, NULL);
269 gtk_tree_view_column_set_sort_column_id(proto_col, 1);
270 g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
271 gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
273 proto_rend = gtk_cell_renderer_text_new();
274 proto_col = gtk_tree_view_column_new_with_attributes(titles[2], proto_rend, "text", 2, NULL);
275 gtk_tree_view_column_set_sort_column_id(proto_col, 2);
276 g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
277 gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
279 gtk_tree_view_set_search_column(GTK_TREE_VIEW(proto_list), 1); /* col 1 in the *model* */
280 g_object_unref(G_OBJECT(proto_store));
281 gtk_widget_show(proto_list);
283 label = gtk_label_new("Disabling a protocol prevents higher "
284 "layer protocols from being displayed");
285 gtk_misc_set_alignment(GTK_MISC(label), 0.5f, 0.5f);
286 gtk_widget_show(label);
287 gtk_box_pack_start(GTK_BOX(proto_vb), label, FALSE, FALSE, 5);
289 bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
290 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
291 gtk_box_set_spacing(GTK_BOX(bbox), 5);
292 gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
293 gtk_widget_show(bbox);
295 /* Enable All */
296 button = gtk_button_new_with_label("Enable All");
297 g_signal_connect(button, "clicked", G_CALLBACK(enable_all_cb), proto_list);
298 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
299 gtk_widget_show(button);
301 /* Disable All */
302 button = gtk_button_new_with_label("Disable All");
303 g_signal_connect(button, "clicked", G_CALLBACK(disable_all_cb), proto_list);
304 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
305 gtk_widget_show(button);
307 /* Invert */
308 button = gtk_button_new_with_label("Invert");
309 g_signal_connect(button, "clicked", G_CALLBACK(toggle_all_cb), proto_list);
310 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
311 gtk_widget_show(button);
314 /* Button row */
315 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
316 gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
317 gtk_widget_show(bbox);
319 ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
320 g_signal_connect(ok_bt, "clicked", G_CALLBACK(proto_ok_cb), proto_w);
321 gtk_widget_grab_default(ok_bt);
323 apply_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_APPLY);
324 g_signal_connect(apply_bt, "clicked", G_CALLBACK(proto_apply_cb), proto_w);
326 save_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_SAVE);
327 g_signal_connect(save_bt, "clicked", G_CALLBACK(proto_save_cb), proto_w);
329 cancel_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
330 window_set_cancel_button(proto_w, cancel_bt, proto_cancel_cb);
332 help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
333 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_ENABLED_PROTOCOLS_DIALOG);
335 g_signal_connect(proto_w, "delete_event", G_CALLBACK(proto_delete_event_cb), NULL);
336 g_signal_connect(proto_w, "destroy", G_CALLBACK(proto_destroy_cb), NULL);
338 gtk_widget_show(proto_w);
340 gtk_widget_grab_focus(proto_list); /* XXX: force focus to the tree_view. This hack req'd so "type-ahead find"
341 * will be effective after the window is displayed. The issue is
342 * that any call to gtk_tree_view_column_set_sort_column_id above
343 * apparently sets the focus to the column header button and thus
344 * type-ahead find is, in effect, disabled on the column.
345 * Also required: a grab_focus whenever the column header is
346 * clicked to change the column sort order since the click
347 * also changes the focus to the column header button.
348 * Is there a better way to do this ?
351 /* hide the Save button if the user uses implicit save */
352 if(!prefs.gui_use_pref_save) {
353 gtk_widget_hide(save_bt);
356 return proto_vb;
360 void
361 proto_cb(GtkWidget *w _U_, gpointer data _U_)
364 GtkWidget *main_vb, *main_nb, *page_lb, *protocols_page;
365 #if defined(HEUR_DISSECTOR_LIST)
366 GtkWidget *heur_dissectors_page;
367 #endif
368 if (proto_w != NULL) {
369 reactivate_window(proto_w);
370 return;
373 proto_w = dlg_conf_window_new("Wireshark: Enabled Protocols");
374 gtk_window_set_default_size(GTK_WINDOW(proto_w), DEF_WIDTH , DEF_HEIGHT);
376 /* Container for each row of widgets */
378 main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 6, FALSE);
379 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 6);
380 gtk_container_add(GTK_CONTAINER(proto_w), main_vb);
381 gtk_widget_show(main_vb);
383 main_nb = gtk_notebook_new();
384 gtk_box_pack_start(GTK_BOX(main_vb), main_nb, TRUE, TRUE, 0);
387 /* Protocol selection tab ("enable/disable" protocols) */
388 page_lb = gtk_label_new("Enabled Protocols");
389 protocols_page = build_protocols_treeview();
390 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), protocols_page, page_lb);
392 #if defined(HEUR_DISSECTOR_LIST)
393 page_lb = gtk_label_new("Enabled Heuristic dissectors");
394 heur_dissectors_page = build_heur_dissectors_treeview();
395 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), heur_dissectors_page, page_lb);
396 #endif
397 gtk_widget_show_all(proto_w);
398 window_present(proto_w);
399 } /* proto_cb */
401 /* protocol list column header clicked (to change sort) */
402 /* grab_focus(treeview) req'd so that type-ahead find works. */
403 /* (See comment above). */
404 static void
405 proto_col_clicked_cb(GtkWidget *col _U_, GtkWidget *proto_list) {
406 gtk_widget_grab_focus(proto_list);
409 /* Status toggled */
410 static void
411 status_toggled(GtkCellRendererToggle *cell _U_, gchar *path_str, gpointer data)
413 GtkTreeModel *model = (GtkTreeModel *)data;
414 GtkTreeIter iter;
415 GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
416 protocol_data_t *p;
418 gtk_tree_model_get_iter(model, &iter, path);
419 gtk_tree_model_get(model, &iter, 3, &p, -1);
421 if (p->enabled)
422 p->enabled = FALSE;
423 else
424 p->enabled = TRUE;
426 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, p->enabled, -1);
428 gtk_tree_path_free(path);
429 } /* status toggled */
431 /* XXX - We need callbacks for Gtk2 */
433 /* Toggle All */
434 static void
435 toggle_all_cb(GtkWidget *button _U_, gpointer pl)
437 GSList *entry;
438 GtkListStore *s = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pl)));
440 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
441 protocol_data_t *p = (protocol_data_t *)entry->data;
443 if (p->enabled)
444 p->enabled = FALSE;
445 else
446 p->enabled = TRUE;
448 gtk_list_store_set(s, &p->iter, 0, p->enabled, -1);
452 /* Enable/Disable All Helper */
453 static void
454 set_active_all(GtkWidget *w, gboolean new_state)
456 GtkListStore *s = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(w)));
457 GSList *entry;
459 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
460 protocol_data_t *p = (protocol_data_t *)entry->data;
462 p->enabled = new_state;
463 gtk_list_store_set(s, &p->iter, 0, new_state, -1);
467 /* Enable All */
468 static void
469 enable_all_cb(GtkWidget *button _U_, gpointer pl)
471 set_active_all((GtkWidget *)pl, TRUE);
474 /* Disable All */
475 static void
476 disable_all_cb(GtkWidget *button _U_, gpointer pl)
478 set_active_all((GtkWidget *)pl, FALSE);
481 static void
482 proto_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
484 GSList *entry;
486 proto_w = NULL;
487 /* remove protocol list */
488 if (protocol_list) {
489 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
490 g_free(entry->data);
492 g_slist_free(protocol_list);
493 protocol_list = NULL;
497 #if defined(HEUR_DISSECTOR_LIST)
498 static void
499 heur_proto_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
501 GSList *entry;
503 proto_w = NULL;
504 /* remove protocol list */
505 if (heur_protocol_list) {
506 for (entry = heur_protocol_list; entry != NULL; entry = g_slist_next(entry)) {
507 g_free(entry->data);
509 g_slist_free(heur_protocol_list);
510 heur_protocol_list = NULL;
513 #endif
515 /* Treat this as a cancel, by calling "proto_cancel_cb()".
516 XXX - that'll destroy the Protocols dialog; will that upset
517 a higher-level handler that says "OK, we've been asked to delete
518 this, so destroy it"? */
519 static gboolean
520 proto_delete_event_cb(GtkWidget *proto_w_lcl, GdkEvent *event _U_,
521 gpointer dummy _U_)
523 proto_cancel_cb(NULL, proto_w_lcl);
524 return FALSE;
527 /* Update protocol_list 'was_enabled' to current value of 'enabled' */
528 static void
529 update_was_enabled(void)
531 GSList *entry;
533 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
534 protocol_data_t *p = (protocol_data_t *)entry->data;
535 p->was_enabled = p->enabled;
539 static void
540 proto_write(gpointer parent_w _U_)
542 char *pf_dir_path;
543 char *pf_path;
544 int pf_save_errno;
546 /* Create the directory that holds personal configuration files, if
547 necessary. */
548 if (create_persconffile_dir(&pf_dir_path) == -1) {
549 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
550 "Can't create directory\n\"%s\"\nfor disabled protocols file: %s.", pf_dir_path,
551 g_strerror(errno));
552 g_free(pf_dir_path);
553 } else {
554 save_disabled_protos_list(&pf_path, &pf_save_errno);
555 if (pf_path != NULL) {
556 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
557 "Could not save to your disabled protocols file\n\"%s\": %s.",
558 pf_path, g_strerror(pf_save_errno));
559 g_free(pf_path);
564 static void
565 proto_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
567 gboolean redissect;
569 /* update the selection now, so we'll save the right things */
570 redissect = set_proto_selection(GTK_WIDGET(parent_w));
572 /* if we don't have a Save button, just save the settings now */
573 if (!prefs.gui_use_pref_save) {
574 proto_write(parent_w);
577 window_destroy(GTK_WIDGET(parent_w));
578 if (redissect)
579 redissect_packets();
582 static void
583 proto_apply_cb(GtkWidget *apply_bt _U_, gpointer parent_w)
585 gboolean redissect;
587 /* update the selection now, so we'll save the right things */
588 redissect = set_proto_selection(GTK_WIDGET(parent_w));
590 /* if we don't have a Save button, just save the settings now */
591 if (!prefs.gui_use_pref_save) {
592 proto_write(parent_w);
593 update_was_enabled();
596 if (redissect)
597 redissect_packets();
600 static void
601 proto_save_cb(GtkWidget *save_bt _U_, gpointer parent_w)
604 proto_write(parent_w);
606 if (set_proto_selection(GTK_WIDGET(parent_w))) {
607 /* Redissect all the packets, and re-evaluate the display filter. */
608 redissect_packets();
612 static void
613 proto_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
615 gboolean redissect;
617 redissect = revert_proto_selection();
618 window_destroy(GTK_WIDGET(parent_w));
619 if (redissect)
620 redissect_packets();
623 static gboolean
624 set_proto_selection(GtkWidget *parent_w _U_)
626 GSList *entry;
627 gboolean need_redissect = FALSE;
629 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
630 protocol_data_t *p = (protocol_data_t *)entry->data;
631 protocol_t *protocol;
633 protocol = find_protocol_by_id(p->hfinfo_index);
634 if (proto_is_protocol_enabled(protocol) != p->enabled) {
635 proto_set_decoding(p->hfinfo_index, p->enabled);
636 need_redissect = TRUE;
640 return need_redissect;
642 } /* set_proto_selection */
644 static gboolean
645 revert_proto_selection(void)
647 GSList *entry;
648 gboolean need_redissect = FALSE;
651 * Undo all the changes we've made to protocol enable flags.
653 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
654 protocol_data_t *p = (protocol_data_t *)entry->data;
655 protocol_t *protocol;
657 protocol = find_protocol_by_id(p->hfinfo_index);
658 if (proto_is_protocol_enabled(protocol) != p->was_enabled) {
659 proto_set_decoding(p->hfinfo_index, p->was_enabled);
660 need_redissect = TRUE;
664 return need_redissect;
666 } /* revert_proto_selection */
668 static gint
669 protocol_data_compare(gconstpointer a, gconstpointer b)
671 const protocol_data_t *ap = (const protocol_data_t *)a;
672 const protocol_data_t *bp = (const protocol_data_t *)b;
674 return strcmp(ap->abbrev, bp->abbrev);
677 static void
678 create_protocol_list(void)
680 gint i;
681 void *cookie;
682 protocol_t *protocol;
683 protocol_data_t *p;
685 /* Iterate over all the protocols */
687 for (i = proto_get_first_protocol(&cookie); i != -1;
688 i = proto_get_next_protocol(&cookie)) {
689 if (proto_can_toggle_protocol(i)) {
690 p = (protocol_data_t *)g_malloc(sizeof(protocol_data_t));
691 protocol = find_protocol_by_id(i);
692 p->name = proto_get_protocol_name(i);
693 p->abbrev = proto_get_protocol_short_name(protocol);
694 p->hfinfo_index = i;
695 p->enabled = proto_is_protocol_enabled(protocol);
696 p->was_enabled = p->enabled;
697 protocol_list = g_slist_insert_sorted(protocol_list,
698 p, protocol_data_compare);
702 #if defined(HEUR_DISSECTOR_LIST)
703 static void
704 get_heur_dissector(gpointer data, gpointer user_data)
706 protocol_data_t *p;
707 const char *table_name = user_data;
708 heur_dtbl_entry_t *dtbl_entry = data;
709 int proto_id;
711 if(dtbl_entry){
712 p = g_malloc(sizeof(protocol_data_t));
713 proto_id = proto_get_id(dtbl_entry->protocol);
715 p->name = proto_get_protocol_name(proto_id);
716 p->abbrev = g_strdup_printf("%s(%s)",proto_get_protocol_short_name(dtbl_entry->protocol),table_name);
717 p->hfinfo_index = proto_id;
718 if(!proto_is_protocol_enabled(dtbl_entry->protocol)){
719 p->enabled = FALSE;
720 }else {
721 p->enabled = dtbl_entry->enabled;
723 p->was_enabled = p->enabled;
724 heur_protocol_list = g_slist_insert_sorted(heur_protocol_list,
725 p, protocol_data_compare);
729 static void
730 get_heur_dissector_tables(const char *table_name, gpointer table, gpointer w _U_)
732 heur_dissector_list_t *list = table;
734 if(list){
735 g_slist_foreach (*list, get_heur_dissector, (gpointer)table_name);
739 #endif
741 #if defined(HEUR_DISSECTOR_LIST)
742 static void
743 create_heur_protocol_list(void)
745 dissector_all_heur_tables_foreach_table(get_heur_dissector_tables, NULL);
747 gint i;
748 void *cookie;
749 protocol_t *protocol;
750 protocol_data_t *p;
752 /* Iterate over all the protocols */
754 for (i = proto_get_first_protocol(&cookie); i != -1;
755 i = proto_get_next_protocol(&cookie)) {
756 if (proto_can_toggle_protocol(i)) {
757 p = g_malloc(sizeof(protocol_data_t));
758 protocol = find_protocol_by_id(i);
759 p->name = proto_get_protocol_name(i);
760 p->abbrev = proto_get_protocol_short_name(protocol);
761 p->hfinfo_index = i;
762 p->enabled = proto_is_protocol_enabled(protocol);
763 p->was_enabled = p->enabled;
764 protocol_list = g_slist_insert_sorted(protocol_list,
765 p, protocol_data_compare);
769 #endif
771 static void
772 show_proto_selection(GtkListStore *proto_store)
774 GSList *entry;
775 protocol_data_t *p;
777 if (protocol_list == NULL)
778 create_protocol_list();
780 for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
781 p = (protocol_data_t *)entry->data;
783 gtk_list_store_append(proto_store, &p->iter);
784 gtk_list_store_set(proto_store, &p->iter,
785 0, p->enabled,
786 1, p->abbrev,
787 2, p->name,
788 3, p,
789 -1);
792 } /* show_proto_selection */
794 #if defined(HEUR_DISSECTOR_LIST)
795 static void
796 show_heur_selection(GtkListStore *proto_store)
798 GSList *entry;
799 protocol_data_t *p;
801 if (heur_protocol_list == NULL)
802 create_heur_protocol_list();
804 for (entry = heur_protocol_list; entry != NULL; entry = g_slist_next(entry)) {
805 p = entry->data;
807 gtk_list_store_append(proto_store, &p->iter);
808 gtk_list_store_set(proto_store, &p->iter,
809 0, p->enabled,
810 1, p->abbrev,
811 2, p->name,
812 3, p,
813 -1);
816 } /* show_proto_selection */
817 #endif
819 static void
820 proto_disable_dialog_cb(gpointer dialog _U_, gint btn, gpointer data)
822 protocol_t *protocol;
823 gint id = GPOINTER_TO_INT(data);
825 if (btn == ESD_BTN_OK) {
826 /* Allow proto_dlg to work with the original settings */
827 if (protocol_list == NULL)
828 create_protocol_list();
829 /* Toggle the protocol if it's enabled and allowed */
830 protocol = find_protocol_by_id(id);
831 if (proto_is_protocol_enabled(protocol) == TRUE) {
832 if (proto_can_toggle_protocol(id) == TRUE) {
833 proto_set_decoding(id, FALSE);
834 redissect_packets();
840 void
841 proto_disable_cb(GtkWidget *w _U_, gpointer data _U_)
843 header_field_info *hfinfo;
844 gint id;
845 gpointer dialog;
847 if (cfile.finfo_selected == NULL) {
848 /* There is no field selected */
849 return;
852 /* Find the id for the protocol for the selected field. */
853 hfinfo = cfile.finfo_selected->hfinfo;
854 if (hfinfo->parent == -1)
855 id = proto_get_id((protocol_t *)hfinfo->strings);
856 else
857 id = hfinfo->parent;
859 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
860 "Do you want to temporarily disable protocol: %s ?",
861 proto_registrar_get_abbrev(id));
863 simple_dialog_set_cb(dialog, proto_disable_dialog_cb, GINT_TO_POINTER(id));