summaryrefslogtreecommitdiff
path: root/apps/netutils
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-06-29 09:30:09 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-06-29 09:30:09 -0600
commit1deaf2a9634576bf0e0f35a24911c3f22215fbd2 (patch)
treecfc63769fd41a0e4417e2a723d79e4ba8fb6f077 /apps/netutils
parent02bad8e430f112e7f0bac29f52861c7048cb2bbe (diff)
downloadpx4-nuttx-1deaf2a9634576bf0e0f35a24911c3f22215fbd2.tar.gz
px4-nuttx-1deaf2a9634576bf0e0f35a24911c3f22215fbd2.tar.bz2
px4-nuttx-1deaf2a9634576bf0e0f35a24911c3f22215fbd2.zip
Fixes for networking and tiny webserver from Max
Diffstat (limited to 'apps/netutils')
-rw-r--r--apps/netutils/webserver/Kconfig9
-rw-r--r--apps/netutils/webserver/httpd.c44
2 files changed, 35 insertions, 18 deletions
diff --git a/apps/netutils/webserver/Kconfig b/apps/netutils/webserver/Kconfig
index d984427a3..59dcc5f30 100644
--- a/apps/netutils/webserver/Kconfig
+++ b/apps/netutils/webserver/Kconfig
@@ -33,6 +33,15 @@ config NETUTILS_HTTPD_SCRIPT_DISABLE
---help---
This option, if selected, will elide the %! scripting
+config NETUTILS_HTTPD_MAXPATH
+ bool "Maximum size of a path"
+ default 64
+ ---help---
+ This is the maximum size of a PATH used in the web server. This setting
+ is the logically the same as the PATH_MAX setting that (and in fact, if
+ not defined, the MAX_PATH setting will be used). This setting allows
+ more conservative memory allocation.
+
config NETUTILS_HTTPD_CGIPATH
bool "URL/CGI function mapping"
default n
diff --git a/apps/netutils/webserver/httpd.c b/apps/netutils/webserver/httpd.c
index 26989611b..ab67842ee 100644
--- a/apps/netutils/webserver/httpd.c
+++ b/apps/netutils/webserver/httpd.c
@@ -336,8 +336,9 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
{
const char *mime;
const char *ptr;
- char cl[32];
- char s[128];
+ char contentlen[HTTPD_MAX_CONTENTLEN];
+ char header[HTTPD_MAX_HEADERLEN];
+ int hdrlen;
int i;
static const struct
@@ -381,7 +382,8 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
if (len >= 0)
{
- (void) snprintf(cl, sizeof cl, "Content-Length: %d\r\n", len);
+ (void)snprintf(contentlen, HTTPD_MAX_CONTENTLEN,
+ "Content-Length: %d\r\n", len);
}
#ifndef CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE
else
@@ -395,26 +397,32 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
/* TODO: here we "SHOULD" include a Retry-After header */
}
- i = snprintf(s, sizeof s,
- "HTTP/1.0 %d %s\r\n"
+ /* Construct the header.
+ *
+ * REVISIT: Wouldn't asprintf be a better option than a large stack
+ * array?
+ */
+
+ hdrlen = snprintf(header, HTTPD_MAX_HEADERLEN,
+ "HTTP/1.0 %d %s\r\n"
#ifndef CONFIG_NETUTILS_HTTPD_SERVERHEADER_DISABLE
- "Server: uIP/NuttX http://nuttx.org/\r\n"
-#endif
- "Connection: %s\r\n"
- "Content-type: %s\r\n"
- "%s"
- "\r\n",
- status,
- status >= 400 ? "Error" : "OK",
+ "Server: uIP/NuttX http://nuttx.org/\r\n"
+#endif
+ "Connection: %s\r\n"
+ "Content-type: %s\r\n"
+ "%s"
+ "\r\n",
+ status,
+ status >= 400 ? "Error" : "OK",
#ifndef CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE
- pstate->ht_keepalive ? "keep-alive" : "close",
+ pstate->ht_keepalive ? "keep-alive" : "close",
#else
- "close",
+ "close",
#endif
- mime,
- len >= 0 ? cl : "");
+ mime,
+ len >= 0 ? contentlen : "");
- return send_chunk(pstate, s, i);
+ return send_chunk(pstate, header, hdrlen);
}
static int httpd_senderror(struct httpd_state *pstate, int status)