Add text import capability, like text2pcap, directly into the GUI.
[obnox/wireshark/wip.git] / gtk / follow_tcp.c
index 23a6e8ddb52ad672dcf8df265fb7a33ac381572e..f20b02dd8c08e323401d6dbfbd15c655a6f83866 100644 (file)
 #include "../isprint.h"
 #include "../color.h"
 #include "../file.h"
-#include "../globals.h"
 #include "../alert_box.h"
 #include "../simple_dialog.h"
 #include "../tempfile.h"
 #include <wsutil/file_util.h>
 
+#include "gtkglobals.h"
 #include "gtk/color_utils.h"
 #include "gtk/follow_tcp.h"
 #include "gtk/dlg_utils.h"
@@ -68,7 +68,7 @@
 #include "gtk/font_utils.h"
 #include "gtk/help_dlg.h"
 #include "gtk/follow_stream.h"
-
+#include "gtk/utf8_entities.h"
 
 /* With MSVC and a libwireshark.dll, we need a special declaration. */
 WS_VAR_IMPORT FILE *data_out_file;
@@ -90,8 +90,9 @@ follow_tcp_redraw_all(void)
    a dissection routine on belongs (this might be the most recently
    selected packet, or it might be the last packet in the file). */
 void
-follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
+follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_)
 {
+       GtkWidget *filter_cm;
        GtkWidget       *filter_te;
        int             tmp_fd;
        gchar           *follow_filter;
@@ -106,6 +107,7 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
        follow_info_t   *follow_info;
        tcp_stream_chunk sc;
        size_t              nchars;
+       gchar           *data_out_filename;
 
        /* we got tcp so we can follow */
        if (cfile.edt->pi.ipproto != IP_PROTO_TCP) {
@@ -138,13 +140,14 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
           append stuff to the text widget for the TCP stream window,
           if we can arrange that said window not pop up until we're
           done. */
-       tmp_fd = create_tempfile(follow_info->data_out_filename,
-                       sizeof follow_info->data_out_filename, "follow");
+       tmp_fd = create_tempfile(&data_out_filename, "follow");
+       follow_info->data_out_filename = g_strdup(data_out_filename);
 
        if (tmp_fd == -1) {
            simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                          "Could not create temporary file %s: %s",
                          follow_info->data_out_filename, strerror(errno));
+           g_free(follow_info->data_out_filename);
            g_free(follow_info);
            g_free(follow_filter);
            return;
@@ -157,13 +160,15 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
                          follow_info->data_out_filename, strerror(errno));
            ws_close(tmp_fd);
            ws_unlink(follow_info->data_out_filename);
+           g_free(follow_info->data_out_filename);
            g_free(follow_info);
            g_free(follow_filter);
            return;
        }
 
        /* Set the display filter entry accordingly */
-       filter_te = g_object_get_data(G_OBJECT(w), E_DFILTER_TE_KEY);
+       filter_cm = g_object_get_data(G_OBJECT(top_level), E_DFILTER_CM_KEY);
+       filter_te = gtk_bin_get_child(GTK_BIN(filter_cm));
 
        /* needed in follow_filter_out_stream(), is there a better way? */
        follow_info->filter_te = filter_te;
@@ -174,7 +179,7 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
 
        /* allocate our new filter. API claims g_malloc terminates program on failure */
        /* my calc for max alloc needed is really +10 but when did a few extra bytes hurt ? */
-       filter_out_filter_len = strlen(follow_filter) + strlen(previous_filter) + 16;
+       filter_out_filter_len = (int)(strlen(follow_filter) + strlen(previous_filter) + 16);
        follow_info->filter_out_filter = (gchar *)g_malloc(filter_out_filter_len);
 
        /* append the negation */
@@ -201,6 +206,8 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
                          "The packets in the capture file for that stream have no data.");
            ws_close(tmp_fd);
            ws_unlink(follow_info->data_out_filename);
+           g_free(follow_info->data_out_filename);
+           g_free(follow_info->filter_out_filter);
            g_free(follow_info);
            return;
        }
@@ -231,6 +238,8 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
            }
            ws_close(tmp_fd);
            ws_unlink(follow_info->data_out_filename);
+           g_free(follow_info->data_out_filename);
+           g_free(follow_info->filter_out_filter);
            g_free(follow_info);
            return;
        }
@@ -264,13 +273,13 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
        /* Host 0 --> Host 1 */
        if(sc.src_port == stats.port[0]) {
                server_to_client_string =
-                       g_strdup_printf("%s:%s --> %s:%s (%u bytes)",
+                       g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
                                        hostname0, port0,
                                        hostname1, port1,
                                        stats.bytes_written[0]);
        } else {
                server_to_client_string =
-                       g_strdup_printf("%s:%s --> %s:%s (%u bytes)",
+                       g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
                                        hostname1, port1,
                                        hostname0,port0,
                                        stats.bytes_written[0]);
@@ -279,13 +288,13 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
        /* Host 1 --> Host 0 */
        if(sc.src_port == stats.port[1]) {
                client_to_server_string =
-                       g_strdup_printf("%s:%s --> %s:%s (%u bytes)",
+                       g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
                                        hostname0, port0,
                                        hostname1, port1,
                                        stats.bytes_written[1]);
        } else {
                client_to_server_string =
-                       g_strdup_printf("%s:%s --> %s:%s (%u bytes)",
+                       g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
                                        hostname1, port1,
                                        hostname0, port0,
                                        stats.bytes_written[1]);
@@ -307,7 +316,7 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
 #define FLT_BUF_SIZE 1024
 
 /*
- * XXX - the routine pointed to by "print_line" doesn't get handed lines,
+ * XXX - the routine pointed to by "print_line_fcn_p" doesn't get handed lines,
  * it gets handed bufferfuls.  That's fine for "follow_write_raw()"
  * and "follow_add_to_gtk_text()", but, as "follow_print_text()" calls
  * the "print_line()" routine from "print.c", and as that routine might
@@ -325,7 +334,7 @@ follow_tcp_stream_cb(GtkWidget * w, gpointer data _U_)
  */
 frs_return_t
 follow_read_tcp_stream(follow_info_t *follow_info,
-                      gboolean (*print_line)(char *, size_t, gboolean, void *),
+                      gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
                       void *arg)
 {
     tcp_stream_chunk   sc;
@@ -390,10 +399,10 @@ follow_read_tcp_stream(follow_info_t *follow_info,
            if (nchars == 0)
                break;
            /* XXX - if we don't get "bcount" bytes, is that an error? */
-           sc.dlen -= nchars;
+           sc.dlen -= (guint32) nchars;
 
            if (!skip) {
-                   frs_return = follow_show(follow_info, print_line, buffer,
+                   frs_return = follow_show(follow_info, print_line_fcn_p, buffer,
                                             nchars, is_server, arg, global_pos,
                                             &server_packet_count,
                                             &client_packet_count);