Simpler Measurement session, fully in memory

This commit is contained in:
Martin Bauer
2020-06-21 11:10:45 +02:00
parent fc469f47a6
commit c7137f74a1
7 changed files with 206 additions and 53 deletions

View File

@@ -97,41 +97,44 @@ size_t webdavFileListingSpiffs(char *buffer, size_t maxLength,
return bytesWritten;
}
String uriToFileName(const String &uriStr)
String uriToFileName(const String &uriStr, const char *spiffsFolder)
{
String filename;
String filename;
if (uriStr.endsWith(".st"))
filename = uriStr.substring(0, uriStr.length() - strlen(".st"));
filename = "/dat/" + filename;
filename = spiffsFolder + String("/") + filename;
return filename;
}
void webdavHandler(httpd_req_t *req)
std::function<void(httpd_req_t *)> webdavHandler(const char *uriPrefix,
const char *spiffsFolder)
{
String uri = String(req->uri).substring(strlen("/webdav/"));
constexpr size_t WEBDAV_BUFF_LEN = 1024 * 256;
static char *webdavBuffer = (char *)heap_caps_malloc(WEBDAV_BUFF_LEN, MALLOC_CAP_SPIRAM);
switch (req->method)
{
case HTTP_GET:
case HTTP_PROPFIND:
{
size_t bytesWritten = webdavFileListingSpiffs(webdavBuffer, WEBDAV_BUFF_LEN, "/dat");
httpd_resp_send(req, webdavBuffer, bytesWritten);
break;
}
case HTTP_DELETE:
{
httpd_resp_set_hdr(req, "Content-Type", "text/plain");
return [=](httpd_req_t *req) {
String uri = String(req->uri).substring(strlen(uriPrefix));
constexpr size_t WEBDAV_BUFF_LEN = 1024 * 256;
static char *webdavBuffer = (char *)heap_caps_malloc(WEBDAV_BUFF_LEN, MALLOC_CAP_SPIRAM);
switch (req->method)
{
case HTTP_GET:
case HTTP_PROPFIND:
{
size_t bytesWritten = webdavFileListingSpiffs(webdavBuffer, WEBDAV_BUFF_LEN, spiffsFolder);
httpd_resp_send(req, webdavBuffer, bytesWritten);
break;
}
case HTTP_DELETE:
{
httpd_resp_set_hdr(req, "Content-Type", "text/plain");
if (portablefs::remove(uriToFileName(uri).c_str()))
httpd_resp_send(req, "Deleted file", -1);
else
if (portablefs::remove(uriToFileName(uri, spiffsFolder).c_str()))
httpd_resp_send(req, "Deleted file", -1);
else
httpd_resp_send_404(req);
break;
}
default:
httpd_resp_send_404(req);
break;
}
default:
httpd_resp_send_404(req);
}
}
};
}

View File

@@ -1,4 +1,10 @@
#include "Dtypes.h"
#include "EspHttp.h"
void webdavHandler(httpd_req_t *req);
/**
* Handler to serves spiffsFolder via webdav
*
* this handler has to be entered for multiple HTTP verbs: HTTP_GET, HTTP_PROPFIND, HTTP_DELETE
*/
std::function<void(httpd_req_t *)> webdavHandler(const char *uriPrefix,
const char *spiffsFolder);