Fix build by #if 0 out unused de_sgsap_tmsi() function.
[obnox/wireshark/wip.git] / gtk / expert_comp_dlg.c
1 /* expert_comp_dlg.c
2  * expert_comp_dlg   2005 Greg Morris
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32 #include <string.h>
33
34 #include <gtk/gtk.h>
35
36 #include <epan/packet_info.h>
37 #include <epan/tap.h>
38 #include <epan/stat_cmd_args.h>
39
40 #include "../simple_dialog.h"
41 #include "../stat_menu.h"
42
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"
50 #include "gtk/main.h"
51
52
53 /* used to keep track of the statistics for an entire program interface */
54 typedef struct _expert_comp_dlg_t {
55     GtkWidget *win;
56     GtkWidget *chat_label;
57     GtkWidget *note_label;
58     GtkWidget *warn_label;
59     GtkWidget *error_label;
60     GtkWidget *all_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;
65     guint32 disp_events;
66     guint32 chat_events;
67     guint32 note_events;
68     guint32 warn_events;
69     guint32 error_events;
70 } expert_comp_dlg_t;
71
72 static GtkWidget  *expert_comp_dlg_w = NULL;
73
74 static void
75 error_set_title(expert_comp_dlg_t *ss)
76 {
77     char *title;
78
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);
82     g_free(title);
83 }
84
85 static void
86 error_reset(void *pss)
87 {
88     expert_comp_dlg_t *ss=(expert_comp_dlg_t *)pss;
89     gchar *buf;
90
91     ss->error_events = 0;
92     ss->warn_events = 0;
93     ss->note_events = 0;
94     ss->chat_events = 0;
95     ss->disp_events = 0;
96
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);
100     g_free(buf);
101
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);
105     g_free(buf);
106
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);
110     g_free(buf);
111
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);
115     g_free(buf);
116
117     gtk_label_set_text( GTK_LABEL(ss->all_label), "Details: 0");
118     error_set_title(ss);
119 }
120
121 static gboolean
122 error_packet(void *pss, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *prv)
123 {
124     expert_comp_dlg_t *ss=(expert_comp_dlg_t *)pss;
125     const expert_info_t *error_pkt=prv;
126
127     /* if return value is 0 then no error */
128     if(error_pkt==NULL){
129         return FALSE;
130     }
131
132     switch (error_pkt->severity) {
133     case PI_ERROR:
134         ss->disp_events++;
135         ss->error_events++;
136         init_error_table_row(&ss->error_table, error_pkt);
137         break;
138     case PI_WARN:
139         ss->disp_events++;
140         ss->warn_events++;
141         init_error_table_row(&ss->warn_table, error_pkt);
142         break;
143     case PI_NOTE:
144         ss->disp_events++;
145         ss->note_events++;
146         init_error_table_row(&ss->note_table, error_pkt);
147         break;
148     case PI_CHAT:
149         ss->disp_events++;
150         ss->chat_events++;
151         init_error_table_row(&ss->chat_table, error_pkt);
152         break;
153     default:
154         return FALSE; /* Don't draw */
155     }
156     return TRUE; /* Draw */
157 }
158
159 static void
160 expert_comp_draw(void *data)
161 {
162     gchar *buf = NULL;
163
164     expert_comp_dlg_t *ss=(expert_comp_dlg_t *)data;
165
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);
168     g_free(buf);
169
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);
172     g_free(buf);
173
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);
176     g_free(buf);
177
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);
180     g_free(buf);
181
182     buf = g_strdup_printf("Details: %u", ss->disp_events);
183     gtk_label_set_text( GTK_LABEL(ss->all_label), buf);
184     g_free(buf);
185
186 }
187
188 static void
189 win_destroy_cb(GtkWindow *win _U_, gpointer data)
190 {
191     expert_comp_dlg_t *ss=(expert_comp_dlg_t *)data;
192
193     protect_thread_critical_region();
194     remove_tap_listener(ss);
195     unprotect_thread_critical_region();
196
197     if (expert_comp_dlg_w != NULL) {
198         window_destroy(expert_comp_dlg_w);
199         expert_comp_dlg_w = NULL;
200     }
201
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);
206     g_free(ss);
207
208 }
209
210 static void
211 expert_comp_init(const char *optarg _U_, void* userdata _U_)
212 {
213     expert_comp_dlg_t *ss;
214     const char *filter=NULL;
215     GString *error_string;
216     GtkWidget *temp_page;
217     GtkWidget *main_nb;
218     GtkWidget *vbox;
219     GtkWidget *hbox;
220     GtkWidget *bbox;
221     GtkWidget *close_bt;
222     GtkWidget *help_bt;
223     expert_tapdata_t *etd;
224     GtkTooltips *tooltips = gtk_tooltips_new();
225
226     ss=g_malloc(sizeof(expert_comp_dlg_t));
227
228     ss->disp_events = 0;
229     ss->chat_events = 0;
230     ss->note_events = 0;
231     ss->warn_events = 0;
232     ss->error_events = 0;
233
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);
237
238     error_set_title(ss);
239
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);
243
244     main_nb = gtk_notebook_new();
245     gtk_box_pack_start(GTK_BOX(vbox), main_nb, TRUE, TRUE, 0);
246
247     /* We must display TOP LEVEL Widget before calling init_table() */
248     gtk_widget_show_all(ss->win);
249
250     /* Errors */
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);
258
259     /* Warnings */
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);
267
268     /* Notes */
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);
276
277     /* Chat */
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);
285
286     /* Details */
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);
290
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);
294
295     etd->win=ss->win;
296     expert_dlg_init_table(etd, temp_page);
297
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,
301                                        expert_dlg_reset,
302                                        expert_dlg_packet,
303                                        expert_dlg_draw);
304     if(error_string){
305         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
306         g_string_free(error_string, TRUE);
307         g_free(etd);
308         return;
309     }
310
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);
313
314     /* Register the tap listener */
315
316     error_string=register_tap_listener("expert", ss, filter, 0, error_reset, error_packet, expert_comp_draw);
317     if(error_string){
318         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
319         g_string_free(error_string, TRUE);
320         g_free(ss);
321         return;
322     }
323
324     /* Button row. */
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);
327
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);
330
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);
334
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);
337
338     gtk_widget_show_all(ss->win);
339     window_present(ss->win);
340
341     /*
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
345      * tree built.
346      *
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.
352      */
353     cf_retap_packets(&cfile);
354
355     /* This will bring up the progress bar
356      * Put our window back in front
357      */
358     gdk_window_raise(ss->win->window);
359     /* Set the lable text */
360     expert_comp_draw(ss);
361 }
362
363
364 void
365 expert_comp_dlg_launch(void)
366 {
367     if (expert_comp_dlg_w) {
368         reactivate_window(expert_comp_dlg_w);
369     } else {
370         expert_comp_init("", NULL);
371     }
372 }
373
374 void
375 register_tap_listener_expert_comp(void)
376 {
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);
381 }