1 /* supported_protos_dlg.c
3 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/prefs.h>
37 #include "../globals.h"
39 #include "gtk/supported_protos_dlg.h"
40 #include "gtk/gtkglobals.h"
41 #include "gtk/gui_utils.h"
42 #include "gtk/dlg_utils.h"
43 #include "gtk/font_utils.h"
47 static const char *proto_supported =
48 "The following %d protocols (and packet types) are currently\n"
49 "supported by Wireshark:\n\n";
51 static const char *dfilter_supported =
52 "The following per-protocol fields are currently supported by\n"
53 "Wireshark and can be used in display filters:\n";
62 static void supported_destroy_cb(GtkWidget *w, gpointer data);
63 static void insert_text(GtkWidget *w, const char *buffer, int nchars);
64 static void set_supported_text(GtkWidget *w, supported_type_t type);
67 * Keep a static pointer to the current "Supported" window, if any, so that
68 * if somebody tries to do "Help->Supported" while there's already a
69 * "Supported" window up, we just pop up the existing one, rather than
72 static GtkWidget *supported_w = NULL;
75 * Keep static pointers to the text widgets as well (for text format changes).
77 static GtkWidget *proto_text, *dfilter_text;
81 void supported_cb(GtkWidget *w _U_, gpointer data _U_)
84 GtkWidget *main_vb, *bbox, *supported_nb, *ok_bt, *label, *txt_scrollw,
88 if (supported_w != NULL) {
89 /* There's already a "Supported" dialog box; reactivate it. */
90 reactivate_window(supported_w);
94 supported_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Supported Protocols");
95 gtk_window_set_default_size(GTK_WINDOW(supported_w), DEF_WIDTH * 2/3, DEF_HEIGHT * 2/3);
96 gtk_container_set_border_width(GTK_CONTAINER(supported_w), 2);
98 /* Container for each row of widgets */
99 main_vb = gtk_vbox_new(FALSE, 1);
100 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 1);
101 gtk_container_add(GTK_CONTAINER(supported_w), main_vb);
102 gtk_widget_show(main_vb);
104 /* supported topics container */
105 supported_nb = gtk_notebook_new();
106 gtk_container_add(GTK_CONTAINER(main_vb), supported_nb);
110 proto_vb = gtk_vbox_new(FALSE, 0);
111 gtk_container_set_border_width(GTK_CONTAINER(proto_vb), 1);
113 txt_scrollw = scrolled_window_new(NULL, NULL);
114 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
116 gtk_box_pack_start(GTK_BOX(proto_vb), txt_scrollw, TRUE, TRUE, 0);
117 proto_text = gtk_text_view_new();
118 gtk_text_view_set_editable(GTK_TEXT_VIEW(proto_text), FALSE);
119 set_supported_text(proto_text, PROTOCOL_SUPPORTED);
120 gtk_container_add(GTK_CONTAINER(txt_scrollw), proto_text);
121 gtk_widget_show(txt_scrollw);
122 gtk_widget_show(proto_text);
123 gtk_widget_show(proto_vb);
124 label = gtk_label_new("Protocols");
125 gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), proto_vb, label);
127 /* display filter fields */
128 dfilter_vb = gtk_vbox_new(FALSE, 0);
129 gtk_container_set_border_width(GTK_CONTAINER(dfilter_vb), 1);
131 txt_scrollw = scrolled_window_new(NULL, NULL);
132 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
134 gtk_box_pack_start(GTK_BOX(dfilter_vb), txt_scrollw, TRUE, TRUE, 0);
135 dfilter_text = gtk_text_view_new();
136 if (prefs.gui_scrollbar_on_right) {
137 gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
138 GTK_CORNER_TOP_LEFT);
141 gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
142 GTK_CORNER_TOP_RIGHT);
144 gtk_text_view_set_editable(GTK_TEXT_VIEW(dfilter_text), FALSE);
145 set_supported_text(dfilter_text, DFILTER_SUPPORTED);
146 gtk_container_add(GTK_CONTAINER(txt_scrollw), dfilter_text);
147 gtk_widget_show(txt_scrollw);
148 gtk_widget_show(dfilter_text);
149 gtk_widget_show(dfilter_vb);
150 label = gtk_label_new("Display Filter Fields");
151 gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), dfilter_vb, label);
153 /* XXX add other panels here ... */
155 gtk_widget_show(supported_nb);
158 bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
159 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
160 gtk_widget_show(bbox);
162 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
163 window_set_cancel_button(supported_w, ok_bt, window_cancel_button_cb);
165 g_signal_connect(supported_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
166 g_signal_connect(supported_w, "destroy", G_CALLBACK(supported_destroy_cb), NULL);
168 gtk_widget_show(supported_w);
169 window_present(supported_w);
172 static void supported_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
174 /* Note that we no longer have a Help window. */
178 static void insert_text(GtkWidget *w, const char *buffer, int nchars)
180 GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
183 gtk_text_buffer_get_end_iter(buf, &iter);
184 #if GTK_CHECK_VERSION(3,0,0)
185 gtk_widget_override_font(w, user_font_get_regular());
187 gtk_widget_modify_font(w, user_font_get_regular());
189 if (!g_utf8_validate(buffer, -1, NULL))
190 printf("Invalid utf8 encoding: %s\n", buffer); /* ToDo: Don't use printf ?? */
191 gtk_text_buffer_insert(buf, &iter, buffer, nchars);
195 static void set_supported_text(GtkWidget *w, supported_type_t type)
198 #define BUFF_LEN 4096
200 char buffer[BUFF_LEN];
201 header_field_info *hfinfo;
202 int i, len, maxlen = 0, maxlen2 = 0, maxlen4 = 0;
203 const char *type_name;
204 void *cookie, *cookie2;
205 protocol_t *protocol;
206 const char *name, *short_name, *filter_name;
207 int namel = 0, short_namel = 0, filter_namel = 0;
213 * the width and height computations are performed to make the
214 * horizontal scrollbar work in gtk1.2. This is only necessary for the
215 * PROTOCOL_SUPPORTED and DFILTER_SUPPORTED windows since all others should
216 * not have any horizontal scrollbar (line wrapping enabled).
222 case PROTOCOL_SUPPORTED :
223 /* first pass to know the maximum length of first field */
225 for (i = proto_get_first_protocol(&cookie); i != -1;
226 i = proto_get_next_protocol(&cookie)) {
228 protocol = find_protocol_by_id(i);
229 name = proto_get_protocol_name(i);
230 short_name = proto_get_protocol_short_name(protocol);
231 filter_name = proto_get_protocol_filter_name(i);
232 if ((len = (int) strlen(name)) > namel)
234 if ((len = (int) strlen(short_name)) > short_namel)
236 if ((len = (int) strlen(filter_name)) > filter_namel)
240 len = g_snprintf(buffer, BUFF_LEN, proto_supported, count);
241 insert_text(w, buffer, len);
243 /* ok, display the correctly aligned strings */
244 for (i = proto_get_first_protocol(&cookie); i != -1;
245 i = proto_get_next_protocol(&cookie)) {
246 protocol = find_protocol_by_id(i);
247 name = proto_get_protocol_name(i);
248 short_name = proto_get_protocol_short_name(protocol);
249 filter_name = proto_get_protocol_filter_name(i);
251 /* the name used for sorting in the left column */
252 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s\n",
253 -short_namel, short_name,
255 -filter_namel, filter_name);
256 insert_text(w, buffer, len);
261 case DFILTER_SUPPORTED :
263 /* XXX we should display hinfo->blurb instead of name (if not empty) */
265 /* first pass to know the maximum length of first and second fields */
266 for (i = proto_get_first_protocol(&cookie); i != -1;
267 i = proto_get_next_protocol(&cookie)) {
269 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
270 hfinfo = proto_get_next_protocol_field(&cookie2)) {
272 if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
275 if ((len = (int) strlen(hfinfo->abbrev)) > maxlen)
277 if ((len = (int) strlen(hfinfo->name)) > maxlen2)
279 if (hfinfo->blurb != NULL) {
280 if ((len = (int) strlen(hfinfo->blurb)) > maxlen4)
286 insert_text(w, dfilter_supported, (int) strlen(dfilter_supported));
289 for (i = proto_get_first_protocol(&cookie); i != -1;
290 i = proto_get_next_protocol(&cookie)) {
291 protocol = find_protocol_by_id(i);
292 name = proto_get_protocol_name(i);
293 short_name = proto_get_protocol_short_name(protocol);
294 filter_name = proto_get_protocol_filter_name(i);
297 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
298 hfinfo = proto_get_next_protocol_field(&cookie2)) {
300 if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
306 len = g_snprintf(buffer, BUFF_LEN, "\n%s - %s (%s) [%d fields]:\n",
307 short_name, name, filter_name, count);
308 insert_text(w, buffer, len);
310 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
311 hfinfo = proto_get_next_protocol_field(&cookie2)) {
313 if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
316 type_name = ftype_pretty_name(hfinfo->type);
317 if (hfinfo->blurb != NULL && hfinfo->blurb[0] != '\0') {
318 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s (%s)\n",
319 -maxlen, hfinfo->abbrev,
320 -maxlen2, hfinfo->name,
321 -maxlen4, hfinfo->blurb,
324 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s (%s)\n",
325 -maxlen, hfinfo->abbrev,
326 -maxlen2, hfinfo->name,
329 insert_text(w, buffer, len);
332 len = g_snprintf(buffer, BUFF_LEN, "\n-- Total %d fields\n", fcount);
333 insert_text(w, buffer, len);
337 g_assert_not_reached();
340 } /* set_supported_text */
343 static void clear_supported_text(GtkWidget *w)
345 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
347 gtk_text_buffer_set_text(buf, "", 0);
351 /* Redraw all the text widgets, to use a new font. */
352 void supported_redraw(void)
354 if (supported_w != NULL) {
355 clear_supported_text(proto_text);
356 set_supported_text(proto_text, PROTOCOL_SUPPORTED);
357 clear_supported_text(dfilter_text);
358 set_supported_text(dfilter_text, DFILTER_SUPPORTED);