Have the frame_tvbuff.c routines not use the global cfile.
[metze/wireshark/wip.git] / ui / gtk / sctp_stat_dlg.c
1 /*
2  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24 #include <string.h>
25
26 #include <gtk/gtk.h>
27
28 #include "epan/to_str.h"
29
30 #include <epan/stat_groups.h>
31
32 #include "ui/gtk/gui_stat_menu.h"
33 #include "ui/gtk/gui_utils.h"
34 #include "ui/gtk/main.h"
35 #include "ui/gtk/sctp_stat_gtk.h"
36 #include "ui/gtk/gtkglobals.h"
37
38 #include "ui/gtk/old-gtk-compat.h"
39 #include "ui/gtk/stock_icons.h"
40
41 #include "globals.h"
42
43 static GtkWidget *sctp_stat_dlg = NULL;
44 static GtkWidget *clist         = NULL;
45 static GList     *last_list     = NULL;
46 static gchar     *filter_string = NULL;
47 static sctp_assoc_info_t     *selected_stream = NULL;  /* current selection */
48 static sctp_allassocs_info_t *sctp_assocs = NULL;
49 static guint16    n_children = 0;
50 static GtkWidget *bt_afilter = NULL, *bt_unselect = NULL, *bt_analyse = NULL, *bt_filter = NULL;
51 static gboolean   prevent_update = FALSE, filter_applied = FALSE;
52
53 enum
54 {
55         PORT1_COLUMN,
56         PORT2_COLUMN,
57         PACKETS_COLUMN,
58         CHECKSUM_TYPE_COLUMN,
59         CHECKSUM_ERRORS_COLUMN,
60         DATA_CHUNKS_COLUMN,
61         DATA_BYTES_COLUMN,
62         VTAG1_COLUMN,
63         VTAG2_COLUMN,
64         N_COLUMN
65 };
66
67
68 static void
69 sctp_stat_on_select_row(GtkTreeSelection *sel, gpointer user_data _U_)
70 {
71         GtkTreeModel      *model;
72         GtkTreeIter        iter;
73         GList             *list;
74         sctp_assoc_info_t *assoc;
75         gboolean           stream_found = FALSE;
76         guint32            port2, port1;
77         guint32            checksum, data_chunks, data_bytes, packets, vtag1, vtag2;
78
79         if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
80                 gtk_tree_model_get(model, &iter,
81                         PORT1_COLUMN, &port1,
82                         PORT2_COLUMN, &port2,
83                         PACKETS_COLUMN, &packets,
84                         CHECKSUM_ERRORS_COLUMN, &checksum,
85                         DATA_CHUNKS_COLUMN, &data_chunks,
86                         DATA_BYTES_COLUMN, &data_bytes,
87                         VTAG1_COLUMN, &vtag1,
88                         VTAG2_COLUMN, &vtag2,
89                         -1);
90         } else {
91                 /* Nothing selected */
92                 return;
93         }
94
95         list = g_list_first(sctp_assocs->assoc_info_list);
96
97         while (list)
98         {
99                 assoc = (sctp_assoc_info_t*)(list->data);
100                 if ((assoc->port1 == port1) && (assoc->port2 == port2)
101                     && (assoc->n_packets     == packets)
102                     && (assoc->n_data_chunks == data_chunks)
103                     && (assoc->n_data_bytes  == data_bytes)
104                     && (assoc->verification_tag1 == vtag1) && (assoc->verification_tag2 == vtag2))
105                 {
106                         selected_stream = assoc;
107                         stream_found    = TRUE;
108                         break;
109                 }
110                 list = g_list_next(list);
111         }
112
113         if (!stream_found)
114                 selected_stream = NULL;
115
116         gtk_widget_set_sensitive(bt_unselect,TRUE);
117         gtk_widget_set_sensitive(bt_analyse,TRUE);
118         gtk_widget_set_sensitive(bt_filter,TRUE);
119 }
120
121 static
122 GtkWidget *create_list(void)
123 {
124         GtkListStore      *list_store;
125         GtkWidget *        list;
126         GtkTreeViewColumn *column;
127         GtkCellRenderer   *renderer;
128         GtkTreeView       *list_view;
129         GtkTreeSelection  *selection;
130
131         list_store = gtk_list_store_new(N_COLUMN,
132                 G_TYPE_UINT,   /* Port1*/
133                 G_TYPE_UINT,   /* Port2*/
134                 G_TYPE_UINT,   /* number of packets */
135                 G_TYPE_STRING, /* checksum type */
136                 G_TYPE_UINT,   /* number of checksum errors */
137                 G_TYPE_UINT,   /* number of data chunks */
138                 G_TYPE_UINT,   /* number of data bytes */
139                 G_TYPE_UINT,   /* vtag1 */
140                 G_TYPE_UINT);  /* vtag2 */
141
142         /* Create a view */
143         list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store));
144
145         list_view = GTK_TREE_VIEW(list);
146
147         /* Speed up the list display */
148         gtk_tree_view_set_fixed_height_mode(list_view, TRUE);
149
150         gtk_tree_view_set_headers_clickable(list_view, TRUE);
151
152         /* The view now holds a reference.  We can get rid of our own reference */
153         g_object_unref(G_OBJECT(list_store));
154
155         /*
156          * Create the first column packet, associating the "text" attribute of the
157          * cell_renderer to the first column of the model
158          */
159         /* 1:st column */
160         renderer = gtk_cell_renderer_text_new();
161         column   = gtk_tree_view_column_new_with_attributes("Port 1", renderer,
162                 "text", PORT1_COLUMN,
163                 NULL);
164
165         gtk_tree_view_column_set_sort_column_id(column, PORT1_COLUMN);
166         gtk_tree_view_column_set_resizable(column, TRUE);
167         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
168         gtk_tree_view_column_set_min_width(column, 80);
169
170         /* Add the column to the view. */
171         gtk_tree_view_append_column(list_view, column);
172
173         /* 2:nd column... */
174         renderer = gtk_cell_renderer_text_new();
175         column = gtk_tree_view_column_new_with_attributes("Port 2", renderer,
176                     "text", PORT2_COLUMN,
177                     NULL);
178         gtk_tree_view_column_set_sort_column_id(column, PORT2_COLUMN);
179         gtk_tree_view_column_set_resizable(column, TRUE);
180         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
181         gtk_tree_view_column_set_min_width(column, 80);
182         gtk_tree_view_append_column(list_view, column);
183
184         /* 3:d column... */
185         renderer = gtk_cell_renderer_text_new();
186         column   = gtk_tree_view_column_new_with_attributes("No of Packets", renderer,
187                     "text", PACKETS_COLUMN,
188                     NULL);
189         gtk_tree_view_column_set_sort_column_id(column, PACKETS_COLUMN);
190         gtk_tree_view_column_set_resizable(column, TRUE);
191         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
192         gtk_tree_view_column_set_min_width(column, 120);
193         gtk_tree_view_append_column(list_view, column);
194
195         /* 4:th column... */
196         renderer = gtk_cell_renderer_text_new();
197         column   = gtk_tree_view_column_new_with_attributes("Checksum", renderer,
198                     "text", CHECKSUM_TYPE_COLUMN,
199                     NULL);
200         gtk_tree_view_column_set_sort_column_id(column, CHECKSUM_TYPE_COLUMN);
201         gtk_tree_view_column_set_resizable(column, TRUE);
202         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
203         gtk_tree_view_column_set_min_width(column, 120);
204         gtk_tree_view_append_column(list_view, column);
205
206         /* 5:th column... */
207         renderer = gtk_cell_renderer_text_new();
208         column   = gtk_tree_view_column_new_with_attributes("No of Errors", renderer,
209                     "text", CHECKSUM_ERRORS_COLUMN,
210                     NULL);
211         gtk_tree_view_column_set_sort_column_id(column, CHECKSUM_ERRORS_COLUMN);
212         gtk_tree_view_column_set_resizable(column, TRUE);
213         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
214         gtk_tree_view_column_set_min_width(column, 120);
215         gtk_tree_view_append_column(list_view, column);
216
217         /* 6:th column... */
218         renderer = gtk_cell_renderer_text_new();
219         column   = gtk_tree_view_column_new_with_attributes("Data Chunks", renderer,
220                     "text", DATA_CHUNKS_COLUMN,
221                     NULL);
222         gtk_tree_view_column_set_sort_column_id(column, DATA_CHUNKS_COLUMN);
223         gtk_tree_view_column_set_resizable(column, TRUE);
224         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
225         gtk_tree_view_column_set_min_width(column, 120);
226         gtk_tree_view_append_column(list_view, column);
227
228         /* 7:th column... */
229         renderer = gtk_cell_renderer_text_new();
230         column   = gtk_tree_view_column_new_with_attributes("Data Bytes", renderer,
231                     "text", DATA_BYTES_COLUMN,
232                     NULL);
233         gtk_tree_view_column_set_sort_column_id(column, DATA_BYTES_COLUMN);
234         gtk_tree_view_column_set_resizable(column, TRUE);
235         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
236         gtk_tree_view_column_set_min_width(column, 120);
237         gtk_tree_view_append_column(list_view, column);
238
239         /* 8:th column... */
240         renderer = gtk_cell_renderer_text_new();
241         column   = gtk_tree_view_column_new_with_attributes("VTag 1", renderer,
242                     "text", VTAG1_COLUMN,
243                     NULL);
244         gtk_tree_view_column_set_sort_column_id(column, VTAG1_COLUMN);
245         gtk_tree_view_column_set_resizable(column, TRUE);
246         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
247         gtk_tree_view_column_set_min_width(column, 120);
248         gtk_tree_view_append_column(list_view, column);
249
250
251         /* 9:th column... */
252         renderer = gtk_cell_renderer_text_new();
253         column   = gtk_tree_view_column_new_with_attributes("VTag 2", renderer,
254                     "text", VTAG2_COLUMN,
255                     NULL);
256         gtk_tree_view_column_set_sort_column_id(column, VTAG2_COLUMN);
257         gtk_tree_view_column_set_resizable(column, TRUE);
258         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
259         gtk_tree_view_column_set_min_width(column, 120);
260         gtk_tree_view_append_column(list_view, column);
261
262         /* Now enable the sorting of each column */
263         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view), TRUE);
264         gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(list_view), TRUE);
265
266         /* Setup the selection handler */
267         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
268         gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
269         g_signal_connect(selection, "changed", G_CALLBACK(sctp_stat_on_select_row), NULL);
270         return list;
271 }
272
273 static void
274 dlg_destroy(GtkWidget *w _U_, gpointer user_data _U_)
275 {
276         guint32  i, j;
277         GList   *list;
278         struct sctp_analyse *child_data;
279
280         j = n_children;
281         for (i=0; i<j; i++)
282         {
283                 list = g_list_last(sctp_assocs->children);
284                 child_data = (struct sctp_analyse *)list->data;
285                 gtk_grab_remove(GTK_WIDGET(child_data->window));
286                 gtk_widget_destroy(GTK_WIDGET(child_data->window));
287         }
288         g_list_free(sctp_assocs->children);
289         sctp_assocs->children = NULL;
290         sctp_stat_dlg  = NULL;
291         prevent_update = FALSE;
292         filter_applied = FALSE;
293 }
294
295 void
296 decrease_analyse_childcount(void)
297 {
298         n_children--;
299 }
300
301 void
302 increase_analyse_childcount(void)
303 {
304         n_children++;
305 }
306
307 void
308 set_analyse_child(struct sctp_analyse *child)
309 {
310         sctp_assocs->children = g_list_append(sctp_assocs->children, child);
311 }
312
313 void
314 remove_analyse_child(struct sctp_analyse *child)
315 {
316         sctp_assocs->children = g_list_remove(sctp_assocs->children, child);
317 }
318
319
320
321 static void add_to_clist(sctp_assoc_info_t* assinfo)
322 {
323         GtkListStore *list_store;
324         GtkTreeIter   iter;
325
326         list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(clist))); /* Get store */
327
328         gtk_list_store_insert_with_values( list_store , &iter, G_MAXINT,
329                                            PORT1_COLUMN,           (guint32)assinfo->port1,
330                                            PORT2_COLUMN,           (guint32)assinfo->port2,
331                                            PACKETS_COLUMN,         assinfo->n_packets,
332                                            CHECKSUM_TYPE_COLUMN,   assinfo->checksum_type,
333                                            CHECKSUM_ERRORS_COLUMN, assinfo->n_checksum_errors,
334                                            DATA_CHUNKS_COLUMN,     assinfo->n_data_chunks,
335                                            DATA_BYTES_COLUMN,      assinfo->n_data_bytes,
336                                            VTAG1_COLUMN,           assinfo->verification_tag1,
337                                            VTAG2_COLUMN,           assinfo->verification_tag2,
338                                            -1);
339 }
340
341 static void
342 sctp_stat_on_unselect(GtkButton *button _U_, gpointer user_data _U_)
343 {
344         if (filter_string != NULL) {
345                 g_free(filter_string);
346                 filter_string = NULL;
347         }
348
349         selected_stream = NULL;
350         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), "");
351         main_filter_packets(&cfile, "", FALSE);
352         gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(clist)));
353         gtk_widget_set_sensitive(bt_unselect,FALSE);
354         gtk_widget_set_sensitive(bt_filter,FALSE);
355         gtk_widget_set_sensitive(bt_analyse,FALSE);
356         gtk_widget_set_sensitive(bt_afilter,FALSE);
357         prevent_update = FALSE;
358         filter_applied = FALSE;
359 }
360
361 void sctp_stat_dlg_update(void)
362 {
363         GList *list;
364
365         list = (sctp_stat_get_info()->assoc_info_list);
366         if ((sctp_stat_dlg != NULL) && !prevent_update)
367         {
368                 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(clist))));
369                 list = g_list_first(sctp_stat_get_info()->assoc_info_list);
370
371                 while (list)
372                 {
373                         add_to_clist((sctp_assoc_info_t*)(list->data));
374                         list = g_list_next(list);
375                 }
376         }
377         last_list = list;
378 }
379
380
381
382 static void
383 sctp_stat_on_apply_filter(GtkButton *button _U_, gpointer user_data _U_)
384 {
385         GList   *list;
386         sctp_assoc_info_t *assoc;
387         guint16  port1, port2;
388         guint32  data_chunks, data_bytes, packets, vtag1, vtag2;
389
390         if (filter_string != NULL)
391         {
392                 port1 = selected_stream->port1;
393                 port2 = selected_stream->port2;
394                 data_chunks = selected_stream->n_data_chunks;
395                 data_bytes  = selected_stream->n_data_bytes;
396                 packets = selected_stream->n_packets;
397                 vtag1 = selected_stream->verification_tag1;
398                 vtag2 = selected_stream->verification_tag2;
399                 main_filter_packets(&cfile, filter_string, FALSE);
400                 list = g_list_first(sctp_assocs->assoc_info_list);
401
402                 while (list)
403                 {
404                         assoc = (sctp_assoc_info_t*)(list->data);
405                         if ((assoc->port1 == port1) && (assoc->port2 == port2)
406                             && (assoc->n_packets     == packets)
407                             && (assoc->n_data_chunks == data_chunks)
408                             && (assoc->n_data_bytes  == data_bytes)
409                             && (assoc->verification_tag1 == vtag1) && (assoc->verification_tag2 == vtag2))
410                         {
411                                 selected_stream = assoc;
412                                 break;
413                         }
414                         list = g_list_next(list);
415                 }
416                 gtk_widget_set_sensitive(bt_afilter,FALSE);
417                 prevent_update = TRUE;
418                 filter_applied = TRUE;
419         }
420 }
421
422 static void
423 sctp_stat_on_filter(GtkButton *button _U_, gpointer user_data _U_)
424 {
425         if (selected_stream == NULL) {
426                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), "");
427                 return;
428         }
429
430         if (selected_stream->check_address == FALSE)
431         {
432                 gchar   *f_string;
433
434                 f_string = g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && "
435                         "((sctp.verification_tag==0x%x && sctp.verification_tag!=0x0) || "
436                         "(sctp.verification_tag==0x0 && sctp.initiate_tag==0x%x) || "
437                         "(sctp.verification_tag==0x%x && (sctp.abort_t_bit==1 || "
438                         "sctp.shutdown_complete_t_bit==1)))) ||"
439                         "(sctp.srcport==%u && sctp.dstport==%u && ((sctp.verification_tag==0x%x "
440                         "&& sctp.verification_tag!=0x0) || "
441                         "(sctp.verification_tag==0x0 && sctp.initiate_tag==0x%x) ||"
442                         "(sctp.verification_tag==0x%x && (sctp.abort_t_bit==1 ||"
443                         " sctp.shutdown_complete_t_bit==1)))))",
444                 selected_stream->port1,
445                 selected_stream->port2,
446                 selected_stream->verification_tag1,
447                 selected_stream->initiate_tag,
448                 selected_stream->verification_tag2,
449                 selected_stream->port2,
450                 selected_stream->port1,
451                 selected_stream->verification_tag2,
452                 selected_stream->initiate_tag,
453                 selected_stream->verification_tag1);
454                 filter_string = f_string;
455         }
456         else
457         {
458                 gchar   *str;
459                 GString *gstring;
460                 GList   *srclist, *dstlist;
461                 struct sockaddr_in *infosrc;
462                 struct sockaddr_in *infodst;
463                 address addr;
464                 char    *addr_str;
465
466                 srclist = g_list_first(selected_stream->addr1);
467                 infosrc = (struct sockaddr_in *)(srclist->data);
468                 set_address(&addr, AT_IPv4, 4, &(infosrc->sin_addr.s_addr));
469                 addr_str = (char*)address_to_str(NULL, &addr);
470                 gstring = g_string_new(g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && (ip.src==%s",
471                         selected_stream->port1, selected_stream->port2, addr_str));
472                 srclist= g_list_next(srclist);
473                 wmem_free(NULL, addr_str);
474
475                 while (srclist)
476                 {
477                         infosrc = (struct sockaddr_in *)(srclist->data);
478                         set_address(&addr, AT_IPv4, 4, &(infosrc->sin_addr.s_addr));
479                         addr_str = (char*)address_to_str(NULL, &addr);
480                         str = g_strdup_printf("|| ip.src==%s", addr_str);
481                         g_string_append(gstring, str);
482                         wmem_free(NULL, addr_str);
483                         srclist = g_list_next(srclist);
484                 }
485                 dstlist = g_list_first(selected_stream->addr2);
486                 infodst = (struct sockaddr_in *)(dstlist->data);
487                 set_address(&addr, AT_IPv4, 4, &(infodst->sin_addr.s_addr));
488                 addr_str = (char*)address_to_str(NULL, &addr);
489                 str = g_strdup_printf(") && (ip.dst==%s", addr_str);
490                 g_string_append(gstring, str);
491                 wmem_free(NULL, addr_str);
492                 dstlist = g_list_next(dstlist);
493                 while (dstlist)
494                 {
495                         infodst = (struct sockaddr_in *)(dstlist->data);
496                         set_address(&addr, AT_IPv4, 4, &(infodst->sin_addr.s_addr));
497                         addr_str = (char*)address_to_str(NULL, &addr);
498                         str = g_strdup_printf("|| ip.dst==%s", addr_str);
499                         g_string_append(gstring, str);
500                         wmem_free(NULL, addr_str);
501                         dstlist = g_list_next(dstlist);
502                 }
503                 srclist = g_list_first(selected_stream->addr1);
504                 infosrc = (struct sockaddr_in *)(srclist->data);
505                 set_address(&addr, AT_IPv4, 4, &(infosrc->sin_addr.s_addr));
506                 addr_str = (char*)address_to_str(NULL, &addr);
507                 str = g_strdup_printf(")) || (sctp.dstport==%u && sctp.srcport==%u && (ip.dst==%s",
508                         selected_stream->port1, selected_stream->port2, addr_str);
509                 g_string_append(gstring, str);
510                 wmem_free(NULL, addr_str);
511                 srclist = g_list_next(srclist);
512
513                 while (srclist)
514                 {
515                         infosrc = (struct sockaddr_in *)(srclist->data);
516                         set_address(&addr, AT_IPv4, 4, &(infosrc->sin_addr.s_addr));
517                         addr_str = (char*)address_to_str(NULL, &addr);
518                         str = g_strdup_printf("|| ip.dst==%s", addr_str);
519                         g_string_append(gstring, str);
520                         wmem_free(NULL, addr_str);
521                         srclist= g_list_next(srclist);
522                 }
523
524                 dstlist = g_list_first(selected_stream->addr2);
525                 infodst = (struct sockaddr_in *)(dstlist->data);
526                 set_address(&addr, AT_IPv4, 4, &(infodst->sin_addr.s_addr));
527                 addr_str = (char*)address_to_str(NULL, &addr);
528                 str = g_strdup_printf(") && (ip.src==%s", addr_str);
529                 g_string_append(gstring, str);
530                 wmem_free(NULL, addr_str);
531                 dstlist = g_list_next(dstlist);
532                 while (dstlist)
533                 {
534                         infodst = (struct sockaddr_in *)(dstlist->data);
535                         set_address(&addr, AT_IPv4, 4, &(infodst->sin_addr.s_addr));
536                         addr_str = (char*)address_to_str(NULL, &addr);
537                         str = g_strdup_printf("|| ip.src==%s", addr_str);
538                         g_string_append(gstring, str);
539                         wmem_free(NULL, addr_str);
540                         dstlist = g_list_next(dstlist);
541                 }
542                 str = g_strdup(")))");
543                 g_string_append(gstring, str);
544                 filter_string = g_string_free(gstring,FALSE);
545         }
546
547         if (filter_string != NULL) {
548                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
549         } else {
550                 g_assert_not_reached();
551         }
552         gtk_widget_set_sensitive(bt_afilter,TRUE);
553         gtk_widget_set_sensitive(bt_filter,FALSE);
554         prevent_update = TRUE;
555         filter_applied = FALSE;
556 }
557
558
559 static void
560 sctp_stat_on_close(GtkWidget *button _U_, gpointer user_data _U_)
561 {
562         gtk_grab_remove(sctp_stat_dlg);
563         gtk_widget_destroy(sctp_stat_dlg);
564         prevent_update = FALSE;
565         filter_applied = FALSE;
566 }
567
568 static void
569 sctp_stat_on_analyse(GtkButton *button _U_, gpointer user_data _U_)
570 {
571         if (selected_stream == NULL)
572                 return;
573         else
574                 assoc_analyse(selected_stream);
575         gtk_widget_set_sensitive(bt_analyse,FALSE);
576         if (!filter_applied)
577                 gtk_widget_set_sensitive(bt_filter,TRUE);
578         prevent_update = TRUE;
579 }
580
581
582 static void
583 gtk_sctpstat_dlg(void)
584 {
585         GtkWidget *sctp_stat_dlg_w;
586         GtkWidget *vbox1;
587         GtkWidget *scrolledwindow1;
588         GtkWidget *hbuttonbox2;
589         GtkWidget *bt_close;
590
591         sctp_stat_dlg_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: SCTP Associations");
592         gtk_window_set_position(GTK_WINDOW(sctp_stat_dlg_w), GTK_WIN_POS_CENTER);
593         gtk_window_set_default_size(GTK_WINDOW(sctp_stat_dlg_w), 1000, 300);
594         g_signal_connect(sctp_stat_dlg_w, "destroy", G_CALLBACK(dlg_destroy), NULL);
595
596         /* Container for each row of widgets */
597         vbox1 = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 2, FALSE);
598         gtk_container_set_border_width(GTK_CONTAINER(vbox1), 8);
599         gtk_container_add(GTK_CONTAINER(sctp_stat_dlg_w), vbox1);
600         gtk_widget_show(vbox1);
601
602         scrolledwindow1 = scrolled_window_new(NULL, NULL);
603         gtk_widget_show(scrolledwindow1);
604         gtk_box_pack_start(GTK_BOX(vbox1), scrolledwindow1, TRUE, TRUE, 0);
605
606         clist = create_list();
607         gtk_widget_show(clist);
608         gtk_container_add(GTK_CONTAINER(scrolledwindow1), clist);
609         gtk_widget_set_size_request(clist, 1050, 200);
610
611         gtk_widget_show(sctp_stat_dlg_w);
612
613         hbuttonbox2 = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
614         gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox2, FALSE, FALSE, 0);
615         gtk_container_set_border_width(GTK_CONTAINER(hbuttonbox2), 10);
616         gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox2), GTK_BUTTONBOX_SPREAD);
617         gtk_box_set_spacing(GTK_BOX(hbuttonbox2), 0);
618         gtk_widget_show(hbuttonbox2);
619
620         bt_unselect = gtk_button_new_with_label("Unselect");
621         gtk_container_add(GTK_CONTAINER(hbuttonbox2), bt_unselect);
622         gtk_widget_show(bt_unselect);
623         gtk_widget_set_sensitive(bt_unselect,FALSE);
624
625         bt_filter = gtk_button_new_with_label("Set filter");
626         gtk_container_add(GTK_CONTAINER(hbuttonbox2), bt_filter);
627         gtk_widget_show(bt_filter);
628         gtk_widget_set_sensitive(bt_filter,FALSE);
629
630         bt_afilter = gtk_button_new_with_label("Apply filter");
631         gtk_container_add(GTK_CONTAINER(hbuttonbox2), bt_afilter);
632         gtk_widget_show(bt_afilter);
633         gtk_widget_set_sensitive(bt_afilter,FALSE);
634
635         bt_analyse = gtk_button_new_with_label("Analyse");
636         gtk_container_add(GTK_CONTAINER(hbuttonbox2), bt_analyse);
637         gtk_widget_show(bt_analyse);
638         gtk_widget_set_sensitive(bt_analyse,FALSE);
639
640         bt_close = ws_gtk_button_new_from_stock(GTK_STOCK_CLOSE);
641         gtk_container_add(GTK_CONTAINER(hbuttonbox2), bt_close);
642         gtk_widget_set_can_default(bt_close, TRUE);
643         window_set_cancel_button(sctp_stat_dlg_w, bt_close, sctp_stat_on_close);
644         gtk_widget_grab_focus(bt_close);
645         gtk_widget_show(bt_close);
646
647         g_signal_connect(sctp_stat_dlg_w, "destroy", G_CALLBACK(dlg_destroy), NULL);
648         g_signal_connect(bt_unselect, "clicked", G_CALLBACK(sctp_stat_on_unselect), NULL);
649         g_signal_connect(bt_filter, "clicked", G_CALLBACK(sctp_stat_on_filter), NULL);
650         g_signal_connect(bt_afilter, "clicked", G_CALLBACK(sctp_stat_on_apply_filter), NULL);
651         g_signal_connect(bt_analyse, "clicked", G_CALLBACK(sctp_stat_on_analyse), NULL);
652
653         sctp_stat_dlg = sctp_stat_dlg_w;
654         cf_retap_packets(&cfile);
655         gdk_window_raise(gtk_widget_get_window(sctp_stat_dlg_w));
656
657 }
658
659 static void sctp_stat_dlg_show(void)
660 {
661         if (sctp_stat_dlg != NULL)
662         {
663                 /* There's already a dialog box; reactivate it. */
664                 reactivate_window(sctp_stat_dlg);
665                 /* Another list since last call? */
666                 if ((sctp_stat_get_info()->assoc_info_list) != last_list)
667                         sctp_stat_dlg_update();
668         }
669         else
670         {
671                 /* Create and show the dialog box */
672                 gtk_sctpstat_dlg();
673                 sctp_stat_dlg_update();
674         }
675 }
676
677
678 void sctp_stat_start(GtkAction *action _U_, gpointer user_data _U_)
679 {
680         prevent_update = FALSE;
681         filter_applied = FALSE;
682         sctp_assocs = (sctp_allassocs_info_t *)g_malloc(sizeof(sctp_allassocs_info_t));
683         sctp_assocs = (sctp_allassocs_info_t*)sctp_stat_get_info();
684         /* Register the tap listener */
685         if (sctp_stat_get_info()->is_registered == FALSE)
686         register_tap_listener_sctp_stat();
687         /*  (redissect all packets) */
688         sctp_stat_scan();
689
690         /* Show the dialog box with the list of streams */
691         sctp_stat_dlg_show();
692 }
693
694 /****************************************************************************/
695
696 GtkWidget *get_stat_dlg(void)
697 {
698         return sctp_stat_dlg;
699 }
700
701
702 /*
703  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
704  *
705  * Local variables:
706  * c-basic-offset: 8
707  * tab-width: 8
708  * indent-tabs-mode: t
709  * End:
710  *
711  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
712  * :indentSize=8:tabSize=8:noTabs=false:
713  */