/* open_link(link): * * Will format a link from the current web pages so that it suits the * open_url() function and finally call it to open the requested URL. */ static void open_link(char *link) { char *urlptr; 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). */ strncpy(&url[5], link, WWW_CONF_MAX_URLLEN); } 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; ++urlptr); strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url)); } else { /* A fully relative link is found. We find the last slash in the current URL and paste the link there. */ /* XXX: we should really parse any ../ in the link as well. */ for(urlptr = url + strlen(url); urlptr != url && *urlptr != ISO_slash; --urlptr); ++urlptr; strncpy(urlptr, link, WWW_CONF_MAX_URLLEN - (urlptr - url)); } /* Open the URL. */ show_url(); open_url(); start_loading(); }
/* 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). */ static void set_url(char *host, u16_t port, char *file) { 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(); }
/* www_process(): * * The program's signal dispatcher function. Is called whenever a signal arrives. */ PROCESS_THREAD(www_process, ev, data) { static struct ctk_widget *w; #if WWW_CONF_WITH_WGET static char *argptr; #endif /* WWW_CONF_WITH_WGET */ w = (struct ctk_widget *)data; PROCESS_BEGIN(); /* Create the main window. */ memset(webpage, 0, sizeof(webpage)); ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH, WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser"); make_window(); #ifdef WWW_CONF_HOMEPAGE strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl)); #endif /* WWW_CONF_HOMEPAGE */ CTK_WIDGET_FOCUS(&mainwindow, &urlentry); #if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC) #if CTK_CONF_WINDOWS /* 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); #endif /* CTK_CONF_WINDOWS */ #endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */ ctk_window_open(&mainwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { webclient_appcall(data); } else if(ev == ctk_signal_widget_activate) { if(w == (struct ctk_widget *)&gobutton || w == (struct ctk_widget *)&urlentry) { start_loading(); firsty = 0; #if WWW_CONF_HISTORY_SIZE > 0 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) { 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(); CTK_WIDGET_FOCUS(&mainwindow, &backbutton); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ } 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(); #if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC) } else if(w == (struct ctk_widget *)&wgetnobutton) { #if CTK_CONF_WINDOWS ctk_dialog_close(); #else /* CTK_CONF_WINDOWS */ clear_page(); #endif /* CTK_CONF_WINDOWS */ } else if(w == (struct ctk_widget *)&wgetyesbutton) { #if CTK_CONF_WINDOWS ctk_dialog_close(); #else /* CTK_CONF_WINDOWS */ clear_page(); #endif /* CTK_CONF_WINDOWS */ #if WWW_CONF_WITH_WGET quit(); argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN); if(argptr != NULL) { strncpy(argptr, url, WWW_CONF_MAX_URLLEN); } program_handler_load("wget.prg", argptr); #else /* WWW_CONF_WITH_WGET */ petsciiconv_topetscii(url, sizeof(url)); /* Clear screen */ ctk_restore(); WWW_CONF_WGET_EXEC(url); redraw_window(); show_statustext("Cannot exec wget"); #endif /* WWW_CONF_WITH_WGET */ #endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */ #if WWW_CONF_FORMS } else { /* Assume form widget. */ struct inputattrib *input = (struct inputattrib *) (((char *)w) - offsetof(struct inputattrib, widget)); formsubmit(input->formptr); #endif /* WWW_CONF_FORMS */ } } else if(ev == ctk_signal_hyperlink_activate) { firsty = 0; #if WWW_CONF_HISTORY_SIZE > 0 log_back(); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ set_link(w->widget.hyperlink.url); show_url(); open_url(); start_loading(); CTK_WIDGET_FOCUS(&mainwindow, &stopbutton); } else if(ev == ctk_signal_hyperlink_hover) { if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) { strncpy(statustexturl, w->widget.hyperlink.url, sizeof(statustexturl)); petsciiconv_topetscii(statustexturl, sizeof(statustexturl)); show_statustext(statustexturl); } #if UIP_UDP } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) { open_url(); } else { show_statustext("Host not found"); } #endif /* UIP_UDP */ } else if(ev == ctk_signal_window_close || ev == PROCESS_EVENT_EXIT) { quit(); } }
//------------------------------------------------------------------------------ void TCErisoApp::MItemAuthorWebClicked() { show_url(SHINTA_URL_AUTHOR_WEB); }