Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / gtk / camel_counter.c
blob53e334abfddb20028966278fdf9032852401fea8
1 /* camel_counter.c
2 * camel message counter for Wireshark
3 * Copyright 2006 Florent Drouin (based on h225_counter.c from Lars Roland)
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
29 #include <string.h>
30 #include <gtk/gtk.h>
32 #include <epan/epan.h>
33 #include <epan/packet_info.h>
34 #include <epan/value_string.h>
35 #include <epan/tap.h>
36 #include <epan/packet.h>
37 #include <epan/asn1.h>
38 #include <epan/camel-persistentdata.h>
40 #include "../stat_menu.h"
42 #include "ui/simple_dialog.h"
44 #include "ui/gtk/main.h"
45 #include "ui/gtk/dlg_utils.h"
46 #include "ui/gtk/gui_utils.h"
47 #include "ui/gtk/gui_stat_util.h"
48 #include "ui/gtk/tap_param_dlg.h"
50 #include "ui/gtk/old-gtk-compat.h"
52 static void gtk_camelcounter_reset(void *phs);
53 static int gtk_camelcounter_packet(void *phs,
54 packet_info *pinfo _U_,
55 epan_dissect_t *edt _U_,
56 const void *phi);
57 static void gtk_camelcounter_draw(void *phs);
58 static void win_destroy_cb(GtkWindow *win _U_, gpointer data);
59 static void gtk_camelcounter_init(const char *opt_arg, void *userdata _U_);
60 void register_tap_listener_gtk_camelcounter(void);
62 /* following values represent the size of their valuestring arrays */
64 struct camelcounter_t {
65 GtkWidget *win;
66 GtkWidget *vbox;
67 char *filter;
68 GtkWidget *scrolled_window;
69 GtkTreeView *table;
70 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
73 static void gtk_camelcounter_reset(void *phs)
75 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
76 int i;
78 /* Erase Message Type count */
79 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
80 p_counter->camel_msg[i]=0;
86 * If there is a valid camel operation, increase the value in the array of counter
88 static int gtk_camelcounter_packet(void *phs,
89 packet_info *pinfo _U_,
90 epan_dissect_t *edt _U_,
91 const void *phi)
93 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
94 const struct camelsrt_info_t * pi=(struct camelsrt_info_t *)phi;
95 if (pi->opcode != 255)
96 p_counter->camel_msg[pi->opcode]++;
98 return 1;
101 static void gtk_camelcounter_draw(void *phs)
103 struct camelcounter_t *p_counter=(struct camelcounter_t *)phs;
104 int i;
105 char str[256];
106 GtkListStore *store;
107 GtkTreeIter iter;
109 /* Now print Message and Reason Counter Table */
110 /* clear list before printing */
111 store = GTK_LIST_STORE(gtk_tree_view_get_model(p_counter->table));
112 gtk_list_store_clear(store);
114 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
115 /* Message counter */
116 if(p_counter->camel_msg[i]!=0) {
117 g_snprintf(str, 256, "Request %s", val_to_str(i,camel_opr_code_strings,"Unknown message "));
119 gtk_list_store_append(store, &iter);
120 gtk_list_store_set(store, &iter,
121 0, str,
122 1, p_counter->camel_msg[i],
123 -1);
125 } /* Message Type */
128 static void win_destroy_cb(GtkWindow *win _U_, gpointer data)
130 struct camelcounter_t *hs=(struct camelcounter_t *)data;
132 remove_tap_listener(hs);
134 if(hs->filter){
135 g_free(hs->filter);
136 hs->filter=NULL;
138 g_free(hs);
141 static const stat_column titles[]={
142 {G_TYPE_STRING, LEFT, "Message Type or Reason"},
143 {G_TYPE_UINT, RIGHT, "Count" }
146 static void gtk_camelcounter_init(const char *opt_arg, void *userdata _U_)
148 struct camelcounter_t *p_camelcounter;
149 const char *filter=NULL;
150 GString *error_string;
151 GtkWidget *bbox;
152 GtkWidget *close_bt;
154 if(strncmp(opt_arg,"camel,counter,",14) == 0){
155 filter=opt_arg+14;
156 } else {
157 filter=NULL;
160 p_camelcounter=(struct camelcounter_t *)g_malloc(sizeof(struct camelcounter_t));
161 p_camelcounter->filter=g_strdup(filter);
163 gtk_camelcounter_reset(p_camelcounter);
165 /* transient_for top_level */
166 p_camelcounter->win=dlg_window_new("Wireshark: CAMEL counters");
167 gtk_window_set_destroy_with_parent (GTK_WINDOW(p_camelcounter->win), TRUE);
169 gtk_window_set_default_size(GTK_WINDOW(p_camelcounter->win), 500, 300);
171 p_camelcounter->vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
172 gtk_container_set_border_width(GTK_CONTAINER(p_camelcounter->vbox), 12);
174 init_main_stat_window(p_camelcounter->win, p_camelcounter->vbox, "CAMEL Messages Counters", filter);
176 /* init a scrolled window*/
177 p_camelcounter->scrolled_window = scrolled_window_new(NULL, NULL);
179 p_camelcounter->table = create_stat_table(p_camelcounter->scrolled_window, p_camelcounter->vbox, 2, titles);
181 error_string=register_tap_listener("CAMEL", p_camelcounter, filter, 0,
182 gtk_camelcounter_reset,
183 gtk_camelcounter_packet,
184 gtk_camelcounter_draw);
186 if(error_string){
187 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
188 g_string_free(error_string, TRUE);
189 g_free(p_camelcounter);
190 return;
193 /* Button row. */
194 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
195 gtk_box_pack_end(GTK_BOX(p_camelcounter->vbox), bbox, FALSE, FALSE, 0);
197 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
198 window_set_cancel_button(p_camelcounter->win, close_bt, window_cancel_button_cb);
200 g_signal_connect(p_camelcounter->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
201 g_signal_connect(p_camelcounter->win, "destroy", G_CALLBACK(win_destroy_cb), p_camelcounter);
203 gtk_widget_show_all(p_camelcounter->win);
204 window_present(p_camelcounter->win);
206 cf_retap_packets(&cfile);
207 gdk_window_raise(gtk_widget_get_window(p_camelcounter->win));
210 static tap_param camel_counter_params[] = {
211 { PARAM_FILTER, "Filter", NULL }
214 static tap_param_dlg camel_counter_dlg = {
215 "CAMEL Messages and Response Status",
216 "camel,counter",
217 gtk_camelcounter_init,
219 G_N_ELEMENTS(camel_counter_params),
220 camel_counter_params
223 void /* Next line mandatory */
224 register_tap_listener_gtk_camelcounter(void)
226 register_param_stat(&camel_counter_dlg, "CAMEL Messages and Response Status",
227 REGISTER_STAT_GROUP_TELEPHONY_GSM);