ENH: make this work for older versions of OSX
[cmake.git] / Utilities / cmxmlrpc / synch_client.c
blob7c814858fa06bffed684b7517027f93c61f30db6
1 /* A simple synchronous XML-RPC client written in C. */
3 #include <stdio.h>
4 #include <stdlib.h>
6 #include <xmlrpc.h>
7 #include <xmlrpc_client.h>
9 #define NAME "XML-RPC C Test Client"
10 #define VERSION "0.1"
12 static void die_if_fault_occurred (xmlrpc_env *env)
14 if (env->fault_occurred) {
15 fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
16 env->fault_string, env->fault_code);
17 exit(1);
23 int
24 main(int const argc,
25 const char ** const argv ATTR_UNUSED) {
27 xmlrpc_env env;
28 char *state_name;
29 int cc;
31 if (argc-1 > 0) {
32 fprintf(stderr, "No arguments");
33 exit(0);
36 /* Start up our XML-RPC client library. */
37 xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
39 /* Initialize our error-handling environment. */
40 xmlrpc_env_init(&env);
42 /* Call the famous server at UserLand. */
43 for ( cc = 30; cc < 35; cc ++ )
45 xmlrpc_value *result;
46 result = xmlrpc_client_call(&env, "http://betty.userland.com/RPC2",
47 "examples.getStateName",
48 "(i)", (xmlrpc_int32) cc);
49 die_if_fault_occurred(&env);
51 /* Get our state name and print it out. */
52 xmlrpc_parse_value(&env, result, "s", &state_name);
53 die_if_fault_occurred(&env);
54 printf("%d: %s\n", cc, state_name);
56 /* Dispose of our result value. */
57 xmlrpc_DECREF(result);
61 /* Clean up our error-handling environment. */
62 xmlrpc_env_clean(&env);
64 /* Shutdown our XML-RPC client library. */
65 xmlrpc_client_cleanup();
67 return 0;