3
XML-RPC definitions for C++
6
XML-RPC declarations are given in the gSOAP header file xml-rpc.h
7
Iterators and iostream operators are declared in xml-rpc-iters.h
9
Example calling sequence:
11
// get XML-RPC serializers
13
#include "xml-rpc-io.h"
16
soap *ctx = soap_new();
18
methodCall myMethod(ctx, "<endpoint-URL>", "<method-name>");
19
// populate input parameters
20
myMethod[0] = ...; // first param
21
myMethod[1] = ...; // second param
23
// make the call and get the response parameters
24
params output = myMethod();
27
soap_print_fault(ctx, stderr);
28
else if (output.empty())
29
cout << myMethod.fault() << endl;
31
for (params::iterator arg = output.begin(); arg != output.end(); ++arg)
39
--------------------------------------------------------------------------------
40
gSOAP XML Web services tools
41
Copyright (C) 2001-2004, Robert van Engelen, Genivia, Inc. All Rights Reserved.
42
This software is released under one of the following two licenses:
43
GPL or Genivia's license for commercial use.
44
--------------------------------------------------------------------------------
47
This program is free software; you can redistribute it and/or modify it under
48
the terms of the GNU General Public License as published by the Free Software
49
Foundation; either version 2 of the License, or (at your option) any later
52
This program is distributed in the hope that it will be useful, but WITHOUT ANY
53
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
54
PARTICULAR PURPOSE. See the GNU General Public License for more details.
56
You should have received a copy of the GNU General Public License along with
57
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
58
Place, Suite 330, Boston, MA 02111-1307 USA
60
Author contact information:
61
engelen@genivia.com / engelen@acm.org
62
--------------------------------------------------------------------------------
63
A commercial use license is available from Genivia, Inc., contact@genivia.com
64
--------------------------------------------------------------------------------
72
value::value(struct soap *soap)
73
{ soap_default_value(soap, this);
76
value::value(struct soap *soap, struct _array &a)
77
{ soap_default_value(soap, this);
81
value::value(struct soap *soap, _base64 &b)
82
{ soap_default_value(soap, this);
86
value::value(struct soap *soap, bool b)
87
{ soap_default_value(soap, this);
91
value::value(struct soap *soap, char *s)
92
{ soap_default_value(soap, this);
96
value::value(struct soap *soap, double d)
97
{ soap_default_value(soap, this);
101
value::value(struct soap *soap, int n)
102
{ soap_default_value(soap, this);
106
value::value(struct soap *soap, struct _struct &r)
107
{ soap_default_value(soap, this);
111
bool value::is_array() const
112
{ return __type == SOAP_TYPE__array;
115
bool value::is_base64() const
116
{ return __type == SOAP_TYPE__base64;
119
bool value::is_bool() const
120
{ return __type == SOAP_TYPE__boolean;
123
bool value::is_double() const
124
{ return __type == SOAP_TYPE__double;
127
bool value::is_false() const
128
{ return __type == SOAP_TYPE__boolean && (bool)*(_boolean*)ref == false;
131
bool value::is_int() const
132
{ return __type == SOAP_TYPE__int || __type == SOAP_TYPE__i4;
135
bool value::is_struct() const
136
{ return __type == SOAP_TYPE__struct;
139
bool value::is_string() const
140
{ return __type == SOAP_TYPE__string || (__any && *__any);
143
bool value::is_true() const
144
{ return __type == SOAP_TYPE__boolean && (bool)*(_boolean*)ref == true;
147
value::operator struct _array&()
148
{ if (__type == SOAP_TYPE__array)
149
return *(struct _array*)ref;
150
return *soap_new__array(soap, -1);
153
value::operator const struct _array&() const
154
{ if (__type == SOAP_TYPE__array)
155
return *(const struct _array*)ref;
156
return *soap_new__array(soap, -1);
159
value::operator struct _base64&()
160
{ if (__type == SOAP_TYPE__base64)
161
return *(struct _base64*)ref;
162
return *soap_new__base64(soap, -1);
165
value::operator const struct _base64&() const
166
{ if (__type == SOAP_TYPE__base64)
167
return *(const struct _base64*)ref;
168
return *soap_new__base64(soap, -1);
171
value::operator char*()
172
{ if (__type == SOAP_TYPE__string || __type == SOAP_TYPE__dateTime_DOTiso8601)
179
value::operator const char*() const
180
{ if (__type == SOAP_TYPE__string || __type == SOAP_TYPE__dateTime_DOTiso8601)
181
return (const char*)ref;
187
value::operator double() const
188
{ if (__type == SOAP_TYPE__double)
189
return (double)*(_double*)ref;
193
value::operator int() const
194
{ if (__type == SOAP_TYPE__int)
195
return (int)*(_int*)ref;
196
if (__type == SOAP_TYPE__i4)
197
return (int)*(_i4*)ref;
201
value::operator struct _struct&()
202
{ if (__type == SOAP_TYPE__struct)
203
return *(struct _struct*)ref;
204
return *soap_new__struct(soap, -1);
207
value::operator const struct _struct&() const
208
{ if (__type == SOAP_TYPE__struct)
209
return *(const struct _struct*)ref;
210
return *soap_new__struct(soap, -1);
213
struct value& value::operator[](int n)
214
{ return ((struct _array&)*this)[n];
217
struct value& value::operator[](const char *s)
218
{ return ((struct _struct&)*this)[s];
221
struct _array& value::operator=(struct _array& a)
222
{ __type = SOAP_TYPE__array;
228
_base64& value::operator=(_base64& b)
229
{ __type = SOAP_TYPE__base64;
235
bool value::operator=(bool b)
236
{ __type = SOAP_TYPE__boolean;
238
ref = soap_malloc(soap, sizeof(_boolean));
239
*(_boolean*)ref = (_boolean)b;
243
char* value::operator=(char *s)
244
{ __type = SOAP_TYPE__string;
246
ref = soap_strdup(soap, s);
250
double value::operator=(double d)
251
{ __type = SOAP_TYPE__double;
253
ref = soap_malloc(soap, sizeof(_double));
254
*(_double*)ref = (_double)d;
258
int value::operator=(int n)
259
{ __type = SOAP_TYPE__int;
261
ref = soap_malloc(soap, sizeof(_int));
262
*(_int*)ref = (_int)n;
266
struct _struct& value::operator=(struct _struct& r)
267
{ __type = SOAP_TYPE__struct;
273
time_t value::operator=(time_t t)
274
{ __type = SOAP_TYPE__dateTime_DOTiso8601;
276
ref = soap_strdup(soap, soap_dateTime2s(soap, t));
283
_struct::_struct(struct soap *soap)
284
{ soap_default__struct(soap, this);
287
_struct::_struct(struct soap *soap, int len)
288
{ soap_default__struct(soap, this);
290
member = (struct member*)soap_malloc(soap, __size * sizeof(struct member));
291
for (int i = 0; i < __size; i++)
292
soap_default_member(soap, &member[i]);
295
bool _struct::empty() const
296
{ return __size == 0;
299
int _struct::size() const
303
struct value& _struct::operator[](const char *s)
307
member = (struct member*)soap_malloc(soap, sizeof(struct member));
310
{ for (i = 0; i < __size; i++)
311
{ if (!strcmp(member[i].name, s))
312
return member[i].value;
315
struct member *newmember = (struct member*)soap_malloc(soap, __size * sizeof(struct member));
316
for (i = 0; i < __size - 1; i++)
317
newmember[i] = member[i];
318
soap_unlink(soap, member);
322
member[i].name = soap_strdup(soap, s);
323
soap_default_value(soap, &member[i].value);
324
return member[i].value;
327
_struct_iterator _struct::begin()
328
{ _struct_iterator iter(this);
332
_struct_iterator _struct::end()
333
{ _struct_iterator iter(this);
341
_array::_array(struct soap *soap)
342
{ soap_default__array(soap, this);
345
_array::_array(struct soap *soap, int len)
346
{ soap_default__array(soap, this);
348
data.value = (struct value*)soap_malloc(soap, data.__size * sizeof(struct value));
349
for (int i = 0; i < data.__size; i++)
350
soap_default_value(soap, &data.value[i]);
353
bool _array::empty() const
354
{ return data.__size == 0;
357
int _array::size() const
358
{ return data.__size;
361
struct value& _array::operator[](int n)
363
{ data.__size = n + 1;
364
data.value = (struct value*)soap_malloc(soap, data.__size * sizeof(struct value));
365
for (int i = 0; i < data.__size; i++)
366
soap_default_value(soap, &data.value[i]);
368
else if (data.__size <= n)
369
{ int oldsize = data.__size;
371
struct value *newvalue = (struct value*)soap_malloc(soap, data.__size * sizeof(struct value));
373
for (i = 0; i < oldsize; i++)
374
newvalue[i] = data.value[i];
375
for (; i < data.__size; i++)
376
soap_default_value(soap, &newvalue[i]);
377
soap_unlink(soap, data.value);
379
data.value = newvalue;
381
return data.value[n];
384
_array_iterator _array::begin()
385
{ _array_iterator iter(this);
389
_array_iterator _array::end()
390
{ _array_iterator iter(this);
398
_base64::_base64(struct soap *soap)
399
{ soap_default__base64(soap, this);
402
int _base64::size() const
406
unsigned char* _base64::ptr()
413
params::params(struct soap *soap)
414
{ soap_default_params(soap, this);
417
params::params(struct soap *soap, int len)
418
{ soap_default_params(soap, this);
420
param = (struct param*)soap_malloc(soap, __size * sizeof(struct param));
421
for (int i = 0; i < __size; i++)
422
soap_default_param(soap, ¶m[i]);
425
bool params::empty() const
426
{ return __size == 0;
429
int params::size() const
433
struct value& params::operator[](int n)
436
param = (struct param*)soap_malloc(soap, __size * sizeof(struct param));
437
for (int i = 0; i < __size; i++)
438
soap_default_param(soap, ¶m[i]);
440
else if (__size <= n)
441
{ int oldsize = __size;
443
struct param *newparam = (struct param*)soap_malloc(soap, __size * sizeof(struct param));
445
for (i = 0; i < oldsize; i++)
446
newparam[i] = param[i];
447
for (; i < __size; i++)
448
soap_default_param(soap, &newparam[i]);
449
soap_unlink(soap, param);
453
return param[n].value;
456
params_iterator params::begin()
457
{ params_iterator iter(this);
461
params_iterator params::end()
462
{ params_iterator iter(this);
467
methodCall::methodCall()
470
methodCall::methodCall(struct soap *soap, const char *endpoint, const char *name)
471
{ soap_default_methodCall(soap, this);
472
methodName = soap_strdup(soap, name);
473
methodEndpoint = soap_strdup(soap, endpoint);
474
methodResponse = NULL;
477
struct value& methodCall::operator[](int n)
481
struct params& methodCall::operator()()
482
{ /* no namespaces */
483
soap->namespaces = NULL;
484
/* no SOAP encodingStyle */
485
soap->encodingStyle = NULL;
486
/* connect, send request, and receive response */
487
if (soap_connect(soap, methodEndpoint, NULL)
488
|| soap_begin_send(soap)
489
|| soap_put_methodCall(soap, this, "methodCall", NULL)
490
|| soap_end_send(soap)
491
|| soap_begin_recv(soap)
492
|| !(methodResponse = soap_get_methodResponse(soap, methodResponse, "methodResponse", NULL))
493
|| soap_end_recv(soap))
494
methodResponse = NULL;
495
soap_closesock(soap);
496
if (methodResponse && methodResponse->params)
497
return *methodResponse->params;
498
return *soap_new_params(soap, -1);
501
struct params& methodCall::operator()(const struct params& args)
508
struct params& methodCall::response()
509
{ if (!methodResponse)
510
methodResponse = soap_new_methodResponse(soap, -1);
511
if (!methodResponse->params)
512
methodResponse->params = soap_new_params(soap, -1);
513
return *methodResponse->params;
516
struct value& methodCall::fault()
517
{ if (methodResponse && methodResponse->fault)
518
return methodResponse->fault->value;
519
return *soap_new_value(soap, -1);
522
int methodCall::error() const
523
{ return soap->error;
526
methodResponse::methodResponse()
529
methodResponse::methodResponse(struct soap *soap)
530
{ soap_default_methodResponse(soap, this);
533
_array_iterator::_array_iterator()
534
{ value = start = NULL;
537
_array_iterator::_array_iterator(const struct _array* a)
538
{ value = start = a->data.value;
541
bool _array_iterator::operator==(const _array_iterator& that) const
542
{ return this->value == that.value;
545
bool _array_iterator::operator!=(const _array_iterator& that) const
546
{ return this->value != that.value;
549
int _array_iterator::index() const
550
{ return value - start;
553
struct value& _array_iterator::operator*() const
557
_array_iterator& _array_iterator::operator++()
562
_array_iterator& _array_iterator::operator+=(int step)
567
_struct_iterator::_struct_iterator()
571
_struct_iterator::_struct_iterator(const struct _struct* s)
572
{ member = s->member;
575
bool _struct_iterator::operator==(const _struct_iterator& that) const
576
{ return this->member == that.member;
579
bool _struct_iterator::operator!=(const _struct_iterator& that) const
580
{ return this->member != that.member;
583
const char* _struct_iterator::index() const
584
{ return member->name;
587
struct value& _struct_iterator::operator*() const
588
{ return member->value;
591
_struct_iterator& _struct_iterator::operator++()
596
_struct_iterator& _struct_iterator::operator+=(int step)
601
params_iterator::params_iterator()
602
{ start = param = NULL;
605
params_iterator::params_iterator(const struct params* s)
606
{ start = param = s->param;
609
bool params_iterator::operator==(const params_iterator& that) const
610
{ return this->param == that.param;
613
bool params_iterator::operator!=(const params_iterator& that) const
614
{ return this->param != that.param;
617
int params_iterator::index() const
618
{ return param - start;
621
struct value& params_iterator::operator*() const
622
{ return param->value;
625
params_iterator& params_iterator::operator++()
630
params_iterator& params_iterator::operator+=(int step)