PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llsdappservices.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 277 lines | 218 code | 26 blank | 33 comment | 13 complexity | af21c065f4e696ca5b0c7bce5e253188 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsdappservices.cpp
  3. * @author Phoenix
  4. * @date 2006-09-12
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "llsdappservices.h"
  29. #include "llapp.h"
  30. #include "llhttpnode.h"
  31. #include "llsdserialize.h"
  32. void LLSDAppServices::useServices()
  33. {
  34. /*
  35. Having this function body here, causes the classes and globals in this
  36. file to be linked into any program that uses the llmessage library.
  37. */
  38. }
  39. class LLHTTPConfigService : public LLHTTPNode
  40. {
  41. public:
  42. virtual void describe(Description& desc) const
  43. {
  44. desc.shortInfo("GET an array of all the options in priority order.");
  45. desc.getAPI();
  46. desc.source(__FILE__, __LINE__);
  47. }
  48. virtual LLSD simpleGet() const
  49. {
  50. LLSD result;
  51. LLApp* app = LLApp::instance();
  52. for(int ii = 0; ii < LLApp::PRIORITY_COUNT; ++ii)
  53. {
  54. result.append(app->getOptionData((LLApp::OptionPriority)ii));
  55. }
  56. return result;
  57. }
  58. };
  59. LLHTTPRegistration<LLHTTPConfigService>
  60. gHTTPRegistratiAppConfig("/app/config");
  61. class LLHTTPConfigRuntimeService : public LLHTTPNode
  62. {
  63. public:
  64. virtual void describe(Description& desc) const
  65. {
  66. desc.shortInfo("Manipulate a map of runtime-override options.");
  67. desc.getAPI();
  68. desc.postAPI();
  69. desc.source(__FILE__, __LINE__);
  70. }
  71. virtual LLSD simpleGet() const
  72. {
  73. return LLApp::instance()->getOptionData(
  74. LLApp::PRIORITY_RUNTIME_OVERRIDE);
  75. }
  76. virtual void post(
  77. LLHTTPNode::ResponsePtr response,
  78. const LLSD& context,
  79. const LLSD& input) const
  80. {
  81. LLSD result = LLApp::instance()->getOptionData(
  82. LLApp::PRIORITY_RUNTIME_OVERRIDE);
  83. LLSD::map_const_iterator iter = input.beginMap();
  84. LLSD::map_const_iterator end = input.endMap();
  85. for(; iter != end; ++iter)
  86. {
  87. result[(*iter).first] = (*iter).second;
  88. }
  89. LLApp::instance()->setOptionData(
  90. LLApp::PRIORITY_RUNTIME_OVERRIDE,
  91. result);
  92. response->result(result);
  93. }
  94. };
  95. LLHTTPRegistration<LLHTTPConfigRuntimeService>
  96. gHTTPRegistrationRuntimeConfig("/app/config/runtime-override");
  97. class LLHTTPConfigRuntimeSingleService : public LLHTTPNode
  98. {
  99. public:
  100. virtual void describe(Description& desc) const
  101. {
  102. desc.shortInfo("Manipulate a single runtime-override option.");
  103. desc.getAPI();
  104. desc.putAPI();
  105. desc.delAPI();
  106. desc.source(__FILE__, __LINE__);
  107. }
  108. virtual bool validate(const std::string& name, LLSD& context) const
  109. {
  110. //llinfos << "validate: " << name << ", "
  111. // << LLSDOStreamer<LLSDNotationFormatter>(context) << llendl;
  112. if((std::string("PUT") == context["request"]["verb"].asString()) && !name.empty())
  113. {
  114. return true;
  115. }
  116. else
  117. {
  118. // This is for GET and DELETE
  119. LLSD options = LLApp::instance()->getOptionData(
  120. LLApp::PRIORITY_RUNTIME_OVERRIDE);
  121. if(options.has(name)) return true;
  122. else return false;
  123. }
  124. }
  125. virtual void get(
  126. LLHTTPNode::ResponsePtr response,
  127. const LLSD& context) const
  128. {
  129. std::string name = context["request"]["wildcard"]["option-name"];
  130. LLSD options = LLApp::instance()->getOptionData(
  131. LLApp::PRIORITY_RUNTIME_OVERRIDE);
  132. response->result(options[name]);
  133. }
  134. virtual void put(
  135. LLHTTPNode::ResponsePtr response,
  136. const LLSD& context,
  137. const LLSD& input) const
  138. {
  139. std::string name = context["request"]["wildcard"]["option-name"];
  140. LLSD options = LLApp::instance()->getOptionData(
  141. LLApp::PRIORITY_RUNTIME_OVERRIDE);
  142. options[name] = input;
  143. LLApp::instance()->setOptionData(
  144. LLApp::PRIORITY_RUNTIME_OVERRIDE,
  145. options);
  146. response->result(input);
  147. }
  148. virtual void del(
  149. LLHTTPNode::ResponsePtr response,
  150. const LLSD& context) const
  151. {
  152. std::string name = context["request"]["wildcard"]["option-name"];
  153. LLSD options = LLApp::instance()->getOptionData(
  154. LLApp::PRIORITY_RUNTIME_OVERRIDE);
  155. options.erase(name);
  156. LLApp::instance()->setOptionData(
  157. LLApp::PRIORITY_RUNTIME_OVERRIDE,
  158. options);
  159. response->result(LLSD());
  160. }
  161. };
  162. LLHTTPRegistration<LLHTTPConfigRuntimeSingleService>
  163. gHTTPRegistrationRuntimeSingleConfig(
  164. "/app/config/runtime-override/<option-name>");
  165. template<int PRIORITY>
  166. class LLHTTPConfigPriorityService : public LLHTTPNode
  167. {
  168. public:
  169. virtual void describe(Description& desc) const
  170. {
  171. desc.shortInfo("Get a map of the options at this priority.");
  172. desc.getAPI();
  173. desc.source(__FILE__, __LINE__);
  174. }
  175. virtual void get(
  176. LLHTTPNode::ResponsePtr response,
  177. const LLSD& context) const
  178. {
  179. response->result(LLApp::instance()->getOptionData(
  180. (LLApp::OptionPriority)PRIORITY));
  181. }
  182. };
  183. LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_COMMAND_LINE> >
  184. gHTTPRegistrationCommandLineConfig("/app/config/command-line");
  185. LLHTTPRegistration<
  186. LLHTTPConfigPriorityService<LLApp::PRIORITY_SPECIFIC_CONFIGURATION> >
  187. gHTTPRegistrationSpecificConfig("/app/config/specific");
  188. LLHTTPRegistration<
  189. LLHTTPConfigPriorityService<LLApp::PRIORITY_GENERAL_CONFIGURATION> >
  190. gHTTPRegistrationGeneralConfig("/app/config/general");
  191. LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_DEFAULT> >
  192. gHTTPRegistrationDefaultConfig("/app/config/default");
  193. class LLHTTPLiveConfigService : public LLHTTPNode
  194. {
  195. public:
  196. virtual void describe(Description& desc) const
  197. {
  198. desc.shortInfo("Get a map of the currently live options.");
  199. desc.getAPI();
  200. desc.source(__FILE__, __LINE__);
  201. }
  202. virtual void get(
  203. LLHTTPNode::ResponsePtr response,
  204. const LLSD& context) const
  205. {
  206. LLSD result;
  207. LLApp* app = LLApp::instance();
  208. LLSD::map_const_iterator iter;
  209. LLSD::map_const_iterator end;
  210. for(int ii = LLApp::PRIORITY_COUNT - 1; ii >= 0; --ii)
  211. {
  212. LLSD options = app->getOptionData((LLApp::OptionPriority)ii);
  213. iter = options.beginMap();
  214. end = options.endMap();
  215. for(; iter != end; ++iter)
  216. {
  217. result[(*iter).first] = (*iter).second;
  218. }
  219. }
  220. response->result(result);
  221. }
  222. };
  223. LLHTTPRegistration<LLHTTPLiveConfigService>
  224. gHTTPRegistrationLiveConfig("/app/config/live");
  225. class LLHTTPLiveConfigSingleService : public LLHTTPNode
  226. {
  227. public:
  228. virtual void describe(Description& desc) const
  229. {
  230. desc.shortInfo("Get the named live option.");
  231. desc.getAPI();
  232. desc.source(__FILE__, __LINE__);
  233. }
  234. virtual bool validate(const std::string& name, LLSD& context) const
  235. {
  236. llinfos << "LLHTTPLiveConfigSingleService::validate(" << name
  237. << ")" << llendl;
  238. LLSD option = LLApp::instance()->getOption(name);
  239. if(option.isDefined()) return true;
  240. else return false;
  241. }
  242. virtual void get(
  243. LLHTTPNode::ResponsePtr response,
  244. const LLSD& context) const
  245. {
  246. std::string name = context["request"]["wildcard"]["option-name"];
  247. response->result(LLApp::instance()->getOption(name));
  248. }
  249. };
  250. LLHTTPRegistration<LLHTTPLiveConfigSingleService>
  251. gHTTPRegistrationLiveSingleConfig("/app/config/live/<option-name>");