summaryrefslogtreecommitdiff
path: root/indra/llmessage/llfiltersd2xmlrpc.h
blob: 55938d3e2b5f22329e41e8c40ac14d2a545b35c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
 * @file llfiltersd2xmlrpc.h
 * @author Phoenix
 * @date 2005-04-26
 *
 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#ifndef LL_LLFILTERSD2XMLRPC_H
#define LL_LLFILTERSD2XMLRPC_H

/**
 * These classes implement the necessary pipes for translating between
 * xmlrpc and llsd rpc. The llsd rpcs mechanism was developed as an
 * extensible and easy to parse serialization grammer which maintains
 * a time efficient in-memory representation.
 */

#include <iosfwd>
#include "lliopipe.h"

/**
 * @class LLFilterSD2XMLRPC
 * @brief Filter from serialized LLSD to an XMLRPC method call
 *
 * This clas provides common functionality for the LLFilterSD2XMLRPRC
 * request and response classes.
 */
class LLFilterSD2XMLRPC : public LLIOPipe
{
public:
    LLFilterSD2XMLRPC();
    virtual ~LLFilterSD2XMLRPC();

protected:
    /**
     * @brief helper method
     */
    void streamOut(std::ostream& ostr, const LLSD& sd);
};

/**
 * @class LLFilterSD2XMLRPCResponse
 * @brief Filter from serialized LLSD to an XMLRPC response
 *
 * This class filters a serialized LLSD object to an xmlrpc
 * repsonse. Since resonses are limited to a single param, the xmlrprc
 * response only serializes it as one object.
 * This class correctly handles normal llsd responses as well as llsd
 * rpc faults.
 *
 * For example, if given:
 * <code>{'response':[ i200, r3.4, {"foo":"bar"} ]}</code>
 * Would generate:
 * <code>
 *  <?xml version="1.0"?>
 *  <methodResponse><params><param><array><data>
 *    <value><int>200</int></value>
 *    <value><double>3.4</double></value>
 *    <value><struct><member>
 *      <name>foo</name><value><string>bar</string></value></member>
 *      </struct></value>
 *  </data></array></param></params></methodResponse>
 * </code>
 */
class LLFilterSD2XMLRPCResponse : public LLFilterSD2XMLRPC
{
public:
    // constructor
    LLFilterSD2XMLRPCResponse();

    // destructor
    virtual ~LLFilterSD2XMLRPCResponse();

    /* @name LLIOPipe virtual implementations
     */
    //@{
protected:
    /**
     * @brief Process the data in buffer.
     */
    virtual EStatus process_impl(
        const LLChannelDescriptors& channels,
        buffer_ptr_t& buffer,
        bool& eos,
        LLSD& context,
        LLPumpIO* pump);
    //@}
};

/**
 * @class LLFilterSD2XMLRPCRequest
 * @brief Filter from serialized LLSD to an XMLRPC method call
 *
 * This class will accept any kind of serialized LLSD object, but you
 * probably want to have an array on the outer boundary since this
 * object will interpret each element in the top level LLSD as a
 * parameter into the xmlrpc spec.
 *
 * For example, you would represent 3 params as:
 * <code>
 *  {'method'='foo', 'parameter':[i200, r3.4, {"foo":"bar"}]}
 * </code>
 * To generate:
 * <code>
 *  <?xml version="1.0"?>
 *  <methodCall><params>
 *  <param><value><int>200</int></value></param>
 *  <param><value><double>3.4</double></value></param>
 *  <param><value><struct><member>
 *    <name>foo</name><value><string>bar</string></value></member>
 *    </struct></value></param>
 *  </params></methodCall>
 *
 * This class will accept 2 different kinds of encodings. The first
 * just an array of params as long as you specify the method in the
 * constructor. It will also accept a structured data in the form:
 * {'method':'$method_name', 'parameter':[...] } In the latter form, the
 * encoded 'method' will be used regardless of the construction of the
 * object, and the 'parameter' will be used as parameter to the call.
 */
class LLFilterSD2XMLRPCRequest : public LLFilterSD2XMLRPC
{
public:
    // constructor
    LLFilterSD2XMLRPCRequest();

    // constructor
    LLFilterSD2XMLRPCRequest(const char* method);

    // destructor
    virtual ~LLFilterSD2XMLRPCRequest();

    /* @name LLIOPipe virtual implementations
     */
    //@{
protected:
    /**
     * @brief Process the data in buffer.
     */
    virtual EStatus process_impl(
        const LLChannelDescriptors& channels,
        buffer_ptr_t& buffer,
        bool& eos,
        LLSD& context,
        LLPumpIO* pump);
    //@}

protected:
    // The method name of this request.
    std::string mMethod;
};

/**
 * @class LLFilterXMLRPCResponse2LLSD
 * @brief Filter from serialized XMLRPC method response to LLSD
 *
 * The xmlrpc spec states that responses can only have one element
 * which can be of any supported type.
 * This takes in  xml of the form:
 * <code>
 * <?xml version=\"1.0\"?><methodResponse><params><param>
 * <value><string>ok</string></value></param></params></methodResponse>
 * </code>
 * And processes it into:
 *  <code>'ok'</code>
 *
 */
class LLFilterXMLRPCResponse2LLSD : public LLIOPipe
{
public:
    // constructor
    LLFilterXMLRPCResponse2LLSD();

    // destructor
    virtual ~LLFilterXMLRPCResponse2LLSD();

    /* @name LLIOPipe virtual implementations
     */
    //@{
protected:
    /**
     * @brief Process the data in buffer.
     */
    virtual EStatus process_impl(
        const LLChannelDescriptors& channels,
        buffer_ptr_t& buffer,
        bool& eos,
        LLSD& context,
        LLPumpIO* pump);
    //@}

protected:
};

/**
 * @class LLFilterXMLRPCRequest2LLSD
 * @brief Filter from serialized XMLRPC method call to LLSD
 *
 * This takes in  xml of the form:
 * <code>
 *  <?xml version=\"1.0\"?><methodCall>
 *  <methodName>repeat</methodName>
 *  <params>
 *  <param><value><i4>4</i4></value></param>
 *  <param><value><string>ok</string></value></param>
 *  </params></methodCall>
 * </code>
 * And processes it into:
 *  <code>{ 'method':'repeat', 'params':[i4, 'ok'] }</code>
 */
class LLFilterXMLRPCRequest2LLSD : public LLIOPipe
{
public:
    // constructor
    LLFilterXMLRPCRequest2LLSD();

    // destructor
    virtual ~LLFilterXMLRPCRequest2LLSD();

    /* @name LLIOPipe virtual implementations
     */
    //@{
protected:
    /**
     * @brief Process the data in buffer.
     */
    virtual EStatus process_impl(
        const LLChannelDescriptors& channels,
        buffer_ptr_t& buffer,
        bool& eos,
        LLSD& context,
        LLPumpIO* pump);
    //@}

protected:
};

/**
 * @brief This function takes string, and escapes it appropritately
 * for inclusion as xml data.
 */
std::string xml_escape_string(const std::string& in);

/**
 * @brief Externally available constants
 */
extern const char LLSDRPC_REQUEST_HEADER_1[];
extern const char LLSDRPC_REQUEST_HEADER_2[];
extern const char LLSDRPC_REQUEST_FOOTER[];

#endif // LL_LLFILTERSD2XMLRPC_H