* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/* With MSVC and a libethereal.dll this file needs to import some variables
- in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */
-#define _NEED_VAR_IMPORT_
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "packet-range.h"
#include "print.h"
#include "file.h"
-#include "menu.h"
+#include "fileset.h"
#include "util.h"
#include "merge.h"
#include "alert_box.h"
#include "simple_dialog.h"
#include "progress_dlg.h"
#include "ui_util.h"
-#include "statusbar.h"
#include <epan/prefs.h>
#include <epan/dfilter/dfilter.h>
#include <epan/conversation.h>
static guint32 prevsec, prevusec;
static guint32 cum_bytes = 0;
+static void cf_reset_state(capture_file *cf);
+
static void read_packet(capture_file *cf, long offset);
static void rescan_packets(capture_file *cf, const char *action, const char *action_item,
#define FRAME_DATA_CHUNK_SIZE 1024
-gboolean
+/* one callback for now, we could have a list later */
+static cf_callback_t cf_cb = NULL;
+static gpointer cf_cb_user_data = NULL;
+
+void
+cf_callback_invoke(int event, gpointer data)
+{
+ g_assert(cf_cb != NULL);
+ cf_cb(event, data, cf_cb_user_data);
+}
+
+
+void
+cf_callback_add(cf_callback_t func, gpointer user_data)
+{
+ /* More than one callback listener is currently not implemented,
+ but should be easy to do. */
+ g_assert(cf_cb == NULL);
+ cf_cb = func;
+ cf_cb_user_data = user_data;
+}
+
+void
+cf_callback_remove(cf_callback_t func _U_)
+{
+ g_assert(cf_cb != NULL);
+ cf_cb = NULL;
+ cf_cb_user_data = NULL;
+}
+
+
+cf_status_t
cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
{
wtap *wth;
int fd;
struct stat cf_stat;
+
wth = wtap_open_offline(fname, err, &err_info, TRUE);
if (wth == NULL)
goto fail;
/* The open succeeded. Close whatever capture file we had open,
and fill in the information for this file. */
- cf_close(cf);
+ cf_reset_state(cf);
/* Initialize all data structures used for dissection. */
init_dissection();
G_ALLOC_AND_FREE);
g_assert(cf->plist_chunk);
- return TRUE;
+ fileset_file_opened(fname);
+
+ return CF_OK;
fail:
cf_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
- return FALSE;
+ return CF_ERROR;
}
-/* Reset everything to a pristine state */
-void
-cf_close(capture_file *cf)
+
+/*
+ * Reset the state for the currently closed file, but don't do the
+ * UI callbacks; this is for use in "cf_open()", where we don't
+ * want the UI to go from "file open" to "file closed" back to
+ * "file open", we want it to go from "old file open" to "new file
+ * open and being read".
+ */
+static void
+cf_reset_state(capture_file *cf)
{
/* Die if we're in the middle of reading a file. */
g_assert(cf->state != FILE_READ_IN_PROGRESS);
- /* Destroy all windows, which refer to the
- capture file we're closing. */
- destroy_cfile_wins();
-
if (cf->wth) {
wtap_close(cf->wth);
cf->wth = NULL;
cf->esec = 0;
cf->eusec = 0;
- /* Clear any file-related status bar messages.
- XXX - should be "clear *ALL* file-related status bar messages;
- will there ever be more than one on the stack? */
- statusbar_pop_file_msg();
-
- /* Restore the standard title bar message. */
- set_main_window_name("The Ethereal Network Analyzer");
-
- /* Disable all menu items that make sense only if you have a capture. */
- set_menus_for_capture_file(FALSE);
- set_menus_for_unsaved_capture_file(FALSE);
- set_menus_for_captured_packets(FALSE);
- set_menus_for_selected_packet(cf);
- set_menus_for_capture_in_progress(FALSE);
- set_menus_for_selected_tree_row(cf);
-
reset_tap_listeners();
/* We have no file open. */
cf->state = FILE_CLOSED;
+
+ fileset_file_closed();
}
-/* Set the file name in the status line, in the name for the main window,
- and in the name for the main window's icon. */
-static void
-set_display_filename(capture_file *cf)
+/* Reset everything to a pristine state */
+void
+cf_close(capture_file *cf)
{
- const gchar *name_ptr;
- size_t msg_len;
- static const gchar done_fmt_nodrops[] = " File: %s %s %02u:%02u:%02u";
- static const gchar done_fmt_drops[] = " File: %s %s %02u:%02u:%02u Drops: %u";
- gchar *done_msg;
- gchar *win_name_fmt = "%s - Ethereal";
- gchar *win_name;
- gchar *size_str;
-
- name_ptr = cf_get_display_name(cf);
-
- if (!cf->is_tempfile) {
- /* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(cf->filename);
- }
+ cf_reset_state(cf);
- if (cf->f_len/1024/1024 > 10) {
- size_str = g_strdup_printf("%ld MB", cf->f_len/1024/1024);
- } else if (cf->f_len/1024 > 10) {
- size_str = g_strdup_printf("%ld KB", cf->f_len/1024);
- } else {
- size_str = g_strdup_printf("%ld bytes", cf->f_len);
- }
+ cleanup_dissection();
- if (cf->drops_known) {
- done_msg = g_strdup_printf(done_fmt_drops, name_ptr, size_str,
- cf->esec/3600, cf->esec%3600/60, cf->esec%60, cf->drops);
- } else {
- done_msg = g_strdup_printf(done_fmt_nodrops, name_ptr, size_str,
- cf->esec/3600, cf->esec%3600/60, cf->esec%60);
- }
- statusbar_push_file_msg(done_msg);
- g_free(done_msg);
-
- msg_len = strlen(name_ptr) + strlen(win_name_fmt) + 1;
- win_name = g_malloc(msg_len);
- snprintf(win_name, msg_len, win_name_fmt, name_ptr);
- set_main_window_name(win_name);
- g_free(win_name);
+ cf_callback_invoke(cf_cb_file_closed, cf);
}
cf_read_status_t
int progbar_quantum;
cum_bytes=0;
+
reset_tap_listeners();
tap_dfilter_dlg_update();
- name_ptr = get_basename(cf->filename);
- load_msg = g_strdup_printf(" Loading: %s", name_ptr);
- statusbar_push_file_msg(load_msg);
- g_free(load_msg);
+ cf_callback_invoke(cf_cb_file_read_start, cf);
+ name_ptr = get_basename(cf->filename);
load_msg = g_strdup_printf(load_fmt, name_ptr);
/* Update the progress bar when it gets to this value. */
if (stop_flag) {
/* Well, the user decided to abort the read. Destroy the progress
- bar, close the capture file, and return CF_ABORTED so our caller
+ bar, close the capture file, and return CF_READ_ABORTED so our caller
can do whatever is appropriate when that happens. */
destroy_progress_dlg(progbar);
cf->state = FILE_READ_ABORTED; /* so that we're allowed to close it */
packet_list_thaw(); /* undo our freeze */
cf_close(cf);
- return CF_ABORTED;
+ return CF_READ_ABORTED;
}
read_packet(cf, data_offset);
}
cf->current_frame = cf->first_displayed;
packet_list_thaw();
- statusbar_pop_file_msg();
- set_display_filename(cf);
-
- /* Enable menu items that make sense if you have a capture file you've
- finished reading. */
- set_menus_for_capture_file(TRUE);
- set_menus_for_unsaved_capture_file(!cf->user_saved);
-
- /* Enable menu items that make sense if you have some captured packets. */
- set_menus_for_captured_packets(TRUE);
+ cf_callback_invoke(cf_cb_file_read_finished, cf);
/* If we have any displayed packets to select, select the first of those
packets by making the first row the selected row. */
}
snprintf(err_str, sizeof err_str, errmsg);
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_str);
- return CF_ERROR;
+ return CF_READ_ERROR;
} else
- return CF_OK;
+ return CF_READ_OK;
}
#ifdef HAVE_LIBPCAP
-gboolean
+cf_status_t
cf_start_tail(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
{
- gchar *capture_msg;
- gboolean status;
-
- status = cf_open(cf, fname, is_tempfile, err);
- if (status) {
- /* Disable menu items that make no sense if you're currently running
- a capture. */
- set_menus_for_capture_in_progress(TRUE);
-
- /* Enable menu items that make sense if you have some captured
- packets (yes, I know, we don't have any *yet*). */
- set_menus_for_captured_packets(TRUE);
-
- capture_msg = g_strdup_printf(" %s: <live capture in progress>", cf->iface);
+ cf_status_t cf_status;
- statusbar_push_file_msg(capture_msg);
-
- g_free(capture_msg);
-
- }
- return status;
+ cf_status = cf_open(cf, fname, is_tempfile, err);
+ return cf_status;
}
cf_read_status_t
packet_list_moveto_end();
if (cf->state == FILE_READ_ABORTED) {
- /* Well, the user decided to exit Ethereal. Return CF_ABORTED
+ /* Well, the user decided to exit Ethereal. Return CF_READ_ABORTED
so that our caller can kill off the capture child process;
this will cause an EOF on the pipe from the child, so
"cf_finish_tail()" will be called, and it will clean up
and exit. */
- return CF_ABORTED;
+ return CF_READ_ABORTED;
} else if (*err != 0) {
/* We got an error reading the capture file.
XXX - pop up a dialog box? */
- return CF_ERROR;
+ return CF_READ_ERROR;
} else
- return CF_OK;
+ return CF_READ_OK;
}
cf_read_status_t
int fd;
struct stat cf_stat;
+
+ if(cf->wth == NULL) {
+ cf_close(cf);
+ return CF_READ_ERROR;
+ }
+
packet_list_freeze();
while ((wtap_read(cf->wth, err, &err_info, &data_offset))) {
/* Well, the user decided to abort the read. We're only called
when the child capture process closes the pipe to us (meaning
it's probably exited), so we can just close the capture
- file; we return CF_ABORTED so our caller can do whatever
+ file; we return CF_READ_ABORTED so our caller can do whatever
is appropriate when that happens. */
cf_close(cf);
- return CF_ABORTED;
+ return CF_READ_ABORTED;
}
packet_list_thaw();
WTAP_ENCAP_PER_PACKET). */
cf->lnk_t = wtap_file_encap(cf->wth);
- /* Pop the "<live capture in progress>" message off the status bar. */
- statusbar_pop_file_msg();
-
- set_display_filename(cf);
-
- /* Enable menu items that make sense if you're not currently running
- a capture. */
- set_menus_for_capture_in_progress(FALSE);
-
- /* Enable menu items that make sense if you have a capture file
- you've finished reading. */
- set_menus_for_capture_file(TRUE);
- set_menus_for_unsaved_capture_file(!cf->user_saved);
-
if (*err != 0) {
/* We got an error reading the capture file.
XXX - pop up a dialog box? */
- return CF_ERROR;
+ return CF_READ_ERROR;
} else {
- return CF_OK;
+ return CF_READ_OK;
}
}
#endif /* HAVE_LIBPCAP */
/* Get the last component of the file name, and use that. */
if (cf->filename){
displayname = get_basename(cf->filename);
-
- /* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(cf->filename);
} else {
displayname="(No file)";
}
return cf->count;
}
-/* XXX - use a macro instead? */
-/* XXX - move iface this to capture_opts? */
-gchar *
-cf_get_iface(capture_file *cf)
-{
- return cf->iface;
-}
-
/* XXX - use a macro instead? */
gboolean
cf_is_tempfile(capture_file *cf)
return cf->is_tempfile;
}
+void cf_set_tempfile(capture_file *cf, gboolean is_tempfile)
+{
+ cf->is_tempfile = is_tempfile;
+}
+
+
/* XXX - use a macro instead? */
void cf_set_drops_known(capture_file *cf, gboolean drops_known)
{
cf->drops = drops;
}
-void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
+/* XXX - use a macro instead? */
+gboolean cf_get_drops_known(capture_file *cf)
{
- cf->rfcode = rfcode;
+ return cf->drops_known;
}
-gchar *cf_get_cfilter(capture_file *cf)
+/* XXX - use a macro instead? */
+guint32 cf_get_drops(capture_file *cf)
{
- return cf->cfilter;
+ return cf->drops;
}
-typedef struct {
- color_filter_t *colorf;
- epan_dissect_t *edt;
-} apply_color_filter_args;
-
-/*
- * If no color filter has been applied, apply this one.
- * (The "if no color filter has been applied" is to handle the case where
- * more than one color filter matches the packet.)
- */
-static void
-apply_color_filter(gpointer filter_arg, gpointer argp)
+void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
{
- color_filter_t *colorf = filter_arg;
- apply_color_filter_args *args = argp;
-
- if (colorf->c_colorfilter != NULL && args->colorf == NULL) {
- if (dfilter_apply_edt(colorf->c_colorfilter, args->edt))
- args->colorf = colorf;
- }
+ cf->rfcode = rfcode;
}
static int
union wtap_pseudo_header *pseudo_header, const guchar *buf,
gboolean refilter)
{
- apply_color_filter_args args;
gint row;
gboolean create_proto_tree = FALSE;
epan_dissect_t *edt;
/* just add some value here until we know if it is being displayed or not */
fdata->cum_bytes = cum_bytes + fdata->pkt_len;
- /* We don't yet have a color filter to apply. */
- args.colorf = NULL;
-
/* If we don't have the time stamp of the first packet in the
capture, it's because this is the first packet. Save the time
stamp of this packet as the time stamp of the first packet. */
allocate a protocol tree root node, so that we'll construct
a protocol tree against which a filter expression can be
evaluated. */
- if ((cf->dfcode != NULL && refilter) || filter_list != NULL
+ if ((cf->dfcode != NULL && refilter) || color_filters_used()
|| num_tap_filters != 0)
create_proto_tree = TRUE;
if (cf->dfcode != NULL && refilter) {
epan_dissect_prime_dfilter(edt, cf->dfcode);
}
- if (filter_list) {
- filter_list_prime_edt(edt);
+ if (color_filters_used()) {
+ color_filters_prime_edt(edt);
}
tap_queue_init(edt);
epan_dissect_run(edt, pseudo_header, buf, fdata, &cf->cinfo);
If we don't have a display filter, set "passed_dfilter" to 1. */
if (cf->dfcode != NULL) {
if (refilter) {
- if (cf->dfcode != NULL)
- fdata->flags.passed_dfilter = dfilter_apply_edt(cf->dfcode, edt) ? 1 : 0;
- else
- fdata->flags.passed_dfilter = 1;
+ fdata->flags.passed_dfilter = dfilter_apply_edt(cf->dfcode, edt) ? 1 : 0;
}
} else
fdata->flags.passed_dfilter = 1;
- /* If we have color filters, and the frame is to be displayed, apply
- the color filters. */
- if (fdata->flags.passed_dfilter) {
- if (filter_list != NULL) {
- args.edt = edt;
- g_slist_foreach(filter_list, apply_color_filter, &args);
- }
- }
-
-
if( (fdata->flags.passed_dfilter)
|| (edt->pi.fd->flags.ref_time) ){
/* This frame either passed the display filter list or is marked as
row = packet_list_append(cf->cinfo.col_data, fdata);
- /* If the packet matches a color filter,
- * store matching color_filter_t object in frame data. */
- if (filter_list != NULL && (args.colorf != NULL)) {
- /* add the matching colorfilter to the frame data */
- fdata->color_filter = args.colorf;
- /* If packet is marked, use colors from preferences */
- if (fdata->flags.marked) {
- packet_list_set_colors(row, &prefs.gui_marked_fg, &prefs.gui_marked_bg);
- } else /* if (filter_list != NULL && (args.colorf != NULL)) */ {
- packet_list_set_colors(row, &(args.colorf->fg_color),
- &(args.colorf->bg_color));
- }
- } else {
- /* No color filter match */
- fdata->color_filter = NULL;
+ /* colorize packet: if packet is marked, use preferences,
+ otherwise try to apply color filters */
if (fdata->flags.marked) {
+ fdata->color_filter = NULL;
packet_list_set_colors(row, &prefs.gui_marked_fg, &prefs.gui_marked_bg);
+ } else {
+ fdata->color_filter = color_filters_colorize_packet(row, edt);
}
- }
/* Set the time of the previous displayed frame to the time of this
frame. */
cf->plist_end = fdata;
cf->count++;
+ cf->f_len = offset + phdr->caplen;
fdata->num = cf->count;
add_packet_to_packet_list(fdata, cf, pseudo_header, buf, TRUE);
} else {
}
}
-gboolean
-cf_merge_files(const char *out_filename, int out_fd, int in_file_count,
+cf_status_t
+cf_merge_files(char **out_filenamep, int in_file_count,
char *const *in_filenames, int file_type, gboolean do_append)
{
merge_in_file_t *in_files;
wtap *wth;
+ char *out_filename;
+ char tmpname[128+1];
+ int out_fd;
wtap_dumper *pdh;
int open_err, read_err, write_err, close_err;
gchar *err_info;
free(in_files);
cf_open_failure_alert_box(in_filenames[err_fileno], open_err, err_info,
FALSE, 0);
- return FALSE;
+ return CF_ERROR;
+ }
+
+ if (*out_filenamep != NULL) {
+ out_filename = *out_filenamep;
+ out_fd = open(out_filename, O_CREAT|O_TRUNC|O_BINARY, 0600);
+ if (out_fd == -1)
+ open_err = errno;
+ } else {
+ out_fd = create_tempfile(tmpname, sizeof tmpname, "ether");
+ if (out_fd == -1)
+ open_err = errno;
+ out_filename = g_strdup(tmpname);
+ *out_filenamep = out_filename;
+ }
+ if (out_fd == -1) {
+ err_info = NULL;
+ merge_close_in_files(in_file_count, in_files);
+ free(in_files);
+ cf_open_failure_alert_box(out_filename, open_err, NULL, TRUE, file_type);
+ return CF_ERROR;
}
pdh = wtap_dump_fdopen(out_fd, file_type,
merge_select_frame_type(in_file_count, in_files),
merge_max_snapshot_length(in_file_count, in_files), &open_err);
if (pdh == NULL) {
+ close(out_fd);
merge_close_in_files(in_file_count, in_files);
free(in_files);
cf_open_failure_alert_box(out_filename, open_err, err_info, TRUE,
file_type);
- return FALSE;
+ return CF_ERROR;
}
/* Get the sum of the sizes of all the files. */
cf_write_failure_alert_box(out_filename, write_err);
}
- return (!got_read_error && !got_write_error);
+ return (!got_read_error && !got_write_error) ? CF_OK : CF_ERROR;
}
-gboolean
+cf_status_t
cf_filter_packets(capture_file *cf, gchar *dftext, gboolean force)
{
dfilter_t *dfcode;
/* if new filter equals old one, do nothing unless told to do so */
if (!force && strcmp(filter_new, filter_old) == 0) {
- return TRUE;
+ return CF_OK;
}
if (dftext == NULL) {
g_free(safe_dfilter_error_msg);
g_free(safe_dftext);
g_free(dftext);
- return FALSE;
+ return CF_ERROR;
}
/* Was it empty? */
} else {
rescan_packets(cf, "Filtering", dftext, TRUE, FALSE);
}
- return TRUE;
+ return CF_OK;
}
void
return TRUE;
}
-gboolean
+cf_read_status_t
cf_retap_packets(capture_file *cf)
{
packet_range_t range;
NULL)) {
case PSP_FINISHED:
/* Completed successfully. */
- break;
+ return CF_OK;
case PSP_STOPPED:
/* Well, the user decided to abort the refiltering.
- Return FALSE so our caller knows they did that. */
- return FALSE;
+ Return CF_READ_ABORTED so our caller knows they did that. */
+ return CF_READ_ABORTED;
case PSP_FAILED:
/* Error while retapping. */
- return FALSE;
+ return CF_READ_ERROR;
}
- return TRUE;
+ g_assert_not_reached();
+ return CF_READ_OK;
}
typedef struct {
if (!destroy_print_stream(print_args->stream))
return CF_PRINT_WRITE_ERROR;
- return CF_OK;
+ return CF_PRINT_OK;
}
static gboolean
/* XXX - check for an error */
fclose(fh);
- return CF_OK;
+ return CF_PRINT_OK;
}
static gboolean
/* Fill in the column information, but don't create the protocol tree. */
edt = epan_dissect_new(FALSE, FALSE);
epan_dissect_run(edt, pseudo_header, pd, fdata, &cf->cinfo);
+ epan_dissect_fill_in_columns(edt);
/* Write out the information in that tree. */
proto_tree_write_psml(edt, fh);
/* XXX - check for an error */
fclose(fh);
- return CF_OK;
+ return CF_PRINT_OK;
+}
+
+static gboolean
+write_csv_packet(capture_file *cf, frame_data *fdata,
+ union wtap_pseudo_header *pseudo_header, const guint8 *pd,
+ void *argsp)
+{
+ FILE *fh = argsp;
+ epan_dissect_t *edt;
+
+ /* Fill in the column information, but don't create the protocol tree. */
+ edt = epan_dissect_new(FALSE, FALSE);
+ epan_dissect_run(edt, pseudo_header, pd, fdata, &cf->cinfo);
+ epan_dissect_fill_in_columns(edt);
+
+ /* Write out the information in that tree. */
+ proto_tree_write_csv(edt, fh);
+
+ epan_dissect_free(edt);
+
+ return !ferror(fh);
+}
+
+cf_print_status_t
+cf_write_csv_packets(capture_file *cf, print_args_t *print_args)
+{
+ FILE *fh;
+ psp_return_t ret;
+
+ fh = fopen(print_args->file, "w");
+ if (fh == NULL)
+ return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
+
+ write_csv_preamble(fh);
+ if (ferror(fh)) {
+ fclose(fh);
+ return CF_PRINT_WRITE_ERROR;
+ }
+
+ /* Iterate through the list of packets, printing the packets we were
+ told to print. */
+ ret = process_specified_packets(cf, &print_args->range, "Writing CSV",
+ "selected packets", write_csv_packet,
+ fh);
+
+ switch (ret) {
+
+ case PSP_FINISHED:
+ /* Completed successfully. */
+ break;
+
+ case PSP_STOPPED:
+ /* Well, the user decided to abort the printing. */
+ break;
+
+ case PSP_FAILED:
+ /* Error while printing. */
+ fclose(fh);
+ return CF_PRINT_WRITE_ERROR;
+ }
+
+ write_csv_finale(fh);
+ if (ferror(fh)) {
+ fclose(fh);
+ return CF_PRINT_WRITE_ERROR;
+ }
+
+ /* XXX - check for an error */
+ fclose(fh);
+
+ return CF_PRINT_OK;
}
/* Scan through the packet list and change all columns that use the
if (fdata == NULL) {
/* we didn't find a packet with that packet number */
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "There is no packet with that packet number.");
+ "There is no packet with the packet number %u.", fnumber);
return FALSE; /* we failed to go to that packet */
}
if (!fdata->flags.passed_dfilter) {
/* that packet currently isn't displayed */
/* XXX - add it to the set of displayed packets? */
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "That packet isn't currently being displayed.");
+ "The packet number %u isn't currently being displayed.", fnumber);
return FALSE; /* we failed to go to that packet */
}
epan_dissect_run(cf->edt, &cf->pseudo_header, cf->pd, cf->current_frame,
NULL);
- /* Display the GUI protocol tree and hex dump.
- XXX - why do we dump core if we call "proto_tree_draw()"
- before calling "add_byte_views()"? */
- add_main_byte_views(cf->edt);
- main_proto_tree_draw(cf->edt->tree);
-
- /* A packet is selected. */
- set_menus_for_selected_packet(cf);
+ cf_callback_invoke(cf_cb_packet_selected, cf);
}
/* Unselect the selected packet, if any. */
cf->edt = NULL;
}
- /* Clear out the display of that packet. */
- clear_tree_and_hex_views();
-
/* No packet is selected. */
cf->current_frame = NULL;
- set_menus_for_selected_packet(cf);
+
+ cf_callback_invoke(cf_cb_packet_unselected, cf);
/* No protocol tree means no selected field. */
cf_unselect_field(cf);
void
cf_unselect_field(capture_file *cf)
{
- statusbar_pop_field_msg();
cf->finfo_selected = NULL;
- set_menus_for_selected_tree_row(cf);
+
+ cf_callback_invoke(cf_cb_field_unselected, cf);
}
/*
return TRUE;
}
-gboolean
+cf_status_t
cf_save(capture_file *cf, const char *fname, packet_range_t *range, guint save_format)
{
gchar *from_filename;
- const gchar *name_ptr;
- gchar *save_msg, *save_fmt = " Saving: %s...";
- size_t msg_len;
int err;
gboolean do_copy;
wtap_dumper *pdh;
- struct stat infile, outfile;
save_callback_args_t callback_args;
- name_ptr = get_basename(fname);
- msg_len = strlen(name_ptr) + strlen(save_fmt) + 2;
- save_msg = g_malloc(msg_len);
- snprintf(save_msg, msg_len, save_fmt, name_ptr);
- statusbar_push_file_msg(save_msg);
- g_free(save_msg);
+ cf_callback_invoke(cf_cb_file_safe_started, (gpointer) fname);
- /*
- * Check that the from file is not the same as to file
- * We do it here so we catch all cases ...
- * Unfortunately, the file requester gives us an absolute file
- * name and the read file name may be relative (if supplied on
- * the command line). From Joerg Mayer.
- *
- * This is a bit tricky on win32. The st_ino field is documented as:
- * "The inode, and therefore st_ino, has no meaning in the FAT, ..."
- * but it *is* set to zero if stat() returns without an error,
- * so this is working, but maybe not quite the way expected. ULFL
- */
- infile.st_ino = 1; /* These prevent us from getting equality */
- outfile.st_ino = 2; /* If one or other of the files is not accessible */
- stat(cf->filename, &infile);
- stat(fname, &outfile);
- if (infile.st_ino == outfile.st_ino) {
+ /* don't write over an existing file. */
+ /* this should've been already checked by our caller, just to be sure... */
+ if (file_exists(fname)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%sCapture file: \"%s\" already exists!%s\n\n"
"Please choose a different filename.",
}
}
- /* Pop the "Saving:" message off the status bar. */
- statusbar_pop_file_msg();
+ cf_callback_invoke(cf_cb_file_safe_finished, NULL);
if (packet_range_process_all(range)) {
/* We saved the entire capture, not just some packets from it.
What should we return if it fails or is aborted? */
switch (cf_read(cf)) {
- case CF_OK:
- case CF_ERROR:
+ case CF_READ_OK:
+ case CF_READ_ERROR:
/* Just because we got an error, that doesn't mean we were unable
to read any of the file; we handle what we could get from the
file. */
break;
- case CF_ABORTED:
+ case CF_READ_ABORTED:
/* The user bailed out of re-reading the capture file; the
capture file has been closed - just return (without
changing any menu settings; "cf_close()" set them
correctly for the "no capture file open" state). */
break;
}
- set_menus_for_unsaved_capture_file(FALSE);
+ cf_callback_invoke(cf_cb_file_safe_reload_finished, NULL);
}
}
- return TRUE;
+ return CF_OK;
fail:
- /* Pop the "Saving:" message off the status bar. */
- statusbar_pop_file_msg();
- return FALSE;
+ cf_callback_invoke(cf_cb_file_safe_failed, NULL);
+ return CF_ERROR;
}
static void
if (cf_open(cf, filename, is_tempfile, &err) == CF_OK) {
switch (cf_read(cf)) {
- case CF_OK:
- case CF_ERROR:
+ case CF_READ_OK:
+ case CF_READ_ERROR:
/* Just because we got an error, that doesn't mean we were unable
to read any of the file; we handle what we could get from the
file. */
break;
- case CF_ABORTED:
+ case CF_READ_ABORTED:
/* The user bailed out of re-reading the capture file; the
capture file has been closed - just free the capture file name
string and return (without changing the last containing