Removed unused argument to new_packet_list_copy_summary_cb().
[obnox/wireshark/wip.git] / gtk / ldap_stat.c
1 /* ldap_stat.c
2  * ldap_stat   2003 Ronnie Sahlberg
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32
33 #include <string.h>
34
35 #include <gtk/gtk.h>
36
37 #include <epan/packet_info.h>
38 #include <epan/epan.h>
39 #include <epan/value_string.h>
40 #include <epan/tap.h>
41 #include <epan/dissectors/packet-ldap.h>
42
43 #include "../timestats.h"
44 #include "../simple_dialog.h"
45 #include "../file.h"
46 #include "../stat_menu.h"
47
48 #include "gtk/gui_utils.h"
49 #include "gtk/dlg_utils.h"
50 #include "gtk/service_response_time_table.h"
51 #include "gtk/tap_param_dlg.h"
52 #include "gtk/gtkglobals.h"
53 #include "gtk/main.h"
54
55 #include "gtk/old-gtk-compat.h"
56
57 /* used to keep track of the statistics for an entire program interface */
58 typedef struct _ldapstat_t {
59         GtkWidget *win;
60         srt_stat_table ldap_srt_table;
61 } ldapstat_t;
62
63 static void
64 ldapstat_set_title(ldapstat_t *ldap)
65 {
66         char            *title;
67
68         title = g_strdup_printf("LDAP Service Response Time statistics: %s",
69             cf_get_display_name(&cfile));
70         gtk_window_set_title(GTK_WINDOW(ldap->win), title);
71         g_free(title);
72 }
73
74 static void
75 ldapstat_reset(void *pldap)
76 {
77         ldapstat_t *ldap=(ldapstat_t *)pldap;
78
79         reset_srt_table_data(&ldap->ldap_srt_table);
80         ldapstat_set_title(ldap);
81 }
82
83 static int
84 ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
85 {
86         const ldap_call_response_t *ldap=psi;
87         ldapstat_t *fs=(ldapstat_t *)pldap;
88
89         /* we are only interested in reply packets */
90         if(ldap->is_request){
91                 return 0;
92         }
93         /* if we havnt seen the request, just ignore it */
94         if(!ldap->req_frame){
95                 return 0;
96         }
97
98         /* only use the commands we know how to handle */
99         switch(ldap->protocolOpTag){
100         case LDAP_REQ_BIND:
101         case LDAP_REQ_SEARCH:
102         case LDAP_REQ_MODIFY:
103         case LDAP_REQ_ADD:
104         case LDAP_REQ_DELETE:
105         case LDAP_REQ_MODRDN:
106         case LDAP_REQ_COMPARE:
107         case LDAP_REQ_EXTENDED:
108                 break;
109         default:
110                 return 0;
111         }
112
113         add_srt_table_data(&fs->ldap_srt_table, ldap->protocolOpTag, &ldap->req_time, pinfo);
114
115         return 1;
116 }
117
118
119
120 static void
121 ldapstat_draw(void *pldap)
122 {
123         ldapstat_t *ldap=(ldapstat_t *)pldap;
124
125         draw_srt_table_data(&ldap->ldap_srt_table);
126 }
127
128
129 static void
130 win_destroy_cb(GtkWindow *win _U_, gpointer data)
131 {
132         ldapstat_t *ldap=(ldapstat_t *)data;
133
134         protect_thread_critical_region();
135         remove_tap_listener(ldap);
136         unprotect_thread_critical_region();
137
138         free_srt_table_data(&ldap->ldap_srt_table);
139         g_free(ldap);
140 }
141
142
143 static void
144 gtk_ldapstat_init(const char *optarg, void *userdata _U_)
145 {
146         ldapstat_t *ldap;
147         const char *filter=NULL;
148         GtkWidget *label;
149         char *filter_string;
150         GString *error_string;
151         GtkWidget *vbox;
152         GtkWidget *bbox;
153         GtkWidget *close_bt;
154
155         if(!strncmp(optarg,"ldap,srt,",9)){
156                 filter=optarg+9;
157         } else {
158                 filter=NULL;
159         }
160
161         ldap=g_malloc(sizeof(ldapstat_t));
162
163         ldap->win = dlg_window_new("ldap-stat");
164         gtk_window_set_destroy_with_parent (GTK_WINDOW(ldap->win), TRUE);
165         gtk_window_set_default_size(GTK_WINDOW(ldap->win), 550, 400);
166         ldapstat_set_title(ldap);
167
168         vbox=gtk_vbox_new(FALSE, 3);
169         gtk_container_add(GTK_CONTAINER(ldap->win), vbox);
170         gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
171
172         label=gtk_label_new("LDAP Service Response Time statistics");
173         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
174
175         filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
176         label=gtk_label_new(filter_string);
177         g_free(filter_string);
178         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
179         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
180
181         label=gtk_label_new("LDAP Commands");
182         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
183
184         /* We must display TOP LEVEL Widget before calling init_srt_table() */
185         gtk_widget_show_all(ldap->win);
186
187         init_srt_table(&ldap->ldap_srt_table, 24, vbox, NULL);
188         init_srt_table_row(&ldap->ldap_srt_table, 0, "Bind");
189         init_srt_table_row(&ldap->ldap_srt_table, 1, "<unknown>");
190         init_srt_table_row(&ldap->ldap_srt_table, 2, "<unknown>");
191         init_srt_table_row(&ldap->ldap_srt_table, 3, "Search");
192         init_srt_table_row(&ldap->ldap_srt_table, 4, "<unknown>");
193         init_srt_table_row(&ldap->ldap_srt_table, 5, "<unknown>");
194         init_srt_table_row(&ldap->ldap_srt_table, 6, "Modify");
195         init_srt_table_row(&ldap->ldap_srt_table, 7, "<unknown>");
196         init_srt_table_row(&ldap->ldap_srt_table, 8, "Add");
197         init_srt_table_row(&ldap->ldap_srt_table, 9, "<unknown>");
198         init_srt_table_row(&ldap->ldap_srt_table, 10, "Delete");
199         init_srt_table_row(&ldap->ldap_srt_table, 11, "<unknown>");
200         init_srt_table_row(&ldap->ldap_srt_table, 12, "Modrdn");
201         init_srt_table_row(&ldap->ldap_srt_table, 13, "<unknown>");
202         init_srt_table_row(&ldap->ldap_srt_table, 14, "Compare");
203         init_srt_table_row(&ldap->ldap_srt_table, 15, "<unknown>");
204         init_srt_table_row(&ldap->ldap_srt_table, 16, "<unknown>");
205         init_srt_table_row(&ldap->ldap_srt_table, 17, "<unknown>");
206         init_srt_table_row(&ldap->ldap_srt_table, 18, "<unknown>");
207         init_srt_table_row(&ldap->ldap_srt_table, 19, "<unknown>");
208         init_srt_table_row(&ldap->ldap_srt_table, 20, "<unknown>");
209         init_srt_table_row(&ldap->ldap_srt_table, 21, "<unknown>");
210         init_srt_table_row(&ldap->ldap_srt_table, 22, "<unknown>");
211         init_srt_table_row(&ldap->ldap_srt_table, 23, "Extended");
212
213
214         error_string=register_tap_listener("ldap", ldap, filter, 0, ldapstat_reset, ldapstat_packet, ldapstat_draw);
215         if(error_string){
216                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
217                 g_string_free(error_string, TRUE);
218                 g_free(ldap);
219                 return;
220         }
221
222         /* Button row. */
223         bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
224         gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
225
226         close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
227         window_set_cancel_button(ldap->win, close_bt, window_cancel_button_cb);
228
229         g_signal_connect(ldap->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
230         g_signal_connect(ldap->win, "destroy", G_CALLBACK(win_destroy_cb), ldap);
231
232         gtk_widget_show_all(ldap->win);
233         window_present(ldap->win);
234
235         cf_retap_packets(&cfile);
236         gdk_window_raise(gtk_widget_get_window(ldap->win));
237 }
238
239 static tap_param ldap_stat_params[] = {
240         { PARAM_FILTER, "Filter", NULL }
241 };
242
243 static tap_param_dlg ldap_stat_dlg = {
244         "LDAP Service Response Time Statistics",
245         "ldap,srt",
246         gtk_ldapstat_init,
247         -1,
248         G_N_ELEMENTS(ldap_stat_params),
249         ldap_stat_params
250 };
251
252 void
253 register_tap_listener_gtkldapstat(void)
254 {
255         register_dfilter_stat(&ldap_stat_dlg, "LDAP",
256             REGISTER_STAT_GROUP_RESPONSE_TIME);
257 }
258 #ifdef MAIN_MENU_USE_UIMANAGER
259 void ldap_srt_cb(GtkAction *action, gpointer user_data _U_)
260 {
261         tap_param_dlg_cb(action, &ldap_stat_dlg);
262 }
263 #endif