NetSurf
launch.c
Go to the documentation of this file.
1/*
2 * Copyright 2008-10 Chris Young <chris@unsatisfactorysoftware.co.uk>
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/** \file
20 * Fetching of data from a file (implementation).
21 */
22
23#include "amiga/os3support.h"
24
25#include <string.h>
26#include <stdbool.h>
27#include <stdlib.h>
28#include <proto/exec.h>
29#include <proto/dos.h>
30#include <proto/utility.h>
31#include <proto/openurl.h>
32
33#include "amiga/launch.h"
34#include "amiga/object.h" /* for list abstraction */
35#include "utils/nsoption.h"
36#include "utils/nsurl.h"
37
38struct Library *OpenURLBase = NULL;
39struct OpenURLIFace *IOpenURL = NULL;
40
41static struct MinList *ami_unsupportedprotocols;
42
44{
45 struct MinNode node;
46 lwc_string *protocol;
47};
48
49static struct ami_protocol *ami_openurl_add_protocol(const char *url)
50{
51 nsurl *ns_url;
52 struct ami_protocol *ami_p =
53 (struct ami_protocol *)malloc(sizeof(struct ami_protocol));
54
55 if (nsurl_create(url, &ns_url) != NSERROR_OK) {
56 free(ami_p);
57 return NULL;
58 }
59
61 nsurl_unref(ns_url);
62 if (ami_p->protocol == NULL)
63 {
64 free(ami_p);
65 return NULL;
66 }
67
68 AddTail((struct List *)ami_unsupportedprotocols, (struct Node *)ami_p);
69 return ami_p;
70}
71
72static void ami_openurl_free_list(struct MinList *list)
73{
74 struct ami_protocol *node;
75 struct ami_protocol *nnode;
76
77 if(!IsMinListEmpty(list)) {
78 node = (struct ami_protocol *)GetHead((struct List *)list);
79
80 do
81 {
82 nnode=(struct ami_protocol *)GetSucc((struct Node *)node);
83
84 Remove((struct Node *)node);
85 if (node->protocol) lwc_string_unref(node->protocol);
86 free(node);
87 node = NULL;
88 }while((node=nnode));
89 }
90 free(list);
91}
92
93static BOOL ami_openurl_check_list(struct MinList *list, nsurl *url)
94{
95 struct ami_protocol *node;
96 struct ami_protocol *nnode;
97 lwc_string *url_scheme;
98 bool match;
99
100 if(IsMinListEmpty(list)) return FALSE;
101
102 url_scheme = nsurl_get_component(url, NSURL_SCHEME);
103
104 node = (struct ami_protocol *)GetHead((struct List *)list);
105
106 do
107 {
108 nnode=(struct ami_protocol *)GetSucc((struct Node *)node);
109
110 if ((lwc_string_isequal(url_scheme, node->protocol,
111 &match) == lwc_error_ok) && (match == true)) {
112 lwc_string_unref(url_scheme);
113 return TRUE;
114 }
115 }while((node=nnode));
116
117 lwc_string_unref(url_scheme);
118 return FALSE;
119}
120
121/**
122 * Initialise the fetcher.
123 *
124 * Must be called once before any other function.
125 */
126
128{
129 if(nsoption_bool(use_openurl_lib)) {
130 if((OpenURLBase = OpenLibrary("openurl.library",0))) {
131#ifdef __amigaos4__
132 IOpenURL = (struct OpenURLIFace *)GetInterface(OpenURLBase,"main",1,NULL);
133#endif
134 }
135 }
136
138}
139
141{
142#ifdef __amigaos4__
143 if(IOpenURL) DropInterface((struct Interface *)IOpenURL);
144#endif
145 if(OpenURLBase) CloseLibrary(OpenURLBase);
146
148}
149
151{
152#ifdef __amigaos4__
153 APTR procwin = SetProcWindow((APTR)-1L);
154#endif
155 char *launchurl = NULL;
156
158 {
159 if(IOpenURL)
160 {
161 URL_OpenA((STRPTR)url,NULL);
162 } else {
163 if((launchurl = ASPrintf("URL:%s", nsurl_access(url)))) {
164 BPTR fptr = Open(launchurl,MODE_OLDFILE);
165 if(fptr)
166 {
167 Close(fptr);
168 } else {
170 }
171 FreeVec(launchurl);
172 }
173 }
174 }
175#ifdef __amigaos4__
176 SetProcWindow(procwin);
177#endif
178 return NSERROR_OK;
179}
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
struct MinList * ami_AllocMinList(void)
List abstraction as OS3 appears to have problems with NewMinList()
Definition: object.c:63
static BOOL ami_openurl_check_list(struct MinList *list, nsurl *url)
Definition: launch.c:93
nserror gui_launch_url(struct nsurl *url)
Definition: launch.c:150
struct OpenURLIFace * IOpenURL
Definition: launch.c:39
void ami_openurl_open(void)
Initialise the fetcher.
Definition: launch.c:127
struct Library * OpenURLBase
Definition: launch.c:38
void ami_openurl_close(void)
Definition: launch.c:140
static void ami_openurl_free_list(struct MinList *list)
Definition: launch.c:72
static struct ami_protocol * ami_openurl_add_protocol(const char *url)
Definition: launch.c:49
static struct MinList * ami_unsupportedprotocols
Definition: launch.c:41
Fetching of data from a URL (Registration).
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.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
lwc_string * nsurl_get_component(const nsurl *url, nsurl_component part)
Get part of a URL as a lwc_string, from a NetSurf URL object.
@ NSURL_SCHEME
Definition: nsurl.h:45
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
char * ASPrintf(const char *fmt,...)
Definition: os3support.c:139
struct Node * GetHead(struct List *list)
Definition: os3support.c:364
struct Node * GetSucc(struct Node *node)
Definition: os3support.c:381
Minimal compatibility header for AmigaOS 3.
#define IsMinListEmpty(L)
Definition: os3support.h:54
Interface to utility string handling.
struct MinNode node
Definition: launch.c:45
lwc_string * protocol
Definition: launch.c:46
Option reading and saving interface.
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:270