summaryrefslogtreecommitdiff
path: root/riscos/uri.c
blob: 986a84022693daa2a0673eec7596e79912a26df4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright 2003 Rob Jackson <jacko@xms.ms>
 *
 * 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/>.
 */

#include "utils/config.h"

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oslib/uri.h"
#include "oslib/wimp.h"
#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"
#include "utils/nsurl.h"
#include "utils/utils.h"

void ro_uri_message_received(wimp_message *msg)
{
	uri_full_message_process *uri_message = (uri_full_message_process *)msg;
	uri_h uri_handle;
	char* uri_requested;
	int uri_length;
	nsurl *nsurl;

	uri_handle = uri_message->handle;

	if (nsurl_create(uri_message->uri, &nsurl) != NSERROR_OK) {
		return;
	}

	if (!fetch_can_fetch(nsurl)) {
		nsurl_unref(nsurl);
		return;
	}

	nsurl_unref(nsurl);

	uri_message->your_ref = uri_message->my_ref;
	uri_message->action = message_URI_PROCESS_ACK;

	xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)uri_message,
		uri_message->sender);

	xuri_request_uri(0, 0, 0, uri_handle, &uri_length);
	uri_requested = calloc((unsigned int)uri_length, sizeof(char));
	if (uri_requested == NULL)
		return;

	xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL);

	browser_window_create(uri_requested, NULL, 0, true, false);

	free(uri_requested);
}

bool ro_uri_launch(const char *uri)
{
	uri_h uri_handle;
	wimp_t handle_task;
	uri_dispatch_flags returned;
	os_error *e;

	e = xuri_dispatch(uri_DISPATCH_INFORM_CALLER, uri, task_handle,
			&returned, &handle_task, &uri_handle);

	if (e || returned & 1) {
		return false;
	}

	return true;
}

void ro_uri_bounce(wimp_message *msg)
{
	uri_full_message_process *message = (uri_full_message_process *)msg;
	int size;
	char *uri_buf;
	os_error *e;

	if ((message->flags & 1) == 0)
		return;

	/* Get required buffer size */
	e = xuri_request_uri(0, NULL, 0, message->handle, &size);
	if (e) {
		LOG(("xuri_request_uri: %d: %s", e->errnum, e->errmess));
		return;
	}

	uri_buf = malloc(size);
	if (uri_buf == NULL)
		return;

	/* Get URI */
	e = xuri_request_uri(0, uri_buf, size, message->handle, 0);
	if (e) {
		LOG(("xuri_request_uri: %d: %s", e->errnum, e->errmess));
		free(uri_buf);
		return;
	}

	ro_url_load(uri_buf);

	free(uri_buf);

	return;
}