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.
30 #include <gdk/gdkkeysyms.h>
31 #if GTK_CHECK_VERSION(3,0,0)
32 # include <gdk/gdkkeysyms-compat.h>
35 #include <epan/prefs.h>
36 #include <epan/filesystem.h>
37 #include <epan/disabled_protos.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
);
59 static void show_proto_selection(GtkListStore
*proto_store
);
60 #if defined(HEUR_DISSECTOR_LIST)
61 static void show_heur_selection(GtkListStore
*proto_store
);
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
;
83 typedef struct protocol_data
{
92 #define DISABLED "Disabled"
93 #define STATUS_TXT(x) ((x) ? "" : DISABLED)
96 #if defined(HEUR_DISSECTOR_LIST)
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
;
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
),
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,
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
);
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
);
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
);
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
);
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
);
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
;
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
),
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,
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
);
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
);
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
);
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
);
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
);
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
;
368 if (proto_w
!= NULL
) {
369 reactivate_window(proto_w
);
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
);
397 gtk_widget_show_all(proto_w
);
398 window_present(proto_w
);
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). */
405 proto_col_clicked_cb(GtkWidget
*col _U_
, GtkWidget
*proto_list
) {
406 gtk_widget_grab_focus(proto_list
);
411 status_toggled(GtkCellRendererToggle
*cell _U_
, gchar
*path_str
, gpointer data
)
413 GtkTreeModel
*model
= (GtkTreeModel
*)data
;
415 GtkTreePath
*path
= gtk_tree_path_new_from_string(path_str
);
418 gtk_tree_model_get_iter(model
, &iter
, path
);
419 gtk_tree_model_get(model
, &iter
, 3, &p
, -1);
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 */
435 toggle_all_cb(GtkWidget
*button _U_
, gpointer pl
)
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
;
448 gtk_list_store_set(s
, &p
->iter
, 0, p
->enabled
, -1);
452 /* Enable/Disable All Helper */
454 set_active_all(GtkWidget
*w
, gboolean new_state
)
456 GtkListStore
*s
= GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(w
)));
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);
469 enable_all_cb(GtkWidget
*button _U_
, gpointer pl
)
471 set_active_all((GtkWidget
*)pl
, TRUE
);
476 disable_all_cb(GtkWidget
*button _U_
, gpointer pl
)
478 set_active_all((GtkWidget
*)pl
, FALSE
);
482 proto_destroy_cb(GtkWidget
*w _U_
, gpointer data _U_
)
487 /* remove protocol list */
489 for (entry
= protocol_list
; entry
!= NULL
; entry
= g_slist_next(entry
)) {
492 g_slist_free(protocol_list
);
493 protocol_list
= NULL
;
497 #if defined(HEUR_DISSECTOR_LIST)
499 heur_proto_destroy_cb(GtkWidget
*w _U_
, gpointer data _U_
)
504 /* remove protocol list */
505 if (heur_protocol_list
) {
506 for (entry
= heur_protocol_list
; entry
!= NULL
; entry
= g_slist_next(entry
)) {
509 g_slist_free(heur_protocol_list
);
510 heur_protocol_list
= NULL
;
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"? */
520 proto_delete_event_cb(GtkWidget
*proto_w_lcl
, GdkEvent
*event _U_
,
523 proto_cancel_cb(NULL
, proto_w_lcl
);
527 /* Update protocol_list 'was_enabled' to current value of 'enabled' */
529 update_was_enabled(void)
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
;
540 proto_write(gpointer parent_w _U_
)
546 /* Create the directory that holds personal configuration files, if
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
,
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
));
565 proto_ok_cb(GtkWidget
*ok_bt _U_
, gpointer parent_w
)
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
));
583 proto_apply_cb(GtkWidget
*apply_bt _U_
, gpointer parent_w
)
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();
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. */
613 proto_cancel_cb(GtkWidget
*cancel_bt _U_
, gpointer parent_w
)
617 redissect
= revert_proto_selection();
618 window_destroy(GTK_WIDGET(parent_w
));
624 set_proto_selection(GtkWidget
*parent_w _U_
)
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 */
645 revert_proto_selection(void)
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 */
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
);
678 create_protocol_list(void)
682 protocol_t
*protocol
;
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
);
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)
704 get_heur_dissector(gpointer data
, gpointer user_data
)
707 const char *table_name
= user_data
;
708 heur_dtbl_entry_t
*dtbl_entry
= data
;
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
)){
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
);
730 get_heur_dissector_tables(const char *table_name
, gpointer table
, gpointer w _U_
)
732 heur_dissector_list_t
*list
= table
;
735 g_slist_foreach (*list
, get_heur_dissector
, (gpointer
)table_name
);
741 #if defined(HEUR_DISSECTOR_LIST)
743 create_heur_protocol_list(void)
745 dissector_all_heur_tables_foreach_table(get_heur_dissector_tables
, NULL
);
749 protocol_t
*protocol
;
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
);
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
);
772 show_proto_selection(GtkListStore
*proto_store
)
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
,
792 } /* show_proto_selection */
794 #if defined(HEUR_DISSECTOR_LIST)
796 show_heur_selection(GtkListStore
*proto_store
)
801 if (heur_protocol_list
== NULL
)
802 create_heur_protocol_list();
804 for (entry
= heur_protocol_list
; entry
!= NULL
; entry
= g_slist_next(entry
)) {
807 gtk_list_store_append(proto_store
, &p
->iter
);
808 gtk_list_store_set(proto_store
, &p
->iter
,
816 } /* show_proto_selection */
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
);
841 proto_disable_cb(GtkWidget
*w _U_
, gpointer data _U_
)
843 header_field_info
*hfinfo
;
847 if (cfile
.finfo_selected
== NULL
) {
848 /* There is no field selected */
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
);
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
));