From 15fb63ba9a2f504041c5c1ee2e13c9fac029c81c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 18 Feb 2013 23:08:05 +0100 Subject: [PATCH 1/6] Harmonized ststus texts and and added status on wrong MIME type. --- apps/webbrowser/www.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/webbrowser/www.c b/apps/webbrowser/www.c index 279f882bc..1b8b27ea3 100644 --- a/apps/webbrowser/www.c +++ b/apps/webbrowser/www.c @@ -325,7 +325,7 @@ open_url(void) /* The hostname we present in the hostname table, so we send out the initial GET request. */ if(webclient_get(host, 80, file) == 0) { - show_statustext("Out of memory error."); + show_statustext("Out of memory error"); } else { show_statustext("Connecting..."); } @@ -534,7 +534,7 @@ PROCESS_THREAD(www_process, ev, data) resolv_lookup((char *)data) != NULL) { open_url(); } else { - show_statustext("Host not found."); + show_statustext("Host not found"); } #endif /* UIP_UDP */ } else if(ev == ctk_signal_window_close || @@ -602,7 +602,7 @@ webclient_timedout(void) void webclient_closed(void) { - show_statustext("Stopped."); + show_statustext("Stopped"); petsciiconv_topetscii(webpageptr - x, x); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); redraw_window(); @@ -644,6 +644,7 @@ webclient_datahandler(char *data, uint16_t len) htmlparser_parse(data, len); redraw_window(); } else { + show_statustext("Cannot display web page"); uip_abort(); #if WWW_CONF_WITH_WGET ctk_dialog_open(&wgetdialog); @@ -656,7 +657,7 @@ webclient_datahandler(char *data, uint16_t len) if(data == NULL) { loading = 0; - show_statustext("Done."); + show_statustext("Done"); petsciiconv_topetscii(webpageptr - x, x); CTK_WIDGET_FOCUS(&mainwindow, &urlentry); redraw_window(); From 4938877dd9fc87c16b04248000cf1d6bb70b3446 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 00:25:36 +0100 Subject: [PATCH 2/6] Lifted restrictions on accepted MIME type. The "normal" web is moving forward quickly reducing the interoperability of the Contiki web browser to nearly zero. The Mobile Web fits the capabilities of the Contiki web browser much better. Modern smartphones don't need the Mobile Web anymore but there are large areas in world with rather low end mobile phones and limited mobile bandwidth where the Mobile Web will be necessary for quite some time. From that perspective it is reasonable to increase the Contiki web browser's interoperability with the Mobie Web - namely WAP 2.0 aka XHTML MP. XHTML MP is delivered as MIME types 'application/vnd.wap.xhtml+xml' or 'application/xhtml+xml'. Therefore we (try to) parse the document if the MIME type contains the substring 'html' (which is true 'text/html' too). --- apps/webbrowser/http-strings | 3 +-- apps/webbrowser/http-strings.c | 7 ++----- apps/webbrowser/http-strings.h | 1 - apps/webbrowser/www.c | 2 +- apps/webserver/http-strings | 3 +-- apps/webserver/http-strings.c | 7 ++----- apps/webserver/http-strings.h | 1 - 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/apps/webbrowser/http-strings b/apps/webbrowser/http-strings index ea5ebc1e0..2bba32dc8 100644 --- a/apps/webbrowser/http-strings +++ b/apps/webbrowser/http-strings @@ -6,9 +6,8 @@ http_get "GET " http_10 "HTTP/1.0" http_11 "HTTP/1.1" http_content_type "content-type: " -http_texthtml "text/html" http_location "location: " -http_host "host: " +http_host "Host: " http_crnl "\r\n" http_index_html "/index.html" http_404_html "/404.html" diff --git a/apps/webbrowser/http-strings.c b/apps/webbrowser/http-strings.c index 968a71851..3407105c3 100644 --- a/apps/webbrowser/http-strings.c +++ b/apps/webbrowser/http-strings.c @@ -22,15 +22,12 @@ const char http_11[9] = const char http_content_type[15] = /* "content-type: " */ {0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, }; -const char http_texthtml[10] = -/* "text/html" */ -{0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, }; const char http_location[11] = /* "location: " */ {0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, }; const char http_host[7] = -/* "host: " */ -{0x68, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; +/* "Host: " */ +{0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; const char http_crnl[3] = /* "\r\n" */ {0xd, 0xa, }; diff --git a/apps/webbrowser/http-strings.h b/apps/webbrowser/http-strings.h index f197bba2b..5c2cf9396 100644 --- a/apps/webbrowser/http-strings.h +++ b/apps/webbrowser/http-strings.h @@ -6,7 +6,6 @@ extern const char http_get[5]; extern const char http_10[9]; extern const char http_11[9]; extern const char http_content_type[15]; -extern const char http_texthtml[10]; extern const char http_location[11]; extern const char http_host[7]; extern const char http_crnl[3]; diff --git a/apps/webbrowser/www.c b/apps/webbrowser/www.c index 1b8b27ea3..06726e90a 100644 --- a/apps/webbrowser/www.c +++ b/apps/webbrowser/www.c @@ -638,7 +638,7 @@ void webclient_datahandler(char *data, uint16_t len) { if(len > 0) { - if(strcmp(webclient_mimetype(), http_texthtml) == 0) { + if(strstr(webclient_mimetype(), http_html + 1) != 0) { count = (count + 1) & 3; show_statustext(receivingmsgs[count]); htmlparser_parse(data, len); diff --git a/apps/webserver/http-strings b/apps/webserver/http-strings index 579faee74..7a3d51c03 100644 --- a/apps/webserver/http-strings +++ b/apps/webserver/http-strings @@ -6,9 +6,8 @@ http_get "GET " http_10 "HTTP/1.0" http_11 "HTTP/1.1" http_content_type "content-type: " -http_texthtml "text/html" http_location "location: " -http_host "host: " +http_host "Host: " http_crnl "\r\n" http_index_htm "/index.htm" http_index_html "/index.html" diff --git a/apps/webserver/http-strings.c b/apps/webserver/http-strings.c index 4e22787ea..5c02fedef 100644 --- a/apps/webserver/http-strings.c +++ b/apps/webserver/http-strings.c @@ -22,15 +22,12 @@ const char http_11[9] = const char http_content_type[15] = /* "content-type: " */ {0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, }; -const char http_texthtml[10] = -/* "text/html" */ -{0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, }; const char http_location[11] = /* "location: " */ {0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, }; const char http_host[7] = -/* "host: " */ -{0x68, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; +/* "Host: " */ +{0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, }; const char http_crnl[3] = /* "\r\n" */ {0xd, 0xa, }; diff --git a/apps/webserver/http-strings.h b/apps/webserver/http-strings.h index 35af562d4..01fc8cd9d 100644 --- a/apps/webserver/http-strings.h +++ b/apps/webserver/http-strings.h @@ -6,7 +6,6 @@ extern const char http_get[5]; extern const char http_10[9]; extern const char http_11[9]; extern const char http_content_type[15]; -extern const char http_texthtml[10]; extern const char http_location[11]; extern const char http_host[7]; extern const char http_crnl[3]; From 374c89be0194109edc5a081f5651d15d34838621 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 00:43:16 +0100 Subject: [PATCH 3/6] Added newline on . The tag
(in contrast to the tag ) is normally used to denote content placed on a line by its own. So it makes sense to trigger a newline when
is processed. --- apps/webbrowser/html-strings | 1 + apps/webbrowser/html-strings.c | 3 ++ apps/webbrowser/html-strings.h | 1 + apps/webbrowser/htmlparser.c | 51 ++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/apps/webbrowser/html-strings b/apps/webbrowser/html-strings index e3c43c93b..5e10d41d4 100644 --- a/apps/webbrowser/html-strings +++ b/apps/webbrowser/html-strings @@ -1,5 +1,6 @@ html_slasha "/a\0" html_slashcenter "/center\0" +html_slashdiv "/div\0" html_slashform "/form\0" html_slashh "/h\0" html_slashscript "/script\0" diff --git a/apps/webbrowser/html-strings.c b/apps/webbrowser/html-strings.c index 6292280e6..cb4b05629 100644 --- a/apps/webbrowser/html-strings.c +++ b/apps/webbrowser/html-strings.c @@ -4,6 +4,9 @@ const char html_slasha[4] = const char html_slashcenter[9] = /* "/center\0" */ {0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 00, }; +const char html_slashdiv[6] = +/* "/div\0" */ +{0x2f, 0x64, 0x69, 0x76, 00, }; const char html_slashform[7] = /* "/form\0" */ {0x2f, 0x66, 0x6f, 0x72, 0x6d, 00, }; diff --git a/apps/webbrowser/html-strings.h b/apps/webbrowser/html-strings.h index 21c6c129d..b10a78c59 100644 --- a/apps/webbrowser/html-strings.h +++ b/apps/webbrowser/html-strings.h @@ -1,5 +1,6 @@ extern const char html_slasha[4]; extern const char html_slashcenter[9]; +extern const char html_slashdiv[6]; extern const char html_slashform[7]; extern const char html_slashh[4]; extern const char html_slashscript[9]; diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index c33640191..20d74deeb 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -179,53 +179,55 @@ static const char *tags[] = { html_slasha, #define TAG_SLASHCENTER 1 html_slashcenter, -#define TAG_SLASHFORM 2 +#define TAG_SLASHDIV 2 + html_slashdiv, +#define TAG_SLASHFORM 3 html_slashform, -#define TAG_SLASHH 3 +#define TAG_SLASHH 4 html_slashh, -#define TAG_SLASHSCRIPT 4 +#define TAG_SLASHSCRIPT 5 html_slashscript, -#define TAG_SLASHSELECT 5 +#define TAG_SLASHSELECT 6 html_slashselect, -#define TAG_SLASHSTYLE 6 +#define TAG_SLASHSTYLE 7 html_slashstyle, -#define TAG_A 7 +#define TAG_A 8 html_a, -#define TAG_BODY 8 +#define TAG_BODY 9 html_body, -#define TAG_BR 9 +#define TAG_BR 10 html_br, -#define TAG_CENTER 10 +#define TAG_CENTER 11 html_center, -#define TAG_FORM 11 +#define TAG_FORM 12 html_form, -#define TAG_FRAME 12 +#define TAG_FRAME 13 html_frame, -#define TAG_H1 13 +#define TAG_H1 14 html_h1, -#define TAG_H2 14 +#define TAG_H2 15 html_h2, -#define TAG_H3 15 +#define TAG_H3 16 html_h3, -#define TAG_H4 16 +#define TAG_H4 17 html_h4, -#define TAG_IMG 17 +#define TAG_IMG 18 html_img, -#define TAG_INPUT 18 +#define TAG_INPUT 19 html_input, -#define TAG_LI 19 +#define TAG_LI 20 html_li, -#define TAG_P 20 +#define TAG_P 21 html_p, -#define TAG_SCRIPT 21 +#define TAG_SCRIPT 22 html_script, -#define TAG_SELECT 22 +#define TAG_SELECT 23 html_select, -#define TAG_STYLE 23 +#define TAG_STYLE 24 html_style, -#define TAG_TR 24 +#define TAG_TR 25 html_tr, -#define TAG_LAST 25 +#define TAG_LAST 26 last, }; @@ -376,6 +378,7 @@ parse_tag(void) /* FALLTHROUGH */ case TAG_BR: case TAG_TR: + case TAG_SLASHDIV: case TAG_SLASHH: /* parse_char(ISO_nl);*/ dummy = 0; From d5d646528e30f64901b9a0797228f5f30d046add Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 00:49:01 +0100 Subject: [PATCH 4/6] Added support for self closing tags. XHTML requires self closing tags to be used for empty tags, so we need to recognize them. --- apps/webbrowser/htmlparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index 20d74deeb..dc0914cb6 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -327,7 +327,7 @@ find_tag(char *tag) do { tagc = tag[i]; - if(tagc == 0 && + if((tagc == 0 || tagc == ISO_slash) && tags[first][i] == 0) { return first; } From d71ce70c540653d928234e45a121ae9940af6784 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 19 Feb 2013 21:40:21 +0100 Subject: [PATCH 5/6] Made sure that HTML form values get initialized properly. --- apps/webbrowser/htmlparser.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/webbrowser/htmlparser.c b/apps/webbrowser/htmlparser.c index dc0914cb6..79e2724c6 100644 --- a/apps/webbrowser/htmlparser.c +++ b/apps/webbrowser/htmlparser.c @@ -241,12 +241,25 @@ iswhitespace(char c) c == ISO_ht); } /*-----------------------------------------------------------------------------------*/ +#if WWW_CONF_FORMS +static void +init_input(void) +{ + s.inputtype = HTMLPARSER_INPUTTYPE_NONE; + s.inputname[0] = s.inputvalue[0] = 0; + s.inputvaluesize = 20; /* De facto default size */ +} +#endif /* WWW_CONF_FORMS */ +/*-----------------------------------------------------------------------------------*/ void htmlparser_init(void) { s.majorstate = s.lastmajorstate = MAJORSTATE_DISCARD; s.minorstate = MINORSTATE_TEXT; s.lastchar = 0; +#if WWW_CONF_FORMS + s.formaction[0] = s.formname[0] = 0; +#endif /* WWW_CONF_FORMS */ } /*-----------------------------------------------------------------------------------*/ static char CC_FASTCALL @@ -460,7 +473,7 @@ parse_tag(void) PRINTF(("Form name '%s'\n", s.tagattrparam)); strncpy(s.formname, s.tagattrparam, WWW_CONF_MAX_FORMNAMELEN - 1); } - s.inputname[0] = s.inputvalue[0] = 0; + init_input(); break; case TAG_SLASHFORM: switch_majorstate(MAJORSTATE_BODY); @@ -486,7 +499,7 @@ parse_tag(void) s.formname, s.formaction); break; } - s.inputtype = HTMLPARSER_INPUTTYPE_NONE; + init_input(); } else { PRINTF(("Input '%s' '%s'\n", s.tagattr, s.tagattrparam)); if(strncmp(s.tagattr, html_type, sizeof(html_type)) == 0) { From 4d4b796abbf83c771a836dc8d85df51d7733ceaa Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 6 Mar 2013 14:32:36 +0100 Subject: [PATCH 6/6] Removed useless register keywords. Modern compilers (especially GCC) ignore the register keyword anyway and the latest cc65 snapshot generates actually larger code with the register keyword at the locations in question. --- core/net/tcpip.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/net/tcpip.c b/core/net/tcpip.c index 4b178a1db..fc6db0ad2 100644 --- a/core/net/tcpip.c +++ b/core/net/tcpip.c @@ -284,7 +284,7 @@ void tcp_attach(struct uip_conn *conn, void *appstate) { - register uip_tcp_appstate_t *s; + uip_tcp_appstate_t *s; s = &conn->appstate; s->p = PROCESS_CURRENT(); @@ -298,7 +298,7 @@ void udp_attach(struct uip_udp_conn *conn, void *appstate) { - register uip_udp_appstate_t *s; + uip_udp_appstate_t *s; s = &conn->appstate; s->p = PROCESS_CURRENT(); @@ -394,7 +394,7 @@ eventhandler(process_event_t ev, process_data_t data) } { - register struct uip_conn *cptr; + struct uip_conn *cptr; for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) { if(cptr->appstate.p == p) { @@ -406,7 +406,7 @@ eventhandler(process_event_t ev, process_data_t data) #endif /* UIP_TCP */ #if UIP_UDP { - register struct uip_udp_conn *cptr; + struct uip_udp_conn *cptr; for(cptr = &uip_udp_conns[0]; cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) { @@ -697,7 +697,7 @@ tcpip_poll_tcp(struct uip_conn *conn) void tcpip_uipcall(void) { - register uip_udp_appstate_t *ts; + uip_udp_appstate_t *ts; #if UIP_UDP if(uip_conn != NULL) { @@ -712,7 +712,7 @@ tcpip_uipcall(void) #if UIP_TCP { static unsigned char i; - register struct listenport *l; + struct listenport *l; /* If this is a connection request for a listening port, we must mark the connection with the right process ID. */