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>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "desktop/cookies.h"
|
2008-08-10 00:21:00 +04:00
|
|
|
#include <proto/dos.h>
|
|
|
|
#include "utils/messages.h"
|
2008-09-07 19:58:11 +04:00
|
|
|
#include <stdlib.h>
|
2008-11-15 18:28:17 +03:00
|
|
|
#include <curl/curl.h>
|
2010-03-21 16:32:59 +03:00
|
|
|
#include "utils/utils.h"
|
2010-03-31 20:41:56 +04:00
|
|
|
#include "utils/url.h"
|
2008-08-02 18:31:32 +04:00
|
|
|
|
|
|
|
void warn_user(const char *warning, const char *detail)
|
|
|
|
{
|
2010-04-10 23:37:13 +04:00
|
|
|
char *utf8warning = ami_utf8_easy(messages_get(warning));
|
|
|
|
|
|
|
|
if(!utf8warning) utf8warning = warning;
|
|
|
|
|
2008-08-10 00:21:00 +04:00
|
|
|
TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_WARNING,
|
|
|
|
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\n%s",
|
2010-04-10 23:37:13 +04:00
|
|
|
TDR_Arg1,utf8warning,
|
2008-08-10 00:21:00 +04:00
|
|
|
TDR_Arg2,detail,
|
|
|
|
TAG_DONE);
|
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)
|
|
|
|
{
|
2009-11-01 19:01:07 +03:00
|
|
|
char *tmps, *unesc;
|
2008-11-15 18:28:17 +03:00
|
|
|
CURL *curl;
|
|
|
|
|
2009-11-01 19:01:07 +03:00
|
|
|
tmps = strstr(url, "///localhost/") + 13;
|
|
|
|
|
|
|
|
if(tmps < url) tmps = strstr(url,"///") + 3;
|
|
|
|
|
|
|
|
if(tmps >= url)
|
2008-11-15 18:28:17 +03:00
|
|
|
{
|
2009-11-01 19:01:07 +03:00
|
|
|
if(curl = curl_easy_init())
|
2008-11-15 18:28:17 +03:00
|
|
|
{
|
2009-11-01 19:01:07 +03:00
|
|
|
unesc = curl_easy_unescape(curl,tmps,0,NULL);
|
|
|
|
tmps = strdup(unesc);
|
|
|
|
curl_free(unesc);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
return tmps;
|
2008-11-15 18:28:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return strdup((char *)url);
|
2008-09-07 19:58:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
char *path_to_url(const char *path)
|
|
|
|
{
|
2010-03-31 17:59:57 +04:00
|
|
|
char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
|
2008-09-07 19:58:11 +04:00
|
|
|
|
2010-03-31 17:59:57 +04:00
|
|
|
strcpy(r, FILE_SCHEME_PREFIX);
|
2008-09-07 19:58:11 +04:00
|
|
|
strcat(r, path);
|
|
|
|
|
|
|
|
return r;
|
2008-08-02 18:31:32 +04:00
|
|
|
}
|
2010-03-17 02:55:39 +03:00
|
|
|
|
2010-03-21 16:32:59 +03:00
|
|
|
/**
|
|
|
|
* Return the filename part of a full path
|
|
|
|
*
|
|
|
|
* \param path full path and filename
|
|
|
|
* \return filename (will be freed with free())
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *filename_from_path(char *path)
|
|
|
|
{
|
|
|
|
return strdup(FilePart(path));
|
|
|
|
}
|
|
|
|
|
2010-03-17 02:55:39 +03:00
|
|
|
/**
|
|
|
|
* returns a string without escape chars or |M chars.
|
|
|
|
* (based on remove_underscores from utils.c)
|
|
|
|
* \param translate true to insert a linebreak where there was |M,
|
|
|
|
* and capitalise initial characters after escape chars.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *remove_escape_chars(const char *s, bool translate)
|
|
|
|
{
|
|
|
|
size_t i, ii, len;
|
|
|
|
char *ret;
|
|
|
|
bool nextcharupper = false;
|
|
|
|
len = strlen(s);
|
|
|
|
ret = malloc(len + 1);
|
|
|
|
if (ret == NULL)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0, ii = 0; i < len; i++) {
|
|
|
|
if ((s[i] != '\\') && (s[i] != '|')) {
|
|
|
|
if(nextcharupper) {
|
|
|
|
ret[ii++] = toupper(s[i]);
|
|
|
|
nextcharupper = false;
|
|
|
|
}
|
|
|
|
else ret[ii++] = s[i];
|
|
|
|
}
|
|
|
|
else if ((translate) && (s[i] == '|') && (s[i+1] == 'M')) {
|
|
|
|
ret[ii++] = '\n';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(translate) nextcharupper = true;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret[ii] = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|