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

/indra/llmessage/llsdhttpserver.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 150 lines | 89 code | 27 blank | 34 comment | 6 complexity | 228c5312e783d344ad0637d7d526a923 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsdhttpserver.cpp
  3. * @brief Standard LLSD services
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llsdhttpserver.h"
  28. #include "llhttpnode.h"
  29. /**
  30. * This module implements common services that should be included
  31. * in all server URL trees. These services facilitate debugging and
  32. * introsepction.
  33. */
  34. void LLHTTPStandardServices::useServices()
  35. {
  36. /*
  37. Having this function body here, causes the classes and globals in this
  38. file to be linked into any program that uses the llmessage library.
  39. */
  40. }
  41. class LLHTTPHelloService : public LLHTTPNode
  42. {
  43. public:
  44. virtual void describe(Description& desc) const
  45. {
  46. desc.shortInfo("says hello");
  47. desc.getAPI();
  48. desc.output("\"hello\"");
  49. desc.source(__FILE__, __LINE__);
  50. }
  51. virtual LLSD simpleGet() const
  52. {
  53. LLSD result = "hello";
  54. return result;
  55. }
  56. };
  57. LLHTTPRegistration<LLHTTPHelloService>
  58. gHTTPRegistrationWebHello("/web/hello");
  59. class LLHTTPEchoService : public LLHTTPNode
  60. {
  61. public:
  62. virtual void describe(Description& desc) const
  63. {
  64. desc.shortInfo("echo input");
  65. desc.postAPI();
  66. desc.input("<any>");
  67. desc.output("<the input>");
  68. desc.source(__FILE__, __LINE__);
  69. }
  70. virtual LLSD simplePost(const LLSD& params) const
  71. {
  72. return params;
  73. }
  74. };
  75. LLHTTPRegistration<LLHTTPEchoService>
  76. gHTTPRegistrationWebEcho("/web/echo");
  77. class LLAPIService : public LLHTTPNode
  78. {
  79. public:
  80. virtual void describe(Description& desc) const
  81. {
  82. desc.shortInfo("information about the URLs this server supports");
  83. desc.getAPI();
  84. desc.output("a list of URLs supported");
  85. desc.source(__FILE__, __LINE__);
  86. }
  87. virtual bool handles(const LLSD& remainder, LLSD& context) const
  88. {
  89. return followRemainder(remainder) != NULL;
  90. }
  91. virtual void get(ResponsePtr response, const LLSD& context) const
  92. {
  93. const LLSD& remainder = context["request"]["remainder"];
  94. if (remainder.size() > 0)
  95. {
  96. const LLHTTPNode* node = followRemainder(remainder);
  97. if (!node)
  98. {
  99. response->notFound();
  100. return;
  101. }
  102. Description desc;
  103. node->describe(desc);
  104. response->result(desc.getInfo());
  105. return;
  106. }
  107. response->result(rootNode()->allNodePaths());
  108. }
  109. private:
  110. const LLHTTPNode* followRemainder(const LLSD& remainder) const
  111. {
  112. const LLHTTPNode* node = rootNode();
  113. LLSD::array_const_iterator i = remainder.beginArray();
  114. LLSD::array_const_iterator end = remainder.endArray();
  115. for (; node && i != end; ++i)
  116. {
  117. node = node->findNode(*i);
  118. }
  119. return node;
  120. }
  121. };
  122. LLHTTPRegistration<LLAPIService>
  123. gHTTPRegistrationWebServerApi("/web/server/api");