1 /* A simple standalone XML-RPC server written in C. */
9 #include <xmlrpc-c/base.h>
10 #include <xmlrpc-c/server.h>
11 #include <xmlrpc-c/server_abyss.h>
13 #include "config.h" /* information about this build environment */
16 sample_add(xmlrpc_env * const env,
17 xmlrpc_value * const param_array,
18 void * const user_data ATTR_UNUSED) {
22 /* Parse our argument array. */
23 xmlrpc_decompose_value(env, param_array, "(ii)", &x, &y);
24 if (env->fault_occurred)
27 /* Add our two numbers. */
30 /* Sometimes, make it look hard (so client can see what it's like
31 to do an RPC that takes a while).
36 /* Return our result. */
37 return xmlrpc_build_value(env, "i", z);
44 const char ** const argv) {
46 xmlrpc_server_abyss_parms serverparm;
47 xmlrpc_registry * registryP;
51 fprintf(stderr, "You must specify 1 argument: The TCP port "
52 "number on which the server will accept connections "
53 "for RPCs. You specified %d arguments.\n", argc-1);
57 xmlrpc_env_init(&env);
59 registryP = xmlrpc_registry_new(&env);
61 xmlrpc_registry_add_method(
62 &env, registryP, NULL, "sample.add", &sample_add, NULL);
64 /* In the modern form of the Abyss API, we supply parameters in memory
65 like a normal API. We select the modern form by setting
66 config_file_name to NULL:
68 serverparm.config_file_name = NULL;
69 serverparm.registryP = registryP;
70 serverparm.port_number = atoi(argv[1]);
71 serverparm.log_file_name = "/tmp/xmlrpc_log";
73 printf("Running XML-RPC server...\n");
75 xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));
77 /* xmlrpc_server_abyss() never returns */