Have the frame_tvbuff.c routines not use the global cfile.
[metze/wireshark/wip.git] / ui / gtk / summary_dlg.c
index 8a6ea164399f8aee2928f23383f523ff1058ea1c..2a7bfe7f9975e058a1e35d34e05f3cbbc84df4d0 100644 (file)
 #include "config.h"
 
 #include <string.h>
-#include <time.h>
 
 #include <gtk/gtk.h>
 
-#include <epan/strutil.h>
+#include <version_info.h>
 
-#include <wiretap/wtap.h>
-
-#include <wsutil/ws_version_info.h>
-
-#include "../globals.h"
-#include "../file.h"
-#include "../summary.h"
+#include "../../file.h"
+#include "../../summary.h"
 
 #ifdef HAVE_LIBPCAP
 #include "ui/capture.h"
@@ -49,6 +43,8 @@
 #include "ui/gtk/help_dlg.h"
 #include "ui/gtk/packet_list.h"
 
+#include "globals.h"
+
 #define SUM_STR_MAX      1024
 #define FILTER_SNIP_LEN    50
 #define SHB_STR_SNIP_LEN   50
@@ -145,7 +141,7 @@ summary_ok_cb(GtkWidget *w _U_, GtkWidget *view)
 
     new_comment = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE /* whether to include invisible text */);
 
-    cf_update_capture_comment(&cfile, new_comment);
+    cf_update_section_comment(&cfile, new_comment);
 
     /* Update the main window */
     main_update_for_unsaved_changes(&cfile);
@@ -172,7 +168,6 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
   GtkWidget         *list, *treeview;
   GtkWidget         *comment_view = NULL, *comment_frame, *comment_vbox;
   GtkTextBuffer     *buffer = NULL;
-  gchar             *buf_str;
   GtkListStore      *store;
   GtkTreeIter        iter;
   GtkCellRenderer   *renderer;
@@ -193,6 +188,7 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
 
   unsigned int  elapsed_time;
   iface_options iface;
+  wtap_block_t  shb_inf;
   unsigned int  i;
 
   if (summary_dlg != NULL) {
@@ -272,12 +268,14 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
     g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.file_encap_type));
     add_string_to_grid(grid, &row, "Encapsulation:", string_buff);
   }
-  if (summary.has_snap) {
+  if (summary.snap != 0) {
     /* snapshot length */
     g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
     add_string_to_grid(grid, &row, "Packet size limit:", string_buff);
   }
 
+  shb_inf = wtap_file_get_shb(cfile.provider.wth);
+
   /* Capture file comment area */
   if (wtap_dump_can_write(cfile.linktypes, WTAP_COMMENT_PER_SECTION)) {
     comment_frame = gtk_frame_new("Capture file comments");
@@ -292,12 +290,15 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
     comment_view = gtk_text_view_new();
     gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(comment_view), GTK_WRAP_WORD);
     buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (comment_view));
-    if(summary.opt_comment == NULL) {
-      gtk_text_buffer_set_text (buffer, "", -1);
-    } else {
-      buf_str = g_strdup_printf("%s", summary.opt_comment);
-      gtk_text_buffer_set_text (buffer, buf_str, -1);
-      g_free(buf_str);
+    gtk_text_buffer_set_text (buffer, "", -1);
+    if (shb_inf != NULL) {
+      char *opt_comment;
+
+      /* XXX - this only shows the last comment */
+      for (i = 0; wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
+        if (opt_comment[0] != '\0')
+          gtk_text_buffer_set_text (buffer, opt_comment, -1);
+      }
     }
     gtk_box_pack_start(GTK_BOX(comment_vbox), comment_view, TRUE, TRUE, 0);
     gtk_widget_show (comment_view);
@@ -344,20 +345,28 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
   /* Capture */
   add_string_to_grid(grid, &row, "", "");
   add_string_to_grid_sensitive(grid, &row, "Capture", "", (summary.ifaces->len > 0));
-  if(summary.shb_hardware){
-    /* truncate the string to a reasonable length */
-    g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_hardware);
-    add_string_to_grid(grid, &row, "Capture HW:",string_buff);
-  }
-  if(summary.shb_os){
-    /* truncate the strings to a reasonable length */
-    g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_os);
-    add_string_to_grid(grid, &row, "OS:", string_buff);
-  }
-  if(summary.shb_user_appl){
-    /* truncate the string to a reasonable length */
-    g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_user_appl);
-    add_string_to_grid(grid, &row, "Capture application:", string_buff);
+  if (shb_inf != NULL) {
+    char *str;
+
+    if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS &&
+        str[0] != '\0') {
+      g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str);
+      add_string_to_grid(grid, &row, "Capture HW:",string_buff);
+    }
+
+    if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS &&
+        str[0] != '\0') {
+      /* truncate the strings to a reasonable length */
+      g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str);
+      add_string_to_grid(grid, &row, "OS:", string_buff);
+    }
+
+    if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS &&
+        str[0] != '\0') {
+      /* truncate the strings to a reasonable length */
+      g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str);
+      add_string_to_grid(grid, &row, "Capture application:", string_buff);
+    }
   }
   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
   gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 5);
@@ -653,11 +662,11 @@ summary_to_texbuff(GtkTextBuffer *buffer)
   summary_tally summary;
   gchar         string_buff[SUM_STR_MAX];
   gchar         tmp_buff[SUM_STR_MAX];
-  gchar *buf_str;
+  wtap_block_t shb_inf;
   unsigned int  i;
   unsigned int  elapsed_time;
   iface_options iface;
-  double seconds;
+  double        seconds;
 
   /* initial computations */
   summary_fill_in(&cfile, &summary);
@@ -699,7 +708,7 @@ summary_to_texbuff(GtkTextBuffer *buffer)
     g_snprintf(string_buff, SUM_STR_MAX, INDENT "Encapsulation: %s\n", wtap_encap_string(summary.file_encap_type));
     gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
   }
-  if (summary.has_snap) {
+  if (summary.snap != 0) {
     /* snapshot length */
     g_snprintf(string_buff, SUM_STR_MAX, INDENT "Packet size limit: %u bytes\n", summary.snap);
     gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
@@ -752,20 +761,28 @@ summary_to_texbuff(GtkTextBuffer *buffer)
   g_snprintf(string_buff, SUM_STR_MAX, "Capture:\n");
   gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
 
-  if(summary.shb_hardware){
-    /* truncate the string to a reasonable length */
-    g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture HW: %s\n",summary.shb_hardware);
-    gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-  }
-  if(summary.shb_os){
-    /* truncate the strings to a reasonable length */
-    g_snprintf(string_buff, SUM_STR_MAX, INDENT "OS: %s\n",summary.shb_os);
-    gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-  }
-  if(summary.shb_user_appl){
-    /* truncate the string to a reasonable length */
-    g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture application: %s\n",summary.shb_user_appl);
-    gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+  shb_inf = wtap_file_get_shb(cfile.provider.wth);
+  if (shb_inf != NULL) {
+    char *str;
+
+    if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS &&
+        str[0] != '\0') {
+      /* truncate the string to a reasonable length */
+      g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture HW: %s\n", str);
+      gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+    }
+    if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS &&
+        str[0] != '\0') {
+      /* truncate the strings to a reasonable length */
+      g_snprintf(string_buff, SUM_STR_MAX, INDENT "OS: %s\n", str);
+      gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+    }
+    if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS &&
+        str[0] != '\0') {
+      /* truncate the string to a reasonable length */
+      g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture application: %s\n", str);
+      gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+    }
   }
 
   /* Add empty line */
@@ -879,10 +896,15 @@ summary_to_texbuff(GtkTextBuffer *buffer)
   gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
 
   /* Trace file comments from SHB */
-  if(summary.opt_comment != NULL) {
-    buf_str = g_strdup_printf("%s", summary.opt_comment);
-    gtk_text_buffer_insert_at_cursor(buffer, buf_str, -1);
-    g_free(buf_str);
+  shb_inf = wtap_file_get_shb(cfile.provider.wth);
+  if (shb_inf != NULL) {
+    char *opt_comment;
+
+    for (i = 0; wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) {
+      /* XXX - separator between comments? */
+      if (opt_comment[0] != '\0')
+        gtk_text_buffer_insert_at_cursor(buffer, opt_comment, -1);
+    }
   }