2003-11-18 23:56:45 +00:00
|
|
|
/* supported_protos_dlg.c
|
|
|
|
*
|
|
|
|
* Laurent Deniel <laurent.deniel@free.fr>
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2004-02-20 22:38:44 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2003-11-18 23:56:45 +00:00
|
|
|
* Copyright 2000 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2009-08-27 05:17:40 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-04-13 03:32:24 +00:00
|
|
|
#include <string.h>
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2008-04-13 03:32:24 +00:00
|
|
|
|
|
|
|
#include "../globals.h"
|
|
|
|
|
|
|
|
#include "gtk/supported_protos_dlg.h"
|
|
|
|
#include "gtk/gtkglobals.h"
|
|
|
|
#include "gtk/gui_utils.h"
|
|
|
|
#include "gtk/dlg_utils.h"
|
|
|
|
#include "gtk/font_utils.h"
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *proto_supported =
|
|
|
|
"The following %d protocols (and packet types) are currently\n"
|
2006-05-22 07:29:40 +00:00
|
|
|
"supported by Wireshark:\n\n";
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
static const char *dfilter_supported =
|
|
|
|
"The following per-protocol fields are currently supported by\n"
|
2006-05-22 07:29:40 +00:00
|
|
|
"Wireshark and can be used in display filters:\n";
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PROTOCOL_SUPPORTED,
|
2003-12-21 04:31:58 +00:00
|
|
|
DFILTER_SUPPORTED
|
2003-11-18 23:56:45 +00:00
|
|
|
} supported_type_t;
|
|
|
|
|
|
|
|
static void supported_destroy_cb(GtkWidget *w, gpointer data);
|
|
|
|
static void insert_text(GtkWidget *w, const char *buffer, int nchars);
|
|
|
|
static void set_supported_text(GtkWidget *w, supported_type_t type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Supported" window, if any, so that
|
|
|
|
* if somebody tries to do "Help->Supported" while there's already a
|
|
|
|
* "Supported" window up, we just pop up the existing one, rather than
|
|
|
|
* creating a new one.
|
|
|
|
*/
|
|
|
|
static GtkWidget *supported_w = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep static pointers to the text widgets as well (for text format changes).
|
|
|
|
*/
|
|
|
|
static GtkWidget *proto_text, *dfilter_text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void supported_cb(GtkWidget *w _U_, gpointer data _U_)
|
|
|
|
{
|
|
|
|
|
2004-01-21 21:19:34 +00:00
|
|
|
GtkWidget *main_vb, *bbox, *supported_nb, *ok_bt, *label, *txt_scrollw,
|
2003-11-18 23:56:45 +00:00
|
|
|
*proto_vb,
|
|
|
|
*dfilter_vb;
|
|
|
|
|
|
|
|
if (supported_w != NULL) {
|
|
|
|
/* There's already a "Supported" dialog box; reactivate it. */
|
|
|
|
reactivate_window(supported_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
supported_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Supported Protocols");
|
2004-05-23 23:24:07 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(supported_w), DEF_WIDTH * 2/3, DEF_HEIGHT * 2/3);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(supported_w), 2);
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
/* Container for each row of widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 1);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 1);
|
2003-11-18 23:56:45 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(supported_w), main_vb);
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
|
|
|
/* supported topics container */
|
|
|
|
supported_nb = gtk_notebook_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), supported_nb);
|
|
|
|
|
|
|
|
|
|
|
|
/* humm, gtk 1.2 does not support horizontal scrollbar for text widgets */
|
|
|
|
|
|
|
|
/* protocol list */
|
|
|
|
proto_vb = gtk_vbox_new(FALSE, 0);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(proto_vb), 1);
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
txt_scrollw = scrolled_window_new(NULL, NULL);
|
2004-02-06 19:19:12 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
|
|
|
|
GTK_SHADOW_IN);
|
2003-11-18 23:56:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(proto_vb), txt_scrollw, TRUE, TRUE, 0);
|
|
|
|
proto_text = gtk_text_view_new();
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(proto_text), FALSE);
|
|
|
|
set_supported_text(proto_text, PROTOCOL_SUPPORTED);
|
|
|
|
gtk_container_add(GTK_CONTAINER(txt_scrollw), proto_text);
|
|
|
|
gtk_widget_show(txt_scrollw);
|
|
|
|
gtk_widget_show(proto_text);
|
|
|
|
gtk_widget_show(proto_vb);
|
|
|
|
label = gtk_label_new("Protocols");
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), proto_vb, label);
|
|
|
|
|
|
|
|
/* display filter fields */
|
|
|
|
dfilter_vb = gtk_vbox_new(FALSE, 0);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(dfilter_vb), 1);
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
txt_scrollw = scrolled_window_new(NULL, NULL);
|
2004-02-06 19:19:12 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
|
|
|
|
GTK_SHADOW_IN);
|
2003-11-18 23:56:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(dfilter_vb), txt_scrollw, TRUE, TRUE, 0);
|
|
|
|
dfilter_text = gtk_text_view_new();
|
|
|
|
if (prefs.gui_scrollbar_on_right) {
|
|
|
|
gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
|
|
|
|
GTK_CORNER_TOP_LEFT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
|
|
|
|
GTK_CORNER_TOP_RIGHT);
|
|
|
|
}
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(dfilter_text), FALSE);
|
|
|
|
set_supported_text(dfilter_text, DFILTER_SUPPORTED);
|
|
|
|
gtk_container_add(GTK_CONTAINER(txt_scrollw), dfilter_text);
|
|
|
|
gtk_widget_show(txt_scrollw);
|
|
|
|
gtk_widget_show(dfilter_text);
|
|
|
|
gtk_widget_show(dfilter_vb);
|
|
|
|
label = gtk_label_new("Display Filter Fields");
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), dfilter_vb, label);
|
|
|
|
|
|
|
|
/* XXX add other panels here ... */
|
|
|
|
|
|
|
|
gtk_widget_show(supported_nb);
|
|
|
|
|
2004-01-21 21:19:34 +00:00
|
|
|
/* Button row */
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
|
2003-11-18 23:56:45 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(bbox);
|
2004-01-21 21:19:34 +00:00
|
|
|
|
2008-04-11 17:26:09 +00:00
|
|
|
ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
|
2004-05-23 23:24:07 +00:00
|
|
|
window_set_cancel_button(supported_w, ok_bt, window_cancel_button_cb);
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(supported_w));
|
2003-11-28 00:13:08 +00:00
|
|
|
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(supported_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
|
|
|
|
g_signal_connect(supported_w, "destroy", G_CALLBACK(supported_destroy_cb), NULL);
|
2003-11-28 00:13:08 +00:00
|
|
|
|
2003-11-18 23:56:45 +00:00
|
|
|
gtk_widget_show(supported_w);
|
2004-05-23 23:24:07 +00:00
|
|
|
window_present(supported_w);
|
2003-11-18 23:56:45 +00:00
|
|
|
} /* supported_cb */
|
|
|
|
|
|
|
|
static void supported_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
|
|
|
|
{
|
|
|
|
/* Note that we no longer have a Help window. */
|
|
|
|
supported_w = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void insert_text(GtkWidget *w, const char *buffer, int nchars)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
|
|
|
|
GtkTextIter iter;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter(buf, &iter);
|
2004-06-17 16:35:26 +00:00
|
|
|
gtk_widget_modify_font(w, user_font_get_regular());
|
2003-11-18 23:56:45 +00:00
|
|
|
if (!g_utf8_validate(buffer, -1, NULL))
|
2009-08-27 05:17:40 +00:00
|
|
|
printf("Invalid utf8 encoding: %s\n", buffer); /* ToDo: Don't use printf ?? */
|
2003-11-18 23:56:45 +00:00
|
|
|
gtk_text_buffer_insert(buf, &iter, buffer, nchars);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void set_supported_text(GtkWidget *w, supported_type_t type)
|
|
|
|
{
|
|
|
|
|
|
|
|
#define BUFF_LEN 4096
|
|
|
|
#define B_LEN 256
|
|
|
|
char buffer[BUFF_LEN];
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
int i, len, maxlen = 0, maxlen2 = 0, maxlen4 = 0;
|
|
|
|
const char *type_name;
|
|
|
|
void *cookie, *cookie2;
|
|
|
|
protocol_t *protocol;
|
2005-07-24 19:01:28 +00:00
|
|
|
const char *name, *short_name, *filter_name;
|
2003-11-18 23:56:45 +00:00
|
|
|
int namel = 0, short_namel = 0, filter_namel = 0;
|
|
|
|
int count, fcount;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX quick hack:
|
|
|
|
* the width and height computations are performed to make the
|
|
|
|
* horizontal scrollbar work in gtk1.2. This is only necessary for the
|
|
|
|
* PROTOCOL_SUPPORTED and DFILTER_SUPPORTED windows since all others should
|
|
|
|
* not have any horizontal scrollbar (line wrapping enabled).
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
|
|
|
|
case PROTOCOL_SUPPORTED :
|
|
|
|
/* first pass to know the maximum length of first field */
|
|
|
|
count = 0;
|
|
|
|
for (i = proto_get_first_protocol(&cookie); i != -1;
|
|
|
|
i = proto_get_next_protocol(&cookie)) {
|
|
|
|
count++;
|
2005-07-24 19:01:28 +00:00
|
|
|
protocol = find_protocol_by_id(i);
|
2003-11-18 23:56:45 +00:00
|
|
|
name = proto_get_protocol_name(i);
|
|
|
|
short_name = proto_get_protocol_short_name(protocol);
|
|
|
|
filter_name = proto_get_protocol_filter_name(i);
|
2009-04-16 03:18:10 +00:00
|
|
|
if ((len = (int) strlen(name)) > namel)
|
2003-11-18 23:56:45 +00:00
|
|
|
namel = len;
|
2009-04-16 03:18:10 +00:00
|
|
|
if ((len = (int) strlen(short_name)) > short_namel)
|
2003-11-18 23:56:45 +00:00
|
|
|
short_namel = len;
|
2009-04-16 03:18:10 +00:00
|
|
|
if ((len = (int) strlen(filter_name)) > filter_namel)
|
2003-11-18 23:56:45 +00:00
|
|
|
filter_namel = len;
|
|
|
|
}
|
|
|
|
|
2004-03-13 12:09:27 +00:00
|
|
|
len = g_snprintf(buffer, BUFF_LEN, proto_supported, count);
|
2003-11-18 23:56:45 +00:00
|
|
|
insert_text(w, buffer, len);
|
|
|
|
|
|
|
|
/* ok, display the correctly aligned strings */
|
|
|
|
for (i = proto_get_first_protocol(&cookie); i != -1;
|
|
|
|
i = proto_get_next_protocol(&cookie)) {
|
2005-07-24 19:01:28 +00:00
|
|
|
protocol = find_protocol_by_id(i);
|
2003-11-18 23:56:45 +00:00
|
|
|
name = proto_get_protocol_name(i);
|
|
|
|
short_name = proto_get_protocol_short_name(protocol);
|
|
|
|
filter_name = proto_get_protocol_filter_name(i);
|
|
|
|
|
|
|
|
/* the name used for sorting in the left column */
|
2004-03-13 12:09:27 +00:00
|
|
|
len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s\n",
|
2003-11-18 23:56:45 +00:00
|
|
|
-short_namel, short_name,
|
|
|
|
-namel, name,
|
|
|
|
-filter_namel, filter_name);
|
2009-11-10 12:05:25 +00:00
|
|
|
insert_text(w, buffer, len);
|
2003-11-18 23:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DFILTER_SUPPORTED :
|
|
|
|
|
|
|
|
/* XXX we should display hinfo->blurb instead of name (if not empty) */
|
|
|
|
|
|
|
|
/* first pass to know the maximum length of first and second fields */
|
|
|
|
for (i = proto_get_first_protocol(&cookie); i != -1;
|
|
|
|
i = proto_get_next_protocol(&cookie)) {
|
|
|
|
|
|
|
|
for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
|
|
|
|
hfinfo = proto_get_next_protocol_field(&cookie2)) {
|
|
|
|
|
|
|
|
if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
|
|
|
|
continue;
|
|
|
|
|
2009-04-16 03:18:10 +00:00
|
|
|
if ((len = (int) strlen(hfinfo->abbrev)) > maxlen)
|
2003-11-18 23:56:45 +00:00
|
|
|
maxlen = len;
|
2009-04-16 03:18:10 +00:00
|
|
|
if ((len = (int) strlen(hfinfo->name)) > maxlen2)
|
2003-11-18 23:56:45 +00:00
|
|
|
maxlen2 = len;
|
2005-12-04 04:22:43 +00:00
|
|
|
if (hfinfo->blurb != NULL) {
|
2009-04-16 03:18:10 +00:00
|
|
|
if ((len = (int) strlen(hfinfo->blurb)) > maxlen4)
|
2005-12-04 04:22:43 +00:00
|
|
|
maxlen4 = len;
|
|
|
|
}
|
2003-11-18 23:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:18:10 +00:00
|
|
|
insert_text(w, dfilter_supported, (int) strlen(dfilter_supported));
|
2003-11-18 23:56:45 +00:00
|
|
|
|
|
|
|
fcount = 0;
|
|
|
|
for (i = proto_get_first_protocol(&cookie); i != -1;
|
|
|
|
i = proto_get_next_protocol(&cookie)) {
|
2005-07-24 19:01:28 +00:00
|
|
|
protocol = find_protocol_by_id(i);
|
2003-11-18 23:56:45 +00:00
|
|
|
name = proto_get_protocol_name(i);
|
|
|
|
short_name = proto_get_protocol_short_name(protocol);
|
|
|
|
filter_name = proto_get_protocol_filter_name(i);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
|
|
|
|
hfinfo = proto_get_next_protocol_field(&cookie2)) {
|
|
|
|
|
|
|
|
if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
|
|
|
|
continue;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
fcount += count;
|
|
|
|
|
2004-03-13 12:09:27 +00:00
|
|
|
len = g_snprintf(buffer, BUFF_LEN, "\n%s - %s (%s) [%d fields]:\n",
|
2003-11-18 23:56:45 +00:00
|
|
|
short_name, name, filter_name, count);
|
|
|
|
insert_text(w, buffer, len);
|
|
|
|
|
|
|
|
for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
|
|
|
|
hfinfo = proto_get_next_protocol_field(&cookie2)) {
|
|
|
|
|
|
|
|
if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
type_name = ftype_pretty_name(hfinfo->type);
|
2005-12-04 04:22:43 +00:00
|
|
|
if (hfinfo->blurb != NULL && hfinfo->blurb[0] != '\0') {
|
|
|
|
len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s (%s)\n",
|
|
|
|
-maxlen, hfinfo->abbrev,
|
|
|
|
-maxlen2, hfinfo->name,
|
|
|
|
-maxlen4, hfinfo->blurb,
|
|
|
|
type_name);
|
|
|
|
} else {
|
|
|
|
len = g_snprintf(buffer, BUFF_LEN, "%*s %*s (%s)\n",
|
|
|
|
-maxlen, hfinfo->abbrev,
|
|
|
|
-maxlen2, hfinfo->name,
|
|
|
|
type_name);
|
|
|
|
}
|
2009-11-10 12:05:25 +00:00
|
|
|
insert_text(w, buffer, len);
|
2003-11-18 23:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-13 12:09:27 +00:00
|
|
|
len = g_snprintf(buffer, BUFF_LEN, "\n-- Total %d fields\n", fcount);
|
2003-11-18 23:56:45 +00:00
|
|
|
insert_text(w, buffer, len);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
g_assert_not_reached();
|
|
|
|
break;
|
|
|
|
} /* switch(type) */
|
|
|
|
} /* set_supported_text */
|
|
|
|
|
|
|
|
|
|
|
|
static void clear_supported_text(GtkWidget *w)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
|
|
|
|
|
|
|
|
gtk_text_buffer_set_text(buf, "", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Redraw all the text widgets, to use a new font. */
|
|
|
|
void supported_redraw(void)
|
|
|
|
{
|
|
|
|
if (supported_w != NULL) {
|
|
|
|
clear_supported_text(proto_text);
|
|
|
|
set_supported_text(proto_text, PROTOCOL_SUPPORTED);
|
|
|
|
clear_supported_text(dfilter_text);
|
|
|
|
set_supported_text(dfilter_text, DFILTER_SUPPORTED);
|
|
|
|
}
|
|
|
|
}
|