2003-12-27 07:50:02 +03:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
* Shamelessly hacked from Rob Jackson's URI handler (see uri.c)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/inetsuite.h"
|
|
|
|
#include "oslib/wimp.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2004-04-13 03:59:01 +04:00
|
|
|
#include "netsurf/content/fetch.h"
|
2003-12-27 07:50:02 +03:00
|
|
|
#include "netsurf/desktop/browser.h"
|
|
|
|
#include "netsurf/riscos/theme.h"
|
|
|
|
#include "netsurf/desktop/gui.h"
|
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-04-02 04:41:10 +04:00
|
|
|
#include "netsurf/riscos/uri.h"
|
2004-03-02 21:02:41 +03:00
|
|
|
#include "netsurf/riscos/url_protocol.h"
|
2003-12-27 07:50:02 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
2003-12-27 20:25:19 +03:00
|
|
|
/* Define this to allow posting of data to an URL */
|
|
|
|
#undef ALLOW_POST
|
|
|
|
|
|
|
|
static char *read_string_value(os_string_value string, char *msg);
|
|
|
|
|
2003-12-27 07:50:02 +03:00
|
|
|
void ro_url_message_received(wimp_message* message)
|
|
|
|
{
|
|
|
|
char* uri_requested = NULL;
|
2003-12-27 20:25:19 +03:00
|
|
|
#ifdef ALLOW_POST
|
|
|
|
char* filename = NULL, *mimetype = NULL;
|
|
|
|
bool post=false;
|
2003-12-27 07:50:02 +03:00
|
|
|
struct browser_window* bw;
|
2004-04-13 03:59:01 +04:00
|
|
|
#endif
|
2003-12-27 07:50:02 +03:00
|
|
|
inetsuite_message_open_url *url_message = (inetsuite_message_open_url*)&message->data;
|
|
|
|
|
2003-12-27 20:25:19 +03: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) {
|
2003-12-27 07:50:02 +03:00
|
|
|
uri_requested = xstrdup(url_message->url);
|
|
|
|
LOG(("%s", url_message->url));
|
|
|
|
}
|
|
|
|
else {
|
2003-12-27 20:25:19 +03:00
|
|
|
/* Get URL */
|
|
|
|
if (read_string_value(url_message->indirect.url,
|
|
|
|
(char*)url_message) != 0) {
|
|
|
|
uri_requested = xstrdup(read_string_value(url_message->indirect.url,
|
|
|
|
(char*)url_message));
|
2003-12-27 07:50:02 +03:00
|
|
|
}
|
2003-12-27 20:25:19 +03:00
|
|
|
else {
|
|
|
|
return;
|
2003-12-27 07:50:02 +03:00
|
|
|
}
|
|
|
|
LOG(("%s", uri_requested));
|
2003-12-27 20:25:19 +03:00
|
|
|
|
|
|
|
#ifdef ALLOW_POST
|
|
|
|
/* Get filename */
|
|
|
|
if (read_string_value(url_message->indirect.body_file,
|
|
|
|
(char*)url_message) != 0) {
|
|
|
|
filename = xstrdup(read_string_value(url_message->indirect.body_file,
|
|
|
|
(char*)url_message));
|
|
|
|
}
|
|
|
|
/* We ignore the target window. Just open a new window. */
|
|
|
|
/* Get mimetype */
|
|
|
|
if (url_message->indirect.flags & inetsuite_USE_MIME_TYPE) {
|
|
|
|
if (read_string_value(url_message->indirect.body_mimetype,
|
|
|
|
(char*)url_message) != 0) {
|
|
|
|
mimetype = xstrdup(read_string_value(url_message->indirect.body_mimetype,
|
|
|
|
(char*)url_message));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mimetype = xstrdup("application/x-www-form-urlencoded");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mimetype = xstrdup("application/x-www-form-urlencoded");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Indicate a post request */
|
|
|
|
if (filename && message->size > 28)
|
|
|
|
post = true;
|
2003-12-27 07:50:02 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-04-13 03:59:01 +04:00
|
|
|
if (!fetch_can_fetch(uri_requested)) {
|
2003-12-27 20:25:19 +03:00
|
|
|
#ifdef ALLOW_POST
|
|
|
|
xfree(filename);
|
|
|
|
xfree(mimetype);
|
|
|
|
#endif
|
2003-12-27 07:50:02 +03:00
|
|
|
xfree(uri_requested);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send ack */
|
|
|
|
message->your_ref = message->my_ref;
|
|
|
|
xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, message,
|
|
|
|
message->sender);
|
|
|
|
|
|
|
|
/* create new browser window */
|
2004-05-05 02:23:44 +04:00
|
|
|
browser_window_create(uri_requested, NULL);
|
2003-12-27 20:25:19 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
#if 0
|
2003-12-27 20:25:19 +03:00
|
|
|
if (post) {
|
|
|
|
/* TODO - create urlencoded data from file contents.
|
|
|
|
* Delete the file when finished with it.
|
|
|
|
*/
|
|
|
|
browser_window_open_location_historical(bw, uri_requested, /*data*/0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2003-12-27 07:50:02 +03:00
|
|
|
|
2003-12-27 20:25:19 +03:00
|
|
|
#ifdef ALLOW_POST
|
|
|
|
xfree(filename);
|
|
|
|
xfree(mimetype);
|
|
|
|
#endif
|
2003-12-27 07:50:02 +03:00
|
|
|
xfree(uri_requested);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2003-12-27 20:25:19 +03:00
|
|
|
|
|
|
|
char *read_string_value(os_string_value string, char *msg) {
|
|
|
|
|
|
|
|
if(string.offset == 0) return NULL;
|
|
|
|
if(string.offset > 256) return string.pointer;
|
|
|
|
return &msg[string.offset];
|
|
|
|
}
|
2004-04-02 04:41:10 +04:00
|
|
|
|
|
|
|
bool ro_url_broadcast(char *url) {
|
|
|
|
|
|
|
|
inetsuite_full_message_open_url_direct message;
|
|
|
|
os_error *e;
|
2004-04-02 19:16:15 +04:00
|
|
|
int len = ((strlen(url)+1)>235) ? 235 : strlen(url)+1;
|
|
|
|
|
|
|
|
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-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
*message.url = 0;
|
|
|
|
strncat(message.url, url, 235);
|
2004-04-02 19:16:15 +04:00
|
|
|
message.url[len-1] = 0;
|
|
|
|
e = xwimp_send_message(wimp_USER_MESSAGE_RECORDED,
|
2004-04-02 04:41:10 +04:00
|
|
|
(wimp_message*)&message, 0);
|
|
|
|
if (e) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ro_url_load(char *url) {
|
|
|
|
|
|
|
|
char url_buf[512];
|
|
|
|
char *colon;
|
|
|
|
os_error *e;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
colon = strchr(url, ':');
|
|
|
|
if (!colon) return false;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
strcpy(url_buf, "Alias$URLOpen_");
|
|
|
|
strncat(url_buf, url, colon-url);
|
|
|
|
if (!getenv(url_buf)) return false;
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
strcat(url_buf, " ");
|
|
|
|
strncat(url_buf, url, 512-strlen(url_buf)-1);
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
e = xwimp_start_task(url_buf+5, 0);
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
if (e) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-02 19:16:15 +04:00
|
|
|
|
2004-04-02 04:41:10 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|