1 /* A simple standalone XML-RPC server written in C as an example of use of
2 the Xmlrpc-c libraries.
4 This example expects an already bound socket on Standard Input, ready to
5 be listened on for client connections. Also see xmlrpc_sample_add_server,
6 which is the same thing, except you tell it a TCP port number and it
7 creates the socket itself.
16 #include <xmlrpc-c/base.h>
17 #include <xmlrpc-c/server.h>
18 #include <xmlrpc-c/server_abyss.h>
20 #include "config.h" /* information about this build environment */
23 sample_add(xmlrpc_env * const env,
24 xmlrpc_value * const param_array,
25 void * const user_data ATTR_UNUSED) {
29 /* Parse our argument array. */
30 xmlrpc_decompose_value(env, param_array, "(ii)", &x, &y);
31 if (env->fault_occurred)
34 /* Add our two numbers. */
37 /* Sometimes, make it look hard (so client can see what it's like
38 to do an RPC that takes a while).
43 /* Return our result. */
44 return xmlrpc_build_value(env, "i", z);
51 const char ** const argv) {
53 xmlrpc_server_abyss_parms serverparm;
54 xmlrpc_registry * registryP;
58 fprintf(stderr, "There are no arguments. You must supply a "
59 "bound socket on which to listen for client connections "
60 "as Standard Input\n");
61 if (argv) {} /* silence unused parameter warning */
65 xmlrpc_env_init(&env);
67 registryP = xmlrpc_registry_new(&env);
69 xmlrpc_registry_add_method(
70 &env, registryP, NULL, "sample.add", &sample_add, NULL);
72 /* In the modern form of the Abyss API, we supply parameters in memory
73 like a normal API. We select the modern form by setting
74 config_file_name to NULL:
76 serverparm.config_file_name = NULL;
77 serverparm.registryP = registryP;
78 serverparm.log_file_name = "/tmp/xmlrpc_log";
79 serverparm.keepalive_timeout = 0;
80 serverparm.keepalive_max_conn = 0;
81 serverparm.timeout = 0;
82 serverparm.dont_advertise = FALSE;
83 serverparm.socket_bound = TRUE;
84 serverparm.socket_handle = STDIN_FILENO;
86 printf("Running XML-RPC server...\n");
88 xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(socket_handle));