summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-11-22 12:48:40 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-11-22 12:48:40 +0000
commit2ad451b8005afc667718569077c816195f8bd9ec (patch)
tree9a4268305395e10737e8b1c18c2ee96b0006af7e /nuttx
parent1e17d1ae425452aecad6f1fa99cf9b5903ee3880 (diff)
downloadpx4-nuttx-2ad451b8005afc667718569077c816195f8bd9ec.tar.gz
px4-nuttx-2ad451b8005afc667718569077c816195f8bd9ec.tar.bz2
px4-nuttx-2ad451b8005afc667718569077c816195f8bd9ec.zip
Use normal C strings
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@396 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/netutils/Makefile14
-rw-r--r--nuttx/netutils/smtp/smtp.c55
-rwxr-xr-xnuttx/netutils/uiplib/makestrings.c379
-rw-r--r--nuttx/netutils/uiplib/netutil-strings46
-rw-r--r--nuttx/netutils/webclient/webclient.c228
-rw-r--r--nuttx/netutils/webclient/webclient.h2
6 files changed, 174 insertions, 550 deletions
diff --git a/nuttx/netutils/Makefile b/nuttx/netutils/Makefile
index 4e355ab7f..df164a4a7 100644
--- a/nuttx/netutils/Makefile
+++ b/nuttx/netutils/Makefile
@@ -47,7 +47,6 @@ ifeq ($(CONFIG_NET_UDP),y)
include dhcpc/Make.defs
include resolv/Make.defs
endif
-include Make.str
endif
ASRCS = $(UIPLIB_ASRCS) $(DHCPC_ASRCS) $(RESOLV_ASRCS) $(SMTP_ASRCS) \
@@ -79,16 +78,6 @@ $(BIN): $(OBJS)
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
-makestrings$(EXEEXT): uiplib/makestrings.c
- @gcc -O2 -Wall $< -o $@
-
-.strings: makestrings$(EXEEXT) uiplib/netutil-strings
- @./makestrings uiplib/netutil-strings
- @touch $@
-
-Make.str: makestrings$(EXEEXT) uiplib/netutil-strings
- @./makestrings -s uiplib/netutil-strings >Make.str
-
.depend: Makefile $(SRCS)
ifeq ($(CONFIG_NET),y)
@$(MKDEP) --dep-path . --dep-path uiplib --dep-path dhcpc --dep-path smtp --dep-path webclient \
@@ -97,7 +86,7 @@ ifeq ($(CONFIG_NET),y)
endif
@touch $@
-depend: .strings Make.str .depend
+depend: .depend
clean:
@rm -f $(BIN) *.o *.rel *.asm *.lst *.sym *.adb *~
@@ -107,6 +96,5 @@ clean:
distclean: clean
@rm -f Make.dep .depend
@rm -f $(STRNG_CSRCS) $(STRNG_ASRCS)
- @rm -f rm .strings Make.str netutil-strings.h makestrings$(EXEEXT)
-include Make.dep
diff --git a/nuttx/netutils/smtp/smtp.c b/nuttx/netutils/smtp/smtp.c
index aa351d64b..2827a0d94 100644
--- a/nuttx/netutils/smtp/smtp.c
+++ b/nuttx/netutils/smtp/smtp.c
@@ -57,7 +57,9 @@
#include <net/uip/uip.h>
#include <net/uip/smtp.h>
-#include "netutil-strings.h"
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
#define SMTP_INPUT_BUFFER_SIZE 512
@@ -71,6 +73,10 @@
#define ISO_4 0x34
#define ISO_5 0x35
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
/* This structure represents the state of a single SMTP transaction */
struct smtp_state
@@ -92,6 +98,25 @@ struct smtp_state
char buffer[SMTP_INPUT_BUFFER_SIZE];
};
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const char g_smtp220[] = "220";
+static const char g_smtpcrnlperiodcrnl[] = "\r\n.\r\n";
+static const char g_smtpdata[] = "DATA\r\n";
+static const char g_smtpfrom[] = "From: ";
+static const char g_smtphelo[] = "HELO ";
+static const char g_smtpmailfrom[] = "MAIL FROM: ";
+static const char g_smtpquit[] = "QUIT\r\n";
+static const char g_smtprcptto[] = "RCPT TO: ";
+static const char g_smtpsubject[] = "Subject: ";
+static const char g_smtpto[] = "To: ";
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
{
if (recv(sockfd, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, 0) < 0)
@@ -99,12 +124,12 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
return ERROR;
}
- if (strncmp(psmtp->buffer, smtp_220, 3) != 0)
+ if (strncmp(psmtp->buffer, g_smtp220, strlen(g_smtp220)) != 0)
{
return ERROR;
}
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_helo, psmtp->localhostname);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtphelo, psmtp->localhostname);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
@@ -120,7 +145,7 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
return ERROR;
}
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_mail_from, psmtp->from);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtpmailfrom, psmtp->from);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
@@ -136,7 +161,7 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
return ERROR;
}
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_rcpt_to, psmtp->to);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtprcptto, psmtp->to);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
@@ -154,7 +179,7 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
if (psmtp->cc != 0)
{
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_rcpt_to, psmtp->cc);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtprcptto, psmtp->cc);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
@@ -171,7 +196,7 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
}
}
- if (send(sockfd, smtp_data, strlen(smtp_data), 0) < 0)
+ if (send(sockfd, g_smtpdata, strlen(g_smtpdata), 0) < 0)
{
return ERROR;
}
@@ -186,7 +211,7 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
return ERROR;
}
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_to, psmtp->to);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtpto, psmtp->to);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
@@ -194,20 +219,20 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
if (psmtp->cc != 0)
{
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_to, psmtp->cc);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtpto, psmtp->cc);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
}
}
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_from, psmtp->from);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtpfrom, psmtp->from);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
}
- snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", smtp_subject, psmtp->subject);
+ snprintf(psmtp->buffer, SMTP_INPUT_BUFFER_SIZE, "%s%s\r\n", g_smtpsubject, psmtp->subject);
if (send(sockfd, psmtp->buffer, strlen(psmtp->buffer), 0) < 0)
{
return ERROR;
@@ -218,7 +243,7 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
return ERROR;
}
- if (send(sockfd, smtp_crnlperiodcrnl, strlen(smtp_crnlperiodcrnl), 0) < 0)
+ if (send(sockfd, g_smtpcrnlperiodcrnl, strlen(g_smtpcrnlperiodcrnl), 0) < 0)
{
return ERROR;
}
@@ -233,13 +258,17 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
return ERROR;
}
- if (send(sockfd, smtp_quit, strlen(smtp_quit), 0) < 0)
+ if (send(sockfd, g_smtpquit, strlen(g_smtpquit), 0) < 0)
{
return ERROR;
}
return OK;
}
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
/* Specificy an SMTP server and hostname.
*
* This function is used to configure the SMTP module with an SMTP server and
diff --git a/nuttx/netutils/uiplib/makestrings.c b/nuttx/netutils/uiplib/makestrings.c
deleted file mode 100755
index feebeb120..000000000
--- a/nuttx/netutils/uiplib/makestrings.c
+++ /dev/null
@@ -1,379 +0,0 @@
-/****************************************************************************
- * net/recv.c
- *
- * Copyright (C) 2007 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Based loosely on a uIP perl script by Adam Dunkels
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-#include <libgen.h>
-#include <errno.h>
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-enum eaction { GENSRC=0, SRCLIST=1 };
-
- /****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static const char *g_progname;
-static const char *g_stringfile;
-static enum eaction g_action;
-
-static char g_line[1024];
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Function: parse_stringfile_line
- ****************************************************************************/
-
-void unescape_value(char *pvalue)
-{
- const char *pin;
- char *pout;
-
- pin = pvalue;
- pout = pvalue;
- while (*pin)
- {
- if (*pin == '\\')
- {
- pin++;
- if ( *pin >= 0 && *pin <= 0)
- {
- char *pend;
- unsigned long val = strtoul(pin, &pend, 0);
- if (pend != pin)
- {
- *pout++ = (char)val;
- pin = pend;
- }
- else
- {
- *pout++ = '\\';
- *pout++ = *pin++;
- }
- }
- else
- {
- switch (*pin)
- {
- case 'a':
- *pout++ = 0x07;
- break;
- case 'b':
- *pout++ = 0x08;
- break;
- case 't':
- *pout++ = 0x09;
- break;
- case 'n':
- *pout++ = 0x0a;
- break;
- case 'v':
- *pout++ = 0x0b;
- case 'f':
- *pout++ = 0x0c;
- break;
- case 'r':
- *pout++ = 0x0d;
- break;
- default:
- *pout++ = *pin;
- break;
- }
- pin++;
- }
- }
- else
- {
- *pout++ = *pin++;
- }
- }
- *pout = '\0';
-}
-
-/****************************************************************************
- * Function: parse_stringfile_line
- ****************************************************************************/
-
-int parse_stringfile_line(const char **ppname, const char **ppvalue)
-{
- char *ptmp;
- char *pname;
- char *pvalue;
-
- pname = g_line;
- ptmp = strchr(g_line, ' ');
- if (ptmp)
- {
- *ptmp++ = '\0';
- pvalue = strchr(ptmp, '"');
- if (pvalue)
- {
- pvalue++;
- ptmp = strchr(pvalue, '"');
- if (ptmp)
- {
- *ptmp = '\0';
- unescape_value(pvalue);
- if (ppname)
- {
- *ppname = pname;
- }
- if (ppvalue)
- {
- *ppvalue = pvalue;
- }
- return 0;
- }
- }
- }
- return 1;
-}
-
-/****************************************************************************
- * Function: open_stringfile
- ****************************************************************************/
-
-FILE *open_stringfile(void)
-{
- FILE *stream = fopen(g_stringfile, "r");
- if (!stream)
- {
- fprintf(stderr, "Failed to open %s for reading: %s\n", g_stringfile, strerror(errno));
- }
- return stream;
-}
-
-/****************************************************************************
- * Function: open_outfile
- ****************************************************************************/
-
-FILE *open_outfile(const char *filename)
-{
- FILE *stream = fopen(filename, "w");
- if (!stream)
- {
- fprintf(stderr, "Failed to open %s for writing: %s\n", filename, strerror(errno));
- }
- return stream;
-}
-
-/****************************************************************************
- * Function: generate_mkdefs
- ****************************************************************************/
-
-int generate_mkdefs(void)
-{
- int ret = 1;
- FILE *stream;
-
- if (( stream = open_stringfile()))
- {
- printf("STRNG_ASRCS =\n");
- printf("STRNG_CSRCS = ");
- ret = 0;
- while (fgets(g_line, 1024, stream) && !ret)
- {
- const char *pname;
- ret = parse_stringfile_line(&pname, NULL);
- if (!ret)
- {
- printf("%s.c ", pname);
- }
- }
- fclose(stream);
- }
- return ret;
-}
-
-/****************************************************************************
- * Function: generate_sourcefiles
- ****************************************************************************/
-
-int generate_sourcefiles(void)
-{
- FILE *instream;
- FILE *hstream;
- FILE *cstream;
- const char *pname;
- const char *pvalue;
- char *filename;
- char buffer[512];
- int len;
- int ndx;
- int ret = 1;
-
- filename = strdup(g_stringfile);
- if (( instream = open_stringfile()))
- {
- snprintf(buffer, 512, "%s.h", basename(filename));
- hstream = open_outfile(buffer);
- if (hstream)
- {
- fprintf(hstream, "#ifndef __NETUTIL_STRINGS\n#define __NETUTIL_STRINGS\n\n");
-
- ret = 0;
- while (fgets(g_line, 1024, instream) && !ret)
- {
- ret = parse_stringfile_line(&pname, &pvalue);
- if (!ret)
- {
- len = strlen(pvalue);
-
- snprintf(buffer, 512, "%s.c", pname);
- cstream = open_outfile(buffer);
- if (cstream)
- {
- fprintf(cstream, "const char %s[%d] = {", pname, len);
- for (ndx = 0; ndx < len; ndx++)
- {
- if (ndx > 0)
- {
- fprintf(cstream, ", ");
- }
- fprintf(cstream, "0x%02x", pvalue[ndx]);
- }
- fprintf(cstream, "};\n");
- fclose(cstream);
- }
- fprintf(hstream, "extern const char %s[%d];\n", pname, len);
- }
- }
- fprintf(hstream, "\n#endif /* __NETUTIL_STRINGS */\n");
- fclose(hstream);
- }
- fclose(instream);
- }
- free(filename);
- return ret;
-}
-
-/****************************************************************************
- * Function: show_usage
- ****************************************************************************/
-
-static void show_usage( void )
-{
- fprintf(stderr, "USAGE: %s [OPTIONS] <string-file>\n\n", g_progname );
- fprintf(stderr, "Where [OPTIONS] include:\n");
- fprintf(stderr, "\t-s: Output string source file list on stdout");
- exit(1);
-}
-
-/****************************************************************************
- * Function: show_usage
- ****************************************************************************/
-
-static void parse_commandline( int argc, char **argv )
-{
- int option;
- g_progname = argv[0];
- while ((option = getopt(argc, argv, ":s")) >= 0)
- {
- switch (option)
- {
- case 's':
- g_action = SRCLIST;
- break;
-
- case ':':
- fprintf(stderr, "Missing command argument\n");
- show_usage();
- break;
-
- case '?':
- option = optopt;
- default:
- fprintf(stderr, "Unrecognized option: %c\n", option);
- show_usage();
- break;
- }
- }
-
- if (optind < argc)
- {
- g_stringfile = argv[optind];
- optind++;
- }
- else
- {
- fprintf(stderr, "Missing <string-file> path\n");
- show_usage();
- }
-
- if (optind < argc)
- {
- fprintf(stderr, "Garbage on command line after <string-file>\n");
- show_usage();
- }
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Function: main
- ****************************************************************************/
-
-int main(int argc, char **argv, char **envp)
-{
- int ret = 0;
- parse_commandline(argc, argv);
- switch (g_action)
- {
- case GENSRC:
- ret = generate_sourcefiles();
- break;
- case SRCLIST:
- ret = generate_mkdefs();
- break;
- }
- return ret;
-}
-
diff --git a/nuttx/netutils/uiplib/netutil-strings b/nuttx/netutils/uiplib/netutil-strings
deleted file mode 100644
index 56b89c8f0..000000000
--- a/nuttx/netutils/uiplib/netutil-strings
+++ /dev/null
@@ -1,46 +0,0 @@
-http_10 "HTTP/1.0"
-http_11 "HTTP/1.1"
-http_200 "200 "
-http_301 "301 "
-http_302 "302 "
-http_404_html "/404.html"
-http_content_type "content-type: "
-http_content_type_binary "Content-type: application/octet-stream\r\n\r\n"
-http_content_type_css "Content-type: text/css\r\n\r\n"
-http_content_type_gif "Content-type: image/gif\r\n\r\n"
-http_content_type_html "Content-type: text/html\r\n\r\n"
-http_content_type_jpg "Content-type: image/jpeg\r\n\r\n"
-http_content_type_plain "Content-type: text/plain\r\n\r\n"
-http_content_type_png "Content-type: image/png\r\n\r\n"
-http_content_type_text "Content-type: text/text\r\n\r\n"
-http_crnl "\r\n"
-http_css ".css"
-http_get "GET "
-http_gif ".gif"
-http_header_200 "HTTP/1.0 200 OK\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n"
-http_header_404 "HTTP/1.0 404 Not found\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n"
-http_host "host: "
-http_htm ".htm"
-http_html ".html"
-http_http "http://"
-http_index_html "/index.html"
-http_jpg ".jpg"
-http_location "location: "
-http_png ".png"
-http_referer "Referer:"
-http_shtml ".shtml"
-http_text ".text"
-http_texthtml "text/html"
-http_txt ".txt"
-http_user_agent_fields "Connection: close\r\nUser-Agent: uIP/1.0 (; http://www.sics.se/~adam/uip/)\r\n\r\n"
-smtp_220 "220"
-smtp_crnl "\r\n"
-smtp_crnlperiodcrnl "\r\n.\r\n"http_http "http://"
-smtp_data "DATA\r\n"
-smtp_from "From: "
-smtp_helo "HELO "
-smtp_mail_from "MAIL FROM: "
-smtp_quit "QUIT\r\n"
-smtp_rcpt_to "RCPT TO: "
-smtp_subject "Subject: "
-smtp_to "To: "
diff --git a/nuttx/netutils/webclient/webclient.c b/nuttx/netutils/webclient/webclient.c
index 929bd6d1e..8b5c66001 100644
--- a/nuttx/netutils/webclient/webclient.c
+++ b/nuttx/netutils/webclient/webclient.c
@@ -61,6 +61,10 @@
#include "webclient.h"
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
#define WEBCLIENT_TIMEOUT 100
#define WEBCLIENT_STATE_STATUSLINE 0
@@ -78,104 +82,52 @@
#define ISO_cr 0x0d
#define ISO_space 0x20
-static uint8 g_return; /* Kludge for now */
-
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+static uint8 g_return; /* Kludge for now */
static struct webclient_state s;
-char *webclient_mimetype(void)
-{
- return s.mimetype;
-}
+static const char g_http10[] = "HTTP/1.0";
+static const char g_http11[] = "HTTP/1.1";
+static const char g_httpcontenttype[] = "content-type: ";
+static const char g_httphost[] = "host: ";
+static const char g_httplocation[] = "location: ";
-char *webclient_filename(void)
-{
- return s.file;
-}
+static const char g_httpget[] = "GET ";
+static const char g_httphttp[] = "http://";
-char *webclient_hostname(void)
-{
- return s.host;
-}
+static const char g_httpuseragentfields[] =
+ "Connection: close\r\n"
+ "User-Agent: uIP/1.0 (; http://www.sics.se/~adam/uip/)\r\n\r\n";
-unsigned shortwebclient_port(void)
-{
- return s.port;
-}
+static const char g_http200[] = "200 ";
+static const char g_http301[] = "301 ";
+static const char g_http302[] = "302 ";
-void webclient_init(void)
-{
-}
+static const char g_httpcrnl[] = "\r\n";
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
static void init_connection(void)
{
s.state = WEBCLIENT_STATE_STATUSLINE;
- s.getrequestleft = sizeof(http_get) - 1 + 1 +
- sizeof(http_10) - 1 +
- sizeof(http_crnl) - 1 +
- sizeof(http_host) - 1 +
- sizeof(http_crnl) - 1 +
- strlen(http_user_agent_fields) +
+ s.getrequestleft = strlen(g_httpget) - 1 + 1 +
+ strlen(g_http10) - 1 +
+ strlen(g_httpcrnl) - 1 +
+ strlen(g_httphost) - 1 +
+ strlen(g_httpcrnl) - 1 +
+ strlen(g_httpuseragentfields) +
strlen(s.file) + strlen(s.host);
s.getrequestptr = 0;
s.httpheaderlineptr = 0;
}
-void webclient_close(void)
-{
- s.state = WEBCLIENT_STATE_CLOSE;
-}
-
-unsigned char webclient_get(const char *host, uint16 port, char *file)
-{
- uip_ipaddr_t *ipaddr;
- static uip_ipaddr_t addr;
- struct sockaddr_in server;
- int sockfd;
-
- /* First check if the host is an IP address. */
-
- ipaddr = &addr;
- if (uiplib_ipaddrconv(host, (unsigned char *)addr) == 0)
- {
- if (resolv_query(host, &ipaddr) < 0)
- {
- return ERROR;
- }
- }
-
- /* Create a socket */
-
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0)
- {
- return ERROR;
- }
-
- /* Connect to server. First we have to set some fields in the
- * 'server' structure. The system will assign me an arbitrary
- * local port that is not in use.
- */
-
- server.sin_family = AF_INET;
- memcpy(&server.sin_addr.s_addr, &host, sizeof(in_addr_t));
- server.sin_port = htons(port);
-
- if (connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0)
- {
- return ERROR;
- }
-
- s.port = port;
- strncpy(s.file, file, sizeof(s.file));
- strncpy(s.host, host, sizeof(s.host));
-
- init_connection();
- return OK;
-}
-
static char *copy_string(char *dest, const char *src, int len)
{
strncpy(dest, src, len);
@@ -191,19 +143,19 @@ static void senddata(struct uip_driver_s *dev, struct uip_conn *conn)
if (s.getrequestleft > 0) {
cptr = getrequest = (char *)dev->d_appdata;
- cptr = copy_string(cptr, http_get, sizeof(http_get) - 1);
+ cptr = copy_string(cptr, g_httpget, strlen(g_httpget) - 1);
cptr = copy_string(cptr, s.file, strlen(s.file));
*cptr++ = ISO_space;
- cptr = copy_string(cptr, http_10, sizeof(http_10) - 1);
+ cptr = copy_string(cptr, g_http10, strlen(g_http10) - 1);
- cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1);
+ cptr = copy_string(cptr, g_httpcrnl, strlen(g_httpcrnl) - 1);
- cptr = copy_string(cptr, http_host, sizeof(http_host) - 1);
+ cptr = copy_string(cptr, g_httphost, strlen(g_httphost) - 1);
cptr = copy_string(cptr, s.host, strlen(s.host));
- cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1);
+ cptr = copy_string(cptr, g_httpcrnl, strlen(g_httpcrnl) - 1);
- cptr = copy_string(cptr, http_user_agent_fields,
- strlen(http_user_agent_fields));
+ cptr = copy_string(cptr, g_httpuseragentfields,
+ strlen(g_httpuseragentfields));
len = s.getrequestleft > uip_mss(conn)?
uip_mss(conn):
@@ -238,18 +190,18 @@ static uint16 parse_statusline(struct uip_driver_s *dev, uint16 len)
if (s.httpheaderline[s.httpheaderlineptr] == ISO_nl)
{
- if ((strncmp(s.httpheaderline, http_10, sizeof(http_10) - 1) == 0) ||
- (strncmp(s.httpheaderline, http_11, sizeof(http_11) - 1) == 0))
+ if ((strncmp(s.httpheaderline, g_http10, strlen(g_http10) - 1) == 0) ||
+ (strncmp(s.httpheaderline, g_http11, strlen(g_http11) - 1) == 0))
{
cptr = &(s.httpheaderline[9]);
s.httpflag = HTTPFLAG_NONE;
- if (strncmp(cptr, http_200, sizeof(http_200) - 1) == 0)
+ if (strncmp(cptr, g_http200, strlen(g_http200) - 1) == 0)
{
/* 200 OK */
s.httpflag = HTTPFLAG_OK;
}
- else if (strncmp(cptr, http_301, sizeof(http_301) - 1) == 0 ||
- strncmp(cptr, http_302, sizeof(http_302) - 1) == 0)
+ else if (strncmp(cptr, g_http301, strlen(g_http301) - 1) == 0 ||
+ strncmp(cptr, g_http302, strlen(g_http302) - 1) == 0)
{
/* 301 Moved permanently or 302 Found. Location: header line
* will contain thw new location.
@@ -337,7 +289,7 @@ static uint16 parse_headers(struct uip_driver_s *dev, uint16 len)
s.httpheaderline[s.httpheaderlineptr - 1] = 0;
/* Check for specific HTTP header fields. */
- if (casecmp(s.httpheaderline, http_content_type, sizeof(http_content_type) - 1) == 0)
+ if (casecmp(s.httpheaderline, g_httpcontenttype, strlen(g_httpcontenttype) - 1) == 0)
{
/* Found Content-type field. */
cptr = strchr(s.httpheaderline, ';');
@@ -345,13 +297,13 @@ static uint16 parse_headers(struct uip_driver_s *dev, uint16 len)
{
*cptr = 0;
}
- strncpy(s.mimetype, s.httpheaderline + sizeof(http_content_type) - 1, sizeof(s.mimetype));
+ strncpy(s.mimetype, s.httpheaderline + strlen(g_httpcontenttype) - 1, sizeof(s.mimetype));
}
- else if (casecmp(s.httpheaderline, http_location, sizeof(http_location) - 1) == 0)
+ else if (casecmp(s.httpheaderline, g_httplocation, strlen(g_httplocation) - 1) == 0)
{
- cptr = s.httpheaderline + sizeof(http_location) - 1;
+ cptr = s.httpheaderline + strlen(g_httplocation) - 1;
- if (strncmp(cptr, http_http, 7) == 0)
+ if (strncmp(cptr, g_httphttp, strlen(g_httphttp)) == 0)
{
cptr += 7;
for(i = 0; i < s.httpheaderlineptr - 7; ++i)
@@ -485,3 +437,85 @@ uint8 uip_interrupt_event(struct uip_driver_s *dev, struct uip_conn *conn, uint8
}
return g_return;
}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void webclient_init(void)
+{
+}
+
+unsigned char webclient_get(const char *host, uint16 port, char *file)
+{
+ uip_ipaddr_t *ipaddr;
+ static uip_ipaddr_t addr;
+ struct sockaddr_in server;
+ int sockfd;
+
+ /* First check if the host is an IP address. */
+
+ ipaddr = &addr;
+ if (uiplib_ipaddrconv(host, (unsigned char *)addr) == 0)
+ {
+ if (resolv_query(host, &ipaddr) < 0)
+ {
+ return ERROR;
+ }
+ }
+
+ /* Create a socket */
+
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ {
+ return ERROR;
+ }
+
+ /* Connect to server. First we have to set some fields in the
+ * 'server' structure. The system will assign me an arbitrary
+ * local port that is not in use.
+ */
+
+ server.sin_family = AF_INET;
+ memcpy(&server.sin_addr.s_addr, &host, sizeof(in_addr_t));
+ server.sin_port = htons(port);
+
+ if (connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0)
+ {
+ return ERROR;
+ }
+
+ s.port = port;
+ strncpy(s.file, file, sizeof(s.file));
+ strncpy(s.host, host, sizeof(s.host));
+
+ init_connection();
+ return OK;
+}
+
+void webclient_close(void)
+{
+ s.state = WEBCLIENT_STATE_CLOSE;
+}
+
+char *webclient_mimetype(void)
+{
+ return s.mimetype;
+}
+
+char *webclient_filename(void)
+{
+ return s.file;
+}
+
+char *webclient_hostname(void)
+{
+ return s.host;
+}
+
+unsigned shortwebclient_port(void)
+{
+ return s.port;
+}
+
diff --git a/nuttx/netutils/webclient/webclient.h b/nuttx/netutils/webclient/webclient.h
index 8f7a8644f..80a571377 100644
--- a/nuttx/netutils/webclient/webclient.h
+++ b/nuttx/netutils/webclient/webclient.h
@@ -38,8 +38,6 @@
#include <sys/types.h>
#include <net/uip/uipopt.h>
-#include "netutil-strings.h"
-
#define WEBCLIENT_CONF_MAX_URLLEN 100
struct webclient_state