00001
00033 #include "linden_common.h"
00034 #include "llsdappservices.h"
00035
00036 #include "llapp.h"
00037 #include "llhttpnode.h"
00038 #include "llsdserialize.h"
00039
00040 void LLSDAppServices::useServices()
00041 {
00042
00043
00044
00045
00046 }
00047
00048 class LLHTTPConfigService : public LLHTTPNode
00049 {
00050 public:
00051 virtual void describe(Description& desc) const
00052 {
00053 desc.shortInfo("GET an array of all the options in priority order.");
00054 desc.getAPI();
00055 desc.source(__FILE__, __LINE__);
00056 }
00057
00058 virtual LLSD get() const
00059 {
00060 LLSD result;
00061 LLApp* app = LLApp::instance();
00062 for(int ii = 0; ii < LLApp::PRIORITY_COUNT; ++ii)
00063 {
00064 result.append(app->getOptionData((LLApp::OptionPriority)ii));
00065 }
00066 return result;
00067 }
00068 };
00069
00070 LLHTTPRegistration<LLHTTPConfigService>
00071 gHTTPRegistratiAppConfig("/app/config");
00072
00073 class LLHTTPConfigRuntimeService : public LLHTTPNode
00074 {
00075 public:
00076 virtual void describe(Description& desc) const
00077 {
00078 desc.shortInfo("Manipulate a map of runtime-override options.");
00079 desc.getAPI();
00080 desc.postAPI();
00081 desc.source(__FILE__, __LINE__);
00082 }
00083
00084 virtual LLSD get() const
00085 {
00086 return LLApp::instance()->getOptionData(
00087 LLApp::PRIORITY_RUNTIME_OVERRIDE);
00088 }
00089
00090 virtual void post(
00091 LLHTTPNode::ResponsePtr response,
00092 const LLSD& context,
00093 const LLSD& input) const
00094 {
00095 LLSD result = LLApp::instance()->getOptionData(
00096 LLApp::PRIORITY_RUNTIME_OVERRIDE);
00097 LLSD::map_const_iterator iter = input.beginMap();
00098 LLSD::map_const_iterator end = input.endMap();
00099 for(; iter != end; ++iter)
00100 {
00101 result[(*iter).first] = (*iter).second;
00102 }
00103 LLApp::instance()->setOptionData(
00104 LLApp::PRIORITY_RUNTIME_OVERRIDE,
00105 result);
00106 response->result(result);
00107 }
00108 };
00109
00110 LLHTTPRegistration<LLHTTPConfigRuntimeService>
00111 gHTTPRegistrationRuntimeConfig("/app/config/runtime-override");
00112
00113 class LLHTTPConfigRuntimeSingleService : public LLHTTPNode
00114 {
00115 public:
00116 virtual void describe(Description& desc) const
00117 {
00118 desc.shortInfo("Manipulate a single runtime-override option.");
00119 desc.getAPI();
00120 desc.putAPI();
00121 desc.delAPI();
00122 desc.source(__FILE__, __LINE__);
00123 }
00124
00125 virtual bool validate(const std::string& name, LLSD& context) const
00126 {
00127
00128
00129 if((std::string("PUT") == context["request"]["verb"].asString()) && !name.empty())
00130 {
00131 return true;
00132 }
00133 else
00134 {
00135
00136 LLSD options = LLApp::instance()->getOptionData(
00137 LLApp::PRIORITY_RUNTIME_OVERRIDE);
00138 if(options.has(name)) return true;
00139 else return false;
00140 }
00141 }
00142
00143 virtual void get(
00144 LLHTTPNode::ResponsePtr response,
00145 const LLSD& context) const
00146 {
00147 std::string name = context["request"]["wildcard"]["option-name"];
00148 LLSD options = LLApp::instance()->getOptionData(
00149 LLApp::PRIORITY_RUNTIME_OVERRIDE);
00150 response->result(options[name]);
00151 }
00152
00153 virtual void put(
00154 LLHTTPNode::ResponsePtr response,
00155 const LLSD& context,
00156 const LLSD& input) const
00157 {
00158 std::string name = context["request"]["wildcard"]["option-name"];
00159 LLSD options = LLApp::instance()->getOptionData(
00160 LLApp::PRIORITY_RUNTIME_OVERRIDE);
00161 options[name] = input;
00162 LLApp::instance()->setOptionData(
00163 LLApp::PRIORITY_RUNTIME_OVERRIDE,
00164 options);
00165 response->result(input);
00166 }
00167
00168 virtual void del(
00169 LLHTTPNode::ResponsePtr response,
00170 const LLSD& context) const
00171 {
00172 std::string name = context["request"]["wildcard"]["option-name"];
00173 LLSD options = LLApp::instance()->getOptionData(
00174 LLApp::PRIORITY_RUNTIME_OVERRIDE);
00175 options.erase(name);
00176 LLApp::instance()->setOptionData(
00177 LLApp::PRIORITY_RUNTIME_OVERRIDE,
00178 options);
00179 response->result(LLSD());
00180 }
00181 };
00182
00183 LLHTTPRegistration<LLHTTPConfigRuntimeSingleService>
00184 gHTTPRegistrationRuntimeSingleConfig(
00185 "/app/config/runtime-override/<option-name>");
00186
00187 template<int PRIORITY>
00188 class LLHTTPConfigPriorityService : public LLHTTPNode
00189 {
00190 public:
00191 virtual void describe(Description& desc) const
00192 {
00193 desc.shortInfo("Get a map of the options at this priority.");
00194 desc.getAPI();
00195 desc.source(__FILE__, __LINE__);
00196 }
00197
00198 virtual void get(
00199 LLHTTPNode::ResponsePtr response,
00200 const LLSD& context) const
00201 {
00202 response->result(LLApp::instance()->getOptionData(
00203 (LLApp::OptionPriority)PRIORITY));
00204 }
00205 };
00206
00207 LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_COMMAND_LINE> >
00208 gHTTPRegistrationCommandLineConfig("/app/config/command-line");
00209 LLHTTPRegistration<
00210 LLHTTPConfigPriorityService<LLApp::PRIORITY_SPECIFIC_CONFIGURATION> >
00211 gHTTPRegistrationSpecificConfig("/app/config/specific");
00212 LLHTTPRegistration<
00213 LLHTTPConfigPriorityService<LLApp::PRIORITY_GENERAL_CONFIGURATION> >
00214 gHTTPRegistrationGeneralConfig("/app/config/general");
00215 LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_DEFAULT> >
00216 gHTTPRegistrationDefaultConfig("/app/config/default");
00217
00218 class LLHTTPLiveConfigService : public LLHTTPNode
00219 {
00220 public:
00221 virtual void describe(Description& desc) const
00222 {
00223 desc.shortInfo("Get a map of the currently live options.");
00224 desc.getAPI();
00225 desc.source(__FILE__, __LINE__);
00226 }
00227
00228 virtual void get(
00229 LLHTTPNode::ResponsePtr response,
00230 const LLSD& context) const
00231 {
00232 LLSD result;
00233 LLApp* app = LLApp::instance();
00234 LLSD::map_const_iterator iter;
00235 LLSD::map_const_iterator end;
00236 for(int ii = LLApp::PRIORITY_COUNT - 1; ii >= 0; --ii)
00237 {
00238 LLSD options = app->getOptionData((LLApp::OptionPriority)ii);
00239 iter = options.beginMap();
00240 end = options.endMap();
00241 for(; iter != end; ++iter)
00242 {
00243 result[(*iter).first] = (*iter).second;
00244 }
00245 }
00246 response->result(result);
00247 }
00248 };
00249
00250 LLHTTPRegistration<LLHTTPLiveConfigService>
00251 gHTTPRegistrationLiveConfig("/app/config/live");
00252
00253 class LLHTTPLiveConfigSingleService : public LLHTTPNode
00254 {
00255 public:
00256 virtual void describe(Description& desc) const
00257 {
00258 desc.shortInfo("Get the named live option.");
00259 desc.getAPI();
00260 desc.source(__FILE__, __LINE__);
00261 }
00262
00263 virtual bool validate(const std::string& name, LLSD& context) const
00264 {
00265 llinfos << "LLHTTPLiveConfigSingleService::validate(" << name
00266 << ")" << llendl;
00267 LLSD option = LLApp::instance()->getOption(name);
00268 if(option.isDefined()) return true;
00269 else return false;
00270 }
00271
00272 virtual void get(
00273 LLHTTPNode::ResponsePtr response,
00274 const LLSD& context) const
00275 {
00276 std::string name = context["request"]["wildcard"]["option-name"];
00277 response->result(LLApp::instance()->getOption(name));
00278 }
00279 };
00280
00281 LLHTTPRegistration<LLHTTPLiveConfigSingleService>
00282 gHTTPRegistrationLiveSingleConfig("/app/config/live/<option-name>");