1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

fix reading bytes from incoming POST upload

proper error and premature connection loss should be implemented to
handle weird cases where we might not get the whole post content
This commit is contained in:
ficeto 2015-05-15 02:22:00 +03:00
parent 57c0d3e4bd
commit 0897f9e2e3
4 changed files with 31 additions and 19 deletions

View File

@ -38,7 +38,7 @@ extern "C" {
#include "pgmspace.h"
#include "esp8266_peri.h"
#include "twi.h"
#include "spiffs/spiffs.h"
//#include "spiffs/spiffs.h"
void yield(void);

View File

@ -20,7 +20,6 @@
#include "stddef.h"
#include "osapi.h"
#include "ets_sys.h"
#include <user_config.h>
// ----------- >8 ------------
#define IRAM_ATTR __attribute__((section(".iram.text")))
#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))

View File

@ -83,6 +83,7 @@ protected:
static const char* _responseCodeToString(int code);
void _parseForm(WiFiClient& client, String boundary, uint32_t len);
void _uploadWriteByte(uint8_t b);
uint8_t _uploadReadByte(WiFiClient& client);
struct RequestHandler;
struct RequestArgument {

View File

@ -214,6 +214,16 @@ void ESP8266WebServer::_uploadWriteByte(uint8_t b){
_currentUpload.buf[_currentUpload.currentSize++] = b;
}
uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
int res = client.read();
if(res == -1){
while(!client.available())
yield();
res = client.read();
}
return (uint8_t)res;
}
void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
#ifdef DEBUG
@ -312,23 +322,23 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
#endif
if (_fileUploadHandler) _fileUploadHandler();
_currentUpload.status = UPLOAD_FILE_WRITE;
uint8_t argByte = client.read();
uint8_t argByte = _uploadReadByte(client);
readfile:
while(argByte != 0x0D){
_uploadWriteByte(argByte);
argByte = client.read();
argByte = _uploadReadByte(client);
}
argByte = client.read();
argByte = _uploadReadByte(client);
if (argByte == 0x0A){
argByte = client.read();
argByte = _uploadReadByte(client);
if ((char)argByte != '-'){
//continue reading the file
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
goto readfile;
} else {
argByte = client.read();
argByte = _uploadReadByte(client);
if ((char)argByte != '-'){
//continue reading the file
_uploadWriteByte(0x0D);
@ -366,11 +376,13 @@ readfile:
} else {
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
_uploadWriteByte((uint8_t)('-'));
uint32_t i = 0;
while(i < boundary.length()){
_uploadWriteByte(endBuf[i++]);
}
argByte = client.read();
argByte = _uploadReadByte(client);
goto readfile;
}
} else {