wn_module_log.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * File : wn_module_log.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This software is dual-licensed: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation. For the terms of this
  9. * license, see <http://www.gnu.org/licenses/>.
  10. *
  11. * You are free to use this software under the terms of the GNU General
  12. * Public License, but WITHOUT ANY WARRANTY; without even the implied
  13. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU General Public License for more details.
  15. *
  16. * Alternatively for commercial application, you can contact us
  17. * by email <business@rt-thread.com> for commercial license.
  18. *
  19. * Change Logs:
  20. * Date Author Notes
  21. * 2011-08-02 Bernard the first version
  22. */
  23. #include <webnet.h>
  24. #include <wn_module.h>
  25. #include <wn_utils.h>
  26. #ifdef RT_USING_SAL
  27. #include <arpa/inet.h>
  28. #else
  29. #include <lwip/inet.h>
  30. #endif /* RT_USING_SAL */
  31. #define DBG_ENABLE
  32. #define DBG_COLOR
  33. #define DBG_SECTION_NAME "wn.log"
  34. #define DBG_LEVEL DBG_LOG
  35. #include <rtdbg.h>
  36. #ifdef WEBNET_USING_LOG
  37. int webnet_module_log(struct webnet_session* session, int event)
  38. {
  39. struct webnet_request* request;
  40. if (session != RT_NULL)
  41. {
  42. request = session->request;
  43. }
  44. else
  45. {
  46. request = RT_NULL;
  47. }
  48. if (event == WEBNET_EVENT_INIT)
  49. {
  50. LOG_D("server initialize success.");
  51. }
  52. else if (event == WEBNET_EVENT_URI_PHYSICAL)
  53. {
  54. rt_uint32_t index;
  55. LOG_RAW("\n");
  56. LOG_D(" new client: %s:%u",
  57. inet_ntoa(session->cliaddr.sin_addr),
  58. ntohs(session->cliaddr.sin_port));
  59. switch (request->method)
  60. {
  61. case WEBNET_GET:
  62. LOG_D(" method: GET");
  63. break;
  64. case WEBNET_PUT:
  65. LOG_D(" method: PUT");
  66. break;
  67. case WEBNET_POST:
  68. LOG_D(" method: POST");
  69. break;
  70. case WEBNET_HEADER:
  71. LOG_D(" method: HEADER");
  72. break;
  73. case WEBNET_SUBSCRIBE:
  74. LOG_D(" method: SUBSCRIBE");
  75. break;
  76. case WEBNET_UNSUBSCRIBE:
  77. LOG_D(" method: UNSUBSCRIBE");
  78. break;
  79. default:
  80. break;
  81. }
  82. LOG_D(" request: %s", request->path);
  83. for (index = 0; index < request->query_counter; index ++)
  84. {
  85. LOG_D(" query[%d]: %s => %s", index,
  86. request->query_items[index].name,
  87. request->query_items[index].value);
  88. }
  89. }
  90. else if (event == WEBNET_EVENT_URI_POST)
  91. {
  92. LOG_D("physical url: %s", request->path);
  93. LOG_D(" mime type: %s", mime_get_type(request->path));
  94. }
  95. else if (event == WEBNET_EVENT_RSP_HEADER)
  96. {
  97. }
  98. else if (event == WEBNET_EVENT_RSP_FILE)
  99. {
  100. }
  101. return WEBNET_MODULE_CONTINUE;
  102. }
  103. #endif /* WEBNET_USING_LOG */