2 * expert_comp_dlg 2005 Greg Morris
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
36 #include <epan/packet_info.h>
38 #include <epan/stat_cmd_args.h>
40 #include "../simple_dialog.h"
41 #include "../stat_menu.h"
43 #include "gtk/gui_utils.h"
44 #include "gtk/dlg_utils.h"
45 #include "gtk/expert_comp_table.h"
46 #include "gtk/gui_stat_menu.h"
47 #include "gtk/help_dlg.h"
48 #include "gtk/expert_comp_dlg.h"
49 #include "gtk/stock_icons.h"
53 /* used to keep track of the statistics for an entire program interface */
54 typedef struct _expert_comp_dlg_t {
56 GtkWidget *chat_label;
57 GtkWidget *note_label;
58 GtkWidget *warn_label;
59 GtkWidget *error_label;
61 error_equiv_table chat_table;
62 error_equiv_table note_table;
63 error_equiv_table warn_table;
64 error_equiv_table error_table;
72 static GtkWidget *expert_comp_dlg_w = NULL;
75 error_set_title(expert_comp_dlg_t *ss)
79 title = g_strdup_printf("Expert Info Composite: %s",
80 cf_get_display_name(&cfile));
81 gtk_window_set_title(GTK_WINDOW(ss->win), title);
86 error_reset(void *pss)
88 expert_comp_dlg_t *ss=(expert_comp_dlg_t *)pss;
97 reset_error_table_data(&ss->error_table);
98 buf = g_strdup_printf("Errors: %u (0)", ss->error_table.num_procs);
99 gtk_label_set_text( GTK_LABEL(ss->error_label), buf);
102 reset_error_table_data(&ss->warn_table);
103 buf = g_strdup_printf("Warnings: %u (0)", ss->warn_table.num_procs);
104 gtk_label_set_text( GTK_LABEL(ss->warn_label), buf);
107 reset_error_table_data(&ss->note_table);
108 buf = g_strdup_printf("Notes: %u (0)", ss->note_table.num_procs);
109 gtk_label_set_text( GTK_LABEL(ss->note_label), buf);
112 reset_error_table_data(&ss->chat_table);
113 buf = g_strdup_printf("Chats: %u (0)", ss->chat_table.num_procs);
114 gtk_label_set_text( GTK_LABEL(ss->chat_label), buf);
117 gtk_label_set_text( GTK_LABEL(ss->all_label), "Details: 0");
122 error_packet(void *pss, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *prv)
124 expert_comp_dlg_t *ss=(expert_comp_dlg_t *)pss;
125 const expert_info_t *error_pkt=prv;
127 /* if return value is 0 then no error */
132 switch (error_pkt->severity) {
136 init_error_table_row(&ss->error_table, error_pkt);
141 init_error_table_row(&ss->warn_table, error_pkt);
146 init_error_table_row(&ss->note_table, error_pkt);
151 init_error_table_row(&ss->chat_table, error_pkt);
154 return FALSE; /* Don't draw */
156 return TRUE; /* Draw */
160 expert_comp_draw(void *data)
164 expert_comp_dlg_t *ss=(expert_comp_dlg_t *)data;
166 buf = g_strdup_printf("Errors: %u (%u)", ss->error_table.num_procs, ss->error_events);
167 gtk_label_set_text( GTK_LABEL(ss->error_label), buf);
170 buf = g_strdup_printf("Warnings: %u (%u)", ss->warn_table.num_procs, ss->warn_events);
171 gtk_label_set_text( GTK_LABEL(ss->warn_label), buf);
174 buf = g_strdup_printf("Notes: %u (%u)", ss->note_table.num_procs, ss->note_events);
175 gtk_label_set_text( GTK_LABEL(ss->note_label), buf);
178 buf = g_strdup_printf("Chats: %u (%u)", ss->chat_table.num_procs, ss->chat_events);
179 gtk_label_set_text( GTK_LABEL(ss->chat_label), buf);
182 buf = g_strdup_printf("Details: %u", ss->disp_events);
183 gtk_label_set_text( GTK_LABEL(ss->all_label), buf);
189 win_destroy_cb(GtkWindow *win _U_, gpointer data)
191 expert_comp_dlg_t *ss=(expert_comp_dlg_t *)data;
193 protect_thread_critical_region();
194 remove_tap_listener(ss);
195 unprotect_thread_critical_region();
197 if (expert_comp_dlg_w != NULL) {
198 window_destroy(expert_comp_dlg_w);
199 expert_comp_dlg_w = NULL;
202 free_error_table_data(&ss->error_table);
203 free_error_table_data(&ss->warn_table);
204 free_error_table_data(&ss->note_table);
205 free_error_table_data(&ss->chat_table);
211 expert_comp_init(const char *optarg _U_, void* userdata _U_)
213 expert_comp_dlg_t *ss;
214 const char *filter=NULL;
215 GString *error_string;
216 GtkWidget *temp_page;
223 expert_tapdata_t *etd;
224 GtkTooltips *tooltips = gtk_tooltips_new();
226 ss=g_malloc(sizeof(expert_comp_dlg_t));
232 ss->error_events = 0;
234 expert_comp_dlg_w = ss->win=dlg_window_new("err"); /* transient_for top_level */
235 gtk_window_set_destroy_with_parent (GTK_WINDOW(ss->win), TRUE);
236 gtk_window_set_default_size(GTK_WINDOW(ss->win), 700, 300);
240 vbox=gtk_vbox_new(FALSE, 3);
241 gtk_container_add(GTK_CONTAINER(ss->win), vbox);
242 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
244 main_nb = gtk_notebook_new();
245 gtk_box_pack_start(GTK_BOX(vbox), main_nb, TRUE, TRUE, 0);
247 /* We must display TOP LEVEL Widget before calling init_table() */
248 gtk_widget_show_all(ss->win);
251 temp_page = gtk_vbox_new(FALSE, 6);
252 ss->error_label = gtk_label_new("Errors: 0/y");
253 gtk_widget_show(ss->error_label);
254 hbox = gtk_hbox_new(FALSE, 3);
255 gtk_container_add(GTK_CONTAINER(hbox), ss->error_label);
256 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, hbox);
257 init_error_table(&ss->error_table, 0, temp_page);
260 temp_page = gtk_vbox_new(FALSE, 6);
261 ss->warn_label = gtk_label_new("Warnings: 0/y");
262 gtk_widget_show(ss->warn_label);
263 hbox = gtk_hbox_new(FALSE, 3);
264 gtk_container_add(GTK_CONTAINER(hbox), ss->warn_label);
265 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, hbox);
266 init_error_table(&ss->warn_table, 0, temp_page);
269 temp_page = gtk_vbox_new(FALSE, 6);
270 ss->note_label = gtk_label_new("Notes: 0/y");
271 gtk_widget_show(ss->note_label);
272 hbox = gtk_hbox_new(FALSE, 3);
273 gtk_container_add(GTK_CONTAINER(hbox), ss->note_label);
274 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, hbox);
275 init_error_table(&ss->note_table, 0, temp_page);
278 temp_page = gtk_vbox_new(FALSE, 6);
279 ss->chat_label = gtk_label_new("Chats: 0/y");
280 gtk_widget_show(ss->chat_label);
281 hbox = gtk_hbox_new(FALSE, 3);
282 gtk_container_add(GTK_CONTAINER(hbox), ss->chat_label);
283 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, hbox);
284 init_error_table(&ss->chat_table, 0, temp_page);
287 temp_page = gtk_vbox_new(FALSE, 6);
288 ss->all_label = gtk_label_new("Details: 0");
289 gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, ss->all_label);
291 etd = expert_dlg_new_table();
292 etd->label=gtk_label_new("Please wait ...");
293 gtk_misc_set_alignment(GTK_MISC(etd->label), 0.0f, 0.5f);
296 expert_dlg_init_table(etd, temp_page);
298 /* Add tap listener functions for expert details, From expert_dlg.c*/
299 error_string=register_tap_listener("expert", etd, NULL /* fstring */,
300 TL_REQUIRES_PROTO_TREE,
305 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
306 g_string_free(error_string, TRUE);
311 g_signal_connect(etd->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
312 g_signal_connect(etd->win, "destroy", G_CALLBACK(expert_dlg_destroy_cb), etd);
314 /* Register the tap listener */
316 error_string=register_tap_listener("expert", ss, filter, 0, error_reset, error_packet, expert_comp_draw);
318 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
319 g_string_free(error_string, TRUE);
325 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
326 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
328 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
329 window_set_cancel_button(ss->win, close_bt, window_cancel_button_cb);
331 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
332 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_EXPERT_INFO_DIALOG);
333 gtk_tooltips_set_tip (tooltips, help_bt, "Show topic specific help", NULL);
335 g_signal_connect(ss->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
336 g_signal_connect(ss->win, "destroy", G_CALLBACK(win_destroy_cb), ss);
338 gtk_widget_show_all(ss->win);
339 window_present(ss->win);
342 * At least at present, the only information the tap listener appears
343 * to care about is available regardless of whether the protocol tree
344 * is being built, so we don't appear to need to have the protocol
347 * This means we can use cf_retap_packets(), even though it will only
348 * build the protocol tree if at least one tap has a filter in place.
349 * cf_retap_packets() is faster than cf_redissect_packets(), as it
350 * assumes we didn't change anything that would cause any packets to
351 * dissect differently, and thus doesn't redo the packet display.
353 cf_retap_packets(&cfile);
355 /* This will bring up the progress bar
356 * Put our window back in front
358 gdk_window_raise(ss->win->window);
359 /* Set the lable text */
360 expert_comp_draw(ss);
365 expert_comp_dlg_launch(void)
367 if (expert_comp_dlg_w) {
368 reactivate_window(expert_comp_dlg_w);
370 expert_comp_init("", NULL);
375 register_tap_listener_expert_comp(void)
377 register_stat_cmd_arg("expert_comp", expert_comp_init,NULL);
378 register_stat_menu_item_stock("Expert Info _Composite",
379 REGISTER_ANALYZE_GROUP_UNSORTED, WIRESHARK_STOCK_EXPERT_INFO,
380 expert_comp_dlg_launch, NULL, NULL, NULL);