2 * VoIP calls summary addition for Wireshark
6 * Copyright 2004, Ericsson , Spain
7 * By Francisco Alcoba <francisco.alcoba@ericsson.com>
9 * based on h323_calls_dlg.c
10 * Copyright 2004, Iskratel, Ltd, Kranj
11 * By Miha Jemec <m.jemec@iskratel.si>
13 * H323, RTP and Graph Support
14 * By Alejandro Vaquero, alejandro.vaquero@verso.com
15 * Copyright 2005, Verso Technologies Inc.
17 * Wireshark - Network traffic analyzer
18 * By Gerald Combs <gerald@wireshark.org>
19 * Copyright 1998 Gerald Combs
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version 2
24 * of the License, or (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
45 #include "graph_analysis.h"
46 #include "voip_calls_dlg.h"
47 #include "voip_calls.h"
50 #include "epan/filesystem.h"
53 #include <epan/stat_cmd_args.h>
54 #include "../stat_menu.h"
55 #include "gui_stat_menu.h"
56 #include "dlg_utils.h"
57 #include "gui_utils.h"
58 #include "compat_macros.h"
59 #include "gtkglobals.h"
61 #include "image/clist_ascend.xpm"
62 #include "image/clist_descend.xpm"
63 #include "simple_dialog.h"
65 #include <epan/to_str.h>
67 #include <epan/address.h>
68 #include <epan/addr_resolv.h>
69 #include <epan/dissectors/packet-h248.h>
71 #ifdef HAVE_LIBPORTAUDIO
72 #include "rtp_analysis.h"
73 #include "rtp_player.h"
74 #endif /* HAVE_LIBPORTAUDIO */
77 /****************************************************************************/
78 /* pointer to the one and only dialog window */
79 static GtkWidget *voip_calls_dlg = NULL;
81 static GtkWidget *clist = NULL;
82 static GtkWidget *top_label = NULL;
83 static GtkWidget *status_label = NULL;
85 /*static GtkWidet *bt_unselect = NULL;*/
86 static GtkWidget *bt_filter = NULL;
87 static GtkWidget *bt_graph = NULL;
88 #ifdef HAVE_LIBPORTAUDIO
89 static GtkWidget *bt_player = NULL;
90 #endif /* HAVE_LIBPORTAUDIO */
92 static voip_calls_info_t* selected_call_fwd = NULL; /* current selection */
93 static GList *last_list = NULL;
95 static guint32 calls_nb = 0; /* number of displayed calls */
96 static guint32 calls_ns = 0; /* number of selected calls */
98 static graph_analysis_data_t *graph_analysis_data = NULL;
101 #define CALL_COL_START_TIME 0
102 #define CALL_COL_STOP_TIME 1
103 #define CALL_COL_INITIAL_SPEAKER 2
104 #define CALL_COL_FROM 3
105 #define CALL_COL_TO 4
106 #define CALL_COL_PROTOCOL 5
107 #define CALL_COL_PACKETS 6
108 #define CALL_COL_STATE 7
109 #define CALL_COL_COMMENTS 8
110 static const GdkColor COLOR_SELECT = {0, 0x00ff, 0x80ff, 0x80ff};
111 static const GdkColor COLOR_DEFAULT = {0, 0xffff, 0xffff, 0xffff};
113 /****************************************************************************/
114 /* append a line to clist */
115 static void add_to_clist(voip_calls_info_t* strinfo)
117 gchar label_text[256];
119 gchar *data[NUM_COLS];
120 gchar field[NUM_COLS][50];
122 isup_calls_info_t *tmp_isupinfo;
123 h323_calls_info_t *tmp_h323info;
124 gboolean tmp_bool = FALSE;
125 GdkColor color = COLOR_SELECT;
126 for (c=0;c<NUM_COLS;c++){
127 data[c]=&field[c][0];
130 /* strinfo->selected = FALSE;*/
132 g_snprintf(field[CALL_COL_START_TIME], 15, "%i.%03i", strinfo->start_sec, strinfo->start_usec/1000);
133 g_snprintf(field[CALL_COL_STOP_TIME], 15, "%i.%03i", strinfo->stop_sec, strinfo->stop_usec/1000);
134 /* xxx display_signed_time(data[0], sizeof(field[CALL_COL_START_TIME]), strinfo->start_sec, strinfo->start_usec, USECS); */
135 /* display_signed_time(data[1], sizeof(field[CALL_COL_STOP_TIME]), strinfo->stop_sec, strinfo->stop_usec, USECS); */
136 g_snprintf(field[CALL_COL_INITIAL_SPEAKER], 30, "%s", get_addr_name(&(strinfo->initial_speaker)));
137 g_snprintf(field[CALL_COL_FROM], 50, "%s", strinfo->from_identity);
138 g_snprintf(field[CALL_COL_TO], 50, "%s", strinfo->to_identity);
139 g_snprintf(field[CALL_COL_PROTOCOL], 15, "%s", ((strinfo->protocol==VOIP_COMMON)&&strinfo->protocol_name)?strinfo->protocol_name:voip_protocol_name[strinfo->protocol]);
140 g_snprintf(field[CALL_COL_PACKETS], 15, "%u", strinfo->npackets);
141 g_snprintf(field[CALL_COL_STATE], 15, "%s", voip_call_state_name[strinfo->call_state]);
143 /* Add comments based on the protocol */
144 switch(strinfo->protocol){
146 tmp_isupinfo = strinfo->prot_info;
147 g_snprintf(field[CALL_COL_COMMENTS],30, "%i-%i -> %i-%i", tmp_isupinfo->ni, tmp_isupinfo->opc,
148 tmp_isupinfo->ni, tmp_isupinfo->dpc);
151 tmp_h323info = strinfo->prot_info;
152 if (strinfo->call_state == VOIP_CALL_SETUP)
153 tmp_bool = tmp_h323info->is_faststart_Setup;
155 if ((tmp_h323info->is_faststart_Setup == TRUE) && (tmp_h323info->is_faststart_Proc == TRUE)) tmp_bool = TRUE;
156 g_snprintf(field[CALL_COL_COMMENTS],35, "Tunneling: %s Fast Start: %s", (tmp_h323info->is_h245Tunneling==TRUE?"ON":"OFF"),
157 (tmp_bool==TRUE?"ON":"OFF"));
160 field[CALL_COL_COMMENTS][0]='\0';
161 if (strinfo->call_comment)
162 g_snprintf(field[CALL_COL_COMMENTS],30, "%s", strinfo->call_comment);
165 field[CALL_COL_COMMENTS][0]='\0';
169 added_row = gtk_clist_append(GTK_CLIST(clist), data);
171 /* set the background color if selected */
172 if (strinfo->selected) {
174 gtk_clist_set_background(GTK_CLIST(clist), added_row, &color);
177 /* set data pointer of last row to point to user data for that row */
178 gtk_clist_set_row_data(GTK_CLIST(clist), added_row, strinfo);
180 /* Update the top label with the number of detected calls */
182 g_snprintf(label_text, 256,
183 "Detected %d VoIP %s. Selected %d %s.",
185 plurality(calls_nb, "Call", "Calls"),
187 plurality(calls_ns, "Call", "Calls"));
188 gtk_label_set(GTK_LABEL(top_label), label_text);
190 /* Update the status label with the number of total messages */
191 g_snprintf(label_text, 256,
192 "Total: Calls: %d Start packets: %d Completed calls: %d Rejected calls: %d",
193 g_list_length(voip_calls_get_info()->callsinfo_list),
194 voip_calls_get_info()->start_packets,
195 voip_calls_get_info()->completed_calls,
196 voip_calls_get_info()->rejected_calls);
197 gtk_label_set(GTK_LABEL(status_label), label_text);
201 static void voip_calls_remove_tap_listener(void)
203 /* Remove the calls tap listener */
204 remove_tap_listener_sip_calls();
205 remove_tap_listener_isup_calls();
206 remove_tap_listener_mtp3_calls();
207 remove_tap_listener_h225_calls();
208 remove_tap_listener_h245dg_calls();
209 remove_tap_listener_q931_calls();
210 remove_tap_listener_h248_calls();
211 remove_tap_listener_sccp_calls();
212 remove_tap_listener_sdp_calls();
213 remove_tap_listener_rtp();
214 if (find_tap_id("unistim")) {
215 remove_tap_listener_unistim_calls();
217 if (find_tap_id("voip")) {
218 remove_tap_listener_voip_calls();
220 remove_tap_listener_rtp_event();
221 if (find_tap_id("mgcp")) {
222 remove_tap_listener_mgcp_calls();
224 remove_tap_listener_actrace_calls();
225 remove_tap_listener_t38();
228 /****************************************************************************/
230 /****************************************************************************/
232 voip_calls_on_destroy (GtkObject *object _U_,
233 gpointer user_data _U_)
235 /* remove_tap_listeners */
236 voip_calls_remove_tap_listener();
238 /* Clean up memory used by calls tap */
239 voip_calls_dlg_reset(NULL);
241 /* Note that we no longer have a "VoIP Calls" dialog box. */
242 voip_calls_dlg = NULL;
244 graph_analysis_data = NULL;
248 /****************************************************************************/
250 voip_calls_on_unselect (GtkButton *button _U_,
251 gpointer user_data _U_)
253 selected_call_fwd = NULL;
254 gtk_clist_unselect_all(GTK_CLIST(clist));
255 /* gtk_label_set_text(GTK_LABEL(label_fwd), FWD_LABEL_TEXT);
257 /*gtk_widget_set_sensitive(bt_unselect, FALSE);*/
258 gtk_widget_set_sensitive(bt_filter, FALSE);
259 gtk_widget_set_sensitive(bt_graph, FALSE);
260 #ifdef HAVE_LIBPORTAUDIO
261 gtk_widget_set_sensitive(bt_player, FALSE);
262 #endif /* HAVE_LIBPORTAUDIO */
266 /****************************************************************************/
268 voip_calls_on_filter (GtkButton *button _U_,
269 gpointer user_data _U_)
271 const gchar *filter_string;
273 GString *filter_string_fwd;
274 const gchar *filter_prepend;
275 gboolean isFirst = TRUE;
277 guint filter_length = 0;
278 guint max_filter_length = 2048;
279 sip_calls_info_t *tmp_sipinfo;
280 isup_calls_info_t *tmp_isupinfo;
281 h323_calls_info_t *tmp_h323info;
282 h245_address_t *h245_add = NULL;
284 graph_analysis_item_t *gai;
286 if (selected_call_fwd==NULL)
289 filter_string=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
290 filter_length = strlen(filter_string);
292 while ((c = *filter_string++) != '\0') {
293 if (!isspace((guchar)c)) {
294 /* The filter string isn't blank, so there's already
295 an expression; we OR in the new expression */
296 filter_prepend = " or ";
301 filter_string_fwd = g_string_new(filter_prepend);
303 /* look in the Graph and get all the frame_num for this call */
304 g_string_sprintfa(filter_string_fwd, " (");
305 list = g_list_first(voip_calls_get_info()->graph_analysis->list);
309 if (gai->conv_num == selected_call_fwd->call_num){
310 g_string_sprintfa(filter_string_fwd,"%sframe.number == %d", isFirst?"":" or ", gai->frame_num );
313 list = g_list_next (list);
315 g_string_sprintfa(filter_string_fwd, ") ");
316 filter_length = filter_length + filter_string_fwd->len;
318 if (filter_length < max_filter_length){
319 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
321 g_string_free(filter_string_fwd, TRUE);
322 filter_string_fwd = g_string_new(filter_prepend);
324 switch(selected_call_fwd->protocol){
326 tmp_sipinfo = selected_call_fwd->prot_info;
327 g_string_sprintfa(filter_string_fwd,
328 "(sip.Call-ID == \"%s\") ",
329 tmp_sipinfo->call_identifier
331 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
334 tmp_isupinfo = selected_call_fwd->prot_info;
335 g_string_sprintfa(filter_string_fwd,
336 "(isup.cic == %i and frame.number >=%i and frame.number<=%i and mtp3.network_indicator == %i and ((mtp3.dpc == %i) and (mtp3.opc == %i)) or((mtp3.dpc == %i) and (mtp3.opc == %i))) ",
337 tmp_isupinfo->cic,selected_call_fwd->first_frame_num,
338 selected_call_fwd->last_frame_num,
339 tmp_isupinfo->ni, tmp_isupinfo->dpc, tmp_isupinfo->opc,
340 tmp_isupinfo->opc, tmp_isupinfo->dpc
342 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
345 tmp_h323info = selected_call_fwd->prot_info;
346 g_string_sprintfa(filter_string_fwd,
347 "((h225.guid == %s || q931.call_ref == %x:%x || q931.call_ref == %x:%x) ",
348 guid_to_str(&tmp_h323info->guid[0]),
349 (guint8)(tmp_h323info->q931_crv & 0xff),
350 (guint8)((tmp_h323info->q931_crv & 0xff00)>>8),
351 (guint8)(tmp_h323info->q931_crv2 & 0xff),
352 (guint8)((tmp_h323info->q931_crv2 & 0xff00)>>8));
353 list = g_list_first(tmp_h323info->h245_list);
357 g_string_sprintfa(filter_string_fwd,
358 " || (ip.addr == %s && tcp.port == %d && h245) ",
359 ip_to_str((guint8 *)&(h245_add->h245_address)), h245_add->h245_port);
360 list = g_list_next(list);
362 g_string_sprintfa(filter_string_fwd, ") ");
363 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
366 const gcp_ctx_t* ctx = selected_call_fwd->prot_info;
367 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), ep_strdup_printf("h248.ctx == 0x%x", ctx->id ));
379 /* XXX - not supported */
385 g_string_free(filter_string_fwd, TRUE);
389 /****************************************************************************/
391 voip_calls_on_select_all (GtkButton *button _U_,
392 gpointer user_data _U_)
394 gtk_clist_select_all(GTK_CLIST(clist));
397 /****************************************************************************/
399 on_graph_bt_clicked (GtkButton *button _U_,
400 gpointer user_data _U_)
402 graph_analysis_item_t *gai;
405 voip_calls_info_t *tmp_listinfo;
407 /* reset the "display" parameter in graph analysis */
408 list2 = g_list_first(voip_calls_get_info()->graph_analysis->list);
411 gai->display = FALSE;
412 list2 = g_list_next(list2);
416 /* set the display for selected calls */
417 list = g_list_first(voip_calls_get_info()->callsinfo_list);
419 tmp_listinfo=list->data;
420 if (tmp_listinfo->selected){
421 list2 = g_list_first(voip_calls_get_info()->graph_analysis->list);
424 if (gai->conv_num == tmp_listinfo->call_num){
427 list2 = g_list_next(list2);
430 list = g_list_next(list);
433 /* create or refresh the graph windows */
434 if (graph_analysis_data->dlg.window == NULL) /* create the window */
435 graph_analysis_create(graph_analysis_data);
437 graph_analysis_update(graph_analysis_data); /* refresh it */
440 #ifdef HAVE_LIBPORTAUDIO
441 /****************************************************************************/
443 on_player_bt_clicked (GtkButton *button _U_,
444 gpointer user_data _U_)
446 rtp_player_init(voip_calls_get_info());
448 #endif /* HAVE_LIBPORTAUDIO */
450 /****************************************************************************/
451 /* when the user selects a row in the calls list */
453 voip_calls_on_select_row(GtkCList *clist,
456 GdkEventButton *event _U_,
457 gpointer user_data _U_)
459 /* GdkColor color = COLOR_DEFAULT;*/
460 gchar label_text[80];
462 voip_calls_info_t *listinfo;
464 selected_call_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
466 if (selected_call_fwd==NULL)
469 selected_call_fwd->selected=TRUE;
471 /* count the selected calls */
473 list = g_list_first(voip_calls_get_info()->callsinfo_list);
476 if (listinfo->selected){
479 list = g_list_next(list);
482 g_snprintf(label_text, 80,
483 "Detected %d VoIP %s. Selected %d %s.",
485 plurality(calls_nb, "Call", "Calls"),
487 plurality(calls_ns, "Call", "Calls"));
488 gtk_label_set(GTK_LABEL(top_label), label_text);
492 gtk_widget_set_sensitive(bt_filter, TRUE);
493 gtk_widget_set_sensitive(bt_graph, TRUE);
494 #ifdef HAVE_LIBPORTAUDIO
495 gtk_widget_set_sensitive(bt_player, TRUE);
496 #endif /* HAVE_LIBPORTAUDIO */
498 gtk_widget_set_sensitive(bt_filter, FALSE);
499 gtk_widget_set_sensitive(bt_graph, FALSE);
500 #ifdef HAVE_LIBPORTAUDIO
501 gtk_widget_set_sensitive(bt_player, FALSE);
502 #endif /* HAVE_LIBPORTAUDIO */
505 /* TODO: activate other buttons when implemented */
509 /****************************************************************************/
510 /* when the user selects a row in the calls list */
512 voip_calls_on_unselect_row(GtkCList *clist,
515 GdkEventButton *event _U_,
516 gpointer user_data _U_)
518 gchar label_text[80];
520 voip_calls_info_t *listinfo;
522 selected_call_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
524 if (selected_call_fwd==NULL)
527 selected_call_fwd->selected=FALSE;
529 /* count the selected calls */
531 list = g_list_first(voip_calls_get_info()->callsinfo_list);
534 if (listinfo->selected){
537 list = g_list_next(list);
540 g_snprintf(label_text, 80,
541 "Detected %d VoIP %s. Selected %d %s.",
543 plurality(calls_nb, "Call", "Calls"),
545 plurality(calls_ns, "Call", "Calls"));
546 gtk_label_set(GTK_LABEL(top_label), label_text);
549 gtk_widget_set_sensitive(bt_filter, TRUE);
550 gtk_widget_set_sensitive(bt_graph, TRUE);
551 #ifdef HAVE_LIBPORTAUDIO
552 gtk_widget_set_sensitive(bt_player, TRUE);
553 #endif /* HAVE_LIBPORTAUDIO */
555 gtk_widget_set_sensitive(bt_filter, FALSE);
556 gtk_widget_set_sensitive(bt_graph, FALSE);
557 #ifdef HAVE_LIBPORTAUDIO
558 gtk_widget_set_sensitive(bt_player, FALSE);
559 #endif /* HAVE_LIBPORTAUDIO */
562 /* TODO: activate other buttons when implemented */
572 /****************************************************************************/
574 typedef struct column_arrows {
576 GtkWidget *ascend_pm;
577 GtkWidget *descend_pm;
581 /****************************************************************************/
583 voip_calls_click_column_cb(GtkCList *clist, gint column, gpointer data)
585 column_arrows *col_arrows = (column_arrows *) data;
588 gtk_clist_freeze(clist);
590 for (i=0; i<NUM_COLS; i++) {
591 gtk_widget_hide(col_arrows[i].ascend_pm);
592 gtk_widget_hide(col_arrows[i].descend_pm);
595 if (column == clist->sort_column) {
596 if (clist->sort_type == GTK_SORT_ASCENDING) {
597 clist->sort_type = GTK_SORT_DESCENDING;
598 gtk_widget_show(col_arrows[column].descend_pm);
600 clist->sort_type = GTK_SORT_ASCENDING;
601 gtk_widget_show(col_arrows[column].ascend_pm);
604 clist->sort_type = GTK_SORT_ASCENDING;
605 gtk_widget_show(col_arrows[column].ascend_pm);
606 gtk_clist_set_sort_column(clist, column);
608 gtk_clist_thaw(clist);
610 gtk_clist_sort(clist);
614 /****************************************************************************/
616 voip_calls_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
620 guint i1, i2, i3, i4;
622 const GtkCListRow *row1 = (const GtkCListRow *) ptr1;
623 const GtkCListRow *row2 = (const GtkCListRow *) ptr2;
625 text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
626 text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
628 switch(clist->sort_column){
629 case CALL_COL_START_TIME:
630 case CALL_COL_STOP_TIME:
631 if ((sscanf(text1, "%u.%u", &i1, &i2) != 2) ||
632 (sscanf(text2, "%u.%u", &i3, &i4) != 2) ){
640 case CALL_COL_INITIAL_SPEAKER:
643 case CALL_COL_PROTOCOL:
645 case CALL_COL_COMMENTS:
646 return strcmp (text1, text2);
647 case CALL_COL_PACKETS:
652 g_assert_not_reached();
657 /****************************************************************************/
659 /****************************************************************************/
661 static void voip_calls_dlg_create (void)
663 GtkWidget *voip_calls_dlg_w;
665 GtkWidget *scrolledwindow;
666 GtkWidget *hbuttonbox;
668 GtkWidget *bt_select_all;
669 GtkTooltips *tooltips = gtk_tooltips_new();
670 const gchar *title_name_ptr;
673 const gchar *titles[NUM_COLS] = {"Start Time", "Stop Time", "Initial Speaker", "From", "To", "Protocol", "Packets", "State", "Comments"};
674 column_arrows *col_arrows;
675 GtkWidget *column_lb;
678 title_name_ptr = cf_get_display_name(&cfile);
679 win_name = g_strdup_printf("%s - VoIP Calls", title_name_ptr);
680 voip_calls_dlg_w=window_new(GTK_WINDOW_TOPLEVEL, win_name);
682 gtk_window_set_default_size(GTK_WINDOW(voip_calls_dlg_w), 840, 350);
684 main_vb = gtk_vbox_new (FALSE, 0);
685 gtk_container_add(GTK_CONTAINER(voip_calls_dlg_w), main_vb);
686 gtk_container_set_border_width (GTK_CONTAINER (main_vb), 12);
688 top_label = gtk_label_new ("Detected 0 VoIP Calls. Selected 0 Calls.");
689 gtk_box_pack_start (GTK_BOX (main_vb), top_label, FALSE, FALSE, 8);
691 scrolledwindow = scrolled_window_new (NULL, NULL);
692 gtk_box_pack_start (GTK_BOX (main_vb), scrolledwindow, TRUE, TRUE, 0);
694 clist = gtk_clist_new (NUM_COLS);
695 gtk_clist_set_selection_mode(GTK_CLIST (clist), GTK_SELECTION_MULTIPLE);
697 gtk_container_add (GTK_CONTAINER (scrolledwindow), clist);
699 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_START_TIME, 60);
700 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_STOP_TIME, 60);
701 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_INITIAL_SPEAKER, 80);
702 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_FROM, 130);
703 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_TO, 130);
704 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_PROTOCOL, 50);
705 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_PACKETS, 45);
706 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_STATE, 60);
707 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_COMMENTS, 100);
709 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_START_TIME, GTK_JUSTIFY_LEFT);
710 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_STOP_TIME, GTK_JUSTIFY_LEFT);
711 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_INITIAL_SPEAKER, GTK_JUSTIFY_LEFT);
712 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_FROM, GTK_JUSTIFY_LEFT);
713 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_TO, GTK_JUSTIFY_LEFT);
714 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_PROTOCOL, GTK_JUSTIFY_CENTER);
715 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_PACKETS, GTK_JUSTIFY_CENTER);
716 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_STATE, GTK_JUSTIFY_LEFT);
717 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_COMMENTS, GTK_JUSTIFY_LEFT);
719 gtk_clist_column_titles_show (GTK_CLIST (clist));
721 gtk_clist_set_compare_func(GTK_CLIST(clist), voip_calls_sort_column);
722 gtk_clist_set_sort_column(GTK_CLIST(clist), 0);
723 gtk_clist_set_sort_type(GTK_CLIST(clist), GTK_SORT_ASCENDING);
725 gtk_widget_show(voip_calls_dlg_w);
727 /* sort by column feature */
728 col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
730 for (i=0; i<NUM_COLS; i++) {
731 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
732 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
733 column_lb = gtk_label_new(titles[i]);
734 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
735 gtk_widget_show(column_lb);
737 col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
738 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
739 col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
740 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
741 /* make start time be the default sort order */
743 gtk_widget_show(col_arrows[i].ascend_pm);
745 gtk_clist_set_column_widget(GTK_CLIST(clist), i, col_arrows[i].table);
746 gtk_widget_show(col_arrows[i].table);
749 SIGNAL_CONNECT(clist, "click-column", voip_calls_click_column_cb, col_arrows);
751 /* label_fwd = gtk_label_new (FWD_LABEL_TEXT);
752 gtk_box_pack_start (GTK_BOX (main_vb), label_fwd, FALSE, FALSE, 0);
754 status_label = gtk_label_new ("Total: Calls: 0 Start packets: 0 Completed calls: 0 Rejected calls: 0");
755 gtk_box_pack_start (GTK_BOX (main_vb), status_label, FALSE, FALSE, 8);
758 hbuttonbox = gtk_hbutton_box_new ();
759 gtk_box_pack_start (GTK_BOX (main_vb), hbuttonbox, FALSE, FALSE, 0);
760 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_SPREAD);
761 gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 30);
763 /*bt_unselect = gtk_button_new_with_label ("Unselect");
764 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_unselect);
765 gtk_tooltips_set_tip (tooltips, bt_unselect, "Unselect this conversation", NULL);*/
767 bt_filter = gtk_button_new_with_label ("Prepare Filter");
768 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_filter);
769 gtk_tooltips_set_tip (tooltips, bt_filter, "Prepare a display filter of the selected conversation", NULL);
771 bt_graph = gtk_button_new_with_label("Graph");
772 gtk_container_add(GTK_CONTAINER(hbuttonbox), bt_graph);
773 gtk_widget_show(bt_graph);
774 SIGNAL_CONNECT(bt_graph, "clicked", on_graph_bt_clicked, NULL);
775 gtk_tooltips_set_tip (tooltips, bt_graph, "Show a flow graph of the selected calls.", NULL);
777 #ifdef HAVE_LIBPORTAUDIO
778 bt_player = gtk_button_new_with_label("Player");
779 gtk_container_add(GTK_CONTAINER(hbuttonbox), bt_player);
780 gtk_widget_show(bt_player);
781 SIGNAL_CONNECT(bt_player, "clicked", on_player_bt_clicked, NULL);
782 gtk_tooltips_set_tip (tooltips, bt_player, "Launch the RTP player to listen the selected calls.", NULL);
783 #endif /* HAVE_LIBPORTAUDIO */
785 bt_select_all = gtk_button_new_with_label("Select All");
786 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_select_all);
787 GTK_WIDGET_SET_FLAGS(bt_select_all, GTK_CAN_DEFAULT);
788 gtk_tooltips_set_tip (tooltips, bt_select_all, "Select all the calls", NULL);
790 bt_close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
791 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_close);
792 GTK_WIDGET_SET_FLAGS(bt_close, GTK_CAN_DEFAULT);
793 gtk_tooltips_set_tip (tooltips, bt_close, "Close this dialog", NULL);
795 SIGNAL_CONNECT(clist, "select_row", voip_calls_on_select_row, NULL);
796 SIGNAL_CONNECT(clist, "unselect_row", voip_calls_on_unselect_row, NULL);
797 /*SIGNAL_CONNECT(bt_unselect, "clicked", voip_calls_on_unselect, NULL);*/
798 SIGNAL_CONNECT(bt_filter, "clicked", voip_calls_on_filter, NULL);
800 window_set_cancel_button(voip_calls_dlg_w, bt_close, window_cancel_button_cb);
802 SIGNAL_CONNECT(voip_calls_dlg_w, "delete_event", window_delete_event_cb, NULL);
803 SIGNAL_CONNECT(voip_calls_dlg_w, "destroy", voip_calls_on_destroy, NULL);
804 SIGNAL_CONNECT(bt_select_all, "clicked", voip_calls_on_select_all, NULL);
806 gtk_widget_show_all(voip_calls_dlg_w);
807 window_present(voip_calls_dlg_w);
809 voip_calls_on_unselect(NULL, NULL);
811 voip_calls_dlg = voip_calls_dlg_w;
817 /****************************************************************************/
819 /****************************************************************************/
821 /****************************************************************************/
822 /* update the contents of the dialog box clist */
823 /* list: pointer to list of voip_calls_info_t* */
825 void voip_calls_dlg_update(GList *list)
827 gchar label_text[256];
828 if (voip_calls_dlg != NULL) {
832 g_snprintf(label_text, 256,
833 "Total: Calls: %d Start packets: %d Completed calls: %d Rejected calls: %d",
834 g_list_length(voip_calls_get_info()->callsinfo_list),
835 voip_calls_get_info()->start_packets,
836 voip_calls_get_info()->completed_calls,
837 voip_calls_get_info()->rejected_calls);
838 gtk_label_set(GTK_LABEL(status_label), label_text);
840 gtk_clist_freeze(GTK_CLIST(clist));
841 gtk_clist_clear(GTK_CLIST(clist));
842 list = g_list_first(list);
845 add_to_clist((voip_calls_info_t*)(list->data));
846 list = g_list_next(list);
848 gtk_clist_thaw(GTK_CLIST(clist));
850 g_snprintf(label_text, 256,
851 "Detected %d VoIP %s. Selected %d %s.",
853 plurality(calls_nb, "Call", "Calls"),
855 plurality(calls_ns, "Call", "Calls"));
856 gtk_label_set(GTK_LABEL(top_label), label_text);
863 /****************************************************************************/
864 /* draw function for tap listeners to keep the window up to date */
865 void voip_calls_dlg_draw(void *ptr _U_)
867 if (voip_calls_get_info()->redraw) {
868 voip_calls_dlg_update(voip_calls_get_info()->callsinfo_list);
869 voip_calls_get_info()->redraw = FALSE;
873 /* reset function for tap listeners to clear window, if necessary */
874 void voip_calls_dlg_reset(void *ptr _U_)
876 /* Clean up memory used by calls tap */
877 voip_calls_reset((voip_calls_tapinfo_t*) voip_calls_get_info());
879 /* close the graph window if open */
880 if (graph_analysis_data && graph_analysis_data->dlg.window != NULL) {
881 window_cancel_button_cb(NULL, graph_analysis_data->dlg.window);
882 graph_analysis_data->dlg.window = NULL;
886 /* init function for tap */
887 /* Made extern only for "Fax T38 Analysis..." */
889 voip_calls_init_tap(const char *dummy _U_, void* userdata _U_)
892 gchar *data[NUM_COLS];
893 gchar field[NUM_COLS][50];
895 if (graph_analysis_data == NULL) {
896 graph_analysis_data_init();
897 /* init the Graph Analysys */
898 graph_analysis_data = graph_analysis_init();
899 graph_analysis_data->graph_info = voip_calls_get_info()->graph_analysis;
902 /* Clean up memory used by calls tap */
903 voip_calls_reset((voip_calls_tapinfo_t*) voip_calls_get_info());
905 /* Register the tap listener */
906 sip_calls_init_tap();
907 mtp3_calls_init_tap();
908 isup_calls_init_tap();
909 h225_calls_init_tap();
910 h245dg_calls_init_tap();
911 q931_calls_init_tap();
912 h248_calls_init_tap();
913 sccp_calls_init_tap();
914 sdp_calls_init_tap();
915 /* We don't register this tap, if we don't have the unistim plugin loaded.*/
916 if (find_tap_id("unistim")) {
917 unistim_calls_init_tap();
919 if (find_tap_id("voip")) {
920 VoIPcalls_init_tap();
923 rtp_event_init_tap();
924 /* We don't register this tap, if we don't have the mgcp plugin loaded.*/
925 if (find_tap_id("mgcp")) {
926 mgcp_calls_init_tap();
928 actrace_calls_init_tap();
931 /* create dialog box if necessary */
932 if (voip_calls_dlg == NULL) {
933 voip_calls_dlg_create();
935 /* There's already a dialog box; reactivate it. */
936 reactivate_window(voip_calls_dlg);
939 voip_calls_get_info()->redraw = TRUE;
940 voip_calls_dlg_draw(NULL);
941 voip_calls_get_info()->redraw = TRUE;
942 for (c=0;c<NUM_COLS;c++){
943 data[c]=&field[c][0];
946 g_snprintf(field[3], 50, "Please wait...");
947 gtk_clist_append(GTK_CLIST(clist), data);
949 /* Scan for VoIP calls calls (redissect all packets) */
950 cf_retap_packets(&cfile, FALSE);
952 /* Tap listener will be removed and cleaned up in voip_calls_on_destroy */
956 /****************************************************************************/
957 /* entry point when called via the GTK menu */
958 static void voip_calls_launch(GtkWidget *w _U_, gpointer data _U_)
960 voip_calls_init_tap("",NULL);
963 /****************************************************************************/
965 register_tap_listener_voip_calls_dlg(void)
967 register_stat_cmd_arg("voip,calls",voip_calls_init_tap,NULL);
968 register_stat_menu_item("VoIP Calls", REGISTER_STAT_GROUP_TELEPHONY,
969 voip_calls_launch, NULL, NULL, NULL);