2 * ldap_stat 2003 Ronnie Sahlberg
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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>
41 #include <epan/dissectors/packet-ldap.h>
43 #include "../timestats.h"
44 #include "../simple_dialog.h"
46 #include "../stat_menu.h"
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"
55 #include "gtk/old-gtk-compat.h"
57 /* used to keep track of the statistics for an entire program interface */
58 typedef struct _ldapstat_t {
60 srt_stat_table ldap_srt_table;
64 ldapstat_set_title(ldapstat_t *ldap)
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);
75 ldapstat_reset(void *pldap)
77 ldapstat_t *ldap=(ldapstat_t *)pldap;
79 reset_srt_table_data(&ldap->ldap_srt_table);
80 ldapstat_set_title(ldap);
84 ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
86 const ldap_call_response_t *ldap=psi;
87 ldapstat_t *fs=(ldapstat_t *)pldap;
89 /* we are only interested in reply packets */
93 /* if we havnt seen the request, just ignore it */
98 /* only use the commands we know how to handle */
99 switch(ldap->protocolOpTag){
101 case LDAP_REQ_SEARCH:
102 case LDAP_REQ_MODIFY:
104 case LDAP_REQ_DELETE:
105 case LDAP_REQ_MODRDN:
106 case LDAP_REQ_COMPARE:
107 case LDAP_REQ_EXTENDED:
113 add_srt_table_data(&fs->ldap_srt_table, ldap->protocolOpTag, &ldap->req_time, pinfo);
121 ldapstat_draw(void *pldap)
123 ldapstat_t *ldap=(ldapstat_t *)pldap;
125 draw_srt_table_data(&ldap->ldap_srt_table);
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(const char *optarg, void *userdata _U_)
147 const char *filter=NULL;
150 GString *error_string;
155 if(!strncmp(optarg,"ldap,srt,",9)){
161 ldap=g_malloc(sizeof(ldapstat_t));
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);
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);
172 label=gtk_label_new("LDAP Service Response Time statistics");
173 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
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);
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, 0, ldapstat_reset, ldapstat_packet, ldapstat_draw);
216 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", 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 = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
227 window_set_cancel_button(ldap->win, close_bt, window_cancel_button_cb);
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);
232 gtk_widget_show_all(ldap->win);
233 window_present(ldap->win);
235 cf_retap_packets(&cfile);
236 gdk_window_raise(gtk_widget_get_window(ldap->win));
239 static tap_param ldap_stat_params[] = {
240 { PARAM_FILTER, "Filter", NULL }
243 static tap_param_dlg ldap_stat_dlg = {
244 "LDAP Service Response Time Statistics",
248 G_N_ELEMENTS(ldap_stat_params),
253 register_tap_listener_gtkldapstat(void)
255 register_dfilter_stat(&ldap_stat_dlg, "LDAP",
256 REGISTER_STAT_GROUP_RESPONSE_TIME);
258 #ifdef MAIN_MENU_USE_UIMANAGER
259 void ldap_srt_cb(GtkAction *action, gpointer user_data _U_)
261 tap_param_dlg_cb(action, &ldap_stat_dlg);