btbredr: fix NESTING_INDENT_MISMATCH (CID 1358479)
[metze/wireshark/wip.git] / wireshark-qt.cpp
index 6ac94b451ca24720aa38dd2fe0d5f36dd8f99af7..9b45ec6371c0a06aad4b235b04eef625da813aa5 100644 (file)
 #include <signal.h>
 #endif
 
-#ifdef HAVE_LIBZ
-#include <zlib.h>       /* to get the libz version number */
-#endif
-
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
@@ -48,9 +44,7 @@
 #include <wsutil/plugins.h>
 #endif
 #include <wsutil/report_err.h>
-#include <wsutil/u3.h>
 #include <wsutil/unicode-utils.h>
-#include <wsutil/ws_diag_control.h>
 #include <wsutil/ws_version_info.h>
 
 #include <epan/addr_resolv.h>
 #include <codecs/codecs.h>
 #endif
 
+#ifdef HAVE_EXTCAP
+#include <extcap.h>
+#endif
+
 /* general (not Qt specific) */
 #include "file.h"
-#include "color.h"
-#include "color_filters.h"
+#include "epan/color_filters.h"
 #include "log.h"
 
 #include "epan/rtd_table.h"
@@ -89,6 +86,8 @@
 #include "ui/util.h"
 
 #include "ui/qt/conversation_dialog.h"
+#include "ui/qt/color_utils.h"
+#include "ui/qt/coloring_rules_dialog.h"
 #include "ui/qt/endpoint_dialog.h"
 #include "ui/qt/main_window.h"
 #include "ui/qt/response_time_delay_dialog.h"
@@ -164,7 +163,7 @@ print_usage(gboolean for_help_option) {
         output = stdout;
         fprintf(output, "Wireshark %s\n"
                 "Interactively dump and analyze network traffic.\n"
-                "See http://www.wireshark.org for more information.\n",
+                "See https://www.wireshark.org for more information.\n",
                 get_ws_vcs_version_info());
     } else {
         output = stderr;
@@ -215,7 +214,7 @@ print_usage(gboolean for_help_option) {
     fprintf(output, "Processing:\n");
     fprintf(output, "  -R <read filter>         packet filter in Wireshark display filter syntax\n");
     fprintf(output, "  -n                       disable all name resolutions (def: all enabled)\n");
-    fprintf(output, "  -N <name resolve flags>  enable specific name resolution(s): \"mntC\"\n");
+    fprintf(output, "  -N <name resolve flags>  enable specific name resolution(s): \"mnNtd\"\n");
     fprintf(output, "  --disable-protocol <proto_name>\n");
     fprintf(output, "                           disable dissection of proto_name\n");
     fprintf(output, "  --enable-heuristic <short_name>\n");
@@ -307,19 +306,6 @@ get_wireshark_qt_compiled_info(GString *str)
     /* Capture libraries */
     g_string_append(str, ", ");
     get_compiled_caplibs_version(str);
-
-    /* LIBZ */
-    g_string_append(str, ", ");
-#ifdef HAVE_LIBZ
-    g_string_append(str, "with libz ");
-#ifdef ZLIB_VERSION
-    g_string_append(str, ZLIB_VERSION);
-#else /* ZLIB_VERSION */
-    g_string_append(str, "(version unknown)");
-#endif /* ZLIB_VERSION */
-#else /* HAVE_LIBZ */
-    g_string_append(str, "without libz");
-#endif /* HAVE_LIBZ */
 }
 
 // xxx copied from ../gtk/main.c
@@ -329,7 +315,11 @@ get_gui_compiled_info(GString *str)
     epan_get_compiled_version_info(str);
 
     g_string_append(str, ", ");
-    g_string_append(str, "without PortAudio");
+#ifdef QT_MULTIMEDIA_LIB
+    g_string_append(str, "with QtMultimedia");
+#else
+    g_string_append(str, "without QtMultimedia");
+#endif
 
     g_string_append(str, ", ");
 #ifdef HAVE_AIRPCAP
@@ -349,11 +339,6 @@ get_wireshark_runtime_info(GString *str)
     get_runtime_caplibs_version(str);
 #endif
 
-    /* zlib */
-#if defined(HAVE_LIBZ) && !defined(_WIN32)
-    g_string_append_printf(str, ", with libz %s", zlibVersion());
-#endif
-
     /* stuff used by libwireshark */
     epan_get_runtime_version_info(str);
 
@@ -361,11 +346,6 @@ get_wireshark_runtime_info(GString *str)
     g_string_append(str, ", ");
     get_runtime_airpcap_version(str);
 #endif
-
-    if(u3_active()) {
-        g_string_append(str, ", ");
-        u3_runtime_info(str);
-    }
 }
 
 #ifdef HAVE_LIBPCAP
@@ -514,7 +494,7 @@ int main(int argc, char *argv[])
      * Attempt to get the pathname of the executable file.
      */
     /* init_progfile_dir_error = */ init_progfile_dir(ws_argv[0],
-        (void *) get_gui_compiled_info);
+        (int (*)(int, char **)) get_gui_compiled_info);
     g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir());
 
 #ifdef _WIN32
@@ -612,17 +592,15 @@ int main(int argc, char *argv[])
      */
     // XXX Should the remaining code be in WiresharkApplcation::WiresharkApplication?
 #define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:g:Hh" "jJ:kK:lm:nN:o:P:r:R:St:u:vw:X:Y:z:"
-DIAG_OFF(cast-qual)
     static const struct option long_options[] = {
-        {(char *)"help", no_argument, NULL, 'h'},
-        {(char *)"read-file", required_argument, NULL, 'r' },
-        {(char *)"read-filter", required_argument, NULL, 'R' },
-        {(char *)"display-filter", required_argument, NULL, 'Y' },
-        {(char *)"version", no_argument, NULL, 'v'},
+        {"help", no_argument, NULL, 'h'},
+        {"read-file", required_argument, NULL, 'r' },
+        {"read-filter", required_argument, NULL, 'R' },
+        {"display-filter", required_argument, NULL, 'Y' },
+        {"version", no_argument, NULL, 'v'},
         LONGOPT_CAPTURE_COMMON
         {0, 0, 0, 0 }
     };
-DIAG_ON(cast-qual)
     static const char optstring[] = OPTSTRING;
 
     opterr = 0;
@@ -736,26 +714,24 @@ DIAG_ON(cast-qual)
 
     /* Read the profile independent recent file.  We have to do this here so we can */
     /* set the profile before it can be set from the command line parameter */
-    recent_read_static(&rf_path, &rf_open_errno);
-    if (rf_path != NULL && rf_open_errno != 0) {
+    if (!recent_read_static(&rf_path, &rf_open_errno)) {
         simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                       "Could not open common recent file\n\"%s\": %s.",
                       rf_path, strerror(rf_open_errno));
+        g_free(rf_path);
     }
 
-    /* Init the "Open file" dialog directory */
-    /* (do this after the path settings are processed) */
-
     /* Read the profile dependent (static part) of the recent file. */
     /* Only the static part of it will be read, as we don't have the gui now to fill the */
     /* recent lists which is done in the dynamic part. */
     /* We have to do this already here, so command line parameters can overwrite these values. */
-    recent_read_profile_static(&rf_path, &rf_open_errno);
-    if (rf_path != NULL && rf_open_errno != 0) {
+    if (!recent_read_profile_static(&rf_path, &rf_open_errno)) {
         simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                       "Could not open recent file\n\"%s\": %s.",
                       rf_path, g_strerror(rf_open_errno));
+        g_free(rf_path);
     }
+    wsApp->applyCustomColorsFromRecent();
 
     // Initialize our language
     read_language_prefs();
@@ -769,23 +745,11 @@ DIAG_ON(cast-qual)
     main_w->show();
     // 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, SIGNAL(openCaptureFile(QString,QString,unsigned int)),
+            main_w, SLOT(openCaptureFile(QString,QString,unsigned int)));
 
     /* Init the "Open file" dialog directory */
     /* (do this after the path settings are processed) */
-
-    /* Read the profile dependent (static part) of the recent file. */
-    /* Only the static part of it will be read, as we don't have the gui now to fill the */
-    /* recent lists which is done in the dynamic part. */
-    /* We have to do this already here, so command line parameters can overwrite these values. */
-    recent_read_profile_static(&rf_path, &rf_open_errno);
-    if (rf_path != NULL && rf_open_errno != 0) {
-      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
-            "Could not open recent file\n\"%s\": %s.",
-            rf_path, g_strerror(rf_open_errno));
-    }
-
     if (recent.gui_fileopen_remembered_dir &&
         test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
       wsApp->setLastOpenDir(recent.gui_fileopen_remembered_dir);
@@ -806,7 +770,7 @@ DIAG_ON(cast-qual)
     capture_opts_init(&global_capture_opts);
 #endif
 
-    init_report_err(failure_alert_box, open_failure_alert_box,
+    init_report_err(vfailure_alert_box, open_failure_alert_box,
                     read_failure_alert_box, write_failure_alert_box);
 
     init_open_routines();
@@ -815,7 +779,7 @@ DIAG_ON(cast-qual)
     /* Register all the plugin types we have. */
     epan_register_plugin_types(); /* Types known to libwireshark */
     wtap_register_plugin_types(); /* Types known to libwiretap */
-    codec_register_plugin_types(); /* Types known to libcodec */
+    codec_register_plugin_types(); /* Types known to libwscodecs */
 
     /* Scan for plugins.  This does *not* call their registration routines;
        that's done later. */
@@ -832,8 +796,11 @@ DIAG_ON(cast-qual)
        "-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. */
-    epan_init(register_all_protocols,register_all_protocol_handoffs,
-              splash_update, NULL);
+    if (!epan_init(register_all_protocols,register_all_protocol_handoffs,
+                   splash_update, NULL)) {
+        SimpleDialog::displayQueuedMessages(main_w);
+        return 2;
+    }
 
     splash_update(RA_LISTENERS, NULL, NULL);
 
@@ -847,6 +814,10 @@ DIAG_ON(cast-qual)
     register_all_plugin_tap_listeners();
 #endif
 
+#ifdef HAVE_EXTCAP
+    extcap_register_preferences();
+#endif
+
     register_all_tap_listeners();
     conversation_table_set_gui_info(init_conversation_table);
     hostlist_table_set_gui_info(init_endpoint_table);
@@ -860,7 +831,7 @@ DIAG_ON(cast-qual)
 
     splash_update(RA_PREFERENCES, NULL, NULL);
 
-    prefs_p = ws_app.readConfigurationFiles(&gdp_path, &dp_path);
+    prefs_p = ws_app.readConfigurationFiles(&gdp_path, &dp_path, false);
 
     /*
      * To reset the options parser, set optreset to 1 on platforms that
@@ -971,15 +942,12 @@ DIAG_ON(cast-qual)
             /* Not supported yet */
             break;
         case 'n':        /* No name resolution */
-            gbl_resolv_flags.mac_name = FALSE;
-            gbl_resolv_flags.network_name = FALSE;
-            gbl_resolv_flags.transport_name = FALSE;
-            gbl_resolv_flags.concurrent_dns = FALSE;
+            disable_name_resolution();
             break;
         case 'N':        /* Select what types of addresses/port #s to resolve */
             badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
             if (badopt != '\0') {
-                cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
+                cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'd', m', 'n', 'N', and 't'",
                            badopt);
                 exit(1);
             }
@@ -1174,7 +1142,7 @@ DIAG_ON(cast-qual)
     // XXX Is there a better place to set the timestamp format & precision?
     timestamp_set_type(recent.gui_time_format);
     timestamp_set_precision(recent.gui_time_precision);
-    timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
+    timestamp_set_seconds_type (recent.gui_seconds_format);
 
 #ifdef HAVE_LIBPCAP
     fill_in_local_interfaces(main_window_update);
@@ -1342,27 +1310,33 @@ DIAG_ON(cast-qual)
 
     wsApp->setMonospaceFont(prefs.gui_qt_font_name);
 
+    /* For update of WindowTitle (When use gui.window_title preference) */
+    main_w->setWSWindowTitle();
 ////////
 
     /* Read the dynamic part of the recent file, as we have the gui now ready for
        it. */
-    recent_read_dynamic(&rf_path, &rf_open_errno);
-    if (rf_path != NULL && rf_open_errno != 0) {
+    if (!recent_read_dynamic(&rf_path, &rf_open_errno)) {
         simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                       "Could not open recent file\n\"%s\": %s.",
                       rf_path, g_strerror(rf_open_errno));
+        g_free(rf_path);
     }
 
-    color_filters_enable(recent.packet_list_colorize);
+    packet_list_enable_color(recent.packet_list_colorize);
 
     g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings");
-    color_filters_enable(TRUE);
+    packet_list_enable_color(TRUE);
 
 ////////
 
 
 ////////
-    color_filters_init();
+    gchar* err_msg = NULL;
+    if (!color_filters_init(&err_msg, color_filter_add_cb)) {
+        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
+        g_free(err_msg);
+    }
 
 ////////
 
@@ -1380,10 +1354,10 @@ DIAG_ON(cast-qual)
     SimpleDialog::displayQueuedMessages(main_w);
 
     /* User could specify filename, or display filter, or both */
+    if (!dfilter.isEmpty())
+        main_w->filterPackets(dfilter, false);
     if (!cf_name.isEmpty()) {
         if (main_w->openCaptureFile(cf_name, read_filter, in_file_type)) {
-            if (!dfilter.isEmpty())
-                main_w->filterPackets(dfilter, false);
 
             /* Open stat windows; we do so after creating the main window,
                to avoid Qt warnings, and after successfully opening the
@@ -1407,8 +1381,8 @@ DIAG_ON(cast-qual)
             if (global_capture_opts.save_file != NULL) {
                 /* Save the directory name for future file dialogs. */
                 /* (get_dirname overwrites filename) */
-                gchar *s = get_dirname(g_strdup(global_capture_opts.save_file));
-                set_last_open_dir(s);
+                gchar *s = g_strdup(global_capture_opts.save_file);
+                set_last_open_dir(get_dirname(s));
                 g_free(s);
             }
             /* "-k" was specified; start a capture. */
@@ -1421,7 +1395,7 @@ DIAG_ON(cast-qual)
             if (global_capture_opts.ifaces->len == 0)
                 collect_ifaces(&global_capture_opts);
             CaptureFile::globalCapFile()->window = main_w;
-            if (capture_start(&global_capture_opts, main_w->captureSession(), main_window_update)) {
+            if (capture_start(&global_capture_opts, main_w->captureSession(), main_w->captureInfoData(), main_window_update)) {
                 /* The capture started.  Open stat windows; we do so after creating
                    the main window, to avoid GTK warnings, and after successfully
                    opening the capture file, so we know we have something to compute