X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fhttp.c;h=dd4ee4fd22ffdcdda57f3efba7174f47b39c06d5;hb=e1ab084b6b7434979ca344270526934e2af508d9;hp=e3fc8085790e661dc556e571b068d76142426582;hpb=d603ad8d35758a54f6cb08a7f8c16f6327ea86e0;p=bertos.git diff --git a/bertos/net/http.c b/bertos/net/http.c index e3fc8085..dd4ee4fd 100644 --- a/bertos/net/http.c +++ b/bertos/net/http.c @@ -55,6 +55,7 @@ #include #include +#include #include @@ -65,46 +66,59 @@ static const char http_html_hdr_500[] = "HTTP/1.1 500 Internal Server Error\r\nC static HttpCGI *cgi_table; static http_handler_t http_callback; -/** - * Send on \param client socket - * the 200 Ok http header - */ -void http_sendOk(struct netconn *client) -{ - netconn_write(client, http_html_hdr_200, sizeof(http_html_hdr_200) - 1, NETCONN_NOCOPY); -} - -/** - * Send on \param client socket - * the 404 File not found http header - */ -void http_sendFileNotFound(struct netconn *client) +static char http_hexToAscii(char first, char second) { - netconn_write(client, http_html_hdr_404, sizeof(http_html_hdr_404) - 1, NETCONN_NOCOPY); + char hex[5], *stop; + hex[0] = '0'; + hex[1] = 'x'; + hex[2] = first; + hex[3] = second; + hex[4] = 0; + return strtol(hex, &stop, 16); } -/** - * Send on \param client socket - * the 500 internal server error http header - */ -void http_sendInternalErr(struct netconn *client) +void http_decodeUri(const char *raw_buf, size_t raw_len, char *decodec_buf, size_t len) { - netconn_write(client, http_html_hdr_500, sizeof(http_html_hdr_500) - 1, NETCONN_NOCOPY); + char value; + for (size_t i = 0; i < raw_len; i++) + { + if (!len) + return; + + if (raw_buf[i] == '%') + { + if (i + 2 < raw_len) + { + /* convert hex value after % */ + value = http_hexToAscii(raw_buf[i + 1], raw_buf[i + 2]); + if (value) + { + *decodec_buf++ = value; + len--; + i += 2; + continue; + } + } + } + *decodec_buf++ = raw_buf[i]; + len--; + } } -void http_getPageName(const char *revc_buf, size_t recv_len, char *page_name, size_t len) +void http_getPageName(const char *recv_buf, size_t recv_len, char *page_name, size_t len) { int i = 0; bool str_ok = false; - if (revc_buf && (recv_len > sizeof("GET /"))) + if (recv_buf && (recv_len > sizeof("GET /"))) { - if (*revc_buf++ == 'G' && - *revc_buf++ == 'E' && *revc_buf++ == 'T') + if (*recv_buf++ == 'G' && + *recv_buf++ == 'E' && *recv_buf++ == 'T') { str_ok = true; - revc_buf += 2; + /* skip the space and "/" */ + recv_buf += 2; } } @@ -112,7 +126,7 @@ void http_getPageName(const char *revc_buf, size_t recv_len, char *page_name, si { while ((size_t)i < recv_len) { - char ch = *(revc_buf++); + char ch = *(recv_buf++); if (ch == ' ' || ch == '\t' || ch == '\n') break; if((size_t)i == len - 1) @@ -133,6 +147,35 @@ INLINE const char *get_ext(const char *name) return NULL; } + +/** + * Send on \param client socket + * the 200 Ok http header + */ +void http_sendOk(struct netconn *client) +{ + netconn_write(client, http_html_hdr_200, sizeof(http_html_hdr_200) - 1, NETCONN_NOCOPY); +} + + +/** + * Send on \param client socket + * the 404 File not found http header + */ +void http_sendFileNotFound(struct netconn *client) +{ + netconn_write(client, http_html_hdr_404, sizeof(http_html_hdr_404) - 1, NETCONN_NOCOPY); +} + +/** + * Send on \param client socket + * the 500 internal server error http header + */ +void http_sendInternalErr(struct netconn *client) +{ + netconn_write(client, http_html_hdr_500, sizeof(http_html_hdr_500) - 1, NETCONN_NOCOPY); +} + static http_handler_t cgi_search(const char *name, HttpCGI *table) { if (!table) @@ -149,9 +192,15 @@ static http_handler_t cgi_search(const char *name, HttpCGI *table) if (!strcmp(table[i].name, ext)) break; } - else /* (table[i].type == CGI_MATCH_NAME) */ + else if (table[i].type == CGI_MATCH_NAME) { LOG_INFO("Match all name %s\n", name); + if (strstr(name, table[i].name) != NULL) + break; + } + else /* (table[i].type == CGI_MATCH_WORD) */ + { + LOG_INFO("Match all word %s\n", name); if (!strcmp(table[i].name, name)) break; }