Change a lot of http:// URLs to https://.
[metze/wireshark/wip.git] / ui / gtk / main.c
index a78edc01b891236e803de6abfb4efda604176aaa..bf31fec78a540e36c046c7fc6bd9957730a0d196 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifndef HAVE_GETOPT
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#ifndef HAVE_GETOPT_LONG
 #include "wsutil/wsgetopt.h"
 #endif
 
 #endif /* HAVE_LIBPORTAUDIO */
 
 #include <wsutil/clopts_common.h>
+#include <wsutil/copyright_info.h>
 #include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
 #include <wsutil/report_err.h>
 #include <wsutil/u3.h>
-#include <wsutil/copyright_info.h>
-#include <wsutil/os_version_info.h>
+#include <wsutil/ws_diag_control.h>
 #include <wsutil/ws_version_info.h>
 
 #include <wiretap/merge.h>
@@ -73,7 +77,6 @@
 #include <epan/epan_dissect.h>
 #include <epan/dfilter/dfilter.h>
 #include <epan/strutil.h>
-#include <epan/emem.h>
 #include <epan/ex-opt.h>
 #include <epan/funnel.h>
 #include <epan/expert.h>
 #include <epan/timestamp.h>
 #include <epan/conversation_table.h>
 
+#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
+#include <epan/asn1.h>
+#include <epan/dissectors/packet-kerberos.h>
+#endif
+
 #include <wsutil/cmdarg_err.h>
 #include <wsutil/plugins.h>
 
 #include "../color_filters.h"
 #include "../register.h"
 #include "../ringbuffer.h"
-#include "../version_info.h"
 #include "../log.h"
 
 #include "gtk_iface_monitor.h"
 #include "caputils/capture-wpcap.h"
 #include "caputils/capture_wpcap_packet.h"
 #include <tchar.h> /* Needed for Unicode */
+#include <wsutil/os_version_info.h>
 #include <wsutil/unicode-utils.h>
 #include <commctrl.h>
 #include <shellapi.h>
@@ -339,6 +347,7 @@ match_selected_ptree_cb(gpointer data, MATCH_SELECTED_E action)
         filter = proto_construct_match_selected_string(cfile.finfo_selected,
                                                        cfile.edt);
         match_selected_cb_do((GtkWidget *)g_object_get_data(G_OBJECT(data), E_DFILTER_TE_KEY), action, filter);
+        wmem_free(NULL, filter);
     }
 }
 
@@ -367,6 +376,7 @@ colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr)
             }
             packet_list_colorize_packets();
         }
+        wmem_free(NULL, filter);
     }
 }
 
@@ -381,7 +391,7 @@ static void selected_ptree_info_answered_cb(gpointer dialog _U_, gint btn, gpoin
     case(ESD_BTN_OK):
         if (cfile.finfo_selected) {
             /* open wiki page using the protocol abbreviation */
-            selected_proto_url = g_strdup_printf("http://wiki.wireshark.org/Protocols/%s", proto_abbrev);
+            selected_proto_url = g_strdup_printf("https://wiki.wireshark.org/Protocols/%s", proto_abbrev);
             browser_open_url(selected_proto_url);
             g_free(selected_proto_url);
         }
@@ -460,7 +470,7 @@ static void selected_ptree_ref_answered_cb(gpointer dialog _U_, gint btn, gpoint
     case(ESD_BTN_OK):
         if (cfile.finfo_selected) {
             /* open reference page using the protocol abbreviation */
-            selected_proto_url = g_strdup_printf("http://www.wireshark.org/docs/dfref/%c/%s", proto_abbrev[0], proto_abbrev);
+            selected_proto_url = g_strdup_printf("https://www.wireshark.org/docs/dfref/%c/%s", proto_abbrev[0], proto_abbrev);
             browser_open_url(selected_proto_url);
             g_free(selected_proto_url);
         }
@@ -609,7 +619,7 @@ get_filter_from_packet_list_row_and_column(gpointer data)
              */
             if (strlen(cfile.cinfo.col_expr.col_expr[column]) != 0 &&
                 strlen(cfile.cinfo.col_expr.col_expr_val[column]) != 0) {
-                /* leak a little but safer than ep_ here */
+                /* leak a little; is there a safe wmem_ scope here? */
                 if (cfile.cinfo.col_fmt[column] == COL_CUSTOM) {
                     header_field_info *hfi = proto_registrar_get_byname(cfile.cinfo.col_custom_field[column]);
                     if (hfi && hfi->parent == -1) {
@@ -1167,7 +1177,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;
@@ -1255,20 +1265,6 @@ print_usage(gboolean for_help_option) {
 #endif
 }
 
-static void
-show_version(void)
-{
-    printf("Wireshark %s\n"
-           "\n"
-           "%s"
-           "\n"
-           "%s"
-           "\n"
-           "%s",
-        get_ws_vcs_version_info(), get_copyright_info(), comp_info_str->str,
-        runtime_info_str->str);
-}
-
 /*
  * Report an error in command-line arguments.
  * Creates a console on Windows.
@@ -2110,7 +2106,7 @@ check_and_warn_user_startup(gchar *cf_name _U_)
         "This could be dangerous.\n\n"
         "If you're running Wireshark this way in order to perform live capture, "
         "you may want to be aware that there is a better way documented at\n"
-        "http://wiki.wireshark.org/CaptureSetup/CapturePrivileges", cur_user, cur_group);
+        "https://wiki.wireshark.org/CaptureSetup/CapturePrivileges", cur_user, cur_group);
         g_free(cur_user);
         g_free(cur_group);
         simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
@@ -2167,6 +2163,7 @@ main(int argc, char *argv[])
     gint                 pl_size = 280, tv_size = 95, bv_size = 75;
     gchar               *rc_file, *cf_name = NULL, *rfilter = NULL, *dfilter = NULL, *jfilter = NULL;
     dfilter_t           *rfcode = NULL;
+    gchar               *err_msg;
     gboolean             rfilter_parse_failed = FALSE;
     e_prefs             *prefs_p;
     char                 badopt;
@@ -2174,14 +2171,23 @@ main(int argc, char *argv[])
     guint                go_to_packet = 0;
     search_direction     jump_backwards = SD_FORWARD;
     dfilter_t           *jump_to_filter = NULL;
-    int                  optind_initial;
     unsigned int         in_file_type = WTAP_TYPE_AUTO;
 #ifdef HAVE_GTKOSXAPPLICATION
     GtkosxApplication   *theApp;
 #endif
 
 #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'},
+        LONGOPT_CAPTURE_COMMON
+        {0, 0, 0, 0 }
+    };
+DIAG_ON(cast-qual)
     static const char optstring[] = OPTSTRING;
 
     cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
@@ -2204,7 +2210,7 @@ main(int argc, char *argv[])
     /*
      * Attempt to get the pathname of the executable file.
      */
-    init_progfile_dir_error = init_progfile_dir(argv[0], main);
+    init_progfile_dir_error = init_progfile_dir(argv[0], (void *)main);
 
     /* initialize the funnel mini-api */
     initialize_funnel_ops();
@@ -2261,15 +2267,12 @@ main(int argc, char *argv[])
 #endif /* HAVE_AIRPCAP */
 #endif  /* _WIN32 */
 
-    /* Assemble the compile-time version information string */
-    comp_info_str = g_string_new("Compiled ");
-
-    get_compiled_version_info(comp_info_str, get_wireshark_gtk_compiled_info,
-                              get_gui_compiled_info);
+    /* Get the compile-time version information string */
+    comp_info_str = get_compiled_version_info(get_wireshark_gtk_compiled_info,
+                                              get_gui_compiled_info);
 
-    /* Assemble the run-time version information string */
-    runtime_info_str = g_string_new("Running ");
-    get_runtime_version_info(runtime_info_str, get_wireshark_runtime_info);
+    /* Get the run-time version information string */
+    runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info);
 
     /* Add it to the information to be reported on a crash. */
     ws_add_crash_info("Wireshark %s\n"
@@ -2295,20 +2298,41 @@ main(int argc, char *argv[])
                       rf_path, g_strerror(rf_open_errno));
     }
 
-    /* "pre-scan" the command line parameters, if we have "console only"
-       parameters.  We do this so we don't start GTK+ if we're only showing
-       command-line help or version information.
-
-       XXX - this pre-scan is done before we start GTK+, so we haven't
-       run gtk_init() on the arguments.  That means that GTK+ arguments
-       have not been removed from the argument list; those arguments
-       begin with "--", and will be treated as an error by getopt().
-
-       We thus ignore errors - *and* set "opterr" to 0 to suppress the
-       error messages. */
+    /*
+     * In order to have the -X opts assigned before the wslua machine starts
+     * we need to call getopt_long before epan_init() gets called.
+     *
+     * In addition, we process "console only" parameters (ones where we
+     * send output to the console and exit) here, so we don't start GTK+
+     * if we're only showing command-line help or version information.
+     *
+     * XXX - this pre-scan is done before we start GTK+, so we haven't
+     * run gtk_init() on the arguments.  That means that GTK+ arguments
+     * have not been removed from the argument list; those arguments
+     * begin with "--", and will be treated as an error by getopt_long().
+     *
+     * We thus ignore errors - *and* set "opterr" to 0 to suppress the
+     * error messages.
+     *
+     * XXX - should we, instead, first call gtk_parse_args(), without
+     * calling gtk_init(), and then call this?
+     *
+     * In order to handle, for example, -o options, we also need to call it
+     * *after* epan_init() gets called, so that the dissectors have had a
+     * chance to register their preferences, so we have another getopt_long()
+     * call later.
+     *
+     * XXX - can we do this all with one getopt_long() call, saving the
+     * arguments we can't handle until after initializing libwireshark,
+     * and then process them after initializing libwireshark?
+     *
+     * Note that we don't want to initialize libwireshark until after the
+     * GUI is up, as that can take a while, and we want a window of some
+     * sort up to show progress while that's happening.
+     */
     opterr = 0;
-    optind_initial = optind;
-    while ((opt = getopt(argc, argv, optstring)) != -1) {
+
+    while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
         switch (opt) {
             case 'C':        /* Configuration Profile */
                 if (profile_exists (optarg, FALSE)) {
@@ -2320,7 +2344,7 @@ main(int argc, char *argv[])
                 break;
             case 'D':        /* Print a list of capture devices and exit */
 #ifdef HAVE_LIBPCAP
-                if_list = capture_interface_list(&err, &err_str,main_window_update);
+                if_list = capture_interface_list(&err, &err_str, NULL);
                 if (if_list == NULL) {
                     if (err == 0)
                         cmdarg_err("There are no interfaces on which a capture can be done");
@@ -2364,7 +2388,7 @@ main(int argc, char *argv[])
 #ifdef _WIN32
                 create_console();
 #endif
-                show_version();
+                show_version("Wireshark", comp_info_str, runtime_info_str);
 #ifdef _WIN32
                 destroy_console();
 #endif
@@ -2404,42 +2428,6 @@ main(int argc, char *argv[])
         set_last_open_dir(get_persdatafile_dir());
     }
 
-    /* Set getopt index back to initial value, so it will start with the
-       first command line parameter again.  Also reset opterr to 1, so that
-       error messages are printed by getopt().
-
-       XXX - this seems to work on most platforms, but time will tell.
-       The Single UNIX Specification says "The getopt() function need
-       not be reentrant", so this isn't guaranteed to work.  The Mac
-       OS X 10.4[.x] getopt() man page says
-
-         In order to use getopt() to evaluate multiple sets of arguments, or to
-         evaluate a single set of arguments multiple times, the variable optreset
-         must be set to 1 before the second and each additional set of calls to
-         getopt(), and the variable optind must be reinitialized.
-
-           ...
-
-         The optreset variable was added to make it possible to call the getopt()
-         function multiple times.  This is an extension to the IEEE Std 1003.2
-         (``POSIX.2'') specification.
-
-       which I think comes from one of the other BSDs.
-
-       XXX - if we want to control all the command-line option errors, so
-       that we can display them where we choose (e.g., in a window), we'd
-       want to leave opterr as 0, and produce our own messages using optopt.
-       We'd have to check the value of optopt to see if it's a valid option
-       letter, in which case *presumably* the error is "this option requires
-       an argument but none was specified", or not a valid option letter,
-       in which case *presumably* the error is "this option isn't valid".
-       Some versions of getopt() let you supply a option string beginning
-       with ':', which means that getopt() will return ':' rather than '?'
-       for "this option requires an argument but none was specified", but
-       not all do. */
-    optind = optind_initial;
-    opterr = 1;
-
 #if !GLIB_CHECK_VERSION(2,31,0)
     g_thread_init(NULL);
 #endif
@@ -2469,7 +2457,7 @@ main(int argc, char *argv[])
        by preference settings and then again by the command line parameters. */
     capture_opts_init(&global_capture_opts);
 
-    capture_session_init(&global_capture_session, (void *)&cfile);
+    capture_session_init(&global_capture_session, &cfile);
 #endif
 
     init_report_err(failure_alert_box, open_failure_alert_box,
@@ -2560,8 +2548,42 @@ main(int argc, char *argv[])
 /*#ifdef HAVE_LIBPCAP
     fill_in_local_interfaces();
 #endif*/
+    /*
+     * To reset the options parser, set optreset to 1 on platforms that
+     * have optreset (documented in *BSD and OS X, apparently present but
+     * not documented in Solaris - the Illumos repository seems to
+     * suggest that the first Solaris getopt_long(), at least as of 2004,
+     * was based on the NetBSD one, it had optreset) and set optind to 1,
+     * and set optind to 0 otherwise (documented as working in the GNU
+     * getopt_long().  Setting optind to 0 didn't originally work in the
+     * NetBSD one, but that was added later - we don't want to depend on
+     * it if we have optreset).
+     *
+     * Also reset opterr to 1, so that error messages are printed by
+     * getopt_long().
+     *
+     * XXX - if we want to control all the command-line option errors, so
+     * that we can display them where we choose (e.g., in a window), we'd
+     * want to leave opterr as 0, and produce our own messages using optopt.
+     * We'd have to check the value of optopt to see if it's a valid option
+     * letter, in which case *presumably* the error is "this option requires
+     * an argument but none was specified", or not a valid option letter,
+     * in which case *presumably* the error is "this option isn't valid".
+     * Some versions of getopt() let you supply a option string beginning
+     * with ':', which means that getopt() will return ':' rather than '?'
+     * for "this option requires an argument but none was specified", but
+     * not all do.  But we're now using getopt_long() - what does it do?
+     */
+#ifdef HAVE_OPTRESET
+    optreset = 1;
+    optind = 1;
+#else
+    optind = 0;
+#endif
+    opterr = 1;
+
     /* Now get our args */
-    while ((opt = getopt(argc, argv, optstring)) != -1) {
+    while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
         switch (opt) {
             /*** capture option specific ***/
             case 'a':        /* autostop criteria */
@@ -2759,6 +2781,11 @@ main(int argc, char *argv[])
                  by the preferences set callback) from being used as
                  part of a tap filter.  Instead, we just add the argument
                  to a list of stat arguments. */
+                if (strcmp("help", optarg) == 0) {
+                  fprintf(stderr, "wireshark: The available statistics for the \"-z\" option are:\n");
+                  list_stat_cmd_args();
+                  exit(0);
+                }
                 if (!process_stat_cmd_arg(optarg)) {
                     cmdarg_err("Invalid -z argument.");
                     cmdarg_err_cont("  -z argument must be one of :");
@@ -3058,8 +3085,9 @@ main(int argc, char *argv[])
         show_main_window(TRUE);
         check_and_warn_user_startup(cf_name);
         if (rfilter != NULL) {
-            if (!dfilter_compile(rfilter, &rfcode)) {
-                bad_dfilter_alert_box(top_level, rfilter);
+            if (!dfilter_compile(rfilter, &rfcode, &err_msg)) {
+                bad_dfilter_alert_box(top_level, rfilter, err_msg);
+                g_free(err_msg);
                 rfilter_parse_failed = TRUE;
             }
         }
@@ -3097,8 +3125,9 @@ main(int argc, char *argv[])
                             cf_goto_frame(&cfile, go_to_packet);
                         } else if (jfilter != NULL) {
                             /* try to compile given filter */
-                            if (!dfilter_compile(jfilter, &jump_to_filter)) {
-                                bad_dfilter_alert_box(top_level, jfilter);
+                            if (!dfilter_compile(jfilter, &jump_to_filter, &err_msg)) {
+                                bad_dfilter_alert_box(top_level, jfilter, err_msg);
+                                g_free(err_msg);
                             } else {
                             /* Filter ok, jump to the first packet matching the filter
                                conditions. Default search direction is forward, but if
@@ -3769,7 +3798,6 @@ void change_configuration_profile (const gchar *profile_name)
     /* Set profile name and update the status bar */
     set_profile_name (profile_name);
     profile_bar_update ();
-    filter_expression_reinit(FILTER_EXPRESSION_REINIT_DESTROY);
 
     /* Reset current preferences and apply the new */
     prefs_reset();
@@ -3835,7 +3863,7 @@ main_fields_changed (void)
     if (cfile.dfilter) {
         /* Check if filter is still valid */
         dfilter_t *dfp = NULL;
-        if (!dfilter_compile(cfile.dfilter, &dfp)) {
+        if (!dfilter_compile(cfile.dfilter, &dfp, NULL)) {
             /* Not valid.  Enable 'Apply' button and remove dfilter. */
             g_signal_emit_by_name(G_OBJECT(main_display_filter_widget), "changed");
             g_free(cfile.dfilter);