print.c and ps.c are in libwirshark now.
[metze/wireshark/wip.git] / file.c
diff --git a/file.c b/file.c
index 7fa66819203c3db45451c54041a5f40ea4fde85e..6a0d2ba86de1972529e4d48027532f65071afe6f 100644 (file)
--- a/file.c
+++ b/file.c
@@ -42,6 +42,7 @@
 #endif
 
 #include <epan/epan.h>
+#include <epan/expert.h>
 #include <epan/filesystem.h>
 
 #include "color.h"
 #include <epan/column.h>
 #include <epan/packet.h>
 #include <epan/column-utils.h>
-#include "packet-range.h"
-#include "print.h"
 #include "file.h"
 #include "fileset.h"
-#include "tempfile.h"
+#include "frame_tvbuff.h"
+#include "wsutil/tempfile.h"
 #include "merge.h"
 
 #include <epan/prefs.h>
@@ -75,6 +75,8 @@
 #include "ui/progress_dlg.h"
 #include "ui/ui_util.h"
 
+#include "version_info.h"
+
 /* Needed for addrinfo */
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
@@ -604,8 +606,6 @@ cf_read(capture_file *cf, gboolean reloading)
         progbar_quantum = MIN_QUANTUM;
     }else
       progbar_quantum = 0;
-    /* Progress so far. */
-    progbar_val = 0.0f;
 
     while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
       if (size >= 0) {
@@ -1132,7 +1132,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
       epan_dissect_prime_dfilter(&edt, dfcode);
   }
 
-  epan_dissect_run_with_taps(&edt, phdr, buf, fdata, cinfo);
+  epan_dissect_run_with_taps(&edt, phdr, frame_tvbuff_new(fdata, buf), fdata, cinfo);
 
   /* If we don't have a display filter, set "passed_dfilter" to 1. */
   if (dfcode != NULL) {
@@ -1218,7 +1218,7 @@ read_packet(capture_file *cf, dfilter_t *dfcode,
     epan_dissect_t edt;
     epan_dissect_init(&edt, TRUE, FALSE);
     epan_dissect_prime_dfilter(&edt, cf->rfcode);
-    epan_dissect_run(&edt, phdr, buf, &fdlocal, NULL);
+    epan_dissect_run(&edt, phdr, frame_tvbuff_new(&fdlocal, buf), &fdlocal, NULL);
     passed = dfilter_apply_edt(cf->rfcode, &edt);
     epan_dissect_cleanup(&edt);
   }
@@ -1703,7 +1703,8 @@ cf_read_frame_r(capture_file *cf, frame_data *fdata,
     }
 
     *phdr = frame->phdr;
-    memcpy(pd, frame->pd, fdata->cap_len);
+    buffer_assure_space(buf, frame->phdr.caplen);
+    memcpy(buffer_start_ptr(buf), frame->pd, frame->phdr.caplen);
     return TRUE;
   }
 #endif
@@ -2292,7 +2293,7 @@ retap_packet(capture_file *cf _U_, frame_data *fdata,
   epan_dissect_t         edt;
 
   epan_dissect_init(&edt, args->construct_protocol_tree, FALSE);
-  epan_dissect_run_with_taps(&edt, phdr, pd, fdata, args->cinfo);
+  epan_dissect_run_with_taps(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, args->cinfo);
   epan_dissect_cleanup(&edt);
 
   return TRUE;
@@ -2388,10 +2389,10 @@ print_packet(capture_file *cf, frame_data *fdata,
      information. */
   if (args->print_args->print_summary) {
     col_custom_prime_edt(&edt, &cf->cinfo);
-    epan_dissect_run(&edt, phdr, pd, fdata, &cf->cinfo);
+    epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
     epan_dissect_fill_in_columns(&edt, FALSE, TRUE);
   } else
-    epan_dissect_run(&edt, phdr, pd, fdata, NULL);
+    epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
 
   if (args->print_formfeed) {
     if (!new_page(args->print_args->stream))
@@ -2410,6 +2411,8 @@ print_packet(capture_file *cf, frame_data *fdata,
   g_snprintf(bookmark_name, sizeof bookmark_name, "__frame%u__", fdata->num);
 
   if (args->print_args->print_summary) {
+    if (!args->print_args->print_col_headings)
+        args->print_header_line = FALSE;
     if (args->print_header_line) {
       if (!print_line(args->print_args->stream, 0, args->header_line_buf))
         goto fail;
@@ -2479,7 +2482,8 @@ print_packet(capture_file *cf, frame_data *fdata,
     args->print_separator = TRUE;
 
     /* Print a header line if we print any more packet summaries */
-    args->print_header_line = TRUE;
+    if (args->print_args->print_col_headings)
+        args->print_header_line = TRUE;
   }
 
   if (args->print_args->print_hex) {
@@ -2495,7 +2499,8 @@ print_packet(capture_file *cf, frame_data *fdata,
     args->print_separator = TRUE;
 
     /* Print a header line if we print any more packet summaries */
-    args->print_header_line = TRUE;
+    if (args->print_args->print_col_headings)
+        args->print_header_line = TRUE;
   } /* if (args->print_args->print_dissections != print_dissections_none) */
 
   epan_dissect_cleanup(&edt);
@@ -2525,7 +2530,7 @@ cf_print_packets(capture_file *cf, print_args_t *print_args)
   fmt_data     *cfmt;
 
   callback_args.print_args = print_args;
-  callback_args.print_header_line = TRUE;
+  callback_args.print_header_line = print_args->print_col_headings;
   callback_args.header_line_buf = NULL;
   callback_args.header_line_buf_len = 256;
   callback_args.print_formfeed = FALSE;
@@ -2536,7 +2541,7 @@ cf_print_packets(capture_file *cf, print_args_t *print_args)
   callback_args.num_visible_cols = 0;
   callback_args.visible_cols = NULL;
 
-  if (!print_preamble(print_args->stream, cf->filename)) {
+  if (!print_preamble(print_args->stream, cf->filename, wireshark_svnversion)) {
     destroy_print_stream(print_args->stream);
     return CF_PRINT_WRITE_ERROR;
   }
@@ -2685,7 +2690,7 @@ write_pdml_packet(capture_file *cf _U_, frame_data *fdata,
 
   /* Create the protocol tree, but don't fill in the column information. */
   epan_dissect_init(&edt, TRUE, TRUE);
-  epan_dissect_run(&edt, phdr, pd, fdata, NULL);
+  epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
 
   /* Write out the information in that tree. */
   proto_tree_write_pdml(&edt, fh);
@@ -2759,7 +2764,7 @@ write_psml_packet(capture_file *cf, frame_data *fdata,
   proto_tree_needed = have_custom_cols(&cf->cinfo);
   epan_dissect_init(&edt, proto_tree_needed, proto_tree_needed);
   col_custom_prime_edt(&edt, &cf->cinfo);
-  epan_dissect_run(&edt, phdr, pd, fdata, &cf->cinfo);
+  epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
   epan_dissect_fill_in_columns(&edt, FALSE, TRUE);
 
   /* Write out the information in that tree. */
@@ -2834,7 +2839,7 @@ write_csv_packet(capture_file *cf, frame_data *fdata,
   proto_tree_needed = have_custom_cols(&cf->cinfo);
   epan_dissect_init(&edt, proto_tree_needed, proto_tree_needed);
   col_custom_prime_edt(&edt, &cf->cinfo);
-  epan_dissect_run(&edt, phdr, pd, fdata, &cf->cinfo);
+  epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
   epan_dissect_fill_in_columns(&edt, FALSE, TRUE);
 
   /* Write out the information in that tree. */
@@ -2904,7 +2909,7 @@ write_carrays_packet(capture_file *cf _U_, frame_data *fdata,
   epan_dissect_t  edt;
 
   epan_dissect_init(&edt, TRUE, TRUE);
-  epan_dissect_run(&edt, phdr, pd, fdata, NULL);
+  epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
   proto_tree_write_carrays(fdata->num, fh, &edt);
   epan_dissect_cleanup(&edt);
 
@@ -2997,7 +3002,7 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion)
   /* Construct the protocol tree, including the displayed text */
   epan_dissect_init(&edt, TRUE, TRUE);
   /* We don't need the column information */
-  epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
+  epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
 
   /* Iterate through all the nodes, seeing if they have text that matches. */
   mdata->cf = cf;
@@ -3101,7 +3106,7 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
   /* Don't bother constructing the protocol tree */
   epan_dissect_init(&edt, FALSE, FALSE);
   /* Get the column information */
-  epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata,
+  epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata,
                    &cf->cinfo);
 
   /* Find the Info column */
@@ -3409,7 +3414,7 @@ match_dfilter(capture_file *cf, frame_data *fdata, void *criterion)
 
   epan_dissect_init(&edt, TRUE, FALSE);
   epan_dissect_prime_dfilter(&edt, sfcode);
-  epan_dissect_run(&edt, &cf->phdr, buffer_start_ptr(&cf->buf), fdata, NULL);
+  epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
   result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
   epan_dissect_cleanup(&edt);
   return result;
@@ -3742,7 +3747,7 @@ cf_select_packet(capture_file *cf, int row)
   cf->edt = epan_dissect_new(TRUE, TRUE);
 
   tap_build_interesting(cf->edt);
-  epan_dissect_run(cf->edt, &cf->phdr, buffer_start_ptr(&cf->buf),
+  epan_dissect_run(cf->edt, &cf->phdr, frame_tvbuff_new_buffer(cf->current_frame, &cf->buf),
                    cf->current_frame, NULL);
 
   dfilter_macro_build_ftv_cache(cf->edt->tree);
@@ -3898,6 +3903,8 @@ cf_update_packet_comment(capture_file *cf, frame_data *fdata, gchar *comment)
     cf->packet_comment_count++;
   }
 
+  expert_update_comment_count(cf->packet_comment_count);
+
   /* OK, we have unsaved changes. */
   cf->unsaved_changes = TRUE;
 }
@@ -4197,8 +4204,6 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
       progbar_quantum = MIN_QUANTUM;
   }else
     progbar_quantum = 0;
-  /* Progress so far. */
-  progbar_val = 0.0f;
 
   stop_flag = FALSE;
   g_get_current_time(&start_time);