2006-12-20 22:57:49 -05:00
|
|
|
/* A simple standalone XML-RPC server written in C. */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <xmlrpc-c/base.h>
|
|
|
|
#include <xmlrpc-c/server.h>
|
|
|
|
#include <xmlrpc-c/server_cgi.h>
|
|
|
|
|
|
|
|
#include "config.h" /* information about this build environment */
|
|
|
|
|
|
|
|
static xmlrpc_value *
|
2008-05-23 16:56:24 -04:00
|
|
|
sample_add(xmlrpc_env * const envP,
|
|
|
|
xmlrpc_value * const paramArrayP,
|
2006-12-20 22:57:49 -05:00
|
|
|
void * const user_data ATTR_UNUSED) {
|
|
|
|
|
|
|
|
xmlrpc_int32 x, y, z;
|
|
|
|
|
|
|
|
/* Parse our argument array. */
|
2008-05-23 16:56:24 -04:00
|
|
|
xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
|
|
|
|
if (envP->fault_occurred)
|
2006-12-20 22:57:49 -05:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Add our two numbers. */
|
|
|
|
z = x + y;
|
|
|
|
|
|
|
|
/* Return our result. */
|
2008-05-23 16:56:24 -04:00
|
|
|
return xmlrpc_build_value(envP, "i", z);
|
2006-12-20 22:57:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int const argc,
|
|
|
|
const char ** const argv) {
|
|
|
|
|
|
|
|
xmlrpc_registry * registryP;
|
|
|
|
xmlrpc_env env;
|
|
|
|
|
|
|
|
if (argc-1 > 0 && argv==argv) {
|
|
|
|
fprintf(stderr, "There are no arguments to a CGI script\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlrpc_env_init(&env);
|
|
|
|
|
|
|
|
registryP = xmlrpc_registry_new(&env);
|
|
|
|
|
|
|
|
xmlrpc_registry_add_method(
|
|
|
|
&env, registryP, NULL, "sample.add", &sample_add, NULL);
|
|
|
|
|
|
|
|
xmlrpc_server_cgi_process_call(registryP);
|
|
|
|
|
|
|
|
xmlrpc_registry_free(registryP);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|