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>
42 #include <epan/dissectors/packet-ldap.h>
43 #include "../register.h"
44 #include "../timestats.h"
45 #include "compat_macros.h"
46 #include "../simple_dialog.h"
47 #include "gui_utils.h"
48 #include "dlg_utils.h"
50 #include "../globals.h"
51 #include "filter_dlg.h"
52 #include "service_response_time_table.h"
53 #include "../stat_menu.h"
54 #include "../tap_dfilter_dlg.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, void *userdata _U_)
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, FALSE);
238 static tap_dfilter_dlg ldap_stat_dlg = {
239 "LDAP Service Response Time Statistics",
246 register_tap_listener_gtkldapstat(void)
248 register_dfilter_stat(&ldap_stat_dlg, "LDAP",
249 REGISTER_STAT_GROUP_RESPONSE_TIME);