2 * Display of Expert information.
4 * Implemented as a tap listener to the "expert" tap.
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <epan/packet.h>
38 #include <epan/expert.h>
39 #include <epan/emem.h>
41 #include "epan/packet_info.h"
42 #include <epan/stat_cmd_args.h>
43 #include <epan/prefs.h>
45 #include "../simple_dialog.h"
46 #include "../globals.h"
48 #include "../stat_menu.h"
49 #include "image/clist_ascend.xpm"
50 #include "image/clist_descend.xpm"
52 #include "gtk/find_dlg.h"
53 #include "gtk/color_dlg.h"
55 #include "gtk/gui_utils.h"
56 #include "gtk/gtkglobals.h"
57 #include "gtk/dlg_utils.h"
58 #include "gtk/gui_stat_menu.h"
59 #include "gtk/tap_dfilter_dlg.h"
60 #include "gtk/color_utils.h"
61 #include "gtk/main_proto_draw.h"
62 #include "gtk/help_dlg.h"
63 #include "gtk/expert_dlg.h"
65 static const value_string expert_severity_om_vals[] = {
66 { PI_ERROR, "Errors only" },
67 { PI_WARN, "Error+Warn" },
68 { PI_NOTE, "Error+Warn+Note" },
69 { PI_CHAT, "Error+Warn+Note+Chat" },
74 /* reset of display only, e.g. for filtering */
75 static void expert_dlg_display_reset(expert_tapdata_t * etd)
78 gtk_clist_clear(etd->table);
79 gtk_clist_columns_autosize(etd->table);
81 gtk_window_set_title(GTK_WINDOW(etd->win), "Wireshark: ? Expert Infos");
83 gtk_label_set_text(GTK_LABEL(etd->label), "Please wait ...");
88 /* complete reset, e.g. capture file closed */
89 void expert_dlg_reset(void *tapdata)
91 expert_tapdata_t * etd = tapdata;
96 etd->error_events = 0;
99 /* g_string_chunk_clear() is introduced in glib 2.14 */
100 g_string_chunk_free(etd->text);
101 etd->text = g_string_chunk_new(100);
102 g_array_set_size(etd->ei_array, 0);
104 expert_dlg_display_reset(etd);
107 int expert_dlg_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pointer)
110 expert_tapdata_t * etd = tapdata;
112 g_array_append_val(etd->ei_array, *(expert_info_t *)pointer);
113 etd->last = etd->ei_array->len;
114 ei = &g_array_index(etd->ei_array, expert_info_t, etd->last -1); /* ugly */
115 ei->protocol = g_string_chunk_insert_const(etd->text, ei->protocol);
116 ei->summary = g_string_chunk_insert_const(etd->text, ei->summary);
118 switch(ei->severity) {
132 g_assert_not_reached();
134 if(ei->severity < etd->severity_report_level) {
135 return 0; /* draw not required */
137 return 1; /* draw required */
142 expert_dlg_draw(void *data)
144 expert_tapdata_t *etd = data;
149 const char *entries[5]; /**< column entries */
152 displayed = etd->disp_events;
155 if(etd->last - etd->first) {
156 title = g_strdup_printf("Adding: %u new messages",etd->last - etd->first);
157 gtk_label_set_text(GTK_LABEL(etd->label), title);
162 gtk_clist_freeze(etd->table);
164 /* append new events (remove from new list, append to displayed list and clist) */
165 while(etd->first < etd->last){
166 ei = &g_array_index(etd->ei_array, expert_info_t, etd->first);
169 if(ei->severity < etd->severity_report_level) {
174 if(etd->disp_events == 1000)
175 gtk_clist_columns_autosize(etd->table);
181 g_snprintf(str_buf, sizeof(str_buf), "%u", ei->packet_num);
182 entries[0] = str_buf;
188 entries[1] = val_to_str(ei->severity, expert_severity_vals, "Unknown severity (%u)");
191 entries[2] = val_to_str(ei->group, expert_group_vals, "Unknown group (%u)");
195 entries[3] = ei->protocol;
201 entries[4] = ei->summary;
203 /*gtk_clist_set_pixmap(etd->table, row, 5, ascend_pm, ascend_bm);*/
205 row=gtk_clist_append(etd->table, (gchar **) entries);
206 gtk_clist_set_row_data(etd->table, row, GUINT_TO_POINTER(ei->packet_num));
208 /* set rows background color depending on severity */
209 switch(ei->severity) {
211 gtk_clist_set_background(etd->table, row, &expert_color_chat);
214 gtk_clist_set_background(etd->table, row, &expert_color_note);
217 gtk_clist_set_background(etd->table, row, &expert_color_warn);
220 gtk_clist_set_background(etd->table, row, &expert_color_error);
223 g_assert_not_reached();
225 gtk_clist_set_foreground(etd->table, row, &expert_color_foreground);
228 if (etd->table->sort_column || etd->table->sort_type != GTK_SORT_ASCENDING)
229 gtk_clist_sort(etd->table);
231 /* column autosizing is very slow for large number of entries,
232 * so do it only for the first 1000 of it
233 * (there might be no large changes behind this amount) */
234 if(etd->disp_events < 1000)
235 gtk_clist_columns_autosize(etd->table);
236 gtk_clist_moveto(etd->table,
237 etd->disp_events - 1, -1, 1.0f, 1.0f);
238 gtk_clist_thaw(etd->table);
241 title = g_strdup_printf("Errors: %u Warnings: %u Notes: %u Chats: %u",
242 etd->error_events, etd->warn_events, etd->note_events, etd->chat_events);
243 gtk_label_set_text(GTK_LABEL(etd->label), title);
247 title = g_strdup_printf("Wireshark: %u Expert Info%s",
249 plurality(etd->disp_events, "", "s"));
250 gtk_window_set_title(GTK_WINDOW(etd->win), title);
255 typedef struct column_arrows {
257 GtkWidget *ascend_pm;
258 GtkWidget *descend_pm;
263 srt_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
269 const GtkCListRow *row1 = ptr1;
270 const GtkCListRow *row2 = ptr2;
272 text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
273 text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
275 switch(clist->sort_column){
284 return strcmp (text1, text2);
286 g_assert_not_reached();
292 srt_click_column_cb(GtkCList *clist, gint column, gpointer data)
294 column_arrows *col_arrows = (column_arrows *) data;
297 gtk_clist_freeze(clist);
299 for (i = 0; i < 5; i++) {
300 gtk_widget_hide(col_arrows[i].ascend_pm);
301 gtk_widget_hide(col_arrows[i].descend_pm);
304 if (column == clist->sort_column) {
305 if (clist->sort_type == GTK_SORT_ASCENDING) {
306 clist->sort_type = GTK_SORT_DESCENDING;
307 gtk_widget_show(col_arrows[column].descend_pm);
309 clist->sort_type = GTK_SORT_ASCENDING;
310 gtk_widget_show(col_arrows[column].ascend_pm);
313 clist->sort_type = GTK_SORT_ASCENDING;
314 gtk_widget_show(col_arrows[column].ascend_pm);
315 gtk_clist_set_sort_column(clist, column);
317 gtk_clist_sort(clist);
319 gtk_clist_thaw(clist);
324 select_row_cb(GtkCList *clist, gint row, gint column _U_, GdkEventButton *event _U_, gpointer user_data _U_)
326 guint num = GPOINTER_TO_UINT(gtk_clist_get_row_data(clist, row));
328 cf_goto_frame(&cfile, num);
333 expert_dlg_init_table(expert_tapdata_t * etd, GtkWidget *vbox)
336 column_arrows *col_arrows;
338 GtkWidget *column_lb;
339 GdkBitmap *ascend_bm, *descend_bm;
340 GdkPixmap *ascend_pm, *descend_pm;
341 const char *default_titles[] = { "No.", "Sever.", "Group", "Protocol", "Summary" };
344 etd->scrolled_window=scrolled_window_new(NULL, NULL);
345 gtk_box_pack_start(GTK_BOX(vbox), etd->scrolled_window, TRUE, TRUE, 0);
347 etd->table=(GtkCList *)gtk_clist_new(5);
348 g_signal_connect(etd->table, "select-row", G_CALLBACK(select_row_cb), etd);
350 gtk_widget_show(GTK_WIDGET(etd->table));
351 gtk_widget_show(etd->scrolled_window);
353 col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * 5);
354 win_style = gtk_widget_get_style(etd->scrolled_window);
355 ascend_pm = gdk_pixmap_create_from_xpm_d(etd->scrolled_window->window,
357 &win_style->bg[GTK_STATE_NORMAL],
358 (gchar **)clist_ascend_xpm);
359 descend_pm = gdk_pixmap_create_from_xpm_d(etd->scrolled_window->window,
361 &win_style->bg[GTK_STATE_NORMAL],
362 (gchar **)clist_descend_xpm);
363 for (i = 0; i < 5; i++) {
364 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
365 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
366 column_lb = gtk_label_new(default_titles[i]);
367 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
368 gtk_widget_show(column_lb);
370 col_arrows[i].ascend_pm = gtk_pixmap_new(ascend_pm, ascend_bm);
371 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
372 col_arrows[i].descend_pm = gtk_pixmap_new(descend_pm, descend_bm);
373 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
375 gtk_widget_show(col_arrows[i].ascend_pm);
377 gtk_clist_set_column_widget(GTK_CLIST(etd->table), i, col_arrows[i].table);
378 gtk_widget_show(col_arrows[i].table);
380 gtk_clist_column_titles_show(GTK_CLIST(etd->table));
382 gtk_clist_set_compare_func(etd->table, srt_sort_column);
383 gtk_clist_set_sort_column(etd->table, 0);
384 gtk_clist_set_sort_type(etd->table, GTK_SORT_ASCENDING);
386 gtk_clist_set_column_justification(etd->table, 0, GTK_JUSTIFY_RIGHT);
387 gtk_clist_set_column_justification(etd->table, 3, GTK_JUSTIFY_RIGHT);
388 gtk_clist_set_shadow_type(etd->table, GTK_SHADOW_IN);
389 gtk_clist_column_titles_show(etd->table);
390 gtk_clist_columns_autosize(etd->table);
391 /* gtk_clist_set_selection_mode(etd->table, GTK_SELECTION_SINGLE);*/
392 /* gtk_list_set_selection_mode(GTK_LIST(etd->table), GTK_SELECTION_BROWSE);*/
393 /* gtk_list_select_item(GTK_LIST(value_list), 0);*/
394 gtk_container_add(GTK_CONTAINER(etd->scrolled_window), (GtkWidget *)etd->table);
396 g_signal_connect(etd->table, "click-column", G_CALLBACK(srt_click_column_cb), col_arrows);
398 gtk_widget_show(GTK_WIDGET(etd->table));
399 gtk_widget_show(etd->scrolled_window);
401 /* create popup menu for this table */
402 /*if(etd->filter_string){
403 srt_create_popup_menu(etd);
408 expert_dlg_destroy_cb(GtkWindow *win _U_, gpointer data)
410 expert_tapdata_t *etd=(expert_tapdata_t *)data;
412 protect_thread_critical_region();
413 remove_tap_listener(etd);
414 unprotect_thread_critical_region();
416 /*free_srt_table_data(&etd->afp_srt_table);*/
417 g_array_free(etd->ei_array, TRUE);
418 g_string_chunk_free(etd->text);
424 expert_dlg_severity_cb(GtkWidget *w, gpointer data _U_)
427 expert_tapdata_t * etd;
429 i = gtk_combo_box_get_active (GTK_COMBO_BOX(w));
430 etd = g_object_get_data(G_OBJECT(w), "tapdata");
432 etd->severity_report_level = expert_severity_om_vals[i].value;
434 /* "move" all events from "all" back to "new" lists */
435 protect_thread_critical_region();
437 unprotect_thread_critical_region();
440 expert_dlg_display_reset(etd);
441 expert_dlg_draw(etd);
444 expert_tapdata_t * expert_dlg_new_table(void)
446 expert_tapdata_t * etd;
447 etd=g_malloc0(sizeof(expert_tapdata_t));
449 etd->ei_array = g_array_sized_new(FALSE, FALSE, sizeof(expert_info_t), 1000);
450 etd->text = g_string_chunk_new(100);
451 etd->severity_report_level = PI_CHAT;
456 expert_dlg_init(const char *optarg, void* userdata _U_)
458 expert_tapdata_t * etd;
459 const char *filter=NULL;
460 GString *error_string;
467 GtkWidget *severity_box;
468 GtkWidget *severity_combo_box;
470 GtkTooltips *tooltips = gtk_tooltips_new();
473 if(!strncmp(optarg,"afp,srt,",8)){
479 proto_draw_colors_init();
481 etd = expert_dlg_new_table();
482 etd->win=dlg_window_new("Wireshark: Expert Info"); /* transient_for top_level */
483 gtk_window_set_destroy_with_parent (GTK_WINDOW(etd->win), TRUE);
485 gtk_window_set_default_size(GTK_WINDOW(etd->win), 650, 600);
487 vbox=gtk_vbox_new(FALSE, 3);
488 gtk_container_add(GTK_CONTAINER(etd->win), vbox);
489 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
491 table = gtk_table_new(1, 2, TRUE /* homogeneous */);
492 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
494 etd->label=gtk_label_new("Please wait ...");
495 gtk_misc_set_alignment(GTK_MISC(etd->label), 0.0f, 0.5f);
496 gtk_table_attach_defaults(GTK_TABLE(table), etd->label, 0, 1, 0, 1);
498 severity_box = gtk_hbox_new(FALSE, 0);
499 gtk_table_attach_defaults(GTK_TABLE(table), severity_box, 1, 2, 0, 1);
501 label=gtk_label_new("Severity filter: ");
502 gtk_box_pack_start(GTK_BOX(severity_box), label, FALSE, FALSE, 0);
504 severity_combo_box = gtk_combo_box_new_text ();
505 for(i=0; expert_severity_om_vals[i].strptr != NULL;i++){
506 gtk_combo_box_append_text (GTK_COMBO_BOX (severity_combo_box), expert_severity_om_vals[i].strptr);
507 if(expert_severity_om_vals[i].value == (guint) etd->severity_report_level) {
508 gtk_combo_box_set_active(GTK_COMBO_BOX(severity_combo_box), i);
512 g_object_set_data(G_OBJECT(severity_combo_box), "tapdata", etd);
513 g_signal_connect(severity_combo_box, "changed", G_CALLBACK(expert_dlg_severity_cb), etd->win);
514 gtk_box_pack_start(GTK_BOX(severity_box), severity_combo_box, FALSE, FALSE, 0);
517 /* We must display TOP LEVEL Widget before calling init_srt_table() */
518 gtk_widget_show_all(etd->win);
520 expert_dlg_init_table(etd, vbox);
521 /*for(i=0;i<256;i++){
522 init_srt_table_row(&etd->afp_srt_table, i, val_to_str(i, CommandCode_vals, "Unknown(%u)"));
525 error_string=register_tap_listener("expert", etd, NULL /* fstring */,
531 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
532 g_string_free(error_string, TRUE);
538 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
539 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
541 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
542 window_set_cancel_button(etd->win, close_bt, window_cancel_button_cb);
544 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
545 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_EXPERT_INFO_DIALOG);
546 gtk_tooltips_set_tip (tooltips, help_bt, "Show topic specific help", NULL);
548 g_signal_connect(etd->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
549 g_signal_connect(etd->win, "destroy", G_CALLBACK(expert_dlg_destroy_cb), etd);
551 gtk_widget_show_all(etd->win);
552 window_present(etd->win);
554 cf_retap_packets(&cfile);
556 /* This will bring up the progress bar
557 * Put our window back in front
559 gdk_window_raise(etd->win->window);
560 expert_dlg_draw(etd);
566 expert_dlg_cb(GtkWidget *w _U_, gpointer d _U_)
568 expert_dlg_init("", NULL);
575 register_tap_listener_expert(void)
577 register_stat_cmd_arg("expert", expert_dlg_init,NULL);
579 register_stat_menu_item("E_xpert Info", REGISTER_ANALYZE_GROUP_UNSORTED,
580 expert_dlg_cb, NULL, NULL, NULL);