From aa23c5d7c7b2b79e8ff74eb00bb12531b35731b4 Mon Sep 17 00:00:00 2001 From: asterix Date: Fri, 30 Sep 2011 08:31:00 +0000 Subject: [PATCH] Fix find name function. Pass as argument to cgi callback the rx buffer len. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5121 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/net/http.c | 37 ++++++++++++++++++++++++++++++------- bertos/net/http.h | 2 +- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/bertos/net/http.c b/bertos/net/http.c index 235401cd..bd8f3946 100644 --- a/bertos/net/http.c +++ b/bertos/net/http.c @@ -74,20 +74,42 @@ void http_sendFileNotFound(struct netconn *client) } -static void get_fileName(char *revc_buf, char *name, size_t len) +static void get_fileName(const char *revc_buf, size_t recv_len, char *name, size_t len) { + int i = 0; char *p = strstr(revc_buf, "GET"); if (p) { + //Find the end of the page request. + char *stop = strstr(revc_buf, "HTTP"); + if (!stop) + { + LOG_ERR("Bad GET request\n"); + name[0] = '\0'; + return; + } + //skip the "/" in get string request p += sizeof("GET") + 1; - for (size_t i = 0; *p != ' '; i++,p++) + + while (p != stop) { - if (i > len) + if ((size_t)i == len || (size_t)i >= recv_len) + { + name[i] = '\0'; break; - name[i] = *p; + } + + name[i++] = *(p++); } } + + //Trail white space in the string. + while ( --i >= 0 ) + if (name[i] != ' ' && name[i] != '\t' && name[i] != '\n') + break; + + name[i + 1] = '\0'; } static http_gci_handler_t cgi_search(const char *name, HttpCGI *table) @@ -123,19 +145,20 @@ void http_server(struct netconn *server, struct HttpCGI *table) if (rx_buf_conn) { netbuf_data(rx_buf_conn, (void **)&rx_buf, &len); + if (rx_buf) { memset(file_name, 0, sizeof(file_name)); - get_fileName(rx_buf, file_name, sizeof(file_name)); + get_fileName(rx_buf, len, file_name, sizeof(file_name)); LOG_INFO("Search %s\n", file_name); - if (strlen(file_name) == 0) + if (file_name[0] == '\0') strcpy(file_name, HTTP_DEFAULT_PAGE); http_gci_handler_t cgi = cgi_search(file_name, table); if (cgi) { - cgi(rx_buf, client); + cgi(client, rx_buf, len); } else if (SD_CARD_PRESENT()) { diff --git a/bertos/net/http.h b/bertos/net/http.h index 6b5b3bc1..e280bbaa 100644 --- a/bertos/net/http.h +++ b/bertos/net/http.h @@ -52,7 +52,7 @@ #include #include -typedef int (*http_gci_handler_t)(char *revc_buf, struct netconn *client); +typedef int (*http_gci_handler_t)(struct netconn *client, char *revc_buf, size_t revc_len); typedef struct HttpCGI { -- 2.25.1