summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/NOTICE3
-rw-r--r--cpp/lib/common/CommonOptions.cpp24
-rw-r--r--cpp/lib/common/CommonOptions.h7
-rw-r--r--cpp/src/qpidd.cpp2
4 files changed, 21 insertions, 15 deletions
diff --git a/cpp/NOTICE b/cpp/NOTICE
index c194a63903..769608dd4b 100644
--- a/cpp/NOTICE
+++ b/cpp/NOTICE
@@ -19,6 +19,7 @@ Project dependancies:
* apr version 1.2.7 under the Apache Software License, Version 2.0, and
can be downloded from http://apr.apache.org
- * boost vesrion 1.33.1 or later under the Boost Software License, and
+ * boost version 1.33.1 or later under the Boost Software License, and
can be downloaded from http://www.boost.org
- Included in most OS platfroms by defualt.
+
diff --git a/cpp/lib/common/CommonOptions.cpp b/cpp/lib/common/CommonOptions.cpp
index ebb3543105..2b6657b4e0 100644
--- a/cpp/lib/common/CommonOptions.cpp
+++ b/cpp/lib/common/CommonOptions.cpp
@@ -26,20 +26,20 @@ namespace qpid {
namespace program_options {
-char env2optchar(char env) {
- return (env=='_') ? '-' : tolower(env);
-}
-
-const std::string envPrefix("QPID_");
-
-std::string env2option(const std::string& env) {
- if (env.find(envPrefix) ==0) {
- std::string opt = env.substr(envPrefix.size());
- std::transform(opt.begin(), opt.end(), opt.begin(), env2optchar);
- return opt;
+static const std::string prefix("QPID_");
+
+static char env2optchar(char env) { return (env=='_') ? '-' : tolower(env); }
+
+std::string EnvMapper::operator()(const std::string& env) {
+ if (env.substr(0, prefix.size()) == prefix) {
+ std::string opt = env.substr(prefix.size());
+ transform(opt.begin(), opt.end(), opt.begin(), env2optchar);
+ // Ignore env vars that don't match to known options.
+ if (opts.find_nothrow(opt, false))
+ return opt;
}
return std::string();
-}
+}
} // namespace program_options
diff --git a/cpp/lib/common/CommonOptions.h b/cpp/lib/common/CommonOptions.h
index beaeb114e6..086b9742fb 100644
--- a/cpp/lib/common/CommonOptions.h
+++ b/cpp/lib/common/CommonOptions.h
@@ -64,8 +64,13 @@ value_semantic* optValue(T& value, const char* arg) {
/** Environment-to-option name mapping.
* Maps env variable "QPID_SOME_VAR" to option "some-var"
+ * Ignores env vars that dont match known options._
*/
-std::string env2option(const std::string& env);
+struct EnvMapper {
+ EnvMapper(const options_description& o) : opts(o) {}
+ std::string operator()(const std::string& env);
+ const options_description& opts;
+};
/**
* Like boost::program_options::bool_switch but takes reference, not pointer.
diff --git a/cpp/src/qpidd.cpp b/cpp/src/qpidd.cpp
index 45da8c019f..2672da87d5 100644
--- a/cpp/src/qpidd.cpp
+++ b/cpp/src/qpidd.cpp
@@ -72,7 +72,7 @@ struct QpiddOptions : public Broker::Options
// Earlier sources get precedence.
po::store(po::parse_command_line(argc, argv, desc), vm);
try {
- po::store(po::parse_environment(desc, po::env2option), vm);
+ po::store(po::parse_environment(desc, po::EnvMapper(desc)), vm);
}
catch (const logic_error& e) {
throw logic_error(string("parsing environment variables: ")