1 /* supported_protos_dlg.c
3 * Laurent Deniel <laurent.deniel@free.fr>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 2000 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/proto.h>
31 #include <epan/prefs.h>
33 #include "ui/gtk/supported_protos_dlg.h"
34 #include "ui/gtk/gui_utils.h"
35 #include "ui/gtk/dlg_utils.h"
36 #include "ui/gtk/font_utils.h"
38 static const char *proto_supported =
39 "The following %d protocols (and packet types) are currently\n"
40 "supported by Wireshark:\n\n";
42 static const char *dfilter_supported =
43 "The following per-protocol fields are currently supported by\n"
44 "Wireshark and can be used in display filters:\n";
53 static void supported_destroy_cb(GtkWidget *w, gpointer data);
54 static void insert_text(GtkWidget *w, const char *buffer, int nchars);
55 static void set_supported_text(GtkWidget *w, supported_type_t type);
58 * Keep a static pointer to the current "Supported" window, if any, so that
59 * if somebody tries to do "Help->Supported" while there's already a
60 * "Supported" window up, we just pop up the existing one, rather than
63 static GtkWidget *supported_w = NULL;
66 * Keep static pointers to the text widgets as well (for text format changes).
68 static GtkWidget *proto_text, *dfilter_text;
72 void supported_cb(GtkWidget *w _U_, gpointer data _U_)
75 GtkWidget *main_vb, *bbox, *supported_nb, *ok_bt, *label, *txt_scrollw,
79 if (supported_w != NULL) {
80 /* There's already a "Supported" dialog box; reactivate it. */
81 reactivate_window(supported_w);
85 supported_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Supported Protocols");
86 gtk_window_set_default_size(GTK_WINDOW(supported_w), DEF_WIDTH * 2/3, DEF_HEIGHT * 2/3);
87 gtk_container_set_border_width(GTK_CONTAINER(supported_w), 2);
89 /* Container for each row of widgets */
90 main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);
91 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 1);
92 gtk_container_add(GTK_CONTAINER(supported_w), main_vb);
93 gtk_widget_show(main_vb);
95 /* supported topics container */
96 supported_nb = gtk_notebook_new();
97 gtk_box_pack_start(GTK_BOX(main_vb), supported_nb, TRUE, TRUE, 0);
101 proto_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
102 gtk_container_set_border_width(GTK_CONTAINER(proto_vb), 1);
104 txt_scrollw = scrolled_window_new(NULL, NULL);
105 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
107 gtk_box_pack_start(GTK_BOX(proto_vb), txt_scrollw, TRUE, TRUE, 0);
108 proto_text = gtk_text_view_new();
109 gtk_text_view_set_editable(GTK_TEXT_VIEW(proto_text), FALSE);
110 set_supported_text(proto_text, PROTOCOL_SUPPORTED);
111 gtk_container_add(GTK_CONTAINER(txt_scrollw), proto_text);
112 gtk_widget_show(txt_scrollw);
113 gtk_widget_show(proto_text);
114 gtk_widget_show(proto_vb);
115 label = gtk_label_new("Protocols");
116 gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), proto_vb, label);
118 /* display filter fields */
119 dfilter_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
120 gtk_container_set_border_width(GTK_CONTAINER(dfilter_vb), 1);
122 txt_scrollw = scrolled_window_new(NULL, NULL);
123 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
125 gtk_box_pack_start(GTK_BOX(dfilter_vb), txt_scrollw, TRUE, TRUE, 0);
126 dfilter_text = gtk_text_view_new();
127 gtk_text_view_set_editable(GTK_TEXT_VIEW(dfilter_text), FALSE);
128 set_supported_text(dfilter_text, DFILTER_SUPPORTED);
129 gtk_container_add(GTK_CONTAINER(txt_scrollw), dfilter_text);
130 gtk_widget_show(txt_scrollw);
131 gtk_widget_show(dfilter_text);
132 gtk_widget_show(dfilter_vb);
133 label = gtk_label_new("Display Filter Fields");
134 gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), dfilter_vb, label);
136 /* XXX add other panels here ... */
138 gtk_widget_show(supported_nb);
141 bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
142 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
143 gtk_widget_show(bbox);
145 ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
146 window_set_cancel_button(supported_w, ok_bt, window_cancel_button_cb);
148 g_signal_connect(supported_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
149 g_signal_connect(supported_w, "destroy", G_CALLBACK(supported_destroy_cb), NULL);
151 gtk_widget_show(supported_w);
152 window_present(supported_w);
155 static void supported_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
157 /* Note that we no longer have a Help window. */
161 static void insert_text(GtkWidget *w, const char *buffer, int nchars)
163 GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
166 gtk_text_buffer_get_end_iter(buf, &iter);
167 #if GTK_CHECK_VERSION(3,0,0)
168 gtk_widget_override_font(w, user_font_get_regular());
170 gtk_widget_modify_font(w, user_font_get_regular());
172 if (!g_utf8_validate(buffer, -1, NULL))
173 printf("Invalid utf8 encoding: %s\n", buffer); /* ToDo: Don't use printf ?? */
174 gtk_text_buffer_insert(buf, &iter, buffer, nchars);
178 static void set_supported_text(GtkWidget *w, supported_type_t type)
181 #define BUFF_LEN 4096
183 char buffer[BUFF_LEN];
184 header_field_info *hfinfo;
185 int i, len, maxlen = 0, maxlen2 = 0, maxlen4 = 0;
186 const char *type_name;
187 void *cookie, *cookie2;
188 protocol_t *protocol;
189 const char *name, *short_name, *filter_name;
190 int namel = 0, short_namel = 0, filter_namel = 0;
196 * the width and height computations are performed to make the
197 * horizontal scrollbar work in gtk1.2. This is only necessary for the
198 * PROTOCOL_SUPPORTED and DFILTER_SUPPORTED windows since all others should
199 * not have any horizontal scrollbar (line wrapping enabled).
205 case PROTOCOL_SUPPORTED :
206 /* first pass to know the maximum length of first field */
208 for (i = proto_get_first_protocol(&cookie); i != -1;
209 i = proto_get_next_protocol(&cookie)) {
211 protocol = find_protocol_by_id(i);
212 name = proto_get_protocol_name(i);
213 short_name = proto_get_protocol_short_name(protocol);
214 filter_name = proto_get_protocol_filter_name(i);
215 if ((len = (int) strlen(name)) > namel)
217 if ((len = (int) strlen(short_name)) > short_namel)
219 if ((len = (int) strlen(filter_name)) > filter_namel)
223 len = g_snprintf(buffer, BUFF_LEN, proto_supported, count);
224 insert_text(w, buffer, len);
226 /* ok, display the correctly aligned strings */
227 for (i = proto_get_first_protocol(&cookie); i != -1;
228 i = proto_get_next_protocol(&cookie)) {
229 protocol = find_protocol_by_id(i);
230 name = proto_get_protocol_name(i);
231 short_name = proto_get_protocol_short_name(protocol);
232 filter_name = proto_get_protocol_filter_name(i);
234 /* the name used for sorting in the left column */
235 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s\n",
236 -short_namel, short_name,
238 -filter_namel, filter_name);
239 insert_text(w, buffer, len);
244 case DFILTER_SUPPORTED :
246 /* XXX we should display hinfo->blurb instead of name (if not empty) */
248 /* first pass to know the maximum length of first and second fields */
249 for (i = proto_get_first_protocol(&cookie); i != -1;
250 i = proto_get_next_protocol(&cookie)) {
252 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
253 hfinfo = proto_get_next_protocol_field(i, &cookie2)) {
255 if (hfinfo->same_name_prev_id != -1) /* ignore duplicate names */
258 if ((len = (int) strlen(hfinfo->abbrev)) > maxlen)
260 if ((len = (int) strlen(hfinfo->name)) > maxlen2)
262 if (hfinfo->blurb != NULL) {
263 if ((len = (int) strlen(hfinfo->blurb)) > maxlen4)
269 insert_text(w, dfilter_supported, (int) strlen(dfilter_supported));
272 for (i = proto_get_first_protocol(&cookie); i != -1;
273 i = proto_get_next_protocol(&cookie)) {
274 protocol = find_protocol_by_id(i);
275 name = proto_get_protocol_name(i);
276 short_name = proto_get_protocol_short_name(protocol);
277 filter_name = proto_get_protocol_filter_name(i);
280 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
281 hfinfo = proto_get_next_protocol_field(i, &cookie2)) {
283 if (hfinfo->same_name_prev_id != -1) /* ignore duplicate names */
289 len = g_snprintf(buffer, BUFF_LEN, "\n%s - %s (%s) [%d fields]:\n",
290 short_name, name, filter_name, count);
291 insert_text(w, buffer, len);
293 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
294 hfinfo = proto_get_next_protocol_field(i, &cookie2)) {
296 if (hfinfo->same_name_prev_id != -1) /* ignore duplicate names */
299 type_name = ftype_pretty_name(hfinfo->type);
300 if (hfinfo->blurb != NULL && hfinfo->blurb[0] != '\0') {
301 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s (%s)\n",
302 -maxlen, hfinfo->abbrev,
303 -maxlen2, hfinfo->name,
304 -maxlen4, hfinfo->blurb,
307 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s (%s)\n",
308 -maxlen, hfinfo->abbrev,
309 -maxlen2, hfinfo->name,
312 insert_text(w, buffer, len);
315 len = g_snprintf(buffer, BUFF_LEN, "\n-- Total %d fields\n", fcount);
316 insert_text(w, buffer, len);
320 g_assert_not_reached();
323 } /* set_supported_text */
326 static void clear_supported_text(GtkWidget *w)
328 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
330 gtk_text_buffer_set_text(buf, "", 0);
334 /* Redraw all the text widgets, to use a new font. */
335 void supported_redraw(void)
337 if (supported_w != NULL) {
338 clear_supported_text(proto_text);
339 set_supported_text(proto_text, PROTOCOL_SUPPORTED);
340 clear_supported_text(dfilter_text);
341 set_supported_text(dfilter_text, DFILTER_SUPPORTED);
346 * Editor modelines - http://www.wireshark.org/tools/modelines.html
351 * indent-tabs-mode: nil
354 * vi: set shiftwidth=2 tabstop=8 expandtab:
355 * :indentSize=2:tabSize=8:noTabs=true: