2008-12-14 02:28:26 +03:00
|
|
|
/*
|
2010-03-15 02:00:39 +03:00
|
|
|
* Copyright 2008-10 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2008-12-14 02:28:26 +03:00
|
|
|
*
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
|
2011-01-07 03:14:37 +03:00
|
|
|
#include "amiga/os3support.h"
|
|
|
|
|
2008-12-14 02:28:26 +03:00
|
|
|
#include <string.h>
|
2010-09-12 15:29:58 +04:00
|
|
|
#include <stdbool.h>
|
2011-01-07 03:14:37 +03:00
|
|
|
#include <stdlib.h>
|
2008-12-14 02:28:26 +03:00
|
|
|
#include <proto/exec.h>
|
2010-01-16 18:53:00 +03:00
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/utility.h>
|
2008-12-14 02:28:26 +03:00
|
|
|
#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"
|
2012-04-18 23:44:09 +04:00
|
|
|
|
|
|
|
struct Library *OpenURLBase = NULL;
|
|
|
|
struct OpenURLIFace *IOpenURL = NULL;
|
2008-12-14 02:28:26 +03:00
|
|
|
|
2010-09-12 15:29:58 +04:00
|
|
|
struct MinList ami_unsupportedprotocols;
|
|
|
|
|
|
|
|
struct ami_protocol
|
|
|
|
{
|
|
|
|
struct MinNode node;
|
2014-10-26 13:04:24 +03:00
|
|
|
lwc_string *protocol;
|
2010-09-12 15:29:58 +04:00
|
|
|
};
|
|
|
|
|
2014-11-09 22:53:24 +03:00
|
|
|
static struct ami_protocol *ami_openurl_add_protocol(const char *url)
|
2010-09-12 15:29:58 +04:00
|
|
|
{
|
2014-10-26 13:25:31 +03:00
|
|
|
nsurl *ns_url;
|
2010-09-12 15:29:58 +04:00
|
|
|
struct ami_protocol *ami_p =
|
2013-10-12 16:11:13 +04:00
|
|
|
(struct ami_protocol *)AllocVecTagList(sizeof(struct ami_protocol), NULL);
|
2010-09-12 15:29:58 +04:00
|
|
|
|
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);
|
2014-10-26 13:25:31 +03:00
|
|
|
nsurl_unref(ns_url);
|
2014-10-26 13:04:24 +03:00
|
|
|
if (ami_p->protocol == NULL)
|
2010-09-12 15:29:58 +04:00
|
|
|
{
|
|
|
|
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)
|
2010-09-12 15:29:58 +04:00
|
|
|
{
|
|
|
|
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);
|
2010-09-12 15:29:58 +04:00
|
|
|
FreeVec(node);
|
|
|
|
node = NULL;
|
2014-11-09 22:53:24 +03:00
|
|
|
}while((node=nnode));
|
2010-09-12 15:29:58 +04:00
|
|
|
}
|
|
|
|
|
2014-11-09 22:53:24 +03:00
|
|
|
static BOOL ami_openurl_check_list(struct MinList *list, nsurl *url)
|
2010-09-12 15:29:58 +04:00
|
|
|
{
|
|
|
|
struct ami_protocol *node;
|
|
|
|
struct ami_protocol *nnode;
|
2014-10-26 13:16:59 +03:00
|
|
|
lwc_string *url_scheme;
|
|
|
|
bool match;
|
2010-09-12 15:29:58 +04:00
|
|
|
|
|
|
|
if(IsMinListEmpty(list)) return FALSE;
|
2014-10-26 13:16:59 +03:00
|
|
|
|
2014-10-26 13:30:22 +03:00
|
|
|
url_scheme = nsurl_get_component(url, NSURL_SCHEME);
|
2014-10-26 13:16:59 +03:00
|
|
|
|
2010-09-12 15:29:58 +04:00
|
|
|
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)) {
|
2014-10-26 13:16:59 +03:00
|
|
|
lwc_string_unref(url_scheme);
|
2010-09-12 15:29:58 +04:00
|
|
|
return TRUE;
|
2014-10-26 13:16:59 +03:00
|
|
|
}
|
2014-11-09 22:53:24 +03:00
|
|
|
}while((node=nnode));
|
2010-09-12 15:29:58 +04:00
|
|
|
|
2014-10-26 13:16:59 +03:00
|
|
|
lwc_string_unref(url_scheme);
|
2010-09-12 15:29:58 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-14 02:28:26 +03:00
|
|
|
/**
|
|
|
|
* Initialise the fetcher.
|
|
|
|
*
|
|
|
|
* Must be called once before any other function.
|
|
|
|
*/
|
|
|
|
|
2009-01-11 00:22:46 +03:00
|
|
|
void ami_openurl_open(void)
|
2008-12-14 02:28:26 +03:00
|
|
|
{
|
2012-04-18 23:44:09 +04:00
|
|
|
if(nsoption_bool(use_openurl_lib)) {
|
2015-01-19 02:54:21 +03:00
|
|
|
if((OpenURLBase = OpenLibrary("openurl.library",0))) {
|
|
|
|
#ifdef __amigaos4__
|
2012-04-18 23:44:09 +04:00
|
|
|
IOpenURL = (struct OpenURLIFace *)GetInterface(OpenURLBase,"main",1,NULL);
|
2015-01-19 02:54:21 +03:00
|
|
|
#endif
|
|
|
|
}
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|
2010-09-12 15:29:58 +04:00
|
|
|
|
|
|
|
NewMinList(&ami_unsupportedprotocols);
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|
|
|
|
|
2014-11-09 22:53:24 +03:00
|
|
|
void ami_openurl_close(void)
|
2008-12-14 02:28:26 +03:00
|
|
|
{
|
2015-01-19 02:54:21 +03:00
|
|
|
#ifdef __amigaos4__
|
2008-12-14 02:28:26 +03:00
|
|
|
if(IOpenURL) DropInterface((struct Interface *)IOpenURL);
|
2015-01-19 02:54:21 +03:00
|
|
|
#endif
|
2008-12-14 02:28:26 +03:00
|
|
|
if(OpenURLBase) CloseLibrary(OpenURLBase);
|
2010-09-12 15:29:58 +04:00
|
|
|
|
|
|
|
ami_openurl_free_list(&ami_unsupportedprotocols);
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|
|
|
|
|
2014-05-28 02:52:35 +04:00
|
|
|
nserror gui_launch_url(struct nsurl *url)
|
2008-12-14 02:28:26 +03:00
|
|
|
{
|
2015-01-19 02:54:21 +03:00
|
|
|
#ifdef __amigaos4__
|
2010-03-07 03:46:08 +03:00
|
|
|
APTR procwin = SetProcWindow((APTR)-1L);
|
2015-01-19 02:54:21 +03:00
|
|
|
#endif
|
2010-03-07 03:46:08 +03:00
|
|
|
char *launchurl = NULL;
|
2010-01-16 18:53:00 +03:00
|
|
|
|
2014-10-26 13:16:59 +03:00
|
|
|
if(ami_openurl_check_list(&ami_unsupportedprotocols, url) == FALSE)
|
2010-03-07 03:46:08 +03:00
|
|
|
{
|
2012-04-18 23:44:09 +04:00
|
|
|
if(IOpenURL)
|
2010-03-15 02:00:39 +03:00
|
|
|
{
|
2011-09-03 02:09:23 +04:00
|
|
|
URL_OpenA((STRPTR)url,NULL);
|
2012-04-18 23:44:09 +04:00
|
|
|
} else {
|
2014-11-09 22:53:24 +03:00
|
|
|
if((launchurl = ASPrintf("URL:%s", nsurl_access(url)))) {
|
2014-04-06 02:34:51 +04:00
|
|
|
BPTR fptr = Open(launchurl,MODE_OLDFILE);
|
2014-05-28 02:52:35 +04:00
|
|
|
if(fptr)
|
|
|
|
{
|
|
|
|
Close(fptr);
|
|
|
|
} else {
|
|
|
|
ami_openurl_add_protocol(nsurl_access(url));
|
|
|
|
}
|
2012-04-18 23:44:09 +04:00
|
|
|
FreeVec(launchurl);
|
|
|
|
}
|
|
|
|
}
|
2009-01-11 00:22:46 +03:00
|
|
|
}
|
2015-01-19 02:54:21 +03:00
|
|
|
#ifdef __amigaos4__
|
2014-05-28 02:52:35 +04:00
|
|
|
SetProcWindow(procwin);
|
2015-01-19 02:54:21 +03:00
|
|
|
#endif
|
2014-05-28 02:52:35 +04:00
|
|
|
return NSERROR_OK;
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|