Store pointers to previously displayed and captured packet, not nstime_t deltas.
[metze/wireshark/wip.git] / file.c
diff --git a/file.c b/file.c
index 7ed4328dbd3a2f01c0565098c2628c0ea05b6b2a..ced94b7d0b492c59f7cc4a265abe37b8aa75d4b7 100644 (file)
--- a/file.c
+++ b/file.c
@@ -22,9 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -83,8 +81,8 @@ gboolean auto_scroll_live;
 
 static guint32 cum_bytes;
 static nstime_t first_ts;
-static nstime_t prev_dis_ts;
-static nstime_t prev_cap_ts;
+static frame_data *prev_dis;
+static frame_data *prev_cap;
 
 static gulong computed_elapsed;
 
@@ -244,7 +242,7 @@ cf_timestamp_auto_precision(capture_file *cf)
      "command-line-specified" format. */
   for (i = 0; i < cf->cinfo.num_cols; i++) {
     if (col_has_time_fmt(&cf->cinfo, i)) {
-      new_packet_list_resize_column(i);
+      packet_list_resize_column(i);
     }
   }
 }
@@ -334,14 +332,14 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
 
   nstime_set_zero(&cf->elapsed_time);
   nstime_set_unset(&first_ts);
-  nstime_set_unset(&prev_dis_ts);
-  nstime_set_unset(&prev_cap_ts);
+  prev_dis = NULL;
+  prev_cap = NULL;
   cum_bytes = 0;
 
   /* Adjust timestamp precision if auto is selected, col width will be adjusted */
   cf_timestamp_auto_precision(cf);
   /* XXX needed ? */
-  new_packet_list_queue_draw();
+  packet_list_queue_draw();
   fileset_file_opened(fname);
 
   if (cf->cd_t == WTAP_FILE_BER) {
@@ -433,9 +431,9 @@ cf_reset_state(capture_file *cf)
   cf->linktypes = NULL;
 
   /* Clear the packet list. */
-  new_packet_list_freeze();
-  new_packet_list_clear();
-  new_packet_list_thaw();
+  packet_list_freeze();
+  packet_list_clear();
+  packet_list_thaw();
 
   cf->f_datalen = 0;
   nstime_set_zero(&cf->elapsed_time);
@@ -564,7 +562,7 @@ cf_read(capture_file *cf, gboolean reloading)
   progbar_val = 0.0f;
 
   /* The packet list window will be empty until the file is completly loaded */
-  new_packet_list_freeze();
+  packet_list_freeze();
 
   stop_flag = FALSE;
   g_get_current_time(&start_time);
@@ -672,7 +670,7 @@ cf_read(capture_file *cf, gboolean reloading)
   cf->current_frame = frame_data_sequence_find(cf->frames, cf->first_displayed);
   cf->current_row = 0;
 
-  new_packet_list_thaw();
+  packet_list_thaw();
   if (reloading)
     cf_callback_invoke(cf_cb_file_reload_finished, cf);
   else
@@ -681,7 +679,7 @@ cf_read(capture_file *cf, gboolean reloading)
   /* If we have any displayed packets to select, select the first of those
      packets by making the first row the selected row. */
   if (cf->first_displayed != 0) {
-    new_packet_list_select_first_row();
+    packet_list_select_first_row();
   }
 
   if (stop_flag) {
@@ -787,9 +785,9 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
 
   *err = 0;
 
-  new_packet_list_check_end();
+  packet_list_check_end();
   /* Don't freeze/thaw the list when doing live capture */
-  /*new_packet_list_freeze();*/
+  /*packet_list_freeze();*/
 
   /*g_log(NULL, G_LOG_LEVEL_MESSAGE, "cf_continue_tail: %u new: %u", cf->count, to_read);*/
 
@@ -840,17 +838,17 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
     cf->count, cf->state, *err);*/
 
   /* Don't freeze/thaw the list when doing live capture */
-  /*new_packet_list_thaw();*/
+  /*packet_list_thaw();*/
   /* With the new packet list the first packet
    * isn't automatically selected.
    */
   if (!cf->current_frame)
-    new_packet_list_select_first_row();
+    packet_list_select_first_row();
 
   /* moving to the end of the packet list - if the user requested so and
      we have some new packets. */
   if (newly_displayed_packets && auto_scroll_live && cf->count != 0)
-      new_packet_list_moveto_end();
+      packet_list_moveto_end();
 
   if (cf->state == FILE_READ_ABORTED) {
     /* Well, the user decided to exit Wireshark.  Return CF_READ_ABORTED
@@ -862,8 +860,9 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
   } else if (*err != 0) {
     /* We got an error reading the capture file.
        XXX - pop up a dialog box instead? */
-    g_warning("Error \"%s\" while reading: \"%s\"\n",
-        wtap_strerror(*err), cf->filename);
+    g_warning("Error \"%s\" while reading: \"%s\" (\"%s\")",
+        wtap_strerror(*err), err_info, cf->filename);
+    g_free(err_info);
 
     return CF_READ_ERROR;
   } else
@@ -903,9 +902,9 @@ cf_finish_tail(capture_file *cf, int *err)
     return CF_READ_ERROR;
   }
 
-  new_packet_list_check_end();
+  packet_list_check_end();
   /* Don't freeze/thaw the list when doing live capture */
-  /*new_packet_list_freeze();*/
+  /*packet_list_freeze();*/
 
   while ((wtap_read(cf->wth, err, &err_info, &data_offset))) {
     if (cf->state == FILE_READ_ABORTED) {
@@ -923,7 +922,7 @@ cf_finish_tail(capture_file *cf, int *err)
   }
 
   /* Don't freeze/thaw the list when doing live capture */
-  /*new_packet_list_thaw();*/
+  /*packet_list_thaw();*/
 
   if (cf->state == FILE_READ_ABORTED) {
     /* Well, the user decided to abort the read.  We're only called
@@ -936,7 +935,7 @@ cf_finish_tail(capture_file *cf, int *err)
   }
 
   if (auto_scroll_live && cf->count != 0)
-    new_packet_list_moveto_end();
+    packet_list_moveto_end();
 
   /* We're done reading sequentially through the file. */
   cf->state = FILE_READ_DONE;
@@ -960,6 +959,10 @@ cf_finish_tail(capture_file *cf, int *err)
   if (*err != 0) {
     /* We got an error reading the capture file.
        XXX - pop up a dialog box? */
+
+    g_warning("Error \"%s\" while reading: \"%s\" (\"%s\")",
+        wtap_strerror(*err), err_info, cf->filename);
+    g_free(err_info);
     return CF_READ_ERROR;
   } else {
     return CF_READ_OK;
@@ -1096,7 +1099,8 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
   cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
 
   frame_data_set_before_dissect(fdata, &cf->elapsed_time,
-                                &first_ts, &prev_dis_ts, &prev_cap_ts);
+                                &first_ts, prev_dis, prev_cap);
+  prev_cap = fdata;
 
   /* If either
     + we have a display filter and are re-applying it;
@@ -1145,12 +1149,13 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
 
   if (add_to_packet_list) {
     /* We fill the needed columns from new_packet_list */
-      row = new_packet_list_append(cinfo, fdata, &edt.pi);
+      row = packet_list_append(cinfo, fdata, &edt.pi);
   }
 
   if (fdata->flags.passed_dfilter || fdata->flags.ref_time)
   {
-    frame_data_set_after_dissect(fdata, &cum_bytes, &prev_dis_ts);
+    frame_data_set_after_dissect(fdata, &cum_bytes);
+    prev_dis = fdata;
 
     /* If we haven't yet seen the first frame, this is it.
 
@@ -1799,7 +1804,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
 
   /* Freeze the packet list while we redo it, so we don't get any
      screen updates while it happens. */
-  new_packet_list_freeze();
+  packet_list_freeze();
 
   if (redissect) {
     /* We need to re-initialize all the state information that protocols
@@ -1818,7 +1823,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
 
     /* We need to redissect the packets so we have to discard our old
      * packet list store. */
-    new_packet_list_clear();
+    packet_list_clear();
     add_to_packet_list = TRUE;
   }
 
@@ -1833,8 +1838,8 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
      to check whether it should be displayed and, if so, add it to
      the display list. */
   nstime_set_unset(&first_ts);
-  nstime_set_unset(&prev_dis_ts);
-  nstime_set_unset(&prev_cap_ts);
+  prev_dis = NULL;
+  prev_cap = NULL;
   cum_bytes = 0;
 
   /* Update the progress bar when it gets to this value. */
@@ -1991,12 +1996,12 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
 
   /* Unfreeze the packet list. */
   if (!add_to_packet_list)
-    new_packet_list_recreate_visible_rows();
+    packet_list_recreate_visible_rows();
 
   /* Compute the time it took to filter the file */
   compute_elapsed(&start_time);
 
-  new_packet_list_thaw();
+  packet_list_thaw();
 
   if (selected_frame_num == -1) {
     /* The selected frame didn't pass the filter. */
@@ -2044,9 +2049,9 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
     /* Set to invalid to force update of packet list and packet details */
     cf->current_row = -1;
     if (selected_frame_num == 0) {
-      new_packet_list_select_first_row();
+      packet_list_select_first_row();
     }else{
-      if (!new_packet_list_select_row_from_data(selected_frame)) {
+      if (!packet_list_select_row_from_data(selected_frame)) {
         /* We didn't find a row corresponding to this frame.
            This means that the frame isn't being displayed currently,
            so we can't select it. */
@@ -2074,7 +2079,7 @@ ref_time_packets(capture_file *cf)
   frame_data *fdata;
 
   nstime_set_unset(&first_ts);
-  nstime_set_unset(&prev_dis_ts);
+  prev_dis = NULL;
   cum_bytes = 0;
 
   for (framenum = 1; framenum <= cf->count; framenum++) {
@@ -2103,8 +2108,8 @@ ref_time_packets(capture_file *cf)
      it's because this is the first displayed packet.  Save the time
      stamp of this packet as the time stamp of the previous displayed
      packet. */
-    if (nstime_is_unset(&prev_dis_ts)) {
-        prev_dis_ts = fdata->abs_ts;
+    if (prev_dis == NULL) {
+        prev_dis = fdata;
     }
 
     /* Get the time elapsed between the first packet and this packet. */
@@ -2121,8 +2126,8 @@ ref_time_packets(capture_file *cf)
     /* If this frame is displayed, get the time elapsed between the
      previous displayed packet and this packet. */
     if ( fdata->flags.passed_dfilter ) {
-        nstime_delta(&fdata->del_dis_ts, &fdata->abs_ts, &prev_dis_ts);
-        prev_dis_ts = fdata->abs_ts;
+        fdata->prev_dis = prev_dis;
+        prev_dis = fdata;
     }
 
     /*
@@ -3014,7 +3019,8 @@ match_subtree_text(proto_node *node, gpointer data)
   guint8        c_char;
   size_t        c_match    = 0;
 
-  g_assert(fi && "dissection with an invisible proto tree?");
+  /* dissection with an invisible proto tree? */
+  g_assert(fi);
 
   if (mdata->frame_matched) {
     /* We already had a match; don't bother doing any more work. */
@@ -3566,7 +3572,7 @@ find_packet(capture_file *cf,
   if (new_fd != NULL) {
     /* Find and select */
     cf->search_in_progress = TRUE;
-    found = new_packet_list_select_row_from_data(new_fd);
+    found = packet_list_select_row_from_data(new_fd);
     cf->search_in_progress = FALSE;
     cf->search_pos = 0; /* Reset the position */
     if (!found) {
@@ -3602,7 +3608,7 @@ cf_goto_frame(capture_file *cf, guint fnumber)
     return FALSE;   /* we failed to go to that packet */
   }
 
-  if (!new_packet_list_select_row_from_data(fdata)) {
+  if (!packet_list_select_row_from_data(fdata)) {
     /* We didn't find a row corresponding to this frame.
        This means that the frame isn't being displayed currently,
        so we can't select it. */
@@ -3618,7 +3624,7 @@ gboolean
 cf_goto_top_frame(void)
 {
   /* Find and select */
-  new_packet_list_select_first_row();
+  packet_list_select_first_row();
   return TRUE;  /* we got to that packet */
 }
 
@@ -3626,7 +3632,7 @@ gboolean
 cf_goto_bottom_frame(void)
 {
   /* Find and select */
-  new_packet_list_select_last_row();
+  packet_list_select_last_row();
   return TRUE;  /* we got to that packet */
 }
 
@@ -3660,7 +3666,7 @@ cf_select_packet(capture_file *cf, int row)
   frame_data     *fdata;
 
   /* Get the frame data struct pointer for this frame */
-  fdata = new_packet_list_get_row_data(row);
+  fdata = packet_list_get_row_data(row);
 
   if (fdata == NULL) {
     /* XXX - if a GtkCList's selection mode is GTK_SELECTION_BROWSE, when