"hex_str_to_bytes()" modifies the GByteArray supplied to it, so don't
[obnox/wireshark/wip.git] / gtk / rtp_stream_dlg.c
1 /* rtp_stream_dlg.c
2  * RTP streams summary addition for ethereal
3  *
4  * $Id: rtp_stream_dlg.c,v 1.7 2003/12/17 22:13:08 guy Exp $
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 "menu.h"
40 #include "dlg_utils.h"
41 #include "ui_util.h"
42 #include "main.h"
43 #include "compat_macros.h"
44
45 #include "rtp_pt.h"
46
47 #include <string.h>
48
49 extern GtkWidget *main_display_filter_widget;
50
51 static const value_string rtp_payload_type_vals[] =
52 {
53         { PT_PCMU,      "ITU-T G.711 PCMU" },
54         { PT_1016,      "USA Federal Standard FS-1016" },
55         { PT_G721,      "ITU-T G.721" },
56         { PT_GSM,       "GSM 06.10" },
57         { PT_G723,      "ITU-T G.723" },
58         { PT_DVI4_8000, "DVI4 8000 samples/s" },
59         { PT_DVI4_16000, "DVI4 16000 samples/s" },
60         { PT_LPC,       "Experimental linear predictive encoding from Xerox PARC" },
61         { PT_PCMA,      "ITU-T G.711 PCMA" },
62         { PT_G722,      "ITU-T G.722" },
63         { PT_L16_STEREO, "16-bit uncompressed audio, stereo" },
64         { PT_L16_MONO,  "16-bit uncompressed audio, monaural" },
65         { PT_QCELP,     "Qualcomm Code Excited Linear Predictive coding" },
66         { PT_CN,        "Comfort noise" },
67         { PT_MPA,       "MPEG-I/II Audio"},
68         { PT_G728,      "ITU-T G.728" },
69         { PT_DVI4_11025, "DVI4 11025 samples/s" },
70         { PT_DVI4_22050, "DVI4 22050 samples/s" },
71         { PT_G729,      "ITU-T G.729" },
72         { PT_CELB,      "Sun CellB video encoding" },
73         { PT_JPEG,      "JPEG-compressed video" },
74         { PT_NV,        "'nv' program" },
75         { PT_H261,      "ITU-T H.261" },
76         { PT_MPV,       "MPEG-I/II Video"},
77         { PT_MP2T,      "MPEG-II transport streams"},
78         { PT_H263,      "ITU-T H.263" },
79         { 0,            NULL },
80 };
81
82
83 typedef const guint8 * ip_addr_p;
84
85 static const gchar FWD_LABEL_TEXT[] = "Select a forward stream with left mouse button";
86 static const gchar REV_LABEL_TEXT[] = "Select a reverse stream with SHIFT + left mouse button";
87
88 /****************************************************************************/
89 /* pointer to the one and only dialog window */
90 static GtkWidget *rtp_stream_dlg = NULL;
91
92 /* save as dialog box */
93 static GtkWidget *rtpstream_save_dlg = NULL;
94 static GtkWidget *clist = NULL;
95 static GtkWidget *label_fwd = NULL;
96 static GtkWidget *label_rev = NULL;
97
98 static rtp_stream_info_t* selected_stream_fwd = NULL;  /* current selection */
99 static rtp_stream_info_t* selected_stream_rev = NULL;  /* current selection for reversed */
100 static GList *last_list = NULL;
101
102
103 /****************************************************************************/
104 /* append a line to clist */
105 static void add_to_clist(rtp_stream_info_t* strinfo)
106 {
107         gint added_row;
108         gchar *data[8];
109         gchar field[8][30];
110
111         data[0]=&field[0][0];
112         data[1]=&field[1][0];
113         data[2]=&field[2][0];
114         data[3]=&field[3][0];
115         data[4]=&field[4][0];
116         data[5]=&field[5][0];
117         data[6]=&field[6][0];
118         data[7]=&field[7][0];
119
120         g_snprintf(field[0], 20, "%s", ip_to_str((const guint8*)&(strinfo->src_addr)));
121         g_snprintf(field[1], 20, "%u", strinfo->src_port);
122         g_snprintf(field[2], 20, "%s", ip_to_str((const guint8*)&(strinfo->dest_addr)));
123         g_snprintf(field[3], 20, "%u", strinfo->dest_port);
124         g_snprintf(field[4], 20, "%u", strinfo->ssrc);
125         g_snprintf(field[5], 30, "%s", val_to_str(strinfo->pt, rtp_payload_type_vals,
126                 "Unknown (%u)"));
127         g_snprintf(field[6], 20, "%u", strinfo->npackets);
128         /* XXX: Comment field is not used for the moment */
129 /*      g_snprintf(field[7], 20, "%s", "");*/
130
131         added_row = gtk_clist_append(GTK_CLIST(clist), data);
132
133         /* set data pointer of last row to point to user data for that row */
134         gtk_clist_set_row_data(GTK_CLIST(clist), added_row, strinfo);
135 }
136
137 /****************************************************************************/
138 static void save_stream_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
139 {
140         /* Note that we no longer have a Save voice info dialog box. */
141         rtpstream_save_dlg = NULL;
142 }
143
144 /****************************************************************************/
145 /* save in a file */
146 static void save_stream_ok_cb(GtkWidget *ok_bt _U_, gpointer user_data _U_)
147 {
148         gchar *g_dest;
149
150         if (!selected_stream_fwd)
151                 return;
152
153         g_dest = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION (rtpstream_save_dlg)));
154
155         /* Perhaps the user specified a directory instead of a file.
156         Check whether they did. */
157         if (test_for_directory(g_dest) == EISDIR) {
158                 /* It's a directory - set the file selection box to display it. */
159                 set_last_open_dir(g_dest);
160                 g_free(g_dest);
161                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(rtpstream_save_dlg), last_open_dir);
162                 return;
163         }
164
165         rtpstream_save(selected_stream_fwd, g_dest);
166
167         gtk_widget_destroy(GTK_WIDGET(rtpstream_save_dlg));
168 }
169
170
171 /****************************************************************************/
172 /* CALLBACKS                                                                */
173 /****************************************************************************/
174 static void
175 rtpstream_on_destroy                      (GtkObject       *object _U_,
176                                         gpointer         user_data _U_)
177 {
178         /* Remove the stream tap listener */
179         remove_tap_listener_rtp_stream();
180
181         /* Is there a save voice window open? */
182         if (rtpstream_save_dlg != NULL)
183                 gtk_widget_destroy(rtpstream_save_dlg);
184
185         /* Clean up memory used by stream tap */
186         rtpstream_reset((rtpstream_tapinfo_t*) rtpstream_get_info());
187
188         /* Note that we no longer have a "RTP Streams" dialog box. */
189         rtp_stream_dlg = NULL;
190 }
191
192
193 /****************************************************************************/
194 static void
195 rtpstream_on_unselect                  (GtkButton       *button _U_,
196                                         gpointer         user_data _U_)
197 {
198         selected_stream_fwd = NULL;
199         selected_stream_rev = NULL;
200         gtk_clist_unselect_all(GTK_CLIST(clist));
201         gtk_label_set_text(GTK_LABEL(label_fwd), FWD_LABEL_TEXT);
202         gtk_label_set_text(GTK_LABEL(label_rev), REV_LABEL_TEXT);
203 }
204
205
206 /****************************************************************************/
207 /*
208 static void
209 rtpstream_on_goto                      (GtkButton       *button _U_,
210                                         gpointer         user_data _U_)
211 {
212         if (selected_stream_fwd)
213         {
214                 goto_frame(&cfile, selected_stream_fwd->first_frame_num);
215         }
216 }
217 */
218
219
220 /****************************************************************************/
221 static void
222 rtpstream_on_save                      (GtkButton       *button _U_,
223                                         gpointer         data _U_)
224 {
225         rtpstream_tapinfo_t* tapinfo = data;
226
227         GtkWidget *vertb;
228         GtkWidget *ok_bt;
229
230         if (!selected_stream_fwd)
231                 return;
232
233         if (rtpstream_save_dlg != NULL) {
234                 /* There's already a Save dialog box; reactivate it. */
235                 reactivate_window(rtpstream_save_dlg);
236                 return;
237         }
238
239         rtpstream_save_dlg = gtk_file_selection_new("Ethereal: Save selected stream in rtpdump ('-F dump') format");
240         SIGNAL_CONNECT(rtpstream_save_dlg, "destroy", save_stream_destroy_cb,
241                        NULL);
242
243         /* Container for each row of widgets */
244         vertb = gtk_vbox_new(FALSE, 0);
245         gtk_container_border_width(GTK_CONTAINER(vertb), 5);
246         gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(rtpstream_save_dlg)->action_area),
247                 vertb, FALSE, FALSE, 0);
248         gtk_widget_show (vertb);
249
250         ok_bt = GTK_FILE_SELECTION(rtpstream_save_dlg)->ok_button;
251 /*      OBJECT_SET_DATA(ok_bt, "user_data", tapinfo);*/
252
253         /* Connect the cancel_button to destroy the widget */
254         SIGNAL_CONNECT_OBJECT(GTK_FILE_SELECTION(rtpstream_save_dlg)->cancel_button,
255                 "clicked", (GtkSignalFunc)gtk_widget_destroy,
256                 rtpstream_save_dlg);
257
258         /* Catch the "key_press_event" signal in the window, so that we can catch
259         the ESC key being pressed and act as if the "Cancel" button had
260         been selected. */
261         dlg_set_cancel(rtpstream_save_dlg, GTK_FILE_SELECTION(rtpstream_save_dlg)->cancel_button);
262
263         SIGNAL_CONNECT(ok_bt, "clicked", save_stream_ok_cb, tapinfo);
264
265         gtk_widget_show(rtpstream_save_dlg);
266 }
267
268
269 /****************************************************************************/
270 static void
271 rtpstream_on_mark                      (GtkButton       *button _U_,
272                                         gpointer         user_data _U_)
273 {
274         if (selected_stream_fwd==NULL && selected_stream_rev==NULL)
275                 return;
276         rtpstream_mark(selected_stream_fwd, selected_stream_rev);
277 }
278
279
280 #define MAX_FILTER_LENGTH 320
281
282 /****************************************************************************/
283 static void
284 rtpstream_on_filter                    (GtkButton       *button _U_,
285                                         gpointer         user_data _U_)
286 {
287         gchar filter_string[MAX_FILTER_LENGTH] = "";
288         gchar filter_string_rev[MAX_FILTER_LENGTH] = "";
289
290         if (selected_stream_fwd==NULL && selected_stream_rev==NULL)
291                 return;
292
293         if (selected_stream_fwd)
294         {
295                 g_snprintf(filter_string, MAX_FILTER_LENGTH,
296                         "(ip.src==%s && udp.srcport==%u && ip.dst==%s && udp.dstport==%u && rtp.ssrc==%u)",
297                         ip_to_str((const guint8*)&(selected_stream_fwd->src_addr)),
298                         selected_stream_fwd->src_port,
299                         ip_to_str((const guint8*)&(selected_stream_fwd->dest_addr)),
300                         selected_stream_fwd->dest_port,
301                         selected_stream_fwd->ssrc);
302
303                 if (selected_stream_rev)
304                 {
305                         strcat(filter_string, " || ");
306                 }
307         }
308
309         if (selected_stream_rev)
310         {
311                 g_snprintf(filter_string_rev, MAX_FILTER_LENGTH,
312                         "(ip.src==%s && udp.srcport==%u && ip.dst==%s && udp.dstport==%u && rtp.ssrc==%u)",
313                         ip_to_str((const guint8*)&(selected_stream_rev->src_addr)),
314                         selected_stream_rev->src_port,
315                         ip_to_str((const guint8*)&(selected_stream_rev->dest_addr)),
316                         selected_stream_rev->dest_port,
317                         selected_stream_rev->ssrc);
318                 strcat(filter_string, filter_string_rev);
319         }
320
321         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
322 /*
323         filter_packets(&cfile, filter_string);
324         rtpstream_dlg_update(rtpstream_get_info()->strinfo_list);
325 */
326 }
327
328
329 /****************************************************************************/
330 static void
331 rtpstream_on_close                     (GtkButton        *button _U_,
332                                         gpointer         user_data _U_)
333 {
334         gtk_grab_remove(rtp_stream_dlg);
335         gtk_widget_destroy(rtp_stream_dlg);
336 }
337
338
339 /****************************************************************************/
340 static void
341 rtpstream_on_analyse                   (GtkButton       *button _U_,
342                                         gpointer         user_data _U_)
343 {
344         guint32 ip_src_fwd = 0;
345         guint16 port_src_fwd = 0;
346         guint32 ip_dst_fwd = 0;
347         guint16 port_dst_fwd = 0;
348         guint32 ssrc_fwd = 0;
349         guint32 ip_src_rev = 0;
350         guint16 port_src_rev = 0;
351         guint32 ip_dst_rev = 0;
352         guint16 port_dst_rev = 0;
353         guint32 ssrc_rev = 0;
354
355         if (selected_stream_fwd) {
356                 ip_src_fwd = selected_stream_fwd->src_addr;
357                 port_src_fwd = selected_stream_fwd->src_port;
358                 ip_dst_fwd = selected_stream_fwd->dest_addr;
359                 port_dst_fwd = selected_stream_fwd->dest_port;
360                 ssrc_fwd = selected_stream_fwd->ssrc;
361         }
362
363         if (selected_stream_rev) {
364                 ip_src_rev = selected_stream_rev->src_addr;
365                 port_src_rev = selected_stream_rev->src_port;
366                 ip_dst_rev = selected_stream_rev->dest_addr;
367                 port_dst_rev = selected_stream_rev->dest_port;
368                 ssrc_rev = selected_stream_rev->ssrc;
369         }
370
371         rtp_analysis(
372                 ip_src_fwd,
373                 port_src_fwd,
374                 ip_dst_fwd,
375                 port_dst_fwd,
376                 ssrc_fwd,
377                 ip_src_rev,
378                 port_src_rev,
379                 ip_dst_rev,
380                 port_dst_rev,
381                 ssrc_rev
382                 );
383
384 }
385
386
387 /****************************************************************************/
388 /* This should be the callback function called upon a user-defined
389  * event "signal_rtpstream_update", but i didn't knoow how to do with GTK
390 static void
391 rtpstream_on_update                    (GtkButton       *button _U_,
392                                         gpointer         user_data _U_)
393 {
394         rtpstream_dlg_update(rtpstream_get_info()->strinfo_list);
395 }
396 */
397
398 /****************************************************************************/
399 /* when the user selects a row in the stream list */
400 static void
401 rtpstream_on_select_row(GtkCList *clist,
402                                             gint row _U_,
403                                             gint column _U_,
404                                             GdkEventButton *event _U_,
405                                             gpointer user_data _U_)
406 {
407         gchar label_text[80];
408
409         /* update the labels */
410         if (event->state & GDK_SHIFT_MASK) {
411                 selected_stream_rev = gtk_clist_get_row_data(GTK_CLIST(clist), row);
412                 g_snprintf(label_text, 80, "Reverse: %s:%u -> %s:%u, SSRC=%u",
413                         ip_to_str((ip_addr_p)&selected_stream_rev->src_addr),
414                         selected_stream_rev->src_port,
415                         ip_to_str((ip_addr_p)&selected_stream_rev->dest_addr),
416                         selected_stream_rev->dest_port,
417                         selected_stream_rev->ssrc
418                 );
419                 gtk_label_set_text(GTK_LABEL(label_rev), label_text);
420         }
421         else {
422                 selected_stream_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
423                 g_snprintf(label_text, 80, "Forward: %s:%u -> %s:%u, SSRC=%u",
424                         ip_to_str((ip_addr_p)&selected_stream_fwd->src_addr),
425                         selected_stream_fwd->src_port,
426                         ip_to_str((ip_addr_p)&selected_stream_fwd->dest_addr),
427                         selected_stream_fwd->dest_port,
428                         selected_stream_fwd->ssrc
429                 );
430                 gtk_label_set_text(GTK_LABEL(label_fwd), label_text);
431         }
432
433 /*
434         gtk_widget_set_sensitive(save_bt, TRUE);
435         gtk_widget_set_sensitive(filter_bt, TRUE);
436         gtk_widget_set_sensitive(mark_bt, TRUE);
437 */
438         /* TODO: activate other buttons when implemented */
439 }
440
441
442 /****************************************************************************/
443 /* INTERFACE                                                                */
444 /****************************************************************************/
445
446 static void rtpstream_dlg_create (void)
447 {
448         /* these are global static now:
449         GtkWidget *clist = NULL;
450         GtkWidget *label_fwd = NULL;
451         GtkWidget *label_rev = NULL;
452         */
453         GtkWidget *rtpstream_dlg_w;
454         GtkWidget *dialog_vbox1;
455         GtkWidget *vbox1;
456         GtkWidget *label10;
457         GtkWidget *scrolledwindow1;
458         GtkWidget *label2;
459         GtkWidget *label3;
460         GtkWidget *label4;
461         GtkWidget *label5;
462         GtkWidget *label6;
463         GtkWidget *label7;
464         GtkWidget *label8;
465 /*      GtkWidget *label9;*/
466         GtkWidget *dialog_action_area1;
467         GtkWidget *hbuttonbox2;
468 /*      GtkWidget *bt_goto;*/
469         GtkWidget *bt_unselect;
470         GtkWidget *bt_save;
471         GtkWidget *bt_frames;
472         GtkWidget *bt_filter;
473         GtkWidget *bt_analyse;
474         GtkWidget *bt_close;
475         
476         rtpstream_dlg_w = gtk_dialog_new();
477         gtk_window_set_title (GTK_WINDOW (rtpstream_dlg_w), "Ethereal: RTP Streams");
478         
479         dialog_vbox1 = GTK_DIALOG (rtpstream_dlg_w)->vbox;
480         gtk_widget_show (dialog_vbox1);
481         
482         vbox1 = gtk_vbox_new (FALSE, 0);
483         gtk_widget_ref (vbox1);
484         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "vbox1", vbox1, gtk_widget_unref);
485         gtk_widget_show (vbox1);
486         gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, TRUE, TRUE, 0);
487         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 8);
488         
489         label10 = gtk_label_new ("Detected RTP streams. Choose one for forward and reverse direction for analysis");
490         gtk_widget_ref (label10);
491         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label10", label10,
492                              gtk_widget_unref);
493         gtk_widget_show (label10);
494         gtk_box_pack_start (GTK_BOX (vbox1), label10, FALSE, FALSE, 0);
495         WIDGET_SET_SIZE(label10, -2, 32);
496         
497         scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
498         gtk_widget_ref (scrolledwindow1);
499         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "scrolledwindow1",
500                              scrolledwindow1, gtk_widget_unref);
501         gtk_widget_show (scrolledwindow1);
502         gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
503         
504         clist = gtk_clist_new (7); /* defines number of columns */
505         gtk_widget_ref (clist);
506         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "clist", clist, gtk_widget_unref);
507         gtk_widget_show (clist);
508         gtk_container_add (GTK_CONTAINER (scrolledwindow1), clist);
509         WIDGET_SET_SIZE(clist, 640, 200);
510         gtk_clist_set_column_width (GTK_CLIST (clist), 0, 100);
511         gtk_clist_set_column_width (GTK_CLIST (clist), 1, 50);
512         gtk_clist_set_column_width (GTK_CLIST (clist), 2, 100);
513         gtk_clist_set_column_width (GTK_CLIST (clist), 3, 50);
514         gtk_clist_set_column_width (GTK_CLIST (clist), 4, 80);
515         gtk_clist_set_column_width (GTK_CLIST (clist), 5, 118);
516         gtk_clist_set_column_width (GTK_CLIST (clist), 6, 60);
517 /*      gtk_clist_set_column_width (GTK_CLIST (clist), 7, 51);*/
518         gtk_clist_column_titles_show (GTK_CLIST (clist));
519         
520         label2 = gtk_label_new ("Src IP addr");
521         gtk_widget_ref (label2);
522         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label2", label2,
523                              gtk_widget_unref);
524         gtk_widget_show (label2);
525         gtk_clist_set_column_widget (GTK_CLIST (clist), 0, label2);
526         
527         label3 = gtk_label_new ("Src port");
528         gtk_widget_ref (label3);
529         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label3", label3,
530                              gtk_widget_unref);
531         gtk_widget_show (label3);
532         gtk_clist_set_column_widget (GTK_CLIST (clist), 1, label3);
533         
534         label4 = gtk_label_new ("Dest IP addr");
535         gtk_widget_ref (label4);
536         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label4", label4,
537                              gtk_widget_unref);
538         gtk_widget_show (label4);
539         gtk_clist_set_column_widget (GTK_CLIST (clist), 2, label4);
540         
541         label5 = gtk_label_new ("Dest port");
542         gtk_widget_ref (label5);
543         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label5", label5,
544                              gtk_widget_unref);
545         gtk_widget_show (label5);
546         gtk_clist_set_column_widget (GTK_CLIST (clist), 3, label5);
547         
548         label6 = gtk_label_new ("SSRC");
549         gtk_widget_ref (label6);
550         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label6", label6,
551                              gtk_widget_unref);
552         gtk_widget_show (label6);
553         gtk_clist_set_column_widget (GTK_CLIST (clist), 4, label6);
554         WIDGET_SET_SIZE(label6, 80, -2);
555         
556         label7 = gtk_label_new ("Payload");
557         gtk_widget_ref (label7);
558         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label7", label7,
559                              gtk_widget_unref);
560         gtk_widget_show (label7);
561         gtk_clist_set_column_widget (GTK_CLIST (clist), 5, label7);
562         
563         label8 = gtk_label_new ("Packets");
564         gtk_widget_ref (label8);
565         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label8", label8,
566                              gtk_widget_unref);
567         gtk_widget_show (label8);
568         gtk_clist_set_column_widget (GTK_CLIST (clist), 6, label8);
569 /*      
570         label9 = gtk_label_new ("Comment");
571         gtk_widget_ref (label9);
572         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label9", label9,
573                              gtk_widget_unref);
574         gtk_widget_show (label9);
575         gtk_clist_set_column_widget (GTK_CLIST (clist), 7, label9);
576 */      
577         label_fwd = gtk_label_new (FWD_LABEL_TEXT);
578         gtk_widget_ref (label_fwd);
579         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label_fwd", label_fwd,
580                              gtk_widget_unref);
581         gtk_widget_show (label_fwd);
582         gtk_box_pack_start (GTK_BOX (vbox1), label_fwd, FALSE, FALSE, 0);
583         gtk_label_set_justify (GTK_LABEL (label_fwd), GTK_JUSTIFY_LEFT);
584         
585         label_rev = gtk_label_new (REV_LABEL_TEXT);
586         gtk_widget_ref (label_rev);
587         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "label_rev", label_rev,
588                              gtk_widget_unref);
589         gtk_widget_show (label_rev);
590         gtk_box_pack_start (GTK_BOX (vbox1), label_rev, FALSE, FALSE, 0);
591         gtk_label_set_justify (GTK_LABEL (label_rev), GTK_JUSTIFY_LEFT);
592         
593         dialog_action_area1 = GTK_DIALOG (rtpstream_dlg_w)->action_area;
594         gtk_widget_show (dialog_action_area1);
595         gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 10);
596         
597         hbuttonbox2 = gtk_hbutton_box_new ();
598         gtk_widget_ref (hbuttonbox2);
599         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "hbuttonbox2", hbuttonbox2,
600                              gtk_widget_unref);
601         gtk_widget_show (hbuttonbox2);
602         gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox2, FALSE, FALSE, 0);
603         gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox2), GTK_BUTTONBOX_END);
604         gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox2), 0);
605         
606         bt_unselect = gtk_button_new_with_label ("Unselect");
607         gtk_widget_ref (bt_unselect);
608         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_unselect", bt_unselect,
609                              gtk_widget_unref);
610         gtk_widget_show (bt_unselect);
611         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_unselect);
612         GTK_WIDGET_SET_FLAGS (bt_unselect, GTK_CAN_DEFAULT);
613 /*      
614         bt_goto = gtk_button_new_with_label ("Go to Frame");
615         gtk_widget_ref (bt_goto);
616         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_goto", bt_goto,
617                              gtk_widget_unref);
618         gtk_widget_show (bt_goto);
619         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_goto);
620         GTK_WIDGET_SET_FLAGS (bt_goto, GTK_CAN_DEFAULT);
621 */      
622         bt_save = gtk_button_new_with_label ("Save as...");
623         gtk_widget_ref (bt_save);
624         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_save", bt_save,
625                              gtk_widget_unref);
626         gtk_widget_show (bt_save);
627         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_save);
628         GTK_WIDGET_SET_FLAGS (bt_save, GTK_CAN_DEFAULT);
629         
630         bt_frames = gtk_button_new_with_label ("Mark frames");
631         gtk_widget_ref (bt_frames);
632         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_frames", bt_frames,
633                              gtk_widget_unref);
634         gtk_widget_show (bt_frames);
635         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_frames);
636         GTK_WIDGET_SET_FLAGS (bt_frames, GTK_CAN_DEFAULT);
637         
638         bt_filter = gtk_button_new_with_label ("Set filter");
639         gtk_widget_ref (bt_filter);
640         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_filter", bt_filter,
641                              gtk_widget_unref);
642         gtk_widget_show (bt_filter);
643         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_filter);
644         GTK_WIDGET_SET_FLAGS (bt_filter, GTK_CAN_DEFAULT);
645         
646         bt_analyse = gtk_button_new_with_label ("Analyse");
647         gtk_widget_ref (bt_analyse);
648         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_analyse", bt_analyse,
649                              gtk_widget_unref);
650         gtk_widget_show (bt_analyse);
651         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_analyse);
652         GTK_WIDGET_SET_FLAGS (bt_analyse, GTK_CAN_DEFAULT);
653         
654         bt_close = gtk_button_new_with_label ("Close");
655         gtk_widget_ref (bt_close);
656         OBJECT_SET_DATA_FULL(rtpstream_dlg_w, "bt_close", bt_close,
657                              gtk_widget_unref);
658         gtk_widget_show (bt_close);
659         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_close);
660         GTK_WIDGET_SET_FLAGS (bt_close, GTK_CAN_DEFAULT);
661         
662         SIGNAL_CONNECT(rtpstream_dlg_w, "destroy", rtpstream_on_destroy, NULL);
663         SIGNAL_CONNECT(clist, "select_row", rtpstream_on_select_row, NULL);
664         SIGNAL_CONNECT(bt_unselect, "clicked", rtpstream_on_unselect, NULL);
665 /*
666         gtk_signal_connect (GTK_OBJECT (bt_goto), "clicked",
667                 GTK_SIGNAL_FUNC (rtpstream_on_goto),
668                 NULL);
669 */
670         SIGNAL_CONNECT(bt_save, "clicked", rtpstream_on_save, NULL);
671         SIGNAL_CONNECT(bt_frames, "clicked", rtpstream_on_mark, NULL);
672         SIGNAL_CONNECT(bt_filter, "clicked", rtpstream_on_filter, NULL);
673         SIGNAL_CONNECT(bt_analyse, "clicked", rtpstream_on_analyse, NULL);
674         SIGNAL_CONNECT(bt_close, "clicked", rtpstream_on_close, NULL);
675 /* XXX: see rtpstream_on_update for comment
676         gtk_signal_connect (GTK_OBJECT (top_level), "signal_rtpstream_update",
677                 GTK_SIGNAL_FUNC (rtpstream_on_update),
678                 NULL);
679 */
680         
681         if (clist) {
682                 gtk_clist_set_column_justification(GTK_CLIST(clist), 0, GTK_JUSTIFY_CENTER);
683                 gtk_clist_set_column_justification(GTK_CLIST(clist), 1, GTK_JUSTIFY_CENTER);
684                 gtk_clist_set_column_justification(GTK_CLIST(clist), 2, GTK_JUSTIFY_CENTER);
685                 gtk_clist_set_column_justification(GTK_CLIST(clist), 3, GTK_JUSTIFY_CENTER);
686                 gtk_clist_set_column_justification(GTK_CLIST(clist), 4, GTK_JUSTIFY_CENTER);
687                 gtk_clist_set_column_justification(GTK_CLIST(clist), 5, GTK_JUSTIFY_LEFT);
688                 gtk_clist_set_column_justification(GTK_CLIST(clist), 6, GTK_JUSTIFY_RIGHT);
689 /*              gtk_clist_set_column_justification(GTK_CLIST(clist), 7, GTK_JUSTIFY_CENTER);*/
690         }
691
692         rtpstream_on_unselect(NULL, NULL);
693
694         rtp_stream_dlg = rtpstream_dlg_w;
695 }
696
697
698 /****************************************************************************/
699 /* PUBLIC                                                                   */
700 /****************************************************************************/
701
702 /****************************************************************************/
703 /* update the contents of the dialog box clist */
704 /* list: pointer to list of rtp_stream_info_t* */
705 void rtpstream_dlg_update(GList *list)
706 {
707         if (rtp_stream_dlg != NULL) {
708                 gtk_clist_clear(GTK_CLIST(clist));
709
710                 list = g_list_first(list);
711                 while (list)
712                 {
713                         add_to_clist((rtp_stream_info_t*)(list->data));
714                         list = g_list_next(list);
715                 }
716
717                 rtpstream_on_unselect(NULL, NULL);
718         }
719
720         last_list = list;
721 }
722
723
724 /****************************************************************************/
725 /* update the contents of the dialog box clist */
726 /* list: pointer to list of rtp_stream_info_t* */
727 void rtpstream_dlg_show(GList *list)
728 {
729         if (rtp_stream_dlg != NULL) {
730                 /* There's already a dialog box; reactivate it. */
731                 reactivate_window(rtp_stream_dlg);
732                 /* Another list since last call? */
733                 if (list != last_list) {
734                         rtpstream_dlg_update(list);
735                 }
736         }
737         else {
738                 /* Create and show the dialog box */
739                 rtpstream_dlg_create();
740                 rtpstream_dlg_update(list);
741                 gtk_widget_show(rtp_stream_dlg);
742         }
743 }
744
745
746 /****************************************************************************/
747 /* entry point when called via the GTK menu */
748 void rtpstream_launch(GtkWidget *w _U_, gpointer data _U_)
749 {
750         /* Register the tap listener */
751         register_tap_listener_rtp_stream();
752
753         /* Scan for RTP streams (redissect all packets) */
754         rtpstream_scan();
755
756         /* Show the dialog box with the list of streams */
757         rtpstream_dlg_show(rtpstream_get_info()->strinfo_list);
758
759         /* Tap listener will be removed and cleaned up in rtpstream_on_destroy */
760 }
761
762 /****************************************************************************/
763 void
764 register_tap_menu_rtp_stream(void)
765 {
766         register_tap_menu_item("Statistics/RTP Streams/Show All...",
767             rtpstream_launch, NULL, NULL, NULL);
768 }