2 * ldap_stat 2003 Ronnie Sahlberg
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.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
37 #include <epan/packet_info.h>
38 #include <epan/epan.h>
39 #include <epan/value_string.h>
42 #include "stat_menu.h"
44 #include <epan/dissectors/packet-ldap.h>
45 #include "../register.h"
46 #include "../timestats.h"
47 #include "compat_macros.h"
48 #include "../simple_dialog.h"
50 #include "dlg_utils.h"
52 #include "../globals.h"
53 #include "filter_dlg.h"
54 #include "service_response_time_table.h"
55 #include "gtkglobals.h"
58 /* used to keep track of the statistics for an entire program interface */
59 typedef struct _ldapstat_t {
61 srt_stat_table ldap_srt_table;
65 ldapstat_set_title(ldapstat_t *ldap)
69 title = g_strdup_printf("LDAP Service Response Time statistics: %s",
70 cf_get_display_name(&cfile));
71 gtk_window_set_title(GTK_WINDOW(ldap->win), title);
76 ldapstat_reset(void *pldap)
78 ldapstat_t *ldap=(ldapstat_t *)pldap;
80 reset_srt_table_data(&ldap->ldap_srt_table);
81 ldapstat_set_title(ldap);
85 ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
87 const ldap_call_response_t *ldap=psi;
88 ldapstat_t *fs=(ldapstat_t *)pldap;
90 /* we are only interested in reply packets */
94 /* if we havnt seen the request, just ignore it */
99 /* only use the commands we know how to handle */
100 switch(ldap->protocolOpTag){
102 case LDAP_REQ_SEARCH:
103 case LDAP_REQ_MODIFY:
105 case LDAP_REQ_DELETE:
106 case LDAP_REQ_MODRDN:
107 case LDAP_REQ_COMPARE:
108 case LDAP_REQ_EXTENDED:
114 add_srt_table_data(&fs->ldap_srt_table, ldap->protocolOpTag, &ldap->req_time, pinfo);
122 ldapstat_draw(void *pldap)
124 ldapstat_t *ldap=(ldapstat_t *)pldap;
126 draw_srt_table_data(&ldap->ldap_srt_table);
130 void protect_thread_critical_region(void);
131 void unprotect_thread_critical_region(void);
133 win_destroy_cb(GtkWindow *win _U_, gpointer data)
135 ldapstat_t *ldap=(ldapstat_t *)data;
137 protect_thread_critical_region();
138 remove_tap_listener(ldap);
139 unprotect_thread_critical_region();
141 free_srt_table_data(&ldap->ldap_srt_table);
147 gtk_ldapstat_init(const char *optarg)
150 const char *filter=NULL;
152 char filter_string[256];
153 GString *error_string;
158 if(!strncmp(optarg,"ldap,srt,",9)){
164 ldap=g_malloc(sizeof(ldapstat_t));
166 ldap->win=window_new(GTK_WINDOW_TOPLEVEL, "ldap-stat");
167 gtk_window_set_default_size(GTK_WINDOW(ldap->win), 550, 400);
168 ldapstat_set_title(ldap);
170 vbox=gtk_vbox_new(FALSE, 3);
171 gtk_container_add(GTK_CONTAINER(ldap->win), vbox);
172 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
174 label=gtk_label_new("LDAP Service Response Time statistics");
175 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
177 g_snprintf(filter_string,255,"Filter:%s",filter?filter:"");
178 label=gtk_label_new(filter_string);
179 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
181 label=gtk_label_new("LDAP Commands");
182 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
184 /* We must display TOP LEVEL Widget before calling init_srt_table() */
185 gtk_widget_show_all(ldap->win);
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");
214 error_string=register_tap_listener("ldap", ldap, filter, ldapstat_reset, ldapstat_packet, ldapstat_draw);
216 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
217 g_string_free(error_string, TRUE);
223 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
224 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
226 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
227 window_set_cancel_button(ldap->win, close_bt, window_cancel_button_cb);
229 SIGNAL_CONNECT(ldap->win, "delete_event", window_delete_event_cb, NULL);
230 SIGNAL_CONNECT(ldap->win, "destroy", win_destroy_cb, ldap);
232 gtk_widget_show_all(ldap->win);
233 window_present(ldap->win);
235 cf_retap_packets(&cfile);
240 static GtkWidget *dlg=NULL;
241 static GtkWidget *filter_entry;
250 ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
255 str = g_string_new("ldap,srt");
256 filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
258 g_string_sprintfa(str,",%s", filter);
260 gtk_ldapstat_init(str->str);
261 g_string_free(str, TRUE);
265 gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
268 GtkWidget *filter_box, *filter_bt;
269 GtkWidget *bbox, *start_button, *cancel_button;
271 static construct_args_t args = {
272 "Service Response Time Statistics Filter",
277 /* if the window is already open, bring it to front */
279 gdk_window_raise(dlg->window);
283 dlg=dlg_window_new("Ethereal: Compute LDAP Service Response Time statistics");
284 gtk_window_set_default_size(GTK_WINDOW(dlg), 300, -1);
286 dlg_box=gtk_vbox_new(FALSE, 10);
287 gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
288 gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
289 gtk_widget_show(dlg_box);
292 filter_box=gtk_hbox_new(FALSE, 3);
295 filter_bt=BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
296 SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
297 gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, FALSE, 0);
298 gtk_widget_show(filter_bt);
301 filter_entry=gtk_entry_new();
302 SIGNAL_CONNECT(filter_entry, "changed", filter_te_syntax_check_cb, NULL);
304 /* filter prefs dialog */
305 OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_entry);
306 /* filter prefs dialog */
308 gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
309 filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
311 gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
313 gtk_widget_show(filter_entry);
315 gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
316 gtk_widget_show(filter_box);
319 bbox = dlg_button_row_new(ETHEREAL_STOCK_CREATE_STAT, GTK_STOCK_CANCEL, NULL);
320 gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
321 gtk_widget_show(bbox);
323 start_button = OBJECT_GET_DATA(bbox, ETHEREAL_STOCK_CREATE_STAT);
324 SIGNAL_CONNECT_OBJECT(start_button, "clicked",
325 ldapstat_start_button_clicked, NULL);
327 cancel_button = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
328 window_set_cancel_button(dlg, cancel_button, window_cancel_button_cb);
330 /* Catch the "activate" signal on the filter text entry, so that
331 if the user types Return there, we act as if the "Create Stat"
332 button had been selected, as happens if Return is typed if some
333 widget that *doesn't* handle the Return key has the input
335 dlg_set_activate(filter_entry, start_button);
337 gtk_widget_grab_default(start_button );
339 /* Give the initial focus to the "Filter" entry box. */
340 gtk_widget_grab_focus(filter_entry);
342 SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
344 gtk_widget_show_all(dlg);
349 register_tap_listener_gtkldapstat(void)
351 register_stat_cmd_arg("ldap,srt", gtk_ldapstat_init);
353 register_stat_menu_item("LDAP...", REGISTER_STAT_GROUP_RESPONSE_TIME,
354 gtk_ldapstat_cb, NULL, NULL, NULL);