2 * Copyright (c) 2002, Adam Dunkels.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * This file is part of the Contiki desktop environment
32 * $Id: www.c,v 1.14 2010/07/21 21:03:06 oliverschmidt Exp $
39 #include "lib/ctk-textentry-cmdline.h"
40 #include "contiki-net.h"
41 #include "lib/petsciiconv.h"
43 #if WWW_CONF_WITH_WGET
44 #include "program-handler.h"
45 #endif /* WWW_CONF_WITH_WGET */
47 #include "webclient.h"
48 #include "htmlparser.h"
49 #include "http-strings.h"
57 #define PRINTF(x) printf x
61 /* The array that holds the current URL. */
62 static char url
[WWW_CONF_MAX_URLLEN
+ 1];
63 static char tmpurl
[WWW_CONF_MAX_URLLEN
+ 1];
65 /* The array that holds the web page text. */
66 static char webpage
[WWW_CONF_WEBPAGE_WIDTH
*
67 WWW_CONF_WEBPAGE_HEIGHT
+ 1];
70 /* The CTK widgets for the main window. */
71 static struct ctk_window mainwindow
;
73 #if WWW_CONF_HISTORY_SIZE > 0
74 static struct ctk_button backbutton
=
75 {CTK_BUTTON(0, 0, 4, "Back")};
76 static struct ctk_button downbutton
=
77 {CTK_BUTTON(10, 0, 4, "Down")};
78 #else /* WWW_CONF_HISTORY_SIZE > 0 */
79 static struct ctk_button downbutton
=
80 {CTK_BUTTON(0, 0, 4, "Down")};
81 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
82 static struct ctk_button stopbutton
=
83 {CTK_BUTTON(WWW_CONF_WEBPAGE_WIDTH
- 16, 0, 4, "Stop")};
84 static struct ctk_button gobutton
=
85 {CTK_BUTTON(WWW_CONF_WEBPAGE_WIDTH
- 4, 0, 2, "Go")};
87 static struct ctk_separator sep1
=
88 {CTK_SEPARATOR(0, 2, WWW_CONF_WEBPAGE_WIDTH
)};
90 static char editurl
[WWW_CONF_MAX_URLLEN
+ 1];
91 static struct ctk_textentry urlentry
=
92 {CTK_TEXTENTRY(0, 1, WWW_CONF_WEBPAGE_WIDTH
- 2,
93 1, editurl
, WWW_CONF_MAX_URLLEN
)};
94 static struct ctk_label webpagelabel
=
95 {CTK_LABEL(0, 3, WWW_CONF_WEBPAGE_WIDTH
,
96 WWW_CONF_WEBPAGE_HEIGHT
, webpage
)};
98 static char statustexturl
[WWW_CONF_WEBPAGE_WIDTH
];
99 static struct ctk_label statustext
=
100 {CTK_LABEL(0, WWW_CONF_WEBPAGE_HEIGHT
+ 4,
101 WWW_CONF_WEBPAGE_WIDTH
, 1, "")};
102 static struct ctk_separator sep2
=
103 {CTK_SEPARATOR(0, WWW_CONF_WEBPAGE_HEIGHT
+ 3,
104 WWW_CONF_WEBPAGE_WIDTH
)};
106 #if WWW_CONF_WITH_WGET
107 static struct ctk_window wgetdialog
;
108 static struct ctk_label wgetlabel1
=
109 {CTK_LABEL(1, 1, 34, 1, "This web page cannot be displayed.")};
110 static struct ctk_label wgetlabel2
=
111 {CTK_LABEL(1, 3, 35, 1, "Would you like to download instead?")};
112 static struct ctk_button wgetnobutton
=
113 {CTK_BUTTON(1, 5, 6, "Cancel")};
114 static struct ctk_button wgetyesbutton
=
115 {CTK_BUTTON(11, 5, 24, "Close browser & download")};
116 #endif /* WWW_CONF_WITH_WGET */
118 #if WWW_CONF_HISTORY_SIZE > 0
119 /* The char arrays that hold the history of visited URLs. */
120 static char history
[WWW_CONF_HISTORY_SIZE
][WWW_CONF_MAX_URLLEN
];
121 static char history_last
;
122 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
124 /* The CTK widget definitions for the hyperlinks and the char arrays
125 that hold the link URLs. */
127 char formaction
[WWW_CONF_MAX_FORMACTIONLEN
];
128 char formname
[WWW_CONF_MAX_FORMNAMELEN
];
129 #define FORMINPUTTYPE_SUBMITBUTTON 1
130 #define FORMINPUTTYPE_INPUTFIELD 2
131 unsigned char inputtype
;
132 char inputname
[WWW_CONF_MAX_INPUTNAMELEN
];
136 union pagewidgetattrib
{
137 char url
[WWW_CONF_MAX_URLLEN
];
139 struct formattribs form
;
140 #endif /* WWW_CONF_FORMS */
142 static struct ctk_widget pagewidgets
[WWW_CONF_MAX_NUMPAGEWIDGETS
];
143 static union pagewidgetattrib pagewidgetattribs
[WWW_CONF_MAX_NUMPAGEWIDGETS
];
144 static unsigned char pagewidgetptr
;
146 #if WWW_CONF_RENDERSTATE
147 static unsigned char renderstate
;
148 #endif /* WWW_CONF_RENDERSTATE */
151 #define ISO_space 0x20
152 #define ISO_ampersand 0x26
153 #define ISO_plus 0x2b
154 #define ISO_slash 0x2f
156 #define ISO_questionmark 0x3f
158 /* The state of the rendering code. */
159 static char *webpageptr
;
160 static unsigned char x
, y
;
161 static unsigned char loading
;
162 static unsigned short firsty
, pagey
;
164 static unsigned char count
;
165 static char receivingmsgs
[4][23] = {
166 "Receiving web page ...",
167 "Receiving web page. ..",
168 "Receiving web page.. .",
169 "Receiving web page... "
172 PROCESS(www_process
, "Web browser");
174 AUTOSTART_PROCESSES(&www_process
);
176 static void formsubmit(struct formattribs
*attribs
);
178 /*-----------------------------------------------------------------------------------*/
181 * Creates the web browser's window.
186 #if WWW_CONF_HISTORY_SIZE > 0
187 CTK_WIDGET_ADD(&mainwindow
, &backbutton
);
188 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
189 CTK_WIDGET_ADD(&mainwindow
, &downbutton
);
190 CTK_WIDGET_ADD(&mainwindow
, &stopbutton
);
191 CTK_WIDGET_ADD(&mainwindow
, &gobutton
);
192 CTK_WIDGET_ADD(&mainwindow
, &urlentry
);
193 CTK_WIDGET_ADD(&mainwindow
, &sep1
);
194 CTK_WIDGET_ADD(&mainwindow
, &webpagelabel
);
195 CTK_WIDGET_SET_FLAG(&webpagelabel
, CTK_WIDGET_FLAG_MONOSPACE
);
196 CTK_WIDGET_ADD(&mainwindow
, &sep2
);
197 CTK_WIDGET_ADD(&mainwindow
, &statustext
);
201 /*-----------------------------------------------------------------------------------*/
204 * Convenience function that calls upon CTK to redraw the browser
209 ctk_window_redraw(&mainwindow
);
211 /*-----------------------------------------------------------------------------------*/
215 ctk_window_clear(&mainwindow
);
218 memset(webpage
, 0, WWW_CONF_WEBPAGE_WIDTH
* WWW_CONF_WEBPAGE_HEIGHT
);
220 /*-----------------------------------------------------------------------------------*/
224 memcpy(editurl
, url
, WWW_CONF_MAX_URLLEN
);
225 strncpy(editurl
, "http://", 7);
226 petsciiconv_topetscii(editurl
+ 7, WWW_CONF_MAX_URLLEN
- 7);
227 CTK_WIDGET_REDRAW(&urlentry
);
229 /*-----------------------------------------------------------------------------------*/
236 webpageptr
= webpage
;
240 /*-----------------------------------------------------------------------------------*/
242 show_statustext(char *text
)
244 ctk_label_set_text(&statustext
, text
);
245 CTK_WIDGET_REDRAW(&statustext
);
247 /*-----------------------------------------------------------------------------------*/
250 * Called when the URL present in the global "url" variable should be
251 * opened. It will call the hostname resolver as well as the HTTP
258 static char host
[32];
260 register char *urlptr
;
261 static uip_ipaddr_t addr
;
263 /* Trim off any spaces in the end of the url. */
264 urlptr
= url
+ strlen(url
) - 1;
265 while(*urlptr
== ' ' && urlptr
> url
) {
270 /* Don't even try to go further if the URL is empty. */
275 /* See if the URL starts with http://, otherwise prepend it. */
276 if(strncmp(url
, http_http
, 7) != 0) {
277 while(urlptr
>= url
) {
278 *(urlptr
+ 7) = *urlptr
;
281 strncpy(url
, http_http
, 7);
284 /* Find host part of the URL. */
286 for(i
= 0; i
< sizeof(host
); ++i
) {
298 /* XXX: Here we should find the port part of the URL, but this isn't
299 currently done because of laziness from the programmer's side
302 /* Find file part of the URL. */
303 while(*urlptr
!= '/' && *urlptr
!= 0) {
313 /* Try to lookup the hostname. If it fails, we initiate a hostname
314 lookup and print out an informative message on the statusbar. */
315 if(uiplib_ipaddrconv(host
, &addr
) == 0) {
316 if(resolv_lookup(host
) == NULL
) {
318 show_statustext("Resolving host...");
323 uiplib_ipaddrconv(host
, &addr
);
326 /* The hostname we present in the hostname table, so we send out the
327 initial GET request. */
328 if(webclient_get(host
, 80, file
) == 0) {
329 show_statustext("Out of memory error.");
331 show_statustext("Connecting...");
335 /*-----------------------------------------------------------------------------------*/
338 * Will format a link from the current web pages so that it suits the
339 * open_url() function and finally call it to open the requested URL.
342 open_link(char *link
)
346 if(strncmp(link
, http_http
, 7) == 0) {
347 /* The link starts with http://. We just copy the contents of the
348 link into the url string and jump away. */
349 strncpy(url
, link
, WWW_CONF_MAX_URLLEN
);
350 } else if(*link
== ISO_slash
&&
351 *(link
+ 1) == ISO_slash
) {
352 /* The link starts with //, so we'll copy it into the url
353 variable, starting after the http (which already is present in
354 the url variable since we were able to open the web page on
355 which this link was found in the first place). */
356 strncpy(&url
[5], link
, WWW_CONF_MAX_URLLEN
);
357 } else if(*link
== ISO_slash
) {
358 /* The link starts with a slash, so it is a non-relative link
359 within the same web site. We find the start of the filename of
360 the current URL and paste the contents of this link there, and
361 head off to the new URL. */
362 for(urlptr
= &url
[7];
363 *urlptr
!= 0 && *urlptr
!= ISO_slash
;
365 strncpy(urlptr
, link
, WWW_CONF_MAX_URLLEN
- (urlptr
- url
));
367 /* A fully relative link is found. We find the last slash in the
368 current URL and paste the link there. */
370 /* XXX: we should really parse any ../ in the link as well. */
371 for(urlptr
= url
+ strlen(url
);
372 urlptr
!= url
&& *urlptr
!= ISO_slash
;
375 strncpy(urlptr
, link
, WWW_CONF_MAX_URLLEN
- (urlptr
- url
));
384 /*-----------------------------------------------------------------------------------*/
385 #if WWW_CONF_HISTORY_SIZE > 0
388 * Copies the current URL from the url variable and into the log for
394 if(strncmp(url
, history
[(int)history_last
], WWW_CONF_MAX_URLLEN
) != 0) {
395 memcpy(history
[(int)history_last
], url
, WWW_CONF_MAX_URLLEN
);
397 if(history_last
>= WWW_CONF_HISTORY_SIZE
) {
402 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
403 /*-----------------------------------------------------------------------------------*/
407 ctk_window_close(&mainwindow
);
408 process_exit(&www_process
);
411 /*-----------------------------------------------------------------------------------*/
414 * The program's signal dispatcher function. Is called whenever a signal arrives.
416 PROCESS_THREAD(www_process
, ev
, data
)
418 static struct ctk_widget
*w
;
419 static unsigned char i
;
420 #if WWW_CONF_WITH_WGET
422 #endif /* WWW_CONF_WITH_WGET */
424 w
= (struct ctk_widget
*)data
;
428 /* Create the main window. */
429 memset(webpage
, 0, sizeof(webpage
));
430 ctk_window_new(&mainwindow
, WWW_CONF_WEBPAGE_WIDTH
,
431 WWW_CONF_WEBPAGE_HEIGHT
+5, "Web browser");
433 #ifdef WWW_CONF_HOMEPAGE
434 strncpy(editurl
, WWW_CONF_HOMEPAGE
, sizeof(editurl
));
435 #endif /* WWW_CONF_HOMEPAGE */
436 CTK_WIDGET_FOCUS(&mainwindow
, &urlentry
);
438 #if WWW_CONF_WITH_WGET
439 /* Create download dialog.*/
440 ctk_dialog_new(&wgetdialog
, 38, 7);
441 CTK_WIDGET_ADD(&wgetdialog
, &wgetlabel1
);
442 CTK_WIDGET_ADD(&wgetdialog
, &wgetlabel2
);
443 CTK_WIDGET_ADD(&wgetdialog
, &wgetnobutton
);
444 CTK_WIDGET_ADD(&wgetdialog
, &wgetyesbutton
);
445 #endif /* WWW_CONF_WITH_WGET */
447 ctk_window_open(&mainwindow
);
451 PROCESS_WAIT_EVENT();
453 if(ev
== tcpip_event
) {
454 webclient_appcall(data
);
455 } else if(ev
== ctk_signal_widget_activate
) {
456 if(w
== (struct ctk_widget
*)&gobutton
||
457 w
== (struct ctk_widget
*)&urlentry
) {
460 #if WWW_CONF_HISTORY_SIZE > 0
462 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
463 memcpy(url
, editurl
, WWW_CONF_MAX_URLLEN
);
464 petsciiconv_toascii(url
, WWW_CONF_MAX_URLLEN
);
466 CTK_WIDGET_FOCUS(&mainwindow
, &gobutton
);
467 #if WWW_CONF_HISTORY_SIZE > 0
468 } else if(w
== (struct ctk_widget
*)&backbutton
) {
472 if(history_last
> WWW_CONF_HISTORY_SIZE
) {
473 history_last
= WWW_CONF_HISTORY_SIZE
- 1;
475 memcpy(url
, history
[(int)history_last
], WWW_CONF_MAX_URLLEN
);
477 CTK_WIDGET_FOCUS(&mainwindow
, &backbutton
);
478 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
479 } else if(w
== (struct ctk_widget
*)&downbutton
) {
480 firsty
= pagey
+ WWW_CONF_WEBPAGE_HEIGHT
- 4;
483 CTK_WIDGET_FOCUS(&mainwindow
, &downbutton
);
484 } else if(w
== (struct ctk_widget
*)&stopbutton
) {
487 #if WWW_CONF_WITH_WGET
488 } else if(w
== (struct ctk_widget
*)&wgetnobutton
) {
490 } else if(w
== (struct ctk_widget
*)&wgetyesbutton
) {
493 argptr
= arg_alloc((char)WWW_CONF_MAX_URLLEN
);
495 strncpy(argptr
, url
, WWW_CONF_MAX_URLLEN
);
497 program_handler_load("wget.prg", argptr
);
498 #endif /* WWW_CONF_WITH_WGET */
501 /* Check form buttons */
502 for(i
= 0; i
< pagewidgetptr
; ++i
) {
503 if(&pagewidgets
[i
] == w
) {
504 formsubmit(&pagewidgetattribs
[i
].form
);
505 /* show_statustext(pagewidgetattribs[i].form.formaction);*/
506 /* PRINTF(("Formaction %s formname %s inputname %s\n",
507 pagewidgetattribs[i].form.formaction,
508 pagewidgetattribs[i].form.formname,
509 pagewidgetattribs[i].form.inputname));*/
513 #endif /* WWW_CONF_FORMS */
515 } else if(ev
== ctk_signal_hyperlink_activate
) {
517 #if WWW_CONF_HISTORY_SIZE > 0
519 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
520 open_link(w
->widget
.hyperlink
.url
);
521 CTK_WIDGET_FOCUS(&mainwindow
, &stopbutton
);
522 /* ctk_window_open(&mainwindow);*/
523 } else if(ev
== ctk_signal_hyperlink_hover
) {
524 if(CTK_WIDGET_TYPE((struct ctk_widget
*)data
) ==
525 CTK_WIDGET_HYPERLINK
) {
526 strncpy(statustexturl
, w
->widget
.hyperlink
.url
,
527 sizeof(statustexturl
));
528 petsciiconv_topetscii(statustexturl
, sizeof(statustexturl
));
529 show_statustext(statustexturl
);
532 } else if(ev
== resolv_event_found
) {
533 /* Either found a hostname, or not. */
534 if((char *)data
!= NULL
&&
535 resolv_lookup((char *)data
) != NULL
) {
538 show_statustext("Host not found.");
541 } else if(ev
== ctk_signal_window_close
||
542 ev
== PROCESS_EVENT_EXIT
) {
548 /*-----------------------------------------------------------------------------------*/
551 * Constructs an URL from the arguments and puts it into the global
552 * "url" variable and the visible "editurl" (which is shown in the URL
553 * text entry widget in the browser window).
556 set_url(char *host
, u16_t port
, char *file
)
560 memset(url
, 0, WWW_CONF_MAX_URLLEN
);
562 if(strncmp(file
, http_http
, 7) == 0) {
563 strncpy(url
, file
, sizeof(url
));
565 strncpy(url
, http_http
, 7);
567 strcpy(urlptr
, host
);
568 urlptr
+= strlen(host
);
569 strcpy(urlptr
, file
);
574 /*-----------------------------------------------------------------------------------*/
575 /* webclient_aborted():
577 * Callback function. Called from the webclient when the HTTP
578 * connection was abruptly aborted.
581 webclient_aborted(void)
583 show_statustext("Connection reset by peer");
585 /*-----------------------------------------------------------------------------------*/
586 /* webclient_timedout():
588 * Callback function. Called from the webclient when the HTTP
589 * connection timed out.
592 webclient_timedout(void)
594 show_statustext("Connection timed out");
596 /*-----------------------------------------------------------------------------------*/
597 /* webclient_closed():
599 * Callback function. Called from the webclient when the HTTP
600 * connection was closed after a request from the "webclient_close()"
604 webclient_closed(void)
606 show_statustext("Stopped.");
607 petsciiconv_topetscii(webpageptr
- x
, x
);
608 CTK_WIDGET_FOCUS(&mainwindow
, &downbutton
);
611 /*-----------------------------------------------------------------------------------*/
612 /* webclient_connected():
614 * Callback function. Called from the webclient when the HTTP
615 * connection is connected.
618 webclient_connected(void)
624 show_statustext("Request sent...");
625 set_url(webclient_hostname(), webclient_port(), webclient_filename());
627 #if WWW_CONF_RENDERSTATE
628 renderstate
= HTMLPARSER_RENDERSTATE_NONE
;
629 #endif /* WWW_CONF_RENDERSTATE */
632 /*-----------------------------------------------------------------------------------*/
633 /* webclient_datahandler():
635 * Callback function. Called from the webclient module when HTTP data
639 webclient_datahandler(char *data
, u16_t len
)
642 if(strcmp(webclient_mimetype(), http_texthtml
) == 0) {
643 count
= (count
+ 1) & 3;
644 show_statustext(receivingmsgs
[count
]);
645 htmlparser_parse(data
, len
);
649 #if WWW_CONF_WITH_WGET
650 ctk_dialog_open(&wgetdialog
);
651 #endif /* WWW_CONF_WITH_WGET */
654 /* Clear remaining parts of page. */
660 show_statustext("Done.");
661 petsciiconv_topetscii(webpageptr
- x
, x
);
662 CTK_WIDGET_FOCUS(&mainwindow
, &urlentry
);
666 /*-----------------------------------------------------------------------------------*/
668 add_pagewidget(char *text
, unsigned char len
, unsigned char type
,
669 unsigned char border
)
671 register struct ctk_widget
*lptr
;
673 static unsigned char maxwidth
;
674 static void *dataptr
;
680 if(len
+ border
== 0) {
684 maxwidth
= WWW_CONF_WEBPAGE_WIDTH
- (1 + 2 * border
);
686 /* If the text of the link is too long so that it does not fit into
687 the width of the current window, counting from the current x
688 coordinate, we first try to jump to the next line. */
689 if(len
+ x
> maxwidth
) {
690 htmlparser_newline();
696 /* If the text of the link still is too long, we just chop it off!
697 XXX: this is not really the right thing to do, we should probably
698 either make a link into a multiline link, or add multiple
699 buttons. But this will do for now. */
707 if(firsty
== pagey
) {
709 /* To save memory, we'll copy the widget text to the web page
710 drawing area and reference it from there. */
713 memcpy(wptr
, text
, len
);
715 wptr
[len
+ border
] = ' ';
716 if(pagewidgetptr
< WWW_CONF_MAX_NUMPAGEWIDGETS
) {
717 dataptr
= &pagewidgetattribs
[pagewidgetptr
];
718 lptr
= &pagewidgets
[pagewidgetptr
];
721 case CTK_WIDGET_HYPERLINK
:
722 CTK_HYPERLINK_NEW((struct ctk_hyperlink
*)lptr
, x
,
726 case CTK_WIDGET_BUTTON
:
727 CTK_BUTTON_NEW((struct ctk_button
*)lptr
, x
,
730 ((struct formattribs
*)dataptr
)->inputvalue
= wptr
;
732 case CTK_WIDGET_TEXTENTRY
:
733 CTK_TEXTENTRY_NEW((struct ctk_textentry
*)lptr
, x
,
736 ((struct formattribs
*)dataptr
)->inputvalue
= wptr
;
739 CTK_WIDGET_SET_FLAG(lptr
, CTK_WIDGET_FLAG_MONOSPACE
);
740 CTK_WIDGET_ADD(&mainwindow
, lptr
);
745 /* Increase the x coordinate with the length of the link text plus
746 the extra space behind it and the CTK button markers. */
747 len
= len
+ 1 + 2 * border
;
750 if(firsty
== pagey
) {
754 if(x
== WWW_CONF_WEBPAGE_WIDTH
) {
755 htmlparser_newline();
760 /*-----------------------------------------------------------------------------------*/
761 #if WWW_CONF_RENDERSTATE
763 centerline(char *wptr
)
765 unsigned char spaces
, i
;
767 register struct ctk_widget
*linksptr
;
769 cptr
= wptr
+ WWW_CONF_WEBPAGE_WIDTH
;
770 for(spaces
= 0; spaces
< WWW_CONF_WEBPAGE_WIDTH
; ++spaces
) {
778 while(cptr
>= wptr
) {
779 *(cptr
+ spaces
) = *cptr
;
783 memset(wptr
, ' ', spaces
);
785 linksptr
= pagewidgets
;
787 for(i
= 0; i
< pagewidgetptr
; ++i
) {
788 if(CTK_WIDGET_YPOS(linksptr
) == y
+ 2) {
789 linksptr
->x
+= spaces
;
790 linksptr
->widget
.hyperlink
.text
+= spaces
;
795 #endif /* WWW_CONF_RENDERSTATE */
796 /*-----------------------------------------------------------------------------------*/
798 htmlparser_newline(void)
812 webpageptr
+= (WWW_CONF_WEBPAGE_WIDTH
- x
);
816 wptr
= webpageptr
- WWW_CONF_WEBPAGE_WIDTH
;
817 petsciiconv_topetscii(wptr
,
818 WWW_CONF_WEBPAGE_WIDTH
);
819 #if WWW_CONF_RENDERSTATE
820 if(renderstate
& HTMLPARSER_RENDERSTATE_CENTER
) {
823 #endif /* WWW_CONF_RENDERSTATE */
825 if(y
== WWW_CONF_WEBPAGE_HEIGHT
) {
830 /*-----------------------------------------------------------------------------------*/
832 htmlparser_word(char *word
, unsigned char wordlen
)
836 if(wordlen
+ 1 > WWW_CONF_WEBPAGE_WIDTH
- x
) {
837 htmlparser_newline();
841 if(pagey
== firsty
) {
842 memcpy(webpageptr
, word
, wordlen
);
843 webpageptr
+= wordlen
;
848 if(x
== WWW_CONF_WEBPAGE_WIDTH
) {
849 htmlparser_newline();
854 /*-----------------------------------------------------------------------------------*/
856 htmlparser_link(char *text
, unsigned char textlen
, char *url
)
858 static char *linkurlptr
;
860 linkurlptr
= add_pagewidget(text
, textlen
, CTK_WIDGET_HYPERLINK
, 0);
861 if(linkurlptr
!= NULL
&&
862 strlen(url
) < WWW_CONF_MAX_URLLEN
) {
863 strcpy(linkurlptr
, url
);
866 /*-----------------------------------------------------------------------------------*/
867 #if WWW_CONF_RENDERSTATE
869 htmlparser_renderstate(unsigned char s
)
871 if((s
& HTMLPARSER_RENDERSTATE_STATUSMASK
) ==
872 HTMLPARSER_RENDERSTATE_BEGIN
) {
873 renderstate
|= s
& ~HTMLPARSER_RENDERSTATE_STATUSMASK
;
875 renderstate
&= ~(s
& ~HTMLPARSER_RENDERSTATE_STATUSMASK
);
878 #endif /* WWW_CONF_RENDERSTATE */
880 /*-----------------------------------------------------------------------------------*/
883 htmlparser_submitbutton(char *text
, char *name
,
884 char *formname
, char *formaction
)
886 register struct formattribs
*form
;
888 form
= add_pagewidget(text
, (unsigned char)strlen(text
), CTK_WIDGET_BUTTON
, 1);
890 strncpy(form
->formaction
, formaction
, WWW_CONF_MAX_FORMACTIONLEN
);
891 strncpy(form
->formname
, formname
, WWW_CONF_MAX_FORMNAMELEN
);
892 strncpy(form
->inputname
, name
, WWW_CONF_MAX_INPUTNAMELEN
);
893 form
->inputtype
= FORMINPUTTYPE_SUBMITBUTTON
;
896 /*-----------------------------------------------------------------------------------*/
898 htmlparser_inputfield(unsigned char size
, char *text
, char *name
,
899 char *formname
, char *formaction
)
901 register struct formattribs
*form
;
903 form
= add_pagewidget(text
, size
, CTK_WIDGET_TEXTENTRY
, 1);
905 strncpy(form
->formaction
, formaction
, WWW_CONF_MAX_FORMACTIONLEN
);
906 strncpy(form
->formname
, formname
, WWW_CONF_MAX_FORMNAMELEN
);
907 strncpy(form
->inputname
, name
, WWW_CONF_MAX_INPUTNAMELEN
);
908 form
->inputtype
= FORMINPUTTYPE_INPUTFIELD
;
911 /*-----------------------------------------------------------------------------------*/
913 formsubmit(struct formattribs
*attribs
)
916 register char *urlptr
, *valueptr
;
917 register struct formattribs
*faptr
;
921 strncpy(urlptr
, attribs
->formaction
, WWW_CONF_MAX_URLLEN
);
922 tmpurl
[WWW_CONF_MAX_URLLEN
] = 0;
923 urlptr
+= strlen(urlptr
);
924 *urlptr
= ISO_questionmark
;
927 /* Construct an URL by finding all input field forms with the same
928 formname as the current submit button, and add the submit button
929 URL stuff as well. */
930 for(i
= 0; i
< pagewidgetptr
; ++i
) {
931 if(urlptr
- &tmpurl
[0] >= WWW_CONF_MAX_URLLEN
) {
935 faptr
= &pagewidgetattribs
[i
].form
;
937 if(strcmp(attribs
->formaction
, faptr
->formaction
) == 0 &&
938 strcmp(attribs
->formname
, faptr
->formname
) == 0 &&
939 (faptr
->inputtype
== FORMINPUTTYPE_INPUTFIELD
||
942 /* Copy the name of the input field into the URL and append a
944 strncpy(urlptr
, faptr
->inputname
, WWW_CONF_MAX_URLLEN
- strlen(tmpurl
));
945 tmpurl
[WWW_CONF_MAX_URLLEN
] = 0;
946 urlptr
+= strlen(urlptr
);
950 /* Convert and copy the contents of the input field to the URL
951 and append an ampersand. */
952 valueptr
= pagewidgets
[i
].widget
.textentry
.text
;
953 petsciiconv_toascii(valueptr
, WWW_CONF_MAX_INPUTVALUELEN
);
954 for(j
= 0; j
< WWW_CONF_MAX_INPUTVALUELEN
; ++j
) {
955 if(urlptr
- &tmpurl
[0] >= WWW_CONF_MAX_URLLEN
) {
959 if(*urlptr
== ISO_space
) {
969 *urlptr
= ISO_ampersand
;
975 #if WWW_CONF_HISTORY_SIZE > 0
977 #endif /* WWW_CONF_HISTORY_SIZE > 0 */
980 #endif /* WWW_CONF_FORMS */
981 /*-----------------------------------------------------------------------------------*/