Microsoft Credential Security Support Provider (CredSSP) support.
[obnox/wireshark/wip.git] / gtk / megaco_stat.c
1 /* megaco_stat.c
2  * megaco-statistics for Wireshark
3  * Copyright 2003 Lars Roland
4  * Copyright 2008, Ericsson AB
5  * By Balint Reczey <balint.reczey@ericsson.com>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <string.h>
37
38 #include <gtk/gtk.h>
39
40 #include <epan/packet_info.h>
41 #include <epan/epan.h>
42 #include <epan/value_string.h>
43 #include <epan/tap.h>
44 #include "epan/gcp.h"
45 #include <epan/prefs-int.h>
46
47 #include "../timestats.h"
48 #include "../simple_dialog.h"
49 #include "../file.h"
50 #include "../stat_menu.h"
51
52 #include "gtk/gui_stat_util.h"
53 #include "gtk/dlg_utils.h"
54 #include "gtk/tap_param_dlg.h"
55 #include "gtk/gui_utils.h"
56 #include "gtk/main.h"
57
58 #include "tap-megaco-common.h"
59
60 #include "gtk/old-gtk-compat.h"
61
62 static void
63 megacostat_reset(void *pms)
64 {
65         megacostat_t *ms=(megacostat_t *)pms;
66         int i;
67
68         for(i=0;i<NUM_TIMESTATS;i++) {
69                 ms->rtd[i].num=0;
70                 ms->rtd[i].min_num=0;
71                 ms->rtd[i].max_num=0;
72                 ms->rtd[i].min.secs=0;
73                 ms->rtd[i].min.nsecs=0;
74                 ms->rtd[i].max.secs=0;
75                 ms->rtd[i].max.nsecs=0;
76                 ms->rtd[i].tot.secs=0;
77                 ms->rtd[i].tot.nsecs=0;
78         }
79
80         ms->open_req_num=0;
81         ms->disc_rsp_num=0;
82         ms->req_dup_num=0;
83         ms->rsp_dup_num=0;
84 }
85
86 static void
87 megacostat_draw(void *pms)
88 {
89         megacostat_t *ms=(megacostat_t *)pms;
90         int i;
91         char str[3][256];
92         GtkListStore *store;
93         GtkTreeIter iter;
94
95         /* clear list before printing */
96         store = GTK_LIST_STORE(gtk_tree_view_get_model(ms->table));
97         gtk_list_store_clear(store);
98
99         for(i=0;i<NUM_TIMESTATS;i++) {
100                 /* nothing seen, nothing to do */
101                 if(ms->rtd[i].num==0){
102                         continue;
103                 }
104
105                 g_snprintf(str[0], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(ms->rtd[i].min)));
106                 g_snprintf(str[1], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(ms->rtd[i].max)));
107                 g_snprintf(str[2], sizeof(char[256]), "%8.2f msec", get_average(&(ms->rtd[i].tot), ms->rtd[i].num));
108                 gtk_list_store_append(store, &iter);
109                 gtk_list_store_set(store, &iter,
110                         0, val_to_str(i,megaco_message_type,"Other"),
111                         1, ms->rtd[i].num,
112                         2, str[0],
113                         3, str[1],
114                         4, str[2],
115                         5, ms->rtd[i].min_num,
116                         6, ms->rtd[i].max_num,
117                         -1);
118         }
119 }
120
121 static void
122 win_destroy_cb(GtkWindow *win _U_, gpointer data)
123 {
124         megacostat_t *ms=(megacostat_t *)data;
125
126         protect_thread_critical_region();
127         remove_tap_listener(ms);
128         unprotect_thread_critical_region();
129
130         if(ms->filter){
131                 g_free(ms->filter);
132                 ms->filter=NULL;
133         }
134         g_free(ms);
135 }
136
137 static const stat_column titles[]={
138         {G_TYPE_STRING, LEFT, "Type" },
139         {G_TYPE_UINT, RIGHT,   "Messages" },
140         {G_TYPE_STRING, RIGHT, "Min SRT" },
141         {G_TYPE_STRING, RIGHT, "Max SRT" },
142         {G_TYPE_STRING, RIGHT, "Avg SRT" },
143         {G_TYPE_UINT, RIGHT,  "Min in Frame" },
144         {G_TYPE_UINT, RIGHT,  "Max in Frame" }
145 };
146
147 static void
148 gtk_megacostat_init(const char *optarg, void *userdata _U_)
149 {
150         megacostat_t *ms;
151         GString *error_string;
152         GtkWidget *bt_close;
153         GtkWidget *bbox;
154         pref_t *megaco_ctx_track,*h248_ctx_track;
155
156         megaco_ctx_track = prefs_find_preference(prefs_find_module("megaco"),"ctx_info");
157         h248_ctx_track = prefs_find_preference(prefs_find_module("h248"),"ctx_info");
158
159         if (!megaco_ctx_track || !h248_ctx_track) {
160                 /* No such preferences */
161                 return;
162         }
163
164         if (!*megaco_ctx_track->varp.boolp || !*h248_ctx_track->varp.boolp) {
165                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Track Context option at Protocols -> MEGACO and Protocols -> H248 preferences has to be set to true to enable measurement of service reponse times.");
166                 return;
167         }
168
169         ms=g_malloc(sizeof(megacostat_t));
170
171         if(strncmp(optarg,"megaco,srt,",11) == 0){
172                 ms->filter=g_strdup(optarg+11);
173         } else {
174                 ms->filter=NULL;
175         }
176
177         megacostat_reset(ms);
178
179         ms->win = dlg_window_new("MEGACO SRT");  /* transient_for top_level */
180         gtk_window_set_destroy_with_parent (GTK_WINDOW(ms->win), TRUE);
181
182         gtk_window_set_default_size(GTK_WINDOW(ms->win), 550, 150);
183
184         ms->vbox=gtk_vbox_new(FALSE, 3);
185
186         init_main_stat_window(ms->win, ms->vbox, "MEGACO Service Response Time (SRT) Statistics", ms->filter);
187
188         /* init a scrolled window*/
189         ms->scrolled_window = scrolled_window_new(NULL, NULL);
190
191         ms->table = create_stat_table(ms->scrolled_window, ms->vbox, 7, titles);
192
193         error_string=register_tap_listener("megaco", ms, ms->filter, 0, megacostat_reset, megacostat_packet, megacostat_draw);
194         if(error_string){
195                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
196                 g_string_free(error_string, TRUE);
197                 g_free(ms->filter);
198                 g_free(ms);
199                 return;
200         }
201
202         /* Button row. */
203         bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
204         gtk_box_pack_start(GTK_BOX(ms->vbox), bbox, FALSE, FALSE, 0);
205
206         bt_close = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
207         window_set_cancel_button(ms->win, bt_close, window_cancel_button_cb);
208
209         g_signal_connect(ms->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
210         g_signal_connect(ms->win, "destroy", G_CALLBACK(win_destroy_cb), ms);
211
212         gtk_widget_show_all(ms->win);
213         window_present(ms->win);
214
215         cf_retap_packets(&cfile);
216         gdk_window_raise(gtk_widget_get_window(ms->win));
217 }
218
219 static tap_param megaco_srt_params[] = {
220         { PARAM_FILTER, "Filter", NULL }
221 };
222
223 static tap_param_dlg megaco_srt_dlg = {
224         "MEGACO Service Response Time (SRT) Statistics",
225         "megaco,srt",
226         gtk_megacostat_init,
227         -1,
228         G_N_ELEMENTS(megaco_srt_params),
229         megaco_srt_params
230 };
231
232 void
233 register_tap_listener_gtkmegacostat(void)
234 {
235         register_dfilter_stat(&megaco_srt_dlg, "MEGACO",
236             REGISTER_STAT_GROUP_RESPONSE_TIME);
237 }
238
239 void megaco_srt_cb(GtkAction *action, gpointer user_data _U_)
240 {
241         tap_param_dlg_cb(action, &megaco_srt_dlg);
242 }
243