Add routines to set the personal file directory paths (personal
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 19 Nov 2013 19:45:38 +0000 (19:45 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 19 Nov 2013 19:45:38 +0000 (19:45 +0000)
configuration file directory and directory in which to save captures),
have the routine to parse -P options use them, and move that routine to
libui.

Have that routine just return a gboolean.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@53435 f5534014-38df-0310-8fa8-9805f1628bb7

ui/CMakeLists.txt
ui/Makefile.common
ui/gtk/main.c
ui/persfilepath_opt.c [new file with mode: 0644]
ui/persfilepath_opt.h [new file with mode: 0644]
ui/qt/main.cpp
wsutil/filesystem.c
wsutil/filesystem.h

index 9fa6bca911b6a6e9445ee5d32ad98c27c8a001fc..7ddd0e50a280352901c5d2df13f421874d378bb8 100644 (file)
@@ -32,6 +32,7 @@ set(COMMON_UI_SRC
        help_url.c
        packet_list_utils.c
        iface_lists.c
+       persfilepath_opt.c
        preference_utils.c
        profile.c
        recent.c
index 6b6567e23e853de4bd5f955fd465a9e998ffa39a..6845b5519f734233072b8f821e2f996dd7e6252c 100644 (file)
@@ -53,6 +53,7 @@ WIRESHARK_UI_SRC = \
        iface_lists.c           \
        help_url.c              \
        packet_list_utils.c     \
+       persfilepath_opt.c      \
        preference_utils.c      \
        profile.c               \
        recent.c                \
@@ -78,6 +79,7 @@ noinst_HEADERS = \
        packet_list_utils.h     \
        iface_lists.h           \
        main_statusbar.h        \
+       persfilepath_opt.h      \
        preference_utils.h      \
        profile.h               \
        progress_dlg.h          \
index ab35934156296677d705f3c01ffa2f665f837524..63184d4eea36f83d7478201396d82605cf2c63b9 100644 (file)
 #endif /* HAVE_LIBPORTAUDIO */
 
 #include <wsutil/crash_info.h>
-#include <wsutil/u3.h>
-#include <wsutil/privileges.h>
+#include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
+#include <wsutil/privileges.h>
+#include <wsutil/u3.h>
 
 #include <wiretap/merge.h>
 
 #include <epan/epan.h>
-#include <wsutil/filesystem.h>
 #include <epan/epan_dissect.h>
 #include <epan/timestamp.h>
 #include <epan/plugins.h>
 
 #include "ui/alert_box.h"
 #include "ui/main_statusbar.h"
+#include "ui/persfilepath_opt.h"
 #include "ui/preference_utils.h"
 #include "ui/recent.h"
 #include "ui/recent_utils.h"
@@ -2352,11 +2353,10 @@ main(int argc, char *argv[])
           set_stdin_capture(TRUE);
         break;
 #endif
-      case 'P':        /* Path settings - change these before the Preferences and alike are processed */
-        status = filesystem_opt(opt, optarg);
-        if(status != 0) {
+      case 'P':        /* Personal file directory path settings - change these before the Preferences and alike are processed */
+        if (!persfilepath_opt(opt, optarg)) {
             cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg);
-            exit(status);
+            exit(2);
         }
         break;
       case 'v':        /* Show version and exit */
diff --git a/ui/persfilepath_opt.c b/ui/persfilepath_opt.c
new file mode 100644 (file)
index 0000000..d781ef2
--- /dev/null
@@ -0,0 +1,92 @@
+/* persfilepath_opt.c
+ * Routines to handle command-line options to set paths for directories
+ * containing personal files (configuration, saved captures)
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include <wsutil/filesystem.h>
+
+/*
+ * process command line option that affects the paths of the directories
+ * used for personal files (configuration, saved captures)
+ */
+gboolean
+persfilepath_opt(int opt _U_, const char *optstr)
+{
+    gchar *p, *colonp;
+
+    colonp = strchr(optstr, ':');
+    if (colonp == NULL) {
+        return FALSE;
+    }
+
+    p = colonp;
+    *p++ = '\0';
+
+    /*
+    * Skip over any white space (there probably won't be any, but
+    * as we allow it in the preferences file, we might as well
+    * allow it here).
+    */
+    while (isspace((guchar)*p))
+        p++;
+    if (*p == '\0') {
+        /*
+         * Put the colon back, so if our caller uses, in an
+         * error message, the string they passed us, the message
+         * looks correct.
+         */
+        *colonp = ':';
+        return FALSE;
+    }
+
+    /* directory should be existing */
+    /* XXX - is this a requirement? */
+    if(test_for_directory(p) != EISDIR) {
+        /*
+         * Put the colon back, so if our caller uses, in an
+         * error message, the string they passed us, the message
+         * looks correct.
+         */
+        *colonp = ':';
+        return FALSE;
+    }
+
+    if (strcmp(optstr,"persconf") == 0) {
+        set_persconffile_dir(p);
+    } else if (strcmp(optstr,"persdata") == 0) {
+        set_persdatafile_dir(p);
+    } else {
+        /* XXX - might need to add the temp file path */
+        return FALSE;
+    }
+    *colonp = ':'; /* put the colon back */
+    return TRUE;
+}
diff --git a/ui/persfilepath_opt.h b/ui/persfilepath_opt.h
new file mode 100644 (file)
index 0000000..ac27f3b
--- /dev/null
@@ -0,0 +1,46 @@
+/* persfilepath_opt.h
+ * Definitions of routines to handle command-line options to set paths
+ * for directories containing personal files (configuration, saved
+ * captures)
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PERSFILEPATH_OPT_H
+#define PERSFILEPATH_OPT_H
+
+#include "ws_symbol_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * process command line option that affects the paths of the directories
+ * used for personal files (configuration, saved captures)
+ */
+WS_DLL_PUBLIC gboolean persfilepath_opt(int opt, const char *optstr);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* PERSFILEPATH_OPT_H */
index 97ee1ffa19661e9612a654cc80f84865497a5740..bb27930b3687d72dcf2e511ab8dcd4b1b3bac4d5 100644 (file)
 #endif
 
 #include <wsutil/crash_info.h>
-#include <wsutil/u3.h>
+#include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
+#include <wsutil/privileges.h>
+#include <wsutil/u3.h>
 
 #include <wiretap/merge.h>
 
 #include <epan/epan.h>
-#include <wsutil/filesystem.h>
-#include <wsutil/privileges.h>
 #include <epan/epan_dissect.h>
 #include <epan/timestamp.h>
 #include <epan/packet.h>
@@ -83,6 +83,7 @@
 #include "ui/capture_globals.h"
 #include "ui/iface_lists.h"
 #include "ui/main_statusbar.h"
+#include "ui/persfilepath_opt.h"
 #include "ui/recent.h"
 #include "ui/simple_dialog.h"
 #include "ui/ui_util.h"
@@ -469,7 +470,6 @@ int main(int argc, char *argv[])
 #endif
     e_prefs             *prefs_p;
     GLogLevelFlags       log_flags;
-    int                  status;
 
 #ifdef _WIN32
     create_app_running_mutex();
@@ -676,11 +676,10 @@ int main(int argc, char *argv[])
                 set_stdin_capture(TRUE);
             break;
 #endif
-        case 'P':        /* Path settings - change these before the Preferences and alike are processed */
-            status = filesystem_opt(opt, optarg);
-            if(status != 0) {
+        case 'P':        /* Personal file directory path settings - change these before the Preferences and alike are processed */
+            if (!persfilepath_opt(opt, optarg)) {
                 cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg);
-                exit(status);
+                exit(2);
             }
             break;
         case 'v':        /* Show version and exit */
index 75295cb7f78151e2774808f09d161933c4eafe30..ad72ad1cfe4cfbdc5cb36a12bf3854c317250533 100644 (file)
@@ -1383,6 +1383,13 @@ get_persconffile_dir_no_profile(void)
     return persconffile_dir;
 }
 
+void
+set_persconffile_dir(const char *p)
+{
+    g_free(persconffile_dir);
+    persconffile_dir = g_strdup(p);
+}
+
 const char *
 get_profiles_dir(void)
 {
@@ -1689,21 +1696,16 @@ get_persdatafile_dir(void)
         /* the "My Captures" sub-directory is created (if it doesn't
            exist) by u3util.exe when the U3 Wireshark is first run */
 
-        szPath = g_strdup_printf("%s%s", u3devicedocumentpath, U3_MY_CAPTURES);
-
-        persdatafile_dir = szPath;
-        return szPath;
+        persdatafile_dir = g_strdup_printf("%s%s", u3devicedocumentpath, U3_MY_CAPTURES);
+        return persdatafile_dir
     } else {
         /*
          * Hint: SHGetFolderPath is not available on MSVC 6 - without
          * Platform SDK
          */
-        bRet = SHGetSpecialFolderPath(NULL, tszPath, CSIDL_PERSONAL,
-            FALSE);
-        if(bRet == TRUE) {
-            szPath = utf_16to8(tszPath);
-            persdatafile_dir = szPath;
-            return szPath;
+        if (SHGetSpecialFolderPath(NULL, tszPath, CSIDL_PERSONAL, FALSE)) {
+            persdatafile_dir = g_utf16_to_utf8(tszPath, -1, NULL, NULL, NULL);
+            return persdatafile_dir;
         } else {
             return "";
         }
@@ -1713,6 +1715,13 @@ get_persdatafile_dir(void)
 #endif
 }
 
+void
+set_persdatafile_dir(const char *p)
+{
+    g_free(persdatafile_dir);
+    persdatafile_dir = g_strdup(p);
+}
+
 #ifdef _WIN32
 /*
  * Returns the user's home directory on Win32.
@@ -1802,64 +1811,6 @@ get_persconffile_path(const char *filename, gboolean from_profile)
     return path;
 }
 
-/*
- * process command line option belonging to the filesystem settings
- * (move this e.g. to main.c and have set_persconffile_dir() instead in this file?)
- */
-int
-filesystem_opt(int opt _U_, const char *optstr)
-{
-    gchar *p, *colonp;
-
-    colonp = strchr(optstr, ':');
-    if (colonp == NULL) {
-        return 1;
-    }
-
-    p = colonp;
-    *p++ = '\0';
-
-    /*
-    * Skip over any white space (there probably won't be any, but
-    * as we allow it in the preferences file, we might as well
-    * allow it here).
-    */
-    while (isspace((guchar)*p))
-        p++;
-    if (*p == '\0') {
-        /*
-         * Put the colon back, so if our caller uses, in an
-         * error message, the string they passed us, the message
-         * looks correct.
-         */
-        *colonp = ':';
-        return 1;
-    }
-
-    /* directory should be existing */
-    /* XXX - is this a requirement? */
-    if(test_for_directory(p) != EISDIR) {
-        /*
-         * Put the colon back, so if our caller uses, in an
-         * error message, the string they passed us, the message
-         * looks correct.
-         */
-        *colonp = ':';
-        return 1;
-    }
-
-    if (strcmp(optstr,"persconf") == 0) {
-        persconffile_dir = p;
-    } else if (strcmp(optstr,"persdata") == 0) {
-        persdatafile_dir = p;
-        /* XXX - might need to add the temp file path */
-    } else {
-        return 1;
-    }
-    *colonp = ':'; /* put the colon back */
-    return 0;
-}
-
 /*
  * Construct the path name of a global configuration file, given the
  * file name.
index 4915a0ec56891cae0d441b131373c8cbfbbd9e7b..5e6082889aecc0363dd893861bef33cad52f915b 100644 (file)
@@ -196,6 +196,11 @@ WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
  */
 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
 
+/*
+ * Set the path of the personal configuration file directory.
+ */
+WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
+
 /*
  * Get the (default) directory in which personal data is stored.
  *
@@ -205,9 +210,9 @@ WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_pr
 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
 
 /*
- * process command line option belonging to the filesystem settings
+ * Set the path of the directory in which personal data is stored.
  */
-WS_DLL_PUBLIC int filesystem_opt(int opt, const char *optstr);
+WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
 
 /*
  * Return an error message for UNIX-style errno indications on open or