diff options
Diffstat (limited to 'ui/qt/main.cpp')
-rw-r--r-- | ui/qt/main.cpp | 178 |
1 files changed, 114 insertions, 64 deletions
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index 582855f2..c7d459b1 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -10,8 +10,6 @@ #include <config.h> #define WS_LOG_DOMAIN LOG_DOMAIN_MAIN -#include <glib.h> - #include <locale.h> #ifdef _WIN32 @@ -77,6 +75,7 @@ #include "ui/preference_utils.h" #include "ui/software_update.h" #include "ui/taps.h" +#include "ui/profile.h" #include "ui/qt/conversation_dialog.h" #include "ui/qt/utils/color_utils.h" @@ -209,11 +208,27 @@ gather_wireshark_qt_compiled_info(feature_list l) #endif gather_caplibs_compile_info(l); epan_gather_compile_info(l); +#ifdef HAVE_MINIZIPNG + with_feature(l, "Minizip-ng %s", MINIZIPNG_VERSION); +#else +#ifdef HAVE_MINIZIP + with_feature(l, "Minizip %s", MINIZIP_VERSION); +#else + without_feature(l, "Minizip"); +#endif +#endif /* HAVE_MINIZIPNG */ #ifdef QT_MULTIMEDIA_LIB with_feature(l, "QtMultimedia"); #else without_feature(l, "QtMultimedia"); #endif +#if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) +#ifdef QT_DBUS_LIB + with_feature(l, "QtDBus"); +#else + without_feature(l, "QtDBus"); +#endif +#endif /* !Q_OS_WIN && !Q_OS_MAC */ const char *update_info = software_update_info(); if (update_info) { @@ -228,12 +243,6 @@ gather_wireshark_qt_compiled_info(feature_list l) without_feature(l, "AirPcap"); #endif #endif /* _WIN32 */ - -#ifdef HAVE_MINIZIP - with_feature(l, "Minizip"); -#else - without_feature(l, "Minizip"); -#endif } void @@ -339,7 +348,7 @@ qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, const static void check_and_warn_user_startup() { - gchar *cur_user, *cur_group; + char *cur_user, *cur_group; /* Tell the user not to run as root. */ if (running_with_special_privs() && recent.privs_warn_if_elevated) { @@ -447,16 +456,15 @@ macos_enable_layer_backing(void) static GList * capture_opts_get_interface_list(int *err, char **err_str) { - /* - * XXX - should this pass an update callback? - * We already have a window up by the time we start parsing - * the majority of the command-line arguments, because - * we need to do a bunch of initialization work before - * parsing those arguments, and we want to let the user - * know that we're doing that initialization, given that - * it can take a while. - */ - return capture_interface_list(err, err_str, NULL); + if (mainApp) { + GList *if_list = mainApp->getInterfaceList(); + if (if_list == NULL) { + if_list = capture_interface_list(err, err_str, main_window_update); + mainApp->setInterfaceList(if_list); + } + return if_list; + } + return capture_interface_list(err, err_str, main_window_update); } #endif @@ -475,15 +483,15 @@ int main(int argc, char *qt_argv[]) char *rf_path; int rf_open_errno; #ifdef HAVE_LIBPCAP - gchar *err_str, *err_str_secondary;; + char *err_str, *err_str_secondary; #else #ifdef _WIN32 #ifdef HAVE_AIRPCAP - gchar *err_str; + char *err_str; #endif #endif #endif - gchar *err_msg = NULL; + char *err_msg = NULL; df_error_t *df_err = NULL; QString dfilter, read_filter; @@ -491,7 +499,7 @@ int main(int argc, char *qt_argv[]) int caps_queries = 0; #endif /* Start time in microseconds */ - guint64 start_time = g_get_monotonic_time(); + uint64_t start_time = g_get_monotonic_time(); static const struct report_message_routines wireshark_report_routines = { vfailure_alert_box, vwarning_alert_box, @@ -542,7 +550,7 @@ int main(int argc, char *qt_argv[]) /* Initialize log handler early so we can have proper logging during startup. */ ws_log_init("wireshark", vcmdarg_err); /* For backward compatibility with GLib logging and Wireshark 3.4. */ - ws_log_console_writer_set_use_stdout(TRUE); + ws_log_console_writer_set_use_stdout(true); qInstallMessageHandler(qt_log_message_handler); @@ -551,7 +559,7 @@ int main(int argc, char *qt_argv[]) #endif #ifdef DEBUG_STARTUP_TIME - prefs.gui_console_open = console_open_always; + ws_log_console_open = LOG_CONSOLE_OPEN_ALWAYS; #endif /* DEBUG_STARTUP_TIME */ #if defined(Q_OS_MAC) @@ -675,7 +683,7 @@ int main(int argc, char *qt_argv[]) g_free (rf_path); } - profile_store_persconffiles(TRUE); + profile_store_persconffiles(true); recent_init(); /* Read the profile independent recent file. We have to do this here so we can */ @@ -704,7 +712,7 @@ int main(int argc, char *qt_argv[]) // https://bugreports.qt.io/browse/QTBUG-53022 - The device pixel ratio is pretty much bogus on Windows. // https://bugreports.qt.io/browse/QTBUG-55510 - Windows have wrong size // - // Deprecated in Qt6. + // Deprecated in Qt6, which is Per-Monitor DPI Aware V2 by default. // warning: 'Qt::AA_EnableHighDpiScaling' is deprecated: High-DPI scaling is always enabled. // This attribute no longer has any effect. #if defined(Q_OS_WIN) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -762,8 +770,10 @@ int main(int argc, char *qt_argv[]) GLibMainloopOnQEventLoop::setup(main_w); // We may not need a queued connection here but it would seem to make sense // to force the issue. - main_w->connect(&ws_app, SIGNAL(openCaptureFile(QString,QString,unsigned int)), - main_w, SLOT(openCaptureFile(QString,QString,unsigned int))); + main_w->connect(&ws_app, &WiresharkApplication::openCaptureFile, + main_w, [&](QString cf_path, QString display_filter, unsigned int type) { + main_w->openCaptureFile(cf_path, display_filter, type); + }); main_w->connect(&ws_app, &WiresharkApplication::openCaptureOptions, main_w, &WiresharkMainWindow::showCaptureOptionsDialog); @@ -793,7 +803,7 @@ int main(int argc, char *qt_argv[]) * dissection-time handlers for file-type-dependent blocks can * register using the file type/subtype value for the file type. */ - wtap_init(TRUE); + wtap_init(true); splash_update(RA_DISSECTORS, NULL, NULL); #ifdef DEBUG_STARTUP_TIME @@ -803,14 +813,14 @@ int main(int argc, char *qt_argv[]) "-G" flag, as the "-G" flag dumps information registered by the dissectors, and we must do it before we read the preferences, in case any dissectors register preferences. */ - if (!epan_init(splash_update, NULL, TRUE)) { + if (!epan_init(splash_update, NULL, true)) { SimpleDialog::displayQueuedMessages(main_w); ret_val = WS_EXIT_INIT_FAILED; goto clean_exit; } #ifdef DEBUG_STARTUP_TIME /* epan_init resets the preferences */ - prefs.gui_console_open = console_open_always; + ws_log_console_open = LOG_CONSOLE_OPEN_ALWAYS; ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "epan done, elapsed time %" PRIu64 " us \n", g_get_monotonic_time() - start_time); #endif @@ -847,11 +857,6 @@ int main(int argc, char *qt_argv[]) in_file_type = open_info_name_to_type(ex_opt_get_next("read_format")); } -#ifdef DEBUG_STARTUP_TIME - ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Calling extcap_register_preferences, elapsed time %" PRIu64 " us \n", g_get_monotonic_time() - start_time); -#endif - splash_update(RA_EXTCAP, NULL, NULL); - extcap_register_preferences(); splash_update(RA_PREFERENCES, NULL, NULL); #ifdef DEBUG_STARTUP_TIME ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Calling module preferences, elapsed time %" PRIu64 " us \n", g_get_monotonic_time() - start_time); @@ -864,7 +869,17 @@ int main(int argc, char *qt_argv[]) * line, and store them. We have to do this before applying the * preferences to the capture options. */ - commandline_override_prefs(argc, argv, TRUE); + commandline_override_prefs(argc, argv, true); + + /* Register the extcap preferences. We do this after seeing if the + * capture_no_extcap preference is set in the configuration file + * or command line. This will re-read the extcap specific preferences. + */ +#ifdef DEBUG_STARTUP_TIME + ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Calling extcap_register_preferences, elapsed time %" PRIu64 " us \n", g_get_monotonic_time() - start_time); +#endif + splash_update(RA_EXTCAP, NULL, NULL); + extcap_register_preferences(); /* Some of the preferences affect the capture options. Apply those * before getting the other command line arguments, which can also @@ -875,7 +890,21 @@ int main(int argc, char *qt_argv[]) prefs_to_capture_opts(); /* Now get our remaining args */ - commandline_other_options(argc, argv, TRUE); + + /* XXX: Processing interface options on the command line might retrieve + * interface list. We don't yet know if we will need to retrieve the + * interface capabilities as well (e.g. are we printing capabilities, + * or loading the interface list?) until we parse other options, like + * whether we have a capture file. + * + * We'd prefer to avoid firing up dumpcap twice (once for the list + * without the capabilities and once for capabilities), especially + * on Windows where that could mean two UAC prompts. However, getting + * the interface capabilities is a bit time-consuming so we don't want + * to do it if we don't need to. + */ + + commandline_other_options(argc, argv, true); /* Convert some command-line parameters to QStrings */ if (global_commandline_info.cf_name != NULL) @@ -890,17 +919,9 @@ int main(int argc, char *qt_argv[]) timestamp_set_seconds_type (recent.gui_seconds_format); #ifdef HAVE_LIBPCAP -#ifdef DEBUG_STARTUP_TIME - ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Calling fill_in_local_interfaces, elapsed time %" PRIu64 " us \n", g_get_monotonic_time() - start_time); -#endif - splash_update(RA_INTERFACES, NULL, NULL); - - if (!global_commandline_info.cf_name && !prefs.capture_no_interface_load) - fill_in_local_interfaces(main_window_update); - - if (global_commandline_info.list_link_layer_types) + if (global_commandline_info.list_link_layer_types) caps_queries |= CAPS_QUERY_LINK_TYPES; - if (global_commandline_info.list_timestamp_types) + if (global_commandline_info.list_timestamp_types) caps_queries |= CAPS_QUERY_TIMESTAMP_TYPES; if (global_commandline_info.start_capture || caps_queries) { @@ -919,27 +940,41 @@ int main(int argc, char *qt_argv[]) * and exit. */ if (caps_queries) { - guint i; + unsigned i; #ifdef _WIN32 create_console(); #endif /* _WIN32 */ /* Get the list of link-layer types for the capture devices. */ ret_val = EXIT_SUCCESS; + GList *if_cap_queries = NULL; + if_cap_query_t *if_cap_query; + GHashTable *capability_hash; for (i = 0; i < global_capture_opts.ifaces->len; i++) { interface_options *interface_opts; - if_capabilities_t *caps; - char *auth_str = NULL; interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i); + if_cap_query = g_new(if_cap_query_t, 1); + if_cap_query->name = interface_opts->name; + if_cap_query->monitor_mode = interface_opts->monitor_mode; + if_cap_query->auth_username = NULL; + if_cap_query->auth_password = NULL; #ifdef HAVE_PCAP_REMOTE if (interface_opts->auth_type == CAPTURE_AUTH_PWD) { - auth_str = ws_strdup_printf("%s:%s", interface_opts->auth_username, interface_opts->auth_password); + if_cap_query->auth_username = interface_opts->auth_username; + if_cap_query->auth_password = interface_opts->auth_password; } #endif - caps = capture_get_if_capabilities(interface_opts->name, interface_opts->monitor_mode, - auth_str, &err_str, &err_str_secondary, NULL); - g_free(auth_str); + if_cap_queries = g_list_prepend(if_cap_queries, if_cap_query); + } + if_cap_queries = g_list_reverse(if_cap_queries); + capability_hash = capture_get_if_list_capabilities(if_cap_queries, &err_str, &err_str_secondary, NULL); + g_list_free_full(if_cap_queries, g_free); + for (i = 0; i < global_capture_opts.ifaces->len; i++) { + interface_options *interface_opts; + if_capabilities_t *caps; + interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i); + caps = static_cast<if_capabilities_t*>(g_hash_table_lookup(capability_hash, interface_opts->name)); if (caps == NULL) { cmdarg_err("%s%s%s", err_str, err_str_secondary ? "\n" : "", err_str_secondary ? err_str_secondary : ""); g_free(err_str); @@ -949,7 +984,6 @@ int main(int argc, char *qt_argv[]) } ret_val = capture_opts_print_if_capabilities(caps, interface_opts, caps_queries); - free_if_capabilities(caps); if (ret_val != EXIT_SUCCESS) { break; } @@ -957,9 +991,19 @@ int main(int argc, char *qt_argv[]) #ifdef _WIN32 destroy_console(); #endif /* _WIN32 */ + g_hash_table_destroy(capability_hash); goto clean_exit; } +#ifdef DEBUG_STARTUP_TIME + ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Calling fill_in_local_interfaces, elapsed time %" PRIu64 " us \n", g_get_monotonic_time() - start_time); +#endif + splash_update(RA_INTERFACES, NULL, NULL); + + if (!global_commandline_info.cf_name && !prefs.capture_no_interface_load) { + wsApp->scanLocalInterfaces(nullptr); + } + capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE); capture_opts_trim_ring_num_files(&global_capture_opts); #endif /* HAVE_LIBPCAP */ @@ -972,17 +1016,18 @@ int main(int argc, char *qt_argv[]) #endif splash_update(RA_PREFERENCES_APPLY, NULL, NULL); prefs_apply_all(); + wsApp->emitAppSignal(WiresharkApplication::ColorsChanged); wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged); #ifdef HAVE_LIBPCAP if ((global_capture_opts.num_selected == 0) && (prefs.capture_device != NULL)) { - guint i; + unsigned i; interface_t *device; for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (!device->hidden && strcmp(device->display_name, prefs.capture_device) == 0) { - device->selected = TRUE; + device->selected = true; global_capture_opts.num_selected++; break; } @@ -999,7 +1044,7 @@ int main(int argc, char *qt_argv[]) goto clean_exit; } - build_column_format_array(&CaptureFile::globalCapFile()->cinfo, global_commandline_info.prefs_p->num_cols, TRUE); + build_column_format_array(&CaptureFile::globalCapFile()->cinfo, global_commandline_info.prefs_p->num_cols, true); wsApp->emitAppSignal(WiresharkApplication::ColumnsChanged); // We read "recent" widths above. wsApp->emitAppSignal(WiresharkApplication::RecentPreferencesRead); // Must be emitted after PreferencesChanged. @@ -1022,7 +1067,7 @@ int main(int argc, char *qt_argv[]) * processEvents() here. */ wsApp->allSystemsGo(); - ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Wireshark is up and ready to go, elapsed time %.3fs", (float) (g_get_monotonic_time() - start_time) / 1000000); + ws_info("Wireshark is up and ready to go, elapsed time %.3fs", (float) (g_get_monotonic_time() - start_time) / 1000000); SimpleDialog::displayQueuedMessages(main_w); /* User could specify filename, or display filter, or both */ @@ -1043,7 +1088,7 @@ int main(int argc, char *qt_argv[]) if (global_commandline_info.go_to_packet != 0) { /* Jump to the specified frame number, kept for backward compatibility. */ - cf_goto_frame(CaptureFile::globalCapFile(), global_commandline_info.go_to_packet); + cf_goto_frame(CaptureFile::globalCapFile(), global_commandline_info.go_to_packet, false); } else if (global_commandline_info.jfilter != NULL) { dfilter_t *jump_to_filter = NULL; /* try to compile given filter */ @@ -1069,7 +1114,7 @@ int main(int argc, char *qt_argv[]) if (global_capture_opts.save_file != NULL) { /* Save the directory name for future file dialogs. */ /* (get_dirname overwrites filename) */ - gchar *s = g_strdup(global_capture_opts.save_file); + char *s = g_strdup(global_capture_opts.save_file); set_last_open_dir(get_dirname(s)); g_free(s); } @@ -1079,6 +1124,9 @@ int main(int argc, char *qt_argv[]) /* If no user interfaces were specified on the command line, copy the list of selected interfaces to the set of interfaces to use for this capture. */ + /* XXX: I don't think this can happen, because if start_capture is + * true then capture_opts_default_iface_if_necessary() was called + */ if (global_capture_opts.ifaces->len == 0) collect_ifaces(&global_capture_opts); CaptureFile::globalCapFile()->window = main_w; @@ -1106,8 +1154,10 @@ int main(int argc, char *qt_argv[]) // loaded when the dialog is shown. Register them here. profile_register_persconffile("io_graphs"); profile_register_persconffile("import_hexdump.json"); + profile_register_persconffile("remote_hosts.json"); - profile_store_persconffiles(FALSE); + profile_store_persconffiles(false); + init_profile_list(); // If the wsApp->exec() event loop exits cleanly, we call // WiresharkApplication::cleanup(). |