initial load of upstream version 1.06.32
[xmlrpc-c] / examples / synch_client.c
1 /* A simple synchronous XML-RPC client written in C. */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include <xmlrpc-c/base.h>
7 #include <xmlrpc-c/client.h>
8
9 #include "config.h"  /* information about this build environment */
10
11 #define NAME "XML-RPC C Test Client synch_client"
12 #define VERSION "1.0"
13
14 static void die_if_fault_occurred (xmlrpc_env *env)
15 {
16     if (env->fault_occurred) {
17         fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
18                 env->fault_string, env->fault_code);
19         exit(1);
20     }
21 }
22
23
24
25 int 
26 main(int           const argc, 
27      const char ** const argv ATTR_UNUSED) {
28
29     xmlrpc_env env;
30     xmlrpc_value * resultP;
31     const char * state_name;
32
33     if (argc-1 > 0) {
34         fprintf(stderr, "No arguments");
35         exit(0);
36     }
37
38     /* Start up our XML-RPC client library. */
39     xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
40
41     /* Initialize our error-handling environment. */
42     xmlrpc_env_init(&env);
43
44     /* Call the famous server at UserLand. */
45     resultP = xmlrpc_client_call(&env, "http://betty.userland.com/RPC2",
46                                  "examples.getStateName",
47                                  "(i)", (xmlrpc_int32) 41);
48     die_if_fault_occurred(&env);
49     
50     /* Get our state name and print it out. */
51     xmlrpc_read_string(&env, resultP, &state_name);
52     die_if_fault_occurred(&env);
53     printf("%s\n", state_name);
54     free((char*)state_name);
55    
56     /* Dispose of our result value. */
57     xmlrpc_DECREF(resultP);
58
59     /* Clean up our error-handling environment. */
60     xmlrpc_env_clean(&env);
61     
62     /* Shutdown our XML-RPC client library. */
63     xmlrpc_client_cleanup();
64
65     return 0;
66 }