summaryrefslogtreecommitdiff
path: root/qpid/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/src')
-rw-r--r--qpid/cpp/src/qpid/Options.cpp53
-rw-r--r--qpid/cpp/src/qpidd.cpp6
2 files changed, 45 insertions, 14 deletions
diff --git a/qpid/cpp/src/qpid/Options.cpp b/qpid/cpp/src/qpid/Options.cpp
index b96fc59dda..c0e955e2b3 100644
--- a/qpid/cpp/src/qpid/Options.cpp
+++ b/qpid/cpp/src/qpid/Options.cpp
@@ -74,14 +74,28 @@ struct EnvOptMapper {
}
- string configFileLine (string& line) {
+ void badArg ( string& line ) {
+ ostringstream msg;
+ msg << "Bad argument: |" << line << "|\n";
+ throw Exception(msg.str());
+ }
- if ( isComment ( line ) )
- return string();
- size_t pos = line.find ('=');
- if (pos == string::npos)
+ string configFileLine (string& line, bool allowUnknowns=true) {
+
+ if ( isComment ( line ) ) {
return string();
+ }
+
+ size_t pos = line.find ('=');
+ if (pos == string::npos) {
+ if ( allowUnknowns ) {
+ return string();
+ }
+ else {
+ badArg ( line );
+ }
+ }
string key = line.substr (0, pos);
#if (BOOST_VERSION >= 103300)
typedef const std::vector< boost::shared_ptr<po::option_description> > OptDescs;
@@ -89,16 +103,31 @@ struct EnvOptMapper {
find_if(opts.options().begin(), opts.options().end(), boost::bind(matchCase, key, _1));
if (i != opts.options().end())
return string (line) + "\n";
- else
- return string();
+ else {
+ if ( allowUnknowns ) {
+ return string();
+ }
+ else {
+ badArg ( line );
+ }
+ }
#else
- // Use 'count' to see if this option exists. Using 'find' will SEGV or hang
- // if the option has not been defined yet.
+ // Use 'count' to see if this option exists. Using 'find' will
+ // SEGV or hang if the option has not been defined yet.
if ( opts.count(key.c_str()) > 0 )
return string ( line ) + "\n";
- else
- return string ( );
+ else {
+ if ( allowUnknowns ) {
+ return string ( );
+ }
+ else {
+ badArg ( line );
+ }
+ }
#endif
+ // Control will not arrive here, but the compiler things it could.
+ // Calls to badArg(), that I used above, throw.
+ return string();
}
const Options& opts;
@@ -160,7 +189,7 @@ void Options::parse(int argc, char const* const* argv, const std::string& config
while (!conf.eof()) {
string line;
getline (conf, line);
- filtered << mapper.configFileLine (line);
+ filtered << mapper.configFileLine (line, allowUnknown);
}
po::store(po::parse_config_file(filtered, *this), vm);
diff --git a/qpid/cpp/src/qpidd.cpp b/qpid/cpp/src/qpidd.cpp
index 8e0c52f770..e17dea3164 100644
--- a/qpid/cpp/src/qpidd.cpp
+++ b/qpid/cpp/src/qpidd.cpp
@@ -82,10 +82,12 @@ int run_broker(int argc, char *argv[], bool hidden)
qpid::loadModuleDir (bootOptions.module.loadDir, isDefault);
}
- // Parse options
+ // Parse options. In the second pass, do not allow unknown options.
+ // All the modules have been added now, so any unknown options
+ // should be flagged as errors.
try {
options.reset(new QpiddOptions(argv[0]));
- options->parse(argc, argv, options->common.config);
+ options->parse(argc, argv, options->common.config, false);
} catch (const std::exception& /*e*/) {
if (helpArgSeen) {
// provide help even when parsing fails