/* wsp_stat.c
* wsp_stat 2003 Jean-Michel FAYARD
*
- * $Id: wsp_stat.c,v 1.2 2003/09/17 19:39:34 guy Exp $
+ * $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
# include "config.h"
#endif
+#include <string.h>
+
#include <gtk/gtk.h>
-#include "menu.h"
-#include "epan/packet_info.h"
+
+#include <epan/packet_info.h>
+#include <epan/epan.h>
+
#include "simple_dialog.h"
-#include "tap.h"
+#include "gui_utils.h"
+#include "dlg_utils.h"
+#include <epan/tap.h>
#include "../register.h"
#include "../globals.h"
-#include "compat_macros.h"
-#include "../packet-wsp.h"
-#include <string.h>
+#include <epan/dissectors/packet-wsp.h>
+#include "../stat_menu.h"
+#include "../tap_dfilter_dlg.h"
/* used to keep track of the stats for a specific PDU type*/
typedef struct _wsp_pdu_t {
} wspstat_t;
/* used to keep track of a single type of status code */
typedef struct _wsp_status_code_t {
- gchar *name;
+ const gchar *name;
guint32 packets;
GtkWidget *widget;/* label in which we print the number of packets */
wspstat_t *sp; /* entire program interface */
} wsp_status_code_t;
-static GtkWidget *dlg=NULL, *dlg_box;
-static GtkWidget *filter_box;
-static GtkWidget *filter_label, *filter_entry;
-static GtkWidget *start_button;
-
static void
wsp_free_hash( gpointer key, gpointer value, gpointer user_data _U_ )
{
* or create it if it don't exist.
*/
static void
-wsp_draw_statuscode(gchar *key _U_, wsp_status_code_t *data, gchar * string_buff )
+wsp_draw_statuscode(gchar *key _U_, wsp_status_code_t *data, gchar * unused _U_ )
{
+ char string_buff[256];
+
if ((data==NULL) || (data->packets==0))
return;
if (data->widget==NULL){ /* create an entry in the table */
/* Maybe we should display the hexadecimal value ? */
- /* sprintf(string_buff, "%s (0X%x)", data->name, *key); */
+ /* g_snprintf(string_buff, 256, "%s (0X%x)", data->name, *key); */
tmp = gtk_label_new( data->name /* string_buff */ );
gtk_table_attach_defaults(GTK_TABLE(data->sp->table_status_code), tmp, x, x+1, y, y+1);
gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
gtk_widget_show(tmp);
- sprintf( string_buff, "%9d", data->packets );
+ g_snprintf( string_buff, 256, "%9d", data->packets );
data->widget = gtk_label_new( string_buff );
gtk_table_attach_defaults(GTK_TABLE(data->sp->table_status_code), data->widget, x+1, x+2, y, y+1);
gtk_label_set_justify(GTK_LABEL(data->widget), GTK_JUSTIFY_LEFT);
data->sp->index++;
} else {
/* Just update the label string */
- sprintf( string_buff, "%9d", data->packets );
+ g_snprintf( string_buff, 256, "%9d", data->packets );
gtk_label_set( GTK_LABEL(data->widget), string_buff);
}
}
}
static int
-wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *pri)
+wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
{
wspstat_t *sp=psp;
- wsp_info_value_t *value=pri;
+ const wsp_info_value_t *value=pri;
gint index = pdut2index(value->pdut);
int retour=0;
for(i=1;i<=sp->num_pdus ; i++)
{
- sprintf(str, "%9d", sp->pdu_stats[i ].packets);
+ g_snprintf(str, 256, "%9d", sp->pdu_stats[i ].packets);
gtk_label_set( GTK_LABEL(sp->pdu_stats[i].widget), str);
}
index=sp->index;
- g_hash_table_foreach( sp->hash, (GHFunc) wsp_draw_statuscode, str );
+ g_hash_table_foreach( sp->hash, (GHFunc) wsp_draw_statuscode, NULL );
if (index != sp->index){
/* We have inserted a new entry corresponding to a status code ,
* let's resize the table */
}
static void
-add_table_entry(wspstat_t *sp, char *str, int x, int y, int index)
+add_table_entry(wspstat_t *sp, const char *str, int x, int y, int index)
{
GtkWidget *tmp;
x=2;
}
/* Maybe we should display the hexadecimal value ? */
- /* snprintf(buffer, 50, "%s (0X%x)", match_strval( index2pdut( i ), vals_pdu_type), index2pdut(i) );*/
+ /* g_snprintf(buffer, 50, "%s (0X%x)", match_strval( index2pdut( i ), vals_pdu_type), index2pdut(i) );*/
add_table_entry( sp,
match_strval(index2pdut(i), vals_pdu_type), /* or buffer, */
x,
/* When called, this function will create a new instance of gtk2-wspstat.
*/
static void
-gtk_wspstat_init(char *optarg)
+gtk_wspstat_init(const char *optarg, void *userdata _U_)
{
wspstat_t *sp;
- char *filter=NULL;
+ const char *filter=NULL;
char *title=NULL;
GString *error_string;
GtkWidget *main_vb, *pdutypes_fr, *statuscode_fr ;
+ GtkWidget *bt_close;
+ GtkWidget *bbox;
guint32 i;
wsp_status_code_t *sc;
- if (!strncmp (optarg, "wsp,stat,", 9)){
+ if (strncmp (optarg, "wsp,stat,", 9) == 0){
filter=optarg+9;
} else {
filter=NULL;
}
sp = g_malloc( sizeof(wspstat_t) );
+ sp->win = window_new(GTK_WINDOW_TOPLEVEL, "wsp-stat");
sp->hash = g_hash_table_new( g_int_hash, g_int_equal);
for (i=0 ; vals_status[i].strptr ; i++ )
{
sp->num_pdus = 16;
sp->pdu_stats=g_malloc( (sp->num_pdus+1) * sizeof( wsp_pdu_t) );
if(filter){
- sp->filter=g_malloc(strlen(filter)+1);
- strcpy(sp->filter,filter);
- title=g_strdup_printf("WSP Stats with filter: %s", filter);
+ sp->filter=g_strdup(filter);
+ title=g_strdup_printf("Wireshark: WAP-WSP statistics with filter: %s", filter);
} else {
sp->filter=NULL;
- title=g_strdup("WSP Stats");
+ title=g_strdup("Wireshark: WAP-WSP statistics");
}
for (i=0;i<=sp->num_pdus; i++)
{
sp->pdu_stats[i].packets=0;
}
- sp->win = gtk_window_new( GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title( GTK_WINDOW(sp->win), title );
+ gtk_window_set_title(GTK_WINDOW(sp->win), title);
g_free(title);
- SIGNAL_CONNECT( sp->win, "destroy", win_destroy_cb, sp);
-
/* container for the two frames */
- main_vb = gtk_vbox_new(FALSE, 10);
- gtk_container_border_width(GTK_CONTAINER(main_vb), 10);
+ main_vb = gtk_vbox_new(FALSE, 3);
+ gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
gtk_container_add(GTK_CONTAINER(sp->win), main_vb);
- gtk_widget_show(main_vb);
/* PDU Types frame */
pdutypes_fr = gtk_frame_new("Summary of PDU Types (wsp.pdu_type)");
gtk_container_add(GTK_CONTAINER(main_vb), pdutypes_fr);
- gtk_widget_show(pdutypes_fr);
sp->table_pdu_types = gtk_table_new( (sp->num_pdus+1) / 2 + 1, 4, FALSE);
gtk_container_add( GTK_CONTAINER( pdutypes_fr), sp->table_pdu_types);
gtk_container_set_border_width( GTK_CONTAINER(sp->table_pdu_types) , 10);
wsp_init_table(sp);
- gtk_widget_show( sp->table_pdu_types );
/* Status Codes frame */
statuscode_fr = gtk_frame_new("Summary of Status Code (wsp.reply.status)");
gtk_container_add(GTK_CONTAINER(main_vb), statuscode_fr);
- gtk_widget_show(statuscode_fr);
sp->table_status_code = gtk_table_new( 0, 4, FALSE);
gtk_container_add( GTK_CONTAINER( statuscode_fr), sp->table_status_code);
gtk_container_set_border_width( GTK_CONTAINER(sp->table_status_code) , 10);
sp->index = 0; /* No answers to display yet */
-
error_string = register_tap_listener(
"wsp",
sp,
wspstat_draw);
if (error_string){
/* error, we failed to attach to the tap. clean up */
- simple_dialog( ESD_TYPE_WARN, NULL, error_string->str );
+ simple_dialog( ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str );
g_free(sp->pdu_stats);
g_free(sp->filter);
g_free(sp);
g_string_free(error_string, TRUE);
return ;
}
- gtk_widget_show_all( sp->win );
- redissect_packets(&cfile);
-}
-
+ /* Button row. */
+ bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
+ gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
-static void
-wspstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
-{
- char *filter;
- char str[256];
+ bt_close = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
+ window_set_cancel_button(sp->win, bt_close, window_cancel_button_cb);
- filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
- if(filter[0]==0){
- gtk_wspstat_init("wsp,stat,");
- } else {
- sprintf(str, "wsp,stat,%s", filter);
- gtk_wspstat_init(str);
- }
-}
+ g_signal_connect(sp->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
+ g_signal_connect(sp->win, "destroy", G_CALLBACK(win_destroy_cb), sp);
-static void
-dlg_destroy_cb(void)
-{
- dlg=NULL;
-}
-
-static void
-gtk_wspstat_cb(GtkWidget *w _U_, gpointer d _U_)
-{
- /* if the window is already open, bring it to front */
- if(dlg){
- gdk_window_raise(dlg->window);
- return;
- }
-
- dlg=gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(dlg), "WSP Statistics");
- SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
- dlg_box=gtk_vbox_new(FALSE, 0);
- gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
- gtk_widget_show(dlg_box);
-
-
- /* filter box */
- filter_box=gtk_hbox_new(FALSE, 10);
- /* Filter label */
- gtk_container_set_border_width(GTK_CONTAINER(filter_box), 10);
- filter_label=gtk_label_new("Filter:");
- gtk_box_pack_start(GTK_BOX(filter_box), filter_label, FALSE, FALSE, 0);
- gtk_widget_show(filter_label);
-
- filter_entry=gtk_entry_new_with_max_length(250);
- gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, FALSE, FALSE, 0);
- gtk_widget_show(filter_entry);
+ gtk_widget_show_all(sp->win);
+ window_present(sp->win);
- gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
- gtk_widget_show(filter_box);
-
-
- /* the start button */
- start_button=gtk_button_new_with_label("Create Stat");
- SIGNAL_CONNECT_OBJECT(start_button, "clicked",
- wspstat_start_button_clicked, NULL);
- gtk_box_pack_start(GTK_BOX(dlg_box), start_button, TRUE, TRUE, 0);
- gtk_widget_show(start_button);
-
- gtk_widget_show_all(dlg);
+ cf_retap_packets(&cfile, FALSE);
}
+static tap_dfilter_dlg wsp_stat_dlg = {
+ "WAP-WSP Packet Counter",
+ "wsp,stat",
+ gtk_wspstat_init,
+ -1
+};
void
register_tap_listener_gtkwspstat(void)
{
- register_ethereal_tap("wsp,stat,", gtk_wspstat_init);
-}
-
-void
-register_tap_menu_gtkwspstat(void)
-{
- register_tap_menu_item("Statistics/Watch protocol/WAP-WSP", gtk_wspstat_cb);
+ register_dfilter_stat(&wsp_stat_dlg, "WAP-WSP",
+ REGISTER_STAT_GROUP_TELEPHONY);
}