|
27 | 27 |
|
28 | 28 | */ |
29 | 29 |
|
| 30 | +#include "strutils.h" |
| 31 | + |
30 | 32 | #include <FS.h> |
31 | 33 | #if defined(ARDUINO_ARCH_ESP8266) || defined(CORE_MOCK) |
32 | 34 | #include <ESP8266WiFi.h> |
@@ -76,10 +78,6 @@ const char * FileName(const char * path) |
76 | 78 | #include <time.h> |
77 | 79 | #include <ESPWebDAV.h> |
78 | 80 |
|
79 | | -// define cal constants |
80 | | -const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
81 | | -const char *wdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
82 | | - |
83 | 81 | #define ALLOW "PROPPATCH,PROPFIND,OPTIONS,DELETE" SCUNLOCK ",COPY" SCLOCK ",MOVE,HEAD,POST,PUT,GET" |
84 | 82 |
|
85 | 83 | #if WEBDAV_LOCK_SUPPORT |
@@ -129,16 +127,6 @@ static const __FlashStringHelper* streamError (Stream::Report r) |
129 | 127 | #define BUF_FREE() do { (void)0; } while (0) |
130 | 128 | #endif |
131 | 129 |
|
132 | | -void ESPWebDAVCore::stripSlashes(String& name) |
133 | | -{ |
134 | | - size_t i = 0; |
135 | | - while (i < name.length()) |
136 | | - if (name[i] == '/' && name.length() > 1 && ((i == name.length() - 1) || name[i + 1] == '/')) |
137 | | - name.remove(i, 1); |
138 | | - else |
139 | | - i++; |
140 | | -} |
141 | | - |
142 | 130 | #if WEBDAV_LOCK_SUPPORT |
143 | 131 |
|
144 | 132 |
|
@@ -825,17 +813,6 @@ void ESPWebDAVCore::sendContentProp(const String& what, const String& response) |
825 | 813 | } |
826 | 814 |
|
827 | 815 |
|
828 | | -String ESPWebDAVCore::date2date(time_t date) |
829 | | -{ |
830 | | - // get & convert time to required format |
831 | | - // Tue, 13 Oct 2015 17:07:35 GMT |
832 | | - tm* gTm = gmtime(&date); |
833 | | - char buf[40]; |
834 | | - snprintf(buf, sizeof(buf), "%s, %02d %s %04d %02d:%02d:%02d GMT", wdays[gTm->tm_wday], gTm->tm_mday, months[gTm->tm_mon], gTm->tm_year + 1900, gTm->tm_hour, gTm->tm_min, gTm->tm_sec); |
835 | | - return buf; |
836 | | -} |
837 | | - |
838 | | - |
839 | 816 | void ESPWebDAVCore::sendPropResponse(bool isDir, const String& fullResPathFS, size_t size, time_t lastWrite, time_t creationDate) |
840 | 817 | { |
841 | 818 | String fullResPath = fullResPathFS; |
@@ -1197,33 +1174,6 @@ void ESPWebDAVCore::handleDirectoryCreate(ResourceType resource) |
1197 | 1174 | } |
1198 | 1175 |
|
1199 | 1176 |
|
1200 | | -String ESPWebDAVCore::urlToUri(const String& url) |
1201 | | -{ |
1202 | | - int index; |
1203 | | - if (url.startsWith("http") && (index = url.indexOf("://")) <= 5) |
1204 | | - { |
1205 | | - int uriStart = url.indexOf('/', index + 3); |
1206 | | - return url.substring(uriStart); |
1207 | | - } |
1208 | | - return url; |
1209 | | -} |
1210 | | - |
1211 | | -void ESPWebDAVCore::replaceFront (String& str, const String& from, const String& to) |
1212 | | -{ |
1213 | | - if (from.length() && to.length() && str.indexOf(from) == 0) |
1214 | | - { |
1215 | | - DBG_PRINT("replaceFront(%s, %s): %s -> ", from.c_str(), to.c_str(), str.c_str()); |
1216 | | - String repl; |
1217 | | - repl.reserve(str.length() + to.length() - from.length() + 1); |
1218 | | - repl = to; |
1219 | | - size_t skip = from.length() == 1? 0: from.length(); |
1220 | | - repl += str.c_str() + skip; |
1221 | | - str = repl; |
1222 | | - stripSlashes(str); |
1223 | | - DBG_PRINT("%s", str.c_str()); |
1224 | | - } |
1225 | | -} |
1226 | | - |
1227 | 1177 | void ESPWebDAVCore::handleMove(ResourceType resource, File& src) |
1228 | 1178 | { |
1229 | 1179 | const char* successCode = "201 Created"; |
@@ -1835,71 +1785,3 @@ void ESPWebDAVCore::processRange(const String& range) |
1835 | 1785 | } |
1836 | 1786 |
|
1837 | 1787 |
|
1838 | | -int ESPWebDAVCore::htoi(char c) |
1839 | | -{ |
1840 | | - c = tolower(c); |
1841 | | - return c >= '0' && c <= '9' ? c - '0' : |
1842 | | - c >= 'a' && c <= 'f' ? c - 'a' + 10 : |
1843 | | - -1; |
1844 | | -} |
1845 | | - |
1846 | | - |
1847 | | -char ESPWebDAVCore::itoH(int c) |
1848 | | -{ |
1849 | | - return c <= 9 ? c + '0' : c - 10 + 'A'; |
1850 | | -} |
1851 | | - |
1852 | | - |
1853 | | -int ESPWebDAVCore::hhtoi(const char* c) |
1854 | | -{ |
1855 | | - int h = htoi(*c); |
1856 | | - int l = htoi(*(c + 1)); |
1857 | | - return h < 0 || l < 0 ? -1 : (h << 4) + l; |
1858 | | -} |
1859 | | - |
1860 | | - |
1861 | | -String ESPWebDAVCore::enc2c(const String& encoded) |
1862 | | -{ |
1863 | | - String ret = encoded; |
1864 | | - for (size_t i = 0; ret.length() >= 2 && i < ret.length() - 2; i++) |
1865 | | - if (ret[i] == '%') |
1866 | | - { |
1867 | | - int v = hhtoi(ret.c_str() + i + 1); |
1868 | | - if (v > 0) |
1869 | | - { |
1870 | | - ret[i] = v < 128 ? (char)v : '='; |
1871 | | - ret.remove(i + 1, 2); |
1872 | | - } |
1873 | | - } |
1874 | | - return ret; |
1875 | | -} |
1876 | | - |
1877 | | - |
1878 | | -static inline bool notEncodable (char c) |
1879 | | -{ |
1880 | | - return c > 32 && c < 127; |
1881 | | -} |
1882 | | - |
1883 | | -String ESPWebDAVCore::c2enc(const String& decoded) |
1884 | | -{ |
1885 | | - size_t l = decoded.length(); |
1886 | | - for (size_t i = 0; i < decoded.length(); i++) |
1887 | | - if (!notEncodable(decoded[i])) |
1888 | | - l += 2; |
1889 | | - |
1890 | | - String ret; |
1891 | | - ret.reserve(l); |
1892 | | - for (size_t i = 0; i < decoded.length(); i++) |
1893 | | - { |
1894 | | - char c = decoded[i]; |
1895 | | - if (notEncodable(c)) |
1896 | | - ret += c; |
1897 | | - else |
1898 | | - { |
1899 | | - ret += '%'; |
1900 | | - ret += itoH(c >> 4); |
1901 | | - ret += itoH(c & 0xf); |
1902 | | - } |
1903 | | - } |
1904 | | - return ret; |
1905 | | -} |
0 commit comments