initial load of upstream version 1.06.32
[xmlrpc-c] / src / test / cgitest1.c
1 /*============================================================================
2   Act like a CGI script -- read POST data from Standard Input, interpret
3   it as an XML-RPC call, and write an XML-RPC response to Standard Output.
4
5   This is for use by a test program.
6 ============================================================================*/
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <errno.h>
12
13 #include "xmlrpc_config.h"
14
15 #include "xmlrpc-c/base.h"
16 #include "xmlrpc-c/server.h"
17 #include "xmlrpc-c/server_cgi.h"
18
19 #include "test.h"
20
21
22 int total_tests;
23 int total_failures;
24
25
26
27 static xmlrpc_value *
28 sample_add(xmlrpc_env *   const env, 
29            xmlrpc_value * const param_array, 
30            void *         const user_data ATTR_UNUSED) {
31
32     xmlrpc_int32 x, y, z;
33
34     /* Parse our argument array. */
35     xmlrpc_decompose_value(env, param_array, "(ii)", &x, &y);
36     if (env->fault_occurred)
37         return NULL;
38
39     /* Add our two numbers. */
40     z = x + y;
41
42     /* Return our result. */
43     return xmlrpc_build_value(env, "i", z);
44 }
45
46
47
48 int
49 main(int     argc ATTR_UNUSED,
50      char ** argv ATTR_UNUSED) {
51
52     xmlrpc_env env;
53     xmlrpc_registry * registryP;
54     xmlrpc_value * argArrayP;
55
56     xmlrpc_env_init(&env);
57
58     registryP = xmlrpc_registry_new(&env);
59     TEST(registryP != NULL);
60     TEST_NO_FAULT(&env);
61
62     xmlrpc_registry_add_method(&env, registryP, NULL, "sample.add",
63                                sample_add, NULL);
64     TEST_NO_FAULT(&env);
65
66     argArrayP = xmlrpc_build_value(&env, "(ii)",
67                                    (xmlrpc_int32) 25, (xmlrpc_int32) 17); 
68     TEST_NO_FAULT(&env);
69
70     /* The following reads from Standard Input and writes to Standard
71        Output
72     */
73     xmlrpc_server_cgi_process_call(registryP);
74
75     xmlrpc_DECREF(argArrayP);
76     xmlrpc_registry_free(registryP);
77
78     return 0;
79 }