2 * ldap_stat 2003 Ronnie Sahlberg
4 * $Id: ldap_stat.c,v 1.9 2004/01/21 21:19:33 ulfl Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
37 #include "../epan/packet_info.h"
38 #include "../epan/epan.h"
41 #include "../epan/value_string.h"
42 #include "../packet-ldap.h"
43 #include "../register.h"
44 #include "../timestats.h"
45 #include "compat_macros.h"
46 #include "../simple_dialog.h"
47 #include "dlg_utils.h"
49 #include "../globals.h"
50 #include "filter_prefs.h"
51 #include "service_response_time_table.h"
53 extern GtkWidget *main_display_filter_widget;
55 /* used to keep track of the statistics for an entire program interface */
56 typedef struct _ldapstat_t {
58 srt_stat_table ldap_srt_table;
62 ldapstat_set_title(ldapstat_t *ldap)
66 title = g_strdup_printf("LDAP Service Response Time statistics: %s",
67 cf_get_display_name(&cfile));
68 gtk_window_set_title(GTK_WINDOW(ldap->win), title);
73 ldapstat_reset(void *pldap)
75 ldapstat_t *ldap=(ldapstat_t *)pldap;
77 reset_srt_table_data(&ldap->ldap_srt_table);
78 ldapstat_set_title(ldap);
82 ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, void *psi)
84 ldap_call_response_t *ldap=(ldap_call_response_t *)psi;
85 ldapstat_t *fs=(ldapstat_t *)pldap;
87 /* we are only interested in reply packets */
91 /* if we havnt seen the request, just ignore it */
96 /* only use the commands we know how to handle */
97 switch(ldap->protocolOpTag){
100 case LDAP_REQ_MODIFY:
102 case LDAP_REQ_DELETE:
103 case LDAP_REQ_MODRDN:
104 case LDAP_REQ_COMPARE:
105 case LDAP_REQ_EXTENDED:
111 add_srt_table_data(&fs->ldap_srt_table, ldap->protocolOpTag, &ldap->req_time, pinfo);
119 ldapstat_draw(void *pldap)
121 ldapstat_t *ldap=(ldapstat_t *)pldap;
123 draw_srt_table_data(&ldap->ldap_srt_table);
127 void protect_thread_critical_region(void);
128 void unprotect_thread_critical_region(void);
130 win_destroy_cb(GtkWindow *win _U_, gpointer data)
132 ldapstat_t *ldap=(ldapstat_t *)data;
134 protect_thread_critical_region();
135 remove_tap_listener(ldap);
136 unprotect_thread_critical_region();
138 free_srt_table_data(&ldap->ldap_srt_table);
144 gtk_ldapstat_init(char *optarg)
149 char filter_string[256];
150 GString *error_string;
153 if(!strncmp(optarg,"ldap,srt,",9)){
159 ldap=g_malloc(sizeof(ldapstat_t));
161 ldap->win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
162 gtk_window_set_default_size(GTK_WINDOW(ldap->win), 550, 400);
163 ldapstat_set_title(ldap);
164 SIGNAL_CONNECT(ldap->win, "destroy", win_destroy_cb, ldap);
166 vbox=gtk_vbox_new(FALSE, 0);
167 gtk_container_add(GTK_CONTAINER(ldap->win), vbox);
168 gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
169 gtk_widget_show(vbox);
171 label=gtk_label_new("LDAP Service Response Time statistics");
172 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
173 gtk_widget_show(label);
175 snprintf(filter_string,255,"Filter:%s",filter?filter:"");
176 label=gtk_label_new(filter_string);
177 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
178 gtk_widget_show(label);
181 label=gtk_label_new("LDAP Commands");
182 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
183 gtk_widget_show(label);
185 /* We must display TOP LEVEL Widget before calling init_srt_table() */
186 gtk_widget_show(ldap->win);
188 init_srt_table(&ldap->ldap_srt_table, 24, vbox, NULL);
189 init_srt_table_row(&ldap->ldap_srt_table, 0, "Bind");
190 init_srt_table_row(&ldap->ldap_srt_table, 1, "<unknown>");
191 init_srt_table_row(&ldap->ldap_srt_table, 2, "<unknown>");
192 init_srt_table_row(&ldap->ldap_srt_table, 3, "Search");
193 init_srt_table_row(&ldap->ldap_srt_table, 4, "<unknown>");
194 init_srt_table_row(&ldap->ldap_srt_table, 5, "<unknown>");
195 init_srt_table_row(&ldap->ldap_srt_table, 6, "Modify");
196 init_srt_table_row(&ldap->ldap_srt_table, 7, "<unknown>");
197 init_srt_table_row(&ldap->ldap_srt_table, 8, "Add");
198 init_srt_table_row(&ldap->ldap_srt_table, 9, "<unknown>");
199 init_srt_table_row(&ldap->ldap_srt_table, 10, "Delete");
200 init_srt_table_row(&ldap->ldap_srt_table, 11, "<unknown>");
201 init_srt_table_row(&ldap->ldap_srt_table, 12, "Modrdn");
202 init_srt_table_row(&ldap->ldap_srt_table, 13, "<unknown>");
203 init_srt_table_row(&ldap->ldap_srt_table, 14, "Compare");
204 init_srt_table_row(&ldap->ldap_srt_table, 15, "<unknown>");
205 init_srt_table_row(&ldap->ldap_srt_table, 16, "<unknown>");
206 init_srt_table_row(&ldap->ldap_srt_table, 17, "<unknown>");
207 init_srt_table_row(&ldap->ldap_srt_table, 18, "<unknown>");
208 init_srt_table_row(&ldap->ldap_srt_table, 19, "<unknown>");
209 init_srt_table_row(&ldap->ldap_srt_table, 20, "<unknown>");
210 init_srt_table_row(&ldap->ldap_srt_table, 21, "<unknown>");
211 init_srt_table_row(&ldap->ldap_srt_table, 22, "<unknown>");
212 init_srt_table_row(&ldap->ldap_srt_table, 23, "Extended");
215 error_string=register_tap_listener("ldap", ldap, filter, ldapstat_reset, ldapstat_packet, ldapstat_draw);
217 simple_dialog(ESD_TYPE_WARN, NULL, error_string->str);
218 g_string_free(error_string, TRUE);
223 gtk_widget_show_all(ldap->win);
224 retap_packets(&cfile);
229 static GtkWidget *dlg=NULL;
230 static GtkWidget *filter_entry;
239 dlg_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
241 gtk_widget_destroy(GTK_WIDGET(parent_w));
245 ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
250 str = g_string_new("ldap,srt");
251 filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
253 g_string_sprintfa(str,",%s", filter);
255 gtk_ldapstat_init(str->str);
256 g_string_free(str, TRUE);
260 gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
263 GtkWidget *filter_box, *filter_bt;
264 GtkWidget *bbox, *start_button, *cancel_button;
266 static construct_args_t args = {
267 "Service Response Time Statistics Filter",
272 /* if the window is already open, bring it to front */
274 gdk_window_raise(dlg->window);
278 dlg=dlg_window_new("Ethereal: Compute LDAP Service Response Time statistics");
279 SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
281 dlg_box=gtk_vbox_new(FALSE, 10);
282 gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
283 gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
284 gtk_widget_show(dlg_box);
287 filter_box=gtk_hbox_new(FALSE, 3);
290 filter_bt=BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
291 SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
292 gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, FALSE, 0);
293 gtk_widget_show(filter_bt);
296 filter_entry=gtk_entry_new();
297 WIDGET_SET_SIZE(filter_entry, 300, -2);
299 /* filter prefs dialog */
300 OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_entry);
301 /* filter prefs dialog */
303 gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
304 filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
306 gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
308 gtk_widget_show(filter_entry);
310 gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
311 gtk_widget_show(filter_box);
314 bbox = dlg_button_row_new(ETHEREAL_STOCK_CREATE_STAT, GTK_STOCK_CANCEL, NULL);
315 gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
316 gtk_widget_show(bbox);
318 start_button = OBJECT_GET_DATA(bbox, ETHEREAL_STOCK_CREATE_STAT);
319 gtk_widget_grab_default(start_button );
320 SIGNAL_CONNECT_OBJECT(start_button, "clicked",
321 ldapstat_start_button_clicked, NULL);
323 cancel_button = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
324 SIGNAL_CONNECT(cancel_button, "clicked", dlg_cancel_cb, dlg);
326 /* Catch the "activate" signal on the filter text entry, so that
327 if the user types Return there, we act as if the "Create Stat"
328 button had been selected, as happens if Return is typed if some
329 widget that *doesn't* handle the Return key has the input
331 dlg_set_activate(filter_entry, start_button);
333 /* Catch the "key_press_event" signal in the window, so that we can
334 catch the ESC key being pressed and act as if the "Cancel" button
335 had been selected. */
336 dlg_set_cancel(dlg, cancel_button);
338 /* Give the initial focus to the "Filter" entry box. */
339 gtk_widget_grab_focus(filter_entry);
341 gtk_widget_show_all(dlg);
345 register_tap_listener_gtkldapstat(void)
347 register_ethereal_tap("ldap,srt", gtk_ldapstat_init);
351 register_tap_menu_gtkldapstat(void)
353 register_tap_menu_item("_Statistics/Service Response Time/LDAP...",
354 gtk_ldapstat_cb, NULL, NULL, NULL);