interop-cgi.c 6.4 KB

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