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>
export_object_smb.c
export_object_tftp.c
filters.c
- follow.c
help_url.c
iface_lists.c
io_graph_item.c
export_object_smb.c \
export_object_tftp.c \
filters.c \
- follow.c \
iface_lists.c \
io_graph_item.c \
language.c \
+++ /dev/null
-/* 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:
- */
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
#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)
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 */
* 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;
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,
#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)
{
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 */
* 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;
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);
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
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)
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;
/* 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;
/* 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;
(*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;
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) {
(*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;
#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;
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"
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,
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__ */
/*
#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;
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 */
* 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;
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);
#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)
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 */
* 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;
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,