2 ** openurl.library - universal URL display and browser
5 ** Written by Troels Walsted Hansen <troels@thule.no>
6 ** Placed in the public domain.
9 ** - Alfonso Ranieri <alforan@tin.it>
10 ** - Stefan Kost <ensonic@sonicpulse.de>
15 #include <dos/dostags.h>
16 #include "openurl.library_rev.h"
17 #include <exec/execbase.h>
19 /**************************************************************************/
22 AROS_LH2(ULONG
, URL_OpenA
,
23 AROS_LHA(STRPTR
, URL
, A0
),
24 AROS_LHA(struct TagItem
*, attrs
, A1
),
25 struct Library
*, library
, 5, Openurl
31 URL_OpenA(REG(a0
,UBYTE
*URL
),REG(a1
,struct TagItem
*attrs
))
35 UBYTE buf
[256], *fullURL
= NULL
, *pubScreenName
;
36 ULONG res
, show
, toFront
, newWindow
, launch
, httpPrepend
= FALSE
;
39 ObtainSemaphore(&lib_prefsSem
);
43 pubScreenName
= (UBYTE
*)GetTagData(URL_PubScreenName
,(IPTR
)"Workbench",attrs
);
44 show
= GetTagData(URL_Show
,lib_prefs
->up_DefShow
,attrs
);
45 toFront
= GetTagData(URL_BringToFront
,lib_prefs
->up_DefBringToFront
,attrs
);
46 newWindow
= GetTagData(URL_NewWindow
,lib_prefs
->up_DefNewWindow
,attrs
);
47 launch
= GetTagData(URL_Launch
,lib_prefs
->up_DefLaunch
,attrs
);
49 /* make a copy of the global list of named ports */
51 res
= copyList(&portList
,&SysBase
->PortList
,sizeof(struct Node
));
55 /* prepend "http://" if URL has no method */
56 if (lib_prefs
->up_Flags
& UPF_PREPENDHTTP
)
60 colon
= strchr(URL
,':');
62 if (!colon
) httpPrepend
= TRUE
;
67 for (p
= URL
; p
<colon
; p
++)
69 if (!isalnum(*p
) && (*p
!='+') && (*p
!='-'))
80 ULONG len
= strlen(URL
)+8;
84 if (!(fullURL
= allocVecPooled(strlen(URL
)+8))) goto done
;
88 msprintf(fullURL
,"http://%s",(IPTR
)URL
);
92 /* Be case insensitive - Piru */
93 if ((lib_prefs
->up_Flags
& UPF_DOMAILTO
) && !Strnicmp(URL
,"mailto:",7))
94 res
= sendToMailer(fullURL
,&portList
,show
,toFront
,launch
,pubScreenName
);
96 if ((lib_prefs
->up_Flags
& UPF_DOFTP
) && !Strnicmp(URL
,"ftp://",6))
97 res
= sendToFTP(fullURL
,&portList
,show
,toFront
,newWindow
,launch
,pubScreenName
);
98 else res
= sendToBrowser(fullURL
,&portList
,show
,toFront
,newWindow
,launch
,pubScreenName
);
101 ReleaseSemaphore(&lib_prefsSem
);
102 freeList(&portList
,sizeof(struct Node
));
103 if (httpPrepend
&& fullURL
&& fullURL
!=buf
) freeVecPooled(fullURL
);
112 /**************************************************************************/
115 AROS_LH1(struct URL_Prefs
*, URL_GetPrefsA
,
116 AROS_LHA(struct TagItem
*, attrs
, A0
),
117 struct Library
*, library
, 12, Openurl
122 struct URL_Prefs
* LIBCALL
123 URL_GetPrefsA(REG(a0
,struct TagItem
*attrs
))
129 mode
= GetTagData(URL_GetPrefs_Mode
,URL_GetPrefs_Mode_Env
,attrs
);
131 if (mode
==URL_GetPrefs_Mode_Default
)
133 if (!(p
= allocPooled(sizeof(struct URL_Prefs
)))) return NULL
;
139 if ((mode
==URL_GetPrefs_Mode_Env
) || (mode
==URL_GetPrefs_Mode_Envarc
))
141 mode
= (mode
==URL_GetPrefs_Mode_Env
) ? LOADPREFS_ENV
: LOADPREFS_ENVARC
;
143 if (!(p
= allocPooled(sizeof(struct URL_Prefs
))))
146 if (loadPrefs(p
,mode
))
149 if (GetTagData(URL_GetPrefs_FallBack
,TRUE
,attrs
))
152 if ((mode
==LOADPREFS_ENV
) && loadPrefs(p
,LOADPREFS_ENVARC
))
160 URL_FreePrefsA(p
,NULL
);
165 ObtainSemaphoreShared(&lib_prefsSem
);
166 p
= copyPrefs(lib_prefs
);
167 ReleaseSemaphore(&lib_prefsSem
);
175 /**************************************************************************/
178 AROS_LH0(struct URL_Prefs
*, URL_OldGetPrefs
,
179 struct Library
*, library
, 6, Openurl
184 struct URL_Prefs
* LIBCALL
185 URL_OldGetPrefs(void)
188 return URL_GetPrefsA(NULL
);
194 /**************************************************************************/
197 AROS_LH2(VOID
, URL_FreePrefsA
,
198 AROS_LHA(struct URL_Prefs
*, p
, A0
),
199 AROS_LHA(struct TagItem
*, attrs
, A1
),
200 struct Library
*, library
, 13, Openurl
206 URL_FreePrefsA(REG(a0
,struct URL_Prefs
*p
),REG(a1
,struct TagItem
*attrs
))
211 freeList((struct List
*)&p
->up_BrowserList
,sizeof(struct URL_BrowserNode
));
212 freeList((struct List
*)&p
->up_MailerList
,sizeof(struct URL_MailerNode
));
213 freeList((struct List
*)&p
->up_FTPList
,sizeof(struct URL_FTPNode
));
214 freePooled(p
,sizeof(*p
));
221 /**************************************************************************/
224 AROS_LH1(VOID
, URL_OldFreePrefs
,
225 AROS_LHA(struct URL_Prefs
*, p
, A0
),
226 struct Library
*, library
, 7, Openurl
232 URL_OldFreePrefs(REG(a0
,struct URL_Prefs
*p
))
235 URL_FreePrefsA(p
,NULL
);
241 /**************************************************************************/
244 AROS_LH2(ULONG
, URL_SetPrefsA
,
245 AROS_LHA(struct URL_Prefs
*, p
, A0
),
246 AROS_LHA(struct TagItem
*, attrs
, A1
),
247 struct Library
*, library
, 14, Openurl
253 URL_SetPrefsA(REG(a0
,struct URL_Prefs
*p
),REG(a1
,struct TagItem
*attrs
))
258 if (p
->up_Version
==PREFS_VERSION
)
260 struct URL_Prefs
*newp
;
262 ObtainSemaphore(&lib_prefsSem
);
264 if ((newp
= copyPrefs(p
)))
266 newp
->up_Version
= PREFS_VERSION
;
267 newp
->up_Flags
&= ~UPF_ISDEFAULTS
;
269 URL_FreePrefsA(lib_prefs
,NULL
);
272 if ((res
= savePrefs(DEF_ENV
,lib_prefs
)))
274 if (GetTagData(URL_SetPrefs_Save
,FALSE
,attrs
))
276 res
= savePrefs(DEF_ENVARC
,lib_prefs
);
281 ReleaseSemaphore(&lib_prefsSem
);
290 /**************************************************************************/
293 AROS_LH2(ULONG
, URL_OldSetPrefs
,
294 AROS_LHA(struct URL_Prefs
*, p
, A0
),
295 AROS_LHA(BOOL
, save
, D0
),
296 struct Library
*, library
, 8, Openurl
302 URL_OldSetPrefs(REG(a0
,struct URL_Prefs
*p
),REG(d0
,ULONG save
))
305 struct TagItem stags
[] = { {URL_SetPrefs_Save
,0} , {TAG_DONE
} };
307 stags
[0].ti_Data
= save
;
309 return URL_SetPrefsA(p
,stags
);
315 /**************************************************************************/
318 AROS_LH0(struct URL_Prefs
*, URL_OldGetDefaultPrefs
,
319 struct Library
*, library
, 9, Openurl
324 struct URL_Prefs
* LIBCALL
325 URL_OldGetDefaultPrefs(void)
328 struct TagItem gtags
[] = { {URL_GetPrefs_Mode
,URL_GetPrefs_Mode_Default
} , {TAG_DONE
} };
330 return URL_GetPrefsA(gtags
);
336 /**************************************************************************/
339 AROS_LH1(ULONG
, URL_LaunchPrefsAppA
,
340 AROS_LHA(struct TagItem
*, tags
, A0
),
341 struct Library
*, library
, 15, Openurl
347 URL_LaunchPrefsAppA(REG(a0
,struct TagItem
*attrs
))
352 if ((in
= Open("NIL:",MODE_OLDFILE
)))
356 if ((out
= Open("NIL:",MODE_OLDFILE
)))
359 struct TagItem stags
[] = {{SYS_Input
, 0},
361 {NP_StackSize
, 16000},
364 {NP_PPCStackSize
, 32000},
368 if (GetVar("OpenURL_Prefs_Path",name
,sizeof(name
),GVF_GLOBAL_ONLY
)<=0)
369 strcpy(name
,"Sys:Prefs/OpenURL");
371 stags
[0].ti_Data
= (IPTR
)in
;
372 stags
[1].ti_Data
= (IPTR
)out
;
373 SystemTagList(name
,stags
);
387 /**************************************************************************/
390 AROS_LH0(ULONG
, URL_OldLaunchPrefsApp
,
391 struct Library
*, library
, 10, Openurl
397 URL_OldLaunchPrefsApp(void)
400 return URL_LaunchPrefsAppA(NULL
);
406 /**************************************************************************/
409 AROS_LH2(ULONG
, URL_GetAttr
,
410 AROS_LHA(ULONG
, attr
, D0
),
411 AROS_LHA(IPTR
*, storage
, A0
),
412 struct Library
*, library
, 16, Openurl
418 URL_GetAttr(REG(d0
,ULONG attr
),REG(a0
,ULONG
*storage
))
423 case URL_GetAttr_Version
: *storage
= VERSION
; return TRUE
;
424 case URL_GetAttr_Revision
: *storage
= REVISION
; return TRUE
;
425 case URL_GetAttr_VerString
: *storage
= (IPTR
)PRGNAME
; return TRUE
;
427 case URL_GetAttr_PrefsVer
: *storage
= PREFS_VERSION
; return TRUE
;
429 case URL_GetAttr_HandlerVersion
: *storage
= 0; return TRUE
;
430 case URL_GetAttr_HandlerRevision
: *storage
= 0; return TRUE
;
431 case URL_GetAttr_HandlerVerString
: *storage
= (IPTR
)""; return TRUE
;
433 default: return FALSE
;
440 /**************************************************************************/
446 struct RexxMsg
*msg
= (struct RexxMsg
*)REG_A0
;
448 LONG ASM SAVEDS
dispatch(REG(a0
,struct RexxMsg
*msg
),REG(a1
,UBYTE
**resPtr
))
452 UBYTE
*fun
= msg
->rm_Args
[0];
453 ULONG res
, na
= msg
->rm_Action
& RXARGMASK
;
455 if (!stricmp(fun
,"OPENURL"))
460 struct TagItem tags
[MAXRMARG
+1];
464 for (i
= na
, j
= 0, url
= NULL
; i
>0; i
--)
466 UBYTE
*arg
= msg
->rm_Args
[i
];
469 if (!arg
|| !*arg
) continue;
471 if (!stricmp(arg
,"SHOW") || !stricmp(arg
,"NOSHOW")) tag
= URL_Show
;
472 else if (!stricmp(arg
,"TOFRONT") || !stricmp(arg
,"NOTOFRONT")) tag
= URL_BringToFront
;
473 else if (!stricmp(arg
,"NEWWIN") || !stricmp(arg
,"NONEWWIN")) tag
= URL_NewWindow
;
474 else if (!stricmp(arg
,"LAUNCH") || !stricmp(arg
,"NOLAUNCH")) tag
= URL_Launch
;
481 tags
[j
].ti_Tag
= tag
;
482 tags
[j
++].ti_Data
= strnicmp(arg
,"NO",2);
485 tags
[j
].ti_Tag
= TAG_END
;
487 res
= url
&& URL_OpenA(url
,tags
);
492 if (!stricmp(fun
,"OPENURLPREFS"))
494 if (na
!=0) return 17;
496 res
= URL_LaunchPrefsAppA(NULL
);
502 return (REG_A0
= (ULONG
)CreateArgstring(res
? "1" : "0",1)) ? 0 : 3;
504 return (*resPtr
= CreateArgstring(res
? "1" : "0",1)) ? 0 : 3;
507 #endif /* !__AROS__ */
509 /**************************************************************************/