Add an explicit capture_cb_capture_failed indication for the case where
we weren't even able to start a capture, rather than delivering a fake "capture start" indication and relying on a later "capture file closed" indication - for a capture that was never opened in the first place - to handle GUI cleanups. Don't deliver any GUI indications in cf_close() if we didn't have a capture file open in the first place. Clear the status bar and welcome header if that indication is delivered. If we start a capture from the command line with the -k flag, don't show the captured packet information unless the capture actually starts. svn path=/trunk/; revision=41521
This commit is contained in:
parent
fd4894c8f8
commit
cd1debf183
130
capture.c
130
capture.c
@ -549,75 +549,73 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
|
||||
if (msg != NULL)
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", msg);
|
||||
|
||||
/* if we didn't start the capture, do a fake start. */
|
||||
/* (happens if we got an error message - we won't get a filename then). */
|
||||
if(capture_opts->state == CAPTURE_PREPARING) {
|
||||
if(capture_opts->real_time_mode) {
|
||||
capture_callback_invoke(capture_cb_capture_update_started, capture_opts);
|
||||
} else {
|
||||
capture_callback_invoke(capture_cb_capture_fixed_started, capture_opts);
|
||||
}
|
||||
}
|
||||
|
||||
if(capture_opts->real_time_mode) {
|
||||
cf_read_status_t status;
|
||||
|
||||
/* Read what remains of the capture file. */
|
||||
status = cf_finish_tail(capture_opts->cf, &err);
|
||||
|
||||
/* XXX: If -Q (quit-after-cap) then cf->count clr'd below so save it first */
|
||||
packet_count_save = cf_get_packet_count(capture_opts->cf);
|
||||
/* Tell the GUI we are not doing a capture any more.
|
||||
Must be done after the cf_finish_tail(), so file lengths are
|
||||
correctly displayed */
|
||||
capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
|
||||
|
||||
/* Finish the capture. */
|
||||
switch (status) {
|
||||
|
||||
case CF_READ_OK:
|
||||
if ((packet_count_save == 0) && !capture_opts->restart) {
|
||||
simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
|
||||
"%sNo packets captured!%s\n"
|
||||
"\n"
|
||||
"As no data was captured, closing the %scapture file!\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"Help about capturing can be found at:\n"
|
||||
"\n"
|
||||
" http://wiki.wireshark.org/CaptureSetup"
|
||||
#ifdef _WIN32
|
||||
"\n\n"
|
||||
"Wireless (Wi-Fi/WLAN):\n"
|
||||
"Try to switch off promiscuous mode in the Capture Options!"
|
||||
#endif
|
||||
"",
|
||||
simple_dialog_primary_start(), simple_dialog_primary_end(),
|
||||
cf_is_tempfile(capture_opts->cf) ? "temporary " : "");
|
||||
cf_close(capture_opts->cf);
|
||||
}
|
||||
break;
|
||||
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_READ_ABORTED:
|
||||
/* Exit by leaving the main loop, so that any quit functions
|
||||
we registered get called. */
|
||||
main_window_quit();
|
||||
break;
|
||||
}
|
||||
|
||||
/* We didn't start a capture; note that the attempt to start it
|
||||
failed. */
|
||||
capture_callback_invoke(capture_cb_capture_failed, capture_opts);
|
||||
} else {
|
||||
/* first of all, we are not doing a capture any more */
|
||||
capture_callback_invoke(capture_cb_capture_fixed_finished, capture_opts);
|
||||
/* We started a capture; process what's left of the capture file if
|
||||
we were in "update list of packets in real time" mode, or process
|
||||
all of it if we weren't. */
|
||||
if(capture_opts->real_time_mode) {
|
||||
cf_read_status_t status;
|
||||
|
||||
/* this is a normal mode capture and if no error happened, read in the capture file data */
|
||||
if(capture_opts->save_file != NULL) {
|
||||
capture_input_read_all(capture_opts, cf_is_tempfile(capture_opts->cf),
|
||||
cf_get_drops_known(capture_opts->cf), cf_get_drops(capture_opts->cf));
|
||||
/* Read what remains of the capture file. */
|
||||
status = cf_finish_tail(capture_opts->cf, &err);
|
||||
|
||||
/* XXX: If -Q (quit-after-cap) then cf->count clr'd below so save it first */
|
||||
packet_count_save = cf_get_packet_count(capture_opts->cf);
|
||||
/* Tell the GUI we are not doing a capture any more.
|
||||
Must be done after the cf_finish_tail(), so file lengths are
|
||||
correctly displayed */
|
||||
capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
|
||||
|
||||
/* Finish the capture. */
|
||||
switch (status) {
|
||||
|
||||
case CF_READ_OK:
|
||||
if ((packet_count_save == 0) && !capture_opts->restart) {
|
||||
simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
|
||||
"%sNo packets captured!%s\n"
|
||||
"\n"
|
||||
"As no data was captured, closing the %scapture file!\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"Help about capturing can be found at:\n"
|
||||
"\n"
|
||||
" http://wiki.wireshark.org/CaptureSetup"
|
||||
#ifdef _WIN32
|
||||
"\n\n"
|
||||
"Wireless (Wi-Fi/WLAN):\n"
|
||||
"Try to switch off promiscuous mode in the Capture Options!"
|
||||
#endif
|
||||
"",
|
||||
simple_dialog_primary_start(), simple_dialog_primary_end(),
|
||||
cf_is_tempfile(capture_opts->cf) ? "temporary " : "");
|
||||
cf_close(capture_opts->cf);
|
||||
}
|
||||
break;
|
||||
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_READ_ABORTED:
|
||||
/* Exit by leaving the main loop, so that any quit functions
|
||||
we registered get called. */
|
||||
main_window_quit();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* first of all, we are not doing a capture any more */
|
||||
capture_callback_invoke(capture_cb_capture_fixed_finished, capture_opts);
|
||||
|
||||
/* this is a normal mode capture and if no error happened, read in the capture file data */
|
||||
if(capture_opts->save_file != NULL) {
|
||||
capture_input_read_all(capture_opts, cf_is_tempfile(capture_opts->cf),
|
||||
cf_get_drops_known(capture_opts->cf), cf_get_drops(capture_opts->cf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,8 @@ typedef enum {
|
||||
capture_cb_capture_fixed_started,
|
||||
capture_cb_capture_fixed_continue,
|
||||
capture_cb_capture_fixed_finished,
|
||||
capture_cb_capture_stopping
|
||||
capture_cb_capture_stopping,
|
||||
capture_cb_capture_failed
|
||||
} capture_cbs;
|
||||
|
||||
typedef void (*capture_callback_t) (gint event, capture_options *capture_opts,
|
||||
|
13
file.c
13
file.c
@ -364,6 +364,9 @@ fail:
|
||||
* 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".
|
||||
*
|
||||
* XXX - currently, cf_open() calls cf_close(), rather than
|
||||
* cf_reset_state().
|
||||
*/
|
||||
static void
|
||||
cf_reset_state(capture_file *cf)
|
||||
@ -428,18 +431,16 @@ cf_reset_state(capture_file *cf)
|
||||
void
|
||||
cf_close(capture_file *cf)
|
||||
{
|
||||
/* do GUI things even if file is already closed,
|
||||
* e.g. to cleanup things if a capture couldn't be started */
|
||||
cf_callback_invoke(cf_cb_file_closing, cf);
|
||||
if(cf->state != FILE_CLOSED) {
|
||||
cf_callback_invoke(cf_cb_file_closing, cf);
|
||||
|
||||
/* close things, if not already closed before */
|
||||
if(cf->state != FILE_CLOSED) {
|
||||
color_filters_cleanup();
|
||||
cf_reset_state(cf);
|
||||
cleanup_dissection();
|
||||
}
|
||||
|
||||
cf_callback_invoke(cf_cb_file_closed, cf);
|
||||
cf_callback_invoke(cf_cb_file_closed, cf);
|
||||
}
|
||||
}
|
||||
|
||||
/* an out of memory exception occured, wait for a user button press to exit */
|
||||
|
@ -1647,7 +1647,6 @@ main_capture_cb_capture_fixed_finished(capture_options *capture_opts _U_)
|
||||
main_do_quit();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBPCAP */
|
||||
|
||||
static void
|
||||
@ -1791,6 +1790,9 @@ main_capture_callback(gint event, capture_options *capture_opts, gpointer user_d
|
||||
gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsicon64_xpm));
|
||||
#endif
|
||||
break;
|
||||
case(capture_cb_capture_failed):
|
||||
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture failed");
|
||||
break;
|
||||
default:
|
||||
g_warning("main_capture_callback: event %u unknown", event);
|
||||
g_assert_not_reached();
|
||||
@ -3017,7 +3019,7 @@ main(int argc, char *argv[])
|
||||
g_free(s);
|
||||
}
|
||||
/* "-k" was specified; start a capture. */
|
||||
show_main_window(TRUE);
|
||||
show_main_window(FALSE);
|
||||
check_and_warn_user_startup(cf_name);
|
||||
|
||||
/* If no user interfaces were specified on the command line,
|
||||
|
@ -899,6 +899,20 @@ statusbar_capture_fixed_finished_cb(capture_options *capture_opts _U_)
|
||||
gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
statusbar_capture_failed_cb(capture_options *capture_opts _U_)
|
||||
{
|
||||
#if 0
|
||||
capture_file *cf = capture_opts->cf;
|
||||
#endif
|
||||
|
||||
/* Pop the "<live capture in progress>" message off the status bar. */
|
||||
statusbar_pop_file_msg();
|
||||
welcome_header_pop_msg();
|
||||
|
||||
/* Pop the "<capturing>" message off the status bar */
|
||||
gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
|
||||
}
|
||||
#endif /* HAVE_LIBPCAP */
|
||||
|
||||
|
||||
@ -1011,6 +1025,9 @@ statusbar_capture_callback(gint event, capture_options *capture_opts,
|
||||
/* Beware: this state won't be called, if the capture child
|
||||
* closes the capturing on it's own! */
|
||||
break;
|
||||
case(capture_cb_capture_failed):
|
||||
statusbar_capture_failed_cb(capture_opts);
|
||||
break;
|
||||
default:
|
||||
g_warning("statusbar_capture_callback: event %u unknown", event);
|
||||
g_assert_not_reached();
|
||||
|
Loading…
x
Reference in New Issue
Block a user