|
|
@ -88,88 +88,95 @@ int ICACHE_FLASH_ATTR cgiJsonHook(HttpdConnData *connData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
|
|
|
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
|
|
|
|
|
|
|
|
|
|
|
|
if( !flashConfig.slip_enable ) |
|
|
|
void * cgiData = connData->cgiData; |
|
|
|
{ |
|
|
|
|
|
|
|
errorResponse(connData, 400, "Slip processing is disabled!"); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CmdCallback* cb = cmdGetCbByName( WEB_CB ); |
|
|
|
|
|
|
|
if( cb == NULL ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
errorResponse(connData, 500, "No MCU callback is registered!"); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if( serbridgeInProgramming() ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
errorResponse(connData, 500, "Slip disabled at programming mode!"); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char reasonBuf[16]; |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
int len = httpdFindArg(connData->getArgs, "reason", reasonBuf, sizeof(reasonBuf)); |
|
|
|
|
|
|
|
if( len < 0 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
errorResponse(connData, 400, "No reason specified!"); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestReason reason = INVALID; |
|
|
|
|
|
|
|
for(i=0; i < sizeof(web_server_reasons)/sizeof(char *); i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( os_strcmp( web_server_reasons[i], reasonBuf ) == 0 ) |
|
|
|
|
|
|
|
reason = (RequestReason)i; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( reason == INVALID ) |
|
|
|
if( cgiData == NULL ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
errorResponse(connData, 400, "Invalid reason!"); |
|
|
|
if( !flashConfig.slip_enable ) |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
{ |
|
|
|
} |
|
|
|
errorResponse(connData, 400, "Slip processing is disabled!"); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
char body[1024]; |
|
|
|
} |
|
|
|
int bodyLen = -1; |
|
|
|
CmdCallback* cb = cmdGetCbByName( WEB_CB ); |
|
|
|
|
|
|
|
if( cb == NULL ) |
|
|
|
switch(reason) |
|
|
|
{ |
|
|
|
{ |
|
|
|
errorResponse(connData, 500, "No MCU callback is registered!"); |
|
|
|
case BUTTON: |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
bodyLen = httpdFindArg(connData->getArgs, "id", body, sizeof(body)); |
|
|
|
} |
|
|
|
if( bodyLen <= 0 ) |
|
|
|
if( serbridgeInProgramming() ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
errorResponse(connData, 400, "No button ID specified!"); |
|
|
|
errorResponse(connData, 500, "Slip disabled at programming mode!"); |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case SUBMIT: |
|
|
|
char reasonBuf[16]; |
|
|
|
{ |
|
|
|
int i; |
|
|
|
// TODO
|
|
|
|
int len = httpdFindArg(connData->getArgs, "reason", reasonBuf, sizeof(reasonBuf)); |
|
|
|
} |
|
|
|
if( len < 0 ) |
|
|
|
break; |
|
|
|
{ |
|
|
|
case LOAD: |
|
|
|
errorResponse(connData, 400, "No reason specified!"); |
|
|
|
case REFRESH: |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
default: |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
RequestReason reason = INVALID; |
|
|
|
|
|
|
|
for(i=0; i < sizeof(web_server_reasons)/sizeof(char *); i++) |
|
|
|
os_printf("Web callback to MCU: %s\n", reasonBuf); |
|
|
|
{ |
|
|
|
|
|
|
|
if( os_strcmp( web_server_reasons[i], reasonBuf ) == 0 ) |
|
|
|
cmdResponseStart(CMD_WEB_REQ_CB, (uint32_t)cb->callback, bodyLen >= 0 ? 5 : 4); |
|
|
|
reason = (RequestReason)i; |
|
|
|
uint16_t r = (uint16_t)reason; |
|
|
|
} |
|
|
|
cmdResponseBody(&r, sizeof(uint16_t)); |
|
|
|
|
|
|
|
cmdResponseBody(&connData->conn->proto.tcp->remote_ip, 4); |
|
|
|
if( reason == INVALID ) |
|
|
|
cmdResponseBody(&connData->conn->proto.tcp->remote_port, sizeof(uint16_t)); |
|
|
|
{ |
|
|
|
cmdResponseBody(connData->url, os_strlen(connData->url)); |
|
|
|
errorResponse(connData, 400, "Invalid reason!"); |
|
|
|
if( bodyLen >= 0 ) |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
cmdResponseBody(body, bodyLen); |
|
|
|
} |
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
|
|
|
|
char body[1024]; |
|
|
|
|
|
|
|
int bodyLen = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(reason) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case BUTTON: |
|
|
|
|
|
|
|
bodyLen = httpdFindArg(connData->getArgs, "id", body, sizeof(body)); |
|
|
|
|
|
|
|
if( bodyLen <= 0 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
errorResponse(connData, 400, "No button ID specified!"); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case SUBMIT: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case LOAD: |
|
|
|
|
|
|
|
case REFRESH: |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("Web callback to MCU: %s\n", reasonBuf); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_WEB_REQ_CB, (uint32_t)cb->callback, bodyLen >= 0 ? 5 : 4); |
|
|
|
|
|
|
|
uint16_t r = (uint16_t)reason; |
|
|
|
|
|
|
|
cmdResponseBody(&r, sizeof(uint16_t)); |
|
|
|
|
|
|
|
cmdResponseBody(&connData->conn->proto.tcp->remote_ip, 4); |
|
|
|
|
|
|
|
cmdResponseBody(&connData->conn->proto.tcp->remote_port, sizeof(uint16_t)); |
|
|
|
|
|
|
|
cmdResponseBody(connData->url, os_strlen(connData->url)); |
|
|
|
|
|
|
|
if( bodyLen >= 0 ) |
|
|
|
|
|
|
|
cmdResponseBody(body, bodyLen); |
|
|
|
|
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
|
|
|
|
if( reason == SUBMIT ) |
|
|
|
if( reason == SUBMIT ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
httpdStartResponse(connData, 204); |
|
|
|
httpdStartResponse(connData, 204); |
|
|
|
httpdEndHeaders(connData); |
|
|
|
httpdEndHeaders(connData); |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connData->cgiData = (void *)1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_MORE; |
|
|
|
} |
|
|
|
} |
|
|
|