btbredr: fix NESTING_INDENT_MISMATCH (CID 1358479)
[metze/wireshark/wip.git] / wireshark-qt.cpp
index 64604c3cb4f8debaf5e419ab3feee7074adac58a..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"
@@ -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): \"mnNtCd\"\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
@@ -353,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);
 
@@ -365,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
@@ -518,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
@@ -616,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;
@@ -747,9 +721,6 @@ DIAG_ON(cast-qual)
         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. */
@@ -760,6 +731,7 @@ DIAG_ON(cast-qual)
                       rf_path, g_strerror(rf_open_errno));
         g_free(rf_path);
     }
+    wsApp->applyCustomColorsFromRecent();
 
     // Initialize our language
     read_language_prefs();
@@ -778,18 +750,6 @@ DIAG_ON(cast-qual)
 
     /* 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. */
-    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);
-    }
-
     if (recent.gui_fileopen_remembered_dir &&
         test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
       wsApp->setLastOpenDir(recent.gui_fileopen_remembered_dir);
@@ -810,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();
@@ -819,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. */
@@ -854,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);
@@ -867,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
@@ -983,7 +947,7 @@ DIAG_ON(cast-qual)
         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 'C', 'd', m', 'n', 'N', and 't'",
+                cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'd', m', 'n', 'N', and 't'",
                            badopt);
                 exit(1);
             }
@@ -1178,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);
@@ -1346,6 +1310,8 @@ 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
@@ -1357,16 +1323,20 @@ DIAG_ON(cast-qual)
         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);
+    }
 
 ////////
 
@@ -1384,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
@@ -1411,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. */
@@ -1425,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