diff options
-rw-r--r-- | ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ui/Makefile.common | 2 | ||||
-rw-r--r-- | ui/gtk/main.c | 14 | ||||
-rw-r--r-- | ui/persfilepath_opt.c | 92 | ||||
-rw-r--r-- | ui/persfilepath_opt.h | 46 | ||||
-rw-r--r-- | ui/qt/main.cpp | 15 | ||||
-rw-r--r-- | wsutil/filesystem.c | 87 | ||||
-rw-r--r-- | wsutil/filesystem.h | 9 |
8 files changed, 181 insertions, 85 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 9fa6bca911..7ddd0e50a2 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -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 diff --git a/ui/Makefile.common b/ui/Makefile.common index 6b6567e23e..6845b5519f 100644 --- a/ui/Makefile.common +++ b/ui/Makefile.common @@ -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 \ diff --git a/ui/gtk/main.c b/ui/gtk/main.c index ab35934156..63184d4eea 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -64,14 +64,14 @@ #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> @@ -111,6 +111,7 @@ #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 index 0000000000..d781ef2e6a --- /dev/null +++ b/ui/persfilepath_opt.c @@ -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 index 0000000000..ac27f3bb76 --- /dev/null +++ b/ui/persfilepath_opt.h @@ -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 */ diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index 97ee1ffa19..bb27930b36 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -37,14 +37,14 @@ #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 */ diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index 75295cb7f7..ad72ad1cfe 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -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. @@ -1803,64 +1812,6 @@ get_persconffile_path(const char *filename, gboolean from_profile) } /* - * 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. * diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h index 4915a0ec56..5e6082889a 100644 --- a/wsutil/filesystem.h +++ b/wsutil/filesystem.h @@ -197,6 +197,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. * * On Win32, this is the "My Documents" folder in the personal profile. @@ -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 |