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.

92 lines
2.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: simpleserver.c,v 1.19 2006/07/09 16:24:19 snowdrop Exp $
  3. *
  4. * CSOAP Project: CSOAP examples project
  5. * Copyright (C) 2003-2004 Ferhat Ayaz
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program 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
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
  20. *
  21. * Email: ferhatayaz@yahoo.com
  22. ******************************************************************/
  23. #include <nanohttp/nanohttp-logging.h>
  24. #include <libcsoap/soap-server.h>
  25. static const char *url = "/csoapserver";
  26. static const char *urn = "urn:examples";
  27. static const char *method = "sayHello";
  28. herror_t
  29. say_hello(SoapCtx * req, SoapCtx * res)
  30. {
  31. herror_t err;
  32. char *name;
  33. xmlNodePtr method, node;
  34. err = soap_env_new_with_response(req->env, &res->env);
  35. if (err != H_OK)
  36. {
  37. return err;
  38. }
  39. method = soap_env_get_method(req->env);
  40. node = soap_xml_get_children(method);
  41. while (node)
  42. {
  43. name = (char *) xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1);
  44. soap_env_add_itemf(res->env, "xsd:string", "echo", "Hello '%s'", name);
  45. node = soap_xml_get_next(node);
  46. xmlFree(name);
  47. }
  48. return H_OK;
  49. }
  50. int
  51. main(int argc, char *argv[])
  52. {
  53. herror_t err;
  54. SoapRouter *router;
  55. hlog_set_level(HLOG_INFO);
  56. err = soap_server_init_args(argc, argv);
  57. if (err != H_OK)
  58. {
  59. log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
  60. herror_code(err));
  61. herror_release(err);
  62. return 1;
  63. }
  64. router = soap_router_new();
  65. soap_router_register_service(router, say_hello, method, urn);
  66. soap_server_register_router(router, url);
  67. log_info1("press ctrl-c to shutdown");
  68. soap_server_run();
  69. log_info1("shutting down\n");
  70. soap_server_destroy();
  71. return 0;
  72. }