2005-02-28 21:26:20 +00:00
|
|
|
/* A simple synchronous XML-RPC client written in C. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2005-03-01 16:21:56 +00:00
|
|
|
#include <stdlib.h>
|
2005-02-28 21:26:20 +00:00
|
|
|
|
|
|
|
#include <xmlrpc.h>
|
|
|
|
#include <xmlrpc_client.h>
|
|
|
|
|
|
|
|
#define NAME "XML-RPC C Test Client"
|
|
|
|
#define VERSION "0.1"
|
|
|
|
|
|
|
|
static void die_if_fault_occurred (xmlrpc_env *env)
|
|
|
|
{
|
|
|
|
if (env->fault_occurred) {
|
|
|
|
fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
|
|
|
|
env->fault_string, env->fault_code);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int const argc,
|
|
|
|
const char ** const argv ATTR_UNUSED) {
|
|
|
|
|
|
|
|
xmlrpc_env env;
|
|
|
|
char *state_name;
|
2005-03-04 20:04:59 +00:00
|
|
|
int cc;
|
2005-02-28 21:26:20 +00:00
|
|
|
|
|
|
|
if (argc-1 > 0) {
|
|
|
|
fprintf(stderr, "No arguments");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start up our XML-RPC client library. */
|
|
|
|
xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
|
|
|
|
|
|
|
|
/* Initialize our error-handling environment. */
|
|
|
|
xmlrpc_env_init(&env);
|
|
|
|
|
|
|
|
/* Call the famous server at UserLand. */
|
2005-03-04 20:04:59 +00:00
|
|
|
for ( cc = 30; cc < 35; cc ++ )
|
|
|
|
{
|
2005-03-06 13:52:50 +00:00
|
|
|
xmlrpc_value *result;
|
2005-03-04 20:04:59 +00:00
|
|
|
result = xmlrpc_client_call(&env, "http://betty.userland.com/RPC2",
|
2005-02-28 21:26:20 +00:00
|
|
|
"examples.getStateName",
|
2005-03-04 20:04:59 +00:00
|
|
|
"(i)", (xmlrpc_int32) cc);
|
|
|
|
die_if_fault_occurred(&env);
|
|
|
|
|
|
|
|
/* Get our state name and print it out. */
|
|
|
|
xmlrpc_parse_value(&env, result, "s", &state_name);
|
|
|
|
die_if_fault_occurred(&env);
|
|
|
|
printf("%d: %s\n", cc, state_name);
|
2005-03-06 13:52:50 +00:00
|
|
|
|
|
|
|
/* Dispose of our result value. */
|
|
|
|
xmlrpc_DECREF(result);
|
|
|
|
|
2005-03-04 20:04:59 +00:00
|
|
|
}
|
2005-02-28 21:26:20 +00:00
|
|
|
|
|
|
|
/* Clean up our error-handling environment. */
|
|
|
|
xmlrpc_env_clean(&env);
|
|
|
|
|
|
|
|
/* Shutdown our XML-RPC client library. */
|
|
|
|
xmlrpc_client_cleanup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|