2
0

gen_sample_add_xml.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* This program generates on Standard Output the XML for an XML-RPC
  2. call suitable for the xmlrpc_sample_add_server program.
  3. This is the same XML that the xmlrpc_sample_add_client program sends.
  4. Use this either as an example of how to use the Xmlrpc-c XML-generating
  5. functions or to generate XML that you can use to test an XML-RPC
  6. server.
  7. */
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <xmlrpc-c/base.h>
  11. #include "config.h"
  12. static void
  13. die_if_fault_occurred(xmlrpc_env * const envP) {
  14. if (envP->fault_occurred) {
  15. fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
  16. envP->fault_string, envP->fault_code);
  17. exit(1);
  18. }
  19. }
  20. int
  21. main(int const argc,
  22. const char ** const argv) {
  23. char * const methodName = "sample.add";
  24. xmlrpc_env env;
  25. xmlrpc_value * params;
  26. xmlrpc_mem_block * xmlmemblockP;
  27. if (argc-1 > 0) {
  28. fprintf(stderr, "This program has no arguments\n");
  29. exit(1);
  30. }
  31. /* Initialize our error-handling environment. */
  32. xmlrpc_env_init(&env);
  33. params = xmlrpc_build_value(&env, "(ii)",
  34. (xmlrpc_int32) 5, (xmlrpc_int32) 7);
  35. die_if_fault_occurred(&env);
  36. xmlmemblockP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
  37. xmlrpc_serialize_call(&env, xmlmemblockP, methodName, params);
  38. die_if_fault_occurred(&env);
  39. fwrite(XMLRPC_MEMBLOCK_CONTENTS(char, xmlmemblockP),
  40. sizeof(char),
  41. XMLRPC_MEMBLOCK_SIZE(char, xmlmemblockP),
  42. stdout);
  43. XMLRPC_MEMBLOCK_FREE(char, xmlmemblockP);
  44. /* Dispose of our parameter array. */
  45. xmlrpc_DECREF(params);
  46. /* Clean up our error-handling environment. */
  47. xmlrpc_env_clean(&env);
  48. return 0;
  49. }