S&B Volcano vaporizer remote control with Pi Pico W
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

http_files.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * http_files.c
  3. *
  4. * Based on BittyHTTP example.
  5. *
  6. * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  7. * Copyright (c) 2019 Paul Hutchinson
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in all
  17. * copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. */
  27. #include <string.h>
  28. #include "WebServer.h"
  29. #include "config.h"
  30. #include "log.h"
  31. #include "http.h"
  32. struct FileInfo {
  33. const char *Filename; // With Path
  34. bool Dynamic;
  35. const char **Cookies;
  36. const char **Gets;
  37. const char **Posts;
  38. void (*WriteFile)(struct WebServer *Web);
  39. };
  40. void File_Root(struct WebServer *Web);
  41. static struct FileInfo m_Files[] = {
  42. // Filename, Dynamic, Cookies, Gets, Posts, Callback
  43. { "/", false, NULL, NULL, NULL, File_Root },
  44. };
  45. bool FS_GetFileProperties(const char *Filename, struct WSPageProp *PageProp) {
  46. PageProp->FileID = 0;
  47. for (size_t r = 0; r < sizeof(m_Files) / sizeof(struct FileInfo); r++) {
  48. if (strcmp(Filename, m_Files[r].Filename) != 0) {
  49. continue;
  50. }
  51. PageProp->FileID = (uintptr_t)&m_Files[r];
  52. PageProp->DynamicFile = m_Files[r].Dynamic;
  53. PageProp->Cookies = m_Files[r].Cookies;
  54. PageProp->Gets = m_Files[r].Gets;
  55. PageProp->Posts = m_Files[r].Posts;
  56. debug("serving '%s'", Filename);
  57. return true;
  58. }
  59. debug("unknown file '%s'", Filename);
  60. return false;
  61. }
  62. void FS_SendFile(struct WebServer *Web, uintptr_t FileID) {
  63. struct FileInfo *File = (struct FileInfo *)FileID;
  64. if ((Web == NULL) || (File == NULL)) {
  65. debug("invalid param");
  66. return;
  67. }
  68. File->WriteFile(Web);
  69. }
  70. t_ElapsedTime ReadElapsedClock(void) {
  71. return to_ms_since_boot(get_absolute_time()) / 1000;
  72. }
  73. const char RootHTML[]=
  74. "<!DOCTYPE html>"
  75. "<html>"
  76. "<head>"
  77. "<title>Volcano Remote</title>"
  78. "</head>"
  79. "<body>"
  80. "<h1>Hello World</h1>"
  81. "</body>"
  82. "</html>";
  83. void File_Root(struct WebServer *Web) {
  84. WS_WriteWhole(Web,RootHTML, sizeof(RootHTML) - 1);
  85. }