diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-11-19 19:45:38 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-11-19 19:45:38 +0000 |
commit | 06098fce7bcac3e8267cba5c7d74c1ea3c7efb99 (patch) | |
tree | 660e2944ca2d12d551242dc5c60cbbb0871a1107 /ui | |
parent | 935a4debb1b230eb4106e5e056390ca598f4f91b (diff) | |
download | wireshark-06098fce7bcac3e8267cba5c7d74c1ea3c7efb99.tar.gz |
Add routines to set the personal file directory paths (personal
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.
svn path=/trunk/; revision=53435
Diffstat (limited to 'ui')
-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 |
6 files changed, 155 insertions, 15 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 */ |