2006-12-20 22:57:49 -05:00
|
|
|
/* A simple synchronous XML-RPC client written in C, as an example of
|
|
|
|
an Xmlrpc-c client. This invokes the sample.add procedure that the
|
|
|
|
Xmlrpc-c example server.c server provides. I.e. it adds to numbers
|
|
|
|
together, the hard way.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <xmlrpc-c/base.h>
|
|
|
|
#include <xmlrpc-c/client.h>
|
|
|
|
|
|
|
|
#include "config.h" /* information about this build environment */
|
|
|
|
|
|
|
|
#define NAME "Xmlrpc-c Test Client"
|
|
|
|
#define VERSION "1.0"
|
|
|
|
|
|
|
|
static void
|
2008-05-23 16:56:24 -04:00
|
|
|
die_if_fault_occurred (xmlrpc_env * const envP) {
|
|
|
|
if (envP->fault_occurred) {
|
2006-12-20 22:57:49 -05:00
|
|
|
fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
|
2008-05-23 16:56:24 -04:00
|
|
|
envP->fault_string, envP->fault_code);
|
2006-12-20 22:57:49 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int const argc,
|
|
|
|
const char ** const argv ATTR_UNUSED) {
|
|
|
|
|
|
|
|
xmlrpc_env env;
|
2008-05-23 16:56:24 -04:00
|
|
|
xmlrpc_value * resultP;
|
2006-12-20 22:57:49 -05:00
|
|
|
xmlrpc_int32 sum;
|
2008-05-23 16:56:24 -04:00
|
|
|
const char * const serverUrl = "http://localhost:8080/RPC2";
|
|
|
|
const char * const methodName = "sample.add";
|
2006-12-20 22:57:49 -05:00
|
|
|
|
|
|
|
if (argc-1 > 0) {
|
|
|
|
fprintf(stderr, "This program has no arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize our error-handling environment. */
|
|
|
|
xmlrpc_env_init(&env);
|
|
|
|
|
|
|
|
/* Start up our XML-RPC client library. */
|
|
|
|
xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
|
|
|
|
die_if_fault_occurred(&env);
|
|
|
|
|
|
|
|
printf("Making XMLRPC call to server url '%s' method '%s' "
|
|
|
|
"to request the sum "
|
|
|
|
"of 5 and 7...\n", serverUrl, methodName);
|
|
|
|
|
|
|
|
/* Make the remote procedure call */
|
2008-05-23 16:56:24 -04:00
|
|
|
resultP = xmlrpc_client_call(&env, serverUrl, methodName,
|
|
|
|
"(ii)", (xmlrpc_int32) 5, (xmlrpc_int32) 7);
|
2006-12-20 22:57:49 -05:00
|
|
|
die_if_fault_occurred(&env);
|
|
|
|
|
|
|
|
/* Get our sum and print it out. */
|
2008-05-23 16:56:24 -04:00
|
|
|
xmlrpc_read_int(&env, resultP, &sum);
|
2006-12-20 22:57:49 -05:00
|
|
|
die_if_fault_occurred(&env);
|
2008-05-23 16:56:24 -04:00
|
|
|
printf("The sum is %d\n", sum);
|
2006-12-20 22:57:49 -05:00
|
|
|
|
|
|
|
/* Dispose of our result value. */
|
2008-05-23 16:56:24 -04:00
|
|
|
xmlrpc_DECREF(resultP);
|
2006-12-20 22:57:49 -05:00
|
|
|
|
|
|
|
/* Clean up our error-handling environment. */
|
|
|
|
xmlrpc_env_clean(&env);
|
|
|
|
|
|
|
|
/* Shutdown our XML-RPC client library. */
|
|
|
|
xmlrpc_client_cleanup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|