server_abyss.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "unistdx.h"
  2. #include <stdio.h>
  3. #include "bool.h"
  4. #include "xmlrpc_config.h"
  5. #include "xmlrpc-c/base.h"
  6. #include "xmlrpc-c/server.h"
  7. #include "xmlrpc-c/abyss.h"
  8. #include "xmlrpc-c/server_abyss.h"
  9. #include "testtool.h"
  10. #include "server_abyss.h"
  11. static xmlrpc_call_processor myXmlProcessor;
  12. static void
  13. myXmlProcessor(xmlrpc_env * const envP ATTR_UNUSED,
  14. void * const processorArg ATTR_UNUSED,
  15. const char * const callXml ATTR_UNUSED,
  16. size_t const callXmlLen ATTR_UNUSED,
  17. TSession * const abyssSessionP ATTR_UNUSED,
  18. xmlrpc_mem_block ** const responseXmlPP ATTR_UNUSED) {
  19. printf("XML processor running\n");
  20. }
  21. static void
  22. testSetHandlers(TServer * const abyssServerP) {
  23. xmlrpc_env env;
  24. xmlrpc_registry * registryP;
  25. xmlrpc_server_abyss_handler_parms parms;
  26. xmlrpc_env_init(&env);
  27. registryP = xmlrpc_registry_new(&env);
  28. TEST_NO_FAULT(&env);
  29. TEST(registryP != NULL);
  30. parms.xml_processor = &myXmlProcessor;
  31. parms.xml_processor_arg = NULL;
  32. parms.xml_processor_max_stack = 512;
  33. parms.uri_path = "/RPC6";
  34. parms.chunk_response = true;
  35. parms.allow_origin = "*";
  36. xmlrpc_server_abyss_set_handler3(
  37. &env, abyssServerP, &parms, XMLRPC_AHPSIZE(xml_processor_arg));
  38. TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR); /* Parms too short */
  39. xmlrpc_server_abyss_set_handler3(
  40. &env, abyssServerP, &parms, XMLRPC_AHPSIZE(allow_origin));
  41. TEST_NO_FAULT(&env);
  42. xmlrpc_server_abyss_set_handler2(abyssServerP, "/RPC5",
  43. &myXmlProcessor, NULL, 512, true);
  44. xmlrpc_server_abyss_set_handler(&env, abyssServerP, "/RPC3", registryP);
  45. TEST_NO_FAULT(&env);
  46. xmlrpc_server_abyss_set_handlers2(abyssServerP, "/RPC4", registryP);
  47. xmlrpc_server_abyss_set_handlers(abyssServerP, registryP);
  48. xmlrpc_server_abyss_set_default_handler(abyssServerP);
  49. xmlrpc_registry_free(registryP);
  50. {
  51. xmlrpc_registry * registryP;
  52. registryP = xmlrpc_registry_new(&env);
  53. xmlrpc_server_abyss_set_handlers(abyssServerP, registryP);
  54. xmlrpc_registry_free(registryP);
  55. }
  56. xmlrpc_env_clean(&env);
  57. }
  58. static void
  59. testServerParms(void) {
  60. xmlrpc_server_abyss_parms parms;
  61. parms.config_file_name = NULL;
  62. parms.registryP = NULL;
  63. parms.port_number = 1000;
  64. parms.log_file_name = "/tmp/xmlrpc_logfile";
  65. parms.keepalive_timeout = 5;
  66. parms.keepalive_max_conn = 4;
  67. parms.timeout = 50;
  68. parms.dont_advertise = TRUE;
  69. parms.uri_path = "/RPC9";
  70. parms.chunk_response = TRUE;
  71. parms.allow_origin = "*";
  72. };
  73. static void
  74. testObject(void) {
  75. xmlrpc_env env;
  76. xmlrpc_server_abyss_parms parms;
  77. xmlrpc_server_abyss_t * serverP;
  78. xmlrpc_registry * registryP;
  79. xmlrpc_server_abyss_sig * oldHandlersP;
  80. xmlrpc_env_init(&env);
  81. registryP = xmlrpc_registry_new(&env);
  82. TEST_NO_FAULT(&env);
  83. parms.config_file_name = NULL;
  84. parms.registryP = registryP;
  85. serverP = NULL;
  86. xmlrpc_server_abyss_create(&env, &parms, XMLRPC_APSIZE(registryP),
  87. &serverP);
  88. TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR); /* Global init not done */
  89. xmlrpc_server_abyss_global_init(&env);
  90. TEST_NO_FAULT(&env);
  91. xmlrpc_server_abyss_create(&env, &parms, XMLRPC_APSIZE(registryP),
  92. &serverP);
  93. TEST_NO_FAULT(&env);
  94. TEST(serverP != NULL);
  95. xmlrpc_server_abyss_terminate(&env, serverP);
  96. TEST_NO_FAULT(&env);
  97. xmlrpc_server_abyss_reset_terminate(&env, serverP);
  98. TEST_NO_FAULT(&env);
  99. xmlrpc_server_abyss_setup_sig(&env, serverP, &oldHandlersP);
  100. TEST_NO_FAULT(&env);
  101. xmlrpc_server_abyss_use_sigchld(serverP);
  102. xmlrpc_server_abyss_restore_sig(oldHandlersP);
  103. TEST_NO_FAULT(&env);
  104. free(oldHandlersP);
  105. xmlrpc_server_abyss_destroy(serverP);
  106. xmlrpc_registry_free(registryP);
  107. xmlrpc_server_abyss_global_term();
  108. xmlrpc_server_abyss_setup_sig(&env, serverP, &oldHandlersP);
  109. TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR); /* Not globally initialized */
  110. xmlrpc_env_clean(&env);
  111. }
  112. void
  113. test_server_abyss(void) {
  114. TServer abyssServer;
  115. printf("Running Abyss XML-RPC server tests...\n");
  116. ServerCreate(&abyssServer, "testserver", 8080, NULL, NULL);
  117. testSetHandlers(&abyssServer);
  118. ServerSetKeepaliveTimeout(&abyssServer, 60);
  119. ServerSetKeepaliveMaxConn(&abyssServer, 10);
  120. ServerSetTimeout(&abyssServer, 0);
  121. ServerSetAdvertise(&abyssServer, FALSE);
  122. ServerFree(&abyssServer);
  123. testServerParms();
  124. testObject();
  125. printf("\n");
  126. printf("Abyss XML-RPC server tests done.\n");
  127. }