2 * Dialog for exporting PDUs to file
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <wiretap/pcap-encap.h>
30 #include <epan/exported_pdu.h>
33 #include "ui/gtk/old-gtk-compat.h"
34 #include "ui/gtk/capture_file_dlg.h"
35 #include "ui/gtk/dlg_utils.h"
36 #include "ui/gtk/gui_utils.h"
37 #include "ui/gtk/filter_dlg.h"
38 #include "ui/gtk/gtkglobals.h"
39 #include "ui/gtk/filter_autocomplete.h"
40 #include "ui/gtk/stock_icons.h"
43 #include "ui/tap_export_pdu.h"
44 #include "ui/gtk/export_pdu_dlg.h"
46 static GtkWidget *export_pdu_dlg = NULL;
49 typedef struct _exp_pdu_dlg_t {
50 GtkWidget *filter_widget;
51 GtkWidget *tap_name_widget;
52 exp_pdu_t exp_pdu_tap_data;
57 export_pdu_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
59 /* Note that we no longer have a export_pdu dialog box. */
60 export_pdu_dlg = NULL;
64 export_pdu_action(gpointer data)
66 const char *filter = NULL;
67 exp_pdu_dlg_t *exp_pdu_dlg_data = (exp_pdu_dlg_t *)data;
68 gchar *tap_name = NULL;
70 filter = gtk_entry_get_text(GTK_ENTRY(exp_pdu_dlg_data->filter_widget));
71 tap_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(exp_pdu_dlg_data->tap_name_widget));
73 do_export_pdu(filter, tap_name, &(exp_pdu_dlg_data->exp_pdu_tap_data));
74 window_destroy(export_pdu_dlg);
75 g_free(exp_pdu_dlg_data);
80 export_pdu_show_cb(GtkWidget *w _U_, gpointer d _U_)
83 GtkWidget *main_vb, *bbox, *close_bt, *ok_bt;
84 GtkWidget *grid, *filter_bt;
85 exp_pdu_dlg_t *exp_pdu_dlg_data;
86 const char *filter = NULL;
88 GSList *tap_name_list;
90 static construct_args_t args = {
91 "Wireshark: Export PDUs Filter",
92 TRUE, /* dialog should have an Apply button */
93 FALSE, /* if parent text widget should be activated on "Ok" or "Apply" */
94 FALSE /* dialog is modal and transient to the parent window */
97 if (export_pdu_dlg != NULL) {
98 /* There's already a export_pdu dialog box; reactivate it. */
99 reactivate_window(export_pdu_dlg);
103 exp_pdu_dlg_data = (exp_pdu_dlg_t *)g_malloc(sizeof(exp_pdu_dlg_t));
104 exp_pdu_dlg_data->exp_pdu_tap_data.pkt_encap = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
106 export_pdu_dlg = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Export PDUs to pcap-ng file");
108 g_signal_connect(export_pdu_dlg, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
109 g_signal_connect(export_pdu_dlg, "destroy", G_CALLBACK(export_pdu_destroy_cb), NULL);
111 main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
112 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
113 gtk_container_add(GTK_CONTAINER(export_pdu_dlg), main_vb);
116 grid = ws_gtk_grid_new();
117 ws_gtk_grid_set_column_spacing(GTK_GRID(grid), 6);
118 ws_gtk_grid_set_row_spacing(GTK_GRID(grid), 3);
119 gtk_box_pack_start(GTK_BOX(main_vb), grid, TRUE, TRUE, 0);
123 filter_bt=ws_gtk_button_new_from_stock(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
124 g_signal_connect(filter_bt, "clicked", G_CALLBACK(display_filter_construct_cb), &args);
125 ws_gtk_grid_attach_defaults(GTK_GRID(grid), filter_bt, 0, row, 1, 1);
126 gtk_widget_show(filter_bt);
129 exp_pdu_dlg_data->filter_widget=gtk_entry_new();
130 g_signal_connect(exp_pdu_dlg_data->filter_widget, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
131 g_object_set_data(G_OBJECT(grid), E_FILT_AUTOCOMP_PTR_KEY, NULL);
132 g_signal_connect(exp_pdu_dlg_data->filter_widget, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
133 g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, exp_pdu_dlg_data->filter_widget);
135 filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
137 gtk_entry_set_text(GTK_ENTRY(exp_pdu_dlg_data->filter_widget), filter);
139 colorize_filter_te_as_empty(exp_pdu_dlg_data->filter_widget);
142 ws_gtk_grid_attach_defaults(GTK_GRID(grid), exp_pdu_dlg_data->filter_widget, 1, row, 1, 1);
143 gtk_widget_show(exp_pdu_dlg_data->filter_widget);
146 /* Select which tap to run */
148 exp_pdu_dlg_data->tap_name_widget = gtk_combo_box_text_new();
149 for (tap_name_list = get_export_pdu_tap_list(); tap_name_list; tap_name_list = g_slist_next(tap_name_list)) {
150 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(exp_pdu_dlg_data->tap_name_widget), (const char*)(tap_name_list->data));
152 gtk_combo_box_set_active(GTK_COMBO_BOX(exp_pdu_dlg_data->tap_name_widget), 0);
154 ws_gtk_grid_attach_defaults(GTK_GRID(grid), exp_pdu_dlg_data->tap_name_widget, 0, row, 1, 1);
155 gtk_widget_show(exp_pdu_dlg_data->tap_name_widget);
157 /* Setup the button row */
159 bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
160 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
162 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
163 window_set_cancel_button(export_pdu_dlg, close_bt, window_cancel_button_cb);
164 gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
166 ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
167 g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_export_pdu_ok_cb), exp_pdu_dlg_data);
168 gtk_widget_grab_default(ok_bt);
169 gtk_widget_set_tooltip_text(ok_bt, "Export PDUs to a temporary capture file");
171 gtk_widget_show_all(export_pdu_dlg);
172 window_present(export_pdu_dlg);
182 * indent-tabs-mode: nil
185 * ex: set shiftwidth=4 tabstop=8 expandtab:
186 * :indentSize=4:tabSize=8:noTabs=true: