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:
parent
57c0d3e4bd
commit
0897f9e2e3
@ -38,7 +38,7 @@ extern "C" {
|
|||||||
#include "pgmspace.h"
|
#include "pgmspace.h"
|
||||||
#include "esp8266_peri.h"
|
#include "esp8266_peri.h"
|
||||||
#include "twi.h"
|
#include "twi.h"
|
||||||
#include "spiffs/spiffs.h"
|
//#include "spiffs/spiffs.h"
|
||||||
|
|
||||||
void yield(void);
|
void yield(void);
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include "stddef.h"
|
#include "stddef.h"
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
#include "ets_sys.h"
|
#include "ets_sys.h"
|
||||||
#include <user_config.h>
|
|
||||||
// ----------- >8 ------------
|
// ----------- >8 ------------
|
||||||
#define IRAM_ATTR __attribute__((section(".iram.text")))
|
#define IRAM_ATTR __attribute__((section(".iram.text")))
|
||||||
#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
|
#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
|
||||||
|
@ -83,6 +83,7 @@ protected:
|
|||||||
static const char* _responseCodeToString(int code);
|
static const char* _responseCodeToString(int code);
|
||||||
void _parseForm(WiFiClient& client, String boundary, uint32_t len);
|
void _parseForm(WiFiClient& client, String boundary, uint32_t len);
|
||||||
void _uploadWriteByte(uint8_t b);
|
void _uploadWriteByte(uint8_t b);
|
||||||
|
uint8_t _uploadReadByte(WiFiClient& client);
|
||||||
|
|
||||||
struct RequestHandler;
|
struct RequestHandler;
|
||||||
struct RequestArgument {
|
struct RequestArgument {
|
||||||
|
@ -214,6 +214,16 @@ void ESP8266WebServer::_uploadWriteByte(uint8_t b){
|
|||||||
_currentUpload.buf[_currentUpload.currentSize++] = 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){
|
void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -312,23 +322,23 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
|
|||||||
#endif
|
#endif
|
||||||
if (_fileUploadHandler) _fileUploadHandler();
|
if (_fileUploadHandler) _fileUploadHandler();
|
||||||
_currentUpload.status = UPLOAD_FILE_WRITE;
|
_currentUpload.status = UPLOAD_FILE_WRITE;
|
||||||
uint8_t argByte = client.read();
|
uint8_t argByte = _uploadReadByte(client);
|
||||||
readfile:
|
readfile:
|
||||||
while(argByte != 0x0D){
|
while(argByte != 0x0D){
|
||||||
_uploadWriteByte(argByte);
|
_uploadWriteByte(argByte);
|
||||||
argByte = client.read();
|
argByte = _uploadReadByte(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
argByte = client.read();
|
argByte = _uploadReadByte(client);
|
||||||
if (argByte == 0x0A){
|
if (argByte == 0x0A){
|
||||||
argByte = client.read();
|
argByte = _uploadReadByte(client);
|
||||||
if ((char)argByte != '-'){
|
if ((char)argByte != '-'){
|
||||||
//continue reading the file
|
//continue reading the file
|
||||||
_uploadWriteByte(0x0D);
|
_uploadWriteByte(0x0D);
|
||||||
_uploadWriteByte(0x0A);
|
_uploadWriteByte(0x0A);
|
||||||
goto readfile;
|
goto readfile;
|
||||||
} else {
|
} else {
|
||||||
argByte = client.read();
|
argByte = _uploadReadByte(client);
|
||||||
if ((char)argByte != '-'){
|
if ((char)argByte != '-'){
|
||||||
//continue reading the file
|
//continue reading the file
|
||||||
_uploadWriteByte(0x0D);
|
_uploadWriteByte(0x0D);
|
||||||
@ -366,11 +376,13 @@ readfile:
|
|||||||
} else {
|
} else {
|
||||||
_uploadWriteByte(0x0D);
|
_uploadWriteByte(0x0D);
|
||||||
_uploadWriteByte(0x0A);
|
_uploadWriteByte(0x0A);
|
||||||
|
_uploadWriteByte((uint8_t)('-'));
|
||||||
|
_uploadWriteByte((uint8_t)('-'));
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
while(i < boundary.length()){
|
while(i < boundary.length()){
|
||||||
_uploadWriteByte(endBuf[i++]);
|
_uploadWriteByte(endBuf[i++]);
|
||||||
}
|
}
|
||||||
argByte = client.read();
|
argByte = _uploadReadByte(client);
|
||||||
goto readfile;
|
goto readfile;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user