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>
|
2014-06-05 15:06:47 +04:00
|
|
|
#include <unistd.h>
|
2010-12-30 03:48:09 +03:00
|
|
|
|
2008-08-02 18:31:32 +04:00
|
|
|
#include <sys/types.h>
|
2014-06-05 15:06:47 +04:00
|
|
|
#include <sys/stat.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>
|
|
|
|
|
2014-05-27 03:08:04 +04:00
|
|
|
#include "utils/corestrings.h"
|
2014-11-10 21:48:26 +03:00
|
|
|
#include "utils/log.h"
|
2014-05-27 02:43:36 +04:00
|
|
|
#include "utils/file.h"
|
2014-11-10 21:48:26 +03:00
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/url.h"
|
2010-12-30 03:48:09 +03:00
|
|
|
#include "utils/utils.h"
|
2008-08-02 18:31:32 +04:00
|
|
|
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "desktop/cookie_manager.h"
|
|
|
|
#include "desktop/mouse.h"
|
|
|
|
#include "desktop/gui_window.h"
|
|
|
|
|
|
|
|
#include "amiga/gui.h"
|
2014-11-10 21:48:26 +03:00
|
|
|
#include "amiga/misc.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "amiga/utf8.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;
|
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_Image, (struct Image *)REQIMAGE_WARNING,
|
|
|
|
/* REQ_CharSet, 106, */
|
|
|
|
#endif
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
if (req) {
|
2014-11-10 21:48:26 +03:00
|
|
|
IDoMethod(req, RM_OPENREQ, NULL, NULL, scrn);
|
2012-07-29 00:56:27 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
/**
|
|
|
|
* Create a path from a nsurl using amiga file handling.
|
|
|
|
*
|
2014-07-02 19:39:08 +04:00
|
|
|
* @param[in] url The url to encode.
|
2014-05-27 02:43:36 +04:00
|
|
|
* @param[out] path_out A string containing the result path which should
|
|
|
|
* be freed by the caller.
|
|
|
|
* @return NSERROR_OK and the path is written to \a path or error code
|
|
|
|
* on faliure.
|
|
|
|
*/
|
|
|
|
static nserror amiga_nsurl_to_path(struct nsurl *url, char **path_out)
|
2008-08-02 18:31:32 +04:00
|
|
|
{
|
2014-05-27 02:43:36 +04:00
|
|
|
lwc_string *urlpath;
|
|
|
|
char *path;
|
|
|
|
bool match;
|
|
|
|
lwc_string *scheme;
|
|
|
|
nserror res;
|
|
|
|
char *colon;
|
|
|
|
char *slash;
|
|
|
|
|
|
|
|
if ((url == NULL) || (path_out == NULL)) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
2009-11-01 19:01:07 +03:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
scheme = nsurl_get_component(url, NSURL_SCHEME);
|
2010-04-17 14:43:12 +04:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
if (lwc_string_caseless_isequal(scheme, corestring_lwc_file,
|
|
|
|
&match) != lwc_error_ok)
|
|
|
|
{
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
lwc_string_unref(scheme);
|
|
|
|
if (match == false) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
2010-04-17 14:43:12 +04:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
urlpath = nsurl_get_component(url, NSURL_PATH);
|
|
|
|
if (urlpath == NULL) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
2010-07-15 02:36:04 +04:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
res = url_unescape(lwc_string_data(urlpath) + 1, &path);
|
|
|
|
lwc_string_unref(urlpath);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
|
|
|
}
|
2010-07-12 00:42:06 +04:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
colon = strchr(path, ':');
|
2010-07-12 00:42:06 +04:00
|
|
|
if(colon == NULL)
|
|
|
|
{
|
2014-05-27 02:43:36 +04:00
|
|
|
slash = strchr(path, '/');
|
|
|
|
if(slash)
|
2010-07-12 00:42:06 +04:00
|
|
|
{
|
|
|
|
*slash = ':';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-27 02:43:36 +04:00
|
|
|
int len = strlen(path);
|
|
|
|
path[len] = ':';
|
|
|
|
path[len + 1] = '\0';
|
2010-07-12 00:42:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
*path_out = path;
|
2008-11-15 18:28:17 +03:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
return NSERROR_OK;
|
2008-09-07 19:58:11 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
/**
|
|
|
|
* Create a nsurl from a path using amiga file handling.
|
|
|
|
*
|
|
|
|
* Perform the necessary operations on a path to generate a nsurl.
|
|
|
|
*
|
|
|
|
* @param[in] path The path to convert.
|
|
|
|
* @param[out] url_out pointer to recive the nsurl, The returned url
|
|
|
|
* must be unreferenced by the caller.
|
|
|
|
* @return NSERROR_OK and the url is placed in \a url or error code on
|
|
|
|
* faliure.
|
|
|
|
*/
|
|
|
|
static nserror amiga_path_to_nsurl(const char *path, struct nsurl **url_out)
|
2008-09-07 19:58:11 +04:00
|
|
|
{
|
2010-07-12 00:42:06 +04:00
|
|
|
char *colon = NULL;
|
|
|
|
char *r = NULL;
|
|
|
|
char newpath[1024 + strlen(path)];
|
|
|
|
BPTR lock = 0;
|
2014-05-27 02:43:36 +04:00
|
|
|
nserror ret;
|
2008-09-07 19:58:11 +04:00
|
|
|
|
2014-11-10 21:48:26 +03:00
|
|
|
if((lock = Lock(path, SHARED_LOCK))) {
|
2010-07-12 00:42:06 +04:00
|
|
|
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);
|
2014-05-27 02:43:36 +04:00
|
|
|
if (r == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
2008-09-07 19:58:11 +04:00
|
|
|
|
2014-11-10 21:48:26 +03:00
|
|
|
if((colon = strchr(newpath, ':'))) *colon = '/';
|
2010-07-12 00:42:06 +04:00
|
|
|
|
|
|
|
strcpy(r, "file:///");
|
|
|
|
strcat(r, newpath);
|
2010-07-12 00:48:06 +04:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
ret = nsurl_create(r, url_out);
|
|
|
|
free(r);
|
|
|
|
|
|
|
|
return ret;
|
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;
|
|
|
|
}
|
2014-05-27 02:43:36 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a posix path from one or more component elemnts.
|
|
|
|
*
|
|
|
|
* If a string is allocated it must be freed by the caller.
|
|
|
|
*
|
|
|
|
* @param[in,out] str pointer to string pointer if this is NULL enough
|
|
|
|
* storage will be allocated for the complete path.
|
|
|
|
* @param[in,out] size The size of the space available if \a str not
|
|
|
|
* NULL on input and if not NULL set to the total
|
|
|
|
* output length on output.
|
2014-07-02 19:39:08 +04:00
|
|
|
* @param[in] nelm The number of elements.
|
|
|
|
* @param[in] ap The elements of the path as string pointers.
|
2014-05-27 02:43:36 +04:00
|
|
|
* @return NSERROR_OK and the complete path is written to str
|
|
|
|
* or error code on faliure.
|
|
|
|
*/
|
|
|
|
static nserror amiga_vmkpath(char **str, size_t *size, size_t nelm, va_list ap)
|
|
|
|
{
|
|
|
|
const char *elm[16];
|
|
|
|
size_t elm_len[16];
|
|
|
|
size_t elm_idx;
|
|
|
|
char *fname;
|
|
|
|
size_t fname_len = 0;
|
|
|
|
|
|
|
|
/* check the parameters are all sensible */
|
|
|
|
if ((nelm == 0) || (nelm > 16)) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
if ((*str != NULL) && (size == NULL)) {
|
|
|
|
/* if the caller is providing the buffer they must say
|
|
|
|
* how much space is available.
|
|
|
|
*/
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate how much storage we need for the complete path
|
|
|
|
* with all the elements.
|
|
|
|
*/
|
|
|
|
for (elm_idx = 0; elm_idx < nelm; elm_idx++) {
|
|
|
|
elm[elm_idx] = va_arg(ap, const char *);
|
|
|
|
/* check the argument is not NULL */
|
|
|
|
if (elm[elm_idx] == NULL) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
elm_len[elm_idx] = strlen(elm[elm_idx]);
|
|
|
|
fname_len += elm_len[elm_idx];
|
|
|
|
}
|
|
|
|
fname_len += nelm; /* allow for separators and terminator */
|
|
|
|
|
|
|
|
/* ensure there is enough space */
|
|
|
|
fname = *str;
|
|
|
|
if (fname != NULL) {
|
|
|
|
if (fname_len > *size) {
|
|
|
|
return NSERROR_NOSPACE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fname = malloc(fname_len);
|
|
|
|
if (fname == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the first element complete */
|
|
|
|
memmove(fname, elm[0], elm_len[0]);
|
|
|
|
fname[elm_len[0]] = 0;
|
|
|
|
|
|
|
|
/* add the remaining elements */
|
|
|
|
for (elm_idx = 1; elm_idx < nelm; elm_idx++) {
|
|
|
|
if (!AddPart(fname, elm[elm_idx], fname_len)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*str = fname;
|
|
|
|
if (size != NULL) {
|
|
|
|
*size = fname_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the basename of a file using posix path handling.
|
|
|
|
*
|
|
|
|
* This gets the last element of a path and returns it.
|
|
|
|
*
|
|
|
|
* @param[in] path The path to extract the name from.
|
|
|
|
* @param[in,out] str Pointer to string pointer if this is NULL enough
|
|
|
|
* storage will be allocated for the path element.
|
|
|
|
* @param[in,out] size The size of the space available if \a
|
|
|
|
* str not NULL on input and set to the total
|
|
|
|
* output length on output.
|
|
|
|
* @return NSERROR_OK and the complete path is written to str
|
|
|
|
* or error code on faliure.
|
|
|
|
*/
|
|
|
|
static nserror amiga_basename(const char *path, char **str, size_t *size)
|
|
|
|
{
|
|
|
|
const char *leafname;
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
if (path == NULL) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
leafname = FilePart(path);
|
|
|
|
if (leafname == NULL) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
fname = strdup(leafname);
|
|
|
|
if (fname == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
*str = fname;
|
|
|
|
if (size != NULL) {
|
|
|
|
*size = strlen(fname);
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-05 15:06:47 +04:00
|
|
|
/**
|
|
|
|
* Ensure that all directory elements needed to store a filename exist.
|
|
|
|
*
|
|
|
|
* @param fname The filename to ensure the path to exists.
|
|
|
|
* @return NSERROR_OK on success or error code on failure.
|
|
|
|
*/
|
|
|
|
static nserror amiga_mkdir_all(const char *fname)
|
|
|
|
{
|
|
|
|
char *dname;
|
|
|
|
char *sep;
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
dname = strdup(fname);
|
|
|
|
|
|
|
|
sep = strrchr(dname, '/');
|
|
|
|
if (sep == NULL) {
|
|
|
|
/* no directory separator path is just filename so its ok */
|
|
|
|
free(dname);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sep = 0; /* null terminate directory path */
|
|
|
|
|
|
|
|
if (stat(dname, &sb) == 0) {
|
|
|
|
free(dname);
|
|
|
|
if (S_ISDIR(sb.st_mode)) {
|
|
|
|
/* path to file exists and is a directory */
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
return NSERROR_NOT_DIRECTORY;
|
|
|
|
}
|
|
|
|
*sep = '/'; /* restore separator */
|
|
|
|
|
|
|
|
sep = dname;
|
|
|
|
while (*sep == '/') {
|
|
|
|
sep++;
|
|
|
|
}
|
|
|
|
while ((sep = strchr(sep, '/')) != NULL) {
|
|
|
|
*sep = 0;
|
|
|
|
if (stat(dname, &sb) != 0) {
|
|
|
|
if (nsmkdir(dname, S_IRWXU) != 0) {
|
|
|
|
/* could not create path element */
|
|
|
|
free(dname);
|
|
|
|
return NSERROR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (! S_ISDIR(sb.st_mode)) {
|
|
|
|
/* path element not a directory */
|
|
|
|
free(dname);
|
|
|
|
return NSERROR_NOT_DIRECTORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*sep = '/'; /* restore separator */
|
|
|
|
/* skip directory separators */
|
|
|
|
while (*sep == '/') {
|
|
|
|
sep++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(dname);
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
/* amiga file handling operations */
|
|
|
|
static struct gui_file_table file_table = {
|
|
|
|
.mkpath = amiga_vmkpath,
|
|
|
|
.basename = amiga_basename,
|
|
|
|
.nsurl_to_path = amiga_nsurl_to_path,
|
|
|
|
.path_to_nsurl = amiga_path_to_nsurl,
|
2014-06-05 15:06:47 +04:00
|
|
|
.mkdir_all = amiga_mkdir_all,
|
2014-05-27 02:43:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gui_file_table *amiga_file_table = &file_table;
|