diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-03-27 00:06:28 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-03-27 00:06:28 +0000 |
commit | 5ebce14f1e190de6a43068f86efd232aa4747a10 (patch) | |
tree | d635159dd8ef3ab5cb7fff9563fe4267838c35ba /nuttx/netutils | |
parent | c099737f809c1d2730af9cffcdecea4d700f4c4e (diff) | |
download | px4-nuttx-5ebce14f1e190de6a43068f86efd232aa4747a10.tar.gz px4-nuttx-5ebce14f1e190de6a43068f86efd232aa4747a10.tar.bz2 px4-nuttx-5ebce14f1e190de6a43068f86efd232aa4747a10.zip |
More bugfixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1646 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils')
-rw-r--r-- | nuttx/netutils/webclient/webclient.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/nuttx/netutils/webclient/webclient.c b/nuttx/netutils/webclient/webclient.c index 510e631a7..25d68558b 100644 --- a/nuttx/netutils/webclient/webclient.c +++ b/nuttx/netutils/webclient/webclient.c @@ -303,72 +303,77 @@ static inline int wget_parseheaders(struct wget_s *ws) * we parse it. */ - if (ws->line[0] == ISO_cr) + if (ndx > 0) /* Should always be true */ { - /* This was the last header line (i.e., and empty "\r\n"), so - * we are done with the headers and proceed with the actual - * data. - */ + if (ws->line[0] == ISO_cr) + { + /* This was the last header line (i.e., and empty "\r\n"), so + * we are done with the headers and proceed with the actual + * data. + */ - ws->state = WEBCLIENT_STATE_DATA; - goto exit; - } + ws->state = WEBCLIENT_STATE_DATA; + goto exit; + } - ws->line[ndx] = '\0'; + /* Truncate the trailing \r\n */ - /* Check for specific HTTP header fields. */ + ws->line[ndx-1] = '\0'; -#ifdef CONFIG_WEBCLIENT_GETMIMETYPE - if (strncasecmp(ws->line, g_httpcontenttype, strlen(g_httpcontenttype)) == 0) - { - /* Found Content-type field. */ + /* Check for specific HTTP header fields. */ - char *dest = strchr(ws->line, ';'); - if (dest != NULL) +#ifdef CONFIG_WEBCLIENT_GETMIMETYPE + if (strncasecmp(ws->line, g_httpcontenttype, strlen(g_httpcontenttype)) == 0) { - *dest = 0; + /* Found Content-type field. */ + + char *dest = strchr(ws->line, ';'); + if (dest != NULL) + { + *dest = 0; + } + strncpy(ws->mimetype, ws->line + strlen(g_httpcontenttype), sizeof(ws->mimetype)); } - strncpy(ws->mimetype, ws->line + strlen(g_httpcontenttype) - 1, sizeof(ws->mimetype)); - } - else + else #endif - if (strncasecmp(ws->line, g_httplocation, strlen(g_httplocation)) == 0) - { - /* Save a pointer to the location */ + if (strncasecmp(ws->line, g_httplocation, strlen(g_httplocation)) == 0) + { + /* Save a pointer to the location */ - char *dest = ws->line + strlen(g_httplocation) - 1; + char *dest = ws->line + strlen(g_httplocation); - /* Concatenate the hostname */ + /* Concatenate the hostname */ - if (strncmp(dest, g_httphttp, strlen(g_httphttp)) == 0) - { - for(i = 0, dest += 7; i < ws->ndx - 7; i++, dest++) + if (strncmp(dest, g_httphttp, strlen(g_httphttp)) == 0) { - if (*dest == 0 || *dest == '/' || *dest == ' ' || *dest == ':') + for(i = 0, dest += 7; i < ws->ndx - 7; i++, dest++) { - ws->hostname[i] = 0; - break; - } - else if (i < CONFIG_NETUTILS_WEBCLIENT_MAXHOSTNAME-1) - { - ws->hostname[i] = *dest; + if (*dest == 0 || *dest == '/' || *dest == ' ' || *dest == ':') + { + ws->hostname[i] = 0; + break; + } + else if (i < CONFIG_NETUTILS_WEBCLIENT_MAXHOSTNAME-1) + { + ws->hostname[i] = *dest; + } } } - } - /* Copy the location */ + /* Copy the location */ - strncpy(ws->filename, dest, CONFIG_NETUTILS_WEBCLIENT_MAXFILENAME-1); + strncpy(ws->filename, dest, CONFIG_NETUTILS_WEBCLIENT_MAXFILENAME-1); - /* Make sure that everything is NULL terminated */ + /* Make sure that everything is NULL terminated */ - ws->hostname[CONFIG_NETUTILS_WEBCLIENT_MAXHOSTNAME-1] = '\0'; - ws->filename[CONFIG_NETUTILS_WEBCLIENT_MAXFILENAME-1] = '\0'; - nvdbg("New hostname='%s' filename='%s'\n", ws->hostname, ws->filename); + ws->hostname[CONFIG_NETUTILS_WEBCLIENT_MAXHOSTNAME-1] = '\0'; + ws->filename[CONFIG_NETUTILS_WEBCLIENT_MAXFILENAME-1] = '\0'; + nvdbg("New hostname='%s' filename='%s'\n", ws->hostname, ws->filename); + } } - /* We're done parsing, so we reset the pointer and start the - * next line. + /* We're done parsing this line, so we reset the index to the start + * of the next line. */ ndx = 0; |