huge cleanup of capture file API (functions in file.c/file.h).
[obnox/wireshark/wip.git] / gtk / rtp_stream_dlg.c
1 /* rtp_stream_dlg.c
2  * RTP streams summary addition for ethereal
3  *
4  * $Id$
5  *
6  * Copyright 2003, Alcatel Business Systems
7  * By Lars Ruoff <lars.ruoff@gmx.net>
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation,  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif
31
32 #include "rtp_stream_dlg.h"
33 #include "rtp_stream.h"
34 #include "rtp_analysis.h"
35
36 #include "globals.h"
37 #include "epan/filesystem.h"
38
39 #include "tap_menu.h"
40 #include "dlg_utils.h"
41 #include "ui_util.h"
42 #include "compat_macros.h"
43 #include "gtkglobals.h"
44
45 #include "image/clist_ascend.xpm"
46 #include "image/clist_descend.xpm"
47
48 #include "rtp_pt.h"
49
50 #include <epan/address.h>
51
52 #include <string.h>
53
54
55 static const gchar FWD_LABEL_TEXT[] = "Select a forward stream with left mouse button";
56 static const gchar REV_LABEL_TEXT[] = "Select a reverse stream with SHIFT + left mouse button";
57
58 /****************************************************************************/
59 /* pointer to the one and only dialog window */
60 static GtkWidget *rtp_stream_dlg = NULL;
61
62 /* save as dialog box */
63 static GtkWidget *rtpstream_save_dlg = NULL;
64 static GtkWidget *clist = NULL;
65 static GtkWidget *top_label = NULL;
66 static GtkWidget *label_fwd = NULL;
67 static GtkWidget *label_rev = NULL;
68
69 static rtp_stream_info_t* selected_stream_fwd = NULL;  /* current selection */
70 static rtp_stream_info_t* selected_stream_rev = NULL;  /* current selection for reversed */
71 static GList *last_list = NULL;
72
73 static guint32 streams_nb = 0;     /* number of displayed streams */
74
75 /****************************************************************************/
76 /* append a line to clist */
77 static void add_to_clist(rtp_stream_info_t* strinfo)
78 {
79         gchar label_text[256];
80         gint added_row;
81         gchar *data[8];
82         gchar field[8][30];
83
84         data[0]=&field[0][0];
85         data[1]=&field[1][0];
86         data[2]=&field[2][0];
87         data[3]=&field[3][0];
88         data[4]=&field[4][0];
89         data[5]=&field[5][0];
90         data[6]=&field[6][0];
91         data[7]=&field[7][0];
92
93         g_snprintf(field[0], 20, "%s", address_to_str_w_none(&(strinfo->src_addr)));
94         g_snprintf(field[1], 20, "%u", strinfo->src_port);
95         g_snprintf(field[2], 20, "%s", address_to_str_w_none(&(strinfo->dest_addr)));
96         g_snprintf(field[3], 20, "%u", strinfo->dest_port);
97         g_snprintf(field[4], 20, "%u", strinfo->ssrc);
98         g_snprintf(field[5], 30, "%s", val_to_str(strinfo->pt, rtp_payload_type_vals,
99                 "Unknown (%u)"));
100         g_snprintf(field[6], 20, "%u", strinfo->npackets);
101         /* XXX: Comment field is not used for the moment */
102 /*      g_snprintf(field[7], 20, "%s", "");*/
103
104         added_row = gtk_clist_append(GTK_CLIST(clist), data);
105
106         /* set data pointer of last row to point to user data for that row */
107         gtk_clist_set_row_data(GTK_CLIST(clist), added_row, strinfo);
108
109         /* Update the top label with the number of detected streams */
110         sprintf(label_text,
111                 "Detected %d RTP streams. Choose one for forward and reverse direction for analysis",
112                 ++streams_nb);
113         gtk_label_set(GTK_LABEL(top_label), label_text);
114 }
115
116 /****************************************************************************/
117 static void save_stream_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
118 {
119         /* Note that we no longer have a Save voice info dialog box. */
120         rtpstream_save_dlg = NULL;
121 }
122
123 /****************************************************************************/
124 /* save in a file */
125 static void save_stream_ok_cb(GtkWidget *ok_bt _U_, gpointer user_data _U_)
126 {
127         gchar *g_dest;
128
129         if (!selected_stream_fwd)
130                 return;
131
132         g_dest = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION (rtpstream_save_dlg)));
133
134         /* Perhaps the user specified a directory instead of a file.
135         Check whether they did. */
136         if (test_for_directory(g_dest) == EISDIR) {
137                 /* It's a directory - set the file selection box to display it. */
138                 set_last_open_dir(g_dest);
139                 g_free(g_dest);
140                 file_selection_set_current_folder(rtpstream_save_dlg, get_last_open_dir());
141                 return;
142         }
143
144         /*
145          * Don't dismiss the dialog box if the save operation fails.
146          */
147         if (!rtpstream_save(selected_stream_fwd, g_dest))
148                 return;
149
150         window_destroy(GTK_WIDGET(rtpstream_save_dlg));
151 }
152
153
154 /****************************************************************************/
155 /* CALLBACKS                                                                */
156 /****************************************************************************/
157 static void
158 rtpstream_on_destroy                      (GtkObject       *object _U_,
159                                         gpointer         user_data _U_)
160 {
161         /* Remove the stream tap listener */
162         remove_tap_listener_rtp_stream();
163
164         /* Is there a save voice window open? */
165         if (rtpstream_save_dlg != NULL)
166                 window_destroy(rtpstream_save_dlg);
167
168         /* Clean up memory used by stream tap */
169         rtpstream_reset((rtpstream_tapinfo_t*) rtpstream_get_info());
170
171         /* Note that we no longer have a "RTP Streams" dialog box. */
172         rtp_stream_dlg = NULL;
173 }
174
175
176 /****************************************************************************/
177 static void
178 rtpstream_on_unselect                  (GtkButton       *button _U_,
179                                         gpointer         user_data _U_)
180 {
181         selected_stream_fwd = NULL;
182         selected_stream_rev = NULL;
183         gtk_clist_unselect_all(GTK_CLIST(clist));
184         gtk_label_set_text(GTK_LABEL(label_fwd), FWD_LABEL_TEXT);
185         gtk_label_set_text(GTK_LABEL(label_rev), REV_LABEL_TEXT);
186 }
187
188
189 /****************************************************************************/
190 gint rtp_stream_info_cmp_reverse(gconstpointer aa, gconstpointer bb)
191 {
192         const struct _rtp_stream_info* a = aa;
193         const struct _rtp_stream_info* b = bb;
194
195         if (a==NULL || b==NULL)
196                 return 1;
197         if ((ADDRESSES_EQUAL(&(a->src_addr), &(b->dest_addr)))
198                 && (a->src_port == b->dest_port)
199                 && (ADDRESSES_EQUAL(&(a->dest_addr), &(b->src_addr)))
200                 && (a->dest_port == b->src_port))
201                 return 0;
202         else
203                 return 1;
204 }
205
206 /****************************************************************************/
207 static void
208 rtpstream_on_findrev                   (GtkButton       *button _U_,
209                                         gpointer         user_data _U_)
210 {
211         gint row;
212         gint start_row;
213         rtp_stream_info_t* pstream = NULL;
214
215         if (selected_stream_fwd==NULL)
216                 return;
217         if (selected_stream_rev==NULL) {
218                 pstream = selected_stream_fwd;
219         }
220         else {
221                 pstream = selected_stream_rev;
222         }
223
224         start_row = gtk_clist_find_row_from_data(GTK_CLIST(clist), pstream);
225         row = start_row+1;
226
227         for (row=start_row+1;
228                 (pstream = gtk_clist_get_row_data(GTK_CLIST(clist), row));
229                 row++) {
230                 if (rtp_stream_info_cmp_reverse(selected_stream_fwd, pstream) == 0) {
231                         gtk_clist_select_row(GTK_CLIST(clist), row, 0);
232                         gtk_clist_moveto(GTK_CLIST(clist), row, 0, 0.5, 0);
233                         return;
234                 }
235         }
236
237         /* wrap around */
238         for (row=0;
239                 (pstream = gtk_clist_get_row_data(GTK_CLIST(clist), row)) && row<start_row;
240                 row++) {
241                 if (rtp_stream_info_cmp_reverse(selected_stream_fwd, pstream) == 0) {
242                         gtk_clist_select_row(GTK_CLIST(clist), row, 0);
243                         gtk_clist_moveto(GTK_CLIST(clist), row, 0, 0.5, 0);
244                         return;
245                 }
246         }
247
248         /* if we didnt find another stream, highlight the current reverse stream */
249         if (selected_stream_rev!=NULL) {
250                 gtk_clist_select_row(GTK_CLIST(clist), row, 0);
251                 gtk_clist_moveto(GTK_CLIST(clist), row, 0, 0.5, 0);
252         }
253 }
254
255
256 /****************************************************************************/
257 /*
258 static void
259 rtpstream_on_goto                      (GtkButton       *button _U_,
260                                         gpointer         user_data _U_)
261 {
262         if (selected_stream_fwd)
263         {
264                 cf_goto_frame(&cfile, selected_stream_fwd->first_frame_num);
265         }
266 }
267 */
268
269
270 /****************************************************************************/
271 static void
272 rtpstream_on_save                      (GtkButton       *button _U_,
273                                         gpointer         data _U_)
274 {
275         rtpstream_tapinfo_t* tapinfo = data;
276
277         GtkWidget *vertb;
278         GtkWidget *ok_bt;
279
280         if (!selected_stream_fwd)
281                 return;
282
283         if (rtpstream_save_dlg != NULL) {
284                 /* There's already a Save dialog box; reactivate it. */
285                 reactivate_window(rtpstream_save_dlg);
286                 return;
287         }
288
289         /* XXX - use file_selection from dlg_utils instead! */
290         rtpstream_save_dlg = gtk_file_selection_new("Ethereal: Save selected stream in rtpdump ('-F dump') format");
291
292         /* Container for each row of widgets */
293         vertb = gtk_vbox_new(FALSE, 0);
294         gtk_container_border_width(GTK_CONTAINER(vertb), 5);
295         gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(rtpstream_save_dlg)->action_area),
296                 vertb, FALSE, FALSE, 0);
297         gtk_widget_show (vertb);
298
299         ok_bt = GTK_FILE_SELECTION(rtpstream_save_dlg)->ok_button;
300         SIGNAL_CONNECT(ok_bt, "clicked", save_stream_ok_cb, tapinfo);
301
302         window_set_cancel_button(rtpstream_save_dlg,
303             GTK_FILE_SELECTION(rtpstream_save_dlg)->cancel_button, window_cancel_button_cb);
304
305         SIGNAL_CONNECT(rtpstream_save_dlg, "delete_event", window_delete_event_cb, NULL);
306         SIGNAL_CONNECT(rtpstream_save_dlg, "destroy", save_stream_destroy_cb,
307                        NULL);
308
309         gtk_widget_show(rtpstream_save_dlg);
310         window_present(rtpstream_save_dlg);
311 }
312
313
314 /****************************************************************************/
315 static void
316 rtpstream_on_mark                      (GtkButton       *button _U_,
317                                         gpointer         user_data _U_)
318 {
319         if (selected_stream_fwd==NULL && selected_stream_rev==NULL)
320                 return;
321         rtpstream_mark(selected_stream_fwd, selected_stream_rev);
322 }
323
324
325 /****************************************************************************/
326 static void
327 rtpstream_on_filter                    (GtkButton       *button _U_,
328                                         gpointer         user_data _U_)
329 {
330         gchar *filter_string = NULL;
331         gchar *filter_string_fwd = NULL;
332         gchar *filter_string_rev = NULL;
333         gchar ip_version[3];
334
335         if (selected_stream_fwd==NULL && selected_stream_rev==NULL)
336                 return;
337
338         if (selected_stream_fwd)
339         {
340                 if (selected_stream_fwd->src_addr.type==AT_IPv6){
341                         strcpy(ip_version,"v6");
342                 }               
343                 else{
344                         strcpy(ip_version,"");
345                 }
346                 filter_string_fwd = g_strdup_printf(
347                         "(ip%s.src==%s && udp.srcport==%u && ip%s.dst==%s && udp.dstport==%u && rtp.ssrc==%u)",
348                         ip_version,
349                         address_to_str_w_none(&(selected_stream_fwd->src_addr)),
350                         selected_stream_fwd->src_port,
351                         ip_version,
352                         address_to_str_w_none(&(selected_stream_fwd->dest_addr)),
353                         selected_stream_fwd->dest_port,
354                         selected_stream_fwd->ssrc);
355         filter_string = filter_string_fwd;
356         }
357
358         if (selected_stream_rev)
359         {
360                 if (selected_stream_fwd->src_addr.type==AT_IPv6){
361                         strcpy(ip_version,"v6");
362                 }               
363                 else{
364                         strcpy(ip_version,"");
365                 }
366                 filter_string_rev = g_strdup_printf(
367                         "(ip%s.src==%s && udp.srcport==%u && ip%s.dst==%s && udp.dstport==%u && rtp.ssrc==%u)",
368                         ip_version,
369                         address_to_str_w_none(&(selected_stream_rev->src_addr)),
370                         selected_stream_rev->src_port,
371                         ip_version,
372                         address_to_str_w_none(&(selected_stream_rev->dest_addr)),
373                         selected_stream_rev->dest_port,
374                         selected_stream_rev->ssrc);
375
376                 filter_string = filter_string_rev;
377
378             if (selected_stream_fwd)
379             {
380             filter_string = g_strdup_printf("%s || %s", filter_string, filter_string_rev);
381             g_free(filter_string_fwd);
382             g_free(filter_string_rev);
383         }
384     }
385
386     gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
387     g_free(filter_string);
388
389 /*
390         main_filter_packets(&cfile, filter_string, FALSE);
391         rtpstream_dlg_update(rtpstream_get_info()->strinfo_list);
392 */
393 }
394
395
396 /****************************************************************************/
397 static void
398 rtpstream_on_analyse                   (GtkButton       *button _U_,
399                                         gpointer         user_data _U_)
400
401         address ip_src_fwd;
402         guint16 port_src_fwd = 0;
403         address ip_dst_fwd;
404         guint16 port_dst_fwd = 0;
405         guint32 ssrc_fwd = 0;
406         address ip_src_rev;
407         guint16 port_src_rev = 0;
408         address ip_dst_rev;
409         guint16 port_dst_rev = 0;
410         guint32 ssrc_rev = 0;
411         
412         SET_ADDRESS(&ip_src_fwd,AT_NONE,0,NULL);
413         SET_ADDRESS(&ip_dst_fwd,AT_NONE,0,NULL);
414         SET_ADDRESS(&ip_src_rev,AT_NONE,0,NULL);
415         SET_ADDRESS(&ip_dst_rev,AT_NONE,0,NULL);
416         
417         if (selected_stream_fwd) {
418                 COPY_ADDRESS(&(ip_src_fwd), &(selected_stream_fwd->src_addr));
419                 port_src_fwd = selected_stream_fwd->src_port;
420                 COPY_ADDRESS(&(ip_dst_fwd), &(selected_stream_fwd->dest_addr));
421                 port_dst_fwd = selected_stream_fwd->dest_port;
422                 ssrc_fwd = selected_stream_fwd->ssrc;
423         }
424
425         if (selected_stream_rev) {
426                 COPY_ADDRESS(&(ip_src_rev), &(selected_stream_rev->src_addr));
427                 port_src_rev = selected_stream_rev->src_port;
428                 COPY_ADDRESS(&(ip_dst_rev), &(selected_stream_rev->dest_addr));
429                 port_dst_rev = selected_stream_rev->dest_port;
430                 ssrc_rev = selected_stream_rev->ssrc;
431         }
432
433         rtp_analysis(
434                 &ip_src_fwd,
435                 port_src_fwd,
436                 &ip_dst_fwd,
437                 port_dst_fwd,
438                 ssrc_fwd,
439                 &ip_src_rev,
440                 port_src_rev,
441                 &ip_dst_rev,
442                 port_dst_rev,
443                 ssrc_rev
444                 );
445
446 }
447
448
449 /****************************************************************************/
450 /* when the user selects a row in the stream list */
451 static void
452 rtpstream_on_select_row(GtkCList *clist,
453                                             gint row _U_,
454                                             gint column _U_,
455                                             GdkEventButton *event _U_,
456                                             gpointer user_data _U_)
457 {
458         gchar label_text[80];
459
460         /* update the labels */
461         if (event==NULL || event->state & GDK_SHIFT_MASK) {
462                 selected_stream_rev = gtk_clist_get_row_data(GTK_CLIST(clist), row);
463                 g_snprintf(label_text, 80, "Reverse: %s:%u -> %s:%u, SSRC=%u",
464                         address_to_str_w_none(&(selected_stream_rev->src_addr)),
465                         selected_stream_rev->src_port,
466                         address_to_str_w_none(&(selected_stream_rev->dest_addr)),
467                         selected_stream_rev->dest_port,
468                         selected_stream_rev->ssrc
469                 );
470                 gtk_label_set_text(GTK_LABEL(label_rev), label_text);
471         }
472         else {
473                 selected_stream_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
474                 g_snprintf(label_text, 80, "Forward: %s:%u -> %s:%u, SSRC=%u",
475                         address_to_str_w_none(&(selected_stream_fwd->src_addr)),
476                         selected_stream_fwd->src_port,
477                         address_to_str_w_none(&(selected_stream_fwd->dest_addr)),
478                         selected_stream_fwd->dest_port,
479                         selected_stream_fwd->ssrc
480                 );
481                 gtk_label_set_text(GTK_LABEL(label_fwd), label_text);
482         }
483
484 /*
485         gtk_widget_set_sensitive(save_bt, TRUE);
486         gtk_widget_set_sensitive(filter_bt, TRUE);
487         gtk_widget_set_sensitive(mark_bt, TRUE);
488 */
489         /* TODO: activate other buttons when implemented */
490 }
491
492
493 /****************************************************************************/
494 #define NUM_COLS 7
495
496 typedef struct column_arrows {
497         GtkWidget *table;
498         GtkWidget *ascend_pm;
499         GtkWidget *descend_pm;
500 } column_arrows;
501
502
503 /****************************************************************************/
504 static void
505 rtpstream_click_column_cb(GtkCList *clist, gint column, gpointer data)
506 {
507         column_arrows *col_arrows = (column_arrows *) data;
508         int i;
509
510         gtk_clist_freeze(clist);
511
512         for (i=0; i<NUM_COLS; i++) {
513                 gtk_widget_hide(col_arrows[i].ascend_pm);
514                 gtk_widget_hide(col_arrows[i].descend_pm);
515         }
516
517         if (column == clist->sort_column) {
518                 if (clist->sort_type == GTK_SORT_ASCENDING) {
519                         clist->sort_type = GTK_SORT_DESCENDING;
520                         gtk_widget_show(col_arrows[column].descend_pm);
521                 } else {
522                         clist->sort_type = GTK_SORT_ASCENDING;
523                         gtk_widget_show(col_arrows[column].ascend_pm);
524                 }
525         } else {
526                 clist->sort_type = GTK_SORT_ASCENDING;
527                 gtk_widget_show(col_arrows[column].ascend_pm);
528                 gtk_clist_set_sort_column(clist, column);
529         }
530         gtk_clist_thaw(clist);
531
532         gtk_clist_sort(clist);
533 }
534
535
536 /****************************************************************************/
537 static gint
538 rtpstream_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
539 {
540         char *text1 = NULL;
541         char *text2 = NULL;
542         int i1, i2;
543
544         const GtkCListRow *row1 = (const GtkCListRow *) ptr1;
545         const GtkCListRow *row2 = (const GtkCListRow *) ptr2;
546
547         text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
548         text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
549
550         switch(clist->sort_column){
551         case 0:
552         case 2:
553         case 5:
554         case 7:
555                 return strcmp (text1, text2);
556         case 1:
557         case 3:
558         case 4:
559         case 6:
560                 i1=atoi(text1);
561                 i2=atoi(text2);
562                 return i1-i2;
563         }
564         g_assert_not_reached();
565         return 0;
566 }
567
568
569 /****************************************************************************/
570 /* INTERFACE                                                                */
571 /****************************************************************************/
572
573 static void rtpstream_dlg_create (void)
574 {
575         GtkWidget *rtpstream_dlg_w;
576         GtkWidget *main_vb;
577         GtkWidget *scrolledwindow;
578         GtkWidget *hbuttonbox;
579 /*      GtkWidget *bt_goto;*/
580         GtkWidget *bt_unselect;
581         GtkWidget *bt_findrev;
582         GtkWidget *bt_save;
583         GtkWidget *bt_mark;
584         GtkWidget *bt_filter;
585         GtkWidget *bt_analyze;
586         GtkWidget *bt_close;
587     GtkTooltips *tooltips = gtk_tooltips_new();
588
589         gchar *titles[8] =  {"Src IP addr", "Src port",  "Dest IP addr", "Dest port", "SSRC", "Payload", "Packets", "Comment"};
590         column_arrows *col_arrows;
591         GtkWidget *column_lb;
592         int i;
593
594         rtpstream_dlg_w = dlg_window_new("Ethereal: RTP Streams");
595         gtk_window_set_default_size(GTK_WINDOW(rtpstream_dlg_w), 620, 200);
596
597         main_vb = gtk_vbox_new (FALSE, 0);
598         gtk_container_add(GTK_CONTAINER(rtpstream_dlg_w), main_vb);
599         gtk_container_set_border_width (GTK_CONTAINER (main_vb), 12);
600
601         top_label = gtk_label_new ("Detected 0 RTP streams. Choose one for forward and reverse direction for analysis");
602         gtk_box_pack_start (GTK_BOX (main_vb), top_label, FALSE, FALSE, 8);
603
604         scrolledwindow = scrolled_window_new (NULL, NULL);
605         gtk_box_pack_start (GTK_BOX (main_vb), scrolledwindow, TRUE, TRUE, 0);
606
607         clist = gtk_clist_new (NUM_COLS);
608         gtk_container_add (GTK_CONTAINER (scrolledwindow), clist);
609
610         gtk_clist_set_column_width (GTK_CLIST (clist), 0, 100);
611         gtk_clist_set_column_width (GTK_CLIST (clist), 1, 50);
612         gtk_clist_set_column_width (GTK_CLIST (clist), 2, 100);
613         gtk_clist_set_column_width (GTK_CLIST (clist), 3, 50);
614         gtk_clist_set_column_width (GTK_CLIST (clist), 4, 80);
615         gtk_clist_set_column_width (GTK_CLIST (clist), 5, 118);
616         gtk_clist_set_column_width (GTK_CLIST (clist), 6, 40);
617 /*      gtk_clist_set_column_width (GTK_CLIST (clist), 7, 51);*/
618
619         gtk_clist_set_column_justification(GTK_CLIST(clist), 0, GTK_JUSTIFY_CENTER);
620         gtk_clist_set_column_justification(GTK_CLIST(clist), 1, GTK_JUSTIFY_CENTER);
621         gtk_clist_set_column_justification(GTK_CLIST(clist), 2, GTK_JUSTIFY_CENTER);
622         gtk_clist_set_column_justification(GTK_CLIST(clist), 3, GTK_JUSTIFY_CENTER);
623         gtk_clist_set_column_justification(GTK_CLIST(clist), 4, GTK_JUSTIFY_CENTER);
624         gtk_clist_set_column_justification(GTK_CLIST(clist), 5, GTK_JUSTIFY_LEFT);
625         gtk_clist_set_column_justification(GTK_CLIST(clist), 6, GTK_JUSTIFY_RIGHT);
626 /*      gtk_clist_set_column_justification(GTK_CLIST(clist), 7, GTK_JUSTIFY_CENTER);*/
627
628         gtk_clist_column_titles_show (GTK_CLIST (clist));
629
630         gtk_clist_set_compare_func(GTK_CLIST(clist), rtpstream_sort_column);
631         gtk_clist_set_sort_column(GTK_CLIST(clist), 0);
632         gtk_clist_set_sort_type(GTK_CLIST(clist), GTK_SORT_ASCENDING);
633
634         gtk_widget_show(rtpstream_dlg_w);
635
636         /* sort by column feature */
637         col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
638
639         for (i=0; i<NUM_COLS; i++) {
640                 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
641                 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
642                 column_lb = gtk_label_new(titles[i]);
643                 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
644                 gtk_widget_show(column_lb);
645
646                 col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
647                 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
648                 col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
649                 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
650                 /* make src-ip be the default sort order */
651                 if (i == 0) {
652                         gtk_widget_show(col_arrows[i].ascend_pm);
653                 }
654                 gtk_clist_set_column_widget(GTK_CLIST(clist), i, col_arrows[i].table);
655                 gtk_widget_show(col_arrows[i].table);
656         }
657
658         SIGNAL_CONNECT(clist, "click-column", rtpstream_click_column_cb, col_arrows);
659
660         label_fwd = gtk_label_new (FWD_LABEL_TEXT);
661         gtk_box_pack_start (GTK_BOX (main_vb), label_fwd, FALSE, FALSE, 0);
662
663         label_rev = gtk_label_new (REV_LABEL_TEXT);
664         gtk_box_pack_start (GTK_BOX (main_vb), label_rev, FALSE, FALSE, 0);
665
666     /* button row */
667         hbuttonbox = gtk_hbutton_box_new ();
668         gtk_box_pack_start (GTK_BOX (main_vb), hbuttonbox, FALSE, FALSE, 0);
669         gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
670         gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 0);
671
672         bt_unselect = gtk_button_new_with_label ("Unselect");
673         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_unselect);
674     gtk_tooltips_set_tip (tooltips, bt_unselect, "Undo stream selection", NULL);
675
676         bt_findrev = gtk_button_new_with_label ("Find Reverse");
677         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_findrev);
678     gtk_tooltips_set_tip (tooltips, bt_findrev, "Find the reverse stream matching the selected forward stream", NULL);
679 /*
680         bt_goto = BUTTON_NEW_FROM_STOCK(GTK_STOCK_JUMP_TO);
681         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_goto);
682 */
683         bt_save = BUTTON_NEW_FROM_STOCK(GTK_STOCK_SAVE_AS);
684         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_save);
685     gtk_tooltips_set_tip (tooltips, bt_save, "Save stream payload in rtpdump format", NULL);
686
687         bt_mark = gtk_button_new_with_label ("Mark packets");
688         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_mark);
689     gtk_tooltips_set_tip (tooltips, bt_mark, "Mark packets of the selected stream(s)", NULL);
690
691         bt_filter = gtk_button_new_with_label ("Prepare filter");
692         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_filter);
693     gtk_tooltips_set_tip (tooltips, bt_filter, "Prepare a display filter of the selected stream(s)", NULL);
694
695         bt_analyze = gtk_button_new_with_label ("Analyze");
696         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_analyze);
697     gtk_tooltips_set_tip (tooltips, bt_analyze, "Open an analyze window of the selected stream(s)", NULL);
698
699         bt_close = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
700         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_close);
701     gtk_tooltips_set_tip (tooltips, bt_close, "Close this dialog", NULL);
702         GTK_WIDGET_SET_FLAGS(bt_close, GTK_CAN_DEFAULT);
703
704         SIGNAL_CONNECT(clist, "select_row", rtpstream_on_select_row, NULL);
705         SIGNAL_CONNECT(bt_unselect, "clicked", rtpstream_on_unselect, NULL);
706         SIGNAL_CONNECT(bt_findrev, "clicked", rtpstream_on_findrev, NULL);
707 /*
708         SIGNAL_CONNECT(bt_goto, "clicked", rtpstream_on_goto, NULL);
709 */
710         SIGNAL_CONNECT(bt_save, "clicked", rtpstream_on_save, NULL);
711         SIGNAL_CONNECT(bt_mark, "clicked", rtpstream_on_mark, NULL);
712         SIGNAL_CONNECT(bt_filter, "clicked", rtpstream_on_filter, NULL);
713         SIGNAL_CONNECT(bt_analyze, "clicked", rtpstream_on_analyse, NULL);
714
715         window_set_cancel_button(rtpstream_dlg_w, bt_close, window_cancel_button_cb);
716
717         SIGNAL_CONNECT(rtpstream_dlg_w, "delete_event", window_delete_event_cb, NULL);
718         SIGNAL_CONNECT(rtpstream_dlg_w, "destroy", rtpstream_on_destroy, NULL);
719
720         gtk_widget_show_all(rtpstream_dlg_w);
721         window_present(rtpstream_dlg_w);
722
723         rtpstream_on_unselect(NULL, NULL);
724
725         rtp_stream_dlg = rtpstream_dlg_w;
726 }
727
728
729 /****************************************************************************/
730 /* PUBLIC                                                                   */
731 /****************************************************************************/
732
733 /****************************************************************************/
734 /* update the contents of the dialog box clist */
735 /* list: pointer to list of rtp_stream_info_t* */
736 void rtpstream_dlg_update(GList *list)
737 {
738         if (rtp_stream_dlg != NULL) {
739                 gtk_clist_clear(GTK_CLIST(clist));
740                 streams_nb = 0;
741
742                 list = g_list_first(list);
743                 while (list)
744                 {
745                         add_to_clist((rtp_stream_info_t*)(list->data));
746                         list = g_list_next(list);
747                 }
748
749                 rtpstream_on_unselect(NULL, NULL);
750         }
751
752         last_list = list;
753 }
754
755
756 /****************************************************************************/
757 /* update the contents of the dialog box clist */
758 /* list: pointer to list of rtp_stream_info_t* */
759 void rtpstream_dlg_show(GList *list)
760 {
761         if (rtp_stream_dlg != NULL) {
762                 /* There's already a dialog box; reactivate it. */
763                 reactivate_window(rtp_stream_dlg);
764                 /* Another list since last call? */
765                 if (list != last_list) {
766                         rtpstream_dlg_update(list);
767                 }
768         }
769         else {
770                 /* Create and show the dialog box */
771                 rtpstream_dlg_create();
772                 rtpstream_dlg_update(list);
773         }
774 }
775
776
777 /****************************************************************************/
778 /* entry point when called via the GTK menu */
779 void rtpstream_launch(GtkWidget *w _U_, gpointer data _U_)
780 {
781         /* Register the tap listener */
782         register_tap_listener_rtp_stream();
783
784         /* Scan for RTP streams (redissect all packets) */
785         rtpstream_scan();
786
787         /* Show the dialog box with the list of streams */
788         rtpstream_dlg_show(rtpstream_get_info()->strinfo_list);
789
790         /* Tap listener will be removed and cleaned up in rtpstream_on_destroy */
791 }
792
793 /****************************************************************************/
794 void
795 register_tap_listener_rtp_stream_dlg(void)
796 {
797         register_tap_menu_item("RTP/Show All Streams...", REGISTER_TAP_GROUP_NONE,
798             rtpstream_launch, NULL, NULL, NULL);
799 }