~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to tools/gsoap/gsoap-linux-2.7/samples/xml-rpc/.svn/text-base/xml-rpc.cpp.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
XML-RPC definitions for C++
4
 
 
5
 
Note: 
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
8
 
 
9
 
Example calling sequence:
10
 
 
11
 
// get XML-RPC serializers
12
 
#include "soapH.h"
13
 
#include "xml-rpc-io.h"
14
 
 
15
 
// set up context
16
 
soap *ctx = soap_new();
17
 
// define method
18
 
methodCall myMethod(ctx, "<endpoint-URL>", "<method-name>");
19
 
// populate input parameters
20
 
myMethod[0] = ...; // first param
21
 
myMethod[1] = ...; // second param
22
 
...
23
 
// make the call and get the response parameters
24
 
params output = myMethod();
25
 
// error?
26
 
if (myMethod.error())
27
 
  soap_print_fault(ctx, stderr);
28
 
else if (output.empty())
29
 
  cout << myMethod.fault() << endl;
30
 
else
31
 
  for (params::iterator arg = output.begin(); arg != output.end(); ++arg)
32
 
    cout << *arg << endl;
33
 
// delete all
34
 
soap_destroy(ctx);
35
 
soap_end(ctx);
36
 
soap_done(ctx);
37
 
free(ctx);
38
 
 
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
 
--------------------------------------------------------------------------------
45
 
GPL license.
46
 
 
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
50
 
version.
51
 
 
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.
55
 
 
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
59
 
 
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
 
--------------------------------------------------------------------------------
65
 
*/
66
 
 
67
 
#include "soapH.H"
68
 
 
69
 
value::value()
70
 
{ }
71
 
 
72
 
value::value(struct soap *soap)
73
 
{ soap_default_value(soap, this);
74
 
}
75
 
 
76
 
value::value(struct soap *soap, struct _array &a)
77
 
{ soap_default_value(soap, this);
78
 
  *this = a;
79
 
}
80
 
 
81
 
value::value(struct soap *soap, _base64 &b)
82
 
{ soap_default_value(soap, this);
83
 
  *this = b;
84
 
}
85
 
 
86
 
value::value(struct soap *soap, bool b)
87
 
{ soap_default_value(soap, this);
88
 
  *this = b;
89
 
}
90
 
 
91
 
value::value(struct soap *soap, char *s)
92
 
{ soap_default_value(soap, this);
93
 
  *this = s;
94
 
}
95
 
 
96
 
value::value(struct soap *soap, double d)
97
 
{ soap_default_value(soap, this);
98
 
  *this = d;
99
 
}
100
 
 
101
 
value::value(struct soap *soap, int n)
102
 
{ soap_default_value(soap, this);
103
 
  *this = n;
104
 
}
105
 
 
106
 
value::value(struct soap *soap, struct _struct &r)
107
 
{ soap_default_value(soap, this);
108
 
  *this = r;
109
 
}
110
 
 
111
 
bool value::is_array() const
112
 
{ return __type == SOAP_TYPE__array;
113
 
}
114
 
 
115
 
bool value::is_base64() const
116
 
{ return __type == SOAP_TYPE__base64;
117
 
}
118
 
 
119
 
bool value::is_bool() const
120
 
{ return __type == SOAP_TYPE__boolean;
121
 
}
122
 
 
123
 
bool value::is_double() const
124
 
{ return __type == SOAP_TYPE__double;
125
 
}
126
 
 
127
 
bool value::is_false() const
128
 
{ return __type == SOAP_TYPE__boolean && (bool)*(_boolean*)ref == false;
129
 
}
130
 
 
131
 
bool value::is_int() const
132
 
{ return __type == SOAP_TYPE__int || __type == SOAP_TYPE__i4;
133
 
}
134
 
 
135
 
bool value::is_struct() const
136
 
{ return __type == SOAP_TYPE__struct;
137
 
}
138
 
 
139
 
bool value::is_string() const
140
 
{ return __type == SOAP_TYPE__string || (__any && *__any);
141
 
}
142
 
 
143
 
bool value::is_true() const
144
 
{ return __type == SOAP_TYPE__boolean && (bool)*(_boolean*)ref == true;
145
 
}
146
 
 
147
 
value::operator struct _array&()
148
 
{ if (__type == SOAP_TYPE__array)
149
 
    return *(struct _array*)ref;
150
 
  return *soap_new__array(soap, -1);
151
 
}
152
 
 
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);
157
 
}
158
 
 
159
 
value::operator struct _base64&()
160
 
{ if (__type == SOAP_TYPE__base64)
161
 
    return *(struct _base64*)ref;
162
 
  return *soap_new__base64(soap, -1);
163
 
}
164
 
 
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);
169
 
}
170
 
 
171
 
value::operator char*()
172
 
{ if (__type == SOAP_TYPE__string || __type == SOAP_TYPE__dateTime_DOTiso8601)
173
 
    return (char*)ref;
174
 
  if (__any)
175
 
    return __any;
176
 
  return "";
177
 
}
178
 
 
179
 
value::operator const char*() const
180
 
{ if (__type == SOAP_TYPE__string || __type == SOAP_TYPE__dateTime_DOTiso8601)
181
 
    return (const char*)ref;
182
 
  if (__any)
183
 
    return __any;
184
 
  return "";
185
 
}
186
 
 
187
 
value::operator double() const
188
 
{ if (__type == SOAP_TYPE__double)
189
 
    return (double)*(_double*)ref;
190
 
  return 0.0;
191
 
}
192
 
 
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;
198
 
  return 0;
199
 
}
200
 
 
201
 
value::operator struct _struct&()
202
 
{ if (__type == SOAP_TYPE__struct)
203
 
    return *(struct _struct*)ref;
204
 
  return *soap_new__struct(soap, -1);
205
 
}
206
 
 
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);
211
 
}
212
 
 
213
 
struct value& value::operator[](int n)
214
 
{ return ((struct _array&)*this)[n];
215
 
}
216
 
 
217
 
struct value& value::operator[](const char *s)
218
 
{ return ((struct _struct&)*this)[s];
219
 
}
220
 
 
221
 
struct _array& value::operator=(struct _array& a)
222
 
{ __type = SOAP_TYPE__array;
223
 
  __any = NULL;
224
 
  ref = &a;
225
 
  return a;
226
 
}
227
 
 
228
 
_base64& value::operator=(_base64& b)
229
 
{ __type = SOAP_TYPE__base64;
230
 
  __any = NULL;
231
 
  ref = &b;
232
 
  return b;
233
 
}
234
 
 
235
 
bool value::operator=(bool b)
236
 
{ __type = SOAP_TYPE__boolean;
237
 
  __any = NULL;
238
 
  ref = soap_malloc(soap, sizeof(_boolean));
239
 
  *(_boolean*)ref = (_boolean)b;
240
 
  return b;
241
 
}
242
 
 
243
 
char* value::operator=(char *s)
244
 
{ __type = SOAP_TYPE__string;
245
 
  __any = NULL;
246
 
  ref = soap_strdup(soap, s);
247
 
  return s;
248
 
}
249
 
 
250
 
double value::operator=(double d)
251
 
{ __type = SOAP_TYPE__double;
252
 
  __any = NULL;
253
 
  ref = soap_malloc(soap, sizeof(_double));
254
 
  *(_double*)ref = (_double)d;
255
 
  return d;
256
 
}
257
 
 
258
 
int value::operator=(int n)
259
 
{ __type = SOAP_TYPE__int;
260
 
  __any = NULL;
261
 
  ref = soap_malloc(soap, sizeof(_int));
262
 
  *(_int*)ref = (_int)n;
263
 
  return n;
264
 
}
265
 
 
266
 
struct _struct& value::operator=(struct _struct& r)
267
 
{ __type = SOAP_TYPE__struct;
268
 
  __any = NULL;
269
 
  ref = &r;
270
 
  return r;
271
 
}
272
 
 
273
 
time_t value::operator=(time_t t)
274
 
{ __type = SOAP_TYPE__dateTime_DOTiso8601;
275
 
  __any = NULL;
276
 
  ref = soap_strdup(soap, soap_dateTime2s(soap, t));
277
 
  return t;
278
 
}
279
 
 
280
 
_struct::_struct()
281
 
{ }
282
 
 
283
 
_struct::_struct(struct soap *soap)
284
 
{ soap_default__struct(soap, this);
285
 
}
286
 
 
287
 
_struct::_struct(struct soap *soap, int len)
288
 
{ soap_default__struct(soap, this);
289
 
  __size = len;
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]);
293
 
}
294
 
 
295
 
bool _struct::empty() const
296
 
{ return __size == 0;
297
 
}
298
 
 
299
 
int _struct::size() const
300
 
{ return __size;
301
 
}
302
 
 
303
 
struct value& _struct::operator[](const char *s)
304
 
{ int i = 0;
305
 
  if (!member)
306
 
  { __size = 1;
307
 
    member = (struct member*)soap_malloc(soap, sizeof(struct member));
308
 
  }
309
 
  else
310
 
  { for (i = 0; i < __size; i++)
311
 
    { if (!strcmp(member[i].name, s))
312
 
        return member[i].value;
313
 
    }
314
 
    __size++;
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);
319
 
    free(member);
320
 
    member = newmember;
321
 
  }
322
 
  member[i].name = soap_strdup(soap, s);
323
 
  soap_default_value(soap, &member[i].value);
324
 
  return member[i].value;
325
 
}
326
 
 
327
 
_struct_iterator _struct::begin()
328
 
{ _struct_iterator iter(this);
329
 
  return iter;
330
 
}
331
 
 
332
 
_struct_iterator _struct::end()
333
 
{ _struct_iterator iter(this);
334
 
  iter += __size;
335
 
  return iter;
336
 
}
337
 
 
338
 
_array::_array()
339
 
{ }
340
 
 
341
 
_array::_array(struct soap *soap)
342
 
{ soap_default__array(soap, this);
343
 
}
344
 
 
345
 
_array::_array(struct soap *soap, int len)
346
 
{ soap_default__array(soap, this);
347
 
  data.__size = len;
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]);
351
 
}
352
 
 
353
 
bool _array::empty() const
354
 
{ return data.__size == 0;
355
 
}
356
 
 
357
 
int _array::size() const
358
 
{ return data.__size;
359
 
}
360
 
 
361
 
struct value& _array::operator[](int n)
362
 
{ if (!data.value)
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]);
367
 
  }
368
 
  else if (data.__size <= n)
369
 
  { int oldsize = data.__size;
370
 
    data.__size = n + 1;
371
 
    struct value *newvalue = (struct value*)soap_malloc(soap, data.__size * sizeof(struct value));
372
 
    int i;
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);
378
 
    free(data.value);
379
 
    data.value = newvalue;
380
 
  }
381
 
  return data.value[n];
382
 
}
383
 
 
384
 
_array_iterator _array::begin()
385
 
{ _array_iterator iter(this);
386
 
  return iter;
387
 
}
388
 
 
389
 
_array_iterator _array::end()
390
 
{ _array_iterator iter(this);
391
 
  iter += data.__size;
392
 
  return iter;
393
 
}
394
 
 
395
 
_base64::_base64()
396
 
{ }
397
 
 
398
 
_base64::_base64(struct soap *soap)
399
 
{ soap_default__base64(soap, this);
400
 
}
401
 
 
402
 
int _base64::size() const
403
 
{ return __size;
404
 
}
405
 
 
406
 
unsigned char* _base64::ptr()
407
 
{ return __ptr;
408
 
}
409
 
 
410
 
params::params()
411
 
{ }
412
 
 
413
 
params::params(struct soap *soap)
414
 
{ soap_default_params(soap, this);
415
 
}
416
 
 
417
 
params::params(struct soap *soap, int len)
418
 
{ soap_default_params(soap, this);
419
 
  __size = len;
420
 
  param = (struct param*)soap_malloc(soap, __size * sizeof(struct param));
421
 
  for (int i = 0; i < __size; i++)
422
 
    soap_default_param(soap, &param[i]);
423
 
}
424
 
 
425
 
bool params::empty() const
426
 
{ return __size == 0;
427
 
}
428
 
 
429
 
int params::size() const
430
 
{ return __size;
431
 
}
432
 
 
433
 
struct value& params::operator[](int n)
434
 
{ if (!param)
435
 
  { __size = n + 1;
436
 
    param = (struct param*)soap_malloc(soap, __size * sizeof(struct param));
437
 
    for (int i = 0; i < __size; i++)
438
 
      soap_default_param(soap, &param[i]);
439
 
  }
440
 
  else if (__size <= n)
441
 
  { int oldsize = __size;
442
 
    __size = n + 1;
443
 
    struct param *newparam = (struct param*)soap_malloc(soap, __size * sizeof(struct param));
444
 
    int i;
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);
450
 
    free(param);
451
 
    param = newparam;
452
 
  }
453
 
  return param[n].value;
454
 
}
455
 
 
456
 
params_iterator params::begin()
457
 
{ params_iterator iter(this);
458
 
  return iter;
459
 
}
460
 
 
461
 
params_iterator params::end()
462
 
{ params_iterator iter(this);
463
 
  iter += __size;
464
 
  return iter;
465
 
}
466
 
 
467
 
methodCall::methodCall()
468
 
{ }
469
 
 
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;
475
 
}
476
 
 
477
 
struct value& methodCall::operator[](int n)
478
 
{ return params[n];
479
 
}
480
 
 
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);
499
 
}
500
 
 
501
 
struct params& methodCall::operator()(const struct params& args)
502
 
{ /* parameters */
503
 
  params = args;
504
 
  /* invoke */
505
 
  return (*this)();
506
 
}
507
 
 
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;
514
 
}
515
 
 
516
 
struct value& methodCall::fault()
517
 
{ if (methodResponse && methodResponse->fault)
518
 
    return methodResponse->fault->value;
519
 
  return *soap_new_value(soap, -1);
520
 
}
521
 
 
522
 
int methodCall::error() const
523
 
{ return soap->error;
524
 
}
525
 
 
526
 
methodResponse::methodResponse()
527
 
{ }
528
 
 
529
 
methodResponse::methodResponse(struct soap *soap)
530
 
{ soap_default_methodResponse(soap, this);
531
 
}
532
 
 
533
 
_array_iterator::_array_iterator()
534
 
{ value = start = NULL;
535
 
}
536
 
 
537
 
_array_iterator::_array_iterator(const struct _array* a)
538
 
{ value = start = a->data.value;
539
 
}
540
 
 
541
 
bool _array_iterator::operator==(const _array_iterator& that) const
542
 
{ return this->value == that.value;
543
 
}
544
 
 
545
 
bool _array_iterator::operator!=(const _array_iterator& that) const
546
 
{ return this->value != that.value;
547
 
}
548
 
 
549
 
int _array_iterator::index() const
550
 
{ return value - start;
551
 
}
552
 
 
553
 
struct value& _array_iterator::operator*() const
554
 
{ return *value;
555
 
}
556
 
 
557
 
_array_iterator& _array_iterator::operator++()
558
 
{ value++;
559
 
  return *this;
560
 
}
561
 
 
562
 
_array_iterator& _array_iterator::operator+=(int step)
563
 
{ value += step;
564
 
  return *this;
565
 
}
566
 
 
567
 
_struct_iterator::_struct_iterator()
568
 
{ member = NULL;
569
 
}
570
 
 
571
 
_struct_iterator::_struct_iterator(const struct _struct* s)
572
 
{ member = s->member;
573
 
}
574
 
 
575
 
bool _struct_iterator::operator==(const _struct_iterator& that) const
576
 
{ return this->member == that.member;
577
 
}
578
 
 
579
 
bool _struct_iterator::operator!=(const _struct_iterator& that) const
580
 
{ return this->member != that.member;
581
 
}
582
 
 
583
 
const char* _struct_iterator::index() const
584
 
{ return member->name;
585
 
}
586
 
 
587
 
struct value& _struct_iterator::operator*() const
588
 
{ return member->value;
589
 
}
590
 
 
591
 
_struct_iterator& _struct_iterator::operator++()
592
 
{ member++;
593
 
  return *this;
594
 
}
595
 
 
596
 
_struct_iterator& _struct_iterator::operator+=(int step)
597
 
{ member += step;
598
 
  return *this;
599
 
}
600
 
 
601
 
params_iterator::params_iterator()
602
 
{ start = param = NULL;
603
 
}
604
 
 
605
 
params_iterator::params_iterator(const struct params* s)
606
 
{ start = param = s->param;
607
 
}
608
 
 
609
 
bool params_iterator::operator==(const params_iterator& that) const
610
 
{ return this->param == that.param;
611
 
}
612
 
 
613
 
bool params_iterator::operator!=(const params_iterator& that) const
614
 
{ return this->param != that.param;
615
 
}
616
 
 
617
 
int params_iterator::index() const
618
 
{ return param - start;
619
 
}
620
 
 
621
 
struct value& params_iterator::operator*() const
622
 
{ return param->value;
623
 
}
624
 
 
625
 
params_iterator& params_iterator::operator++()
626
 
{ param++;
627
 
  return *this;
628
 
}
629
 
 
630
 
params_iterator& params_iterator::operator+=(int step)
631
 
{ param += step;
632
 
  return *this;
633
 
}