Rename the tap_dfilter_dlg.[ch] files to reflect that they can do more
[obnox/wireshark/wip.git] / gtk / radius_stat.c
index 3b881bd795288ccb9b4e321a2ca2eb56ef30bf5b..353a00883e40084560618eb6e043e7a43273e832 100644 (file)
 #include <epan/tap.h>
 #include <epan/dissectors/packet-radius.h>
 
-#include "../register.h"
 #include "../timestats.h"
 #include "../simple_dialog.h"
 #include "../file.h"
-#include "../globals.h"
 #include "../stat_menu.h"
 
 #include "gtk/gui_stat_util.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/tap_dfilter_dlg.h"
+#include "gtk/tap_param_dlg.h"
 #include "gtk/gui_utils.h"
 #include "gtk/main.h"
 
@@ -73,7 +71,7 @@ typedef struct _radiusstat_t {
        GtkWidget *vbox;
        char *filter;
        GtkWidget *scrolled_window;
-       GtkCList *table;
+       GtkTreeView *table;
        radius_rtd_t radius_rtd[NUM_TIMESTATS];
 } radiusstat_t;
 
@@ -83,7 +81,7 @@ static const value_string radius_message_code[] = {
   {  2,        "Accounting"},
   {  3,        "Access Password"},
   {  4, "Ascend Access Event"},
-  {  5, "Diconnect"},
+  {  5, "Disconnect"},
   {  6, "Change Filter"},
   {  7, "Other"},
   {  0, NULL}
@@ -230,41 +228,41 @@ radiusstat_draw(void *prs)
 {
        radiusstat_t *rs=(radiusstat_t *)prs;
        int i;
-       char *str[NUM_COLUMNS];
-
-       for(i=0;i<NUM_COLUMNS;i++) {
-               str[i]=g_malloc(sizeof(char[256]));
-       }
+       char str[5][256];
+       GtkListStore *store;
+       GtkTreeIter iter;
 
        /* clear list before printing */
-       gtk_clist_clear(rs->table);
+       store = GTK_LIST_STORE(gtk_tree_view_get_model(rs->table));
+       gtk_list_store_clear(store);
 
        for(i=0;i<NUM_TIMESTATS;i++) {
                /* nothing seen, nothing to do */
                if(rs->radius_rtd[i].stats.num==0){
                        continue;
                }
-
-               g_snprintf(str[0], sizeof(char[256]), "%s", val_to_str(i,radius_message_code,"Other"));
-               g_snprintf(str[1], sizeof(char[256]), "%d", rs->radius_rtd[i].stats.num);
-               g_snprintf(str[2], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(rs->radius_rtd[i].stats.min)));
-               g_snprintf(str[3], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(rs->radius_rtd[i].stats.max)));
-               g_snprintf(str[4], sizeof(char[256]), "%8.2f msec", get_average(&(rs->radius_rtd[i].stats.tot), rs->radius_rtd[i].stats.num));
-               g_snprintf(str[5], sizeof(char[256]), "%6u", rs->radius_rtd[i].stats.min_num);
-               g_snprintf(str[6], sizeof(char[256]), "%6u", rs->radius_rtd[i].stats.max_num);
-               g_snprintf(str[7], sizeof(char[256]), "%4u", rs->radius_rtd[i].open_req_num);
-               g_snprintf(str[8], sizeof(char[256]), "%4u", rs->radius_rtd[i].disc_rsp_num);
-               g_snprintf(str[9], sizeof(char[256]), "%4u (%4.2f%%)", rs->radius_rtd[i].req_dup_num,
+               g_snprintf(str[0], 256, "%8.2f msec", nstime_to_msec(&(rs->radius_rtd[i].stats.min)));
+               g_snprintf(str[1], 256, "%8.2f msec", nstime_to_msec(&(rs->radius_rtd[i].stats.max)));
+               g_snprintf(str[2], 256, "%8.2f msec", get_average(&(rs->radius_rtd[i].stats.tot), rs->radius_rtd[i].stats.num));
+               g_snprintf(str[3], 256, "%4u (%4.2f%%)", rs->radius_rtd[i].req_dup_num,
                        rs->radius_rtd[i].stats.num?((double)rs->radius_rtd[i].req_dup_num*100)/(double)rs->radius_rtd[i].stats.num:0);
-               g_snprintf(str[10], sizeof(char[256]), "%4u (%4.2f%%)", rs->radius_rtd[i].rsp_dup_num,
+               g_snprintf(str[4], 256, "%4u (%4.2f%%)", rs->radius_rtd[i].rsp_dup_num,
                        rs->radius_rtd[i].stats.num?((double)rs->radius_rtd[i].rsp_dup_num*100)/(double)rs->radius_rtd[i].stats.num:0);
 
-               gtk_clist_append(rs->table, str);
-       }
-
-       gtk_widget_show(GTK_WIDGET(rs->table));
-       for(i=0;i<NUM_COLUMNS;i++) {
-               g_free(str[i]);
+               gtk_list_store_append(store, &iter);
+               gtk_list_store_set(store, &iter,
+                       0, val_to_str(i, radius_message_code,"Other"),
+                       1, rs->radius_rtd[i].stats.num,
+                       2, str[0],
+                       3, str[1],
+                       4, str[2],
+                       5, rs->radius_rtd[i].stats.min_num,
+                       6, rs->radius_rtd[i].stats.max_num,
+                       7, rs->radius_rtd[i].open_req_num,
+                       8, rs->radius_rtd[i].disc_rsp_num,
+                       9, str[3],
+                       10, str[4],
+                       -1);
        }
 }
 
@@ -284,54 +282,54 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
        g_free(rs);
 }
 
-static const gchar *titles[]={
-                       "Type",
-                       "Messages",
-                       "Min SRT",
-                       "Max SRT",
-                       "Avg SRT",
-                       "Min in Frame",
-                       "Max in Frame",
-                       "Open Requests",
-                       "Discarded Responses",
-                       "Repeated Requests",
-                       "Repeated Responses" };
+static const stat_column titles[]={
+       {G_TYPE_STRING, LEFT,  "Type" },
+       {G_TYPE_UINT, RIGHT,   "Messages" },
+       {G_TYPE_STRING, RIGHT, "Min SRT" },
+       {G_TYPE_STRING, RIGHT, "Max SRT" },
+       {G_TYPE_STRING, RIGHT, "Avg SRT" },
+       {G_TYPE_UINT, RIGHT,   "Min in Frame" },
+       {G_TYPE_UINT, RIGHT,   "Max in Frame" },
+       {G_TYPE_UINT, RIGHT,   "Open Requests" },
+       {G_TYPE_UINT, RIGHT,   "Discarded Responses" },
+       {G_TYPE_STRING, RIGHT, "Repeated Requests" },
+       {G_TYPE_STRING, RIGHT, "Repeated Responses"}
+};
 
 static void
 gtk_radiusstat_init(const char *optarg, void *userdata _U_)
 {
        radiusstat_t *rs;
-       const char *filter=NULL;
        GString *error_string;
        GtkWidget *bt_close;
        GtkWidget *bbox;
 
+       rs=g_malloc(sizeof(radiusstat_t));
+
        if(strncmp(optarg,"radius,srt,",11) == 0){
-               filter=optarg+11;
+               rs->filter=g_strdup(optarg+11);
        } else {
-               filter="";
+               rs->filter=NULL;
        }
 
-       rs=g_malloc(sizeof(radiusstat_t));
-       rs->filter=g_strdup(filter);
-
        radiusstat_reset(rs);
 
-       rs->win=window_new(GTK_WINDOW_TOPLEVEL, "RADIUS SRT");
+       rs->win = dlg_window_new("RADIUS SRT");  /* transient_for top_level */
+       gtk_window_set_destroy_with_parent (GTK_WINDOW(rs->win), TRUE);
        gtk_window_set_default_size(GTK_WINDOW(rs->win), 600, 150);
 
        rs->vbox=gtk_vbox_new(FALSE, 3);
 
-       init_main_stat_window(rs->win, rs->vbox, "RADIUS Service Response Time (SRT) Statistics", filter);
+       init_main_stat_window(rs->win, rs->vbox, "RADIUS Service Response Time (SRT) Statistics", rs->filter);
 
        /* init a scrolled window*/
        rs->scrolled_window = scrolled_window_new(NULL, NULL);
 
        rs->table = create_stat_table(rs->scrolled_window, rs->vbox, NUM_COLUMNS, titles);
 
-       error_string=register_tap_listener("radius", rs, filter, radiusstat_reset, radiusstat_packet, radiusstat_draw);
+       error_string=register_tap_listener("radius", rs, rs->filter, 0, radiusstat_reset, radiusstat_packet, radiusstat_draw);
        if(error_string){
-               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
                g_string_free(error_string, TRUE);
                g_free(rs->filter);
                g_free(rs);
@@ -351,15 +349,21 @@ gtk_radiusstat_init(const char *optarg, void *userdata _U_)
        gtk_widget_show_all(rs->win);
        window_present(rs->win);
 
-       cf_retap_packets(&cfile, FALSE);
+       cf_retap_packets(&cfile);
        gdk_window_raise(rs->win->window);
 }
 
-static tap_dfilter_dlg radius_srt_dlg = {
+static tap_param radius_stat_params[] = {
+       { PARAM_FILTER, "Filter", NULL }
+};
+
+static tap_param_dlg radius_srt_dlg = {
        "RADIUS Service Response Time (SRT) Statistics",
        "radius,srt",
        gtk_radiusstat_init,
-       -1
+       -1,
+       G_N_ELEMENTS(radius_stat_params),
+       radius_stat_params
 };
 
 void