Use the expert system to show packet comments.

The packet comment widget should be replaced by a ListView with two columns,  packet no and Comment.

svn path=/trunk/; revision=41322
This commit is contained in:
Anders Broman 2012-03-02 13:31:16 +00:00
parent 15a88e695f
commit ff47bdf96c
7 changed files with 76 additions and 42 deletions

View File

@ -122,7 +122,7 @@ call_frame_end_routine(gpointer routine, gpointer dummy _U_)
static void
dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
{
proto_item *volatile ti = NULL;
proto_item *volatile ti = NULL, *comment_item;
guint cap_len = 0, frame_len = 0;
proto_tree *volatile tree;
proto_tree *comments_tree;
@ -185,9 +185,12 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
if(pinfo->fd->opt_comment){
item = proto_tree_add_item(tree, proto_pkt_comment, tvb, 0, -1, ENC_NA);
comments_tree = proto_item_add_subtree(item, ett_comments);
proto_tree_add_string_format(comments_tree, hf_comments_text, tvb, 0, -1,
comment_item = proto_tree_add_string_format(comments_tree, hf_comments_text, tvb, 0, -1,
pinfo->fd->opt_comment, "%s",
pinfo->fd->opt_comment);
expert_add_info_format(pinfo, comment_item, PI_COMMENTS_GROUP, PI_COMMENT,
"%s", pinfo->fd->opt_comment);
}

View File

@ -60,6 +60,7 @@ const value_string expert_group_vals[] = {
{ PI_DEBUG, "Debug" },
{ PI_PROTOCOL, "Protocol" },
{ PI_SECURITY, "Security" },
{ PI_COMMENTS_GROUP, "Comment" },
{ 0, NULL }
};
@ -68,6 +69,7 @@ const value_string expert_severity_vals[] = {
{ PI_WARN, "Warn" },
{ PI_NOTE, "Note" },
{ PI_CHAT, "Chat" },
{ PI_COMMENT, "Comment" },
{ 0, "Ok" },
{ 0, NULL }
};

View File

@ -506,8 +506,10 @@ typedef proto_node proto_item;
#define PI_DEBUG 0x08000000
/** The protocol field violates a protocol specification, usually PI_WARN */
#define PI_PROTOCOL 0x09000000
/* The protocol field indicates a security probem (e.g. unsecure implementation) */
/** The protocol field indicates a security probem (e.g. unsecure implementation) */
#define PI_SECURITY 0x0a000000
/** The protocol field indicates a packet comment */
#define PI_COMMENTS_GROUP 0x0b000000
/* add more, see http://wiki.wireshark.org/Development/ExpertInfo */

View File

@ -70,15 +70,18 @@ enum
/* used to keep track of the statistics for an entire program interface */
typedef struct _expert_comp_dlg_t {
GtkWidget *win;
GtkWidget *pkt_comments_label;
GtkWidget *chat_label;
GtkWidget *note_label;
GtkWidget *warn_label;
GtkWidget *error_label;
GtkWidget *all_label;
error_equiv_table pkt_comments_table;
error_equiv_table chat_table;
error_equiv_table note_table;
error_equiv_table warn_table;
error_equiv_table error_table;
guint32 pkt_comments_events;
guint32 disp_events;
guint32 chat_events;
guint32 note_events;
@ -91,6 +94,7 @@ struct expert_tapdata_s {
GtkWidget *scrolled_window;
GtkTreeView *tree_view;
GtkWidget *label;
guint32 pkt_comments_events;
guint32 disp_events;
guint32 chat_events;
guint32 note_events;
@ -149,6 +153,7 @@ expert_dlg_reset(void *tapdata)
etd->note_events = 0;
etd->warn_events = 0;
etd->error_events = 0;
etd->pkt_comments_events = 0;
etd->last = 0;
etd->first = 0;
/* g_string_chunk_clear() is introduced in glib 2.14 */
@ -172,6 +177,9 @@ expert_dlg_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_
ei->summary = g_string_chunk_insert_const(etd->text, ei->summary);
switch(ei->severity) {
case(PI_COMMENT):
etd->pkt_comments_events++;
break;
case(PI_CHAT):
etd->chat_events++;
break;
@ -215,6 +223,7 @@ error_reset(void *pss)
ss->note_events = 0;
ss->chat_events = 0;
ss->disp_events = 0;
ss->pkt_comments_events = 0;
reset_error_table_data(&ss->error_table);
buf = g_strdup_printf("Errors: %u (0)", ss->error_table.num_procs);
@ -237,6 +246,11 @@ error_reset(void *pss)
g_free(buf);
gtk_label_set_text( GTK_LABEL(ss->all_label), "Details: 0");
reset_error_table_data(&ss->pkt_comments_table);
buf = g_strdup_printf("Packet Coments: %u (0)", ss->pkt_comments_table.num_procs);
gtk_label_set_text( GTK_LABEL(ss->pkt_comments_label), buf);
g_free(buf);
error_set_title(ss);
}
@ -272,6 +286,11 @@ error_packet(void *pss, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const v
ss->chat_events++;
init_error_table_row(&ss->chat_table, error_pkt);
break;
case PI_COMMENT:
ss->disp_events++; /* Count ? */
ss->pkt_comments_events++;
init_error_table_row(&ss->pkt_comments_table, error_pkt);
break;
default:
return FALSE; /* Don't draw */
}
@ -305,6 +324,10 @@ expert_comp_draw(void *data)
gtk_label_set_text( GTK_LABEL(ss->all_label), buf);
g_free(buf);
buf = g_strdup_printf("Packet Comments: %u (%u)", ss->pkt_comments_table.num_procs, ss->pkt_comments_events);
gtk_label_set_text( GTK_LABEL(ss->pkt_comments_label), buf);
g_free(buf);
}
static void
@ -325,6 +348,7 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
free_error_table_data(&ss->warn_table);
free_error_table_data(&ss->note_table);
free_error_table_data(&ss->chat_table);
free_error_table_data(&ss->pkt_comments_table);
g_free(ss);
}
@ -351,7 +375,7 @@ static expert_tapdata_t * expert_dlg_new_table(void)
etd->ei_array = g_array_sized_new(FALSE, FALSE, sizeof(expert_info_t), 1000);
etd->text = g_string_chunk_new(100);
etd->severity_report_level = PI_CHAT;
etd->severity_report_level = PI_COMMENT;
return etd;
}
@ -367,13 +391,13 @@ expert_dlg_init_table(expert_tapdata_t * etd, GtkWidget *vbox)
/* Create the store */
store = gtk_list_store_new(N_COLUMNS, /* Total number of columns */
G_TYPE_UINT, /* No */
G_TYPE_POINTER, /* Severity */
G_TYPE_POINTER, /* Group */
G_TYPE_POINTER, /* Protocol */
G_TYPE_POINTER, /* Summary */
G_TYPE_STRING, /* forground */
G_TYPE_STRING); /* Background */
G_TYPE_UINT, /* No */
G_TYPE_POINTER, /* Severity */
G_TYPE_POINTER, /* Group */
G_TYPE_POINTER, /* Protocol */
G_TYPE_POINTER, /* Summary */
G_TYPE_STRING, /* forground */
G_TYPE_STRING); /* Background */
/* Create a view */
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
@ -410,7 +434,7 @@ expert_dlg_init_table(expert_tapdata_t * etd, GtkWidget *vbox)
gtk_tree_view_column_set_sort_column_id(column, NO_COLUMN);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_min_width(column, 80);
gtk_tree_view_column_set_min_width(column, 40);
gtk_tree_view_append_column (etd->tree_view, column);
/* Severity */
@ -571,6 +595,9 @@ expert_dlg_draw(void *data)
/* set rows background color depending on severity */
switch(ei->severity) {
case(PI_COMMENT):
color_str = expert_color_comment_str;
break;
case(PI_CHAT):
color_str = expert_color_chat_str;
break;
@ -607,9 +634,9 @@ expert_dlg_draw(void *data)
}
if(etd->label) {
title = g_strdup_printf("Errors: %u Warnings: %u Notes: %u Chats: %u",
title = g_strdup_printf("Errors: %u Warnings: %u Notes: %u Chats: %u, Packet comments",
etd->error_events, etd->warn_events,
etd->note_events, etd->chat_events);
etd->note_events, etd->chat_events, etd->pkt_comments_events);
gtk_label_set_text(GTK_LABEL(etd->label), title);
g_free(title);
}
@ -627,7 +654,7 @@ expert_comp_init(const char *optarg _U_, void* userdata _U_)
expert_comp_dlg_t *ss;
const char *filter=NULL;
GString *error_string;
GtkWidget *temp_page;
GtkWidget *temp_page, *details_page;
GtkWidget *main_nb;
GtkWidget *vbox;
GtkWidget *hbox;
@ -639,6 +666,7 @@ expert_comp_init(const char *optarg _U_, void* userdata _U_)
ss=g_malloc(sizeof(expert_comp_dlg_t));
ss->pkt_comments_events = 0;
ss->disp_events = 0;
ss->chat_events = 0;
ss->note_events = 0;
@ -718,16 +746,25 @@ expert_comp_init(const char *optarg _U_, void* userdata _U_)
init_error_table(&ss->chat_table, 0, temp_page);
/* Details */
temp_page = gtk_vbox_new(FALSE, 6);
details_page = gtk_vbox_new(FALSE, 6);
ss->all_label = gtk_label_new("Details: 0");
gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, ss->all_label);
gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), details_page, ss->all_label);
etd = expert_dlg_new_table();
/* Paket comments */
temp_page = gtk_vbox_new(FALSE, 6);
ss->pkt_comments_label = gtk_label_new("Packet Comments: 0/y");
gtk_widget_show(ss->pkt_comments_label);
hbox = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(hbox), ss->pkt_comments_label);
gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, hbox);
init_error_table(&ss->pkt_comments_table, 0, temp_page);
etd = expert_dlg_new_table();
etd->label=gtk_label_new("Please wait ...");
gtk_misc_set_alignment(GTK_MISC(etd->label), 0.0f, 0.5f);
etd->win=ss->win;
expert_dlg_init_table(etd, temp_page);
expert_dlg_init_table(etd, details_page);
/* Add tap listener functions for expert details, From expert_dlg.c*/
error_string=register_tap_listener("expert", etd, NULL /* fstring */,

View File

@ -648,7 +648,7 @@ init_error_table(error_equiv_table *err, guint num_procs, GtkWidget *vbox)
sortable = GTK_TREE_SORTABLE(store);
/* Speed up the list display */
gtk_tree_view_set_fixed_height_mode(err->tree_view, TRUE);
gtk_tree_view_set_fixed_height_mode(err->tree_view, TRUE);
gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW (tree), FALSE);
@ -659,7 +659,8 @@ init_error_table(error_equiv_table *err, guint num_procs, GtkWidget *vbox)
renderer = gtk_cell_renderer_text_new ();
/* Create the first column, associating the "text" attribute of the
* cell_renderer to the first column of the model */
* cell_renderer to the first column of the model
*/
column = gtk_tree_view_column_new_with_attributes ("Group", renderer, NULL);
gtk_tree_view_column_set_sort_column_id(column, GROUP_COLUMN);
gtk_tree_view_column_set_resizable(column, TRUE);

View File

@ -795,8 +795,6 @@ add_byte_views(epan_dissect_t *edt, GtkWidget *tree_view,
{
GSList *src_le;
data_source *src;
int i, count = 0;
data_source *srccpy, *srcptr;
/*
* Get rid of all the old notebook tabs.
@ -808,27 +806,9 @@ add_byte_views(epan_dissect_t *edt, GtkWidget *tree_view,
* Add to the specified byte view notebook tabs for hex dumps
* of all the data sources for the specified frame.
*/
/* Note:
* The fundamental problem is that the edt->pi.data_src, etc. in the
* following loop was using the ep memory pool and while in the loop,
* any update caused by add_byte_tab() would trigger another
* epan_dissect_run() call which will reset the memory pool and invalidate
* the content of edt->pi.data_src linked list.
* As a work-around the data_src linked list may be
* copied over to a local (stack) storage.
* The other data structure, such as src->tvb and edt->tree may need be
* copied as well, but not done in this workaround. */
for (src_le = edt->pi.data_src; src_le != NULL; src_le = src_le->next) {
count++;
}
srccpy = srcptr = (data_source *) g_malloc(count*sizeof(data_source));
for (src_le = edt->pi.data_src; src_le != NULL; src_le = src_le->next) {
src = src_le->data;
*srcptr = *src;
srcptr++;
}
for (i = 0; i < count; i++) {
add_byte_tab(byte_nb_ptr, get_data_source_name(&srccpy[i]), srccpy[i].tvb, edt->tree,
add_byte_tab(byte_nb_ptr, get_data_source_name(src), src->tvb, edt->tree,
tree_view);
}
@ -1875,6 +1855,7 @@ set_ptree_font_all(PangoFontDescription *font)
*/
static gboolean colors_ok = FALSE;
GdkColor expert_color_comment = {0, 0x0000, 0xffff, 0x0000 }; /* Green */
GdkColor expert_color_chat = { 0, 0x8080, 0xb7b7, 0xf7f7 }; /* light blue */
GdkColor expert_color_note = { 0, 0xa0a0, 0xffff, 0xffff }; /* bright turquoise */
GdkColor expert_color_warn = { 0, 0xf7f7, 0xf2f2, 0x5353 }; /* yellow */
@ -1882,6 +1863,7 @@ GdkColor expert_color_error = { 0, 0xffff, 0x5c5c, 0x5c5c };
GdkColor expert_color_foreground = { 0, 0x0000, 0x0000, 0x0000 }; /* black */
GdkColor hidden_proto_item = { 0, 0x4444, 0x4444, 0x4444 }; /* gray */
gchar *expert_color_comment_str;
gchar *expert_color_chat_str;
gchar *expert_color_note_str;
gchar *expert_color_warn_str;
@ -1901,6 +1883,7 @@ void proto_draw_colors_init(void)
get_color(&expert_color_error);
get_color(&expert_color_foreground);
#endif
expert_color_comment_str = gdk_color_to_string(&expert_color_comment);
expert_color_chat_str = gdk_color_to_string(&expert_color_chat);
expert_color_note_str = gdk_color_to_string(&expert_color_note);
expert_color_warn_str = gdk_color_to_string(&expert_color_warn);
@ -1987,6 +1970,10 @@ tree_cell_renderer(GtkTreeViewColumn *tree_column _U_, GtkCellRenderer *cell,
if(FI_GET_FLAG(fi, PI_SEVERITY_MASK)) {
switch(FI_GET_FLAG(fi, PI_SEVERITY_MASK)) {
case(PI_COMMENT):
g_object_set (cell, "background-gdk", &expert_color_comment, NULL);
g_object_set (cell, "background-set", TRUE, NULL);
break;
case(PI_CHAT):
g_object_set (cell, "background-gdk", &expert_color_chat, NULL);
g_object_set (cell, "background-set", TRUE, NULL);

View File

@ -236,6 +236,7 @@ extern void select_bytes_view (GtkWidget *widget, gpointer data, gint view);
extern void proto_draw_colors_init(void);
/** the expert colors */
extern GdkColor expert_color_comment;
extern GdkColor expert_color_chat;
extern GdkColor expert_color_note;
extern GdkColor expert_color_warn;
@ -243,6 +244,7 @@ extern GdkColor expert_color_error;
extern GdkColor expert_color_foreground;
/* string representation of expert colors */
extern gchar *expert_color_comment_str;
extern gchar *expert_color_chat_str;
extern gchar *expert_color_note_str;
extern gchar *expert_color_warn_str;