netsurf/amiga/launch.c

177 lines
3.9 KiB
C
Raw Normal View History

/*
* Copyright 2008-10 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* 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/>.
*/
/** \file
* Fetching of data from a file (implementation).
*/
#include "amiga/os3support.h"
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <proto/openurl.h>
2014-11-09 22:53:24 +03:00
#include "amiga/launch.h"
2013-05-26 01:46:27 +04:00
#include "utils/nsoption.h"
2014-07-01 01:38:58 +04:00
#include "utils/nsurl.h"
struct Library *OpenURLBase = NULL;
struct OpenURLIFace *IOpenURL = NULL;
struct MinList ami_unsupportedprotocols;
struct ami_protocol
{
struct MinNode node;
2014-10-26 13:04:24 +03:00
lwc_string *protocol;
};
2014-11-09 22:53:24 +03:00
static struct ami_protocol *ami_openurl_add_protocol(const char *url)
{
nsurl *ns_url;
struct ami_protocol *ami_p =
(struct ami_protocol *)AllocVecTagList(sizeof(struct ami_protocol), NULL);
2014-10-26 13:04:24 +03:00
if (nsurl_create(url, &ns_url) != NSERROR_OK) {
FreeVec(ami_p);
return NULL;
}
ami_p->protocol = nsurl_get_component(ns_url, NSURL_SCHEME);
nsurl_unref(ns_url);
2014-10-26 13:04:24 +03:00
if (ami_p->protocol == NULL)
{
FreeVec(ami_p);
return NULL;
}
AddTail((struct List *)&ami_unsupportedprotocols, (struct Node *)ami_p);
return ami_p;
}
2014-11-09 22:53:24 +03:00
static void ami_openurl_free_list(struct MinList *list)
{
struct ami_protocol *node;
struct ami_protocol *nnode;
if(IsMinListEmpty(list)) return;
node = (struct ami_protocol *)GetHead((struct List *)list);
do
{
nnode=(struct ami_protocol *)GetSucc((struct Node *)node);
Remove((struct Node *)node);
2014-10-26 13:04:24 +03:00
if (node->protocol) lwc_string_unref(node->protocol);
FreeVec(node);
node = NULL;
2014-11-09 22:53:24 +03:00
}while((node=nnode));
}
2014-11-09 22:53:24 +03:00
static BOOL ami_openurl_check_list(struct MinList *list, nsurl *url)
{
struct ami_protocol *node;
struct ami_protocol *nnode;
lwc_string *url_scheme;
bool match;
if(IsMinListEmpty(list)) return FALSE;
2014-10-26 13:30:22 +03:00
url_scheme = nsurl_get_component(url, NSURL_SCHEME);
node = (struct ami_protocol *)GetHead((struct List *)list);
do
{
nnode=(struct ami_protocol *)GetSucc((struct Node *)node);
2014-11-09 22:56:29 +03:00
if ((lwc_string_isequal(url_scheme, node->protocol,
&match) == lwc_error_ok) && (match == true)) {
lwc_string_unref(url_scheme);
return TRUE;
}
2014-11-09 22:53:24 +03:00
}while((node=nnode));
lwc_string_unref(url_scheme);
return FALSE;
}
/**
* Initialise the fetcher.
*
* Must be called once before any other function.
*/
void ami_openurl_open(void)
{
if(nsoption_bool(use_openurl_lib)) {
2015-01-19 02:54:21 +03:00
if((OpenURLBase = OpenLibrary("openurl.library",0))) {
#ifdef __amigaos4__
IOpenURL = (struct OpenURLIFace *)GetInterface(OpenURLBase,"main",1,NULL);
2015-01-19 02:54:21 +03:00
#endif
}
}
NewMinList(&ami_unsupportedprotocols);
}
2014-11-09 22:53:24 +03:00
void ami_openurl_close(void)
{
2015-01-19 02:54:21 +03:00
#ifdef __amigaos4__
if(IOpenURL) DropInterface((struct Interface *)IOpenURL);
2015-01-19 02:54:21 +03:00
#endif
if(OpenURLBase) CloseLibrary(OpenURLBase);
ami_openurl_free_list(&ami_unsupportedprotocols);
}
nserror gui_launch_url(struct nsurl *url)
{
2015-01-19 02:54:21 +03:00
#ifdef __amigaos4__
APTR procwin = SetProcWindow((APTR)-1L);
2015-01-19 02:54:21 +03:00
#endif
char *launchurl = NULL;
if(ami_openurl_check_list(&ami_unsupportedprotocols, url) == FALSE)
{
if(IOpenURL)
{
URL_OpenA((STRPTR)url,NULL);
} else {
2014-11-09 22:53:24 +03:00
if((launchurl = ASPrintf("URL:%s", nsurl_access(url)))) {
BPTR fptr = Open(launchurl,MODE_OLDFILE);
if(fptr)
{
Close(fptr);
} else {
ami_openurl_add_protocol(nsurl_access(url));
}
FreeVec(launchurl);
}
}
}
2015-01-19 02:54:21 +03:00
#ifdef __amigaos4__
SetProcWindow(procwin);
2015-01-19 02:54:21 +03:00
#endif
return NSERROR_OK;
}