check for closed connection in all cgi handlers

pull/73/head
Thorsten von Eicken 9 years ago
parent 0c321c8351
commit 4463ed6ddd
  1. 3
      serial/console.c
  2. 1
      user/cgi.c
  3. 15
      user/cgiflash.c
  4. 1
      user/cgipins.c
  5. 12
      user/cgiwifi.c
  6. 2
      user/log.c

@ -49,6 +49,7 @@ console_write_char(char c) {
int ICACHE_FLASH_ATTR
ajaxConsoleReset(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
jsonHeader(connData, 200);
console_rd = console_wr = console_pos = 0;
serbridgeReset();
@ -57,6 +58,7 @@ ajaxConsoleReset(HttpdConnData *connData) {
int ICACHE_FLASH_ATTR
ajaxConsoleBaud(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[512];
int len, status = 400;
len = httpdFindArg(connData->getArgs, "rate", buff, sizeof(buff));
@ -79,6 +81,7 @@ ajaxConsoleBaud(HttpdConnData *connData) {
int ICACHE_FLASH_ATTR
ajaxConsole(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[2048];
int len; // length of text in buff
int console_len = (console_wr+BUF_MAX-console_rd) % BUF_MAX; // num chars in console_buf

@ -55,6 +55,7 @@ int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) {
extern char *esp_link_version; // in user_main.c
int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[1024];
// don't use jsonHeader so the response does get cached
httpdStartResponse(connData, 200);

@ -55,10 +55,7 @@ int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) {
//===== Cgi to query which firmware needs to be uploaded next
int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) {
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
uint8 id = system_upgrade_userbin_check();
httpdStartResponse(connData, 200);
@ -74,10 +71,7 @@ int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) {
//===== Cgi that allows the firmware to be replaced via http POST
int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) {
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
int offset = connData->post->received - connData->post->buffLen;
if (offset == 0) {
@ -147,10 +141,7 @@ static ETSTimer flash_reboot_timer;
// Handle request to reboot into the new firmware
int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) {
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
// sanity-check that the 'next' partition actually contains something that looks like
// valid firmware

@ -106,6 +106,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) {
}
int ICACHE_FLASH_ATTR cgiPins(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
if (connData->requestType == HTTPD_METHOD_GET) {
return cgiPinsGet(connData);
} else if (connData->requestType == HTTPD_METHOD_POST) {

@ -167,6 +167,7 @@ static void ICACHE_FLASH_ATTR scanStartCb(void *arg) {
}
static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
jsonHeader(connData, 200);
if (!cgiWifiAps.scanInProgress) {
cgiWifiAps.scanInProgress = 1;
@ -178,6 +179,7 @@ static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) {
}
static int ICACHE_FLASH_ATTR cgiWiFiGetScan(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[2048];
int len;
@ -428,10 +430,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
int len;
char buff[1024];
if (connData->conn==NULL) {
// Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
if (len!=0) {
@ -512,6 +511,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
char buff[1024];
int len;
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
jsonHeader(connData, 200);
len = os_sprintf(buff, "{");
@ -547,9 +547,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) {
char buff[1024];
if (connData->conn==NULL) {
return HTTPD_CGI_DONE; // Connection aborted
}
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
os_strcpy(buff, "{");
printWifiInfo(buff+1);

@ -87,6 +87,7 @@ ajaxLog(HttpdConnData *connData) {
int log_len = (log_wr+BUF_MAX-log_rd) % BUF_MAX; // num chars in log_buf
int start = 0; // offset onto log_wr to start sending out chars
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
jsonHeader(connData, 200);
// figure out where to start in buffer based on URI param
@ -128,6 +129,7 @@ static char *dbg_mode[] = { "auto", "off", "on" };
int ICACHE_FLASH_ATTR
ajaxLogDbg(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[512];
int len, status = 400;
len = httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));

Loading…
Cancel
Save