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