include stdio include xmlrpc include xmlrpc_client define NAME XML-RPC

 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
#include <stdio.h>
#include <xmlrpc.h>
#include <xmlrpc_client.h>
#define NAME "XML-RPC getSumAndDifference C Client"
#define VERSION "0.1"
#define SERVER_URL "http://xmlrpc-c.sourceforge.net/api/sample.php"
void die_if_fault_occurred (xmlrpc_env *env)
{
/* Check our error-handling environment for an XML-RPC fault. */
if (env->fault_occurred) {
fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
env->fault_string, env->fault_code);
exit(1);
}
}
int main (int argc, char** argv)
{
xmlrpc_env env;
xmlrpc_value *result;
xmlrpc_int32 sum, difference;
/* Start up our XML-RPC client library. */
xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
xmlrpc_env_init(&env);
/* Call our XML-RPC server. */
result = xmlrpc_client_call(&env, SERVER_URL,
"sample.sumAndDifference", "(ii)",
(xmlrpc_int32) 5,
(xmlrpc_int32) 3);
die_if_fault_occurred(&env);
/* Parse our result value. */
xmlrpc_parse_value(&env, result, "{s:i,s:i,*}",
"sum", &sum,
"difference", &difference);
die_if_fault_occurred(&env);
/* Print out our sum and difference. */
printf("Sum: %d, Difference: %d\n", (int) sum, (int) difference);
/* Dispose of our result value. */
xmlrpc_DECREF(result);
/* Shutdown our XML-RPC client library. */
xmlrpc_env_clean(&env);
xmlrpc_client_cleanup();
return 0;
}