2008-08-02 18:31:32 +04:00
|
|
|
/*
|
2010-03-21 16:32:59 +03:00
|
|
|
* Copyright 2008-2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2008-08-02 18:31:32 +04: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2010-12-30 03:48:09 +03:00
|
|
|
#include <stdlib.h>
|
2008-08-02 18:31:32 +04:00
|
|
|
#include <string.h>
|
2010-12-30 03:48:09 +03:00
|
|
|
|
2008-08-02 18:31:32 +04:00
|
|
|
#include <sys/types.h>
|
2010-12-30 03:48:09 +03:00
|
|
|
|
2008-08-10 00:21:00 +04:00
|
|
|
#include <proto/dos.h>
|
2012-07-29 00:56:27 +04:00
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
#include <proto/utility.h>
|
2010-12-30 03:48:09 +03:00
|
|
|
|
2012-07-29 00:56:27 +04:00
|
|
|
#include <proto/requester.h>
|
|
|
|
#include <classes/requester.h>
|
|
|
|
|
|
|
|
#include "amiga/gui.h"
|
2010-12-30 03:48:09 +03:00
|
|
|
#include "amiga/utf8.h"
|
2013-09-03 01:41:04 +04:00
|
|
|
#include "desktop/cookie_manager.h"
|
2010-12-30 03:48:09 +03:00
|
|
|
#include "utils/log.h"
|
2008-08-10 00:21:00 +04:00
|
|
|
#include "utils/messages.h"
|
2010-03-31 20:41:56 +04:00
|
|
|
#include "utils/url.h"
|
2010-12-30 03:48:09 +03:00
|
|
|
#include "utils/utils.h"
|
2008-08-02 18:31:32 +04:00
|
|
|
|
|
|
|
void warn_user(const char *warning, const char *detail)
|
|
|
|
{
|
2012-07-29 00:56:27 +04:00
|
|
|
Object *req = NULL;
|
2010-04-10 23:37:13 +04:00
|
|
|
char *utf8warning = ami_utf8_easy(messages_get(warning));
|
2012-07-29 00:56:27 +04:00
|
|
|
STRPTR bodytext = NULL;
|
|
|
|
LONG result = 0;
|
2010-04-10 23:37:13 +04:00
|
|
|
|
2010-12-26 21:51:24 +03:00
|
|
|
LOG(("%s %s", warning, detail));
|
|
|
|
|
2012-07-29 00:56:27 +04:00
|
|
|
bodytext = ASPrintf("\33b%s\33n\n%s",
|
|
|
|
utf8warning != NULL ? utf8warning : warning, detail);
|
|
|
|
|
|
|
|
req = NewObject(REQUESTER_GetClass(), NULL,
|
|
|
|
REQ_Type, REQTYPE_INFO,
|
|
|
|
REQ_TitleText, messages_get("NetSurf"),
|
|
|
|
REQ_BodyText, bodytext,
|
|
|
|
REQ_GadgetText, messages_get("OK"),
|
|
|
|
#ifdef __amigaos4__
|
|
|
|
REQ_VarArgs,
|
|
|
|
REQ_Image, (struct Image *)REQIMAGE_WARNING,
|
|
|
|
/* REQ_CharSet, 106, */
|
|
|
|
#endif
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
if (req) {
|
|
|
|
result = IDoMethod(req, RM_OPENREQ, NULL, NULL, scrn);
|
|
|
|
DisposeObject(req);
|
|
|
|
}
|
2010-04-10 23:39:40 +04:00
|
|
|
|
2012-07-29 00:56:27 +04:00
|
|
|
if(bodytext) FreeVec(bodytext);
|
2010-04-10 23:39:40 +04:00
|
|
|
if(utf8warning) free(utf8warning);
|
2008-08-02 18:31:32 +04:00
|
|
|
}
|
|
|
|
|
2012-12-08 21:47:57 +04:00
|
|
|
int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win)
|
2012-12-08 21:25:25 +04:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
char *utf8text = ami_utf8_easy(body);
|
|
|
|
char *utf8gadget1 = ami_utf8_easy(messages_get(opt1));
|
|
|
|
char *utf8gadget2 = ami_utf8_easy(messages_get(opt2));
|
|
|
|
char *utf8gadgets = ASPrintf("%s|%s", utf8gadget1, utf8gadget2);
|
|
|
|
free(utf8gadget1);
|
|
|
|
free(utf8gadget2);
|
|
|
|
|
|
|
|
res = TimedDosRequesterTags(TDR_ImageType, TDRIMAGE_WARNING,
|
|
|
|
TDR_TitleString, messages_get("NetSurf"),
|
|
|
|
TDR_FormatString, utf8text,
|
|
|
|
TDR_GadgetString, utf8gadgets,
|
|
|
|
TDR_Window, win,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
if(utf8text) free(utf8text);
|
|
|
|
if(utf8gadgets) FreeVec(utf8gadgets);
|
2012-12-08 21:47:57 +04:00
|
|
|
|
|
|
|
return res;
|
2012-12-08 21:25:25 +04:00
|
|
|
}
|
|
|
|
|
2008-08-02 18:31:32 +04:00
|
|
|
void die(const char *error)
|
|
|
|
{
|
2008-08-10 00:21:00 +04:00
|
|
|
TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_ERROR,
|
|
|
|
TDR_TitleString,messages_get("NetSurf"),
|
|
|
|
TDR_GadgetString,messages_get("OK"),
|
2008-08-26 05:22:08 +04:00
|
|
|
// TDR_CharSet,106,
|
2008-08-10 00:21:00 +04:00
|
|
|
TDR_FormatString,"%s",
|
|
|
|
TDR_Arg1,error,
|
|
|
|
TAG_DONE);
|
2008-08-02 18:31:32 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *url_to_path(const char *url)
|
|
|
|
{
|
2014-04-05 23:18:26 +04:00
|
|
|
char *unesc, *slash, *colon, *url2;
|
2008-11-15 18:28:17 +03:00
|
|
|
|
2010-04-17 14:43:12 +04:00
|
|
|
if (strncmp(url, "file://", SLEN("file://")) != 0)
|
|
|
|
return NULL;
|
2009-11-01 19:01:07 +03:00
|
|
|
|
2010-04-17 14:43:12 +04:00
|
|
|
url += SLEN("file://");
|
2009-11-01 19:01:07 +03:00
|
|
|
|
2010-04-17 14:43:12 +04:00
|
|
|
if (strncmp(url, "localhost", SLEN("localhost")) == 0)
|
|
|
|
url += SLEN("localhost");
|
|
|
|
|
2010-07-12 00:48:06 +04:00
|
|
|
if (strncmp(url, "/", SLEN("/")) == 0)
|
|
|
|
url += SLEN("/");
|
2010-04-17 14:43:12 +04:00
|
|
|
|
2010-07-15 02:36:04 +04:00
|
|
|
if(*url == '\0')
|
|
|
|
return NULL; /* file:/// is not a valid path */
|
|
|
|
|
2010-07-12 00:42:06 +04:00
|
|
|
url2 = malloc(strlen(url) + 2);
|
|
|
|
strcpy(url2, url);
|
|
|
|
|
|
|
|
colon = strchr(url2, ':');
|
|
|
|
if(colon == NULL)
|
|
|
|
{
|
|
|
|
if(slash = strchr(url2, '/'))
|
|
|
|
{
|
|
|
|
*slash = ':';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len = strlen(url2);
|
|
|
|
url2[len] = ':';
|
|
|
|
url2[len + 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-12 14:23:12 +04:00
|
|
|
if(url_unescape(url2,&unesc) == URL_FUNC_OK)
|
|
|
|
return unesc;
|
2008-11-15 18:28:17 +03:00
|
|
|
|
2010-07-12 00:42:06 +04:00
|
|
|
return (char *)url2;
|
2008-09-07 19:58:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
char *path_to_url(const char *path)
|
|
|
|
{
|
2010-07-12 00:42:06 +04:00
|
|
|
char *colon = NULL;
|
|
|
|
char *r = NULL;
|
|
|
|
char newpath[1024 + strlen(path)];
|
|
|
|
BPTR lock = 0;
|
2008-09-07 19:58:11 +04:00
|
|
|
|
2010-07-12 00:42:06 +04:00
|
|
|
if(lock = Lock(path, MODE_OLDFILE))
|
|
|
|
{
|
|
|
|
DevNameFromLock(lock, newpath, sizeof newpath, DN_FULLPATH);
|
|
|
|
UnLock(lock);
|
|
|
|
}
|
2012-04-18 22:54:15 +04:00
|
|
|
else strlcpy(newpath, path, sizeof newpath);
|
2010-07-12 00:42:06 +04:00
|
|
|
|
|
|
|
r = malloc(strlen(newpath) + SLEN("file:///") + 1);
|
2008-09-07 19:58:11 +04:00
|
|
|
|
2010-07-12 00:42:06 +04:00
|
|
|
if(colon = strchr(newpath, ':')) *colon = '/';
|
|
|
|
|
|
|
|
strcpy(r, "file:///");
|
|
|
|
strcat(r, newpath);
|
2010-07-12 00:48:06 +04:00
|
|
|
|
2008-09-07 19:58:11 +04:00
|
|
|
return r;
|
2008-08-02 18:31:32 +04:00
|
|
|
}
|
2010-03-17 02:55:39 +03:00
|
|
|
|
|
|
|
/**
|
2012-05-07 19:06:48 +04:00
|
|
|
* returns a string with escape chars translated.
|
2010-03-17 02:55:39 +03:00
|
|
|
* (based on remove_underscores from utils.c)
|
|
|
|
*/
|
|
|
|
|
2012-05-07 19:06:48 +04:00
|
|
|
char *translate_escape_chars(const char *s)
|
2010-03-17 02:55:39 +03:00
|
|
|
{
|
|
|
|
size_t i, ii, len;
|
|
|
|
char *ret;
|
|
|
|
len = strlen(s);
|
|
|
|
ret = malloc(len + 1);
|
|
|
|
if (ret == NULL)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0, ii = 0; i < len; i++) {
|
2012-05-07 19:06:48 +04:00
|
|
|
if (s[i] != '\\') {
|
|
|
|
ret[ii++] = s[i];
|
2010-03-17 02:55:39 +03:00
|
|
|
}
|
2012-05-07 19:06:48 +04:00
|
|
|
else if (s[i+1] == 'n') {
|
2010-03-17 02:55:39 +03:00
|
|
|
ret[ii++] = '\n';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret[ii] = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|