Export Object code/documentation updates:
authorsfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 6 Mar 2007 00:36:25 +0000 (00:36 +0000)
committersfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 6 Mar 2007 00:36:25 +0000 (00:36 +0000)
 - Note in the user's guide that export object is not available
   in GTK1 builds of Wireshark.
 - Make scanning through the slists more efficient
 - Use new tap.c function called have_tap_listener() to only save
   object payload data when the export object listener is actively
   listening for it.
 - Save objects in the HTTP dissector with g_malloc() instead of
   se_malloc() and free it when we're done with it - when the
   export object window is closed (Fixes bug #1412)
 - Various minor improvements

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@20980 f5534014-38df-0310-8fa8-9805f1628bb7

docbook/wsug_src/WSUG_chapter_io.xml
epan/dissectors/packet-http.c
gtk/export_object.c
gtk/export_object.h
gtk/export_object_http.c

index 0d693e1a0608a44510ef810a0e9d4fe1db48b802..f9cb0e4ccf7e3531df93287fa1620c21cbc7207b 100644 (file)
            opened with the proper viewer or executed in the case of
            executables (if it is for the same platform you are
            running Wireshark on) without any further work on your
-           part.
+           part.  This feature is not available in the GTK1 build of Wireshark.
          </para>
     <figure>
       <title>The "Export Objects" dialog box</title>
index c32023ad40bb4f82c8d5b010033ea1608659a32f..d9217b62604c73d6e09795a4ee279206c3f9f768 100644 (file)
@@ -1072,6 +1072,17 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo,
                 * only if it was content-encoded and/or transfer-encoded.
                 */
 
+               /* Save values for the Export Object GUI feature if we have
+                * an active listener to process it (which happens when
+                * the export object window is open).  These will be freed
+                * when the export object window is destroyed. */
+               if(have_tap_listener(http_tap)) {
+                       stat_info->content_type = g_strdup(headers.content_type);
+                       stat_info->payload_len = next_tvb->length;
+                       stat_info->payload_data = g_memdup(next_tvb->real_data,
+                                                           next_tvb->length);
+               }
+
                /*
                 * Do subdissector checks.
                 *
@@ -1079,12 +1090,6 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo,
                 * be called if something was on some particular port.
                 */
 
-               /* Save values for the Export Object GUI feature */
-               stat_info->content_type = se_strdup(headers.content_type);
-               stat_info->payload_len = next_tvb->length;
-               stat_info->payload_data = se_memdup(next_tvb->real_data,
-                                                   next_tvb->length);
-
                handle = dissector_get_port_handle(port_subdissector_table,
                    pinfo->match_port);
                if (handle == NULL && headers.content_type != NULL) {
index 725330184803fe56f489d1363138f6dba400e290..bc07a9487572237db916edfbaa8b00e74a8a8617 100644 (file)
@@ -78,13 +78,14 @@ eo_remember_this_row(GtkTreeModel *model _U_, GtkTreePath *path,
        gint *path_index;
 
        if((path_index = gtk_tree_path_get_indices(path)) == NULL)
+               /* Row not found in tree - shouldn't happen */
                return;
 
        object_list->row_selected = path_index[0];
 
+       /* Select the corresponding packet in the packet list */
        entry = g_slist_nth_data(object_list->entries,
                                 object_list->row_selected);
-       
        cf_goto_frame(&cfile, entry->pkt_num);
 }
 
@@ -95,15 +96,28 @@ eo_remember_row_num(GtkTreeSelection *sel, gpointer data)
 }
 
 
+/* Called when the Export Object window is closed in any way */
 static void
 eo_win_destroy_cb(GtkWindow *win _U_, gpointer data)
 {
-        export_object_list_t *object_list = data;
+       export_object_list_t *object_list = data;
+       export_object_entry_t *entry;
+       GSList *slist = object_list->entries;
 
         protect_thread_critical_region();
         remove_tap_listener(object_list);
         unprotect_thread_critical_region();
 
+       while(slist) {
+               entry = slist->data;
+               
+               g_free(entry->content_type);
+               g_free(entry->payload_data);
+               
+               slist = slist->next; 
+       }
+
+       g_slist_free(object_list->entries);
        g_free(object_list);
 }
 
@@ -174,8 +188,7 @@ eo_save_all_clicked_cb(GtkWidget *widget _U_, gpointer arg)
        export_object_list_t *object_list = arg;
        export_object_entry_t *entry;
        GtkWidget *save_in_w;
-       GSList *last_slist_entry;
-       gint last_slist_entry_num, i;
+       GSList *slist = object_list->entries;
 
        save_in_w = file_selection_new("Wireshark: Save All Objects In ...",
                                       FILE_SELECTION_CREATE_FOLDER);
@@ -184,36 +197,27 @@ eo_save_all_clicked_cb(GtkWidget *widget _U_, gpointer arg)
                                     GTK_WINDOW(object_list->dlg));
 
        if(gtk_dialog_run(GTK_DIALOG(save_in_w)) == GTK_RESPONSE_ACCEPT) {
-
-               /* Find the last entry in the SList, then start at the beginning
-                  saving each one until we reach the last entry. */
-               last_slist_entry = g_slist_last(object_list->entries);
-               last_slist_entry_num = g_slist_position(object_list->entries,
-                                                       last_slist_entry);
-
-               for(i = 0; i <= last_slist_entry_num; i++) {
-                       
-                       entry = g_slist_nth_data(object_list->entries, i);
+               while(slist) {
+                       entry = slist->data;
 
                        save_as_fullpath = g_build_filename(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(save_in_w)), entry->filename, NULL);
                        
                        eo_save_entry(save_as_fullpath, entry);
+
+                       slist = slist->next;
                }
        }
 
        window_destroy(save_in_w);
 }
 
+/* Runs at the beginning of tapping only */
 static void
 eo_reset(void *tapdata)
 {
        export_object_list_t *object_list = tapdata;
 
-       if(object_list->entries) {
-               g_slist_free(object_list->entries);
-               object_list->entries = NULL;
-       }
-
+       object_list->entries = NULL;
        object_list->iter = NULL;
        object_list->row_selected = -1;
 }
@@ -224,21 +228,12 @@ eo_draw(void *tapdata)
        export_object_list_t *object_list = tapdata;
        export_object_entry_t *eo_entry;
 
-       GSList *slist_entry = NULL;
-       GSList *last_slist_entry = NULL;
-       gint last_slist_entry_num;
+       GSList *slist = object_list->entries;
        GtkTreeIter new_iter;
        gchar *column_text[EO_NUM_COLUMNS];
 
-       last_slist_entry = g_slist_last(object_list->entries);
-       last_slist_entry_num = g_slist_position(object_list->entries,
-                                               last_slist_entry);
-
-       while(object_list->slist_pos <= last_slist_entry_num &&
-             last_slist_entry_num != -1) {
-               slist_entry = g_slist_nth(object_list->entries,
-                                         object_list->slist_pos);
-               eo_entry = slist_entry->data;
+       while(slist) {
+               eo_entry = slist->data;
                
                column_text[0] = g_strdup_printf("%u", eo_entry->pkt_num);
                column_text[1] = g_strdup_printf("%s", eo_entry->hostname);
@@ -263,7 +258,7 @@ eo_draw(void *tapdata)
                g_free(column_text[3]);
                g_free(column_text[4]);
 
-               object_list->slist_pos++;
+               slist = slist->next;
        }
 }
 
@@ -383,7 +378,7 @@ export_object_window(gchar *tapname, tap_packet_cb tap_packet)
        help_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_HELP);
        SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_EXPORT_OBJECT_LIST);
        gtk_tooltips_set_tip(GTK_TOOLTIPS(button_bar_tips), help_bt,
-                            "Show help on this dialog", NULL);
+                            "Show help for this dialog.", NULL);
        gtk_box_pack_start(GTK_BOX(bbox), help_bt, FALSE, FALSE, 0);
 
        /* Save All button */
@@ -418,7 +413,7 @@ export_object_window(gchar *tapname, tap_packet_cb tap_packet)
         SIGNAL_CONNECT(object_list->dlg, "delete_event",
                       window_delete_event_cb, NULL);
        SIGNAL_CONNECT(object_list->dlg, "destroy",
-                      eo_win_destroy_cb, NULL);
+                      eo_win_destroy_cb, object_list);
                window_set_cancel_button(object_list->dlg, close_bt,
                                 window_cancel_button_cb);
 
index dcf588e4aa43d8b07a58af70a9ee574ba3e70001..86c2732d7103125d0a68cb40ffc98e01b387285c 100644 (file)
@@ -34,7 +34,7 @@ typedef struct _export_object_list_t {
        GtkTreeView *tree_view;
        GtkTreeIter *iter;
        GtkTreeStore *store;
-       gint slist_pos, row_selected;
+       gint row_selected;
 } export_object_list_t;
 
 typedef struct _export_object_entry_t {
index 2665f595cd0878ba3840d4403fcf7f80da15a43b..6ae40ca9c972eabe9e24db52a03eba80292d47c2 100644 (file)
@@ -50,9 +50,10 @@ eo_http_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_,
        const http_info_value_t *stat_info = data;
        export_object_entry_t *entry;
 
-       if(stat_info->content_type) { /* We have new data waiting */
-               entry = g_malloc(sizeof(export_object_entry_t));
-
+       if(stat_info->content_type && /* We have data waiting for us */
+           g_ascii_strncasecmp(stat_info->content_type, "<NULL>", 6) != 0) {
+               entry = g_malloc(sizeof(export_object_entry_t));
+       
                entry->pkt_num = pinfo->fd->num;
                entry->hostname = stat_info->http_host;
                entry->content_type = stat_info->content_type;