diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2013-07-16 14:17:00 -0400 | 
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2013-07-16 14:17:00 -0400 | 
| commit | cfd17448be0c464c1ca64b1e8f3260aa4e98b0ca (patch) | |
| tree | eceab04d1dbcbfd2b651a3c08b3d1664908c868b /indra/newview | |
| parent | 1bb1fe511f451695b331e838cc4aa5fcde5ec7bd (diff) | |
CHOP-960: Validate cmd_line.xml for map-to real settings.xml vars.
A small, fixed set of cmd_line.xml switches can't reasonably be mapped to
settings variables, mostly because they affect the settings machinery itself.
Other than those, every new cmd_line.xml switch should map-to a settings
variable. Validate that only the known set does not have map-to; validate that
map-to variable actually exists.
Diffstat (limited to 'indra/newview')
| -rwxr-xr-x | indra/newview/llcommandlineparser.cpp | 46 | 
1 files changed, 44 insertions, 2 deletions
| diff --git a/indra/newview/llcommandlineparser.cpp b/indra/newview/llcommandlineparser.cpp index 17d403bbe1..7adc6b8c5e 100755 --- a/indra/newview/llcommandlineparser.cpp +++ b/indra/newview/llcommandlineparser.cpp @@ -39,13 +39,17 @@  #include <boost/program_options.hpp>  #include <boost/bind.hpp> -#include<boost/tokenizer.hpp> +#include <boost/tokenizer.hpp> +#include <boost/assign/list_of.hpp>  #if _MSC_VER  #   pragma warning(pop)  #endif  #include "llsdserialize.h" +#include "llerror.h" +#include <string> +#include <set>  #include <iostream>  #include <sstream> @@ -63,6 +67,18 @@ namespace po = boost::program_options;  // This could be good or bad, and probably won't matter for most use cases.  namespace   { +    // List of command-line switches that can't map-to settings variables. +    // Going forward, we want every new command-line switch to map-to some +    // settings variable. This list is used to validate that. +    const std::set<std::string> unmapped_options = boost::assign::list_of +        ("help") +        ("set") +        ("setdefault") +        ("settings") +        ("sessionsettings") +        ("usersessionsettings") +    ; +      po::options_description gOptionsDesc;      po::positional_options_description gPositionalOptions;  	po::variables_map gVariableMap; @@ -561,9 +577,35 @@ void LLControlGroupCLP::configure(const std::string& config_filename, LLControlG              }              boost::function1<void, const token_vector_t&> callback; -            if(option_params.has("map-to") && (NULL != controlGroup)) +            if (! option_params.has("map-to")) +            { +                // If this option isn't mapped to a settings variable, is it +                // one of the ones for which that's unreasonable, or did +                // someone carelessly add a new option? (Make all these +                // configuration errors fatal so a maintainer will catch them +                // right away.) +                std::set<std::string>::const_iterator found = unmapped_options.find(long_name); +                if (found == unmapped_options.end()) +                { +                    llerrs << "New command-line option " << long_name +                           << " should map-to a variable in settings.xml" << llendl; +                } +            } +            else                    // option specifies map-to              {                  std::string controlName = option_params["map-to"].asString(); +                if (! controlGroup) +                { +                    llerrs << "Must pass gSavedSettings to LLControlGroupCLP::configure() for " +                           << long_name << " (map-to " << controlName << ")" << llendl; +                } + +                if (! controlGroup->getControl(controlName)) +                { +                    llerrs << "Option " << long_name << " specifies map-to " << controlName +                           << " which does not exist" << llendl; +                } +                  callback = boost::bind(setControlValueCB, _1,                                          controlName, controlGroup);              } | 
