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