2
0

synch_client.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* A simple synchronous XML-RPC client program written in C. */
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <xmlrpc-c/base.h>
  5. #include <xmlrpc-c/client.h>
  6. #include "config.h" /* information about this build environment */
  7. #define NAME "XML-RPC C Test Client synch_client"
  8. #define VERSION "1.0"
  9. static void
  10. die_if_fault_occurred(xmlrpc_env * const envP) {
  11. if (envP->fault_occurred) {
  12. fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
  13. envP->fault_string, envP->fault_code);
  14. exit(1);
  15. }
  16. }
  17. int
  18. main(int const argc,
  19. const char ** const argv) {
  20. xmlrpc_env env;
  21. xmlrpc_value * resultP;
  22. const char * stateName;
  23. if (argc-1 > 0) {
  24. fprintf(stderr, "No arguments");
  25. exit(0);
  26. }
  27. /* Start up our XML-RPC client library. */
  28. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
  29. /* Initialize our error-handling environment. */
  30. xmlrpc_env_init(&env);
  31. /* Call the famous server at UserLand. */
  32. resultP = xmlrpc_client_call(&env, "http://betty.userland.com/RPC2",
  33. "examples.getStateName",
  34. "(i)", (xmlrpc_int32) 41);
  35. die_if_fault_occurred(&env);
  36. /* Get our state name and print it out. */
  37. xmlrpc_read_string(&env, resultP, &stateName);
  38. die_if_fault_occurred(&env);
  39. printf("%s\n", stateName);
  40. free((char*)stateName);
  41. /* Dispose of our result value. */
  42. xmlrpc_DECREF(resultP);
  43. /* Clean up our error-handling environment. */
  44. xmlrpc_env_clean(&env);
  45. /* Shutdown our XML-RPC client library. */
  46. xmlrpc_client_cleanup();
  47. return 0;
  48. }