diff --git a/configs/eagle100/thttpd/defconfig b/configs/eagle100/thttpd/defconfig index d6d3ec61d2b..fc78a9dace9 100644 --- a/configs/eagle100/thttpd/defconfig +++ b/configs/eagle100/thttpd/defconfig @@ -543,7 +543,7 @@ CONFIG_THTTPD_CGI_STACKSIZE=1024 CONFIG_THTTPD_CGI_BYTECOUNT=20000 CONFIG_THTTPD_CGI_TIMELIMIT=0 CONFIG_THTTPD_CHARSET="iso-8859-1" -CONFIG_THTTPD_IOBUFFERSIZE=256 +CONFIG_THTTPD_IOBUFFERSIZE=1024 #CONFIG_THTTPD_INDEX_NAMES CONFIG_AUTH_FILE=n CONFIG_THTTPD_LISTEN_BACKLOG=8 diff --git a/lib/lib_strcasecmp.c b/lib/lib_strcasecmp.c index 425a3e639f4..d9c5e5636c0 100644 --- a/lib/lib_strcasecmp.c +++ b/lib/lib_strcasecmp.c @@ -54,10 +54,10 @@ #ifndef CONFIG_ARCH_STRCMP int strcasecmp(const char *cs, const char *ct) { - register signed char result; + register int result; for (;;) { - if ((result = toupper(*cs) - toupper(*ct)) != 0 || !*cs) + if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) { break; } diff --git a/lib/lib_strncasecmp.c b/lib/lib_strncasecmp.c index 5b35bfff1e9..c34396a502b 100644 --- a/lib/lib_strncasecmp.c +++ b/lib/lib_strncasecmp.c @@ -54,10 +54,10 @@ #ifndef CONFIG_ARCH_STRNCASECMP int strncasecmp(const char *cs, const char *ct, size_t nb) { - register signed char result = 0; + register int result = 0; for (; nb > 0; nb--) { - if ((result = toupper(*cs) - toupper(*ct)) != 0 || !*cs) + if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) { break; } diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c index 1fe609dffe4..238f91076cb 100644 --- a/netutils/thttpd/libhttpd.c +++ b/netutils/thttpd/libhttpd.c @@ -136,13 +136,13 @@ struct cgi_outbuffer_s static void free_httpd_server(httpd_server *hs); static int initialize_listen_socket(httpd_sockaddr *saP); -static void add_response(httpd_conn *hc, char *str); -static void send_mime(httpd_conn *hc, int status, char *title, char *encodings, - char *extraheads, char *type, off_t length, time_t mod); -static void send_response(httpd_conn *hc, int status, char *title, - char *extraheads, char *form, char *arg); +static void add_response(httpd_conn *hc, const char *str); +static void send_mime(httpd_conn *hc, int status, const char *title, const char *encodings, + const char *extraheads, const char *type, off_t length, time_t mod); +static void send_response(httpd_conn *hc, int status, const char *title, + const char *extraheads, const char *form, const char *arg); static void send_response_tail(httpd_conn *hc); -static void defang(char *str, char *dfstr, int dfsize); +static void defang(const char *str, char *dfstr, int dfsize); #ifdef CONFIG_THTTPD_ERROR_DIRECTORY static int send_err_file(httpd_conn *hc, int status, char *title, char *extraheads, char *filename); @@ -234,41 +234,51 @@ static size_t str_alloc_size = 0; * HTTP Strings ****************************************************************************/ -static char *ok200title = "OK"; -static char *ok206title = "Partial Content"; +static const char ok200title[] = "OK"; +static const char ok206title[] = "Partial Content"; -static char *err302title = "Found"; -static char *err302form = "The actual URL is '%s'.\n"; +static const char err302title[] = "Found"; +static const char err302form[] = "The actual URL is '%s'.\n"; -static char *err304title = "Not Modified"; +static const char err304title[] = "Not Modified"; -char *httpd_err400title = "Bad Request"; -char *httpd_err400form = "Your request has bad syntax or is inherently impossible to satisfy.\n"; +const char httpd_err400title[] = "Bad Request"; +const char httpd_err400form[] = "Your request has bad syntax or is inherently impossible to satisfy.\n"; #ifdef CONFIG_THTTPD_AUTH_FILE -static char *err401title = "Unauthorized"; -static char *err401form = "Authorization required for the URL '%s'.\n"; +static const char err401title[] = "Unauthorized"; +static const char err401form[] = "Authorization required for the URL '%s'.\n"; #endif -static char *err403title = "Forbidden"; +static const char err403title[] = "Forbidden"; #ifndef EXPLICIT_ERROR_PAGES -static char *err403form = "You do not have permission to get URL '%s' from this server.\n"; +static const char err403form[] = "You do not have permission to get URL '%s' from this server.\n"; #endif -static char *err404title = "Not Found"; -static char *err404form = "The requested URL '%s' was not found on this server.\n"; +static const char err404title[] = "Not Found"; +static const char err404form[] = "The requested URL '%s' was not found on this server.\n"; -char *httpd_err408title = "Request Timeout"; -char *httpd_err408form = "No request appeared within a reasonable time period.\n"; +const char httpd_err408title[] = "Request Timeout"; +const char httpd_err408form[] = "No request appeared within a reasonable time period.\n"; -static char *err500title = "Internal Error"; -static char *err500form = "There was an unusual problem serving the requested URL '%s'.\n"; +static const char err500title[] = "Internal Error"; +static const char err500form[] = "There was an unusual problem serving the requested URL '%s'.\n"; -static char *err501title = "Not Implemented"; -static char *err501form = "The requested method '%s' is not implemented by this server.\n"; +static const char err501title[] = "Not Implemented"; +static const char err501form[] = "The requested method '%s' is not implemented by this server.\n"; -char *httpd_err503title = "Service Temporarily Overloaded"; -char *httpd_err503form = "The requested URL '%s' is temporarily overloaded. Please try again later.\n"; +static const char httpd_err503title[] = "Service Temporarily Overloaded"; +static const char httpd_err503form[] = "The requested URL '%s' is temporarily overloaded. Please try again later.\n"; + +static const char html_crlf[] = "\r\n"; +static const char html_html[] = "\r\n"; +static const char html_endhtml[] = "\r\n"; +static const char html_hdtitle[] = "
\n\ -mode links bytes last-changed name\n\ -", fp); + fputs(html_endbody, fp); + fputs(html_endhtml, fp); (void)fclose(fp); exit(0); } @@ -2003,6 +2023,7 @@ static int ls(httpd_conn *hc) { ndbg("task_create: %d\n", errno); closedir(dirp); + INTERNALERROR("task_create"); httpd_send_err(hc, 500, err500title, "", err500form, hc->encodedurl); return -1; } @@ -2028,6 +2049,7 @@ static int ls(httpd_conn *hc) else { closedir(dirp); + NOTIMPLEMENTED(httpd_method_str(hc->method)); httpd_send_err(hc, 501, err501title, "", err501form, httpd_method_str(hc->method)); return -1; } @@ -2319,7 +2341,7 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, ssize_t nbytes_read; char *br; int status; - char *title; + const char *title; char *cp; /* Make sure the connection is in blocking mode. It should already be @@ -2342,7 +2364,9 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, * EAGAIN is not an error, but it is still cause to return. */ - nbytes_read = read(rfd, inbuffer, sizeof(inbuffer)); + nbytes_read = read(hc->conn_fd, inbuffer, sizeof(inbuffer)); + nvdbg("Read %d bytes from fd %d\n", nbytes_read, hc->conn_fd); + if (nbytes_read < 0) { if (errno != EINTR) @@ -2361,6 +2385,7 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, if (nbytes_read <= 0) { + nvdbg("End-of-file\n"); br = &(hdr->buffer[hdr->len]); hdr->state = CGI_OUTBUFFER_HEADERREAD; } @@ -2372,12 +2397,14 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, (void)memcpy(&(hdr->buffer[hdr->len]), inbuffer, nbytes_read); hdr->len += nbytes_read; hdr->buffer[hdr->len] = '\0'; + nvdbg("Header bytes accumulated: %d\n", hdr->len); /* Check for end of header */ if ((br = strstr(hdr->buffer, "\015\012\015\012")) != NULL || (br = strstr(hdr->buffer, "\012\012")) != NULL) { + nvdbg("End-of-header\n"); hdr->state = CGI_OUTBUFFER_HEADERREAD; } else @@ -2430,7 +2457,8 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, /* Write the status line. */ - switch (status) + nvdbg("Status: %d\n", status); + switch (status) { case 200: title = ok200title; @@ -2445,6 +2473,7 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, break; case 400: + BADREQUEST("status"); title = httpd_err400title; break; @@ -2467,10 +2496,12 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, break; case 500: + INTERNALERROR("status"); title = err500title; break; case 501: + NOTIMPLEMENTED("status"); title = err501title; break; @@ -2510,6 +2541,8 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, */ nbytes_read = read(rfd, inbuffer, sizeof(inbuffer)); + nvdbg("Read %d bytes from fd %d\n", nbytes_read, rfd); + if (nbytes_read < 0) { if (errno != EINTR) @@ -2528,6 +2561,7 @@ static inline int cgi_interpose_output(httpd_conn *hc, int rfd, char *inbuffer, if (nbytes_read == 0) { + nvdbg("End-of-file\n"); close(hc->conn_fd); close(rfd); hdr->state = CGI_OUTBUFFER_DONE; @@ -2789,6 +2823,7 @@ errout_with_descriptors: close(rfd); close(hc->conn_fd); + INTERNALERROR("errout"); httpd_send_err(hc, 500, err500title, "", err500form, hc->encodedurl); httpd_write_response(hc); return err; @@ -2834,6 +2869,7 @@ static int cgi(httpd_conn *hc) if (child < 0) { ndbg("task_create: %d\n", errno); + INTERNALERROR("task_create"); httpd_send_err(hc, 500, err500title, "", err500form, hc->encodedurl); return -1; } @@ -2846,6 +2882,7 @@ static int cgi(httpd_conn *hc) } else { + NOTIMPLEMENTED("CGI"); httpd_send_err(hc, 501, err501title, "", err501form, httpd_method_str(hc->method)); return -1; } @@ -2873,6 +2910,7 @@ static int really_start_request(httpd_conn *hc, struct timeval *nowP) if (hc->method != METHOD_GET && hc->method != METHOD_HEAD && hc->method != METHOD_POST) { + NOTIMPLEMENTED("really start"); httpd_send_err(hc, 501, err501title, "", err501form, httpd_method_str(hc->method)); return -1; @@ -2881,6 +2919,7 @@ static int really_start_request(httpd_conn *hc, struct timeval *nowP) /* Stat the file. */ if (stat(hc->expnfilename, &hc->sb) < 0) { + INTERNALERROR(hc->expnfilename); httpd_send_err(hc, 500, err500title, "", err500form, hc->encodedurl); return -1; } @@ -3002,6 +3041,7 @@ static int really_start_request(httpd_conn *hc, struct timeval *nowP) cp = expand_filename(indexname, &pi, hc->tildemapped); if (cp == (char *)0 || pi[0] != '\0') { + INTERNALERROR(indexname); httpd_send_err(hc, 500, err500title, "", err500form, hc->encodedurl); return -1; } @@ -3141,6 +3181,7 @@ static int really_start_request(httpd_conn *hc, struct timeval *nowP) hc->file_fd = open(hc->expnfilename, O_RDONLY); if (!hc->file_fd < 0) { + INTERNALERROR(hc->expnfilename); httpd_send_err(hc, 500, err500title, "", err500form, hc->encodedurl); return -1; } @@ -3493,14 +3534,16 @@ void httpd_realloc_str(char **strP, size_t * maxsizeP, size_t size) } } -void httpd_send_err(httpd_conn *hc, int status, char *title, char *extraheads, - char *form, char *arg) +void httpd_send_err(httpd_conn *hc, int status, const char *title, const char *extraheads, + const char *form, const char *arg) { #ifdef CONFIG_THTTPD_ERROR_DIRECTORY char filename[1000]; /* Try virtual host error page. */ + ndbg("title: \"%s\" form: \"%s\"\n", title, form); + #ifdef CONFIG_THTTPD_VHOST if (hc->hostdir[0] != '\0') { @@ -3508,6 +3551,7 @@ void httpd_send_err(httpd_conn *hc, int status, char *title, char *extraheads, "%s/%s/err%d.html", hc->hostdir, CONFIG_THTTPD_ERROR_DIRECTORY, status); if (send_err_file(hc, status, title, extraheads, filename)) { + nvdbg("Sent VHOST error file\n"); return; } } @@ -3515,10 +3559,10 @@ void httpd_send_err(httpd_conn *hc, int status, char *title, char *extraheads, /* Try server-wide error page. */ - (void)snprintf(filename, sizeof(filename), - "%s/err%d.html", CONFIG_THTTPD_ERROR_DIRECTORY, status); + (void)snprintf(filename, sizeof(filename), "%s/err%d.html", CONFIG_THTTPD_ERROR_DIRECTORY, status); if (send_err_file(hc, status, title, extraheads, filename)) { + nvdbg("Sent server-wide error page\n"); return; } @@ -3533,7 +3577,7 @@ void httpd_send_err(httpd_conn *hc, int status, char *title, char *extraheads, #endif } -char *httpd_method_str(int method) +const char *httpd_method_str(int method) { switch (method) { @@ -3891,21 +3935,27 @@ int httpd_parse_request(httpd_conn *hc) char *pi; hc->checked_idx = 0; /* reset */ - method_str = bufgets(hc); + method_str = bufgets(hc); + nvdbg("method_str: \"%s\"\n", method_str); url = strpbrk(method_str, " \t\012\015"); if (!url) { + BADREQUEST("url-1"); httpd_send_err(hc, 400, httpd_err400title, "", httpd_err400form, ""); return -1; } + *url++ = '\0'; - url += strspn(url, " \t\012\015"); + url += strspn(url, " \t\012\015"); + nvdbg("url: \"%s\"\n", url); protocol = strpbrk(url, " \t\012\015"); + nvdbg("protocol: \"%s\"\n", protocol ? protocol : "
", hc->encodedurl, hc->encodedurl); + fputs(html_html, fp); + fputs(html_hdtitle, fp); + (void)fprintf(fp, "Index of %s", hc->encodedurl, hc->encodedurl); + fputs(html_titlehd, fp); + fputs(html_body, fp); + fputs(html_hdr2, fp); + (void)fprintf(fp, "Index of %s", hc->encodedurl, hc->encodedurl); + fputs(html_endhdr2, fp); + fputs(html_crlf, fp); + fputs("\r\nmode links bytes last-changed name\r\n\n\n"); + fputs("
", fp); /* Read in names. */ @@ -1923,7 +1941,9 @@ mode links bytes last-changed name\n\ nameptrs[i], linkprefix, link, fileclass); } - (void)fprintf(fp, "