PageRenderTime 39ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llfiltersd2xmlrpc.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 271 lines | 74 code | 24 blank | 173 comment | 0 complexity | 5bb49b713bf0069224ea3361fd1cad2b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfiltersd2xmlrpc.h
  3. * @author Phoenix
  4. * @date 2005-04-26
  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_LLFILTERSD2XMLRPC_H
  28. #define LL_LLFILTERSD2XMLRPC_H
  29. /**
  30. * These classes implement the necessary pipes for translating between
  31. * xmlrpc and llsd rpc. The llsd rpcs mechanism was developed as an
  32. * extensible and easy to parse serialization grammer which maintains
  33. * a time efficient in-memory representation.
  34. */
  35. #include <iosfwd>
  36. #include "lliopipe.h"
  37. /**
  38. * @class LLFilterSD2XMLRPC
  39. * @brief Filter from serialized LLSD to an XMLRPC method call
  40. *
  41. * This clas provides common functionality for the LLFilterSD2XMLRPRC
  42. * request and response classes.
  43. */
  44. class LLFilterSD2XMLRPC : public LLIOPipe
  45. {
  46. public:
  47. LLFilterSD2XMLRPC();
  48. virtual ~LLFilterSD2XMLRPC();
  49. protected:
  50. /**
  51. * @brief helper method
  52. */
  53. void streamOut(std::ostream& ostr, const LLSD& sd);
  54. };
  55. /**
  56. * @class LLFilterSD2XMLRPCResponse
  57. * @brief Filter from serialized LLSD to an XMLRPC response
  58. *
  59. * This class filters a serialized LLSD object to an xmlrpc
  60. * repsonse. Since resonses are limited to a single param, the xmlrprc
  61. * response only serializes it as one object.
  62. * This class correctly handles normal llsd responses as well as llsd
  63. * rpc faults.
  64. *
  65. * For example, if given:
  66. * <code>{'response':[ i200, r3.4, {"foo":"bar"} ]}</code>
  67. * Would generate:
  68. * <code>
  69. * <?xml version="1.0"?>
  70. * <methodResponse><params><param><array><data>
  71. * <value><int>200</int></value>
  72. * <value><double>3.4</double></value>
  73. * <value><struct><member>
  74. * <name>foo</name><value><string>bar</string></value></member>
  75. * </struct></value>
  76. * </data></array></param></params></methodResponse>
  77. * </code>
  78. */
  79. class LLFilterSD2XMLRPCResponse : public LLFilterSD2XMLRPC
  80. {
  81. public:
  82. // constructor
  83. LLFilterSD2XMLRPCResponse();
  84. // destructor
  85. virtual ~LLFilterSD2XMLRPCResponse();
  86. /* @name LLIOPipe virtual implementations
  87. */
  88. //@{
  89. protected:
  90. /**
  91. * @brief Process the data in buffer.
  92. */
  93. virtual EStatus process_impl(
  94. const LLChannelDescriptors& channels,
  95. buffer_ptr_t& buffer,
  96. bool& eos,
  97. LLSD& context,
  98. LLPumpIO* pump);
  99. //@}
  100. };
  101. /**
  102. * @class LLFilterSD2XMLRPCRequest
  103. * @brief Filter from serialized LLSD to an XMLRPC method call
  104. *
  105. * This class will accept any kind of serialized LLSD object, but you
  106. * probably want to have an array on the outer boundary since this
  107. * object will interpret each element in the top level LLSD as a
  108. * parameter into the xmlrpc spec.
  109. *
  110. * For example, you would represent 3 params as:
  111. * <code>
  112. * {'method'='foo', 'parameter':[i200, r3.4, {"foo":"bar"}]}
  113. * </code>
  114. * To generate:
  115. * <code>
  116. * <?xml version="1.0"?>
  117. * <methodCall><params>
  118. * <param><value><int>200</int></value></param>
  119. * <param><value><double>3.4</double></value></param>
  120. * <param><value><struct><member>
  121. * <name>foo</name><value><string>bar</string></value></member>
  122. * </struct></value></param>
  123. * </params></methodCall>
  124. *
  125. * This class will accept 2 different kinds of encodings. The first
  126. * just an array of params as long as you specify the method in the
  127. * constructor. It will also accept a structured data in the form:
  128. * {'method':'$method_name', 'parameter':[...] } In the latter form, the
  129. * encoded 'method' will be used regardless of the construction of the
  130. * object, and the 'parameter' will be used as parameter to the call.
  131. */
  132. class LLFilterSD2XMLRPCRequest : public LLFilterSD2XMLRPC
  133. {
  134. public:
  135. // constructor
  136. LLFilterSD2XMLRPCRequest();
  137. // constructor
  138. LLFilterSD2XMLRPCRequest(const char* method);
  139. // destructor
  140. virtual ~LLFilterSD2XMLRPCRequest();
  141. /* @name LLIOPipe virtual implementations
  142. */
  143. //@{
  144. protected:
  145. /**
  146. * @brief Process the data in buffer.
  147. */
  148. virtual EStatus process_impl(
  149. const LLChannelDescriptors& channels,
  150. buffer_ptr_t& buffer,
  151. bool& eos,
  152. LLSD& context,
  153. LLPumpIO* pump);
  154. //@}
  155. protected:
  156. // The method name of this request.
  157. std::string mMethod;
  158. };
  159. /**
  160. * @class LLFilterXMLRPCResponse2LLSD
  161. * @brief Filter from serialized XMLRPC method response to LLSD
  162. *
  163. * The xmlrpc spec states that responses can only have one element
  164. * which can be of any supported type.
  165. * This takes in xml of the form:
  166. * <code>
  167. * <?xml version=\"1.0\"?><methodResponse><params><param>
  168. * <value><string>ok</string></value></param></params></methodResponse>
  169. * </code>
  170. * And processes it into:
  171. * <code>'ok'</code>
  172. *
  173. */
  174. class LLFilterXMLRPCResponse2LLSD : public LLIOPipe
  175. {
  176. public:
  177. // constructor
  178. LLFilterXMLRPCResponse2LLSD();
  179. // destructor
  180. virtual ~LLFilterXMLRPCResponse2LLSD();
  181. /* @name LLIOPipe virtual implementations
  182. */
  183. //@{
  184. protected:
  185. /**
  186. * @brief Process the data in buffer.
  187. */
  188. virtual EStatus process_impl(
  189. const LLChannelDescriptors& channels,
  190. buffer_ptr_t& buffer,
  191. bool& eos,
  192. LLSD& context,
  193. LLPumpIO* pump);
  194. //@}
  195. protected:
  196. };
  197. /**
  198. * @class LLFilterXMLRPCRequest2LLSD
  199. * @brief Filter from serialized XMLRPC method call to LLSD
  200. *
  201. * This takes in xml of the form:
  202. * <code>
  203. * <?xml version=\"1.0\"?><methodCall>
  204. * <methodName>repeat</methodName>
  205. * <params>
  206. * <param><value><i4>4</i4></value></param>
  207. * <param><value><string>ok</string></value></param>
  208. * </params></methodCall>
  209. * </code>
  210. * And processes it into:
  211. * <code>{ 'method':'repeat', 'params':[i4, 'ok'] }</code>
  212. */
  213. class LLFilterXMLRPCRequest2LLSD : public LLIOPipe
  214. {
  215. public:
  216. // constructor
  217. LLFilterXMLRPCRequest2LLSD();
  218. // destructor
  219. virtual ~LLFilterXMLRPCRequest2LLSD();
  220. /* @name LLIOPipe virtual implementations
  221. */
  222. //@{
  223. protected:
  224. /**
  225. * @brief Process the data in buffer.
  226. */
  227. virtual EStatus process_impl(
  228. const LLChannelDescriptors& channels,
  229. buffer_ptr_t& buffer,
  230. bool& eos,
  231. LLSD& context,
  232. LLPumpIO* pump);
  233. //@}
  234. protected:
  235. };
  236. /**
  237. * @brief This function takes string, and escapes it appropritately
  238. * for inclusion as xml data.
  239. */
  240. std::string xml_escape_string(const std::string& in);
  241. /**
  242. * @brief Externally available constants
  243. */
  244. extern const char LLSDRPC_REQUEST_HEADER_1[];
  245. extern const char LLSDRPC_REQUEST_HEADER_2[];
  246. extern const char LLSDRPC_REQUEST_FOOTER[];
  247. #endif // LL_LLFILTERSD2XMLRPC_H