freeswitch/libs/xmlrpc-c/examples/xmlrpc_sample_add_server_cgi.c
Michael Jerris 3abb7730b2 add xmlrpc-c 1.03.14 to in tree libs
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3772 d0543943-73ff-0310-b7d9-9358b9ac24b2
2006-12-21 03:57:49 +00:00

58 lines
1.2 KiB
C

/* 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 *
sample_add(xmlrpc_env * const env,
xmlrpc_value * const param_array,
void * const user_data ATTR_UNUSED) {
xmlrpc_int32 x, y, z;
/* Parse our argument array. */
xmlrpc_decompose_value(env, param_array, "(ii)", &x, &y);
if (env->fault_occurred)
return NULL;
/* Add our two numbers. */
z = x + y;
/* Return our result. */
return xmlrpc_build_value(env, "i", z);
}
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;
}