ESPWebDAV.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef ESPWEBDAV_H
  2. #define ESPWEBDAV_H
  3. #include <WiFi.h>
  4. #include <SdFat.h>
  5. #include "mbedtls/sha1.h"
  6. // debugging
  7. #define DBG_PRINT(...) { Serial.print(__VA_ARGS__); }
  8. #define DBG_PRINTLN(...) { Serial.println(__VA_ARGS__); }
  9. // production
  10. //#define DBG_PRINT(...) { }
  11. //#define DBG_PRINTLN(...) { }
  12. // constants for WebServer
  13. #define CONTENT_LENGTH_UNKNOWN ((size_t) -1)
  14. #define CONTENT_LENGTH_NOT_SET ((size_t) -2)
  15. #define HTTP_MAX_POST_WAIT 5000
  16. enum ResourceType { RESOURCE_NONE, RESOURCE_FILE, RESOURCE_DIR };
  17. enum DepthType { DEPTH_NONE, DEPTH_CHILD, DEPTH_ALL };
  18. void sha1( String str_data, uint8_t hash[20] );
  19. //using namespace sdfat;
  20. class ESPWebDAV {
  21. public:
  22. bool init(int serverPort);
  23. bool initSD(int chipSelectPin, SPISettings spiSettings);
  24. bool isClientWaiting();
  25. void handleClient(String blank = "");
  26. void rejectClient(String rejectMessage);
  27. void sdChdir(const char* path) ;
  28. protected:
  29. typedef void (ESPWebDAV::*THandlerFunction)(String);
  30. void processClient(THandlerFunction handler, String message);
  31. void handleNotFound();
  32. void handleReject(String rejectMessage);
  33. void handleRequest(String blank);
  34. void handleOptions(ResourceType resource);
  35. void handleLock(ResourceType resource);
  36. void handleUnlock(ResourceType resource);
  37. void handlePropPatch(ResourceType resource);
  38. void handleProp(ResourceType resource);
  39. #ifdef GOTEK_SDFAT2
  40. void sendPropResponse(boolean recursing, FsFile *curFile);
  41. void handleWriteError(String message, FsFile *wFile);
  42. #else
  43. void sendPropResponse(boolean recursing, FatFile *curFile);
  44. void handleWriteError(String message, FatFile *wFile);
  45. #endif
  46. void handleGet(ResourceType resource, bool isGet);
  47. void handlePut(ResourceType resource);
  48. void handleDirectoryCreate(ResourceType resource);
  49. void handleMove(ResourceType resource);
  50. void handleDelete(ResourceType resource);
  51. // Sections are copied from ESP8266Webserver
  52. String getMimeType(String path);
  53. String urlDecode(const String& text);
  54. String urlToUri(String url);
  55. bool parseRequest();
  56. void sendHeader(const String& name, const String& value, bool first = false);
  57. void send(String code, const char* content_type, const String& content);
  58. void _prepareHeader(String& response, String code, const char* content_type, size_t contentLength);
  59. void sendContent(const String& content);
  60. void sendContent_P(PGM_P content);
  61. void setContentLength(size_t len);
  62. size_t readBytesWithTimeout(uint8_t *buf, size_t bufSize);
  63. size_t readBytesWithTimeout(uint8_t *buf, size_t bufSize, size_t numToRead);
  64. // variables pertaining to current most HTTP request being serviced
  65. WiFiServer *server;
  66. SdFat sd;
  67. WiFiClient client;
  68. String method;
  69. String uri;
  70. String contentLengthHeader;
  71. String depthHeader;
  72. String hostHeader;
  73. String destinationHeader;
  74. String _responseHeaders;
  75. bool _chunked;
  76. int _contentLength;
  77. // SD stuff
  78. //bool isSDInit = false;
  79. };
  80. #endif // ESPWEBDAV_H