2003-12-27 07:50:02 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
2004-05-13 18:39:43 +04:00
|
|
|
* Copyright 2003 Rob Jackson <jacko@xms.ms>
|
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-12-27 07:50:02 +03:00
|
|
|
*/
|
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/** \file
|
|
|
|
* ANT URL launching protocol (implementation).
|
|
|
|
*
|
|
|
|
* See http://www.vigay.com/inet/inet_url.html
|
|
|
|
*/
|
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
#include <ctype.h>
|
2003-12-27 07:50:02 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/inetsuite.h"
|
|
|
|
#include "oslib/wimp.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/uri.h"
|
|
|
|
#include "riscos/url_protocol.h"
|
|
|
|
#include "utils/log.h"
|
2011-09-27 16:02:15 +04:00
|
|
|
#include "utils/nsurl.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/utils.h"
|
2003-12-27 07:50:02 +03:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/**
|
|
|
|
* Handle a Message_InetSuiteOpenURL.
|
|
|
|
*/
|
2003-12-27 20:25:19 +03:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
void ro_url_message_received(wimp_message *message)
|
2003-12-27 07:50:02 +03:00
|
|
|
{
|
2004-05-13 18:39:43 +04:00
|
|
|
char *url;
|
|
|
|
int i;
|
|
|
|
inetsuite_message_open_url *url_message =
|
|
|
|
(inetsuite_message_open_url*) &message->data;
|
|
|
|
os_error *error;
|
2011-09-27 16:02:15 +04:00
|
|
|
nsurl *nsurl;
|
2004-05-13 18:39:43 +04:00
|
|
|
|
|
|
|
/* If the url_message->indirect.tag is non-zero,
|
|
|
|
* then the message data is contained within the message block.
|
|
|
|
*/
|
|
|
|
if (url_message->indirect.tag != 0) {
|
|
|
|
url = strndup(url_message->url, 236);
|
|
|
|
if (!url) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* terminate at first control character */
|
|
|
|
for (i = 0; !iscntrl(url[i]); i++)
|
|
|
|
;
|
|
|
|
url[i] = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!url_message->indirect.url.offset) {
|
|
|
|
LOG(("no URL in message"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (28 < message->size &&
|
|
|
|
url_message->indirect.body_file.offset) {
|
|
|
|
LOG(("POST for URL message not implemented"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (url_message->indirect.url.offset < 28 ||
|
|
|
|
236 <= url_message->indirect.url.offset) {
|
|
|
|
LOG(("external pointers in URL message unimplemented"));
|
|
|
|
/* these messages have never been seen in the wild,
|
|
|
|
* and there is the problem of invalid addresses which
|
|
|
|
* would cause an abort */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = strndup((char *) url_message +
|
|
|
|
url_message->indirect.url.offset,
|
|
|
|
236 - url_message->indirect.url.offset);
|
|
|
|
if (!url) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; !iscntrl(url[i]); i++)
|
|
|
|
;
|
|
|
|
url[i] = 0;
|
|
|
|
}
|
|
|
|
|
2011-09-27 16:02:15 +04:00
|
|
|
if (nsurl_create(url, &nsurl) != NSERROR_OK) {
|
2004-05-13 18:39:43 +04:00
|
|
|
free(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-27 16:02:15 +04:00
|
|
|
if (!fetch_can_fetch(nsurl)) {
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
free(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/* send ack */
|
|
|
|
message->your_ref = message->my_ref;
|
|
|
|
error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, message,
|
|
|
|
message->sender);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_send_message: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
}
|
2003-12-27 20:25:19 +03:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/* create new browser window */
|
2008-08-24 14:31:38 +04:00
|
|
|
browser_window_create(url, 0, 0, true, false);
|
2003-12-27 20:25:19 +03:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
free(url);
|
2003-12-27 20:25:19 +03:00
|
|
|
}
|
2004-04-02 04:41:10 +04:00
|
|
|
|
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/**
|
|
|
|
* Broadcast an ANT URL message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_url_broadcast(const char *url)
|
|
|
|
{
|
2004-04-02 04:41:10 +04:00
|
|
|
inetsuite_full_message_open_url_direct message;
|
2004-05-13 18:39:43 +04:00
|
|
|
os_error *error;
|
|
|
|
int len = strlen(url) + 1;
|
|
|
|
|
2009-07-01 16:05:51 +04:00
|
|
|
/* If URL is too long, then forget ANT and try URI, instead */
|
|
|
|
if (236 < len) {
|
|
|
|
ro_uri_launch(url);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
|
|
|
message.size = ((20+len+3) & ~3);
|
2004-04-02 04:41:10 +04:00
|
|
|
message.your_ref = 0;
|
|
|
|
message.action = message_INET_SUITE_OPEN_URL;
|
2004-05-13 18:39:43 +04:00
|
|
|
strncpy(message.url, url, 235);
|
|
|
|
message.url[235] = 0;
|
|
|
|
error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message *) &message, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_send_message: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
2004-04-02 04:41:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/**
|
|
|
|
* Launch a program to handle an URL, using the ANT protocol
|
|
|
|
* Alias$URLOpen_ system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_url_load(const char *url)
|
|
|
|
{
|
|
|
|
char *command;
|
2004-04-02 04:41:10 +04:00
|
|
|
char *colon;
|
2004-05-13 18:39:43 +04:00
|
|
|
os_error *error;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
colon = strchr(url, ':');
|
2004-05-13 18:39:43 +04:00
|
|
|
if (!colon) {
|
|
|
|
LOG(("invalid url '%s'", url));
|
|
|
|
return;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
command = malloc(40 + (colon - url) + strlen(url));
|
|
|
|
if (!command) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2009-03-27 04:15:52 +03:00
|
|
|
sprintf(command, "Alias$URLOpen_%.*s", (int) (colon - url), url);
|
2004-05-13 18:39:43 +04:00
|
|
|
if (!getenv(command)) {
|
|
|
|
free(command);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2009-03-27 04:15:52 +03:00
|
|
|
sprintf(command, "URLOpen_%.*s %s", (int) (colon - url), url, url);
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
error = xwimp_start_task(command, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_start_task: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
2004-04-02 04:41:10 +04:00
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
free(command);
|
2004-04-02 04:41:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-13 18:39:43 +04:00
|
|
|
/**
|
|
|
|
* Handle a bounced Message_InetSuiteOpenURL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_url_bounce(wimp_message *message)
|
|
|
|
{
|
|
|
|
inetsuite_message_open_url *url_message =
|
|
|
|
(inetsuite_message_open_url*) &message->data;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
/* ant broadcast bounced -> try uri broadcast / load */
|
|
|
|
ro_uri_launch(url_message->url);
|
|
|
|
}
|
2004-09-14 03:59:30 +04:00
|
|
|
|