httpd_p.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <cfg/http.h>
  2. #include <sys/heap.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <memdebug.h>
  6. #include "httpd_p.h"
  7. /*
  8. * W A R N I N G
  9. * -------------
  10. *
  11. * This file is not part of the Ethernut API. It exists purely as an
  12. * implementation detail. This header file may change from version to
  13. * version without notice, or even be removed.
  14. *
  15. * We mean it.
  16. */
  17. /*!
  18. * \brief Default index files.
  19. *
  20. * The first entry must contain an empty string.
  21. */
  22. /*! \brief Default file system. */
  23. #ifndef HTTP_DEFAULT_ROOT
  24. #define HTTP_DEFAULT_ROOT "UROM:"
  25. #endif
  26. char *http_root;
  27. char *default_files[] = {
  28. "",
  29. "/index.html",
  30. "/index.htm",
  31. "/default.html",
  32. "/default.htm",
  33. "/index.shtml",
  34. "/index.xhtml",
  35. "/index.asp",
  36. "/default.asp",
  37. NULL
  38. };
  39. /*!
  40. * \brief Create a file path from an URL.
  41. * \internal
  42. * \param url Pointer to the URL string
  43. * \param addon Filename to be appended to the path
  44. */
  45. char *CreateFilePath(const char *url, const char *addon)
  46. {
  47. char *root = http_root ? http_root : HTTP_DEFAULT_ROOT;
  48. size_t urll = strlen(url);
  49. char *path = malloc(strlen(root) + urll + strlen(addon) + 1);
  50. if (path) {
  51. strcpy(path, root);
  52. strcat(path, url);
  53. if (*addon) {
  54. strcat(path, addon + (urll == 0 || url[urll - 1] == '/'));
  55. }
  56. }
  57. return path;
  58. }
  59. /*!
  60. * \brief Release request info structure.
  61. * \internal
  62. * \param req Pointer to the info structure. If NULL, nothing
  63. * is released.
  64. */
  65. void DestroyRequestInfo(REQUEST * req)
  66. {
  67. if (req) {
  68. if (req->req_url)
  69. free(req->req_url);
  70. if (req->req_query)
  71. free(req->req_query);
  72. if (req->req_type)
  73. free(req->req_type);
  74. if (req->req_cookie)
  75. free(req->req_cookie);
  76. if (req->req_auth)
  77. free(req->req_auth);
  78. if (req->req_agent)
  79. free(req->req_agent);
  80. if (req->req_qptrs)
  81. free(req->req_qptrs);
  82. if (req->req_referer)
  83. free(req->req_referer);
  84. if (req->req_host)
  85. free(req->req_host);
  86. if (req->req_encoding)
  87. free(req->req_encoding);
  88. free(req);
  89. }
  90. }