From 883c738c0a30622dcc4189b63bf1af18b45295fb Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 12 Sep 2010 11:29:58 +0000 Subject: Stop launch-handler from reporting unknown protocols more than once svn path=/trunk/netsurf/; revision=10760 --- amiga/fetch_mailto.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) (limited to 'amiga/fetch_mailto.c') diff --git a/amiga/fetch_mailto.c b/amiga/fetch_mailto.c index c710f3949..d031d12a4 100755 --- a/amiga/fetch_mailto.c +++ b/amiga/fetch_mailto.c @@ -21,14 +21,78 @@ */ #include +#include #include #include #include #include +#include struct Library *OpenURLBase; struct OpenURLIFace *IOpenURL; +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; +} + /** * Initialise the fetcher. * @@ -37,16 +101,24 @@ struct OpenURLIFace *IOpenURL; void ami_openurl_open(void) { + struct ami_protocol *ami_p; + if(OpenURLBase = OpenLibrary("openurl.library",0)) { IOpenURL = (struct OpenURLIFace *)GetInterface(OpenURLBase,"main",1,NULL); } + + NewMinList(&ami_unsupportedprotocols); + ami_openurl_add_protocol("about:"); + ami_openurl_add_protocol("javascript:"); } void ami_openurl_close(const char *scheme) { if(IOpenURL) DropInterface((struct Interface *)IOpenURL); if(OpenURLBase) CloseLibrary(OpenURLBase); + + ami_openurl_free_list(&ami_unsupportedprotocols); } void gui_launch_url(const char *url) @@ -55,14 +127,15 @@ void gui_launch_url(const char *url) char *launchurl = NULL; BPTR fptr = 0; - if((strncasecmp(url,"ABOUT:",6)) && - (strncasecmp(url,"JAVASCRIPT:",11))) + if(ami_openurl_check_list(&ami_unsupportedprotocols, url) == FALSE) { launchurl = ASPrintf("URL:%s",url); - if(launchurl && (fptr = Open(launchurl,MODE_OLDFILE))) + if(launchurl) { - Close(fptr); + fptr = Open(launchurl,MODE_OLDFILE); + if(fptr) Close(fptr); + else ami_openurl_add_protocol(url); } else if(IOpenURL) URL_OpenA(url,NULL); -- cgit v1.2.3