xmlrpc_sample_add_server_cgi.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* A CGI script written in C to effect a simple XML-RPC server.
  2. Example of use:
  3. - Compile this as the executable 'xmlrpc_sample_add_server.cgi'
  4. - Place the .cgi file in web server www.example.com's /cgi-bin
  5. directory.
  6. - Configure the web server to permit CGI scripts in /cgi-bin
  7. (Apache ExecCgi directory option).
  8. - Configure the web server to recognize this .cgi file as a CGI
  9. script (Apache "AddHandler cgi-script ..." or ScriptAlias).
  10. - $ xmlrpc http://www.example.com/cgi-bin/xmlrpc_sample_add_server.cgi \
  11. sample.add i/5 i/7
  12. */
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <xmlrpc-c/base.h>
  16. #include <xmlrpc-c/server.h>
  17. #include <xmlrpc-c/server_cgi.h>
  18. #include "config.h" /* information about this build environment */
  19. static xmlrpc_value *
  20. sample_add(xmlrpc_env * const envP,
  21. xmlrpc_value * const paramArrayP,
  22. void * const user_data) {
  23. xmlrpc_int32 x, y, z;
  24. /* Parse our argument array. */
  25. xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
  26. if (envP->fault_occurred)
  27. return NULL;
  28. /* Add our two numbers. */
  29. z = x + y;
  30. /* Return our result. */
  31. return xmlrpc_build_value(envP, "i", z);
  32. }
  33. int
  34. main(int const argc,
  35. const char ** const argv) {
  36. xmlrpc_registry * registryP;
  37. xmlrpc_env env;
  38. if (argc-1 > 0 && argv==argv) {
  39. fprintf(stderr, "There are no arguments to a CGI script\n");
  40. exit(1);
  41. }
  42. xmlrpc_env_init(&env);
  43. registryP = xmlrpc_registry_new(&env);
  44. xmlrpc_registry_add_method(
  45. &env, registryP, NULL, "sample.add", &sample_add, NULL);
  46. xmlrpc_server_cgi_process_call(registryP);
  47. xmlrpc_registry_free(registryP);
  48. return 0;
  49. }