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>
|
|
|
|
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2012-04-18 23:44:09 +04:00
|
|
|
#include "utils/url.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
char *protocol;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ami_protocol *ami_openurl_add_protocol(const char *url)
|
|
|
|
{
|
|
|
|
struct ami_protocol *ami_p =
|
|
|
|
(struct ami_protocol *)AllocVec(sizeof(struct ami_protocol),
|
|
|
|
MEMF_PRIVATE | MEMF_CLEAR);
|
|
|
|
|
|
|
|
if(url_scheme(url, &ami_p->protocol) != URL_FUNC_OK)
|
|
|
|
{
|
|
|
|
FreeVec(ami_p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddTail((struct List *)&ami_unsupportedprotocols, (struct Node *)ami_p);
|
|
|
|
return ami_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if(node->protocol) free(node->protocol);
|
|
|
|
FreeVec(node);
|
|
|
|
node = NULL;
|
|
|
|
}while(node=nnode);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ami_openurl_check_list(struct MinList *list, const char *url)
|
|
|
|
{
|
|
|
|
struct ami_protocol *node;
|
|
|
|
struct ami_protocol *nnode;
|
|
|
|
|
|
|
|
if(IsMinListEmpty(list)) return FALSE;
|
|
|
|
node = (struct ami_protocol *)GetHead((struct List *)list);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nnode=(struct ami_protocol *)GetSucc((struct Node *)node);
|
|
|
|
|
|
|
|
if(!strncasecmp(url, node->protocol, strlen(node->protocol)))
|
|
|
|
return TRUE;
|
|
|
|
}while(node=nnode);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-09-12 15:29:58 +04:00
|
|
|
struct ami_protocol *ami_p;
|
|
|
|
|
2012-04-18 23:44:09 +04:00
|
|
|
if(nsoption_bool(use_openurl_lib)) {
|
|
|
|
if(OpenURLBase = OpenLibrary("openurl.library",0))
|
|
|
|
IOpenURL = (struct OpenURLIFace *)GetInterface(OpenURLBase,"main",1,NULL);
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|
2010-09-12 15:29:58 +04:00
|
|
|
|
|
|
|
NewMinList(&ami_unsupportedprotocols);
|
|
|
|
ami_openurl_add_protocol("javascript:");
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|
|
|
|
|
2009-01-11 00:22:46 +03:00
|
|
|
void ami_openurl_close(const char *scheme)
|
2008-12-14 02:28:26 +03:00
|
|
|
{
|
|
|
|
if(IOpenURL) DropInterface((struct Interface *)IOpenURL);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-01-11 00:22:46 +03:00
|
|
|
void gui_launch_url(const char *url)
|
2008-12-14 02:28:26 +03:00
|
|
|
{
|
2010-03-07 03:46:08 +03:00
|
|
|
APTR procwin = SetProcWindow((APTR)-1L);
|
|
|
|
char *launchurl = NULL;
|
|
|
|
BPTR fptr = 0;
|
2010-01-16 18:53:00 +03:00
|
|
|
|
2010-09-12 15:29:58 +04: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 {
|
|
|
|
if(launchurl = ASPrintf("URL:%s",url)) {
|
|
|
|
fptr = Open(launchurl,MODE_OLDFILE);
|
|
|
|
if(fptr) Close(fptr);
|
|
|
|
else ami_openurl_add_protocol(url);
|
|
|
|
FreeVec(launchurl);
|
|
|
|
}
|
|
|
|
}
|
2009-01-11 00:22:46 +03:00
|
|
|
}
|
2010-03-07 03:46:08 +03:00
|
|
|
|
|
|
|
SetProcWindow(procwin);
|
2008-12-14 02:28:26 +03:00
|
|
|
}
|