PageRenderTime 35ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/lliohttpserver.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 139 lines | 48 code | 18 blank | 73 comment | 0 complexity | 5c452daf6a88efe33b4370f6cd70f6bd MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lliohttpserver.h
  3. * @brief Declaration of function for creating an HTTP wire server
  4. * @see LLIOServerSocket, LLPumpIO
  5. *
  6. * $LicenseInfo:firstyear=2005&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. #ifndef LL_LLIOHTTPSERVER_H
  28. #define LL_LLIOHTTPSERVER_H
  29. #include "llchainio.h"
  30. #include "llhttpnode.h"
  31. class LLPumpIO;
  32. // common strings use for populating the context. bascally 'request',
  33. // 'wildcard', and 'headers'.
  34. extern const std::string CONTEXT_REQUEST;
  35. extern const std::string CONTEXT_RESPONSE;
  36. extern const std::string CONTEXT_VERB;
  37. extern const std::string CONTEXT_HEADERS;
  38. extern const std::string HTTP_VERB_GET;
  39. extern const std::string HTTP_VERB_PUT;
  40. extern const std::string HTTP_VERB_POST;
  41. extern const std::string HTTP_VERB_DELETE;
  42. extern const std::string HTTP_VERB_OPTIONS;
  43. class LLIOHTTPServer
  44. {
  45. public:
  46. typedef void (*timing_callback_t)(const char* hashed_name, F32 time, void* data);
  47. static LLHTTPNode& create(apr_pool_t* pool, LLPumpIO& pump, U16 port);
  48. /**< Creates an HTTP wire server on the pump for the given TCP port.
  49. *
  50. * Returns the root node of the new server. Add LLHTTPNode instances
  51. * to this root.
  52. *
  53. * Nodes that return NULL for getProtocolHandler(), will use the
  54. * default handler that interprets HTTP on the wire and converts
  55. * it into calls to get(), put(), post(), del() with appropriate
  56. * LLSD arguments and results.
  57. *
  58. * To have nodes that implement some other wire protocol (XML-RPC
  59. * for example), use the helper templates below.
  60. */
  61. static void createPipe(LLPumpIO::chain_t& chain,
  62. const LLHTTPNode& root, const LLSD& ctx);
  63. /**< Create a pipe on the chain that handles HTTP requests.
  64. * The requests are served by the node tree given at root.
  65. *
  66. * This is primarily useful for unit testing.
  67. */
  68. static void setTimingCallback(timing_callback_t callback, void* data);
  69. /**< Register a callback function that will be called every time
  70. * a GET, PUT, POST, or DELETE is handled.
  71. *
  72. * This is used to time the LLHTTPNode handler code, which often hits
  73. * the database or does other, slow operations. JC
  74. */
  75. };
  76. /* @name Helper Templates
  77. *
  78. * These templates make it easy to create nodes that use thier own protocol
  79. * handlers rather than the default. Typically, you subclass LLIOPipe to
  80. * implement the protocol, and then add a node using the templates:
  81. *
  82. * rootNode->addNode("thing", new LLHTTPNodeForPipe<LLThingPipe>);
  83. *
  84. * The templates are:
  85. *
  86. * LLChainIOFactoryForPipe
  87. * - a simple factory that builds instances of a pipe
  88. *
  89. * LLHTTPNodeForFacotry
  90. * - a HTTP node that uses a factory as the protocol handler
  91. *
  92. * LLHTTPNodeForPipe
  93. * - a HTTP node that uses a simple factory based on a pipe
  94. */
  95. //@{
  96. template<class Pipe>
  97. class LLChainIOFactoryForPipe : public LLChainIOFactory
  98. {
  99. public:
  100. virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
  101. {
  102. chain.push_back(LLIOPipe::ptr_t(new Pipe));
  103. return true;
  104. }
  105. };
  106. template<class Factory>
  107. class LLHTTPNodeForFactory : public LLHTTPNode
  108. {
  109. public:
  110. const LLChainIOFactory* getProtocolHandler() const
  111. { return &mProtocolHandler; }
  112. private:
  113. Factory mProtocolHandler;
  114. };
  115. //@}
  116. template<class Pipe>
  117. class LLHTTPNodeForPipe : public LLHTTPNodeForFactory<
  118. LLChainIOFactoryForPipe<Pipe> >
  119. {
  120. };
  121. #endif // LL_LLIOHTTPSERVER_H