merge_all_tap_menus() has been moved to menus.c.
[obnox/wireshark/wip.git] / gtk / sctp_assoc_analyse.c
index fce1b3fdedfbecdf366985079cbda2dbd360b132..1a0977820e142d16334a09097013153f5f5cd212 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
  *
  * $Id$
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
-#include <string.h>
 
 #include <gtk/gtk.h>
 
@@ -36,7 +35,6 @@
 #include "../globals.h"
 #include "../simple_dialog.h"
 #include "../stat_menu.h"
-#include "../register.h"
 
 #include "gtk/gui_stat_menu.h"
 #include "gtk/dlg_utils.h"
@@ -73,7 +71,7 @@ remove_child(struct sctp_udata *child, struct sctp_analyse *parent)
 }
 
 static void
-on_destroy(GtkObject *object _U_, gpointer user_data)
+on_destroy(GObject *object _U_, gpointer user_data)
 {
        struct sctp_analyse *u_data;
        guint16 i, j;
@@ -101,7 +99,7 @@ on_destroy(GtkObject *object _U_, gpointer user_data)
                g_list_free(u_data->children);
                u_data->children = NULL;
        }
-       
+
        g_free(u_data->analyse_nb->page2);
        g_free(u_data->analyse_nb->page3);
        g_free(u_data->analyse_nb);
@@ -123,7 +121,6 @@ static void on_chunk_stat_bt(GtkWidget *widget _U_, struct sctp_analyse* u_data)
        sctp_assoc_info_t* assinfo = NULL;
        int i;
 
-       assinfo = g_malloc(sizeof(sctp_assoc_info_t));
        assinfo = &static_assoc;
        assinfo->addr_chunk_count = (static_assoc.addr_chunk_count);
        for (i=0; i<NUM_CHUNKS; i++)
@@ -149,8 +146,7 @@ static void on_close_dlg(GtkWidget *widget _U_, struct sctp_analyse* u_data)
 static void on_chunk1_dlg(GtkWidget *widget _U_, struct sctp_analyse* u_data)
 {
 sctp_assoc_info_t* assinfo = NULL;
-       
-       assinfo = g_malloc(sizeof(sctp_assoc_info_t));
+
        assinfo = &static_assoc;
        assinfo->addr_chunk_count = (static_assoc.addr_chunk_count);
        u_data->assoc = assinfo;
@@ -161,9 +157,8 @@ static void on_chunk2_dlg(GtkWidget *widget _U_, struct sctp_analyse* u_data)
 {
 sctp_assoc_info_t* assinfo=NULL;
 
-       assinfo = g_malloc(sizeof(sctp_assoc_info_t));
        assinfo = &static_assoc;
-       assinfo->addr_chunk_count = (static_assoc.addr_chunk_count);    
+       assinfo->addr_chunk_count = (static_assoc.addr_chunk_count);
        u_data->assoc = assinfo;
        sctp_chunk_stat_dlg_show(2, u_data);
 }
@@ -192,19 +187,21 @@ void
 update_analyse_dlg(struct sctp_analyse* u_data)
 {
        gchar label_txt[50];
-       gchar *data[1];
        gchar field[1][MAX_ADDRESS_LEN];
-       gint added_row;
        GList *list;
        address *store = NULL;
+       GtkListStore *list_store = NULL;
+       GtkTreeIter  iter;
 
        if (u_data->assoc == NULL)
                return;
 
        if (u_data->window != NULL)
        {
-               gtk_clist_clear(GTK_CLIST(u_data->analyse_nb->page2->clist));
-               gtk_clist_clear(GTK_CLIST(u_data->analyse_nb->page3->clist));
+               gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
+                               (u_data->analyse_nb->page2->clist))));
+               gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
+                       (u_data->analyse_nb->page3->clist))));
        }
 
 
@@ -243,18 +240,19 @@ update_analyse_dlg(struct sctp_analyse* u_data)
                list = g_list_first(u_data->assoc->addr1);
                while (list)
                {
-                       data[0] = &field[0][0];
                        store = (address *) (list->data);
                        if (store->type == AT_IPv4)
                        {
                                g_snprintf(field[0], 30, "%s", ip_to_str((const guint8 *)(store->data)));
                        }
                        else if (store->type == AT_IPv6)
-                       {               
+                       {
                                g_snprintf(field[0], 40, "%s", ip6_to_str((const struct e_in6_addr *)(store->data)));
                        }
-                       added_row = gtk_clist_append(GTK_CLIST(u_data->analyse_nb->page2->clist), data);
-                       gtk_clist_set_row_data(GTK_CLIST(u_data->analyse_nb->page2->clist), added_row, u_data->assoc);
+                       list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (u_data->analyse_nb->page2->clist))); /* Get store */
+
+                       gtk_list_store_insert_with_values( list_store , &iter, G_MAXINT,
+                                                          0,   field[0], -1);
                        list = g_list_next(list);
                }
        }
@@ -300,7 +298,6 @@ update_analyse_dlg(struct sctp_analyse* u_data)
 
                while (list)
                {
-                       data[0] = &field[0][0];
                        store = (address *) (list->data);
                        if (store->type == AT_IPv4)
                        {
@@ -310,8 +307,10 @@ update_analyse_dlg(struct sctp_analyse* u_data)
                        {
                                g_snprintf(field[0], 40, "%s", ip6_to_str((const struct e_in6_addr *)(store->data)));
                        }
-                       added_row = gtk_clist_append(GTK_CLIST(u_data->analyse_nb->page3->clist), data);
-                       gtk_clist_set_row_data(GTK_CLIST(u_data->analyse_nb->page3->clist), added_row, u_data->assoc);
+                       list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (u_data->analyse_nb->page3->clist))); /* Get store */
+
+                       gtk_list_store_insert_with_values( list_store , &iter, G_MAXINT,
+                                                          0,   field[0], -1);
                        list = g_list_next(list);
                }
        }
@@ -347,7 +346,7 @@ update_analyse_dlg(struct sctp_analyse* u_data)
 }
 
 
-void
+static void
 sctp_set_filter (GtkButton *button _U_, struct sctp_analyse* u_data)
 {
        gchar *f_string = NULL;
@@ -359,7 +358,7 @@ sctp_set_filter (GtkButton *button _U_, struct sctp_analyse* u_data)
        sctp_assoc_info_t *selected_stream;
        gchar *filter_string = NULL;
        selected_stream=u_data->assoc;
-       
+
        if (selected_stream->check_address==FALSE)
        {
                f_string = g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && ((sctp.verification_tag==0x%x && sctp.verification_tag!=0x0) || "
@@ -371,13 +370,11 @@ sctp_set_filter (GtkButton *button _U_, struct sctp_analyse* u_data)
                selected_stream->port1,
                selected_stream->port2,
                selected_stream->verification_tag1,
-               /*selected_stream->verification_tag2,*/
                selected_stream->initiate_tag,
                selected_stream->verification_tag2,
                selected_stream->port2,
                selected_stream->port1,
                selected_stream->verification_tag2,
-               /*selected_stream->verification_tag1,*/
                selected_stream->initiate_tag,
                selected_stream->verification_tag1);
                filter_string = f_string;
@@ -443,7 +440,7 @@ sctp_set_filter (GtkButton *button _U_, struct sctp_analyse* u_data)
                filter_string = gstring->str;
                g_string_free(gstring,FALSE);
        }
-       
+
        if (filter_string != NULL) {
                gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
        } else {
@@ -454,7 +451,7 @@ sctp_set_filter (GtkButton *button _U_, struct sctp_analyse* u_data)
 static void analyse_window_set_title(struct sctp_analyse *u_data)
 {
        char *title;
-       
+
        if(!u_data->window){
                return;
        }
@@ -463,6 +460,49 @@ static void analyse_window_set_title(struct sctp_analyse *u_data)
        g_free(title);
 }
 
+static
+GtkWidget *create_list(void)
+{
+       GtkListStore *list_store;
+       GtkWidget * list;
+       GtkTreeViewColumn *column;
+       GtkCellRenderer *renderer;
+       GtkTreeView *list_view;
+       list_store = gtk_list_store_new(1,
+                                       G_TYPE_STRING /* IP address */
+               );
+
+       /* Create a view */
+       list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
+
+       list_view = GTK_TREE_VIEW(list);
+
+       /* Speed up the list display */
+       gtk_tree_view_set_fixed_height_mode(list_view, TRUE);
+
+       /* The view now holds a reference.  We can get rid of our own reference */
+       g_object_unref (G_OBJECT (list_store));
+
+       /*
+        * Create the first column packet, associating the "text" attribute of the
+        * cell_renderer to the first column of the model
+        */
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Address", renderer,
+                                                          "text",      0,
+                                                          NULL);
+
+       gtk_tree_view_column_set_resizable(column, TRUE);
+       gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+       gtk_tree_view_column_set_min_width(column, 300);
+
+       /* Add the column to the view. */
+       gtk_tree_view_append_column (list_view, column);
+
+       gtk_tree_view_set_headers_visible(list_view, FALSE);
+       return list;
+}
+
 static void create_analyse_window(struct sctp_analyse* u_data)
 {
        GtkWidget *window = NULL;
@@ -573,12 +613,9 @@ static void create_analyse_window(struct sctp_analyse* u_data)
        u_data->analyse_nb->page2->scrolled_window = scrolled_window_new(NULL, NULL);
        gtk_widget_set_size_request(u_data->analyse_nb->page2->scrolled_window, 560, 100);
 
-       u_data->analyse_nb->page2->clist = gtk_clist_new(1);
+       u_data->analyse_nb->page2->clist = create_list();
        gtk_widget_show(u_data->analyse_nb->page2->clist);
 
-       gtk_clist_set_column_width(GTK_CLIST(u_data->analyse_nb->page2->clist), 0, 200);
-       gtk_clist_set_column_justification(GTK_CLIST(u_data->analyse_nb->page2->clist), 0, GTK_JUSTIFY_LEFT);
-
        gtk_container_add(GTK_CONTAINER(u_data->analyse_nb->page2->scrolled_window), u_data->analyse_nb->page2->clist);
 
        gtk_box_pack_start(GTK_BOX(addr_hb), u_data->analyse_nb->page2->scrolled_window, TRUE, TRUE, 0);
@@ -639,7 +676,7 @@ static void create_analyse_window(struct sctp_analyse* u_data)
        gtk_button_box_set_layout(GTK_BUTTON_BOX (h_button_box), GTK_BUTTONBOX_SPREAD);
        gtk_box_set_spacing(GTK_BOX (h_button_box), 0);
        gtk_widget_show(h_button_box);
-       
+
        chunk_bt1 = gtk_button_new_with_label("Chunk Statistics");
        gtk_box_pack_start(GTK_BOX(h_button_box), chunk_bt1, FALSE, FALSE, 0);
        gtk_widget_show(chunk_bt1);
@@ -683,11 +720,8 @@ static void create_analyse_window(struct sctp_analyse* u_data)
        u_data->analyse_nb->page3->scrolled_window = scrolled_window_new(NULL, NULL);
        gtk_widget_set_size_request(u_data->analyse_nb->page3->scrolled_window, 560, 100);
 
-       u_data->analyse_nb->page3->clist = gtk_clist_new(1);
-       gtk_widget_show(u_data->analyse_nb->page3->clist);              
-
-       gtk_clist_set_column_width(GTK_CLIST(u_data->analyse_nb->page3->clist), 0, 200);
-       gtk_clist_set_column_justification(GTK_CLIST(u_data->analyse_nb->page3->clist), 0, GTK_JUSTIFY_LEFT);
+       u_data->analyse_nb->page3->clist = create_list();
+       gtk_widget_show(u_data->analyse_nb->page3->clist);
 
        gtk_container_add(GTK_CONTAINER(u_data->analyse_nb->page3->scrolled_window),
        u_data->analyse_nb->page3->clist);
@@ -704,7 +738,7 @@ static void create_analyse_window(struct sctp_analyse* u_data)
 
        vbox_l = gtk_vbox_new(FALSE, 3);
        gtk_box_pack_start(GTK_BOX(hbox), vbox_l, TRUE, TRUE, 0);
-               
+
        hbox_l1 = gtk_hbox_new(FALSE,3);
        gtk_box_pack_start(GTK_BOX(vbox_l), hbox_l1, TRUE, TRUE, 0);
 
@@ -729,7 +763,7 @@ static void create_analyse_window(struct sctp_analyse* u_data)
        gtk_misc_set_alignment (GTK_MISC(u_data->analyse_nb->page3->max_in),0,0);
        u_data->analyse_nb->page3->min_in = gtk_label_new("");
        gtk_box_pack_start(GTK_BOX(vbox_r), u_data->analyse_nb->page3->min_in, TRUE, TRUE, 0);
-       gtk_misc_set_alignment (GTK_MISC(u_data->analyse_nb->page3->min_in),0,0);               
+       gtk_misc_set_alignment (GTK_MISC(u_data->analyse_nb->page3->min_in),0,0);
 
        u_data->analyse_nb->page3->max_out = gtk_label_new("");
        gtk_box_pack_start(GTK_BOX(vbox_r), u_data->analyse_nb->page3->max_out, TRUE, TRUE, 0);
@@ -746,12 +780,12 @@ static void create_analyse_window(struct sctp_analyse* u_data)
        gtk_button_box_set_layout(GTK_BUTTON_BOX (h_button_box), GTK_BUTTONBOX_SPREAD);
        gtk_box_set_spacing(GTK_BOX (h_button_box), 0);
        gtk_widget_show(h_button_box);
-       
+
        chunk_bt1 = gtk_button_new_with_label("Chunk Statistics");
        gtk_box_pack_start(GTK_BOX(h_button_box), chunk_bt1, FALSE, FALSE, 0);
        gtk_widget_show(chunk_bt1);
        g_signal_connect(chunk_bt1, "clicked", G_CALLBACK(on_chunk2_dlg), u_data);
-       
+
        graph_bt1 = gtk_button_new_with_label("Graph TSN");
        gtk_box_pack_start(GTK_BOX(h_button_box), graph_bt1, FALSE, FALSE, 0);
        gtk_widget_show(graph_bt1);
@@ -816,16 +850,10 @@ void assoc_analyse(sctp_assoc_info_t* assoc)
 
 static void sctp_analyse_cb(struct sctp_analyse* u_data, gboolean ext)
 {
-       guint8* ip_src;
-       guint16 srcport;
-       guint8* ip_dst;
-       guint16 dstport;
        GList *list, *framelist;
        dfilter_t *sfcode;
        capture_file *cf;
-       epan_dissect_t *edt;
-       gint err;
-       gchar *err_info;
+       epan_dissect_t edt;
        gboolean frame_matched, frame_found = FALSE;
        frame_data *fdata;
        gchar filter_text[256];
@@ -847,33 +875,23 @@ static void sctp_analyse_cb(struct sctp_analyse* u_data, gboolean ext)
                return; /* if we exit here it's an error */
 
        /* dissect the current frame */
-       if (!wtap_seek_read(cf->wth, fdata->file_off, &cf->pseudo_header,
-           cf->pd, fdata->cap_len, &err, &err_info)) {
-               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                       cf_read_error_message(err, err_info), cf->filename);
-               return;
-       }
+       if (!cf_read_frame(cf, fdata))
+               return; /* error reading the frame */
 
-       edt = epan_dissect_new(TRUE, FALSE);
-       epan_dissect_prime_dfilter(edt, sfcode);
-       epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, NULL);
-       frame_matched = dfilter_apply_edt(sfcode, edt);
+       epan_dissect_init(&edt, TRUE, FALSE);
+       epan_dissect_prime_dfilter(&edt, sfcode);
+       epan_dissect_run(&edt, &cf->pseudo_header, cf->pd, fdata, NULL);
+       frame_matched = dfilter_apply_edt(sfcode, &edt);
 
        /* if it is not an sctp frame, show the dialog */
 
        if (frame_matched != 1) {
-               epan_dissect_free(edt);
+               epan_dissect_cleanup(&edt);
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Please choose an SCTP packet!");
                return;
        }
 
-       ip_src = g_malloc(edt->pi.net_src.len);
-       memcpy(ip_src, edt->pi.net_src.data, edt->pi.net_src.len);
-       ip_dst = g_malloc(edt->pi.net_dst.len);
-       memcpy(ip_dst, edt->pi.net_dst.data, edt->pi.net_dst.len);
-       srcport = edt->pi.srcport;
-       dstport = edt->pi.destport;
        list = g_list_first(sctp_stat_get_info()->assoc_info_list);
 
        while (list)
@@ -931,12 +949,16 @@ struct sctp_analyse * u_data;
        u_data->analyse_nb   = NULL;
        u_data->window       = NULL;
        u_data->num_children = 0;
-       cf_retap_packets(&cfile, FALSE);
+       cf_retap_packets(&cfile);
        sctp_analyse_cb(u_data, TRUE);
        sctp_set_filter(NULL, u_data);
 }
 
+#ifdef MAIN_MENU_USE_UIMANAGER
+void sctp_analyse_start(GtkAction *action _U_, gpointer user_data _U_)
+#else
 void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_)
+#endif
 {
        struct sctp_analyse * u_data;
 
@@ -944,7 +966,7 @@ void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_)
        if (sctp_stat_get_info()->is_registered == FALSE)
                register_tap_listener_sctp_stat();
        /* (redissect all packets) */
-       
+
        sctp_stat_scan();
 
        u_data = g_malloc(sizeof(struct sctp_analyse));
@@ -954,7 +976,7 @@ void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_)
        u_data->window       = NULL;
        u_data->num_children = 0;
 
-       cf_retap_packets(&cfile, FALSE);
+       cf_retap_packets(&cfile);
        sctp_analyse_cb(u_data, FALSE);
 }
 
@@ -962,6 +984,9 @@ void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_)
 void
 register_tap_listener_sctp_analyse(void)
 {
-       register_stat_menu_item("SCTP/Analyse this Association", REGISTER_STAT_GROUP_TELEPHONY,
+#ifdef MAIN_MENU_USE_UIMANAGER
+#else
+       register_stat_menu_item("S_CTP/Analyse this Association", REGISTER_STAT_GROUP_TELEPHONY,
                               sctp_analyse_start, NULL, NULL, NULL);
+#endif
 }