2000-08-03 12:44:40 +00:00
|
|
|
/* follow_dlg.c
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-08-03 12:44:40 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2002-01-11 07:40:32 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2000-08-03 12:44:40 +00:00
|
|
|
* Copyright 2000 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-08-03 12:44:40 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-08-03 12:44:40 +00:00
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2002-09-07 10:01:55 +00:00
|
|
|
#include <stdio.h>
|
2000-08-03 12:44:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-09-12 06:28:02 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2002-01-18 07:25:22 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2004-07-09 23:02:38 +00:00
|
|
|
#include "isprint.h"
|
|
|
|
|
2005-11-06 22:43:25 +00:00
|
|
|
#include "file_util.h"
|
2000-11-21 23:54:10 +00:00
|
|
|
#include "color.h"
|
2004-07-24 00:35:13 +00:00
|
|
|
#include "colors.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
#include "file.h"
|
|
|
|
#include "follow_dlg.h"
|
2005-02-09 23:38:00 +00:00
|
|
|
#include <epan/follow.h>
|
2000-08-03 12:44:40 +00:00
|
|
|
#include "dlg_utils.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "main.h"
|
2004-02-11 01:23:25 +00:00
|
|
|
#include "alert_box.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
#include "simple_dialog.h"
|
2004-07-18 18:06:47 +00:00
|
|
|
#include <epan/dissectors/packet-ipv6.h>
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2004-08-06 19:57:49 +00:00
|
|
|
#include <epan/addr_resolv.h>
|
2004-09-10 22:59:37 +00:00
|
|
|
#include <epan/charsets.h>
|
2006-02-12 21:52:18 +00:00
|
|
|
#include "tempfile.h"
|
2005-08-20 12:09:48 +00:00
|
|
|
#include "gui_utils.h"
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/epan_dissect.h>
|
2002-09-09 20:39:01 +00:00
|
|
|
#include <epan/filesystem.h>
|
2002-11-10 11:00:29 +00:00
|
|
|
#include "compat_macros.h"
|
2004-09-29 00:52:45 +00:00
|
|
|
#include <epan/ipproto.h>
|
2004-05-27 21:55:59 +00:00
|
|
|
#include "print_mswin.h"
|
2004-06-17 16:35:26 +00:00
|
|
|
#include "font_utils.h"
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2006-02-07 10:22:41 +00:00
|
|
|
/* This is backwards-compatibility code for old versions of GTK+ (2.2.1 and
|
|
|
|
* earlier). It defines the new wrap behavior (unknown in earlier versions)
|
|
|
|
* as the old (slightly buggy) wrap behavior.
|
|
|
|
*/
|
|
|
|
#ifndef GTK_WRAP_WORD_CHAR
|
|
|
|
#define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD
|
|
|
|
#endif
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Show Stream */
|
|
|
|
typedef enum {
|
|
|
|
FROM_CLIENT,
|
|
|
|
FROM_SERVER,
|
|
|
|
BOTH_HOSTS
|
|
|
|
} show_stream_t;
|
|
|
|
|
|
|
|
/* Show Type */
|
|
|
|
typedef enum {
|
|
|
|
SHOW_ASCII,
|
|
|
|
SHOW_EBCDIC,
|
2003-03-06 04:23:51 +00:00
|
|
|
SHOW_HEXDUMP,
|
2005-02-02 08:50:40 +00:00
|
|
|
SHOW_CARRAY,
|
|
|
|
SHOW_RAW
|
2000-08-09 05:18:45 +00:00
|
|
|
} show_type_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
show_stream_t show_stream;
|
|
|
|
show_type_t show_type;
|
|
|
|
char data_out_filename[128 + 1];
|
|
|
|
GtkWidget *text;
|
|
|
|
GtkWidget *ascii_bt;
|
|
|
|
GtkWidget *ebcdic_bt;
|
|
|
|
GtkWidget *hexdump_bt;
|
2003-03-06 04:23:51 +00:00
|
|
|
GtkWidget *carray_bt;
|
2005-02-02 08:50:40 +00:00
|
|
|
GtkWidget *raw_bt;
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *follow_save_as_w;
|
2000-08-11 22:18:22 +00:00
|
|
|
gboolean is_ipv6;
|
2003-04-06 22:41:34 +00:00
|
|
|
char *filter_out_filter;
|
|
|
|
GtkWidget *filter_te;
|
|
|
|
GtkWidget *streamwindow;
|
2000-08-09 05:18:45 +00:00
|
|
|
} follow_info_t;
|
|
|
|
|
|
|
|
static void follow_destroy_cb(GtkWidget * win, gpointer data);
|
|
|
|
static void follow_charset_toggle_cb(GtkWidget * w, gpointer parent_w);
|
|
|
|
static void follow_load_text(follow_info_t *follow_info);
|
2003-04-06 22:41:34 +00:00
|
|
|
static void follow_filter_out_stream(GtkWidget * w, gpointer parent_w);
|
2000-08-09 05:18:45 +00:00
|
|
|
static void follow_print_stream(GtkWidget * w, gpointer parent_w);
|
|
|
|
static void follow_save_as_cmd_cb(GtkWidget * w, gpointer data);
|
2004-03-27 11:16:58 +00:00
|
|
|
static void follow_save_as_ok_cb(GtkWidget * w, gpointer fs);
|
2000-08-09 05:18:45 +00:00
|
|
|
static void follow_save_as_destroy_cb(GtkWidget * win, gpointer user_data);
|
|
|
|
static void follow_stream_om_both(GtkWidget * w, gpointer data);
|
|
|
|
static void follow_stream_om_client(GtkWidget * w, gpointer data);
|
|
|
|
static void follow_stream_om_server(GtkWidget * w, gpointer data);
|
|
|
|
|
|
|
|
|
2004-05-09 10:03:41 +00:00
|
|
|
/* With MSVC and a libethereal.dll, we need a special declaration. */
|
|
|
|
ETH_VAR_IMPORT FILE *data_out_file;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
#define E_FOLLOW_INFO_KEY "follow_info_key"
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-09-08 10:59:21 +00:00
|
|
|
/* List of "follow_info_t" structures for all "Follow TCP Stream" windows,
|
|
|
|
so we can redraw them all if the colors or font changes. */
|
|
|
|
static GList *follow_infos;
|
|
|
|
|
|
|
|
/* Add a "follow_info_t" structure to the list. */
|
|
|
|
static void
|
|
|
|
remember_follow_info(follow_info_t *follow_info)
|
|
|
|
{
|
|
|
|
follow_infos = g_list_append(follow_infos, follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a "follow_info_t" structure from the list. */
|
|
|
|
static void
|
|
|
|
forget_follow_info(follow_info_t *follow_info)
|
|
|
|
{
|
|
|
|
follow_infos = g_list_remove(follow_infos, follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_redraw(gpointer data, gpointer user_data _U_)
|
2000-09-08 10:59:21 +00:00
|
|
|
{
|
|
|
|
follow_load_text((follow_info_t *)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw the text in all "Follow TCP Stream" windows. */
|
|
|
|
void
|
|
|
|
follow_redraw_all(void)
|
|
|
|
{
|
|
|
|
g_list_foreach(follow_infos, follow_redraw, NULL);
|
|
|
|
}
|
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
/* Follow the TCP stream, if any, to which the last packet that we called
|
|
|
|
a dissection routine on belongs (this might be the most recently
|
|
|
|
selected packet, or it might be the last packet in the file). */
|
|
|
|
void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_cb(GtkWidget * w, gpointer data _U_)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-17 07:56:44 +00:00
|
|
|
GtkWidget *streamwindow, *vbox, *txt_scrollw, *text, *filter_te;
|
2004-02-22 23:39:07 +00:00
|
|
|
GtkWidget *hbox, *button_hbox, *button, *radio_bt;
|
|
|
|
GtkWidget *stream_fr, *stream_vb;
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *stream_om, *stream_menu, *stream_mi;
|
2004-02-22 23:39:07 +00:00
|
|
|
GtkTooltips *tooltips;
|
|
|
|
int tmp_fd;
|
2000-08-09 05:18:45 +00:00
|
|
|
gchar *follow_filter;
|
2003-04-06 22:41:34 +00:00
|
|
|
const gchar *previous_filter;
|
2004-03-13 14:07:14 +00:00
|
|
|
int filter_out_filter_len;
|
2001-04-02 09:41:56 +00:00
|
|
|
const char *hostname0, *hostname1;
|
2000-08-09 05:18:45 +00:00
|
|
|
char *port0, *port1;
|
|
|
|
char string[128];
|
|
|
|
follow_tcp_stats_t stats;
|
|
|
|
follow_info_t *follow_info;
|
|
|
|
|
|
|
|
/* we got tcp so we can follow */
|
2001-11-21 23:16:26 +00:00
|
|
|
if (cfile.edt->pi.ipproto != 6) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2000-08-09 05:18:45 +00:00
|
|
|
"Error following stream. Please make\n"
|
|
|
|
"sure you have a TCP packet selected.");
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info = g_new0(follow_info_t, 1);
|
|
|
|
|
|
|
|
/* Create a temporary file into which to dump the reassembled data
|
|
|
|
from the TCP stream, and set "data_out_file" to refer to it, so
|
|
|
|
that the TCP code will write to it.
|
|
|
|
|
|
|
|
XXX - it might be nicer to just have the TCP code directly
|
|
|
|
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");
|
|
|
|
|
|
|
|
if (tmp_fd == -1) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2000-08-09 05:18:45 +00:00
|
|
|
"Could not create temporary file %s: %s",
|
|
|
|
follow_info->data_out_filename, strerror(errno));
|
|
|
|
g_free(follow_info);
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
data_out_file = fdopen(tmp_fd, "wb");
|
|
|
|
if (data_out_file == NULL) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2000-08-09 05:18:45 +00:00
|
|
|
"Could not create temporary file %s: %s",
|
|
|
|
follow_info->data_out_filename, strerror(errno));
|
2005-11-06 22:43:25 +00:00
|
|
|
eth_close(tmp_fd);
|
2000-08-09 05:18:45 +00:00
|
|
|
unlink(follow_info->data_out_filename);
|
|
|
|
g_free(follow_info);
|
|
|
|
return;
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Create a new filter that matches all packets in the TCP stream,
|
|
|
|
and set the display filter entry accordingly */
|
|
|
|
reset_tcp_reassembly();
|
2001-11-21 23:16:26 +00:00
|
|
|
follow_filter = build_follow_filter(&cfile.edt->pi);
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Set the display filter entry accordingly */
|
2002-11-10 11:00:29 +00:00
|
|
|
filter_te = OBJECT_GET_DATA(w, E_DFILTER_TE_KEY);
|
2003-04-06 22:41:34 +00:00
|
|
|
|
|
|
|
/* needed in follow_filter_out_stream(), is there a better way? */
|
|
|
|
follow_info->filter_te = filter_te;
|
|
|
|
|
|
|
|
/* save previous filter, const since we're not supposed to alter */
|
|
|
|
previous_filter =
|
|
|
|
(const gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
|
|
|
|
|
|
|
|
/* 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 ? */
|
2004-03-13 14:07:14 +00:00
|
|
|
filter_out_filter_len = strlen(follow_filter) + strlen(previous_filter) + 16;
|
|
|
|
follow_info->filter_out_filter = (gchar *)g_malloc(filter_out_filter_len);
|
2003-04-06 22:41:34 +00:00
|
|
|
|
|
|
|
/* append the negation */
|
|
|
|
if(strlen(previous_filter)) {
|
2004-03-13 14:07:14 +00:00
|
|
|
g_snprintf(follow_info->filter_out_filter, filter_out_filter_len,
|
|
|
|
"%s and !(%s)", previous_filter, follow_filter);
|
2003-04-06 22:41:34 +00:00
|
|
|
} else {
|
2004-03-13 14:07:14 +00:00
|
|
|
g_snprintf(follow_info->filter_out_filter, filter_out_filter_len,
|
|
|
|
"!(%s)", follow_filter);
|
2003-04-06 22:41:34 +00:00
|
|
|
}
|
|
|
|
|
2004-02-23 22:48:52 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(filter_te), follow_filter);
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2004-02-23 22:48:52 +00:00
|
|
|
/* Run the display filter so it goes in effect - even if it's the
|
|
|
|
same as the previous display filter. */
|
|
|
|
main_filter_packets(&cfile, follow_filter, TRUE);
|
2000-08-03 12:44:40 +00:00
|
|
|
|
Clean up the handling of filter strings:
have "filter_packets()" make a copy of the filter string handed
to it, as it may save the filter string in the "capture_file"
structure, and the caller of "filter_packets()" shouldn't have
to worry about the string it passed to "filter_packets()" being
stashed away somewhere so that it can't just free that string or
change it;
have callers of "filter_packets()" free up the string they
handed to it, if the string was allocated and they're done with
it;
plug some memory leaks in "match_selected_cb_do()".
Check for an illegal "action" argument being passed to
"match_selected_cb_do()".
Move some keys out of "keys.h" into "gtk/main.c", as they're only used
in "gtk/main.c".
Make the pointer to the filter list a data item for the combo box, as
it's a copy of the list of strings for the combo box, rather than
attaching it to the widgets that activate the filter (a pointer to the
combo box *itself* is a data item for those widgets).
In "filter_activate_cb()", make a copy of the text from the text entry
field as soon as we fetch it, and use that copy. Free that copy if
we didn't add the filter to the filter list.
Don't make a copy of the entire filter list and use that to set the
combo box's list of items - just use the list itself. Also, when the
list is changed, make the new value the data for the combo box (the list
pointer will actually not be changed, because we happen to be using
"g_list_append()", but let's not rely on that).
svn path=/trunk/; revision=5368
2002-05-03 03:24:47 +00:00
|
|
|
/* Free the filter string, as we're done with it. */
|
|
|
|
g_free(follow_filter);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* The data_out_file should now be full of the streams information */
|
|
|
|
fclose(data_out_file);
|
|
|
|
|
|
|
|
/* The data_out_filename file now has all the text that was in the session */
|
2004-05-22 19:56:19 +00:00
|
|
|
streamwindow = dlg_window_new("Follow TCP stream");
|
2003-04-06 22:41:34 +00:00
|
|
|
|
|
|
|
/* needed in follow_filter_out_stream(), is there a better way? */
|
|
|
|
follow_info->streamwindow = streamwindow;
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_widget_set_name(streamwindow, "TCP stream window");
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(streamwindow), DEF_WIDTH, DEF_HEIGHT);
|
2004-05-27 21:55:59 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(streamwindow), 6);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* setup the container */
|
2004-07-25 08:53:38 +00:00
|
|
|
tooltips = gtk_tooltips_new ();
|
2004-02-22 23:39:07 +00:00
|
|
|
|
2004-05-27 21:55:59 +00:00
|
|
|
vbox = gtk_vbox_new(FALSE, 6);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(streamwindow), vbox);
|
|
|
|
|
2004-02-22 23:39:07 +00:00
|
|
|
/* content frame */
|
|
|
|
if (incomplete_tcp_stream) {
|
2004-07-25 08:53:38 +00:00
|
|
|
stream_fr = gtk_frame_new("Stream Content (incomplete)");
|
2004-02-22 23:39:07 +00:00
|
|
|
} else {
|
2004-07-25 08:53:38 +00:00
|
|
|
stream_fr = gtk_frame_new("Stream Content");
|
2004-02-22 23:39:07 +00:00
|
|
|
}
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), stream_fr);
|
|
|
|
gtk_widget_show(stream_fr);
|
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
stream_vb = gtk_vbox_new(FALSE, 6);
|
2004-05-27 21:55:59 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER(stream_vb) , 6);
|
2004-02-22 23:39:07 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(stream_fr), stream_vb);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* create a scrolled window for the text */
|
2002-01-11 07:40:32 +00:00
|
|
|
txt_scrollw = scrolled_window_new(NULL, NULL);
|
2004-02-06 19:19:12 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
|
|
|
|
GTK_SHADOW_IN);
|
2004-02-06 19:19:12 +00:00
|
|
|
#endif
|
2004-02-22 23:39:07 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(stream_vb), txt_scrollw, TRUE, TRUE, 0);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* create a text box */
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
text = gtk_text_new(NULL, NULL);
|
|
|
|
gtk_text_set_editable(GTK_TEXT(text), FALSE);
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
text = gtk_text_view_new();
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
|
2006-01-03 23:45:58 +00:00
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
|
2002-11-03 17:38:45 +00:00
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(txt_scrollw), text);
|
|
|
|
follow_info->text = text;
|
|
|
|
|
2004-02-22 23:39:07 +00:00
|
|
|
|
|
|
|
/* stream hbox */
|
2000-08-09 05:18:45 +00:00
|
|
|
hbox = gtk_hbox_new(FALSE, 1);
|
2004-02-22 23:39:07 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(stream_vb), hbox, FALSE, FALSE, 0);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-02-22 23:39:07 +00:00
|
|
|
/* Create Save As Button */
|
2004-07-25 08:53:38 +00:00
|
|
|
button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_SAVE_AS);
|
2004-02-22 23:39:07 +00:00
|
|
|
SIGNAL_CONNECT(button, "clicked", follow_save_as_cmd_cb, follow_info);
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, button, "Save the content as currently displayed ", NULL);
|
2004-02-22 23:39:07 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* Create Print Button */
|
2004-07-25 08:53:38 +00:00
|
|
|
button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_PRINT);
|
2004-02-22 23:39:07 +00:00
|
|
|
SIGNAL_CONNECT(button, "clicked", follow_print_stream, follow_info);
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, button, "Print the content as currently displayed", NULL);
|
2004-02-22 23:39:07 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Stream to show */
|
|
|
|
follow_tcp_stats(&stats);
|
|
|
|
|
2000-08-11 22:18:22 +00:00
|
|
|
if (stats.is_ipv6) {
|
|
|
|
struct e_in6_addr ipaddr;
|
|
|
|
memcpy(&ipaddr, stats.ip_address[0], 16);
|
|
|
|
hostname0 = get_hostname6(&ipaddr);
|
|
|
|
memcpy(&ipaddr, stats.ip_address[0], 16);
|
|
|
|
hostname1 = get_hostname6(&ipaddr);
|
|
|
|
} else {
|
|
|
|
guint32 ipaddr;
|
|
|
|
memcpy(&ipaddr, stats.ip_address[0], 4);
|
|
|
|
hostname0 = get_hostname(ipaddr);
|
|
|
|
memcpy(&ipaddr, stats.ip_address[1], 4);
|
|
|
|
hostname1 = get_hostname(ipaddr);
|
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
port0 = get_tcp_port(stats.tcp_port[0]);
|
|
|
|
port1 = get_tcp_port(stats.tcp_port[1]);
|
|
|
|
|
2000-08-11 22:18:22 +00:00
|
|
|
follow_info->is_ipv6 = stats.is_ipv6;
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
stream_om = gtk_option_menu_new();
|
|
|
|
stream_menu = gtk_menu_new();
|
|
|
|
|
2005-02-03 20:44:19 +00:00
|
|
|
/* Both Stream Directions */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(string, sizeof(string),
|
2000-08-09 05:18:45 +00:00
|
|
|
"Entire conversation (%u bytes)",
|
|
|
|
stats.bytes_written[0] + stats.bytes_written[1]);
|
|
|
|
stream_mi = gtk_menu_item_new_with_label(string);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(stream_mi, "activate", follow_stream_om_both,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_menu_append(GTK_MENU(stream_menu), stream_mi);
|
|
|
|
gtk_widget_show(stream_mi);
|
2000-08-09 05:26:11 +00:00
|
|
|
follow_info->show_stream = BOTH_HOSTS;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Host 0 --> Host 1 */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(string, sizeof(string), "%s:%s --> %s:%s (%u bytes)",
|
2000-08-09 05:18:45 +00:00
|
|
|
hostname0, port0, hostname1, port1,
|
|
|
|
stats.bytes_written[0]);
|
|
|
|
stream_mi = gtk_menu_item_new_with_label(string);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(stream_mi, "activate", follow_stream_om_client,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_menu_append(GTK_MENU(stream_menu), stream_mi);
|
|
|
|
gtk_widget_show(stream_mi);
|
|
|
|
|
|
|
|
/* Host 1 --> Host 0 */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(string, sizeof(string), "%s:%s --> %s:%s (%u bytes)",
|
2000-08-09 05:18:45 +00:00
|
|
|
hostname1, port1, hostname0, port0,
|
|
|
|
stats.bytes_written[1]);
|
|
|
|
stream_mi = gtk_menu_item_new_with_label(string);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(stream_mi, "activate", follow_stream_om_server,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_menu_append(GTK_MENU(stream_menu), stream_mi);
|
|
|
|
gtk_widget_show(stream_mi);
|
|
|
|
|
|
|
|
gtk_option_menu_set_menu(GTK_OPTION_MENU(stream_om), stream_menu);
|
|
|
|
/* Set history to 0th item, i.e., the first item. */
|
|
|
|
gtk_option_menu_set_history(GTK_OPTION_MENU(stream_om), 0);
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, stream_om,
|
|
|
|
"Select the stream direction to display", NULL);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), stream_om, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* ASCII radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(NULL, "ASCII");
|
2005-02-03 20:44:19 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, radio_bt, "Stream data output in \"ASCII\" format", NULL);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), TRUE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->ascii_bt = radio_bt;
|
|
|
|
follow_info->show_type = SHOW_ASCII;
|
|
|
|
|
|
|
|
/* EBCDIC radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"EBCDIC");
|
2005-02-03 20:44:19 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, radio_bt, "Stream data output in \"EBCDIC\" format", NULL);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->ebcdic_bt = radio_bt;
|
|
|
|
|
|
|
|
/* HEX DUMP radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"Hex Dump");
|
2005-02-03 20:44:19 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, radio_bt, "Stream data output in \"Hexdump\" format", NULL);
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
2002-11-10 11:00:29 +00:00
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->hexdump_bt = radio_bt;
|
|
|
|
|
2003-03-06 04:23:51 +00:00
|
|
|
/* C Array radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"C Arrays");
|
2005-02-03 20:44:19 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, radio_bt, "Stream data output in \"C Array\" format", NULL);
|
2003-03-06 04:23:51 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
|
|
|
follow_info->carray_bt = radio_bt;
|
|
|
|
|
2005-02-02 08:50:40 +00:00
|
|
|
/* Raw radio button */
|
|
|
|
radio_bt = gtk_radio_button_new_with_label(gtk_radio_button_group
|
|
|
|
(GTK_RADIO_BUTTON(radio_bt)),
|
|
|
|
"Raw");
|
2005-02-03 20:44:19 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, radio_bt, "Stream data output in \"Raw\" (binary) format. "
|
|
|
|
"As this contains non printable characters, the screen output will be in ASCII format", NULL);
|
2005-02-02 08:50:40 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_bt), FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), radio_bt, FALSE, FALSE, 0);
|
|
|
|
SIGNAL_CONNECT(radio_bt, "toggled", follow_charset_toggle_cb,
|
|
|
|
follow_info);
|
|
|
|
follow_info->raw_bt = radio_bt;
|
|
|
|
|
2004-02-22 23:39:07 +00:00
|
|
|
/* button hbox */
|
|
|
|
button_hbox = gtk_hbutton_box_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), button_hbox, FALSE, FALSE, 0);
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END);
|
|
|
|
gtk_button_box_set_spacing(GTK_BUTTON_BOX(button_hbox), 5);
|
2004-02-22 23:39:07 +00:00
|
|
|
|
|
|
|
/* Create exclude stream button */
|
|
|
|
button = gtk_button_new_with_label("Filter out this stream");
|
|
|
|
SIGNAL_CONNECT(button, "clicked", follow_filter_out_stream, follow_info);
|
2004-07-25 08:53:38 +00:00
|
|
|
gtk_tooltips_set_tip (tooltips, button,
|
2004-02-22 23:39:07 +00:00
|
|
|
"Build a display filter which cuts this stream from the capture", NULL);
|
|
|
|
gtk_box_pack_start(GTK_BOX(button_hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Create Close Button */
|
2004-07-25 08:53:38 +00:00
|
|
|
button = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
|
|
|
|
gtk_tooltips_set_tip (tooltips, button,
|
|
|
|
"Close the dialog and keep the current display filter", NULL);
|
2004-02-22 23:39:07 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(button_hbox), button, FALSE, FALSE, 0);
|
2004-07-25 08:53:38 +00:00
|
|
|
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
window_set_cancel_button(streamwindow, button, window_cancel_button_cb);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
/* Tuck away the follow_info object into the window */
|
2002-11-10 11:00:29 +00:00
|
|
|
OBJECT_SET_DATA(streamwindow, E_FOLLOW_INFO_KEY, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
follow_load_text(follow_info);
|
2000-09-08 10:59:21 +00:00
|
|
|
remember_follow_info(follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
data_out_file = NULL;
|
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
SIGNAL_CONNECT(streamwindow, "delete_event", window_delete_event_cb, NULL);
|
2004-05-26 03:49:24 +00:00
|
|
|
SIGNAL_CONNECT(streamwindow, "destroy", follow_destroy_cb, NULL);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Make sure this widget gets destroyed if we quit the main loop,
|
|
|
|
so that if we exit, we clean up any temporary files we have
|
|
|
|
for "Follow TCP Stream" windows. */
|
|
|
|
gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(streamwindow));
|
2004-05-26 03:49:24 +00:00
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_widget_show_all(streamwindow);
|
2004-05-26 03:49:24 +00:00
|
|
|
window_present(streamwindow);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The destroy call back has the responsibility of
|
2003-04-06 22:41:34 +00:00
|
|
|
* unlinking the temporary file
|
|
|
|
* and freeing the filter_out_filter */
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_destroy_cb(GtkWidget *w, gpointer data _U_)
|
2000-08-09 05:18:45 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info;
|
2004-07-25 08:53:38 +00:00
|
|
|
int i;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2002-11-10 11:00:29 +00:00
|
|
|
follow_info = OBJECT_GET_DATA(w, E_FOLLOW_INFO_KEY);
|
2004-05-27 23:09:09 +00:00
|
|
|
i = unlink(follow_info->data_out_filename);
|
2004-07-25 08:53:38 +00:00
|
|
|
if(i != 0) {
|
|
|
|
g_warning("Follow: Couldn't remove temporary file: \"%s\", errno: %s (%u)",
|
|
|
|
follow_info->data_out_filename, strerror(errno), errno);
|
|
|
|
}
|
2003-04-06 22:41:34 +00:00
|
|
|
g_free(follow_info->filter_out_filter);
|
2000-09-08 10:59:21 +00:00
|
|
|
forget_follow_info(follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
g_free(follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX - can I emulate follow_charset_toggle_cb() instead of having
|
2004-11-16 08:21:32 +00:00
|
|
|
* 3 different functions here?
|
|
|
|
* That might not be a bad idea, as it might mean we only reload
|
|
|
|
* the window once, not twice - see follow_charset_toggle_cb()
|
|
|
|
* for an explanation. */
|
2000-08-09 05:18:45 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_om_both(GtkWidget *w _U_, gpointer data)
|
2000-08-09 05:18:45 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
follow_info->show_stream = BOTH_HOSTS;
|
|
|
|
follow_load_text(follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_om_client(GtkWidget *w _U_, gpointer data)
|
2000-08-09 05:18:45 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
follow_info->show_stream = FROM_CLIENT;
|
|
|
|
follow_load_text(follow_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_stream_om_server(GtkWidget *w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
follow_info->show_stream = FROM_SERVER;
|
|
|
|
follow_load_text(follow_info);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-16 08:21:32 +00:00
|
|
|
/* Handles the display style toggling */
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_charset_toggle_cb(GtkWidget * w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2004-11-16 08:21:32 +00:00
|
|
|
follow_info_t *follow_info = data;
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-11-16 08:21:32 +00:00
|
|
|
/*
|
|
|
|
* A radio button toggles when it goes on and when it goes
|
|
|
|
* off, so when you click a radio button two signals are
|
|
|
|
* delivered. We only want to reprocess the display once,
|
|
|
|
* so we do it only when the button goes on.
|
|
|
|
*/
|
|
|
|
if (GTK_TOGGLE_BUTTON(w)->active) {
|
|
|
|
if (w == follow_info->ebcdic_bt)
|
|
|
|
follow_info->show_type = SHOW_EBCDIC;
|
|
|
|
else if (w == follow_info->hexdump_bt)
|
|
|
|
follow_info->show_type = SHOW_HEXDUMP;
|
|
|
|
else if (w == follow_info->carray_bt)
|
|
|
|
follow_info->show_type = SHOW_CARRAY;
|
|
|
|
else if (w == follow_info->ascii_bt)
|
|
|
|
follow_info->show_type = SHOW_ASCII;
|
2005-02-02 08:50:40 +00:00
|
|
|
else if (w == follow_info->raw_bt)
|
|
|
|
follow_info->show_type = SHOW_RAW;
|
2004-11-16 08:21:32 +00:00
|
|
|
follow_load_text(follow_info);
|
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FLT_BUF_SIZE 1024
|
2004-01-25 01:53:24 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FRS_OK,
|
|
|
|
FRS_OPEN_ERROR,
|
|
|
|
FRS_READ_ERROR,
|
|
|
|
FRS_PRINT_ERROR
|
|
|
|
} frs_return_t;
|
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
/*
|
|
|
|
* XXX - the routine pointed to by "print_line" 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
|
|
|
|
* genuinely expect to be handed a line (if, for example, it's using
|
|
|
|
* some OS or desktop environment's printing API, and that API expects
|
|
|
|
* to be handed lines), "follow_print_text()" should probably accumulate
|
|
|
|
* lines in a buffer and hand them "print_line()". (If there's a
|
|
|
|
* complete line in a buffer - i.e., there's nothing of the line in
|
|
|
|
* the previous buffer or the next buffer - it can just hand that to
|
|
|
|
* "print_line()" after filtering out non-printables, as an
|
|
|
|
* optimization.)
|
|
|
|
*
|
|
|
|
* This might or might not be the reason why C arrays display
|
|
|
|
* correctly but get extra blank lines very other line when printed.
|
|
|
|
*/
|
2004-01-25 01:53:24 +00:00
|
|
|
static frs_return_t
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_read_stream(follow_info_t *follow_info,
|
2005-02-02 10:28:51 +00:00
|
|
|
gboolean (*print_line) (char *, size_t, gboolean, void *),
|
2004-07-25 08:53:38 +00:00
|
|
|
void *arg)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
tcp_stream_chunk sc;
|
2000-08-11 22:18:22 +00:00
|
|
|
int bcount, iplen;
|
|
|
|
guint8 client_addr[MAX_IPADDR_LEN];
|
2000-08-09 05:18:45 +00:00
|
|
|
guint16 client_port = 0;
|
|
|
|
gboolean is_server;
|
2004-04-09 19:44:27 +00:00
|
|
|
guint32 current_pos, global_client_pos = 0, global_server_pos = 0;
|
|
|
|
guint32 *global_pos;
|
2000-08-09 05:18:45 +00:00
|
|
|
gboolean skip;
|
2003-03-06 04:23:51 +00:00
|
|
|
gchar initbuf[256];
|
|
|
|
guint32 server_packet_count = 0;
|
|
|
|
guint32 client_packet_count = 0;
|
2004-01-25 01:53:24 +00:00
|
|
|
char buffer[FLT_BUF_SIZE];
|
2004-04-09 19:44:27 +00:00
|
|
|
size_t nchars;
|
2005-02-02 10:28:51 +00:00
|
|
|
static const gchar hexchars[16] = "0123456789abcdef";
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-08-11 22:18:22 +00:00
|
|
|
iplen = (follow_info->is_ipv6) ? 16 : 4;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2005-11-06 22:43:25 +00:00
|
|
|
data_out_file = eth_fopen(follow_info->data_out_filename, "rb");
|
2004-01-25 01:53:24 +00:00
|
|
|
if (data_out_file == NULL) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2004-01-25 01:53:24 +00:00
|
|
|
"Could not open temporary file %s: %s", follow_info->data_out_filename,
|
|
|
|
strerror(errno));
|
|
|
|
return FRS_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fread(&sc, 1, sizeof(sc), data_out_file)) {
|
|
|
|
if (client_port == 0) {
|
|
|
|
memcpy(client_addr, sc.src_addr, iplen);
|
|
|
|
client_port = sc.src_port;
|
|
|
|
}
|
|
|
|
skip = FALSE;
|
|
|
|
if (memcmp(client_addr, sc.src_addr, iplen) == 0 &&
|
|
|
|
client_port == sc.src_port) {
|
|
|
|
is_server = FALSE;
|
|
|
|
global_pos = &global_client_pos;
|
|
|
|
if (follow_info->show_stream == FROM_SERVER) {
|
|
|
|
skip = TRUE;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
is_server = TRUE;
|
|
|
|
global_pos = &global_server_pos;
|
|
|
|
if (follow_info->show_stream == FROM_CLIENT) {
|
|
|
|
skip = TRUE;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
while (sc.dlen > 0) {
|
|
|
|
bcount = (sc.dlen < FLT_BUF_SIZE) ? sc.dlen : FLT_BUF_SIZE;
|
|
|
|
nchars = fread(buffer, 1, bcount, data_out_file);
|
|
|
|
if (nchars == 0)
|
|
|
|
break;
|
2005-02-02 10:28:51 +00:00
|
|
|
sc.dlen -= nchars;
|
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
if (!skip) {
|
|
|
|
switch (follow_info->show_type) {
|
|
|
|
|
|
|
|
case SHOW_EBCDIC:
|
|
|
|
/* If our native arch is ASCII, call: */
|
|
|
|
EBCDIC_to_ASCII(buffer, nchars);
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!(*print_line) (buffer, nchars, is_server, arg))
|
2004-01-25 01:53:24 +00:00
|
|
|
goto print_error;
|
2000-08-09 05:18:45 +00:00
|
|
|
break;
|
2002-01-18 07:25:22 +00:00
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
case SHOW_ASCII:
|
|
|
|
/* If our native arch is EBCDIC, call:
|
|
|
|
* ASCII_TO_EBCDIC(buffer, nchars);
|
|
|
|
*/
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!(*print_line) (buffer, nchars, is_server, arg))
|
2004-01-25 01:53:24 +00:00
|
|
|
goto print_error;
|
|
|
|
break;
|
2003-03-06 04:23:51 +00:00
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
case SHOW_RAW:
|
|
|
|
/* Don't translate, no matter what the native arch
|
|
|
|
* is.
|
|
|
|
*/
|
|
|
|
if (!(*print_line) (buffer, nchars, is_server, arg))
|
|
|
|
goto print_error;
|
|
|
|
break;
|
|
|
|
|
2004-01-25 01:53:24 +00:00
|
|
|
case SHOW_HEXDUMP:
|
|
|
|
current_pos = 0;
|
|
|
|
while (current_pos < nchars) {
|
|
|
|
gchar hexbuf[256];
|
2005-02-02 08:50:40 +00:00
|
|
|
int i;
|
|
|
|
gchar *cur = hexbuf, *ascii_start;
|
2004-01-25 01:53:24 +00:00
|
|
|
|
2005-02-02 08:50:40 +00:00
|
|
|
/* is_server indentation : put 78 spaces at the
|
2004-01-25 01:53:24 +00:00
|
|
|
* beginning of the string */
|
2005-02-02 08:50:40 +00:00
|
|
|
if (is_server && follow_info->show_stream == BOTH_HOSTS) {
|
|
|
|
memset(cur, ' ', 78);
|
|
|
|
cur += 78;
|
|
|
|
}
|
|
|
|
cur += g_snprintf(cur, 20, "%08X ", *global_pos);
|
|
|
|
/* 49 is space consumed by hex chars */
|
|
|
|
ascii_start = cur + 49;
|
2004-01-25 01:53:24 +00:00
|
|
|
for (i = 0; i < 16 && current_pos + i < nchars; i++) {
|
2005-02-02 08:50:40 +00:00
|
|
|
*cur++ =
|
2004-01-25 01:53:24 +00:00
|
|
|
hexchars[(buffer[current_pos + i] & 0xf0) >> 4];
|
2005-02-02 08:50:40 +00:00
|
|
|
*cur++ =
|
2004-01-25 01:53:24 +00:00
|
|
|
hexchars[buffer[current_pos + i] & 0x0f];
|
2005-02-02 08:50:40 +00:00
|
|
|
*cur++ = ' ';
|
|
|
|
if (i == 7)
|
|
|
|
*cur++ = ' ';
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
/* Fill it up if column isn't complete */
|
2005-02-02 08:50:40 +00:00
|
|
|
while (cur < ascii_start)
|
|
|
|
*cur++ = ' ';
|
2004-01-25 01:53:24 +00:00
|
|
|
|
|
|
|
/* Now dump bytes as text */
|
|
|
|
for (i = 0; i < 16 && current_pos + i < nchars; i++) {
|
2005-02-02 08:50:40 +00:00
|
|
|
*cur++ =
|
2004-01-25 01:53:24 +00:00
|
|
|
(isprint((guchar)buffer[current_pos + i]) ?
|
|
|
|
buffer[current_pos + i] : '.' );
|
|
|
|
if (i == 7) {
|
2005-02-02 08:50:40 +00:00
|
|
|
*cur++ = ' ';
|
2003-03-06 04:23:51 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
current_pos += i;
|
|
|
|
(*global_pos) += i;
|
2005-02-02 08:50:40 +00:00
|
|
|
*cur++ = '\n';
|
|
|
|
*cur = 0;
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!(*print_line) (hexbuf, strlen(hexbuf), is_server, arg))
|
2004-01-25 01:53:24 +00:00
|
|
|
goto print_error;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_CARRAY:
|
|
|
|
current_pos = 0;
|
2005-02-02 08:50:40 +00:00
|
|
|
g_snprintf(initbuf, sizeof(initbuf), "char peer%d_%d[] = {\n",
|
|
|
|
is_server ? 1 : 0,
|
2004-01-25 01:53:24 +00:00
|
|
|
is_server ? server_packet_count++ : client_packet_count++);
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!(*print_line) (initbuf, strlen(initbuf), is_server, arg))
|
2004-01-25 01:53:24 +00:00
|
|
|
goto print_error;
|
|
|
|
while (current_pos < nchars) {
|
|
|
|
gchar hexbuf[256];
|
|
|
|
int i, cur;
|
|
|
|
|
|
|
|
cur = 0;
|
|
|
|
for (i = 0; i < 8 && current_pos + i < nchars; i++) {
|
|
|
|
/* Prepend entries with "0x" */
|
|
|
|
hexbuf[cur++] = '0';
|
|
|
|
hexbuf[cur++] = 'x';
|
|
|
|
hexbuf[cur++] =
|
|
|
|
hexchars[(buffer[current_pos + i] & 0xf0) >> 4];
|
|
|
|
hexbuf[cur++] =
|
|
|
|
hexchars[buffer[current_pos + i] & 0x0f];
|
|
|
|
|
|
|
|
/* Delimit array entries with a comma */
|
|
|
|
if (current_pos + i + 1 < nchars)
|
|
|
|
hexbuf[cur++] = ',';
|
|
|
|
|
|
|
|
hexbuf[cur++] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the array if we are at the end */
|
|
|
|
if (current_pos + i == nchars) {
|
|
|
|
hexbuf[cur++] = '}';
|
|
|
|
hexbuf[cur++] = ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
current_pos += i;
|
|
|
|
(*global_pos) += i;
|
|
|
|
hexbuf[cur++] = '\n';
|
|
|
|
hexbuf[cur] = 0;
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!(*print_line) (hexbuf, strlen(hexbuf), is_server, arg))
|
2004-01-25 01:53:24 +00:00
|
|
|
goto print_error;
|
|
|
|
}
|
|
|
|
break;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
if (ferror(data_out_file)) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2004-01-25 01:53:24 +00:00
|
|
|
"Error reading temporary file %s: %s", follow_info->data_out_filename,
|
2000-08-09 05:18:45 +00:00
|
|
|
strerror(errno));
|
2004-01-25 01:53:24 +00:00
|
|
|
fclose(data_out_file);
|
|
|
|
data_out_file = NULL;
|
|
|
|
return FRS_READ_ERROR;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
|
2004-05-27 23:09:09 +00:00
|
|
|
fclose(data_out_file);
|
|
|
|
data_out_file = NULL;
|
2004-01-25 01:53:24 +00:00
|
|
|
return FRS_OK;
|
|
|
|
|
|
|
|
print_error:
|
|
|
|
fclose(data_out_file);
|
|
|
|
data_out_file = NULL;
|
|
|
|
return FRS_PRINT_ERROR;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - for text printing, we probably want to wrap lines at 80 characters;
|
2004-05-27 23:09:09 +00:00
|
|
|
* (PostScript printing is doing this already), and perhaps put some kind of
|
|
|
|
* dingbat (to use the technical term) to indicate a wrapped line, along the
|
|
|
|
* lines of what's done when displaying this in a window, as per Warren Young's
|
|
|
|
* suggestion.
|
2000-08-03 12:44:40 +00:00
|
|
|
*/
|
2004-01-24 10:53:25 +00:00
|
|
|
static gboolean
|
2005-02-02 10:28:51 +00:00
|
|
|
follow_print_text(char *buffer, size_t nchars, gboolean is_server _U_, void *arg)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2004-07-25 08:53:38 +00:00
|
|
|
print_stream_t *stream = arg;
|
2005-02-02 10:28:51 +00:00
|
|
|
size_t i;
|
2004-05-27 23:09:09 +00:00
|
|
|
char *str;
|
2004-05-27 21:55:59 +00:00
|
|
|
|
|
|
|
/* convert non printable characters */
|
|
|
|
for (i = 0; i < nchars; i++) {
|
|
|
|
if (buffer[i] == '\n' || buffer[i] == '\r')
|
|
|
|
continue;
|
2005-01-02 00:23:50 +00:00
|
|
|
if (! isprint((guchar)buffer[i])) {
|
2004-05-27 21:55:59 +00:00
|
|
|
buffer[i] = '.';
|
|
|
|
}
|
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
|
2004-05-27 23:09:09 +00:00
|
|
|
/* convert unterminated char array to a zero terminated string */
|
|
|
|
str = g_malloc(nchars + 1);
|
|
|
|
memcpy(str, buffer, nchars);
|
|
|
|
str[nchars] = 0;
|
2004-07-25 08:53:38 +00:00
|
|
|
print_line(stream, /*indent*/ 0, str);
|
2004-05-27 23:09:09 +00:00
|
|
|
g_free(str);
|
|
|
|
|
2004-01-24 10:53:25 +00:00
|
|
|
return TRUE;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2005-02-02 08:50:40 +00:00
|
|
|
static gboolean
|
2005-02-02 10:28:51 +00:00
|
|
|
follow_write_raw(char *buffer, size_t nchars, gboolean is_server _U_, void *arg)
|
2005-02-02 08:50:40 +00:00
|
|
|
{
|
2005-02-02 10:28:51 +00:00
|
|
|
FILE *fh = arg;
|
|
|
|
size_t nwritten;
|
2005-02-02 08:50:40 +00:00
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
nwritten = fwrite(buffer, 1, nchars, fh);
|
|
|
|
if (nwritten != nchars)
|
|
|
|
return FALSE;
|
2005-02-02 08:50:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-04-06 22:41:34 +00:00
|
|
|
static void
|
2004-04-09 19:44:27 +00:00
|
|
|
follow_filter_out_stream(GtkWidget * w _U_, gpointer data)
|
2003-04-06 22:41:34 +00:00
|
|
|
{
|
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
/* Lock out user from messing with us. (ie. don't free our data!) */
|
|
|
|
gtk_widget_set_sensitive(follow_info->streamwindow, FALSE);
|
|
|
|
|
|
|
|
/* Set the display filter. */
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(follow_info->filter_te), follow_info->filter_out_filter);
|
|
|
|
|
|
|
|
/* Run the display filter so it goes in effect. */
|
2004-02-23 22:48:52 +00:00
|
|
|
main_filter_packets(&cfile, follow_info->filter_out_filter, FALSE);
|
2003-04-06 22:41:34 +00:00
|
|
|
|
|
|
|
/* we force a subsequent close */
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(follow_info->streamwindow);
|
2004-04-09 19:44:27 +00:00
|
|
|
|
2003-04-06 22:41:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_print_stream(GtkWidget * w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2004-07-25 08:53:38 +00:00
|
|
|
print_stream_t *stream;
|
2000-08-09 05:18:45 +00:00
|
|
|
gboolean to_file;
|
|
|
|
char *print_dest;
|
|
|
|
follow_info_t *follow_info = data;
|
2004-05-27 21:55:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
gboolean win_printer = FALSE;
|
|
|
|
#endif
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
switch (prefs.pr_dest) {
|
|
|
|
case PR_DEST_CMD:
|
2004-05-27 21:55:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
win_printer = TRUE;
|
|
|
|
/*XXX should use temp file stuff in util routines */
|
2004-06-29 03:27:52 +00:00
|
|
|
print_dest = g_strdup(tmpnam(NULL));
|
2004-05-27 21:55:59 +00:00
|
|
|
to_file = TRUE;
|
|
|
|
#else
|
|
|
|
print_dest = prefs.pr_cmd;
|
|
|
|
to_file = FALSE;
|
|
|
|
#endif
|
|
|
|
break;
|
2000-08-09 05:18:45 +00:00
|
|
|
case PR_DEST_FILE:
|
2004-05-27 21:55:59 +00:00
|
|
|
print_dest = prefs.pr_file;
|
|
|
|
to_file = TRUE;
|
|
|
|
break;
|
2000-08-09 05:18:45 +00:00
|
|
|
default: /* "Can't happen" */
|
2004-05-27 21:55:59 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
|
|
|
"Couldn't figure out where to send the print "
|
|
|
|
"job. Check your preferences.");
|
|
|
|
return;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
switch (prefs.pr_format) {
|
|
|
|
|
|
|
|
case PR_FMT_TEXT:
|
|
|
|
stream = print_stream_text_new(to_file, print_dest);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PR_FMT_PS:
|
|
|
|
stream = print_stream_ps_new(to_file, print_dest);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
stream = NULL;
|
|
|
|
}
|
|
|
|
if (stream == NULL) {
|
2004-05-27 21:55:59 +00:00
|
|
|
if (to_file) {
|
|
|
|
open_failure_alert_box(prefs.pr_file, errno, TRUE);
|
|
|
|
} else {
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
|
|
|
"Couldn't run print command %s.", prefs.pr_cmd);
|
|
|
|
}
|
|
|
|
return;
|
2004-01-24 10:53:25 +00:00
|
|
|
}
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!print_preamble(stream, cfile.filename))
|
2004-05-27 21:55:59 +00:00
|
|
|
goto print_error;
|
2004-01-25 01:53:24 +00:00
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
switch (follow_read_stream(follow_info, follow_print_text, stream)) {
|
2004-01-25 01:53:24 +00:00
|
|
|
case FRS_OK:
|
2004-05-27 21:55:59 +00:00
|
|
|
break;
|
2004-01-25 01:53:24 +00:00
|
|
|
case FRS_OPEN_ERROR:
|
|
|
|
case FRS_READ_ERROR:
|
2004-05-27 21:55:59 +00:00
|
|
|
/* XXX - cancel printing? */
|
2004-07-25 08:53:38 +00:00
|
|
|
destroy_print_stream(stream);
|
2004-05-27 21:55:59 +00:00
|
|
|
return;
|
2004-01-25 01:53:24 +00:00
|
|
|
case FRS_PRINT_ERROR:
|
2004-05-27 21:55:59 +00:00
|
|
|
goto print_error;
|
2000-08-09 05:18:45 +00:00
|
|
|
}
|
2004-05-27 21:55:59 +00:00
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!print_finale(stream))
|
2004-05-27 21:55:59 +00:00
|
|
|
goto print_error;
|
|
|
|
|
2004-07-25 08:53:38 +00:00
|
|
|
if (!destroy_print_stream(stream)) {
|
2004-05-27 21:55:59 +00:00
|
|
|
if (to_file) {
|
2004-07-25 08:53:38 +00:00
|
|
|
write_failure_alert_box(prefs.pr_file, errno);
|
2004-05-27 21:55:59 +00:00
|
|
|
} else {
|
2004-07-25 08:53:38 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2004-01-24 10:53:25 +00:00
|
|
|
"Error closing print destination.");
|
2004-05-27 21:55:59 +00:00
|
|
|
}
|
2004-01-24 10:53:25 +00:00
|
|
|
}
|
2004-05-27 21:55:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (win_printer) {
|
|
|
|
print_mswin(print_dest);
|
|
|
|
|
|
|
|
/* trash temp file */
|
2005-11-06 22:43:25 +00:00
|
|
|
eth_remove(print_dest);
|
2004-05-27 21:55:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-01-25 01:53:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
print_error:
|
2004-05-27 21:55:59 +00:00
|
|
|
if (to_file) {
|
|
|
|
write_failure_alert_box(prefs.pr_file, errno);
|
|
|
|
} else {
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
|
|
|
"Error writing to print command: %s", strerror(errno));
|
2004-01-25 01:53:24 +00:00
|
|
|
}
|
|
|
|
/* XXX - cancel printing? */
|
2004-07-25 08:53:38 +00:00
|
|
|
destroy_print_stream(stream);
|
2004-05-27 21:55:59 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (win_printer) {
|
|
|
|
/* trash temp file */
|
2005-11-06 22:43:25 +00:00
|
|
|
eth_remove(print_dest);
|
2004-05-27 21:55:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2005-02-02 08:50:40 +00:00
|
|
|
/* static variable declarations to speed up the performance
|
|
|
|
* of follow_load_text and follow_add_to_gtk_text
|
|
|
|
*/
|
|
|
|
static GdkColor server_fg, server_bg;
|
|
|
|
static GdkColor client_fg, client_bg;
|
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
static GtkTextTag *server_tag, *client_tag;
|
|
|
|
#endif
|
|
|
|
|
2004-01-24 10:53:25 +00:00
|
|
|
static gboolean
|
2005-02-02 10:28:51 +00:00
|
|
|
follow_add_to_gtk_text(char *buffer, size_t nchars, gboolean is_server,
|
2004-07-25 08:53:38 +00:00
|
|
|
void *arg)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
GtkWidget *text = arg;
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2
|
|
|
|
GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
|
|
|
|
GtkTextIter iter;
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2003-12-24 01:21:32 +00:00
|
|
|
#if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
|
2001-04-10 12:07:40 +00:00
|
|
|
/* While our isprint() hack is in place, we
|
|
|
|
* have to use convert some chars to '.' in order
|
|
|
|
* to be able to see the data we *should* see
|
|
|
|
* in the GtkText widget.
|
|
|
|
*/
|
2005-02-02 10:28:51 +00:00
|
|
|
size_t i;
|
2001-04-10 12:07:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nchars; i++) {
|
2003-12-24 01:21:32 +00:00
|
|
|
if (buffer[i] == '\n' || buffer[i] == '\r')
|
2002-11-03 17:38:45 +00:00
|
|
|
continue;
|
|
|
|
if (! isprint(buffer[i])) {
|
|
|
|
buffer[i] = '.';
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 12:07:40 +00:00
|
|
|
#endif
|
|
|
|
|
2005-02-02 08:50:40 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-11-21 23:54:10 +00:00
|
|
|
if (is_server) {
|
2005-02-02 08:50:40 +00:00
|
|
|
gtk_text_insert(GTK_TEXT(text), user_font_get_regular(), &server_fg,
|
|
|
|
&server_bg, buffer, nchars);
|
2000-11-21 23:54:10 +00:00
|
|
|
} else {
|
2005-02-02 08:50:40 +00:00
|
|
|
gtk_text_insert(GTK_TEXT(text), user_font_get_regular(), &client_fg,
|
|
|
|
&client_bg, buffer, nchars);
|
2000-11-21 23:54:10 +00:00
|
|
|
}
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
gtk_text_buffer_get_end_iter(buf, &iter);
|
2005-02-02 08:50:40 +00:00
|
|
|
if (is_server) {
|
|
|
|
gtk_text_buffer_insert_with_tags(buf, &iter, buffer, nchars,
|
|
|
|
server_tag, NULL);
|
|
|
|
} else {
|
|
|
|
gtk_text_buffer_insert_with_tags(buf, &iter, buffer, nchars,
|
|
|
|
client_tag, NULL);
|
|
|
|
}
|
2002-11-03 17:38:45 +00:00
|
|
|
#endif
|
2004-01-24 10:53:25 +00:00
|
|
|
return TRUE;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_load_text(follow_info_t *follow_info)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
int bytes_already;
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
GtkTextBuffer *buf;
|
2004-04-09 19:44:27 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(follow_info->text));
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2005-02-02 08:50:40 +00:00
|
|
|
/* prepare colors one time for repeated use by follow_add_to_gtk_text */
|
|
|
|
color_t_to_gdkcolor(&server_fg, &prefs.st_server_fg);
|
|
|
|
color_t_to_gdkcolor(&server_bg, &prefs.st_server_bg);
|
|
|
|
color_t_to_gdkcolor(&client_fg, &prefs.st_client_fg);
|
|
|
|
color_t_to_gdkcolor(&client_bg, &prefs.st_client_bg);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Delete any info already in text box */
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
bytes_already = gtk_text_get_length(GTK_TEXT(follow_info->text));
|
|
|
|
if (bytes_already > 0) {
|
|
|
|
gtk_text_set_point(GTK_TEXT(follow_info->text), 0);
|
|
|
|
gtk_text_forward_delete(GTK_TEXT(follow_info->text), bytes_already);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop the updates while we fill the text box */
|
|
|
|
gtk_text_freeze(GTK_TEXT(follow_info->text));
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
2005-02-02 08:50:40 +00:00
|
|
|
/* prepare tags one time for repeated use by follow_add_to_gtk_text */
|
|
|
|
server_tag = gtk_text_buffer_create_tag(buf, NULL, "foreground-gdk", &server_fg,
|
|
|
|
"background-gdk", &server_bg, "font-desc",
|
|
|
|
user_font_get_regular(), NULL);
|
|
|
|
client_tag = gtk_text_buffer_create_tag(buf, NULL, "foreground-gdk", &client_fg,
|
|
|
|
"background-gdk", &client_bg, "font-desc",
|
|
|
|
user_font_get_regular(), NULL);
|
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
gtk_text_buffer_set_text(buf, "", -1);
|
|
|
|
#endif
|
2004-07-25 08:53:38 +00:00
|
|
|
follow_read_stream(follow_info, follow_add_to_gtk_text, follow_info->text);
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_text_thaw(GTK_TEXT(follow_info->text));
|
2002-11-03 17:38:45 +00:00
|
|
|
#endif
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Save TCP Follow Stream As" window, if
|
|
|
|
* any, so that if somebody tries to do "Save"
|
|
|
|
* while there's already a "Save TCP Follow Stream" window up, we just pop
|
|
|
|
* up the existing one, rather than creating a new one.
|
|
|
|
*/
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_save_as_cmd_cb(GtkWidget *w _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2004-03-29 22:40:58 +00:00
|
|
|
GtkWidget *new_win;
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
if (follow_info->follow_save_as_w != NULL) {
|
|
|
|
/* There's already a dialog box; reactivate it. */
|
|
|
|
reactivate_window(follow_info->follow_save_as_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
new_win = file_selection_new("Ethereal: Save TCP Follow Stream As",
|
2004-03-29 22:40:58 +00:00
|
|
|
FILE_SELECTION_SAVE);
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info->follow_save_as_w = new_win;
|
|
|
|
|
|
|
|
/* Tuck away the follow_info object into the window */
|
2002-11-10 11:00:29 +00:00
|
|
|
OBJECT_SET_DATA(new_win, E_FOLLOW_INFO_KEY, follow_info);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-05-27 21:55:59 +00:00
|
|
|
SIGNAL_CONNECT(new_win, "destroy", follow_save_as_destroy_cb, follow_info);
|
|
|
|
|
2004-03-29 22:40:58 +00:00
|
|
|
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
|
2004-03-27 11:16:58 +00:00
|
|
|
if (gtk_dialog_run(GTK_DIALOG(new_win)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
follow_save_as_ok_cb(new_win, new_win);
|
2004-05-27 21:55:59 +00:00
|
|
|
} else {
|
|
|
|
window_destroy(new_win);
|
2004-03-27 11:16:58 +00:00
|
|
|
}
|
|
|
|
#else
|
2000-08-09 05:18:45 +00:00
|
|
|
/* Connect the ok_button to file_save_as_ok_cb function and pass along a
|
|
|
|
pointer to the file selection box widget */
|
2004-05-26 03:49:24 +00:00
|
|
|
SIGNAL_CONNECT(GTK_FILE_SELECTION(new_win)->ok_button,
|
|
|
|
"clicked", follow_save_as_ok_cb, new_win);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-05-26 03:49:24 +00:00
|
|
|
window_set_cancel_button(new_win,
|
|
|
|
GTK_FILE_SELECTION(new_win)->cancel_button, window_cancel_button_cb);
|
2000-08-09 05:18:45 +00:00
|
|
|
|
|
|
|
gtk_file_selection_set_filename(GTK_FILE_SELECTION(new_win), "");
|
2004-05-26 03:49:24 +00:00
|
|
|
|
|
|
|
SIGNAL_CONNECT(new_win, "delete_event", window_delete_event_cb, NULL);
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
gtk_widget_show_all(new_win);
|
2004-05-26 03:49:24 +00:00
|
|
|
window_present(new_win);
|
2004-03-27 11:16:58 +00:00
|
|
|
#endif
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2000-08-03 12:44:40 +00:00
|
|
|
static void
|
2004-03-27 11:16:58 +00:00
|
|
|
follow_save_as_ok_cb(GtkWidget * w _U_, gpointer fs)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2004-03-27 11:16:58 +00:00
|
|
|
gchar *to_name;
|
|
|
|
follow_info_t *follow_info;
|
|
|
|
FILE *fh;
|
2005-02-02 10:28:51 +00:00
|
|
|
print_stream_t *stream = NULL;
|
2004-03-27 11:16:58 +00:00
|
|
|
gchar *dirname;
|
2000-08-03 12:44:40 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
|
|
|
|
to_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
|
|
|
|
#else
|
|
|
|
to_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
|
|
|
|
#endif
|
2000-08-09 05:18:45 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(to_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
|
|
|
directory, and leave the selection box displayed. */
|
|
|
|
set_last_open_dir(to_name);
|
|
|
|
g_free(to_name);
|
2004-06-01 17:33:37 +00:00
|
|
|
file_selection_set_current_folder(fs, get_last_open_dir());
|
2004-03-27 11:16:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-09-09 20:39:01 +00:00
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
follow_info = OBJECT_GET_DATA(fs, E_FOLLOW_INFO_KEY);
|
|
|
|
if (follow_info->show_type == SHOW_RAW) {
|
|
|
|
/* Write the data out as raw binary data */
|
2005-11-06 22:43:25 +00:00
|
|
|
fh = eth_fopen(to_name, "wb");
|
2005-02-02 10:28:51 +00:00
|
|
|
} else {
|
|
|
|
/* Write it out as text */
|
2005-11-06 22:43:25 +00:00
|
|
|
fh = eth_fopen(to_name, "w");
|
2005-02-02 10:28:51 +00:00
|
|
|
}
|
2004-03-27 11:16:58 +00:00
|
|
|
if (fh == NULL) {
|
|
|
|
open_failure_alert_box(to_name, errno, TRUE);
|
|
|
|
g_free(to_name);
|
|
|
|
return;
|
|
|
|
}
|
2004-01-25 01:53:24 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
gtk_widget_hide(GTK_WIDGET(fs));
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(GTK_WIDGET(fs));
|
2004-01-25 01:53:24 +00:00
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
if (follow_info->show_type == SHOW_RAW) {
|
|
|
|
switch (follow_read_stream(follow_info, follow_write_raw, fh)) {
|
|
|
|
case FRS_OK:
|
|
|
|
if (fclose(fh) == EOF)
|
|
|
|
write_failure_alert_box(to_name, errno);
|
|
|
|
break;
|
2004-03-27 11:16:58 +00:00
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
case FRS_OPEN_ERROR:
|
|
|
|
case FRS_READ_ERROR:
|
|
|
|
fclose(fh);
|
|
|
|
break;
|
2004-03-27 11:16:58 +00:00
|
|
|
|
2005-02-02 10:28:51 +00:00
|
|
|
case FRS_PRINT_ERROR:
|
|
|
|
write_failure_alert_box(to_name, errno);
|
|
|
|
fclose(fh);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream = print_stream_text_stdio_new(fh);
|
|
|
|
switch (follow_read_stream(follow_info, follow_print_text, stream)) {
|
|
|
|
case FRS_OK:
|
|
|
|
if (!destroy_print_stream(stream))
|
|
|
|
write_failure_alert_box(to_name, errno);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRS_OPEN_ERROR:
|
|
|
|
case FRS_READ_ERROR:
|
|
|
|
destroy_print_stream(stream);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRS_PRINT_ERROR:
|
|
|
|
write_failure_alert_box(to_name, errno);
|
|
|
|
destroy_print_stream(stream);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-27 11:16:58 +00:00
|
|
|
}
|
2002-09-09 20:39:01 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
/* Save the directory name for future file dialogs. */
|
|
|
|
dirname = get_dirname(to_name); /* Overwrites to_name */
|
|
|
|
set_last_open_dir(dirname);
|
|
|
|
g_free(to_name);
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
follow_save_as_destroy_cb(GtkWidget * win _U_, gpointer data)
|
2000-08-03 12:44:40 +00:00
|
|
|
{
|
2000-08-09 05:18:45 +00:00
|
|
|
follow_info_t *follow_info = data;
|
|
|
|
|
|
|
|
/* Note that we no longer have a dialog box. */
|
|
|
|
follow_info->follow_save_as_w = NULL;
|
2000-08-03 12:44:40 +00:00
|
|
|
}
|