3 * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
4 * In association with Telos Technology Inc.
6 * MUCH code modified from service_response_time_table.c.
8 * $Id: isup_stat.c,v 1.17 2004/02/18 04:11:42 jmayer Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * This TAP provides statistics for ISUP:
40 #include "epan/packet_info.h"
41 #include "epan/epan.h"
42 #include "epan/value_string.h"
44 #include "image/clist_ascend.xpm"
45 #include "image/clist_descend.xpm"
46 #include "simple_dialog.h"
47 #include "dlg_utils.h"
49 #include "../register.h"
50 #include "../globals.h"
51 #include "filter_prefs.h"
52 #include "compat_macros.h"
53 #include "packet-isup.h"
57 typedef struct column_arrows {
60 GtkWidget *descend_pm;
63 typedef struct _isup_stat_dlg_t {
65 GtkWidget *scrolled_win;
70 #define N_MESSAGE_TYPES 256
72 typedef struct _isup_stat_t {
73 int message_type[N_MESSAGE_TYPES];
77 static isup_stat_dlg_t dlg;
78 static isup_stat_t stat;
87 memset((void *) &stat, 0, sizeof(isup_stat_t));
95 epan_dissect_t *edt _U_,
98 isup_tap_rec_t *data_p = data;
104 #if 0 /* always false because message_type is 8 bit value */
105 if (data_p->message_type >= N_MESSAGE_TYPES)
108 * unknown message type !!!
114 stat.message_type[data_p->message_type]++;
125 char str[256], *strp;
134 while (isup_message_type_value[i].strptr)
136 j = gtk_clist_find_row_from_data(GTK_CLIST(dlg.table), (gpointer) i);
139 stat.message_type[isup_message_type_value[i].value]);
140 strp = g_strdup(str);
141 gtk_clist_set_text(GTK_CLIST(dlg.table), j, 3, strp);
147 gtk_clist_sort(GTK_CLIST(dlg.table));
153 isup_stat_gtk_click_column_cb(
158 column_arrows *col_arrows = (column_arrows *) data;
162 gtk_clist_freeze(clist);
164 for (i=0; i < 4; i++)
166 gtk_widget_hide(col_arrows[i].ascend_pm);
167 gtk_widget_hide(col_arrows[i].descend_pm);
170 if (column == clist->sort_column)
172 if (clist->sort_type == GTK_SORT_ASCENDING)
174 clist->sort_type = GTK_SORT_DESCENDING;
175 gtk_widget_show(col_arrows[column].descend_pm);
179 clist->sort_type = GTK_SORT_ASCENDING;
180 gtk_widget_show(col_arrows[column].ascend_pm);
186 * Columns 0-2 sorted in descending order by default
187 * Columns 3 sorted in ascending order by default
191 clist->sort_type = GTK_SORT_ASCENDING;
192 gtk_widget_show(col_arrows[column].ascend_pm);
196 clist->sort_type = GTK_SORT_DESCENDING;
197 gtk_widget_show(col_arrows[column].descend_pm);
200 gtk_clist_set_sort_column(clist, column);
203 gtk_clist_thaw(clist);
204 gtk_clist_sort(clist);
209 isup_stat_gtk_sort_column(
214 const GtkCListRow *row1 = (const GtkCListRow *) ptr1;
215 const GtkCListRow *row2 = (const GtkCListRow *) ptr2;
220 text1 = GTK_CELL_TEXT(row1->cell[clist->sort_column])->text;
221 text2 = GTK_CELL_TEXT(row2->cell[clist->sort_column])->text;
223 switch (clist->sort_column)
229 i1 = strtol(text1, NULL, 0);
230 i2 = strtol(text2, NULL, 0);
235 return(strcmp(text1, text2));
238 g_assert_not_reached();
245 isup_stat_gtk_dlg_close_cb(
246 GtkButton *button _U_,
247 gpointer user_data _U_)
249 isup_stat_dlg_t *dlg_p = user_data;
251 gtk_grab_remove(GTK_WIDGET(dlg_p->win));
252 gtk_widget_destroy(GTK_WIDGET(dlg_p->win));
257 isup_stat_gtk_win_destroy_cb(
259 gpointer user_data _U_)
261 memset((void *) user_data, 0, sizeof(isup_stat_dlg_t));
266 isup_stat_gtk_win_create(
267 isup_stat_dlg_t *dlg_p,
270 #define INIT_TABLE_NUM_COLUMNS 4
271 char *default_titles[] = { "ID", "Acronym", "Message Name", "Count" };
273 column_arrows *col_arrows;
274 GdkBitmap *ascend_bm, *descend_bm;
275 GdkPixmap *ascend_pm, *descend_pm;
277 GtkWidget *column_lb;
281 GtkWidget *dialog_vbox;
282 GtkWidget *dialog_action_area;
285 dlg_p->win = gtk_dialog_new();
286 gtk_window_set_default_size(GTK_WINDOW(dlg_p->win), 560, 450);
287 gtk_window_set_title(GTK_WINDOW(dlg_p->win), title);
288 SIGNAL_CONNECT(dlg_p->win, "destroy", isup_stat_gtk_win_destroy_cb, dlg_p);
290 dialog_vbox = GTK_DIALOG(dlg_p->win)->vbox;
291 gtk_widget_show(dialog_vbox);
293 dialog_action_area = GTK_DIALOG(dlg_p->win)->action_area;
294 gtk_widget_show(dialog_action_area);
295 gtk_container_set_border_width(GTK_CONTAINER(dialog_action_area), 10);
297 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
298 gtk_box_pack_start(GTK_BOX(dialog_action_area), bbox, FALSE, FALSE, 0);
299 gtk_widget_show(bbox);
301 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
302 SIGNAL_CONNECT(bt_close, "clicked", isup_stat_gtk_dlg_close_cb, dlg_p);
303 gtk_widget_grab_default(bt_close);
305 vbox = gtk_vbox_new(FALSE, 0);
306 gtk_widget_ref(vbox);
307 OBJECT_SET_DATA_FULL(dlg_p->win, "vbox", vbox, gtk_widget_unref);
308 gtk_widget_show(vbox);
309 gtk_box_pack_start(GTK_BOX(dialog_vbox), vbox, TRUE, TRUE, 0);
310 gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
312 dlg_p->scrolled_win = scrolled_window_new(NULL, NULL);
313 gtk_widget_ref(dlg_p->scrolled_win);
314 OBJECT_SET_DATA_FULL(dlg_p->win, "scrolled_win", dlg_p->scrolled_win,
316 gtk_widget_show(dlg_p->scrolled_win);
317 gtk_box_pack_start(GTK_BOX(vbox), dlg_p->scrolled_win, TRUE, TRUE, 0);
319 dlg_p->table = gtk_clist_new(INIT_TABLE_NUM_COLUMNS);
320 gtk_widget_ref(dlg_p->table);
321 OBJECT_SET_DATA_FULL(dlg_p->win, "table", dlg_p->table, gtk_widget_unref);
322 gtk_widget_show(dlg_p->table);
324 gtk_widget_show(dlg_p->win);
327 (column_arrows *) g_malloc(sizeof(column_arrows) * INIT_TABLE_NUM_COLUMNS);
330 gtk_widget_get_style(dlg_p->scrolled_win);
333 gdk_pixmap_create_from_xpm_d(dlg_p->scrolled_win->window,
335 &win_style->bg[GTK_STATE_NORMAL],
336 (gchar **) clist_ascend_xpm);
339 gdk_pixmap_create_from_xpm_d(dlg_p->scrolled_win->window,
341 &win_style->bg[GTK_STATE_NORMAL],
342 (gchar **)clist_descend_xpm);
344 for (i = 0; i < INIT_TABLE_NUM_COLUMNS; i++)
346 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
348 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
350 column_lb = gtk_label_new(default_titles[i]);
352 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb,
353 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
355 gtk_widget_show(column_lb);
357 col_arrows[i].ascend_pm =
358 gtk_pixmap_new(ascend_pm, ascend_bm);
360 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm,
361 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
363 col_arrows[i].descend_pm =
364 gtk_pixmap_new(descend_pm, descend_bm);
366 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm,
367 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
371 /* default column sorting */
372 gtk_widget_show(col_arrows[i].ascend_pm);
375 gtk_clist_set_column_widget(GTK_CLIST(dlg_p->table), i, col_arrows[i].table);
376 gtk_widget_show(col_arrows[i].table);
378 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
380 gtk_clist_set_compare_func(GTK_CLIST(dlg_p->table), isup_stat_gtk_sort_column);
381 gtk_clist_set_sort_column(GTK_CLIST(dlg_p->table), 0);
382 gtk_clist_set_sort_type(GTK_CLIST(dlg_p->table), GTK_SORT_ASCENDING);
384 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 0, 60);
385 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 1, 60);
386 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 2, 290);
387 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 3, 50);
389 gtk_clist_set_shadow_type(GTK_CLIST(dlg_p->table), GTK_SHADOW_IN);
390 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
391 gtk_container_add(GTK_CONTAINER(dlg_p->scrolled_win), dlg_p->table);
393 SIGNAL_CONNECT(dlg_p->table, "click-column", isup_stat_gtk_click_column_cb, col_arrows);
398 * Never gets called ?
404 /* does not appear to be called */
420 * if the window is already open, bring it to front
424 gdk_window_raise(dlg.win->window);
428 isup_stat_gtk_win_create(&dlg, "ISUP Message Type Statistics");
431 while (isup_message_type_value[i].strptr)
433 sprintf(str, "%u", isup_message_type_value[i].value);
434 dlg.entries[0] = g_strdup(str);
436 dlg.entries[1] = g_strdup(isup_message_type_value_acro[i].strptr);
438 dlg.entries[2] = g_strdup(isup_message_type_value[i].strptr);
440 dlg.entries[3] = g_strdup("0");
442 gtk_clist_insert(GTK_CLIST(dlg.table), i, dlg.entries);
443 gtk_clist_set_row_data(GTK_CLIST(dlg.table), i, (gpointer) i);
448 isup_stat_draw(NULL);
453 register_tap_listener_gtkisup_stat(void)
458 register_ethereal_tap("isup,", isup_stat_gtk_init);
460 memset((void *) &stat, 0, sizeof(isup_stat_t));
463 register_tap_listener("isup", NULL, NULL,
470 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_p->str);
471 g_string_free(err_p, TRUE);
479 register_tap_menu_gtkisup_stat(void)
481 register_tap_menu_item("_Statistics/ISUP Message Type", isup_stat_gtk_cb, NULL, NULL, NULL);