You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
3.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: soap-router.c,v 1.10 2006/07/09 16:24:19 snowdrop Exp $
  3. *
  4. * CSOAP Project: A SOAP client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammer.net
  23. ******************************************************************/
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27. #ifdef HAVE_STRING_H
  28. #include <string.h>
  29. #endif
  30. #ifdef HAVE_ERRNO_H
  31. #include <errno.h>
  32. #endif
  33. #include <nanohttp/nanohttp-logging.h>
  34. #include "soap-router.h"
  35. SoapRouter *
  36. soap_router_new(void)
  37. {
  38. SoapRouter *router;
  39. if (!(router = (SoapRouter *) malloc(sizeof(SoapRouter))))
  40. {
  41. log_error2("malloc failed (%s)", strerror(errno));
  42. return NULL;
  43. }
  44. memset(router, 0, sizeof(SoapRouter));
  45. return router;
  46. }
  47. void
  48. soap_router_register_service(SoapRouter * router,
  49. SoapServiceFunc func,
  50. const char *method, const char *urn)
  51. {
  52. SoapService *service;
  53. service = soap_service_new(urn, method, func);
  54. if (router->service_tail == NULL)
  55. {
  56. router->service_head =
  57. router->service_tail = soap_service_node_new(service, NULL);
  58. }
  59. else
  60. {
  61. router->service_tail->next = soap_service_node_new(service, NULL);
  62. router->service_tail = router->service_tail->next;
  63. }
  64. return;
  65. }
  66. void
  67. soap_router_register_security(SoapRouter * router, httpd_auth auth)
  68. {
  69. router->auth = auth;
  70. return;
  71. }
  72. void
  73. soap_router_register_description(SoapRouter * router, xmlDocPtr wsdl)
  74. {
  75. if (router->wsdl)
  76. xmlFreeDoc(router->wsdl);
  77. router->wsdl = xmlCopyDoc(wsdl, 1);
  78. return;
  79. }
  80. void
  81. soap_router_register_default_service(SoapRouter *router, SoapServiceFunc func, const char *method, const char *urn) {
  82. SoapService *service;
  83. service = soap_service_new(urn, method, func);
  84. if (router->service_tail == NULL)
  85. {
  86. router->service_head = router->service_tail = soap_service_node_new(service, NULL);
  87. }
  88. else
  89. {
  90. router->service_tail->next = soap_service_node_new(service, NULL);
  91. router->service_tail = router->service_tail->next;
  92. }
  93. router->default_service = service;
  94. return;
  95. }
  96. SoapService *
  97. soap_router_find_service(SoapRouter * router,
  98. const char *urn, const char *method)
  99. {
  100. SoapServiceNode *node;
  101. if (router == NULL || urn == NULL || method == NULL)
  102. return NULL;
  103. node = router->service_head;
  104. while (node)
  105. {
  106. if (node->service && node->service->urn && node->service->method)
  107. {
  108. if (!strcmp(node->service->urn, urn)
  109. && !strcmp(node->service->method, method))
  110. return node->service;
  111. }
  112. node = node->next;
  113. }
  114. return router->default_service;
  115. }
  116. void
  117. soap_router_free(SoapRouter * router)
  118. {
  119. SoapServiceNode *node;
  120. log_verbose2("enter: router=%p", router);
  121. if (!router)
  122. return;
  123. while (router->service_head)
  124. {
  125. node = router->service_head->next;
  126. /* log_verbose2("soap_service_free(%p)\n",
  127. router->service_head->service); */
  128. soap_service_free(router->service_head->service);
  129. free(router->service_head);
  130. router->service_head = node;
  131. }
  132. if (router->wsdl)
  133. xmlFreeDoc(router->wsdl);
  134. free(router);
  135. log_verbose1("leave with success");
  136. return;
  137. }