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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
|
/**
* XRCLIENT.C
*
* Client-side procedures used by an application to make a call to a
* remote service. In this interface, the calling application must
* first initialize a client context for a specific service, then
* create a parameter array of arguments before invoking the function
* either synchronously or asynchronously. Once the call completes,
* API procedures are used to extract the result values.
*
* Client methods:
* // call services
* cnum = xr_initClient (char *url, char *name, char *version)
* xr_callSync (cnum, char *name)
* xr_callASync (cnum, char *name, void *func, .....)
* xr_closeClient (cnum)
*
* xr_initParam (cnum) // init params
* xr_setVerbose (verbose) // verbose flag
* xr_setDebug (debug) // debug flag
*
* xr_setIntInParam (cnum, int ival) // scalar param
* xr_setDoubleInParam (cnum, double dval)
* xr_setBoolInParam (cnum, int bval)
* xr_setStringInParam (cnum, char *str)
* xr_setDatetimeInParam (cnum, char *date)
* xr_setStructInParam (cnum, int snum)
* xr_setArrayInParam (cnum, int anum)
*
* stat = xr_getIntFromResult (cnum, int *ival) // get results
* stat = xr_getDoubleFromResult (cnum, double *dval)
* stat = xr_getBoolFromResult (cnum, int *bval)
* stat = xr_getStringFromResult (cnum, char **value)
* stat = xr_getDatetimeFromResult (cnum, char **date)
* stat = xr_getStructFromResult (cnum)
* stat = xr_getArrayFromResult (cnum)
*
* xr_envClean (cnum) // cleanup
* xr_freeParam (cnum)
* xr_freeResult (cnum)
* xr_clientCleanup (cnum)
*
*
* stat = xr_resultArrayInt (int anum, int index, int *value)
* stat = xr_resultArrayDouble (int anum, int index, int *value)
* stat = xr_resultArrayBool (int anum, int index, int *value)
* stat = xr_resultArrayString (int anum, int index, char **value)
* stat = xr_resultArrayDatetime (int anum, int index, char **value)
* stat = xr_resultArrayStruct (int anum, int index, int *value)
*
*
* @brief Client-side procedures
*
* @file xrClient.c
* @author Mike Fitzpatrick
* @date 6/10/09
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <xmlrpc-c/base.h>
#include <xmlrpc-c/client.h>
#include <xmlrpc-c/server.h>
#include <xmlrpc-c/server_abyss.h>
#include "xrpcP.h"
#define DEBUG 0
/*
#define REUSE_CLIENT 1
*/
#define USE_DEFAULT_TRANSPORT 1
#define CLIENT_START 0 /* slot zero reserved for monitor */
int client_errstat = OK;
int num_asynch_threads = 0;
int client_debug = 0;
int client_verbose = 0;
pthread_mutex_t async_mutex = PTHREAD_MUTEX_INITIALIZER;
static Client clientArray[MAX_CLIENTS];
static int nclients = -1;
int global_init = 0;
typedef struct {
int cnum;
char *name;
Client *client;
xmlrpc_value *param;
xmlrpc_value *result;
void *ret_handler;
} ASynch, *ASynchP;
static void *xr_asynchRunner (void *arg);
static void xr_defaultAsynchHandler (char *serverUrl, char *methodName,
xmlrpc_value *paramArrayP, void *user_data, xmlrpc_env *faultP,
xmlrpc_value *resultP);
/* ***********************************************************************
** INITCLIENT - Initialize the client-side environment
*************************************************************************/
int
xr_newASync (int cnum)
{
int aclient;
ClientP client = &clientArray[cnum];
aclient = xr_initClient (client->url, "async", "v1.0");
xr_initParam (aclient);
return (aclient);
}
int
xr_setClient (int cnum, char *url)
{
ClientP client = &clientArray[cnum];
memset (client, 0, sizeof(Client));
strcpy (client->url, url);
return (cnum);
}
int
xr_initClient (char *url, char *name, char *version)
{
int client_num = CLIENT_START;
ClientP client;
struct xmlrpc_clientparms clientParms;
/* Initialize XML-RPC interface. We create a private client object so
** we can use asynchronous calls to get the response.
*/
memset (&clientParms, 0, sizeof(clientParms));
for (client_num=CLIENT_START; client_num < MAX_CLIENTS; client_num++) {
client = &clientArray[client_num];
#ifdef REUSE_CLIENT
/* If we've already seen this client before, we've already created
* the RPC client.
*/
if (client->url[0] && strcmp (url, client->url) == 0) {
client->in_use = 1;
client_errstat = OK;
return (client_num);
}
#endif
if (! client->in_use) {
memset (client, 0, sizeof (Client) );
break;
}
}
xmlrpc_env_init (&client->env);
if (! global_init++)
xmlrpc_client_setup_global_const (&client->env);
die_on_error (&client->env);
#ifdef USE_DEFAULT_TRANSPORT
xmlrpc_client_create (&client->env, XMLRPC_CLIENT_NO_FLAGS, name, version,
&clientParms, 0,
&client->rpc_client);
#else
clientParms.transport = "curl";
xmlrpc_client_create (&client->env, XMLRPC_CLIENT_NO_FLAGS, name, version,
&clientParms, XMLRPC_CPSIZE(transport),
&client->rpc_client);
#endif
die_on_error (&client->env);
client->in_use++; /* increment counters */
nclients++;
strcpy (client->url, url); /* save the service url */
client_errstat = OK;
return (client_num);
}
int
xr_closeClient (int cnum)
{
ClientP client = &clientArray[cnum];
if (cnum < 0)
return (ERR);
xr_freeParam (cnum);
xr_freeResult (cnum);
/* Clean up our error-handling environment.
*/
xmlrpc_env_init (&client->env);
xmlrpc_env_clean (&client->env);
/* Close down the client.
xmlrpc_client_destroy (client->rpc_client);
*/
/*
xmlrpc_client_teardown_global_const ();
global_init = 0;
*/
/*
*/
memset (client, 0, sizeof(Client));
nclients--;
return (OK);
}
int xr_pause () { int i = 0; i++; return (i); }
/* CALLSYNC -- Make a synchronous service call. The result value is parsed
** in the caller via the API and using the 'result' pointer gotten here.
*/
int
xr_callSync (int cnum, char *method_name)
{
xmlrpc_value *result = (xmlrpc_value *) NULL;
ClientP client = &clientArray[cnum];
#ifdef DTS
int ntries = 0;
#endif
xmlrpc_server_info *serverInfoP =
xmlrpc_server_info_new (&client->env, client->url);
assert (cnum < MAX_CLIENTS); /* validate the client number */
client_errstat = OK;
xmlrpc_env_init (&client->env);
#ifdef DTS
try_again_:
#endif
xmlrpc_client_call2 (&client->env, client->rpc_client, serverInfoP,
method_name, client->param, &result);
if (client->env.fault_occurred) {
client_errstat = ERR;
if (client_verbose)
warn_on_error (&client->env);
#ifdef DTS
if (strcmp (method_name, "ping") != 0 &&
strcmp (method_name, "poke") != 0 &&
strcmp (method_name, "dtslog") != 0) {
xr_pause();
xmlrpc_env_init (&client->env);
if (ntries++ < 30) {
sleep (3);
fprintf (stderr, "retry ....\n");
goto try_again_;
}
}
#endif
} else {
/*
strcpy (client->faultString, client->env.fault_string);
*/
client_errstat = OK;
}
/* The result is a <params> array with a single <param> entry whose
** <value> will be one of the base XML-RPC types. In the case of an
** <array> or <struct> we need to extract data from those sepearately.
*/
client->result = result;
/* We have the call results, so free the parameters.
xr_freeParam (cnum);
*/
xmlrpc_server_info_free (serverInfoP); /* clean up */
return (client_errstat);
}
/* CALLASYNC -- Make an asynchronous service call. We do this by spawning
** a thread to make the call and handle the result. Treat each asynch
** message as a new client connection.
*/
int
xr_callASync (int cnum, char *name, void *ret_handler)
{
ClientP client = &clientArray[cnum];
pthread_attr_t attr; /* wait thread attribute */
pthread_t tnum; /* wait thread */
ASynch *as = calloc (1, sizeof(ASynch));
/* Get a new client connection for the thread.
tcnum = xr_initClient (client->url, "xrASync", "v1.0");
tclient = &clientArray[tcnum];
bcopy (&clientArray[cnum], &clientArray[tcnum], sizeof(Client) );
xmlrpc_INCREF (tclient->param);
*/
/* Create a detatched thread in which to run.
*/
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
as->name = name;
as->cnum = cnum;
as->client = client;
as->ret_handler = ret_handler;
/* Start the asynch wait thread.
*/
num_asynch_threads++;
if (pthread_create (&tnum, &attr, (void *)xr_asynchRunner, (void *)as)) {
perror ("Cannot start asynch wait thread");
exit (-1);
}
return (OK);
}
static void *
xr_asynchRunner ( void *arg )
{
xmlrpc_env env;
xmlrpc_value *result = (xmlrpc_value *) NULL;
xmlrpc_server_info *serverInfoP;
xmlrpc_client *clientP;
ASynch *as = (ASynch *)(arg);
ClientP client = as->client;
int client_num = as->cnum;
char *url = as->client->url;
xmlrpc_env_init (&env);
serverInfoP = xmlrpc_server_info_new (&env, url);
/* Setup.
*/
xmlrpc_client_setup_global_const (&env);
xmlrpc_client_create (&env, XMLRPC_CLIENT_NO_FLAGS, XR_NAME, XR_VERSION,
NULL, 0, &clientP);
client_errstat = OK;
as->client->handlerFunc = as->ret_handler;
/* Make the asynchronous call and send it off by calling the finish
** routine.
*/
xmlrpc_env_init (&env);
xmlrpc_client_start_rpc (&env, clientP, serverInfoP,
as->name, client->param,
(xmlrpc_response_handler) xr_defaultAsynchHandler,
(void *)&client_num);
if (env.fault_occurred) {
client_errstat = ERR;
if (client_verbose)
warn_on_error (&client->env);
xmlrpc_env_init (&client->env);
}
xmlrpc_client_event_loop_finish (clientP);
/*
** The result is a <params> array with a single <param> entry whose
** <value> will be one of the base XML-RPC types. In the case of an
** <array> or <struct> we need to extract data from those sepearately.
*/
as->client->result = as->result = result;
xmlrpc_server_info_free (serverInfoP); /* clean up */
client->in_use = 0;
xr_closeClient (client_num);
free ((void *)as);
pthread_exit (&client_errstat); /* exit the thread */
}
/* Default asynchronous response handler.
*/
static void
xr_defaultAsynchHandler (char *serverUrl, char *methodName,
xmlrpc_value *paramArrayP,
void *user_data,
xmlrpc_env *faultP,
xmlrpc_value *resultP)
{
int *cnum = (int *)user_data;
ClientP client = &clientArray[*cnum];
int lock;
if (resultP) {
xmlrpc_INCREF(resultP);
client->result = resultP;
if ( (*(PFI)(client->handlerFunc))((void *)cnum) )
fprintf (stderr, "Error calling asynch handler function\n");
} else if (faultP->fault_occurred) {
fprintf (stderr, "Error in asynch (%s): %s\n",
methodName, faultP->fault_string);
client->env = *faultP;
}
/* Decrement the open thread counter.
*/
lock = pthread_mutex_lock (&async_mutex);
num_asynch_threads--;
if (num_asynch_threads < 0)
num_asynch_threads = 0;
lock = pthread_mutex_unlock (&async_mutex);
}
/* XR_ASYNCWAIT -- Wait for all pending asyncronous requests to complete.
**
*/
int
xr_asyncWait ()
{
register int wait = 0;
while (1) {
pthread_mutex_lock (&async_mutex);
wait = num_asynch_threads;
pthread_mutex_unlock (&async_mutex);
if (wait)
sleep (1);
else
break;
}
return (OK);
}
/***************************************************************************
** Set parameter values. This code is used by the programming calling
** the service, i.e. the 'Client'. As such we 'set' the parameters for the
** call. It is in the method implementation on the server side that we
** 'get' the params from the call.
****************************************************************************/
/* Initialize the parameter calling array.
**
*/
void
xr_initParam (int cnum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
/* If we're initializing the calling parameters, free up an previous
** params, results or status flags.
*/
if ( client->param )
xr_freeParam ( cnum );
if ( client->result )
xr_freeResult ( cnum );
client_errstat = OK;
/* Allocate an array for the parameters.
*/
xmlrpc_env_init (&client->env);
client->param = xmlrpc_array_new (&client->env);
if (client_verbose)
warn_on_error (&client->env);
}
/*
** Flag utilities.
*/
void xr_setVerbose (int verbose) { client_verbose = verbose; }
void xr_setDebug (int debug ) { client_debug = debug; }
/* Set parameters of various types. If the param was initialized as an
** an array simply append the new value, otherwise overwrite the param
** with the specified value after freeing it.
*/
void
xr_setIntInParam (int cnum, int value)
{
ClientP client = &clientArray[cnum];
xmlrpc_value *v = (xmlrpc_value *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
xmlrpc_env_init (&client->env); /* initialize env */
v = xmlrpc_int_new (&client->env, value);
if (! client->param )
client->param = xmlrpc_array_new (&client->env);
xmlrpc_array_append_item (&client->env, client->param, v);
if (client_verbose)
warn_on_error (&client->env);
xmlrpc_DECREF(v); /* free temp value */
}
void
xr_setDoubleInParam (int cnum, double value)
{
ClientP client = &clientArray[cnum];
xmlrpc_value *v = (xmlrpc_value *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
xmlrpc_env_init (&client->env);
v = xmlrpc_double_new (&client->env, value);
if (! client->param) /* safety initialization */
client->param = xmlrpc_array_new (&client->env);
xmlrpc_array_append_item (&client->env, client->param, v);
if (client_verbose)
warn_on_error (&client->env);
xmlrpc_DECREF(v);
}
void
xr_setBoolInParam (int cnum, int value)
{
ClientP client = &clientArray[cnum];
xmlrpc_value *v = (xmlrpc_value *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
xmlrpc_env_init (&client->env);
v = xmlrpc_bool_new (&client->env, (xmlrpc_bool) value);
if (! client->param) /* safety initialization */
client->param = xmlrpc_array_new (&client->env);
xmlrpc_array_append_item (&client->env, client->param, v);
if (client_verbose)
warn_on_error (&client->env);
xmlrpc_DECREF(v);
}
void
xr_setStringInParam (int cnum, char *str)
{
ClientP client = &clientArray[cnum];
xmlrpc_value *v = (xmlrpc_value *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
xmlrpc_env_init (&client->env);
v = xmlrpc_string_new (&client->env, (str ? str : ""));
if (! client->param) /* safety initialization */
client->param = xmlrpc_array_new (&client->env);
xmlrpc_array_append_item (&client->env, client->param, v);
if (client_verbose)
warn_on_error (&client->env);
xmlrpc_DECREF(v);
}
void
xr_setDatetimeInParam (int cnum, char *str)
{
ClientP client = &clientArray[cnum];
xmlrpc_value *v = (xmlrpc_value *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
xmlrpc_env_init (&client->env);
v = xmlrpc_datetime_new_str (&client->env, (const char *)str);
if (! client->param) /* safety initialization */
client->param = xmlrpc_array_new (&client->env);
xmlrpc_array_append_item (&client->env, client->param, v);
if (client_verbose)
warn_on_error (&client->env);
xmlrpc_DECREF(v);
}
void
xr_setStructInParam (int cnum, int snum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (! client->param) /* safety initialization */
client->param = xmlrpc_array_new (&client->env);
xmlrpc_env_init (&client->env);
xmlrpc_array_append_item (&client->env, client->param, xr_getSParam(snum));
if (client_verbose)
warn_on_error (&client->env);
}
void
xr_setArrayInParam (int cnum, int anum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (! client->param) /* safety initialization */
client->param = xmlrpc_array_new (&client->env);
xmlrpc_env_init (&client->env);
xmlrpc_array_append_item (&client->env, client->param,
xr_getAElement(anum));
if (client_verbose)
warn_on_error (&client->env);
}
/***************************************************************************
** Get/Set result values.
****************************************************************************/
int
xr_getIntFromResult (int cnum, int *value)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client_errstat == OK) {
xmlrpc_env_init (&client->env);
xmlrpc_read_int (&client->env, client->result, value);
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
int
xr_getDoubleFromResult (int cnum, double *value)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client_errstat == OK) {
xmlrpc_read_double (&client->env, client->result, value);
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
int
xr_getBoolFromResult (int cnum, int *value)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client_errstat == OK) {
xmlrpc_env_init (&client->env);
xmlrpc_read_bool (&client->env, client->result, (xmlrpc_bool *) value);
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
int
xr_getStringFromResult (int cnum, char **value)
{
ClientP client = &clientArray[cnum];
const char *str = (char *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client_errstat == OK) {
xmlrpc_env_init (&client->env);
xmlrpc_read_string (&client->env, client->result, &str);
if (str) {
if (*value)
strcpy (*value, str);
else
*value = strdup (str);
free ((char *) str);
}
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
int
xr_getDatetimeFromResult (int cnum, char **date)
{
ClientP client = &clientArray[cnum];
const char *str = (char *) NULL;
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client_errstat == OK) {
xmlrpc_env_init (&client->env);
xmlrpc_read_datetime_str (&client->env, client->result, &str);
strcpy (*date, str);
if (str) free ((char *) str);
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
int
xr_getStructFromResult (int cnum, int *snum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
*snum = 0;
if (client_errstat == OK) {
*snum = xr_newStruct (); /* FIXME */
xr_setSParam (*snum, client->result);
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
int
xr_getArrayFromResult (int cnum, int *anum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client_errstat == OK) {
*anum = xr_newArray ();
xr_setAElement (*anum, client->result);
return (client->env.fault_occurred ? ERR : OK);
} else
return (ERR);
}
/***************************************************************************
** Utility procedures.
****************************************************************************/
/**
* XR_GETERRMSG -- Get the error message from the last call.
*/
char *
xr_getErrMsg (int cnum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
return (client->env.fault_string);
}
/**
* XR_GETERRCODE -- Get the error code from the last call.
*/
int
xr_getErrCode (int cnum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
return (client->env.fault_occurred);
}
/***************************************************************************
** Cleanup procedures.
****************************************************************************/
/**
* XR_ENVCLEAN -- Clean the environment of the specified client.
*/
void
xr_envClean (int cnum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
xmlrpc_env_clean (&client->env); /* cleanup error-handling env */
}
/**
* XR_FREEPARAM -- Free the Client parameter xmlrpc_value.
*/
void
xr_freeParam (int cnum)
{
ClientP client = &clientArray[cnum];
int refcount = 0;
extern int xmlrpc_refcount();
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client->param) {
/*
int len = xmlrpc_array_size (&client->env, client->param);
xmlrpc_value *v;
while (len >= 0) {
xmlrpc_array_read_item (&client->env, client->param, --len, &v);
warn_on_error (&client->env);
xmlrpc_DECREF (v);
}
*/
refcount = xmlrpc_refcount (client->param) - 1;
xmlrpc_DECREF (client->param);
#ifdef CLEAN_ENV
xmlrpc_env_clean(&client->env);
#endif
}
if (refcount == 0)
client->param = (xmlrpc_value *) NULL;
}
/**
* Free the Client result xmlrpc_value.
*/
void
xr_freeResult (int cnum)
{
ClientP client = &clientArray[cnum];
int refcount = 0;
extern int xmlrpc_refcount();
assert (cnum < MAX_CLIENTS); /* validate the client number */
if (client->result) {
/*
int len = xmlrpc_array_size (&client->env, client->result);
xmlrpc_value *v;
while (len >= 0) {
xmlrpc_array_read_item (&client->env, client->result, --len, &v);
warn_on_error (&client->env);
xmlrpc_DECREF (v);
}
*/
refcount = xmlrpc_refcount (client->result) - 1;
if (refcount)
xmlrpc_DECREF (client->result);
#ifdef CLEAN_ENV
xmlrpc_env_clean(&client->env);
#endif
}
if (refcount == 0)
client->result = (xmlrpc_value *) NULL;
}
/**
* Shutdown our XML-RPC client library.
*/
void
xr_clientCleanup (int cnum)
{
assert (cnum < MAX_CLIENTS); /* validate the client number */
/*
if (client->rpc_client)
xmlrpc_client_cleanup ();
*/
xr_envClean (cnum); /* cleanup error-handling env */
}
void
printClient (int cnum)
{
ClientP client = &clientArray[cnum];
assert (cnum < MAX_CLIENTS); /* validate the client number */
fprintf (stderr, "Client %d\n", cnum);
fprintf (stderr, " url = '%s'\n", client->url);
fprintf (stderr, " param = 0x%lx\n", (long) client->param);
fprintf (stderr, " result = 0x%lx\n", (long) client->result);
fprintf (stderr, " client = 0x%lx\n", (long) client->rpc_client);
fprintf (stderr, " in_use = %d\n", client->in_use);
}
|