diff options
author | James Cook <james@lindenlab.com> | 2007-01-02 08:33:20 +0000 |
---|---|---|
committer | James Cook <james@lindenlab.com> | 2007-01-02 08:33:20 +0000 |
commit | 420b91db29485df39fd6e724e782c449158811cb (patch) | |
tree | b471a94563af914d3ed3edd3e856d21cb1b69945 /indra/llmessage/llsdappservices.cpp |
Print done when done.
Diffstat (limited to 'indra/llmessage/llsdappservices.cpp')
-rw-r--r-- | indra/llmessage/llsdappservices.cpp | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/indra/llmessage/llsdappservices.cpp b/indra/llmessage/llsdappservices.cpp new file mode 100644 index 0000000000..c10e9bd113 --- /dev/null +++ b/indra/llmessage/llsdappservices.cpp @@ -0,0 +1,259 @@ +/** + * @file llsdappservices.cpp + * @author Phoenix + * @date 2006-09-12 + * + * Copyright (c) 2006-$CurrentYear$, Linden Research, Inc. + * $License$ + */ + +#include "linden_common.h" +#include "llsdappservices.h" + +#include "llapp.h" +#include "llhttpnode.h" +#include "llsdserialize.h" + +void LLSDAppServices::useServices() +{ + /* + Having this function body here, causes the classes and globals in this + file to be linked into any program that uses the llmessage library. + */ +} + +class LLHTTPConfigService : public LLHTTPNode +{ +public: + virtual void describe(Description& desc) const + { + desc.shortInfo("GET an array of all the options in priority order."); + desc.getAPI(); + desc.source(__FILE__, __LINE__); + } + + virtual LLSD get() const + { + LLSD result; + LLApp* app = LLApp::instance(); + for(int ii = 0; ii < LLApp::PRIORITY_COUNT; ++ii) + { + result.append(app->getOptionData((LLApp::OptionPriority)ii)); + } + return result; + } +}; + +LLHTTPRegistration<LLHTTPConfigService> + gHTTPRegistratiAppConfig("/app/config"); + +class LLHTTPConfigRuntimeService : public LLHTTPNode +{ +public: + virtual void describe(Description& desc) const + { + desc.shortInfo("Manipulate a map of runtime-override options."); + desc.getAPI(); + desc.postAPI(); + desc.source(__FILE__, __LINE__); + } + + virtual LLSD get() const + { + return LLApp::instance()->getOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE); + } + + virtual void post( + LLHTTPNode::ResponsePtr response, + const LLSD& context, + const LLSD& input) const + { + LLSD result = LLApp::instance()->getOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE); + LLSD::map_const_iterator iter = input.beginMap(); + LLSD::map_const_iterator end = input.endMap(); + for(; iter != end; ++iter) + { + result[(*iter).first] = (*iter).second; + } + LLApp::instance()->setOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE, + result); + response->result(result); + } +}; + +LLHTTPRegistration<LLHTTPConfigRuntimeService> + gHTTPRegistrationRuntimeConfig("/app/config/runtime-override"); + +class LLHTTPConfigRuntimeSingleService : public LLHTTPNode +{ +public: + virtual void describe(Description& desc) const + { + desc.shortInfo("Manipulate a single runtime-override option."); + desc.getAPI(); + desc.putAPI(); + desc.delAPI(); + desc.source(__FILE__, __LINE__); + } + + virtual bool validate(const std::string& name, LLSD& context) const + { + //llinfos << "validate: " << name << ", " + // << LLSDOStreamer<LLSDNotationFormatter>(context) << llendl; + if((std::string("PUT") == context["request"]["verb"].asString()) && !name.empty()) + { + return true; + } + else + { + // This is for GET and DELETE + LLSD options = LLApp::instance()->getOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE); + if(options.has(name)) return true; + else return false; + } + } + + virtual void get( + LLHTTPNode::ResponsePtr response, + const LLSD& context) const + { + std::string name = context["request"]["wildcard"]["option-name"]; + LLSD options = LLApp::instance()->getOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE); + response->result(options[name]); + } + + virtual void put( + LLHTTPNode::ResponsePtr response, + const LLSD& context, + const LLSD& input) const + { + std::string name = context["request"]["wildcard"]["option-name"]; + LLSD options = LLApp::instance()->getOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE); + options[name] = input; + LLApp::instance()->setOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE, + options); + response->result(input); + } + + virtual void del( + LLHTTPNode::ResponsePtr response, + const LLSD& context) const + { + std::string name = context["request"]["wildcard"]["option-name"]; + LLSD options = LLApp::instance()->getOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE); + options.erase(name); + LLApp::instance()->setOptionData( + LLApp::PRIORITY_RUNTIME_OVERRIDE, + options); + response->result(LLSD()); + } +}; + +LLHTTPRegistration<LLHTTPConfigRuntimeSingleService> + gHTTPRegistrationRuntimeSingleConfig( + "/app/config/runtime-override/<option-name>"); + +template<int PRIORITY> +class LLHTTPConfigPriorityService : public LLHTTPNode +{ +public: + virtual void describe(Description& desc) const + { + desc.shortInfo("Get a map of the options at this priority."); + desc.getAPI(); + desc.source(__FILE__, __LINE__); + } + + virtual void get( + LLHTTPNode::ResponsePtr response, + const LLSD& context) const + { + response->result(LLApp::instance()->getOptionData( + (LLApp::OptionPriority)PRIORITY)); + } +}; + +LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_COMMAND_LINE> > + gHTTPRegistrationCommandLineConfig("/app/config/command-line"); +LLHTTPRegistration< + LLHTTPConfigPriorityService<LLApp::PRIORITY_SPECIFIC_CONFIGURATION> > + gHTTPRegistrationSpecificConfig("/app/config/specific"); +LLHTTPRegistration< + LLHTTPConfigPriorityService<LLApp::PRIORITY_GENERAL_CONFIGURATION> > + gHTTPRegistrationGeneralConfig("/app/config/general"); +LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_DEFAULT> > + gHTTPRegistrationDefaultConfig("/app/config/default"); + +class LLHTTPLiveConfigService : public LLHTTPNode +{ +public: + virtual void describe(Description& desc) const + { + desc.shortInfo("Get a map of the currently live options."); + desc.getAPI(); + desc.source(__FILE__, __LINE__); + } + + virtual void get( + LLHTTPNode::ResponsePtr response, + const LLSD& context) const + { + LLSD result; + LLApp* app = LLApp::instance(); + LLSD::map_const_iterator iter; + LLSD::map_const_iterator end; + for(int ii = LLApp::PRIORITY_COUNT - 1; ii >= 0; --ii) + { + LLSD options = app->getOptionData((LLApp::OptionPriority)ii); + iter = options.beginMap(); + end = options.endMap(); + for(; iter != end; ++iter) + { + result[(*iter).first] = (*iter).second; + } + } + response->result(result); + } +}; + +LLHTTPRegistration<LLHTTPLiveConfigService> + gHTTPRegistrationLiveConfig("/app/config/live"); + +class LLHTTPLiveConfigSingleService : public LLHTTPNode +{ +public: + virtual void describe(Description& desc) const + { + desc.shortInfo("Get the named live option."); + desc.getAPI(); + desc.source(__FILE__, __LINE__); + } + + virtual bool validate(const std::string& name, LLSD& context) const + { + llinfos << "LLHTTPLiveConfigSingleService::validate(" << name + << ")" << llendl; + LLSD option = LLApp::instance()->getOption(name); + if(option) return true; + else return false; + } + + virtual void get( + LLHTTPNode::ResponsePtr response, + const LLSD& context) const + { + std::string name = context["request"]["wildcard"]["option-name"]; + response->result(LLApp::instance()->getOption(name)); + } +}; + +LLHTTPRegistration<LLHTTPLiveConfigSingleService> + gHTTPRegistrationLiveSingleConfig("/app/config/live/<option-name>"); |