removed malloc from webserver

This commit is contained in:
Martijn Scheepers
2018-02-02 10:05:14 +01:00
parent 088ac4c416
commit 41a1fa6df7
4 changed files with 32 additions and 68 deletions

View File

@@ -6,35 +6,4 @@ config WIFI_SSID
help
SSID (network name) for the example to connect to.
config WIFI_PASSWORD
string "WiFi Password"
default "myssid"
help
WiFi password (WPA or WPA2) for the example to use.
Can be left blank if the network has no security set.
config SERVER_IP
string "HTTP Server IP"
default "192.168.0.3"
help
HTTP Server IP to download the image file from.
See example README.md for details.
config SERVER_PORT
string "HTTP Server Port"
default "8070"
help
HTTP Server port to connect to.
Should be chosen not to conflict with any other port used
on the system.
config EXAMPLE_FILENAME
string "HTTP GET Filename"
default "/hello-world.bin"
help
Filename of the app image file to download for
the OTA update.
endmenu

View File

@@ -91,43 +91,42 @@ void http_server_netconn_serve(struct netconn *conn)
struct netbuf *inbuf;
char *buf;
u16_t buflen;
err_t err;
/* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one netbuf */
err = netconn_recv(conn, &inbuf);
//err_t err;
err_t err = netconn_recv(conn, &inbuf);
if (err == ERR_OK) {
netbuf_data(inbuf, (void**)&buf, &buflen);
buf[buflen] = '\0';
ESP_LOGI(TAG, "buffer = %s \n", buf);
if(strncmp(buf, "GET /", 5) == 0){
int len = strchr(&buf[4], ' ') - &buf[4];
char *filepath = malloc(len + 1);
strncpy(filepath, &buf[4], len);
filepath[len] = '\0';
char *filepath = &buf[4];
char *end = strchr(&buf[4], ' ');
*end = '\0';
ESP_LOGI(TAG, "GET filepath = %s", filepath);
return_page(conn, filepath);
free(filepath);
}
if(strncmp(buf, "POST /", 6) == 0){
int len = strchr(&buf[5], ' ') - &buf[5];
char *filepath = malloc(len + 1);
strncpy(filepath, &buf[5], len);
filepath[len] = '\0';
}else if(strncmp(buf, "POST /", 6) == 0){
char *filepath = &buf[5];
char *ptr = strchr(&buf[5], ' ');
*ptr = '\0';
ESP_LOGI(TAG, "POST filepath = %s", filepath);
ptr += 1;
char *content_type = strstr(ptr, "Content-Type:");
char *idx = strstr(buf, "Content-Type:");
idx = idx + 14;
if(content_type == NULL){
return_notfound(conn);
goto cleanup;
}
content_type = content_type + 14;
ESP_LOGI(TAG, "POST content_type = %s", content_type);
if(strncmp(idx, "application/x-www-form-urlencoded", 33) == 0){
if(strncmp(content_type, "application/x-www-form-urlencoded", 33) == 0){
ESP_LOGI(TAG, "------- application/x-www-form-urlencoded --------");
idx = strstr(buf, "\r\n\r\n");
idx = idx + 4;
char *content = strstr(ptr, "\r\n\r\n");
content += 4;
char *token;
token = strtok(idx, "&");
token = strtok(content, "&");
while(token != NULL){
ESP_LOGI(TAG,"token: %s", token);
@@ -142,15 +141,16 @@ void http_server_netconn_serve(struct netconn *conn)
token = strtok(NULL, "&");
}
}else if(strncmp(idx, "multipart/form-data", 19) == 0){
}else if(strncmp(content_type, "multipart/form-data", 19) == 0){
ESP_LOGI(TAG, "------ multipart/form-data -------");
}
return_page(conn, filepath);
free(filepath);
}else{
return_notfound(conn);
}
}
cleanup:
netconn_close(conn);
netbuf_delete(inbuf);
}

View File

@@ -77,10 +77,6 @@ CONFIG_MONITOR_BAUD=115200
# Example Configuration
#
CONFIG_WIFI_SSID="SDNmtr"
CONFIG_WIFI_PASSWORD="LockedSDN"
CONFIG_SERVER_IP="192.168.0.128"
CONFIG_SERVER_PORT="8070"
CONFIG_EXAMPLE_FILENAME="/mqtt_iobox.bin"
#
# Partition Table
@@ -329,10 +325,10 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
CONFIG_LOG_DEFAULT_LEVEL_NONE=
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
CONFIG_LOG_DEFAULT_LEVEL_WARN=
CONFIG_LOG_DEFAULT_LEVEL_INFO=
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y
CONFIG_LOG_DEFAULT_LEVEL=5
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_COLORS=y
#

View File

@@ -306,8 +306,7 @@ CONFIG_TIMER_TASK_PRIORITY=1
CONFIG_TIMER_TASK_STACK_DEPTH=2048
CONFIG_TIMER_QUEUE_LENGTH=10
CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
CONFIG_FREERTOS_USE_TRACE_FACILITY=
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=
CONFIG_FREERTOS_DEBUG_INTERNALS=
@@ -330,10 +329,10 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
CONFIG_LOG_DEFAULT_LEVEL_NONE=
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
CONFIG_LOG_DEFAULT_LEVEL_WARN=
CONFIG_LOG_DEFAULT_LEVEL_INFO=
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y
CONFIG_LOG_DEFAULT_LEVEL=5
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_COLORS=y
#