|
|
@ -22,7 +22,7 @@ void multipartFreeBoundaryBuffer(MultipartCtx * context) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, char * buff, int len, int last) |
|
|
|
int multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, char * buff, int len, int last) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( len != 0 ) |
|
|
|
if( len != 0 ) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -35,7 +35,7 @@ void multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, cha |
|
|
|
while( context->boundaryBufferPtr > 0 ) |
|
|
|
while( context->boundaryBufferPtr > 0 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( ! last && context->boundaryBufferPtr <= 2 * BOUNDARY_SIZE ) |
|
|
|
if( ! last && context->boundaryBufferPtr <= 2 * BOUNDARY_SIZE ) |
|
|
|
return; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
int dataSize = BOUNDARY_SIZE; |
|
|
|
int dataSize = BOUNDARY_SIZE; |
|
|
|
|
|
|
|
|
|
|
@ -96,7 +96,8 @@ void multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, cha |
|
|
|
{ |
|
|
|
{ |
|
|
|
context->boundaryBuffer[pos] = 0; |
|
|
|
context->boundaryBuffer[pos] = 0; |
|
|
|
os_printf("Uploading file: %s\n", context->boundaryBuffer + start); |
|
|
|
os_printf("Uploading file: %s\n", context->boundaryBuffer + start); |
|
|
|
context->callBack( FILE_START, context->boundaryBuffer + start, pos - start, 0 ); |
|
|
|
if( context->callBack( FILE_START, context->boundaryBuffer + start, pos - start, 0 ) ) |
|
|
|
|
|
|
|
return 1; |
|
|
|
context->boundaryBuffer[pos] = '"'; |
|
|
|
context->boundaryBuffer[pos] = '"'; |
|
|
|
context->state = STATE_SEARCH_HEADER_END; |
|
|
|
context->state = STATE_SEARCH_HEADER_END; |
|
|
|
} |
|
|
|
} |
|
|
@ -111,7 +112,8 @@ void multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, cha |
|
|
|
{ |
|
|
|
{ |
|
|
|
char c = context->boundaryBuffer[dataSize]; |
|
|
|
char c = context->boundaryBuffer[dataSize]; |
|
|
|
context->boundaryBuffer[dataSize] = 0; // add terminating zero (for easier handling)
|
|
|
|
context->boundaryBuffer[dataSize] = 0; // add terminating zero (for easier handling)
|
|
|
|
context->callBack( FILE_DATA, context->boundaryBuffer, dataSize, context->position ); |
|
|
|
if( context->callBack( FILE_DATA, context->boundaryBuffer, dataSize, context->position ) ) |
|
|
|
|
|
|
|
return 1; |
|
|
|
context->boundaryBuffer[dataSize] = c; |
|
|
|
context->boundaryBuffer[dataSize] = c; |
|
|
|
context->position += dataSize; |
|
|
|
context->position += dataSize; |
|
|
|
} |
|
|
|
} |
|
|
@ -126,7 +128,8 @@ void multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, cha |
|
|
|
dataSize += os_strlen(boundary); |
|
|
|
dataSize += os_strlen(boundary); |
|
|
|
if( context->state == STATE_UPLOAD_FILE ) |
|
|
|
if( context->state == STATE_UPLOAD_FILE ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
context->callBack( FILE_DONE, NULL, 0, context->position ); |
|
|
|
if( context->callBack( FILE_DONE, NULL, 0, context->position ) ) |
|
|
|
|
|
|
|
return 1; |
|
|
|
os_printf("File upload done\n"); |
|
|
|
os_printf("File upload done\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -136,6 +139,7 @@ void multipartProcessBoundaryBuffer(MultipartCtx * context, char * boundary, cha |
|
|
|
context->boundaryBufferPtr -= dataSize; |
|
|
|
context->boundaryBufferPtr -= dataSize; |
|
|
|
os_memcpy(context->boundaryBuffer, context->boundaryBuffer + dataSize, context->boundaryBufferPtr); |
|
|
|
os_memcpy(context->boundaryBuffer, context->boundaryBuffer + dataSize, context->boundaryBufferPtr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int ICACHE_FLASH_ATTR multipartProcess(MultipartCtx * context, HttpdConnData * connData ) |
|
|
|
int ICACHE_FLASH_ATTR multipartProcess(MultipartCtx * context, HttpdConnData * connData ) |
|
|
@ -162,25 +166,42 @@ int ICACHE_FLASH_ATTR multipartProcess(MultipartCtx * context, HttpdConnData * c |
|
|
|
multipartAllocBoundaryBuffer(context); |
|
|
|
multipartAllocBoundaryBuffer(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int feed = 0; |
|
|
|
if( context->state != STATE_ERROR ) |
|
|
|
while( feed < post->buffLen ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
int len = post->buffLen - feed; |
|
|
|
int feed = 0; |
|
|
|
if( len > BOUNDARY_SIZE ) |
|
|
|
while( feed < post->buffLen ) |
|
|
|
len = BOUNDARY_SIZE; |
|
|
|
{ |
|
|
|
multipartProcessBoundaryBuffer(context, post->multipartBoundary, post->buff + feed, len, 0); |
|
|
|
int len = post->buffLen - feed; |
|
|
|
feed += len; |
|
|
|
if( len > BOUNDARY_SIZE ) |
|
|
|
|
|
|
|
len = BOUNDARY_SIZE; |
|
|
|
|
|
|
|
if( multipartProcessBoundaryBuffer(context, post->multipartBoundary, post->buff + feed, len, 0) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
context->state = STATE_ERROR; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
feed += len; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
context->recvPosition += post->buffLen; |
|
|
|
context->recvPosition += post->buffLen; |
|
|
|
if( context->recvPosition < post->len ) |
|
|
|
if( context->recvPosition < post->len ) |
|
|
|
return HTTPD_CGI_MORE; |
|
|
|
return HTTPD_CGI_MORE; |
|
|
|
|
|
|
|
|
|
|
|
multipartProcessBoundaryBuffer(context, post->multipartBoundary, NULL, 0, 1); |
|
|
|
if( context->state != STATE_ERROR ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( multipartProcessBoundaryBuffer(context, post->multipartBoundary, NULL, 0, 1) ) |
|
|
|
|
|
|
|
context->state = STATE_ERROR; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
multipartFreeBoundaryBuffer( context ); |
|
|
|
multipartFreeBoundaryBuffer( context ); |
|
|
|
|
|
|
|
|
|
|
|
httpdStartResponse(connData, 204); |
|
|
|
if( context->state == STATE_ERROR ) |
|
|
|
httpdEndHeaders(connData); |
|
|
|
errorResponse(connData, 400, "Invalid file upload!"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
httpdStartResponse(connData, 204); |
|
|
|
|
|
|
|
httpdEndHeaders(connData); |
|
|
|
|
|
|
|
} |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|