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.
44 #include <epan/epan.h>
45 #include <epan/packet.h>
46 #include "epan/filesystem.h"
48 #include <epan/stat_cmd_args.h>
49 #include <epan/to_str.h>
50 #include <epan/address.h>
51 #include <epan/addr_resolv.h>
52 #include <epan/dissectors/packet-h248.h>
54 #include "../register.h"
55 #include "../globals.h"
56 #include "../stat_menu.h"
58 #include "gtk/graph_analysis.h"
59 #include "gtk/voip_calls_dlg.h"
60 #include "gtk/voip_calls.h"
61 #include "gtk/gui_stat_menu.h"
62 #include "gtk/dlg_utils.h"
63 #include "gtk/gui_utils.h"
64 #include "gtk/gtkglobals.h"
66 #include "image/clist_ascend.xpm"
67 #include "image/clist_descend.xpm"
68 #include "simple_dialog.h"
70 #ifdef HAVE_LIBPORTAUDIO
71 #include "gtk/rtp_analysis.h"
72 #include "gtk/rtp_player.h"
73 #endif /* HAVE_LIBPORTAUDIO */
76 /****************************************************************************/
77 /* pointer to the one and only dialog window */
78 static GtkWidget *voip_calls_dlg = NULL;
80 static GtkWidget *clist = NULL;
81 static GtkWidget *top_label = NULL;
82 static GtkWidget *status_label = NULL;
84 /*static GtkWidet *bt_unselect = NULL;*/
85 static GtkWidget *bt_filter = NULL;
86 static GtkWidget *bt_graph = NULL;
87 #ifdef HAVE_LIBPORTAUDIO
88 static GtkWidget *bt_player = NULL;
89 #endif /* HAVE_LIBPORTAUDIO */
91 static voip_calls_info_t* selected_call_fwd = NULL; /* current selection */
92 static GList *last_list = NULL;
94 static guint32 calls_nb = 0; /* number of displayed calls */
95 static guint32 calls_ns = 0; /* number of selected calls */
97 static graph_analysis_data_t *graph_analysis_data = NULL;
100 #define CALL_COL_START_TIME 0
101 #define CALL_COL_STOP_TIME 1
102 #define CALL_COL_INITIAL_SPEAKER 2
103 #define CALL_COL_FROM 3
104 #define CALL_COL_TO 4
105 #define CALL_COL_PROTOCOL 5
106 #define CALL_COL_PACKETS 6
107 #define CALL_COL_STATE 7
108 #define CALL_COL_COMMENTS 8
109 static const GdkColor COLOR_SELECT = {0, 0x00ff, 0x80ff, 0x80ff};
110 static const GdkColor COLOR_DEFAULT = {0, 0xffff, 0xffff, 0xffff};
111 static const GdkColor COLOR_FOREGROUND = {0, 0x0000, 0x0000, 0x0000};
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 bg_color = COLOR_SELECT;
126 GdkColor fg_color = COLOR_FOREGROUND;
127 for (c=0;c<NUM_COLS;c++){
128 data[c]=&field[c][0];
131 /* strinfo->selected = FALSE;*/
133 g_snprintf(field[CALL_COL_START_TIME], 15, "%i.%03i", strinfo->start_sec, strinfo->start_usec/1000);
134 g_snprintf(field[CALL_COL_STOP_TIME], 15, "%i.%03i", strinfo->stop_sec, strinfo->stop_usec/1000);
135 /* xxx display_signed_time(data[0], sizeof(field[CALL_COL_START_TIME]), strinfo->start_sec, strinfo->start_usec, USECS); */
136 /* display_signed_time(data[1], sizeof(field[CALL_COL_STOP_TIME]), strinfo->stop_sec, strinfo->stop_usec, USECS); */
137 g_snprintf(field[CALL_COL_INITIAL_SPEAKER], 30, "%s", get_addr_name(&(strinfo->initial_speaker)));
138 g_snprintf(field[CALL_COL_FROM], 50, "%s", strinfo->from_identity);
139 g_snprintf(field[CALL_COL_TO], 50, "%s", strinfo->to_identity);
140 g_snprintf(field[CALL_COL_PROTOCOL], 15, "%s", ((strinfo->protocol==VOIP_COMMON)&&strinfo->protocol_name)?strinfo->protocol_name:voip_protocol_name[strinfo->protocol]);
141 g_snprintf(field[CALL_COL_PACKETS], 15, "%u", strinfo->npackets);
142 g_snprintf(field[CALL_COL_STATE], 15, "%s", voip_call_state_name[strinfo->call_state]);
144 /* Add comments based on the protocol */
145 switch(strinfo->protocol){
147 tmp_isupinfo = strinfo->prot_info;
148 g_snprintf(field[CALL_COL_COMMENTS],30, "%i-%i -> %i-%i", tmp_isupinfo->ni, tmp_isupinfo->opc,
149 tmp_isupinfo->ni, tmp_isupinfo->dpc);
152 tmp_h323info = strinfo->prot_info;
153 if (strinfo->call_state == VOIP_CALL_SETUP)
154 tmp_bool = tmp_h323info->is_faststart_Setup;
156 if ((tmp_h323info->is_faststart_Setup == TRUE) && (tmp_h323info->is_faststart_Proc == TRUE)) tmp_bool = TRUE;
157 g_snprintf(field[CALL_COL_COMMENTS],35, "Tunneling: %s Fast Start: %s", (tmp_h323info->is_h245Tunneling==TRUE?"ON":"OFF"),
158 (tmp_bool==TRUE?"ON":"OFF"));
161 field[CALL_COL_COMMENTS][0]='\0';
162 if (strinfo->call_comment)
163 g_snprintf(field[CALL_COL_COMMENTS],30, "%s", strinfo->call_comment);
166 field[CALL_COL_COMMENTS][0]='\0';
170 added_row = gtk_clist_append(GTK_CLIST(clist), data);
172 /* set the background color if selected */
173 if (strinfo->selected) {
175 gtk_clist_set_background(GTK_CLIST(clist), added_row, &bg_color);
176 gtk_clist_set_foreground(GTK_CLIST(clist), added_row, &fg_color);
179 /* set data pointer of last row to point to user data for that row */
180 gtk_clist_set_row_data(GTK_CLIST(clist), added_row, strinfo);
182 /* Update the top label with the number of detected calls */
184 g_snprintf(label_text, 256,
185 "Detected %d VoIP %s. Selected %d %s.",
187 plurality(calls_nb, "Call", "Calls"),
189 plurality(calls_ns, "Call", "Calls"));
190 gtk_label_set_text(GTK_LABEL(top_label), label_text);
192 /* Update the status label with the number of total messages */
193 g_snprintf(label_text, 256,
194 "Total: Calls: %d Start packets: %d Completed calls: %d Rejected calls: %d",
195 g_list_length(voip_calls_get_info()->callsinfo_list),
196 voip_calls_get_info()->start_packets,
197 voip_calls_get_info()->completed_calls,
198 voip_calls_get_info()->rejected_calls);
199 gtk_label_set_text(GTK_LABEL(status_label), label_text);
203 static void voip_calls_remove_tap_listener(void)
205 /* Remove the calls tap listener */
206 remove_tap_listener_sip_calls();
207 remove_tap_listener_isup_calls();
208 remove_tap_listener_mtp3_calls();
209 remove_tap_listener_h225_calls();
210 remove_tap_listener_h245dg_calls();
211 remove_tap_listener_q931_calls();
212 remove_tap_listener_h248_calls();
213 remove_tap_listener_sccp_calls();
214 remove_tap_listener_sdp_calls();
215 remove_tap_listener_rtp();
216 if (find_tap_id("unistim")) {
217 remove_tap_listener_unistim_calls();
219 if (find_tap_id("voip")) {
220 remove_tap_listener_voip_calls();
222 remove_tap_listener_rtp_event();
223 remove_tap_listener_mgcp_calls();
224 remove_tap_listener_actrace_calls();
225 remove_tap_listener_t38();
226 remove_tap_listener_skinny_calls();
227 remove_tap_listener_iax2_calls();
230 /****************************************************************************/
232 /****************************************************************************/
234 voip_calls_on_destroy (GtkObject *object _U_,
235 gpointer user_data _U_)
237 /* remove_tap_listeners */
238 voip_calls_remove_tap_listener();
240 /* Clean up memory used by calls tap */
241 voip_calls_dlg_reset(NULL);
243 /* Note that we no longer have a "VoIP Calls" dialog box. */
244 voip_calls_dlg = NULL;
246 graph_analysis_data = NULL;
250 /****************************************************************************/
252 voip_calls_on_unselect (GtkButton *button _U_,
253 gpointer user_data _U_)
255 selected_call_fwd = NULL;
256 gtk_clist_unselect_all(GTK_CLIST(clist));
257 /* gtk_label_set_text(GTK_LABEL(label_fwd), FWD_LABEL_TEXT);
259 /*gtk_widget_set_sensitive(bt_unselect, FALSE);*/
260 gtk_widget_set_sensitive(bt_filter, FALSE);
261 gtk_widget_set_sensitive(bt_graph, FALSE);
262 #ifdef HAVE_LIBPORTAUDIO
263 gtk_widget_set_sensitive(bt_player, FALSE);
264 #endif /* HAVE_LIBPORTAUDIO */
268 /****************************************************************************/
270 voip_calls_on_filter (GtkButton *button _U_,
271 gpointer user_data _U_)
273 const gchar *filter_string;
275 GString *filter_string_fwd;
276 const gchar *filter_prepend;
277 gboolean isFirst = TRUE;
279 size_t filter_length = 0;
280 size_t max_filter_length = 2048;
281 sip_calls_info_t *tmp_sipinfo;
282 isup_calls_info_t *tmp_isupinfo;
283 h323_calls_info_t *tmp_h323info;
284 h245_address_t *h245_add = NULL;
286 graph_analysis_item_t *gai;
288 if (selected_call_fwd==NULL)
291 filter_string=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
292 filter_length = strlen(filter_string);
294 while ((c = *filter_string++) != '\0') {
295 if (!isspace((guchar)c)) {
296 /* The filter string isn't blank, so there's already
297 an expression; we OR in the new expression */
298 filter_prepend = " or ";
303 filter_string_fwd = g_string_new(filter_prepend);
305 /* look in the Graph and get all the frame_num for this call */
306 g_string_append_printf(filter_string_fwd, " (");
307 list = g_list_first(voip_calls_get_info()->graph_analysis->list);
311 if (gai->conv_num == selected_call_fwd->call_num){
312 g_string_append_printf(filter_string_fwd,"%sframe.number == %d", isFirst?"":" or ", gai->frame_num );
315 list = g_list_next (list);
317 g_string_append_printf(filter_string_fwd, ") ");
318 filter_length = filter_length + filter_string_fwd->len;
320 if (filter_length < max_filter_length){
321 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
323 g_string_free(filter_string_fwd, TRUE);
324 filter_string_fwd = g_string_new(filter_prepend);
326 switch(selected_call_fwd->protocol){
328 tmp_sipinfo = selected_call_fwd->prot_info;
329 g_string_append_printf(filter_string_fwd,
330 "(sip.Call-ID == \"%s\") ",
331 tmp_sipinfo->call_identifier
333 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
336 tmp_isupinfo = selected_call_fwd->prot_info;
337 g_string_append_printf(filter_string_fwd,
338 "(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))) ",
339 tmp_isupinfo->cic,selected_call_fwd->first_frame_num,
340 selected_call_fwd->last_frame_num,
341 tmp_isupinfo->ni, tmp_isupinfo->dpc, tmp_isupinfo->opc,
342 tmp_isupinfo->opc, tmp_isupinfo->dpc
344 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
347 tmp_h323info = selected_call_fwd->prot_info;
348 g_string_append_printf(filter_string_fwd,
349 "((h225.guid == %s || q931.call_ref == %x:%x || q931.call_ref == %x:%x) ",
350 guid_to_str(&tmp_h323info->guid[0]),
351 (guint8)(tmp_h323info->q931_crv & 0xff),
352 (guint8)((tmp_h323info->q931_crv & 0xff00)>>8),
353 (guint8)(tmp_h323info->q931_crv2 & 0xff),
354 (guint8)((tmp_h323info->q931_crv2 & 0xff00)>>8));
355 list = g_list_first(tmp_h323info->h245_list);
359 g_string_append_printf(filter_string_fwd,
360 " || (ip.addr == %s && tcp.port == %d && h245) ",
361 ip_to_str((guint8 *)&(h245_add->h245_address)), h245_add->h245_port);
362 list = g_list_next(list);
364 g_string_append_printf(filter_string_fwd, ") ");
365 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), filter_string_fwd->str);
368 const gcp_ctx_t* ctx = selected_call_fwd->prot_info;
369 gtk_entry_append_text(GTK_ENTRY(main_display_filter_widget), ep_strdup_printf("h248.ctx == 0x%x", ctx->id ));
383 /* XXX - not supported */
389 g_string_free(filter_string_fwd, TRUE);
393 /****************************************************************************/
395 voip_calls_on_select_all (GtkButton *button _U_,
396 gpointer user_data _U_)
398 gtk_clist_select_all(GTK_CLIST(clist));
401 /****************************************************************************/
403 on_graph_bt_clicked (GtkButton *button _U_,
404 gpointer user_data _U_)
406 graph_analysis_item_t *gai;
409 voip_calls_info_t *tmp_listinfo;
411 /* reset the "display" parameter in graph analysis */
412 list2 = g_list_first(voip_calls_get_info()->graph_analysis->list);
415 gai->display = FALSE;
416 list2 = g_list_next(list2);
420 /* set the display for selected calls */
421 list = g_list_first(voip_calls_get_info()->callsinfo_list);
423 tmp_listinfo=list->data;
424 if (tmp_listinfo->selected){
425 list2 = g_list_first(voip_calls_get_info()->graph_analysis->list);
428 if (gai->conv_num == tmp_listinfo->call_num){
431 list2 = g_list_next(list2);
434 list = g_list_next(list);
437 /* create or refresh the graph windows */
438 if (graph_analysis_data->dlg.window == NULL) /* create the window */
439 graph_analysis_create(graph_analysis_data);
441 graph_analysis_update(graph_analysis_data); /* refresh it */
444 #ifdef HAVE_LIBPORTAUDIO
445 /****************************************************************************/
447 on_player_bt_clicked (GtkButton *button _U_,
448 gpointer user_data _U_)
450 rtp_player_init(voip_calls_get_info());
452 #endif /* HAVE_LIBPORTAUDIO */
454 /****************************************************************************/
455 /* when the user selects a row in the calls list */
457 voip_calls_on_select_row(GtkCList *clist,
460 GdkEventButton *event _U_,
461 gpointer user_data _U_)
463 /* GdkColor color = COLOR_DEFAULT;*/
464 gchar label_text[80];
466 voip_calls_info_t *listinfo;
468 selected_call_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
470 if (selected_call_fwd==NULL)
473 selected_call_fwd->selected=TRUE;
475 /* count the selected calls */
477 list = g_list_first(voip_calls_get_info()->callsinfo_list);
480 if (listinfo->selected){
483 list = g_list_next(list);
486 g_snprintf(label_text, 80,
487 "Detected %d VoIP %s. Selected %d %s.",
489 plurality(calls_nb, "Call", "Calls"),
491 plurality(calls_ns, "Call", "Calls"));
492 gtk_label_set_text(GTK_LABEL(top_label), label_text);
496 gtk_widget_set_sensitive(bt_filter, TRUE);
497 gtk_widget_set_sensitive(bt_graph, TRUE);
498 #ifdef HAVE_LIBPORTAUDIO
499 gtk_widget_set_sensitive(bt_player, TRUE);
500 #endif /* HAVE_LIBPORTAUDIO */
502 gtk_widget_set_sensitive(bt_filter, FALSE);
503 gtk_widget_set_sensitive(bt_graph, FALSE);
504 #ifdef HAVE_LIBPORTAUDIO
505 gtk_widget_set_sensitive(bt_player, FALSE);
506 #endif /* HAVE_LIBPORTAUDIO */
509 /* TODO: activate other buttons when implemented */
513 /****************************************************************************/
514 /* when the user selects a row in the calls list */
516 voip_calls_on_unselect_row(GtkCList *clist,
519 GdkEventButton *event _U_,
520 gpointer user_data _U_)
522 gchar label_text[80];
524 voip_calls_info_t *listinfo;
526 selected_call_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
528 if (selected_call_fwd==NULL)
531 selected_call_fwd->selected=FALSE;
533 /* count the selected calls */
535 list = g_list_first(voip_calls_get_info()->callsinfo_list);
538 if (listinfo->selected){
541 list = g_list_next(list);
544 g_snprintf(label_text, 80,
545 "Detected %d VoIP %s. Selected %d %s.",
547 plurality(calls_nb, "Call", "Calls"),
549 plurality(calls_ns, "Call", "Calls"));
550 gtk_label_set_text(GTK_LABEL(top_label), label_text);
553 gtk_widget_set_sensitive(bt_filter, TRUE);
554 gtk_widget_set_sensitive(bt_graph, TRUE);
555 #ifdef HAVE_LIBPORTAUDIO
556 gtk_widget_set_sensitive(bt_player, TRUE);
557 #endif /* HAVE_LIBPORTAUDIO */
559 gtk_widget_set_sensitive(bt_filter, FALSE);
560 gtk_widget_set_sensitive(bt_graph, FALSE);
561 #ifdef HAVE_LIBPORTAUDIO
562 gtk_widget_set_sensitive(bt_player, FALSE);
563 #endif /* HAVE_LIBPORTAUDIO */
566 /* TODO: activate other buttons when implemented */
576 /****************************************************************************/
578 typedef struct column_arrows {
580 GtkWidget *ascend_pm;
581 GtkWidget *descend_pm;
585 /****************************************************************************/
587 voip_calls_click_column_cb(GtkCList *clist, gint column, gpointer data)
589 column_arrows *col_arrows = (column_arrows *) data;
592 gtk_clist_freeze(clist);
594 for (i=0; i<NUM_COLS; i++) {
595 gtk_widget_hide(col_arrows[i].ascend_pm);
596 gtk_widget_hide(col_arrows[i].descend_pm);
599 if (column == clist->sort_column) {
600 if (clist->sort_type == GTK_SORT_ASCENDING) {
601 clist->sort_type = GTK_SORT_DESCENDING;
602 gtk_widget_show(col_arrows[column].descend_pm);
604 clist->sort_type = GTK_SORT_ASCENDING;
605 gtk_widget_show(col_arrows[column].ascend_pm);
608 clist->sort_type = GTK_SORT_ASCENDING;
609 gtk_widget_show(col_arrows[column].ascend_pm);
610 gtk_clist_set_sort_column(clist, column);
612 gtk_clist_thaw(clist);
614 gtk_clist_sort(clist);
618 /****************************************************************************/
620 voip_calls_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
624 guint i1, i2, i3, i4;
626 const GtkCListRow *row1 = (const GtkCListRow *) ptr1;
627 const GtkCListRow *row2 = (const GtkCListRow *) ptr2;
629 text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
630 text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
632 switch(clist->sort_column){
633 case CALL_COL_START_TIME:
634 case CALL_COL_STOP_TIME:
635 if ((sscanf(text1, "%u.%u", &i1, &i2) != 2) ||
636 (sscanf(text2, "%u.%u", &i3, &i4) != 2) ){
644 case CALL_COL_INITIAL_SPEAKER:
647 case CALL_COL_PROTOCOL:
649 case CALL_COL_COMMENTS:
650 return strcmp (text1, text2);
651 case CALL_COL_PACKETS:
656 g_assert_not_reached();
661 /****************************************************************************/
663 /****************************************************************************/
665 static void voip_calls_dlg_create (void)
667 GtkWidget *voip_calls_dlg_w;
669 GtkWidget *scrolledwindow;
670 GtkWidget *hbuttonbox;
672 GtkWidget *bt_select_all;
673 GtkTooltips *tooltips = gtk_tooltips_new();
674 const gchar *title_name_ptr;
677 const gchar *titles[NUM_COLS] = {"Start Time", "Stop Time", "Initial Speaker", "From", "To", "Protocol", "Packets", "State", "Comments"};
678 column_arrows *col_arrows;
679 GtkWidget *column_lb;
682 title_name_ptr = cf_get_display_name(&cfile);
683 win_name = g_strdup_printf("%s - VoIP Calls", title_name_ptr);
684 voip_calls_dlg_w=window_new(GTK_WINDOW_TOPLEVEL, win_name);
686 gtk_window_set_default_size(GTK_WINDOW(voip_calls_dlg_w), 840, 350);
688 main_vb = gtk_vbox_new (FALSE, 0);
689 gtk_container_add(GTK_CONTAINER(voip_calls_dlg_w), main_vb);
690 gtk_container_set_border_width (GTK_CONTAINER (main_vb), 12);
692 top_label = gtk_label_new ("Detected 0 VoIP Calls. Selected 0 Calls.");
693 gtk_box_pack_start (GTK_BOX (main_vb), top_label, FALSE, FALSE, 8);
695 scrolledwindow = scrolled_window_new (NULL, NULL);
696 gtk_box_pack_start (GTK_BOX (main_vb), scrolledwindow, TRUE, TRUE, 0);
698 clist = gtk_clist_new (NUM_COLS);
699 gtk_clist_set_selection_mode(GTK_CLIST (clist), GTK_SELECTION_MULTIPLE);
701 gtk_container_add (GTK_CONTAINER (scrolledwindow), clist);
703 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_START_TIME, 60);
704 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_STOP_TIME, 60);
705 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_INITIAL_SPEAKER, 80);
706 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_FROM, 130);
707 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_TO, 130);
708 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_PROTOCOL, 50);
709 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_PACKETS, 45);
710 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_STATE, 60);
711 gtk_clist_set_column_width (GTK_CLIST (clist), CALL_COL_COMMENTS, 100);
713 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_START_TIME, GTK_JUSTIFY_LEFT);
714 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_STOP_TIME, GTK_JUSTIFY_LEFT);
715 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_INITIAL_SPEAKER, GTK_JUSTIFY_LEFT);
716 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_FROM, GTK_JUSTIFY_LEFT);
717 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_TO, GTK_JUSTIFY_LEFT);
718 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_PROTOCOL, GTK_JUSTIFY_CENTER);
719 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_PACKETS, GTK_JUSTIFY_CENTER);
720 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_STATE, GTK_JUSTIFY_LEFT);
721 gtk_clist_set_column_justification(GTK_CLIST(clist), CALL_COL_COMMENTS, GTK_JUSTIFY_LEFT);
723 gtk_clist_column_titles_show (GTK_CLIST (clist));
725 gtk_clist_set_compare_func(GTK_CLIST(clist), voip_calls_sort_column);
726 gtk_clist_set_sort_column(GTK_CLIST(clist), 0);
727 gtk_clist_set_sort_type(GTK_CLIST(clist), GTK_SORT_ASCENDING);
729 gtk_widget_show(voip_calls_dlg_w);
731 /* sort by column feature */
732 col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
734 for (i=0; i<NUM_COLS; i++) {
735 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
736 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
737 column_lb = gtk_label_new(titles[i]);
738 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
739 gtk_widget_show(column_lb);
741 col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
742 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
743 col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
744 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
745 /* make start time be the default sort order */
747 gtk_widget_show(col_arrows[i].ascend_pm);
749 gtk_clist_set_column_widget(GTK_CLIST(clist), i, col_arrows[i].table);
750 gtk_widget_show(col_arrows[i].table);
753 g_signal_connect(clist, "click-column", G_CALLBACK(voip_calls_click_column_cb), col_arrows);
755 /* label_fwd = gtk_label_new (FWD_LABEL_TEXT);
756 gtk_box_pack_start (GTK_BOX (main_vb), label_fwd, FALSE, FALSE, 0);
758 status_label = gtk_label_new ("Total: Calls: 0 Start packets: 0 Completed calls: 0 Rejected calls: 0");
759 gtk_box_pack_start (GTK_BOX (main_vb), status_label, FALSE, FALSE, 8);
762 hbuttonbox = gtk_hbutton_box_new ();
763 gtk_box_pack_start (GTK_BOX (main_vb), hbuttonbox, FALSE, FALSE, 0);
764 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_SPREAD);
765 gtk_box_set_spacing (GTK_BOX (hbuttonbox), 30);
767 /*bt_unselect = gtk_button_new_with_label ("Unselect");
768 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_unselect);
769 gtk_tooltips_set_tip (tooltips, bt_unselect, "Unselect this conversation", NULL);*/
771 bt_filter = gtk_button_new_with_label ("Prepare Filter");
772 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_filter);
773 gtk_tooltips_set_tip (tooltips, bt_filter, "Prepare a display filter of the selected conversation", NULL);
775 bt_graph = gtk_button_new_with_label("Graph");
776 gtk_container_add(GTK_CONTAINER(hbuttonbox), bt_graph);
777 gtk_widget_show(bt_graph);
778 g_signal_connect(bt_graph, "clicked", G_CALLBACK(on_graph_bt_clicked), NULL);
779 gtk_tooltips_set_tip (tooltips, bt_graph, "Show a flow graph of the selected calls.", NULL);
781 #ifdef HAVE_LIBPORTAUDIO
782 bt_player = gtk_button_new_with_label("Player");
783 gtk_container_add(GTK_CONTAINER(hbuttonbox), bt_player);
784 gtk_widget_show(bt_player);
785 g_signal_connect(bt_player, "clicked", G_CALLBACK(on_player_bt_clicked), NULL);
786 gtk_tooltips_set_tip (tooltips, bt_player, "Launch the RTP player to listen the selected calls.", NULL);
787 #endif /* HAVE_LIBPORTAUDIO */
789 bt_select_all = gtk_button_new_with_label("Select All");
790 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_select_all);
791 GTK_WIDGET_SET_FLAGS(bt_select_all, GTK_CAN_DEFAULT);
792 gtk_tooltips_set_tip (tooltips, bt_select_all, "Select all the calls", NULL);
794 bt_close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
795 gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_close);
796 GTK_WIDGET_SET_FLAGS(bt_close, GTK_CAN_DEFAULT);
797 gtk_tooltips_set_tip (tooltips, bt_close, "Close this dialog", NULL);
799 g_signal_connect(clist, "select_row", G_CALLBACK(voip_calls_on_select_row), NULL);
800 g_signal_connect(clist, "unselect_row", G_CALLBACK(voip_calls_on_unselect_row), NULL);
801 /*g_signal_connect(bt_unselect, "clicked", G_CALLBACK(voip_calls_on_unselect), NULL);*/
802 g_signal_connect(bt_filter, "clicked", G_CALLBACK(voip_calls_on_filter), NULL);
804 window_set_cancel_button(voip_calls_dlg_w, bt_close, window_cancel_button_cb);
806 g_signal_connect(voip_calls_dlg_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
807 g_signal_connect(voip_calls_dlg_w, "destroy", G_CALLBACK(voip_calls_on_destroy), NULL);
808 g_signal_connect(bt_select_all, "clicked", G_CALLBACK(voip_calls_on_select_all), NULL);
810 gtk_widget_show_all(voip_calls_dlg_w);
811 window_present(voip_calls_dlg_w);
813 voip_calls_on_unselect(NULL, NULL);
815 voip_calls_dlg = voip_calls_dlg_w;
821 /****************************************************************************/
823 /****************************************************************************/
825 /****************************************************************************/
826 /* update the contents of the dialog box clist */
827 /* list: pointer to list of voip_calls_info_t* */
829 void voip_calls_dlg_update(GList *list)
831 gchar label_text[256];
832 if (voip_calls_dlg != NULL) {
836 g_snprintf(label_text, 256,
837 "Total: Calls: %d Start packets: %d Completed calls: %d Rejected calls: %d",
838 g_list_length(voip_calls_get_info()->callsinfo_list),
839 voip_calls_get_info()->start_packets,
840 voip_calls_get_info()->completed_calls,
841 voip_calls_get_info()->rejected_calls);
842 gtk_label_set_text(GTK_LABEL(status_label), label_text);
844 gtk_clist_freeze(GTK_CLIST(clist));
845 gtk_clist_clear(GTK_CLIST(clist));
846 list = g_list_first(list);
849 add_to_clist((voip_calls_info_t*)(list->data));
850 list = g_list_next(list);
852 gtk_clist_thaw(GTK_CLIST(clist));
854 g_snprintf(label_text, 256,
855 "Detected %d VoIP %s. Selected %d %s.",
857 plurality(calls_nb, "Call", "Calls"),
859 plurality(calls_ns, "Call", "Calls"));
860 gtk_label_set_text(GTK_LABEL(top_label), label_text);
867 /****************************************************************************/
868 /* draw function for tap listeners to keep the window up to date */
869 void voip_calls_dlg_draw(void *ptr _U_)
871 if (voip_calls_get_info()->redraw) {
872 voip_calls_dlg_update(voip_calls_get_info()->callsinfo_list);
873 voip_calls_get_info()->redraw = FALSE;
877 /* reset function for tap listeners to clear window, if necessary */
878 void voip_calls_dlg_reset(void *ptr _U_)
880 /* Clean up memory used by calls tap */
881 voip_calls_reset((voip_calls_tapinfo_t*) voip_calls_get_info());
883 /* close the graph window if open */
884 if (graph_analysis_data && graph_analysis_data->dlg.window != NULL) {
885 window_cancel_button_cb(NULL, graph_analysis_data->dlg.window);
886 graph_analysis_data->dlg.window = NULL;
890 /* init function for tap */
891 /* Made extern only for "Fax T38 Analysis..." */
893 voip_calls_init_tap(const char *dummy _U_, void* userdata _U_)
896 gchar *data[NUM_COLS];
897 gchar field[NUM_COLS][50];
899 if (graph_analysis_data == NULL) {
900 graph_analysis_data_init();
901 /* init the Graph Analysys */
902 graph_analysis_data = graph_analysis_init();
903 graph_analysis_data->graph_info = voip_calls_get_info()->graph_analysis;
906 /* Clean up memory used by calls tap */
907 voip_calls_reset((voip_calls_tapinfo_t*) voip_calls_get_info());
909 /* Register the tap listener */
910 sip_calls_init_tap();
911 mtp3_calls_init_tap();
912 isup_calls_init_tap();
913 h225_calls_init_tap();
914 h245dg_calls_init_tap();
915 q931_calls_init_tap();
916 h248_calls_init_tap();
917 sccp_calls_init_tap();
918 sdp_calls_init_tap();
919 /* We don't register this tap, if we don't have the unistim plugin loaded.*/
920 if (find_tap_id("unistim")) {
921 unistim_calls_init_tap();
923 if (find_tap_id("voip")) {
924 VoIPcalls_init_tap();
927 rtp_event_init_tap();
928 mgcp_calls_init_tap();
929 actrace_calls_init_tap();
931 skinny_calls_init_tap();
932 iax2_calls_init_tap();
934 /* create dialog box if necessary */
935 if (voip_calls_dlg == NULL) {
936 voip_calls_dlg_create();
938 /* There's already a dialog box; reactivate it. */
939 reactivate_window(voip_calls_dlg);
942 voip_calls_get_info()->redraw = TRUE;
943 voip_calls_dlg_draw(NULL);
944 voip_calls_get_info()->redraw = TRUE;
945 for (c=0;c<NUM_COLS;c++){
946 data[c]=&field[c][0];
949 g_snprintf(field[3], 50, "Please wait...");
950 gtk_clist_append(GTK_CLIST(clist), data);
952 /* Scan for VoIP calls calls (redissect all packets) */
953 cf_retap_packets(&cfile);
954 gdk_window_raise(voip_calls_dlg->window);
955 /* Tap listener will be removed and cleaned up in voip_calls_on_destroy */
959 /****************************************************************************/
960 /* entry point when called via the GTK menu */
961 static void voip_calls_launch(GtkWidget *w _U_, gpointer data _U_)
963 voip_calls_init_tap("",NULL);
966 /****************************************************************************/
968 register_tap_listener_voip_calls_dlg(void)
970 register_stat_cmd_arg("voip,calls",voip_calls_init_tap,NULL);
971 register_stat_menu_item("VoIP Calls", REGISTER_STAT_GROUP_TELEPHONY,
972 voip_calls_launch, NULL, NULL, NULL);