blob: 225f255ca5cde6b7370014a18e464995ed66e384 [file] [log] [blame]
adamdunkelsca9ddcb2003-03-19 14:13:31 +00001/*
2 * Copyright (c) 2002, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
adamdunkels06f897e2004-06-06 05:59:20 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkelsca9ddcb2003-03-19 14:13:31 +000015 * products derived from this software without specific prior
16 * written permission.
17 *
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.
29 *
30 * This file is part of the Contiki desktop environment
31 *
oliverschmidt35514d52005-06-12 23:44:29 +000032 * $Id: www.c,v 1.31 2005/06/12 23:44:30 oliverschmidt Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000033 *
34 */
35
adamdunkelsdb300d22004-02-24 09:57:49 +000036#include <string.h>
adamdunkelsca9ddcb2003-03-19 14:13:31 +000037
adamdunkelsf2f8cb22004-07-04 11:35:07 +000038#include "ek.h"
adamdunkelsca9ddcb2003-03-19 14:13:31 +000039#include "ctk.h"
adamdunkelsca9ddcb2003-03-19 14:13:31 +000040#include "webclient.h"
41#include "htmlparser.h"
42#include "http-strings.h"
43#include "resolv.h"
44
45#include "petsciiconv.h"
46
adamdunkels8bb5cca2003-08-24 22:41:31 +000047#include "program-handler.h"
48
adamdunkelsdb300d22004-02-24 09:57:49 +000049#include "uiplib.h"
adamdunkels8bb5cca2003-08-24 22:41:31 +000050
adamdunkelsf2f8cb22004-07-04 11:35:07 +000051#include "tcpip.h"
52
adamdunkels8af703e2003-04-08 11:50:20 +000053#include "loader.h"
54
adamdunkelsca9ddcb2003-03-19 14:13:31 +000055#include "www-conf.h"
56
adamdunkels30c449e2003-07-31 23:12:05 +000057#if 1
adamdunkelsca9ddcb2003-03-19 14:13:31 +000058#define PRINTF(x)
59#else
60#include <stdio.h>
61#define PRINTF(x) printf x
62#endif
63
64
65/* The array that holds the current URL. */
66static char url[WWW_CONF_MAX_URLLEN + 1];
67static char tmpurl[WWW_CONF_MAX_URLLEN + 1];
68
69/* The array that holds the web page text. */
adamdunkels89c1f4e2003-08-09 13:33:25 +000070static char webpage[WWW_CONF_WEBPAGE_WIDTH *
71 WWW_CONF_WEBPAGE_HEIGHT + 1];
adamdunkelsca9ddcb2003-03-19 14:13:31 +000072
adamdunkels269d7be2004-09-03 09:55:22 +000073
adamdunkelsca9ddcb2003-03-19 14:13:31 +000074/* The CTK widgets for the main window. */
75static struct ctk_window mainwindow;
76
77static struct ctk_button backbutton =
78 {CTK_BUTTON(0, 0, 4, "Back")};
79static struct ctk_button downbutton =
80 {CTK_BUTTON(10, 0, 4, "Down")};
81static struct ctk_button stopbutton =
adamdunkels89c1f4e2003-08-09 13:33:25 +000082 {CTK_BUTTON(WWW_CONF_WEBPAGE_WIDTH - 16, 0, 4, "Stop")};
adamdunkelsca9ddcb2003-03-19 14:13:31 +000083static struct ctk_button gobutton =
adamdunkels89c1f4e2003-08-09 13:33:25 +000084 {CTK_BUTTON(WWW_CONF_WEBPAGE_WIDTH - 4, 0, 2, "Go")};
adamdunkelsca9ddcb2003-03-19 14:13:31 +000085
86static struct ctk_separator sep1 =
adamdunkels89c1f4e2003-08-09 13:33:25 +000087 {CTK_SEPARATOR(0, 2, WWW_CONF_WEBPAGE_WIDTH)};
adamdunkelsca9ddcb2003-03-19 14:13:31 +000088
89static char editurl[WWW_CONF_MAX_URLLEN + 1];
90static struct ctk_textentry urlentry =
adamdunkels89c1f4e2003-08-09 13:33:25 +000091 {CTK_TEXTENTRY(0, 1, WWW_CONF_WEBPAGE_WIDTH - 2,
92 1, editurl, WWW_CONF_MAX_URLLEN)};
adamdunkelsca9ddcb2003-03-19 14:13:31 +000093static struct ctk_label webpagelabel =
adamdunkels89c1f4e2003-08-09 13:33:25 +000094 {CTK_LABEL(0, 3, WWW_CONF_WEBPAGE_WIDTH,
95 WWW_CONF_WEBPAGE_HEIGHT, webpage)};
adamdunkelsca9ddcb2003-03-19 14:13:31 +000096
adamdunkels89c1f4e2003-08-09 13:33:25 +000097static char statustexturl[WWW_CONF_WEBPAGE_WIDTH];
adamdunkelsca9ddcb2003-03-19 14:13:31 +000098static struct ctk_label statustext =
adamdunkels89c1f4e2003-08-09 13:33:25 +000099 {CTK_LABEL(0, WWW_CONF_WEBPAGE_HEIGHT + 4,
100 WWW_CONF_WEBPAGE_WIDTH, 1, "")};
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000101static struct ctk_separator sep2 =
adamdunkels89c1f4e2003-08-09 13:33:25 +0000102 {CTK_SEPARATOR(0, WWW_CONF_WEBPAGE_HEIGHT + 3,
103 WWW_CONF_WEBPAGE_WIDTH)};
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000104
adamdunkelsf6eea752003-08-22 19:24:40 +0000105static struct ctk_window wgetdialog;
106static struct ctk_label wgetlabel1 =
adamdunkels77b7a692003-08-29 20:36:23 +0000107 {CTK_LABEL(1, 1, 34, 1, "This web page cannot be displayed.")};
adamdunkelsf6eea752003-08-22 19:24:40 +0000108static struct ctk_label wgetlabel2 =
adamdunkels77b7a692003-08-29 20:36:23 +0000109 {CTK_LABEL(1, 3, 35, 1, "Would you like to download instead?")};
adamdunkelsf6eea752003-08-22 19:24:40 +0000110static struct ctk_button wgetnobutton =
adamdunkels77b7a692003-08-29 20:36:23 +0000111 {CTK_BUTTON(1, 5, 6, "Cancel")};
adamdunkelsf6eea752003-08-22 19:24:40 +0000112static struct ctk_button wgetyesbutton =
adamdunkels77b7a692003-08-29 20:36:23 +0000113 {CTK_BUTTON(11, 5, 24, "Close browser & download")};
adamdunkelsf6eea752003-08-22 19:24:40 +0000114
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000115/* The char arrays that hold the history of visited URLs. */
adamdunkels17e84a32003-04-02 09:54:39 +0000116static char history[WWW_CONF_HISTORY_SIZE][WWW_CONF_MAX_URLLEN];
oliverschmidt10f4b8d2005-02-07 23:13:00 +0000117static char history_last;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000118
119
120/* The CTK widget definitions for the hyperlinks and the char arrays
121 that hold the link URLs. */
122struct formattribs {
123 char formaction[WWW_CONF_MAX_FORMACTIONLEN];
124 char formname[WWW_CONF_MAX_FORMNAMELEN];
125#define FORMINPUTTYPE_SUBMITBUTTON 1
126#define FORMINPUTTYPE_INPUTFIELD 2
127 unsigned char inputtype;
128 char inputname[WWW_CONF_MAX_INPUTNAMELEN];
129 char *inputvalue;
130};
131
132union pagewidgetattrib {
133 char url[WWW_CONF_MAX_URLLEN];
adamdunkelsd59dadf2003-08-15 18:48:35 +0000134#if WWW_CONF_FORMS
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000135 struct formattribs form;
adamdunkelsd59dadf2003-08-15 18:48:35 +0000136#endif /* WWW_CONF_FORMS */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000137};
adamdunkels17e84a32003-04-02 09:54:39 +0000138static struct ctk_widget pagewidgets[WWW_CONF_MAX_NUMPAGEWIDGETS];
139static union pagewidgetattrib pagewidgetattribs[WWW_CONF_MAX_NUMPAGEWIDGETS];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000140static unsigned char pagewidgetptr;
141
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000142#if WWW_CONF_RENDERSTATE
143static unsigned char renderstate;
144#endif /* WWW_CONF_RENDERSTATE */
145
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000146#define ISO_nl 0x0a
147#define ISO_space 0x20
148#define ISO_ampersand 0x26
149#define ISO_plus 0x2b
150#define ISO_slash 0x2f
151#define ISO_eq 0x3d
152#define ISO_questionmark 0x3f
153
154/* The state of the rendering code. */
adamdunkels269d7be2004-09-03 09:55:22 +0000155static char *webpageptr;
156static unsigned char x, y;
157static unsigned char loading;
158static unsigned short firsty, pagey;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000159
160static unsigned char count;
161static char receivingmsgs[4][23] = {
162 "Receiving web page ...",
163 "Receiving web page. ..",
164 "Receiving web page.. .",
165 "Receiving web page... "
166};
167
168
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000169EK_EVENTHANDLER(www_eventhandler, ev, data);
170EK_PROCESS(p, "Web browser", EK_PRIO_NORMAL,
171 www_eventhandler, NULL, NULL);
172static ek_id_t id = EK_ID_NONE;
173
174/*static DISPATCHER_SIGHANDLER(www_sighandler, s, data);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000175static struct dispatcher_proc p =
adamdunkels78c03dc2003-04-09 13:45:05 +0000176 {DISPATCHER_PROC("Web browser", NULL, www_sighandler, webclient_appcall)};
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000177 static ek_id_t id;*/
178
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000179
180
181static void formsubmit(struct formattribs *attribs);
182/*-----------------------------------------------------------------------------------*/
183/* make_window()
184 *
185 * Creates the web browser's window.
186 */
187static void
188make_window(void)
189{
190
191 CTK_WIDGET_ADD(&mainwindow, &backbutton);
192 CTK_WIDGET_ADD(&mainwindow, &downbutton);
193 CTK_WIDGET_ADD(&mainwindow, &stopbutton);
194 CTK_WIDGET_ADD(&mainwindow, &gobutton);
195 CTK_WIDGET_ADD(&mainwindow, &urlentry);
196 CTK_WIDGET_ADD(&mainwindow, &sep1);
197 CTK_WIDGET_ADD(&mainwindow, &webpagelabel);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000198 CTK_WIDGET_SET_FLAG(&webpagelabel, CTK_WIDGET_FLAG_MONOSPACE);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000199 CTK_WIDGET_ADD(&mainwindow, &sep2);
200 CTK_WIDGET_ADD(&mainwindow, &statustext);
201
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000202 pagewidgetptr = 0;
203}
204/*-----------------------------------------------------------------------------------*/
205/* redraw_window():
206 *
207 * Convenience function that calls upon CTK to redraw the browser
208 * window. */
209static void
210redraw_window(void)
211{
212 ctk_window_redraw(&mainwindow);
213}
214/*-----------------------------------------------------------------------------------*/
215/* www_init();
216 *
217 * Initializes and starts the web browser. Called either at startup or
218 * to open the browser window.
219 */
adamdunkels8bb5cca2003-08-24 22:41:31 +0000220LOADER_INIT_FUNC(www_init, arg)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000221{
adamdunkels8bb5cca2003-08-24 22:41:31 +0000222 arg_free(arg);
223
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000224 if(id == EK_ID_NONE) {
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000225 /* id = dispatcher_start(&p);*/
226 id = ek_start(&p);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000227
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000228 }
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000229}
230/*-----------------------------------------------------------------------------------*/
231static void
232clear_page(void)
233{
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000234 ctk_window_clear(&mainwindow);
235 make_window();
adamdunkels269d7be2004-09-03 09:55:22 +0000236 redraw_window();
adamdunkels17e84a32003-04-02 09:54:39 +0000237 memset(webpage, 0, WWW_CONF_WEBPAGE_WIDTH * WWW_CONF_WEBPAGE_HEIGHT);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000238}
239/*-----------------------------------------------------------------------------------*/
240static void
241show_url(void)
242{
243 memcpy(editurl, url, WWW_CONF_MAX_URLLEN);
244 strncpy(editurl, "http://", 7);
245 petsciiconv_topetscii(editurl + 7, WWW_CONF_MAX_URLLEN - 7);
246 CTK_WIDGET_REDRAW(&urlentry);
247}
adamdunkels269d7be2004-09-03 09:55:22 +0000248static void
249start_loading(void)
250{
251 loading = 1;
252 x = y = 0;
253 pagey = 0;
254 webpageptr = webpage;
255
256 clear_page();
257}
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000258/*-----------------------------------------------------------------------------------*/
259static void
260show_statustext(char *text)
261{
262 ctk_label_set_text(&statustext, text);
263 CTK_WIDGET_REDRAW(&statustext);
264}
265/*-----------------------------------------------------------------------------------*/
266/* open_url():
267 *
268 * Called when the URL present in the global "url" variable should be
269 * opened. It will call the hostname resolver as well as the HTTP
270 * client requester.
271 */
272static void
273open_url(void)
274{
275 unsigned char i;
276 static char host[32];
277 char *file;
278 register char *urlptr;
adamdunkels75c276c2003-09-04 19:35:32 +0000279 static u16_t addr[2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000280
281 /* Trim off any spaces in the end of the url. */
282 urlptr = url + strlen(url) - 1;
283 while(*urlptr == ' ' && urlptr > url) {
284 *urlptr = 0;
285 --urlptr;
286 }
287
288 /* Don't even try to go further if the URL is empty. */
289 if(urlptr == url) {
290 return;
291 }
292
293 /* See if the URL starts with http://, otherwise prepend it. */
294 if(strncmp(url, http_http, 7) != 0) {
295 while(urlptr >= url) {
296 *(urlptr + 7) = *urlptr;
297 --urlptr;
298 }
299 strncpy(url, http_http, 7);
300 }
301
302 /* Find host part of the URL. */
303 urlptr = &url[7];
304 for(i = 0; i < sizeof(host); ++i) {
305 if(*urlptr == 0 ||
306 *urlptr == '/' ||
307 *urlptr == ' ' ||
308 *urlptr == ':') {
309 host[i] = 0;
310 break;
311 }
312 host[i] = *urlptr;
313 ++urlptr;
314 }
315
316 /* XXX: Here we should find the port part of the URL, but this isn't
317 currently done because of laziness from the programmer's side
318 :-) */
319
320 /* Find file part of the URL. */
321 while(*urlptr != '/' && *urlptr != 0) {
322 ++urlptr;
323 }
324 if(*urlptr == '/') {
325 file = urlptr;
326 } else {
327 file = "/";
328 }
329
330 /* Try to lookup the hostname. If it fails, we initiate a hostname
331 lookup and print out an informative message on the statusbar. */
adamdunkelsdb300d22004-02-24 09:57:49 +0000332 if(uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) {
adamdunkels75c276c2003-09-04 19:35:32 +0000333 if(resolv_lookup(host) == NULL) {
334 resolv_query(host);
335 show_statustext("Resolving host...");
336 return;
337 }
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000338 }
339
340 /* The hostname we present in the hostname table, so we send out the
341 initial GET request. */
342 if(webclient_get(host, 80, file) == 0) {
343 show_statustext("Out of memory error.");
344 } else {
345 show_statustext("Connecting...");
346 }
347 redraw_window();
348}
349/*-----------------------------------------------------------------------------------*/
350/* open_link(link):
351 *
352 * Will format a link from the current web pages so that it suits the
353 * open_url() function and finally call it to open the requested URL.
354 */
355static void
356open_link(char *link)
357{
358 char *urlptr;
359
360 if(strncmp(link, http_http, 7) == 0) {
361 /* The link starts with http://. We just copy the contents of the
362 link into the url string and jump away. */
363 strncpy(url, link, WWW_CONF_MAX_URLLEN);
364 } else if(*link == ISO_slash &&
365 *(link + 1) == ISO_slash) {
366 /* The link starts with //, so we'll copy it into the url
367 variable, starting after the http (which already is present in
368 the url variable since we were able to open the web page on
369 which this link was found in the first place). */
370 strncpy(&url[5], link, WWW_CONF_MAX_URLLEN);
371 } else if(*link == ISO_slash) {
372 /* The link starts with a slash, so it is a non-relative link
373 within the same web site. We find the start of the filename of
374 the current URL and paste the contents of this link there, and
375 head off to the new URL. */
376 for(urlptr = &url[7];
377 *urlptr != 0 && *urlptr != ISO_slash;
378 ++urlptr);
379 strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url));
380 } else {
381 /* A fully relative link is found. We find the last slash in the
382 current URL and paste the link there. */
383
384 /* XXX: we should really parse any ../ in the link as well. */
385 for(urlptr = url + strlen(url);
386 urlptr != url && *urlptr != ISO_slash;
387 --urlptr);
388 ++urlptr;
389 strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url));
390 }
391
392 /* Open the URL. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000393 show_url();
394 open_url();
adamdunkels269d7be2004-09-03 09:55:22 +0000395
396
397 start_loading();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000398}
399/*-----------------------------------------------------------------------------------*/
400/* log_back():
401 *
402 * Copies the current URL from the url variable and into the log for
403 * the back button.
404 */
405static void
406log_back(void)
407{
adamdunkels89c1f4e2003-08-09 13:33:25 +0000408 if(strncmp(url, history[(int)history_last], WWW_CONF_MAX_URLLEN) != 0) {
409 memcpy(history[(int)history_last], url, WWW_CONF_MAX_URLLEN);
410 ++history_last;
411 if(history_last >= WWW_CONF_HISTORY_SIZE) {
412 history_last = 0;
413 }
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000414 }
415}
416/*-----------------------------------------------------------------------------------*/
adamdunkelsf6eea752003-08-22 19:24:40 +0000417static void
418quit(void)
419{
420 ctk_window_close(&mainwindow);
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000421 ek_exit();
adamdunkelsf6eea752003-08-22 19:24:40 +0000422 id = EK_ID_NONE;
423 LOADER_UNLOAD();
424}
425/*-----------------------------------------------------------------------------------*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000426/* www_dispatcher():
427 *
428 * The program's signal dispatcher function. Is called by the ek
429 * dispatcher whenever a signal arrives.
430 */
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000431/*static
432 DISPATCHER_SIGHANDLER(www_sighandler, s, data)*/
433EK_EVENTHANDLER(www_eventhandler, ev, data)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000434{
435 static struct ctk_widget *w;
436 static unsigned char i;
adamdunkels8bb5cca2003-08-24 22:41:31 +0000437 static char *argptr;
438
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000439 /* DISPATCHER_SIGHANDLER_ARGS(s, data);*/
440 EK_EVENTHANDLER_ARGS(ev, data);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000441
442
443 w = (struct ctk_widget *)data;
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000444
445 if(ev == tcpip_event) {
446 webclient_appcall(data);
447 } else if(ev == EK_EVENT_INIT) {
448 /* Create the main window. */
449 memset(webpage, 0, sizeof(webpage));
450 ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH,
451 WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser");
452 make_window();
453#ifdef WWW_CONF_HOMEPAGE
454 strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl));
455#endif /* WWW_CONF_HOMEPAGE */
456 CTK_WIDGET_FOCUS(&mainwindow, &urlentry);
457
458 /* Create download dialog.*/
459 ctk_dialog_new(&wgetdialog, 38, 7);
460 CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1);
461 CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2);
462 CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton);
463 CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton);
464
465 ctk_window_open(&mainwindow);
466
467 } else if(ev == ctk_signal_widget_activate) {
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000468 if(w == (struct ctk_widget *)&backbutton) {
adamdunkels269d7be2004-09-03 09:55:22 +0000469 firsty = 0;
470 start_loading();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000471
472 --history_last;
adamdunkels17e84a32003-04-02 09:54:39 +0000473 if(history_last > WWW_CONF_HISTORY_SIZE) {
474 history_last = WWW_CONF_HISTORY_SIZE - 1;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000475 }
adamdunkels30c449e2003-07-31 23:12:05 +0000476 memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000477 open_url();
478 CTK_WIDGET_FOCUS(&mainwindow, &backbutton);
479 } else if(w == (struct ctk_widget *)&downbutton) {
adamdunkels269d7be2004-09-03 09:55:22 +0000480 firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4;
481 start_loading();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000482 open_url();
483 CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
adamdunkels328e5352003-08-20 20:54:46 +0000484 } else if(w == (struct ctk_widget *)&gobutton ||
485 w == (struct ctk_widget *)&urlentry) {
adamdunkels269d7be2004-09-03 09:55:22 +0000486 start_loading();
487 firsty = 0;
adamdunkels30c449e2003-07-31 23:12:05 +0000488
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000489 log_back();
490 memcpy(url, editurl, WWW_CONF_MAX_URLLEN);
491 petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN);
492 open_url();
493 CTK_WIDGET_FOCUS(&mainwindow, &gobutton);
494 } else if(w == (struct ctk_widget *)&stopbutton) {
adamdunkels269d7be2004-09-03 09:55:22 +0000495 loading = 0;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000496 webclient_close();
adamdunkelsf6eea752003-08-22 19:24:40 +0000497 } else if(w == (struct ctk_widget *)&wgetnobutton) {
498 ctk_dialog_close();
499 } else if(w == (struct ctk_widget *)&wgetyesbutton) {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000500 ctk_dialog_close();
adamdunkelsf6eea752003-08-22 19:24:40 +0000501 quit();
adamdunkels8bb5cca2003-08-24 22:41:31 +0000502 argptr = arg_alloc(WWW_CONF_MAX_URLLEN);
503 if(argptr != NULL) {
504 strncpy(argptr, url, WWW_CONF_MAX_URLLEN);
505 }
506 program_handler_load("wget.prg", argptr);
adamdunkelsf6eea752003-08-22 19:24:40 +0000507
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000508#if WWW_CONF_FORMS
509 } else {
510 /* Check form buttons */
511 for(i = 0; i < pagewidgetptr; ++i) {
512 if(&pagewidgets[i] == w) {
513 formsubmit(&pagewidgetattribs[i].form);
514 /* show_statustext(pagewidgetattribs[i].form.formaction);*/
515 /* PRINTF(("Formaction %s formname %s inputname %s\n",
516 pagewidgetattribs[i].form.formaction,
517 pagewidgetattribs[i].form.formname,
518 pagewidgetattribs[i].form.inputname));*/
519 break;
520 }
521 }
522#endif /* WWW_CONF_FORMS */
523 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000524 } else if(ev == ctk_signal_hyperlink_activate) {
adamdunkels269d7be2004-09-03 09:55:22 +0000525 firsty = 0;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000526 log_back();
527 open_link(w->widget.hyperlink.url);
528 CTK_WIDGET_FOCUS(&mainwindow, &stopbutton);
adamdunkelsf6eea752003-08-22 19:24:40 +0000529 /* ctk_window_open(&mainwindow);*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000530 } else if(ev == ctk_signal_hyperlink_hover) {
adamdunkels89c1f4e2003-08-09 13:33:25 +0000531 if(CTK_WIDGET_TYPE((struct ctk_widget *)data) ==
532 CTK_WIDGET_HYPERLINK) {
adamdunkelsc4bf5ca2003-04-18 00:20:22 +0000533 strncpy(statustexturl, w->widget.hyperlink.url,
534 sizeof(statustexturl));
535 petsciiconv_topetscii(statustexturl, sizeof(statustexturl));
536 show_statustext(statustexturl);
537 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000538 } else if(ev == resolv_event_found) {
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000539 /* Either found a hostname, or not. */
540 if((char *)data != NULL &&
541 resolv_lookup((char *)data) != NULL) {
542 open_url();
543 } else {
544 show_statustext("Host not found.");
545 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000546 } else if(ev == ctk_signal_window_close ||
547 ev == EK_EVENT_REQUEST_EXIT) {
adamdunkelsf6eea752003-08-22 19:24:40 +0000548 quit();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000549 }
550}
551/*-----------------------------------------------------------------------------------*/
552/* set_url():
553 *
554 * Constructs an URL from the arguments and puts it into the global
555 * "url" variable and the visible "editurl" (which is shown in the URL
556 * text entry widget in the browser window).
557 */
558static void
559set_url(char *host, u16_t port, char *file)
560{
561 char *urlptr;
562
563 memset(url, 0, WWW_CONF_MAX_URLLEN);
564
565 if(strncmp(file, http_http, 7) == 0) {
566 strncpy(url, file, sizeof(url));
567 } else {
568 strncpy(url, http_http, 7);
569 urlptr = url + 7;
570 strcpy(urlptr, host);
571 urlptr += strlen(host);
572 strcpy(urlptr, file);
573 }
574
575 show_url();
576}
577/*-----------------------------------------------------------------------------------*/
578/* webclient_aborted():
579 *
580 * Callback function. Called from the webclient when the HTTP
581 * connection was abruptly aborted.
582 */
583void
584webclient_aborted(void)
585{
586 show_statustext("Connection reset by peer");
587}
588/*-----------------------------------------------------------------------------------*/
589/* webclient_timedout():
590 *
591 * Callback function. Called from the webclient when the HTTP
592 * connection timed out.
593 */
594void
595webclient_timedout(void)
596{
597 show_statustext("Connection timed out");
598}
599/*-----------------------------------------------------------------------------------*/
600/* webclient_closed():
601 *
602 * Callback function. Called from the webclient when the HTTP
603 * connection was closed after a request from the "webclient_close()"
604 * function. .
605 */
606void
607webclient_closed(void)
608{
609 show_statustext("Stopped.");
adamdunkels17e84a32003-04-02 09:54:39 +0000610 petsciiconv_topetscii(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) *
611 WWW_CONF_WEBPAGE_WIDTH], WWW_CONF_WEBPAGE_WIDTH);
oliverschmidtbf5bffe2005-03-13 22:42:31 +0000612 CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000613 redraw_window();
614}
615/*-----------------------------------------------------------------------------------*/
616/* webclient_closed():
617 *
618 * Callback function. Called from the webclient when the HTTP
619 * connection is connected.
620 */
621void
622webclient_connected(void)
623{
adamdunkels269d7be2004-09-03 09:55:22 +0000624 start_loading();
625
626 clear_page();
adamdunkels30c449e2003-07-31 23:12:05 +0000627
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000628 show_statustext("Request sent...");
629 set_url(webclient_hostname(), webclient_port(), webclient_filename());
630
631#if WWW_CONF_RENDERSTATE
632 renderstate = HTMLPARSER_RENDERSTATE_NONE;
633#endif /* WWW_CONF_RENDERSTATE */
634 htmlparser_init();
635}
636/*-----------------------------------------------------------------------------------*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000637/* webclient_datahandler():
638 *
639 * Callback function. Called from the webclient module when HTTP data
640 * has arrived.
641 */
642void
643webclient_datahandler(char *data, u16_t len)
644{
645 if(len > 0) {
adamdunkelsf6eea752003-08-22 19:24:40 +0000646 if(strcmp(webclient_mimetype(), http_texthtml) == 0) {
647 count = (count + 1) & 3;
648 show_statustext(receivingmsgs[count]);
649 htmlparser_parse(data, len);
adamdunkels269d7be2004-09-03 09:55:22 +0000650 redraw_window();
adamdunkelsf6eea752003-08-22 19:24:40 +0000651 } else {
adamdunkels8bb5cca2003-08-24 22:41:31 +0000652 uip_abort();
adamdunkelsf6eea752003-08-22 19:24:40 +0000653 ctk_dialog_open(&wgetdialog);
654 }
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000655 } else {
656 /* Clear remaining parts of page. */
adamdunkels269d7be2004-09-03 09:55:22 +0000657 loading = 0;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000658 }
659
660 if(data == NULL) {
adamdunkels269d7be2004-09-03 09:55:22 +0000661 loading = 0;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000662 show_statustext("Done.");
adamdunkels17e84a32003-04-02 09:54:39 +0000663 petsciiconv_topetscii(&webpage[(WWW_CONF_WEBPAGE_HEIGHT - 1) *
664 WWW_CONF_WEBPAGE_WIDTH], WWW_CONF_WEBPAGE_WIDTH);
oliverschmidtef13b022005-04-28 21:15:44 +0000665 CTK_WIDGET_FOCUS(&mainwindow, &urlentry);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000666 redraw_window();
667 }
668}
669/*-----------------------------------------------------------------------------------*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000670static void *
adamdunkels269d7be2004-09-03 09:55:22 +0000671add_pagewidget(char *text, unsigned char len, unsigned char type,
672 unsigned char border)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000673{
adamdunkelsd59dadf2003-08-15 18:48:35 +0000674 register struct ctk_widget *lptr;
adamdunkels269d7be2004-09-03 09:55:22 +0000675 register unsigned char *wptr;
676 static unsigned char maxwidth;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000677 static void *dataptr;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000678
adamdunkels269d7be2004-09-03 09:55:22 +0000679 if(!loading) {
680 return NULL;
681 }
682
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000683 if(len + border == 0) {
684 return NULL;
685 }
686
adamdunkels17e84a32003-04-02 09:54:39 +0000687 maxwidth = WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000688
689 /* If the text of the link is too long so that it does not fit into
690 the width of the current window, counting from the current x
691 coordinate, we first try to jump to the next line. */
692 if(len + x > maxwidth) {
adamdunkels269d7be2004-09-03 09:55:22 +0000693 htmlparser_newline();
694 if(!loading) {
695 return NULL;
696 }
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000697 }
698
699 /* If the text of the link still is too long, we just chop it off!
700 XXX: this is not really the right thing to do, we should probably
adamdunkels269d7be2004-09-03 09:55:22 +0000701 either make a link into a multiline link, or add multiple
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000702 buttons. But this will do for now. */
703 if(len > maxwidth) {
704 text[maxwidth] = 0;
705 len = maxwidth;
706 }
707
708 dataptr = NULL;
709
adamdunkels269d7be2004-09-03 09:55:22 +0000710 if(firsty == pagey) {
711 wptr = webpageptr;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000712 /* To save memory, we'll copy the widget text to the web page
713 drawing area and reference it from there. */
adamdunkels269d7be2004-09-03 09:55:22 +0000714 wptr[0] = 0;
715 wptr += border;
716 memcpy(wptr, text, len);
717 wptr[len] = 0;
718 wptr[len + border] = ' ';
adamdunkels17e84a32003-04-02 09:54:39 +0000719 if(pagewidgetptr < WWW_CONF_MAX_NUMPAGEWIDGETS) {
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000720 dataptr = &pagewidgetattribs[pagewidgetptr];
721 lptr = &pagewidgets[pagewidgetptr];
722
723 switch(type) {
724 case CTK_WIDGET_HYPERLINK:
725 CTK_HYPERLINK_NEW((struct ctk_hyperlink *)lptr, x,
adamdunkels269d7be2004-09-03 09:55:22 +0000726 y + 3, len,
727 wptr, dataptr);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000728 break;
729 case CTK_WIDGET_BUTTON:
730 CTK_BUTTON_NEW((struct ctk_button *)lptr, x,
adamdunkels269d7be2004-09-03 09:55:22 +0000731 y + 3, len,
732 wptr);
733 ((struct formattribs *)dataptr)->inputvalue = wptr;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000734 break;
735 case CTK_WIDGET_TEXTENTRY:
adamdunkels269d7be2004-09-03 09:55:22 +0000736 CTK_TEXTENTRY_NEW((struct ctk_textentry *)lptr, x,
737 y + 3, len, 1,
738 wptr, len);
739 ((struct formattribs *)dataptr)->inputvalue = wptr;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000740 break;
741 }
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000742 CTK_WIDGET_SET_FLAG(lptr, CTK_WIDGET_FLAG_MONOSPACE);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000743 CTK_WIDGET_ADD(&mainwindow, lptr);
744
745 ++pagewidgetptr;
746 }
747 }
748 /* Increase the x coordinate with the length of the link text plus
749 the extra space behind it and the CTK button markers. */
adamdunkels269d7be2004-09-03 09:55:22 +0000750 len = len + 1 + 2 * border;
751 x += len;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000752
adamdunkels269d7be2004-09-03 09:55:22 +0000753 if(firsty == pagey) {
754 webpageptr += len;
755 }
756
757 if(x == WWW_CONF_WEBPAGE_WIDTH) {
758 htmlparser_newline();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000759 }
760
761 return dataptr;
762}
763/*-----------------------------------------------------------------------------------*/
adamdunkels269d7be2004-09-03 09:55:22 +0000764#if WWW_CONF_RENDERSTATE
765static void
766centerline(char *wptr)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000767{
adamdunkels269d7be2004-09-03 09:55:22 +0000768 unsigned char spaces, i;
769 char *cptr;
770 register struct ctk_widget *linksptr;
771
oliverschmidtd11555c2005-01-30 20:22:17 +0000772 cptr = wptr + WWW_CONF_WEBPAGE_WIDTH;
adamdunkels269d7be2004-09-03 09:55:22 +0000773 for(spaces = 0; spaces < WWW_CONF_WEBPAGE_WIDTH; ++spaces) {
oliverschmidtd11555c2005-01-30 20:22:17 +0000774 if(*--cptr != 0) {
adamdunkels269d7be2004-09-03 09:55:22 +0000775 break;
776 }
777 }
778
oliverschmidtd11555c2005-01-30 20:22:17 +0000779 spaces /= 2;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000780
oliverschmidtd11555c2005-01-30 20:22:17 +0000781 while(cptr >= wptr) {
782 *(cptr + spaces) = *cptr;
783 --cptr;
784 }
785
adamdunkels269d7be2004-09-03 09:55:22 +0000786 memset(wptr, ' ', spaces);
787
788 linksptr = pagewidgets;
789
790 for(i = 0; i < pagewidgetptr; ++i) {
791 if(CTK_WIDGET_YPOS(linksptr) == y + 2) {
792 linksptr->x += spaces;
793 linksptr->widget.hyperlink.text += spaces;
794 }
795 ++linksptr;
796 }
797}
798#endif /* WWW_CONF_RENDERSTATE */
799/*-----------------------------------------------------------------------------------*/
800void
801htmlparser_newline(void)
802{
803 char *wptr;
804
805 if(pagey < firsty) {
806 ++pagey;
807 x = 0;
808 return;
809 }
810
oliverschmidt453510a2005-01-21 14:25:27 +0000811 if(!loading) {
812 return;
813 }
814
adamdunkels269d7be2004-09-03 09:55:22 +0000815 webpageptr += (WWW_CONF_WEBPAGE_WIDTH - x);
816 ++y;
817 x = 0;
818
819 wptr = webpageptr - WWW_CONF_WEBPAGE_WIDTH;
820 petsciiconv_topetscii(wptr,
821 WWW_CONF_WEBPAGE_WIDTH);
822#if WWW_CONF_RENDERSTATE
823 if(renderstate & HTMLPARSER_RENDERSTATE_CENTER) {
824 centerline(wptr);
825 }
826#endif /* WWW_CONF_RENDERSTATE */
827
828 if(y == WWW_CONF_WEBPAGE_HEIGHT) {
829 loading = 0;
830 webclient_close();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000831 }
832}
833/*-----------------------------------------------------------------------------------*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000834void
adamdunkels269d7be2004-09-03 09:55:22 +0000835htmlparser_word(char *word, unsigned char wordlen)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000836{
adamdunkels269d7be2004-09-03 09:55:22 +0000837
838 if(loading) {
839 if(wordlen + 1 > WWW_CONF_WEBPAGE_WIDTH - x) {
840 htmlparser_newline();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000841 }
adamdunkels269d7be2004-09-03 09:55:22 +0000842
843 if(loading) {
844 if(pagey == firsty) {
845 memcpy(webpageptr, word, wordlen);
846 webpageptr += wordlen;
847 *webpageptr = ' ';
848 ++webpageptr;
849 }
850 x += wordlen + 1;
851 if(x == WWW_CONF_WEBPAGE_WIDTH) {
852 htmlparser_newline();
853 }
854 }
855 }
856}
857/*-----------------------------------------------------------------------------------*/
858void
859htmlparser_link(char *text, unsigned char textlen, char *url)
860{
861 static unsigned char *linkurlptr;
862
863 linkurlptr = add_pagewidget(text, textlen, CTK_WIDGET_HYPERLINK, 0);
864 if(linkurlptr != NULL &&
865 strlen(url) < WWW_CONF_MAX_URLLEN) {
866 strcpy(linkurlptr, url);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000867 }
868}
869/*-----------------------------------------------------------------------------------*/
870#if WWW_CONF_RENDERSTATE
871void
872htmlparser_renderstate(unsigned char s)
873{
874 if((s & HTMLPARSER_RENDERSTATE_STATUSMASK) ==
875 HTMLPARSER_RENDERSTATE_BEGIN) {
876 renderstate |= s & ~HTMLPARSER_RENDERSTATE_STATUSMASK;
877 } else {
878 renderstate &= ~(s & ~HTMLPARSER_RENDERSTATE_STATUSMASK);
879 }
880}
881#endif /* WWW_CONF_RENDERSTATE */
882
883#if WWW_CONF_FORMS
884/*-----------------------------------------------------------------------------------*/
885void
886htmlparser_submitbutton(char *text, char *name,
887 char *formname, char *formaction)
888{
889 register struct formattribs *form;
adamdunkels269d7be2004-09-03 09:55:22 +0000890
891 form = add_pagewidget(text, strlen(text), CTK_WIDGET_BUTTON, 1);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000892 if(form != NULL) {
893 strncpy(form->formaction, formaction, WWW_CONF_MAX_FORMACTIONLEN);
894 strncpy(form->formname, formname, WWW_CONF_MAX_FORMNAMELEN);
895 strncpy(form->inputname, name, WWW_CONF_MAX_INPUTNAMELEN);
896 form->inputtype = FORMINPUTTYPE_SUBMITBUTTON;
897 }
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000898}
899/*-----------------------------------------------------------------------------------*/
900void
oliverschmidt35514d52005-06-12 23:44:29 +0000901htmlparser_inputfield(unsigned char size, char *text, char *name,
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000902 char *formname, char *formaction)
903{
904 register struct formattribs *form;
adamdunkels269d7be2004-09-03 09:55:22 +0000905
oliverschmidt35514d52005-06-12 23:44:29 +0000906 form = add_pagewidget(text, size, CTK_WIDGET_TEXTENTRY, 1);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000907 if(form != NULL) {
908 strncpy(form->formaction, formaction, WWW_CONF_MAX_FORMACTIONLEN);
909 strncpy(form->formname, formname, WWW_CONF_MAX_FORMNAMELEN);
910 strncpy(form->inputname, name, WWW_CONF_MAX_INPUTNAMELEN);
911 form->inputtype = FORMINPUTTYPE_INPUTFIELD;
912 }
913}
914/*-----------------------------------------------------------------------------------*/
915static void
916formsubmit(struct formattribs *attribs)
917{
918 unsigned char i, j;
adamdunkels1a23b5b2003-08-05 13:50:02 +0000919 register char *urlptr, *valueptr;
920 register struct formattribs *faptr;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000921
922 urlptr = &tmpurl[0];
923
924 strncpy(urlptr, attribs->formaction, WWW_CONF_MAX_URLLEN);
925 tmpurl[WWW_CONF_MAX_URLLEN] = 0;
926 urlptr += strlen(urlptr);
927 *urlptr = ISO_questionmark;
928 ++urlptr;
929
930
931 /* Construct an URL by finding all input field forms with the same
932 formname as the current submit button, and add the submit button
933 URL stuff as well. */
934 for(i = 0; i < pagewidgetptr; ++i) {
935 if(urlptr - &tmpurl[0] >= WWW_CONF_MAX_URLLEN) {
936 break;
937 }
938
939 faptr = &pagewidgetattribs[i].form;
940
941 if(strcmp(attribs->formaction, faptr->formaction) == 0 &&
942 strcmp(attribs->formname, faptr->formname) == 0 &&
943 (faptr->inputtype == FORMINPUTTYPE_INPUTFIELD ||
944 faptr == attribs)) {
945
946 /* Copy the name of the input field into the URL and append a
947 questionmark. */
948 strncpy(urlptr, faptr->inputname, WWW_CONF_MAX_URLLEN - strlen(tmpurl));
949 tmpurl[WWW_CONF_MAX_URLLEN] = 0;
950 urlptr += strlen(urlptr);
951 *urlptr = ISO_eq;
952 ++urlptr;
953
954 /* Convert and copy the contents of the input field to the URL
955 and append an ampersand. */
956 valueptr = pagewidgets[i].widget.textentry.text;
957 petsciiconv_toascii(valueptr, WWW_CONF_MAX_INPUTVALUELEN);
958 for(j = 0; j < WWW_CONF_MAX_INPUTVALUELEN; ++j) {
959 if(urlptr - &tmpurl[0] >= WWW_CONF_MAX_URLLEN) {
960 break;
961 }
962 *urlptr = *valueptr;
963 if(*urlptr == ISO_space) {
964 *urlptr = ISO_plus;
965 }
966 if(*urlptr == 0) {
967 break;
968 }
969 ++urlptr;
970 ++valueptr;
971 }
972
973 *urlptr = ISO_ampersand;
974 ++urlptr;
975 }
976 }
977 --urlptr;
978 *urlptr = 0;
adamdunkels89c1f4e2003-08-09 13:33:25 +0000979 log_back();
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000980 open_link(tmpurl);
981}
982/*-----------------------------------------------------------------------------------*/
983#endif /* WWW_CONF_FORMS */