initial load of upstream version 1.06.32
[xmlrpc-c] / examples / xmlrpc_sample_add_server_cgi.c
1 /* A simple standalone XML-RPC server written in C. */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include <xmlrpc-c/base.h>
7 #include <xmlrpc-c/server.h>
8 #include <xmlrpc-c/server_cgi.h>
9
10 #include "config.h"  /* information about this build environment */
11
12 static xmlrpc_value *
13 sample_add(xmlrpc_env *   const env, 
14            xmlrpc_value * const param_array, 
15            void *         const user_data ATTR_UNUSED) {
16
17     xmlrpc_int32 x, y, z;
18
19     /* Parse our argument array. */
20     xmlrpc_decompose_value(env, param_array, "(ii)", &x, &y);
21     if (env->fault_occurred)
22         return NULL;
23
24     /* Add our two numbers. */
25     z = x + y;
26
27     /* Return our result. */
28     return xmlrpc_build_value(env, "i", z);
29 }
30
31
32
33 int 
34 main(int           const argc, 
35      const char ** const argv) {
36
37     xmlrpc_registry * registryP;
38     xmlrpc_env env;
39
40     if (argc-1 > 0 && argv==argv) {
41         fprintf(stderr, "There are no arguments to a CGI script\n");
42         exit(1);
43     }
44
45     xmlrpc_env_init(&env);
46
47     registryP = xmlrpc_registry_new(&env);
48
49     xmlrpc_registry_add_method(
50         &env, registryP, NULL, "sample.add", &sample_add, NULL);
51
52     xmlrpc_server_cgi_process_call(registryP);
53
54     xmlrpc_registry_free(registryP);
55
56     return 0;
57 }