2006-06-18 00:41:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002, Adam Dunkels.
|
2009-02-25 09:52:27 +01:00
|
|
|
* All rights reserved.
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
2009-02-25 09:52:27 +01:00
|
|
|
* 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.
|
2006-06-18 00:41:10 +02:00
|
|
|
* 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
|
2009-02-25 09:52:27 +01:00
|
|
|
* with the distribution.
|
2006-06-18 00:41:10 +02:00
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
2009-02-25 09:52:27 +01:00
|
|
|
* written permission.
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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
|
2009-02-25 09:52:27 +01:00
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Contiki desktop environment
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2013-03-06 16:29:36 +01:00
|
|
|
#include <stddef.h>
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
#include "ctk/ctk.h"
|
2009-02-25 09:52:27 +01:00
|
|
|
#include "lib/ctk-textentry-cmdline.h"
|
2006-06-18 00:41:10 +02:00
|
|
|
#include "contiki-net.h"
|
2007-11-30 17:09:40 +01:00
|
|
|
#include "lib/petsciiconv.h"
|
|
|
|
#include "sys/arg.h"
|
2007-12-15 22:56:23 +01:00
|
|
|
#if WWW_CONF_WITH_WGET
|
2007-11-30 17:09:40 +01:00
|
|
|
#include "program-handler.h"
|
2007-12-15 22:56:23 +01:00
|
|
|
#endif /* WWW_CONF_WITH_WGET */
|
2007-11-30 17:09:40 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
#include "webclient.h"
|
|
|
|
#include "htmlparser.h"
|
|
|
|
#include "http-strings.h"
|
|
|
|
|
2007-11-30 17:09:40 +01:00
|
|
|
#include "www.h"
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
#define PRINTF(x)
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(x) printf x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* The array that holds the current URL. */
|
|
|
|
static char url[WWW_CONF_MAX_URLLEN + 1];
|
|
|
|
|
|
|
|
/* The array that holds the web page text. */
|
|
|
|
static char webpage[WWW_CONF_WEBPAGE_WIDTH *
|
|
|
|
WWW_CONF_WEBPAGE_HEIGHT + 1];
|
|
|
|
|
|
|
|
/* The CTK widgets for the main window. */
|
|
|
|
static struct ctk_window mainwindow;
|
|
|
|
|
2010-02-13 11:39:57 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2006-06-18 00:41:10 +02:00
|
|
|
static struct ctk_button backbutton =
|
|
|
|
{CTK_BUTTON(0, 0, 4, "Back")};
|
|
|
|
static struct ctk_button downbutton =
|
|
|
|
{CTK_BUTTON(10, 0, 4, "Down")};
|
2010-02-13 11:39:57 +01:00
|
|
|
#else /* WWW_CONF_HISTORY_SIZE > 0 */
|
|
|
|
static struct ctk_button downbutton =
|
|
|
|
{CTK_BUTTON(0, 0, 4, "Down")};
|
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2006-06-18 00:41:10 +02:00
|
|
|
static struct ctk_button stopbutton =
|
|
|
|
{CTK_BUTTON(WWW_CONF_WEBPAGE_WIDTH - 16, 0, 4, "Stop")};
|
|
|
|
static struct ctk_button gobutton =
|
|
|
|
{CTK_BUTTON(WWW_CONF_WEBPAGE_WIDTH - 4, 0, 2, "Go")};
|
|
|
|
|
|
|
|
static struct ctk_separator sep1 =
|
|
|
|
{CTK_SEPARATOR(0, 2, WWW_CONF_WEBPAGE_WIDTH)};
|
|
|
|
|
|
|
|
static char editurl[WWW_CONF_MAX_URLLEN + 1];
|
|
|
|
static struct ctk_textentry urlentry =
|
|
|
|
{CTK_TEXTENTRY(0, 1, WWW_CONF_WEBPAGE_WIDTH - 2,
|
|
|
|
1, editurl, WWW_CONF_MAX_URLLEN)};
|
|
|
|
static struct ctk_label webpagelabel =
|
|
|
|
{CTK_LABEL(0, 3, WWW_CONF_WEBPAGE_WIDTH,
|
|
|
|
WWW_CONF_WEBPAGE_HEIGHT, webpage)};
|
|
|
|
|
|
|
|
static char statustexturl[WWW_CONF_WEBPAGE_WIDTH];
|
|
|
|
static struct ctk_label statustext =
|
|
|
|
{CTK_LABEL(0, WWW_CONF_WEBPAGE_HEIGHT + 4,
|
|
|
|
WWW_CONF_WEBPAGE_WIDTH, 1, "")};
|
|
|
|
static struct ctk_separator sep2 =
|
|
|
|
{CTK_SEPARATOR(0, WWW_CONF_WEBPAGE_HEIGHT + 3,
|
|
|
|
WWW_CONF_WEBPAGE_WIDTH)};
|
|
|
|
|
2007-11-30 17:09:40 +01:00
|
|
|
#if WWW_CONF_WITH_WGET
|
2006-06-18 00:41:10 +02:00
|
|
|
static struct ctk_window wgetdialog;
|
|
|
|
static struct ctk_label wgetlabel1 =
|
|
|
|
{CTK_LABEL(1, 1, 34, 1, "This web page cannot be displayed.")};
|
|
|
|
static struct ctk_label wgetlabel2 =
|
|
|
|
{CTK_LABEL(1, 3, 35, 1, "Would you like to download instead?")};
|
|
|
|
static struct ctk_button wgetnobutton =
|
|
|
|
{CTK_BUTTON(1, 5, 6, "Cancel")};
|
|
|
|
static struct ctk_button wgetyesbutton =
|
|
|
|
{CTK_BUTTON(11, 5, 24, "Close browser & download")};
|
2007-11-30 17:09:40 +01:00
|
|
|
#endif /* WWW_CONF_WITH_WGET */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2010-02-13 11:39:57 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2006-06-18 00:41:10 +02:00
|
|
|
/* The char arrays that hold the history of visited URLs. */
|
|
|
|
static char history[WWW_CONF_HISTORY_SIZE][WWW_CONF_MAX_URLLEN];
|
|
|
|
static char history_last;
|
2010-02-13 11:39:57 +01:00
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
struct linkattrib {
|
|
|
|
struct ctk_hyperlink hyperlink;
|
|
|
|
char url[1];
|
2006-06-18 00:41:10 +02:00
|
|
|
};
|
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
struct inputattrib;
|
|
|
|
|
|
|
|
struct formattrib {
|
|
|
|
struct inputattrib *nextptr;
|
|
|
|
char action[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct inputattrib {
|
|
|
|
struct inputattrib *nextptr;
|
|
|
|
struct formattrib *formptr;
|
|
|
|
struct ctk_widget widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct textattrib {
|
|
|
|
struct inputattrib *nextptr;
|
|
|
|
struct formattrib *formptr;
|
|
|
|
struct ctk_textentry textentry;
|
|
|
|
char name[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct submitattrib {
|
|
|
|
struct inputattrib *nextptr;
|
|
|
|
struct formattrib *formptr;
|
|
|
|
struct ctk_button button;
|
|
|
|
char name[1];
|
2006-06-18 00:41:10 +02:00
|
|
|
};
|
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
static char pageattribs[WWW_CONF_PAGEATTRIB_SIZE];
|
|
|
|
static char *pageattribptr;
|
|
|
|
|
|
|
|
#if WWW_CONF_FORMS
|
|
|
|
static struct formattrib *formptr;
|
|
|
|
static struct inputattrib *currptr;
|
|
|
|
#endif /* WWW_CONF_FORMS */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
#define ISO_nl 0x0a
|
|
|
|
#define ISO_space 0x20
|
|
|
|
#define ISO_ampersand 0x26
|
|
|
|
#define ISO_plus 0x2b
|
|
|
|
#define ISO_slash 0x2f
|
|
|
|
#define ISO_eq 0x3d
|
|
|
|
#define ISO_questionmark 0x3f
|
|
|
|
|
|
|
|
/* The state of the rendering code. */
|
|
|
|
static char *webpageptr;
|
|
|
|
static unsigned char x, y;
|
|
|
|
static unsigned char loading;
|
|
|
|
static unsigned short firsty, pagey;
|
|
|
|
|
|
|
|
static unsigned char count;
|
|
|
|
static char receivingmsgs[4][23] = {
|
|
|
|
"Receiving web page ...",
|
|
|
|
"Receiving web page. ..",
|
|
|
|
"Receiving web page.. .",
|
|
|
|
"Receiving web page... "
|
|
|
|
};
|
|
|
|
|
|
|
|
PROCESS(www_process, "Web browser");
|
|
|
|
|
2008-02-07 17:28:11 +01:00
|
|
|
AUTOSTART_PROCESSES(&www_process);
|
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
static void CC_FASTCALL formsubmit(struct formattrib *form);
|
2007-11-30 17:09:40 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* make_window()
|
|
|
|
*
|
|
|
|
* Creates the web browser's window.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
make_window(void)
|
2009-02-25 09:52:27 +01:00
|
|
|
{
|
2010-02-13 11:39:57 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2006-06-18 00:41:10 +02:00
|
|
|
CTK_WIDGET_ADD(&mainwindow, &backbutton);
|
2010-02-13 11:39:57 +01:00
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2006-06-18 00:41:10 +02:00
|
|
|
CTK_WIDGET_ADD(&mainwindow, &downbutton);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &stopbutton);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &gobutton);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &urlentry);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &sep1);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &webpagelabel);
|
|
|
|
CTK_WIDGET_SET_FLAG(&webpagelabel, CTK_WIDGET_FLAG_MONOSPACE);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &sep2);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &statustext);
|
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
pageattribptr = pageattribs;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* redraw_window():
|
|
|
|
*
|
|
|
|
* Convenience function that calls upon CTK to redraw the browser
|
|
|
|
* window. */
|
|
|
|
static void
|
|
|
|
redraw_window(void)
|
|
|
|
{
|
|
|
|
ctk_window_redraw(&mainwindow);
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-03-06 16:29:36 +01:00
|
|
|
static char * CC_FASTCALL
|
|
|
|
add_pageattrib(unsigned size)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
if(pageattribptr + size > pageattribs + sizeof(pageattribs)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ptr = pageattribptr;
|
|
|
|
pageattribptr += size;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
#if WWW_CONF_FORMS
|
|
|
|
static void CC_FASTCALL
|
|
|
|
add_forminput(struct inputattrib *inputptr)
|
|
|
|
{
|
|
|
|
inputptr->nextptr = NULL;
|
|
|
|
currptr->nextptr = inputptr;
|
|
|
|
currptr = inputptr;
|
|
|
|
}
|
|
|
|
#endif /* WWW_CONF_FORMS */
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2006-06-18 00:41:10 +02:00
|
|
|
static void
|
|
|
|
clear_page(void)
|
|
|
|
{
|
|
|
|
ctk_window_clear(&mainwindow);
|
|
|
|
make_window();
|
|
|
|
redraw_window();
|
2009-02-25 09:52:27 +01:00
|
|
|
memset(webpage, 0, WWW_CONF_WEBPAGE_WIDTH * WWW_CONF_WEBPAGE_HEIGHT);
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
show_url(void)
|
|
|
|
{
|
|
|
|
memcpy(editurl, url, WWW_CONF_MAX_URLLEN);
|
|
|
|
strncpy(editurl, "http://", 7);
|
|
|
|
petsciiconv_topetscii(editurl + 7, WWW_CONF_MAX_URLLEN - 7);
|
|
|
|
CTK_WIDGET_REDRAW(&urlentry);
|
|
|
|
}
|
2007-11-30 17:09:40 +01:00
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2006-06-18 00:41:10 +02:00
|
|
|
static void
|
|
|
|
start_loading(void)
|
|
|
|
{
|
|
|
|
loading = 1;
|
|
|
|
x = y = 0;
|
|
|
|
pagey = 0;
|
|
|
|
webpageptr = webpage;
|
|
|
|
|
|
|
|
clear_page();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-03-06 16:29:36 +01:00
|
|
|
static void CC_FASTCALL
|
2006-06-18 00:41:10 +02:00
|
|
|
show_statustext(char *text)
|
|
|
|
{
|
|
|
|
ctk_label_set_text(&statustext, text);
|
|
|
|
CTK_WIDGET_REDRAW(&statustext);
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* open_url():
|
|
|
|
*
|
|
|
|
* Called when the URL present in the global "url" variable should be
|
|
|
|
* opened. It will call the hostname resolver as well as the HTTP
|
|
|
|
* client requester.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
open_url(void)
|
|
|
|
{
|
|
|
|
unsigned char i;
|
|
|
|
static char host[32];
|
|
|
|
char *file;
|
|
|
|
register char *urlptr;
|
2010-05-31 17:22:08 +02:00
|
|
|
static uip_ipaddr_t addr;
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/* Trim off any spaces in the end of the url. */
|
|
|
|
urlptr = url + strlen(url) - 1;
|
|
|
|
while(*urlptr == ' ' && urlptr > url) {
|
|
|
|
*urlptr = 0;
|
|
|
|
--urlptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't even try to go further if the URL is empty. */
|
|
|
|
if(urlptr == url) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if the URL starts with http://, otherwise prepend it. */
|
|
|
|
if(strncmp(url, http_http, 7) != 0) {
|
|
|
|
while(urlptr >= url) {
|
|
|
|
*(urlptr + 7) = *urlptr;
|
|
|
|
--urlptr;
|
|
|
|
}
|
|
|
|
strncpy(url, http_http, 7);
|
2009-02-25 09:52:27 +01:00
|
|
|
}
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/* Find host part of the URL. */
|
2009-02-25 09:52:27 +01:00
|
|
|
urlptr = &url[7];
|
2006-06-18 00:41:10 +02:00
|
|
|
for(i = 0; i < sizeof(host); ++i) {
|
|
|
|
if(*urlptr == 0 ||
|
|
|
|
*urlptr == '/' ||
|
|
|
|
*urlptr == ' ' ||
|
|
|
|
*urlptr == ':') {
|
|
|
|
host[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
host[i] = *urlptr;
|
|
|
|
++urlptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: Here we should find the port part of the URL, but this isn't
|
|
|
|
currently done because of laziness from the programmer's side
|
|
|
|
:-) */
|
|
|
|
|
|
|
|
/* Find file part of the URL. */
|
|
|
|
while(*urlptr != '/' && *urlptr != 0) {
|
|
|
|
++urlptr;
|
|
|
|
}
|
|
|
|
if(*urlptr == '/') {
|
|
|
|
file = urlptr;
|
|
|
|
} else {
|
|
|
|
file = "/";
|
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2010-02-01 20:44:30 +01:00
|
|
|
#if UIP_UDP
|
2006-06-18 00:41:10 +02:00
|
|
|
/* Try to lookup the hostname. If it fails, we initiate a hostname
|
|
|
|
lookup and print out an informative message on the statusbar. */
|
2010-05-31 17:22:08 +02:00
|
|
|
if(uiplib_ipaddrconv(host, &addr) == 0) {
|
2006-06-18 00:41:10 +02:00
|
|
|
if(resolv_lookup(host) == NULL) {
|
|
|
|
resolv_query(host);
|
|
|
|
show_statustext("Resolving host...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-02-01 20:44:30 +01:00
|
|
|
#else /* UIP_UDP */
|
2010-05-31 17:22:08 +02:00
|
|
|
uiplib_ipaddrconv(host, &addr);
|
2010-02-01 20:44:30 +01:00
|
|
|
#endif /* UIP_UDP */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
/* The hostname we present in the hostname table, so we send out the
|
|
|
|
initial GET request. */
|
|
|
|
if(webclient_get(host, 80, file) == 0) {
|
2013-02-18 23:08:05 +01:00
|
|
|
show_statustext("Out of memory error");
|
2006-06-18 00:41:10 +02:00
|
|
|
} else {
|
|
|
|
show_statustext("Connecting...");
|
|
|
|
}
|
|
|
|
redraw_window();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-03-06 16:29:36 +01:00
|
|
|
/* set_link(link):
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* Will format a link from the current web pages so that it suits the
|
2013-03-06 16:29:36 +01:00
|
|
|
* open_url() function.
|
2006-06-18 00:41:10 +02:00
|
|
|
*/
|
2013-03-06 16:29:36 +01:00
|
|
|
static void CC_FASTCALL
|
|
|
|
set_link(char *link)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
register char *urlptr;
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(strncmp(link, http_http, 7) == 0) {
|
|
|
|
/* The link starts with http://. We just copy the contents of the
|
|
|
|
link into the url string and jump away. */
|
|
|
|
strncpy(url, link, WWW_CONF_MAX_URLLEN);
|
|
|
|
} else if(*link == ISO_slash &&
|
|
|
|
*(link + 1) == ISO_slash) {
|
|
|
|
/* The link starts with //, so we'll copy it into the url
|
|
|
|
variable, starting after the http (which already is present in
|
|
|
|
the url variable since we were able to open the web page on
|
|
|
|
which this link was found in the first place). */
|
2009-02-25 09:52:27 +01:00
|
|
|
strncpy(&url[5], link, WWW_CONF_MAX_URLLEN);
|
2006-06-18 00:41:10 +02:00
|
|
|
} else if(*link == ISO_slash) {
|
|
|
|
/* The link starts with a slash, so it is a non-relative link
|
|
|
|
within the same web site. We find the start of the filename of
|
|
|
|
the current URL and paste the contents of this link there, and
|
|
|
|
head off to the new URL. */
|
|
|
|
for(urlptr = &url[7];
|
|
|
|
*urlptr != 0 && *urlptr != ISO_slash;
|
2009-02-25 09:52:27 +01:00
|
|
|
++urlptr);
|
|
|
|
strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url));
|
2006-06-18 00:41:10 +02:00
|
|
|
} else {
|
|
|
|
/* A fully relative link is found. We find the last slash in the
|
|
|
|
current URL and paste the link there. */
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/* XXX: we should really parse any ../ in the link as well. */
|
|
|
|
for(urlptr = url + strlen(url);
|
|
|
|
urlptr != url && *urlptr != ISO_slash;
|
|
|
|
--urlptr);
|
|
|
|
++urlptr;
|
2009-02-25 09:52:27 +01:00
|
|
|
strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url));
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2010-02-13 11:39:57 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2006-06-18 00:41:10 +02:00
|
|
|
/* log_back():
|
|
|
|
*
|
|
|
|
* Copies the current URL from the url variable and into the log for
|
|
|
|
* the back button.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
log_back(void)
|
|
|
|
{
|
|
|
|
if(strncmp(url, history[(int)history_last], WWW_CONF_MAX_URLLEN) != 0) {
|
|
|
|
memcpy(history[(int)history_last], url, WWW_CONF_MAX_URLLEN);
|
|
|
|
++history_last;
|
|
|
|
if(history_last >= WWW_CONF_HISTORY_SIZE) {
|
|
|
|
history_last = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-13 11:39:57 +01:00
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2006-06-18 00:41:10 +02:00
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
quit(void)
|
|
|
|
{
|
|
|
|
ctk_window_close(&mainwindow);
|
|
|
|
process_exit(&www_process);
|
|
|
|
LOADER_UNLOAD();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2007-11-30 17:09:40 +01:00
|
|
|
/* www_process():
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
2007-11-30 17:09:40 +01:00
|
|
|
* The program's signal dispatcher function. Is called whenever a signal arrives.
|
2006-06-18 00:41:10 +02:00
|
|
|
*/
|
|
|
|
PROCESS_THREAD(www_process, ev, data)
|
|
|
|
{
|
|
|
|
static struct ctk_widget *w;
|
|
|
|
static unsigned char i;
|
2007-11-30 17:09:40 +01:00
|
|
|
#if WWW_CONF_WITH_WGET
|
2006-06-18 00:41:10 +02:00
|
|
|
static char *argptr;
|
2007-11-30 17:09:40 +01:00
|
|
|
#endif /* WWW_CONF_WITH_WGET */
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
w = (struct ctk_widget *)data;
|
|
|
|
|
|
|
|
PROCESS_BEGIN();
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/* Create the main window. */
|
|
|
|
memset(webpage, 0, sizeof(webpage));
|
2009-02-25 09:52:27 +01:00
|
|
|
ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH,
|
2006-06-18 00:41:10 +02:00
|
|
|
WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser");
|
|
|
|
make_window();
|
|
|
|
#ifdef WWW_CONF_HOMEPAGE
|
|
|
|
strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl));
|
2009-02-25 09:52:27 +01:00
|
|
|
#endif /* WWW_CONF_HOMEPAGE */
|
2006-06-18 00:41:10 +02:00
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &urlentry);
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2007-11-30 17:09:40 +01:00
|
|
|
#if WWW_CONF_WITH_WGET
|
2006-06-18 00:41:10 +02:00
|
|
|
/* Create download dialog.*/
|
|
|
|
ctk_dialog_new(&wgetdialog, 38, 7);
|
|
|
|
CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1);
|
|
|
|
CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2);
|
|
|
|
CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton);
|
|
|
|
CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton);
|
2007-11-30 17:09:40 +01:00
|
|
|
#endif /* WWW_CONF_WITH_WGET */
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
ctk_window_open(&mainwindow);
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
while(1) {
|
|
|
|
|
|
|
|
PROCESS_WAIT_EVENT();
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(ev == tcpip_event) {
|
|
|
|
webclient_appcall(data);
|
|
|
|
} else if(ev == ctk_signal_widget_activate) {
|
2010-02-13 11:39:57 +01:00
|
|
|
if(w == (struct ctk_widget *)&gobutton ||
|
|
|
|
w == (struct ctk_widget *)&urlentry) {
|
|
|
|
start_loading();
|
|
|
|
firsty = 0;
|
2013-03-06 16:29:36 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2010-02-13 11:39:57 +01:00
|
|
|
log_back();
|
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
|
|
|
memcpy(url, editurl, WWW_CONF_MAX_URLLEN);
|
|
|
|
petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN);
|
|
|
|
open_url();
|
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &gobutton);
|
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
|
|
|
} else if(w == (struct ctk_widget *)&backbutton) {
|
2006-06-18 00:41:10 +02:00
|
|
|
firsty = 0;
|
|
|
|
start_loading();
|
|
|
|
--history_last;
|
|
|
|
if(history_last > WWW_CONF_HISTORY_SIZE) {
|
|
|
|
history_last = WWW_CONF_HISTORY_SIZE - 1;
|
|
|
|
}
|
|
|
|
memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN);
|
|
|
|
open_url();
|
2009-02-25 09:52:27 +01:00
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &backbutton);
|
2010-02-13 11:39:57 +01:00
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2006-06-18 00:41:10 +02:00
|
|
|
} else if(w == (struct ctk_widget *)&downbutton) {
|
|
|
|
firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4;
|
|
|
|
start_loading();
|
|
|
|
open_url();
|
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
|
|
|
|
} else if(w == (struct ctk_widget *)&stopbutton) {
|
|
|
|
loading = 0;
|
|
|
|
webclient_close();
|
2007-11-30 17:09:40 +01:00
|
|
|
#if WWW_CONF_WITH_WGET
|
2006-06-18 00:41:10 +02:00
|
|
|
} else if(w == (struct ctk_widget *)&wgetnobutton) {
|
|
|
|
ctk_dialog_close();
|
|
|
|
} else if(w == (struct ctk_widget *)&wgetyesbutton) {
|
2009-02-25 09:52:27 +01:00
|
|
|
ctk_dialog_close();
|
2006-06-18 00:41:10 +02:00
|
|
|
quit();
|
2007-11-18 02:24:39 +01:00
|
|
|
argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN);
|
2006-06-18 00:41:10 +02:00
|
|
|
if(argptr != NULL) {
|
|
|
|
strncpy(argptr, url, WWW_CONF_MAX_URLLEN);
|
2009-02-25 09:52:27 +01:00
|
|
|
}
|
2006-06-18 00:41:10 +02:00
|
|
|
program_handler_load("wget.prg", argptr);
|
2009-02-25 09:52:27 +01:00
|
|
|
#endif /* WWW_CONF_WITH_WGET */
|
2006-06-18 00:41:10 +02:00
|
|
|
#if WWW_CONF_FORMS
|
|
|
|
} else {
|
2013-03-06 16:29:36 +01:00
|
|
|
/* Assume form widget. */
|
|
|
|
struct inputattrib *input = (struct inputattrib *)
|
|
|
|
(((char *)w) - offsetof(struct inputattrib, widget));
|
|
|
|
formsubmit(input->formptr);
|
2006-06-18 00:41:10 +02:00
|
|
|
#endif /* WWW_CONF_FORMS */
|
|
|
|
}
|
|
|
|
} else if(ev == ctk_signal_hyperlink_activate) {
|
|
|
|
firsty = 0;
|
2010-02-13 11:39:57 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2006-06-18 00:41:10 +02:00
|
|
|
log_back();
|
2010-02-13 11:39:57 +01:00
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2013-03-06 16:29:36 +01:00
|
|
|
set_link(w->widget.hyperlink.url);
|
|
|
|
show_url();
|
|
|
|
open_url();
|
|
|
|
start_loading();
|
2006-06-18 00:41:10 +02:00
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &stopbutton);
|
|
|
|
} else if(ev == ctk_signal_hyperlink_hover) {
|
2013-03-06 16:29:36 +01:00
|
|
|
if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) {
|
2006-06-18 00:41:10 +02:00
|
|
|
strncpy(statustexturl, w->widget.hyperlink.url,
|
|
|
|
sizeof(statustexturl));
|
|
|
|
petsciiconv_topetscii(statustexturl, sizeof(statustexturl));
|
|
|
|
show_statustext(statustexturl);
|
|
|
|
}
|
2010-02-01 20:44:30 +01:00
|
|
|
#if UIP_UDP
|
2006-06-18 00:41:10 +02:00
|
|
|
} else if(ev == resolv_event_found) {
|
|
|
|
/* Either found a hostname, or not. */
|
2013-03-06 16:29:36 +01:00
|
|
|
if((char *)data != NULL && resolv_lookup((char *)data) != NULL) {
|
2006-06-18 00:41:10 +02:00
|
|
|
open_url();
|
|
|
|
} else {
|
2013-02-18 23:08:05 +01:00
|
|
|
show_statustext("Host not found");
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2010-02-01 20:44:30 +01:00
|
|
|
#endif /* UIP_UDP */
|
2006-06-18 00:41:10 +02:00
|
|
|
} else if(ev == ctk_signal_window_close ||
|
|
|
|
ev == PROCESS_EVENT_EXIT) {
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* set_url():
|
|
|
|
*
|
|
|
|
* Constructs an URL from the arguments and puts it into the global
|
|
|
|
* "url" variable and the visible "editurl" (which is shown in the URL
|
|
|
|
* text entry widget in the browser window).
|
|
|
|
*/
|
2013-03-06 16:29:36 +01:00
|
|
|
static void CC_FASTCALL
|
2012-02-20 20:13:50 +01:00
|
|
|
set_url(char *host, uint16_t port, char *file)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
|
|
|
char *urlptr;
|
|
|
|
|
|
|
|
memset(url, 0, WWW_CONF_MAX_URLLEN);
|
|
|
|
|
|
|
|
if(strncmp(file, http_http, 7) == 0) {
|
|
|
|
strncpy(url, file, sizeof(url));
|
|
|
|
} else {
|
|
|
|
strncpy(url, http_http, 7);
|
|
|
|
urlptr = url + 7;
|
|
|
|
strcpy(urlptr, host);
|
|
|
|
urlptr += strlen(host);
|
|
|
|
strcpy(urlptr, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
show_url();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* webclient_aborted():
|
|
|
|
*
|
|
|
|
* Callback function. Called from the webclient when the HTTP
|
|
|
|
* connection was abruptly aborted.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
webclient_aborted(void)
|
|
|
|
{
|
|
|
|
show_statustext("Connection reset by peer");
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* webclient_timedout():
|
|
|
|
*
|
|
|
|
* Callback function. Called from the webclient when the HTTP
|
|
|
|
* connection timed out.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
webclient_timedout(void)
|
|
|
|
{
|
|
|
|
show_statustext("Connection timed out");
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
/* webclient_closed():
|
|
|
|
*
|
|
|
|
* Callback function. Called from the webclient when the HTTP
|
|
|
|
* connection was closed after a request from the "webclient_close()"
|
2010-07-21 23:03:06 +02:00
|
|
|
* function.
|
2006-06-18 00:41:10 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
webclient_closed(void)
|
2009-02-25 09:52:27 +01:00
|
|
|
{
|
2013-02-18 23:08:05 +01:00
|
|
|
show_statustext("Stopped");
|
2010-07-21 23:03:06 +02:00
|
|
|
petsciiconv_topetscii(webpageptr - x, x);
|
2006-06-18 00:41:10 +02:00
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
|
|
|
|
redraw_window();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2010-07-21 23:03:06 +02:00
|
|
|
/* webclient_connected():
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* Callback function. Called from the webclient when the HTTP
|
|
|
|
* connection is connected.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
webclient_connected(void)
|
|
|
|
{
|
|
|
|
start_loading();
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
clear_page();
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
show_statustext("Request sent...");
|
|
|
|
set_url(webclient_hostname(), webclient_port(), webclient_filename());
|
|
|
|
|
|
|
|
htmlparser_init();
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2009-02-25 09:52:27 +01:00
|
|
|
/* webclient_datahandler():
|
2006-06-18 00:41:10 +02:00
|
|
|
*
|
|
|
|
* Callback function. Called from the webclient module when HTTP data
|
|
|
|
* has arrived.
|
|
|
|
*/
|
|
|
|
void
|
2012-02-20 20:13:50 +01:00
|
|
|
webclient_datahandler(char *data, uint16_t len)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
|
|
|
if(len > 0) {
|
2013-02-19 00:25:36 +01:00
|
|
|
if(strstr(webclient_mimetype(), http_html + 1) != 0) {
|
2006-06-18 00:41:10 +02:00
|
|
|
count = (count + 1) & 3;
|
|
|
|
show_statustext(receivingmsgs[count]);
|
|
|
|
htmlparser_parse(data, len);
|
|
|
|
redraw_window();
|
|
|
|
} else {
|
2013-02-18 23:08:05 +01:00
|
|
|
show_statustext("Cannot display web page");
|
2006-06-18 00:41:10 +02:00
|
|
|
uip_abort();
|
2007-11-30 17:09:40 +01:00
|
|
|
#if WWW_CONF_WITH_WGET
|
2006-06-18 00:41:10 +02:00
|
|
|
ctk_dialog_open(&wgetdialog);
|
2007-11-30 17:09:40 +01:00
|
|
|
#endif /* WWW_CONF_WITH_WGET */
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Clear remaining parts of page. */
|
|
|
|
loading = 0;
|
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(data == NULL) {
|
|
|
|
loading = 0;
|
2013-02-18 23:08:05 +01:00
|
|
|
show_statustext("Done");
|
2010-07-21 23:03:06 +02:00
|
|
|
petsciiconv_topetscii(webpageptr - x, x);
|
2006-06-18 00:41:10 +02:00
|
|
|
CTK_WIDGET_FOCUS(&mainwindow, &urlentry);
|
|
|
|
redraw_window();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-03-06 16:29:36 +01:00
|
|
|
static void CC_FASTCALL
|
|
|
|
add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char type,
|
|
|
|
unsigned char border)
|
2009-02-25 09:52:27 +01:00
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
char *wptr;
|
2006-06-18 00:41:10 +02:00
|
|
|
static unsigned char maxwidth;
|
|
|
|
|
|
|
|
if(!loading) {
|
2013-03-06 16:29:36 +01:00
|
|
|
return;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
|
|
|
if(textlen + border == 0) {
|
|
|
|
return;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
maxwidth = WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border);
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/* If the text of the link is too long so that it does not fit into
|
|
|
|
the width of the current window, counting from the current x
|
|
|
|
coordinate, we first try to jump to the next line. */
|
2013-03-06 16:29:36 +01:00
|
|
|
if(textlen + x > maxwidth) {
|
2006-06-18 00:41:10 +02:00
|
|
|
htmlparser_newline();
|
|
|
|
if(!loading) {
|
2013-03-06 16:29:36 +01:00
|
|
|
return;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the text of the link still is too long, we just chop it off!
|
|
|
|
XXX: this is not really the right thing to do, we should probably
|
|
|
|
either make a link into a multiline link, or add multiple
|
|
|
|
buttons. But this will do for now. */
|
2013-03-06 16:29:36 +01:00
|
|
|
if(textlen > maxwidth) {
|
2006-06-18 00:41:10 +02:00
|
|
|
text[maxwidth] = 0;
|
2013-03-06 16:29:36 +01:00
|
|
|
textlen = maxwidth;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(firsty == pagey) {
|
2013-03-06 16:29:36 +01:00
|
|
|
unsigned char attriblen = strlen(attrib);
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
wptr = webpageptr;
|
|
|
|
/* To save memory, we'll copy the widget text to the web page
|
|
|
|
drawing area and reference it from there. */
|
|
|
|
wptr[0] = 0;
|
|
|
|
wptr += border;
|
2013-03-06 16:29:36 +01:00
|
|
|
memcpy(wptr, text, textlen);
|
|
|
|
wptr[textlen] = 0;
|
|
|
|
wptr[textlen + border] = ' ';
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case CTK_WIDGET_HYPERLINK: {
|
|
|
|
struct linkattrib *linkptr;
|
|
|
|
|
|
|
|
linkptr = (struct linkattrib *)add_pageattrib(sizeof(struct linkattrib) /* incl 1 attrib char */ + attriblen);
|
|
|
|
if(linkptr != NULL) {
|
|
|
|
CTK_HYPERLINK_NEW(&linkptr->hyperlink, x, y + 3, textlen, wptr, linkptr->url);
|
|
|
|
strcpy(linkptr->url, attrib);
|
|
|
|
CTK_WIDGET_SET_FLAG(&linkptr->hyperlink, CTK_WIDGET_FLAG_MONOSPACE);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &linkptr->hyperlink);
|
|
|
|
}
|
2006-06-18 00:41:10 +02:00
|
|
|
break;
|
2013-03-06 16:29:36 +01:00
|
|
|
}
|
|
|
|
#if WWW_CONF_FORMS
|
|
|
|
case CTK_WIDGET_BUTTON: {
|
|
|
|
struct submitattrib *submitptr;
|
|
|
|
|
|
|
|
submitptr = (struct submitattrib *)add_pageattrib(sizeof(struct submitattrib) /* incl 1 attrib char */ + attriblen);
|
|
|
|
if(submitptr != NULL) {
|
|
|
|
CTK_BUTTON_NEW((struct ctk_button *)&submitptr->button, x, y + 3, textlen, wptr);
|
|
|
|
add_forminput((struct inputattrib *)submitptr);
|
|
|
|
submitptr->formptr = formptr;
|
|
|
|
strcpy(submitptr->name, attrib);
|
|
|
|
CTK_WIDGET_SET_FLAG(&submitptr->button, CTK_WIDGET_FLAG_MONOSPACE);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &submitptr->button);
|
|
|
|
}
|
2006-06-18 00:41:10 +02:00
|
|
|
break;
|
2013-03-06 16:29:36 +01:00
|
|
|
}
|
|
|
|
case CTK_WIDGET_TEXTENTRY: {
|
|
|
|
struct textattrib *textptr;
|
|
|
|
|
|
|
|
textptr = (struct textattrib *)add_pageattrib(sizeof(struct textattrib) /* incl 1 attrib char */ + attriblen + WWW_CONF_MAX_INPUTVALUELEN);
|
|
|
|
if(textptr != NULL) {
|
|
|
|
CTK_TEXTENTRY_NEW((struct ctk_textentry *)&textptr->textentry, x, y + 3, textlen, 1,
|
|
|
|
textptr->name + attriblen + 1, WWW_CONF_MAX_INPUTVALUELEN);
|
|
|
|
add_forminput((struct inputattrib *)textptr);
|
|
|
|
textptr->formptr = formptr;
|
|
|
|
strcpy(textptr->textentry.text, text);
|
|
|
|
strcpy(textptr->name, attrib);
|
|
|
|
CTK_WIDGET_SET_FLAG(&textptr->textentry, CTK_WIDGET_FLAG_MONOSPACE);
|
|
|
|
CTK_WIDGET_ADD(&mainwindow, &textptr->textentry);
|
|
|
|
}
|
2009-02-25 09:52:27 +01:00
|
|
|
break;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
#endif /* WWW_CONF_FORMS */
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Increase the x coordinate with the length of the link text plus
|
|
|
|
the extra space behind it and the CTK button markers. */
|
2013-03-06 16:29:36 +01:00
|
|
|
textlen = textlen + 1 + 2 * border;
|
|
|
|
x += textlen;
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
if(firsty == pagey) {
|
2013-03-06 16:29:36 +01:00
|
|
|
webpageptr += textlen;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(x == WWW_CONF_WEBPAGE_WIDTH) {
|
|
|
|
htmlparser_newline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
htmlparser_newline(void)
|
|
|
|
{
|
|
|
|
char *wptr;
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(pagey < firsty) {
|
|
|
|
++pagey;
|
|
|
|
x = 0;
|
|
|
|
return;
|
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(!loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
webpageptr += (WWW_CONF_WEBPAGE_WIDTH - x);
|
|
|
|
++y;
|
|
|
|
x = 0;
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
wptr = webpageptr - WWW_CONF_WEBPAGE_WIDTH;
|
2013-03-06 16:29:36 +01:00
|
|
|
petsciiconv_topetscii(wptr, WWW_CONF_WEBPAGE_WIDTH);
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
if(y == WWW_CONF_WEBPAGE_HEIGHT) {
|
|
|
|
loading = 0;
|
|
|
|
webclient_close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
htmlparser_word(char *word, unsigned char wordlen)
|
|
|
|
{
|
|
|
|
if(loading) {
|
|
|
|
if(wordlen + 1 > WWW_CONF_WEBPAGE_WIDTH - x) {
|
|
|
|
htmlparser_newline();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(loading) {
|
|
|
|
if(pagey == firsty) {
|
|
|
|
memcpy(webpageptr, word, wordlen);
|
2009-02-25 09:52:27 +01:00
|
|
|
webpageptr += wordlen;
|
2006-06-18 00:41:10 +02:00
|
|
|
*webpageptr = ' ';
|
|
|
|
++webpageptr;
|
|
|
|
}
|
|
|
|
x += wordlen + 1;
|
|
|
|
if(x == WWW_CONF_WEBPAGE_WIDTH) {
|
|
|
|
htmlparser_newline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
htmlparser_link(char *text, unsigned char textlen, char *url)
|
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
add_pagewidget(text, textlen, url, CTK_WIDGET_HYPERLINK, 0);
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-03-06 16:29:36 +01:00
|
|
|
#if WWW_CONF_FORMS
|
2006-06-18 00:41:10 +02:00
|
|
|
void
|
2013-03-06 16:29:36 +01:00
|
|
|
htmlparser_form(char *action)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
formptr = (struct formattrib *)add_pageattrib(sizeof(struct formattrib) + strlen(action));
|
|
|
|
if(formptr != NULL) {
|
|
|
|
formptr->nextptr = NULL;
|
|
|
|
currptr = (struct inputattrib *)formptr;
|
|
|
|
strcpy(formptr->action, action);
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
void
|
2013-03-06 16:29:36 +01:00
|
|
|
htmlparser_submitbutton(char *text, char *name)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
add_pagewidget(text, (unsigned char)strlen(text), name, CTK_WIDGET_BUTTON, 1);
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
void
|
2013-03-06 16:29:36 +01:00
|
|
|
htmlparser_inputfield(unsigned char size, char *text, char *name)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
add_pagewidget(text, size, name, CTK_WIDGET_TEXTENTRY, 1);
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
2013-03-06 16:29:36 +01:00
|
|
|
static void CC_FASTCALL
|
|
|
|
add_query(char delimiter, char *string)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
2013-03-06 16:29:36 +01:00
|
|
|
static char *query;
|
|
|
|
unsigned char length;
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
if(delimiter == ISO_questionmark) {
|
|
|
|
query = url + strlen(url);
|
|
|
|
}
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
length = strlen(string);
|
|
|
|
if(query - url + WWW_CONF_MAX_URLLEN - 1 /* delimiter */ < length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*query++ = delimiter;
|
|
|
|
strcpy(query, string);
|
|
|
|
if(delimiter == ISO_eq) {
|
|
|
|
char *space = query;
|
|
|
|
|
|
|
|
petsciiconv_toascii(query, length);
|
|
|
|
while((space = strchr(space, ISO_space)) != NULL) {
|
|
|
|
*space = ISO_plus;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
}
|
|
|
|
query += length;
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
static void CC_FASTCALL
|
|
|
|
formsubmit(struct formattrib *form)
|
|
|
|
{
|
|
|
|
struct inputattrib *inputptr;
|
|
|
|
char delimiter = ISO_questionmark;
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2013-03-06 16:29:36 +01:00
|
|
|
set_link(form->action);
|
|
|
|
|
|
|
|
for(inputptr = form->nextptr; inputptr != NULL; inputptr = inputptr->nextptr) {
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
if(inputptr->widget.type == CTK_WIDGET_BUTTON) {
|
|
|
|
name = ((struct submitattrib *)inputptr)->name;
|
|
|
|
value = ((struct submitattrib *)inputptr)->button.text;
|
|
|
|
} else {
|
|
|
|
name = ((struct textattrib *)inputptr)->name;
|
|
|
|
value = ((struct textattrib *)inputptr)->textentry.text;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
|
|
|
add_query(delimiter, name);
|
|
|
|
add_query(ISO_eq, value);
|
|
|
|
delimiter = ISO_ampersand;
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
2013-03-06 16:29:36 +01:00
|
|
|
|
2010-02-13 11:39:57 +01:00
|
|
|
#if WWW_CONF_HISTORY_SIZE > 0
|
2006-06-18 00:41:10 +02:00
|
|
|
log_back();
|
2010-02-13 11:39:57 +01:00
|
|
|
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
|
2013-03-06 16:29:36 +01:00
|
|
|
|
|
|
|
show_url();
|
|
|
|
open_url();
|
|
|
|
start_loading();
|
2006-06-18 00:41:10 +02:00
|
|
|
}
|
|
|
|
#endif /* WWW_CONF_FORMS */
|
2010-02-13 11:39:57 +01:00
|
|
|
/*-----------------------------------------------------------------------------------*/
|