diff options
author | Michael Mann <mmann78@netscape.net> | 2016-01-02 21:48:13 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-01-03 15:24:21 +0000 |
commit | 5dd1401291f3ce8b2ff39f9af409348027b940dc (patch) | |
tree | b426e41f059db65824aac8947348ef64809fe8e4 /ui | |
parent | 1fed5fef9a455171323e08f46f2dd8c1b834df79 (diff) |
Cleanup follow stream code
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>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ui/Makefile.common | 1 | ||||
-rw-r--r-- | ui/follow.c | 122 | ||||
-rw-r--r-- | ui/follow.h | 5 | ||||
-rw-r--r-- | ui/gtk/follow_http.c | 10 | ||||
-rw-r--r-- | ui/gtk/follow_ssl.c | 11 | ||||
-rw-r--r-- | ui/gtk/follow_stream.c | 32 | ||||
-rw-r--r-- | ui/gtk/follow_stream.h | 15 | ||||
-rw-r--r-- | ui/gtk/follow_tcp.c | 10 | ||||
-rw-r--r-- | ui/gtk/follow_udp.c | 10 |
10 files changed, 47 insertions, 170 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index f0a496a387..d68079062e 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -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 diff --git a/ui/Makefile.common b/ui/Makefile.common index fd17475a36..a4c689f773 100644 --- a/ui/Makefile.common +++ b/ui/Makefile.common @@ -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 index 8fc6f852d1..0000000000 --- a/ui/follow.c +++ /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: - */ diff --git a/ui/follow.h b/ui/follow.h index 815e7b49a1..f6da1021e3 100644 --- a/ui/follow.h +++ b/ui/follow.h @@ -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 diff --git a/ui/gtk/follow_http.c b/ui/gtk/follow_http.c index dced654025..5362bfc4de 100644 --- a/ui/gtk/follow_http.c +++ b/ui/gtk/follow_http.c @@ -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, diff --git a/ui/gtk/follow_ssl.c b/ui/gtk/follow_ssl.c index 7c30b94f41..c0235dc40e 100644 --- a/ui/gtk/follow_ssl.c +++ b/ui/gtk/follow_ssl.c @@ -61,6 +61,10 @@ #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); diff --git a/ui/gtk/follow_stream.c b/ui/gtk/follow_stream.c index 4a8d4e7b91..79ae6c7c09 100644 --- a/ui/gtk/follow_stream.c +++ b/ui/gtk/follow_stream.c @@ -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; diff --git a/ui/gtk/follow_stream.h b/ui/gtk/follow_stream.h index df8c77da46..cb5252b612 100644 --- a/ui/gtk/follow_stream.h +++ b/ui/gtk/follow_stream.h @@ -27,7 +27,12 @@ #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__ */ /* diff --git a/ui/gtk/follow_tcp.c b/ui/gtk/follow_tcp.c index 111b5de0f1..c8683c0f62 100644 --- a/ui/gtk/follow_tcp.c +++ b/ui/gtk/follow_tcp.c @@ -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); diff --git a/ui/gtk/follow_udp.c b/ui/gtk/follow_udp.c index 960fb2a662..968fa5aeec 100644 --- a/ui/gtk/follow_udp.c +++ b/ui/gtk/follow_udp.c @@ -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, |