NetSurf
uri.c
Go to the documentation of this file.
1/*
2 * Copyright 2003 Rob Jackson <jacko@xms.ms>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * RISC OS URI message handling implementation.
22 */
23
24#include "utils/config.h"
25
26#include <stdbool.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include "oslib/uri.h"
31#include "oslib/wimp.h"
32
33#include "utils/log.h"
34#include "utils/messages.h"
35#include "utils/nsurl.h"
36#include "content/fetch.h"
38
39#include "riscos/gui.h"
40#include "riscos/uri.h"
41#include "riscos/url_protocol.h"
42
43void ro_uri_message_received(wimp_message *msg)
44{
45 uri_full_message_process *uri_message = (uri_full_message_process *)msg;
46 uri_h uri_handle;
47 char* uri_requested;
48 int uri_length;
49 nsurl *url;
50 nserror error;
51
52 uri_handle = uri_message->handle;
53
54 if (nsurl_create(uri_message->uri, &url) != NSERROR_OK) {
55 return;
56 }
57
58 if (!fetch_can_fetch(url)) {
59 nsurl_unref(url);
60 return;
61 }
62
63 nsurl_unref(url);
64
65 uri_message->your_ref = uri_message->my_ref;
66 uri_message->action = message_URI_PROCESS_ACK;
67
68 xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)uri_message,
69 uri_message->sender);
70
71 xuri_request_uri(0, 0, 0, uri_handle, &uri_length);
72 uri_requested = calloc((unsigned int)uri_length, sizeof(char));
73 if (uri_requested == NULL)
74 return;
75
76 xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL);
77
78 error = nsurl_create(uri_requested, &url);
79 free(uri_requested);
80 if (error == NSERROR_OK) {
82 url,
83 NULL,
84 NULL,
85 NULL);
86 nsurl_unref(url);
87 }
88 if (error != NSERROR_OK) {
90 }
91}
92
93bool ro_uri_launch(const char *uri)
94{
95 uri_h uri_handle;
96 wimp_t handle_task;
97 uri_dispatch_flags returned;
98 os_error *e;
99
100 e = xuri_dispatch(uri_DISPATCH_INFORM_CALLER, uri, task_handle,
101 &returned, &handle_task, &uri_handle);
102
103 if (e || returned & 1) {
104 return false;
105 }
106
107 return true;
108}
109
110void ro_uri_bounce(wimp_message *msg)
111{
112 uri_full_message_process *message = (uri_full_message_process *)msg;
113 int size;
114 char *uri_buf;
115 os_error *e;
116
117 if ((message->flags & 1) == 0)
118 return;
119
120 /* Get required buffer size */
121 e = xuri_request_uri(0, NULL, 0, message->handle, &size);
122 if (e) {
123 NSLOG(netsurf, INFO, "xuri_request_uri: %d: %s", e->errnum,
124 e->errmess);
125 return;
126 }
127
128 uri_buf = malloc(size);
129 if (uri_buf == NULL)
130 return;
131
132 /* Get URI */
133 e = xuri_request_uri(0, uri_buf, size, message->handle, 0);
134 if (e) {
135 NSLOG(netsurf, INFO, "xuri_request_uri: %d: %s", e->errnum,
136 e->errmess);
137 free(uri_buf);
138 return;
139 }
140
141 ro_url_load(uri_buf);
142
143 free(uri_buf);
144
145 return;
146}
Browser window creation and manipulation interface.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
bool fetch_can_fetch(const nsurl *url)
Check if a URL's scheme can be fetched.
Definition: fetch.c:586
Fetching of data from a URL (interface).
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
Localised message support (interface).
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
wimp_t task_handle
RISC OS wimp task handle.
Definition: gui.c:115
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2076
Interface to utility string handling.
bool ro_uri_launch(const char *uri)
Definition: uri.c:93
void ro_uri_message_received(wimp_message *msg)
Definition: uri.c:43
void ro_uri_bounce(wimp_message *msg)
Definition: uri.c:110
void ro_url_load(const char *url)
Launch a program to handle an URL, using the ANT protocol Alias$URLOpen_ system.
Definition: url_protocol.c:183
ANT URL launching protocol (interface).