initial load of upstream version 1.06.32
[xmlrpc-c] / tools / interop-server / interop-cgi.c
1 /* A CGI which implements all of the test functions need for an interop
2 ** endpoint. */
3
4 #include <sys/utsname.h>
5 #include <errno.h>
6 #include <string.h>
7
8 #include "xmlrpc-c/base.h"
9 #include "xmlrpc-c/cgi.h"
10
11 #include "version.h"
12
13 #include "config.h"  /* information about this build environment */
14
15
16 /*=========================================================================
17 **  Toolkit Identification
18 **=========================================================================
19 */
20
21 static xmlrpc_value *
22 whichToolkit(xmlrpc_env *   const env, 
23              xmlrpc_value * const param_array, 
24              void *         const user_data ATTR_UNUSED) {
25
26     xmlrpc_value * retval;
27
28     /* Parse our argument array. */
29     xmlrpc_parse_value(env, param_array, "()");
30     if (env->fault_occurred)
31         retval = NULL;
32     else {
33         struct utsname utsname;
34
35         int rc;
36         rc = uname(&utsname);
37         if (rc != 0) {
38             xmlrpc_env_set_fault_formatted(env, XMLRPC_INTERNAL_ERROR,
39                                            "uname() failed.  errno=%d (%s)",
40                                            errno, strerror(errno));
41             retval = NULL;
42         } else {
43             /* Assemble our result. */
44             retval = xmlrpc_build_value(env, "{s:s,s:s,s:s,s:s}",
45                                         "toolkitDocsUrl",
46                                         "http://xmlrpc-c.sourceforge.net/",
47                                         "toolkitName", PACKAGE,
48                                         "toolkitVersion", XMLRPC_C_VERSION"+",
49                                         "toolkitOperatingSystem", 
50                                         utsname.sysname);
51         }
52     }
53     return retval;
54 }
55
56
57
58 static char whichToolkit_help[] =
59 "Identify the toolkit used to implement this server.  The operating system "
60 "information is based on where the toolkit was compiled, not where it's "
61 "currently running.";
62
63
64 /*=========================================================================
65 **  noInParams
66 **=========================================================================
67 **  Test a method with no parameters.
68 */
69
70 static xmlrpc_value *
71 noInParams(xmlrpc_env *   const env, 
72            xmlrpc_value * const param_array, 
73            void *         const user_data ATTR_UNUSED) {
74
75     /* Parse our argument array. */
76     xmlrpc_parse_value(env, param_array, "()");
77     if (env->fault_occurred)
78         return NULL;
79
80     /* Assemble our result. */
81     return xmlrpc_build_value(env, "i", (xmlrpc_int32) 0);
82 }
83
84 static char noInParams_help[] =
85 "A method with no parameters.  Returns an arbitrary int.";
86
87
88 /*=========================================================================
89 **  Echo Tests
90 **=========================================================================
91 **  We're lazy--we only implement one actual echo method, but we hook it
92 **  up to lots of different names.
93 */
94
95 static xmlrpc_value *
96 echoValue(xmlrpc_env *   const env, 
97           xmlrpc_value * const param_array, 
98           void *         const user_data ATTR_UNUSED) {
99
100     xmlrpc_value *val;
101
102     /* Parse our argument array. */
103     xmlrpc_parse_value(env, param_array, "(V)", &val);
104     if (env->fault_occurred)
105         return NULL;
106
107     /* Create a new reference (because both our parameter list and our
108     ** return value will be DECREF'd when we return). */
109     xmlrpc_INCREF(val);
110
111     /* Return our result. */
112     return val;
113 }
114
115 static char echoValue_help[] =
116 "Echo an arbitrary XML-RPC value of any type.";
117
118 static char echoString_help[] =
119 "Echo an arbitrary XML-RPC string.";
120
121 static char echoInteger_help[] =
122 "Echo an arbitrary XML-RPC integer.";
123
124 static char echoBoolean_help[] =
125 "Echo an arbitrary XML-RPC boolean value.";
126
127 static char echoFloat_help[] =
128 "Echo an arbitrary XML-RPC float.";
129
130 static char echoStruct_help[] =
131 "Echo an arbitrary XML-RPC struct.";
132
133 static char echoDate_help[] =
134 "Echo an arbitrary XML-RPC date/time value.";
135
136 static char echoBase64_help[] =
137 "Echo an arbitrary XML-RPC Base64 value.";
138
139 static char echoStringArray_help[] =
140 "Echo an array of arbitrary XML-RPC strings.";
141
142 static char echoIntegerArray_help[] =
143 "Echo an array of arbitrary XML-RPC integers.";
144
145 static char echoFloatArray_help[] =
146 "Echo an array of arbitrary XML-RPC floats.";
147
148 static char echoStructArray_help[] =
149 "Echo an array of arbitrary XML-RPC structs.";
150
151
152 /*=========================================================================
153 **  Server Setup
154 **=========================================================================
155 **  Set up and run our server.
156 */
157
158 int 
159 main(int     const argc ATTR_UNUSED, 
160      char ** const argv ATTR_UNUSED) {
161
162     /* Process our request. */
163     xmlrpc_cgi_init(XMLRPC_CGI_NO_FLAGS);
164
165     /* Add a method to identify our toolkit. */
166     xmlrpc_cgi_add_method_w_doc("interopEchoTests.whichToolkit",
167                                 &whichToolkit, NULL,
168                                 "S:", whichToolkit_help);
169
170     /* Add a whole bunch of test methods. */
171     xmlrpc_cgi_add_method_w_doc("interopEchoTests.noInParams",
172                                 &noInParams, NULL,
173                                 "i:", noInParams_help);
174     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoValue",
175                                 &echoValue, NULL,
176                                 "?", echoValue_help);
177     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoString",
178                                 &echoValue, NULL,
179                                 "s:s", echoString_help);
180     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoInteger",
181                                 &echoValue, NULL,
182                                 "i:i", echoInteger_help);
183     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoBoolean",
184                                 &echoValue, NULL,
185                                 "b:b", echoBoolean_help);
186     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoFloat",
187                                 &echoValue, NULL,
188                                 "d:d", echoFloat_help);
189     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoStruct",
190                                 &echoValue, NULL,
191                                 "S:S", echoStruct_help);
192     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoDate",
193                                 &echoValue, NULL,
194                                 "8:8", echoDate_help);
195     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoBase64",
196                                 &echoValue, NULL,
197                                 "6:6", echoBase64_help);
198     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoStringArray",
199                                 &echoValue, NULL,
200                                 "A:A", echoStringArray_help);
201     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoIntegerArray",
202                                 &echoValue, NULL,
203                                 "A:A", echoIntegerArray_help);
204     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoFloatArray",
205                                 &echoValue, NULL,
206                                 "A:A", echoFloatArray_help);
207     xmlrpc_cgi_add_method_w_doc("interopEchoTests.echoStructArray",
208                                 &echoValue, NULL,
209                                 "A:A", echoStructArray_help);
210
211     xmlrpc_cgi_process_call();
212     xmlrpc_cgi_cleanup();
213
214     return 0;
215 }