Fix build by #if 0 out unused de_sgsap_tmsi() function.
[obnox/wireshark/wip.git] / gtk / ldap_stat.c
index ae56cbaef2ae47278c73c8b825f5b5fa8a036500..12838cc84f74f76e63fcdf9b2f269339488b0fe3 100644 (file)
@@ -1,10 +1,10 @@
 /* ldap_stat.c
  * ldap_stat   2003 Ronnie Sahlberg
  *
- * $Id: ldap_stat.c,v 1.1 2003/11/05 09:04:51 sahlberg 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 <stdio.h>
-
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
 
-#include <gtk/gtk.h>
 #include <string.h>
-#include "../epan/packet_info.h"
-#include "../epan/epan.h"
-#include "menu.h"
-#include "../tap.h"
-#include "../epan/value_string.h"
-#include "../packet-ldap.h"
-#include "../register.h"
+
+#include <gtk/gtk.h>
+
+#include <epan/packet_info.h>
+#include <epan/epan.h>
+#include <epan/value_string.h>
+#include <epan/tap.h>
+#include <epan/dissectors/packet-ldap.h>
+
 #include "../timestats.h"
-#include "compat_macros.h"
 #include "../simple_dialog.h"
-#include "dlg_utils.h"
 #include "../file.h"
-#include "../globals.h"
-#include "filter_prefs.h"
-#include "service_response_time_table.h"
+#include "../stat_menu.h"
+
+#include "gtk/gui_utils.h"
+#include "gtk/dlg_utils.h"
+#include "gtk/filter_dlg.h"
+#include "gtk/service_response_time_table.h"
+#include "gtk/tap_dfilter_dlg.h"
+#include "gtk/gtkglobals.h"
+#include "gtk/main.h"
 
-extern GtkWidget   *main_display_filter_widget;
 
 /* used to keep track of the statistics for an entire program interface */
 typedef struct _ldapstat_t {
@@ -79,9 +81,9 @@ ldapstat_reset(void *pldap)
 }
 
 static int
-ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, void *psi)
+ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
 {
-       ldap_call_response_t *ldap=(ldap_call_response_t *)psi;
+       const ldap_call_response_t *ldap=psi;
        ldapstat_t *fs=(ldapstat_t *)pldap;
 
        /* we are only interested in reply packets */
@@ -89,7 +91,7 @@ ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, void *
                return 0;
        }
        /* if we havnt seen the request, just ignore it */
-       if(!ldap->req_frame){ 
+       if(!ldap->req_frame){
                return 0;
        }
 
@@ -124,8 +126,6 @@ ldapstat_draw(void *pldap)
 }
 
 
-void protect_thread_critical_region(void);
-void unprotect_thread_critical_region(void);
 static void
 win_destroy_cb(GtkWindow *win _U_, gpointer data)
 {
@@ -141,14 +141,16 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
 
 
 static void
-gtk_ldapstat_init(char *optarg)
+gtk_ldapstat_init(const char *optarg, void *userdata _U_)
 {
        ldapstat_t *ldap;
-       char *filter=NULL;
+       const char *filter=NULL;
        GtkWidget *label;
-       char filter_string[256];
+       char *filter_string;
        GString *error_string;
        GtkWidget *vbox;
+       GtkWidget *bbox;
+       GtkWidget *close_bt;
 
        if(!strncmp(optarg,"ldap,srt,",9)){
                filter=optarg+9;
@@ -158,32 +160,29 @@ gtk_ldapstat_init(char *optarg)
 
        ldap=g_malloc(sizeof(ldapstat_t));
 
-       ldap->win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       ldap->win = dlg_window_new("ldap-stat");
+       gtk_window_set_destroy_with_parent (GTK_WINDOW(ldap->win), TRUE);
        gtk_window_set_default_size(GTK_WINDOW(ldap->win), 550, 400);
        ldapstat_set_title(ldap);
-       SIGNAL_CONNECT(ldap->win, "destroy", win_destroy_cb, ldap);
 
-       vbox=gtk_vbox_new(FALSE, 0);
+       vbox=gtk_vbox_new(FALSE, 3);
        gtk_container_add(GTK_CONTAINER(ldap->win), vbox);
-       gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
-       gtk_widget_show(vbox);
+       gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
 
        label=gtk_label_new("LDAP Service Response Time statistics");
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-       gtk_widget_show(label);
 
-       snprintf(filter_string,255,"Filter:%s",filter?filter:"");
+       filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
        label=gtk_label_new(filter_string);
+       g_free(filter_string);
+       gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-       gtk_widget_show(label);
-
 
        label=gtk_label_new("LDAP Commands");
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-       gtk_widget_show(label);
 
        /* We must display TOP LEVEL Widget before calling init_srt_table() */
-       gtk_widget_show(ldap->win);
+       gtk_widget_show_all(ldap->win);
 
        init_srt_table(&ldap->ldap_srt_table, 24, vbox, NULL);
        init_srt_table_row(&ldap->ldap_srt_table, 0, "Bind");
@@ -212,157 +211,41 @@ gtk_ldapstat_init(char *optarg)
        init_srt_table_row(&ldap->ldap_srt_table, 23, "Extended");
 
 
-       error_string=register_tap_listener("ldap", ldap, filter, ldapstat_reset, ldapstat_packet, ldapstat_draw);
+       error_string=register_tap_listener("ldap", ldap, filter, 0, ldapstat_reset, ldapstat_packet, ldapstat_draw);
        if(error_string){
-               simple_dialog(ESD_TYPE_WARN, NULL, error_string->str);
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
                g_string_free(error_string, TRUE);
                g_free(ldap);
                return;
        }
 
-       gtk_widget_show_all(ldap->win);
-       redissect_packets(&cfile);
-}
+       /* Button row. */
+       bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
+       gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
 
+       close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
+       window_set_cancel_button(ldap->win, close_bt, window_cancel_button_cb);
 
+       g_signal_connect(ldap->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
+       g_signal_connect(ldap->win, "destroy", G_CALLBACK(win_destroy_cb), ldap);
 
-static GtkWidget *dlg=NULL;
-static GtkWidget *filter_entry;
-
-static void
-dlg_destroy_cb(void)
-{
-       dlg=NULL;
-}
-
-static void
-dlg_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
-{
-       gtk_widget_destroy(GTK_WIDGET(parent_w));
-}
-
-static void
-ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
-{
-       GString *str;
-       char *filter;
+       gtk_widget_show_all(ldap->win);
+       window_present(ldap->win);
 
-       str = g_string_new("ldap,srt");
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
-       if(filter[0]!=0){
-               g_string_sprintfa(str,",%s", filter);
-       }
-       gtk_ldapstat_init(str->str);
-       g_string_free(str, TRUE);
+       cf_retap_packets(&cfile);
+       gdk_window_raise(ldap->win->window);
 }
 
-static void
-gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
-{
-       GtkWidget *dlg_box;
-       GtkWidget *filter_box, *filter_bt;
-       GtkWidget *bbox, *start_button, *cancel_button;
-       char *filter;
-       static construct_args_t args = {
-         "Service Response Time Statistics Filter",
-         TRUE,
-         FALSE
-       };
-
-       /* if the window is already open, bring it to front */
-       if(dlg){
-               gdk_window_raise(dlg->window);
-               return;
-       }
-
-       dlg=dlg_window_new("Ethereal: Compute LDAP Service Response Time statistics");
-       SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
-
-       dlg_box=gtk_vbox_new(FALSE, 10);
-       gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
-       gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
-       gtk_widget_show(dlg_box);
-
-       /* Filter box */
-       filter_box=gtk_hbox_new(FALSE, 3);
-
-       /* Filter button */
-       filter_bt=gtk_button_new_with_label("Filter:");
-       SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
-       gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, FALSE, 0);
-       gtk_widget_show(filter_bt);
-
-       /* Filter entry */
-       filter_entry=gtk_entry_new();
-       gtk_widget_set_usize(filter_entry, 300, -2);
-
-       /* filter prefs dialog */
-       OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_entry);
-       /* filter prefs dialog */
-
-       gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
-       filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
-       if(filter){
-               gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
-       }
-       gtk_widget_show(filter_entry);
-
-       gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
-       gtk_widget_show(filter_box);
-
-       /* button box */
-       bbox=gtk_hbutton_box_new();
-       gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_DEFAULT_STYLE);
-       gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
-       gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
-       gtk_widget_show(bbox);
-
-       /* the start button */
-       start_button=gtk_button_new_with_label("Create Stat");
-        SIGNAL_CONNECT_OBJECT(start_button, "clicked",
-                              ldapstat_start_button_clicked, NULL);
-       gtk_box_pack_start(GTK_BOX(bbox), start_button, TRUE, TRUE, 0);
-       GTK_WIDGET_SET_FLAGS(start_button, GTK_CAN_DEFAULT);
-       gtk_widget_grab_default(start_button);
-       gtk_widget_show(start_button);
-
-#if GTK_MAJOR_VERSION < 2
-       cancel_button=gtk_button_new_with_label("Cancel");
-#else
-       cancel_button=gtk_button_new_from_stock(GTK_STOCK_CANCEL);
-#endif
-       SIGNAL_CONNECT(cancel_button, "clicked", dlg_cancel_cb, dlg);
-       GTK_WIDGET_SET_FLAGS(cancel_button, GTK_CAN_DEFAULT);
-       gtk_box_pack_start(GTK_BOX(bbox), cancel_button, TRUE, TRUE, 0);
-       gtk_widget_show(cancel_button);
-
-       /* Catch the "activate" signal on the filter text entry, so that
-          if the user types Return there, we act as if the "Create Stat"
-          button had been selected, as happens if Return is typed if some
-          widget that *doesn't* handle the Return key has the input
-          focus. */
-       dlg_set_activate(filter_entry, start_button);
-
-       /* Catch the "key_press_event" signal in the window, so that we can
-          catch the ESC key being pressed and act as if the "Cancel" button
-          had been selected. */
-       dlg_set_cancel(dlg, cancel_button);
-
-       /* Give the initial focus to the "Filter" entry box. */
-       gtk_widget_grab_focus(filter_entry);
-
-       gtk_widget_show_all(dlg);
-}
+static tap_dfilter_dlg ldap_stat_dlg = {
+       "LDAP Service Response Time Statistics",
+       "ldap,srt",
+       gtk_ldapstat_init,
+       -1
+};
 
 void
 register_tap_listener_gtkldapstat(void)
 {
-       register_ethereal_tap("ldap,srt", gtk_ldapstat_init);
-}
-
-void
-register_tap_menu_gtkldapstat(void)
-{
-       register_tap_menu_item("Statistics/Service Response Time/LDAP...",
-           gtk_ldapstat_cb, NULL, NULL);
+       register_dfilter_stat(&ldap_stat_dlg, "LDAP",
+           REGISTER_STAT_GROUP_RESPONSE_TIME);
 }