Cleanup follow stream code
authorMichael Mann <mmann78@netscape.net>
Sun, 3 Jan 2016 02:48:13 +0000 (21:48 -0500)
committerMichael Mann <mmann78@netscape.net>
Sun, 3 Jan 2016 15:24:21 +0000 (15:24 +0000)
Adding Follow HTTP Stream justified some refactoring and code removal.

Change-Id: I9b7ace83f8517e880e78193bb97ac32e3fc91114
Reviewed-on: https://code.wireshark.org/review/13015
Reviewed-by: Michael Mann <mmann78@netscape.net>
ui/CMakeLists.txt
ui/Makefile.common
ui/follow.c [deleted file]
ui/follow.h
ui/gtk/follow_http.c
ui/gtk/follow_ssl.c
ui/gtk/follow_stream.c
ui/gtk/follow_stream.h
ui/gtk/follow_tcp.c
ui/gtk/follow_udp.c

index f0a496a387e741d624f3f52765eaa50f1de4115c..d68079062ec8080fb1eb0d47b5b42beae049b2e9 100644 (file)
@@ -32,7 +32,6 @@ set(COMMON_UI_SRC
        export_object_smb.c
        export_object_tftp.c
        filters.c
-       follow.c
        help_url.c
        iface_lists.c
        io_graph_item.c
index fd17475a3600a29d2c0afa424e788bbf4bf7ad89..a4c689f773f1d98e40a591fe563b321866748353 100644 (file)
@@ -53,7 +53,6 @@ WIRESHARK_UI_SRC = \
        export_object_smb.c     \
        export_object_tftp.c    \
        filters.c               \
-       follow.c                \
        iface_lists.c           \
        io_graph_item.c         \
        language.c              \
diff --git a/ui/follow.c b/ui/follow.c
deleted file mode 100644 (file)
index 8fc6f85..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/* follow.c
- *
- * Wireshark - Network traffic analyzer
- * By Gerald Combs <gerald@wireshark.org>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-
-#include <glib.h>
-
-
-#include "ui/follow.h"
-
-#ifdef HAVE_LIBZ
-static char *
-sgetline(char *str, int *next)
-{
-    char *end;
-
-    end = strstr(str, "\r\n");
-    if (!end) {
-        *next = (int)strlen(str);
-        return NULL;
-    }
-    *end = '\0';
-    *next = (int)(end-str+2);
-    return str;
-}
-
-gboolean
-parse_http_header(char *data, size_t len, size_t *content_start)
-{
-    char *tmp, *copy, *line;
-    size_t pos = 0;
-    int next_line;
-    gboolean is_gzipped;
-
-    /* XXX handle case where only partial header is passed in here.
-     * we should pass something back to indicate whether header is complete.
-     * (if not, is_gzipped is may still be unknown)
-     */
-
-    /*
-     * In order to parse header, we duplicate data and tokenize lines.
-     * We aren't interested in actual data, so use g_strndup instead of memcpy
-     * to (possibly) copy fewer bytes (e.g., if a nul byte exists in data)
-     * This also ensures that we have a terminated string for further
-     * processing.
-     */
-    tmp = copy = g_strndup(data, len);
-    if (!tmp) {
-        *content_start = 0;
-        return FALSE;
-    }
-
-    /* skip HTTP... line*/
-    /*line = */sgetline(tmp, &next_line);
-
-    tmp += next_line;
-    pos += next_line;
-
-    is_gzipped = FALSE;
-
-    *content_start = -1;
-    while ((line = sgetline(tmp, &next_line))) {
-        char *key, *val, *c;
-
-        tmp += next_line;
-        pos += next_line;
-
-        if (strlen(line) == 0) {
-            /* end of header*/
-            break;
-        }
-
-        c = strchr(line, ':');
-        if (!c) break;
-
-        key = line;
-        *c = '\0';
-        val = c+2;
-
-        if (!strcmp(key, "Content-Encoding") && strstr(val, "gzip")) {
-            is_gzipped = TRUE;
-        }
-    }
-    *content_start = pos;
-    g_free(copy);
-    return is_gzipped;
-}
-#endif
-
-
-/*
- * Editor modelines
- *
- * Local Variables:
- * c-basic-offset: 4
- * tab-width: 8
- * indent-tabs-mode: nil
- * End:
- *
- * ex: set shiftwidth=4 tabstop=8 expandtab:
- * :indentSize=4:tabSize=8:noTabs=true:
- */
index 815e7b49a1d140900b296cae540a086ca6d6f3ee..f6da1021e39d8197a594b606c7304bb4c7191914 100644 (file)
@@ -79,11 +79,6 @@ typedef struct {
     GByteArray *data;
 } follow_record_t;
 
-#ifdef HAVE_LIBZ
-gboolean
-parse_http_header(char *data, size_t len, size_t *content_start);
-#endif
-
 #ifdef __cplusplus
 }
 #endif
index dced654025713f5951445dd8ff5b539b7ca4a528..5362bfc4defe33b376ce7bc3308dce99d3c700d6 100644 (file)
@@ -40,6 +40,9 @@
 #include "ui/gtk/main.h"
 #include "ui/gtk/follow_http.h"
 
+static frs_return_t
+follow_read_http_stream(follow_info_t *follow_info, follow_print_line_func follow_print, void *arg);
+
 static gboolean
 http_queue_packet_data(void *tapdata, packet_info *pinfo,
                       epan_dissect_t *edt _U_, const void *data)
@@ -103,6 +106,7 @@ follow_http_stream_cb(GtkWidget *w _U_, gpointer data _U_)
 
     follow_info = g_new0(follow_info_t, 1);
     follow_info->follow_type = FOLLOW_HTTP;
+    follow_info->read_stream = follow_read_http_stream;
 
     /* Create a new filter that matches all packets in the HTTP stream,
        and set the display filter entry accordingly */
@@ -248,9 +252,9 @@ follow_http_stream_cb(GtkWidget *w _U_, gpointer data _U_)
  * This might or might not be the reason why C arrays display
  * correctly but get extra blank lines very other line when printed.
  */
-frs_return_t
+static frs_return_t
 follow_read_http_stream(follow_info_t *follow_info,
-                       gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
+                       follow_print_line_func follow_print,
                        void *arg)
 {
     guint32 global_client_pos = 0, global_server_pos = 0;
@@ -283,7 +287,7 @@ follow_read_http_stream(follow_info_t *follow_info,
             buffer = (char *)g_memdup(follow_record->data->data,
                                      follow_record->data->len);
 
-            frs_return = follow_show(follow_info, print_line_fcn_p,
+            frs_return = follow_show(follow_info, follow_print,
                                      buffer,
                                      follow_record->data->len,
                                      follow_record->is_server, arg,
index 7c30b94f41cd59f7247bb6e44737a3d3c8b01d3a..c0235dc40e2f363f35f3fe53a5c43fdd14583533 100644 (file)
 #include <epan/dissectors/packet-ssl-utils.h>
 #endif
 
+static frs_return_t
+follow_read_ssl_stream(follow_info_t *follow_info, follow_print_line_func follow_print, void *arg);
+
+
 static gboolean
 ssl_queue_packet_data(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const void *ssl)
 {
@@ -156,6 +160,7 @@ follow_ssl_stream_cb(GtkWidget * w _U_, gpointer data _U_)
 
     follow_info = g_new0(follow_info_t, 1);
     follow_info->follow_type = FOLLOW_SSL;
+    follow_info->read_stream = follow_read_ssl_stream;
 
     /* Create a new filter that matches all packets in the SSL stream,
        and set the display filter entry accordingly */
@@ -300,9 +305,9 @@ follow_ssl_stream_cb(GtkWidget * w _U_, gpointer data _U_)
  * This might or might not be the reason why C arrays display
  * correctly but get extra blank lines very other line when printed.
  */
-frs_return_t
+static frs_return_t
 follow_read_ssl_stream(follow_info_t *follow_info,
-               gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
+               follow_print_line_func follow_print,
                void *arg)
 {
     guint32      global_client_pos = 0, global_server_pos = 0;
@@ -330,7 +335,7 @@ follow_read_ssl_stream(follow_info_t *follow_info,
             size_t nchars = rec->data.data_len;
             gchar *buffer = (gchar *)g_memdup(rec->data.data, (guint) nchars);
 
-            frs_return = follow_show(follow_info, print_line_fcn_p, buffer, nchars,
+            frs_return = follow_show(follow_info, follow_print, buffer, nchars,
                 rec->is_from_server, arg, global_pos,
                 &server_packet_count, &client_packet_count);
             g_free(buffer);
index 4a8d4e7b91ae892bdd265fa17505d57c222ad5dc..79ae6c7c09a9f8986d966c476d798b48e5c28006 100644 (file)
@@ -76,24 +76,12 @@ follow_read_stream(follow_info_t *follow_info,
            gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
            void *arg)
 {
-    switch(follow_info->follow_type) {
-
-    case FOLLOW_TCP :
-        return follow_read_tcp_stream(follow_info, print_line_fcn_p, arg);
-
-    case FOLLOW_UDP :
-        return follow_read_udp_stream(follow_info, print_line_fcn_p, arg);
-
-    case FOLLOW_SSL :
-        return follow_read_ssl_stream(follow_info, print_line_fcn_p, arg);
-
-    case FOLLOW_HTTP :
-        return follow_read_http_stream(follow_info, print_line_fcn_p, arg);
-
-    default :
+    if (follow_info->read_stream == NULL) {
         g_assert_not_reached();
         return (frs_return_t)0;
     }
+
+    return follow_info->read_stream(follow_info, print_line_fcn_p, arg);
 }
 
 gboolean
@@ -903,7 +891,7 @@ follow_destroy_cb(GtkWidget *w, gpointer data _U_)
 
 frs_return_t
 follow_show(follow_info_t *follow_info,
-            gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
+            follow_print_line_func follow_print,
             char *buffer, size_t nchars, gboolean is_from_server, void *arg,
             guint32 *global_pos, guint32 *server_packet_count,
             guint32 *client_packet_count)
@@ -917,7 +905,7 @@ follow_show(follow_info_t *follow_info,
     case SHOW_EBCDIC:
         /* If our native arch is ASCII, call: */
         EBCDIC_to_ASCII(buffer, (guint) nchars);
-        if (!(*print_line_fcn_p) (buffer, nchars, is_from_server, arg))
+        if (!follow_print(buffer, nchars, is_from_server, arg))
             return FRS_PRINT_ERROR;
         break;
 
@@ -925,7 +913,7 @@ follow_show(follow_info_t *follow_info,
         /* If our native arch is EBCDIC, call:
          * ASCII_TO_EBCDIC(buffer, nchars);
          */
-        if (!(*print_line_fcn_p) (buffer, nchars, is_from_server, arg))
+        if (!follow_print(buffer, nchars, is_from_server, arg))
             return FRS_PRINT_ERROR;
         break;
 
@@ -933,7 +921,7 @@ follow_show(follow_info_t *follow_info,
         /* Don't translate, no matter what the native arch
          * is.
          */
-        if (!(*print_line_fcn_p) (buffer, nchars, is_from_server, arg))
+        if (!follow_print(buffer, nchars, is_from_server, arg))
             return FRS_PRINT_ERROR;
         break;
 
@@ -980,7 +968,7 @@ follow_show(follow_info_t *follow_info,
             (*global_pos) += i;
             *cur++ = '\n';
             *cur = 0;
-            if (!(*print_line_fcn_p) (hexbuf, strlen(hexbuf), is_from_server, arg))
+            if (!follow_print(hexbuf, strlen(hexbuf), is_from_server, arg))
                 return FRS_PRINT_ERROR;
         }
         break;
@@ -990,7 +978,7 @@ follow_show(follow_info_t *follow_info,
         g_snprintf(initbuf, sizeof(initbuf), "char peer%d_%d[] = {\n",
                is_from_server ? 1 : 0,
                is_from_server ? (*server_packet_count)++ : (*client_packet_count)++);
-        if (!(*print_line_fcn_p) (initbuf, strlen(initbuf), is_from_server, arg))
+        if (!follow_print(initbuf, strlen(initbuf), is_from_server, arg))
             return FRS_PRINT_ERROR;
 
         while (current_pos < nchars) {
@@ -1022,7 +1010,7 @@ follow_show(follow_info_t *follow_info,
             (*global_pos) += i;
             hexbuf[cur++] = '\n';
             hexbuf[cur] = 0;
-            if (!(*print_line_fcn_p) (hexbuf, strlen(hexbuf), is_from_server, arg))
+            if (!follow_print(hexbuf, strlen(hexbuf), is_from_server, arg))
                 return FRS_PRINT_ERROR;
         }
         break;
index df8c77da461c856a724024770ad99c6fd0f5fff8..cb5252b6123badec1cef0c637629cb6e00ecc992 100644 (file)
 #include <gtk/gtk.h>
 #include <ui/follow.h>
 
-typedef struct {
+struct _follow_info;
+
+typedef gboolean (*follow_print_line_func)(char *, size_t, gboolean, void *);
+typedef frs_return_t (*follow_read_stream_func)(struct _follow_info *follow_info, follow_print_line_func follow_print, void *arg);
+
+typedef struct _follow_info {
     follow_type_t   follow_type;
     show_stream_t   show_stream;
     show_type_t     show_type;
@@ -47,6 +52,7 @@ typedef struct {
     guint           bytes_written[2]; /* Index with FROM_CLIENT or FROM_SERVER for readability. */
     guint           client_port;
     address         client_ip;
+    follow_read_stream_func read_stream;
 } follow_info_t;
 
 #define E_FOLLOW_INFO_KEY "follow_info_key"
@@ -62,7 +68,7 @@ void follow_stream(const gchar *title, follow_info_t *follow_info,
                    gchar *server_to_client_string,
                    gchar *client_to_server_string);
 frs_return_t follow_show(follow_info_t *follow_info,
-                         gboolean (*print_line)(char *, size_t, gboolean, void *),
+                         follow_print_line_func follow_print,
                          char *buffer, size_t nchars, gboolean is_server,
                          void *arg, guint32 *global_pos,
                          guint32 *server_packet_count,
@@ -70,11 +76,6 @@ frs_return_t follow_show(follow_info_t *follow_info,
 gboolean follow_add_to_gtk_text(char *buffer, size_t nchars, gboolean is_server,
                                  void *arg);
 
-frs_return_t follow_read_http_stream(follow_info_t *follow_info, gboolean (*print_line)(char *, size_t, gboolean, void *), void *arg);
-frs_return_t follow_read_tcp_stream(follow_info_t *follow_info, gboolean (*print_line)(char *, size_t, gboolean, void *), void *arg);
-frs_return_t follow_read_udp_stream(follow_info_t *follow_info, gboolean (*print_line)(char *, size_t, gboolean, void *), void *arg);
-frs_return_t follow_read_ssl_stream(follow_info_t *follow_info, gboolean (*print_line)(char *, size_t, gboolean, void *), void *arg);
-
 #endif /* __FOLLOW_STREAM_H__ */
 
 /*
index 111b5de0f14fc6e406245769ee8f104aa2a30a9c..c8683c0f6256fd4cf87e784571a888a38b4ef5f5 100644 (file)
@@ -56,6 +56,9 @@
 #include "ui/gtk/follow_stream.h"
 #include "ws_symbol_export.h"
 
+static frs_return_t
+follow_read_tcp_stream(follow_info_t *follow_info, follow_print_line_func follow_print, void *arg);
+
 /* With MSVC and a libwireshark.dll, we need a special declaration. */
 WS_DLL_PUBLIC FILE *data_out_file;
 
@@ -108,6 +111,7 @@ follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_)
 
     follow_info = g_new0(follow_info_t, 1);
     follow_info->follow_type = FOLLOW_TCP;
+    follow_info->read_stream = follow_read_tcp_stream;
 
     /* Create a new filter that matches all packets in the TCP stream,
        and set the display filter entry accordingly */
@@ -328,9 +332,9 @@ follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_)
  * This might or might not be the reason why C arrays display
  * correctly but get extra blank lines very other line when printed.
  */
-frs_return_t
+static frs_return_t
 follow_read_tcp_stream(follow_info_t *follow_info,
-    gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
+    follow_print_line_func follow_print,
     void *arg)
 {
     tcp_stream_chunk    sc;
@@ -401,7 +405,7 @@ follow_read_tcp_stream(follow_info_t *follow_info,
             bytes_read += nchars;
 
             if (!skip) {
-                frs_return = follow_show(follow_info, print_line_fcn_p, buffer,
+                frs_return = follow_show(follow_info, follow_print, buffer,
                                         nchars, is_server, arg, global_pos,
                                         &server_packet_count,
                                         &client_packet_count);
index 960fb2a662d1134b7245fd08be0462513ab28195..968fa5aeecfb1825f5ca710264bf2b79c713a4b4 100644 (file)
@@ -40,6 +40,9 @@
 #include "ui/gtk/main.h"
 #include "ui/gtk/follow_udp.h"
 
+static frs_return_t
+follow_read_udp_stream(follow_info_t *follow_info, follow_print_line_func follow_print, void *arg);
+
 static gboolean
 udp_queue_packet_data(void *tapdata, packet_info *pinfo,
                       epan_dissect_t *edt _U_, const void *data)
@@ -103,6 +106,7 @@ follow_udp_stream_cb(GtkWidget *w _U_, gpointer data _U_)
 
     follow_info = g_new0(follow_info_t, 1);
     follow_info->follow_type = FOLLOW_UDP;
+    follow_info->read_stream = follow_read_udp_stream;
 
     /* Create a new filter that matches all packets in the UDP stream,
        and set the display filter entry accordingly */
@@ -248,9 +252,9 @@ follow_udp_stream_cb(GtkWidget *w _U_, gpointer data _U_)
  * This might or might not be the reason why C arrays display
  * correctly but get extra blank lines very other line when printed.
  */
-frs_return_t
+static frs_return_t
 follow_read_udp_stream(follow_info_t *follow_info,
-                       gboolean (*print_line_fcn_p)(char *, size_t, gboolean, void *),
+                       follow_print_line_func follow_print,
                        void *arg)
 {
     guint32 global_client_pos = 0, global_server_pos = 0;
@@ -283,7 +287,7 @@ follow_read_udp_stream(follow_info_t *follow_info,
             buffer = (char *)g_memdup(follow_record->data->data,
                                      follow_record->data->len);
 
-            frs_return = follow_show(follow_info, print_line_fcn_p,
+            frs_return = follow_show(follow_info, follow_print,
                                      buffer,
                                      follow_record->data->len,
                                      follow_record->is_server, arg,