summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-10-31 00:24:57 +0000
committerVincent Sanders <vince@kyllikki.org>2014-10-31 00:24:57 +0000
commitce3d99191842ded7687dc23c3ccb5f5ccc843558 (patch)
tree8bf59a56a3b5eadf727068201acd3e8c51bd9dc9 /utils
parentf995616509fc3c0556da49c915375108bf268f38 (diff)
downloadnetsurf-ce3d99191842ded7687dc23c3ccb5f5ccc843558.tar.gz
netsurf-ce3d99191842ded7687dc23c3ccb5f5ccc843558.tar.bz2
use nsurl_nice and remove url_nice
change all callers over to using new API for generating nice filenames from a url and remove the old API.
Diffstat (limited to 'utils')
-rw-r--r--utils/url.c103
-rw-r--r--utils/url.h10
2 files changed, 0 insertions, 113 deletions
diff --git a/utils/url.c b/utils/url.c
index e1903a816..92e956b55 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -147,109 +147,6 @@ out_true:
/* exported interface documented in utils/url.h */
-nserror url_nice(const char *url, char **result,
- bool remove_extensions)
-{
- int m;
- regmatch_t match[10];
- regoff_t start, end;
- size_t i;
- char *dot;
-
- *result = 0;
-
- m = regexec(&url_re, url, 10, match, 0);
- if (m) {
- LOG(("url '%s' failed to match regex", url));
- return NSERROR_NOT_FOUND;
- }
-
- /* extract the last component of the path, if possible */
- if (match[URL_RE_PATH].rm_so == -1 || match[URL_RE_PATH].rm_so ==
- match[URL_RE_PATH].rm_eo)
- goto no_path; /* no path, or empty */
- for (end = match[URL_RE_PATH].rm_eo - 1;
- end != match[URL_RE_PATH].rm_so && url[end] == '/';
- end--)
- ;
- if (end == match[URL_RE_PATH].rm_so)
- goto no_path; /* path is a string of '/' */
- end++;
- for (start = end - 1;
- start != match[URL_RE_PATH].rm_so && url[start] != '/';
- start--)
- ;
- if (url[start] == '/')
- start++;
-
- if (!strncasecmp(url + start, "index.", 6) ||
- !strncasecmp(url + start, "default.", 8)) {
- /* try again */
- if (start == match[URL_RE_PATH].rm_so)
- goto no_path;
- for (end = start - 1;
- end != match[URL_RE_PATH].rm_so &&
- url[end] == '/';
- end--)
- ;
- if (end == match[URL_RE_PATH].rm_so)
- goto no_path;
- end++;
- for (start = end - 1;
- start != match[URL_RE_PATH].rm_so &&
- url[start] != '/';
- start--)
- ;
- if (url[start] == '/')
- start++;
- }
-
- *result = malloc(end - start + 1);
- if (!*result) {
- LOG(("malloc failed"));
- return NSERROR_NOMEM;
- }
- strncpy(*result, url + start, end - start);
- (*result)[end - start] = 0;
-
- if (remove_extensions) {
- dot = strchr(*result, '.');
- if (dot && dot != *result)
- *dot = 0;
- }
-
- return NSERROR_OK;
-
-no_path:
-
- /* otherwise, use the host name, with '.' replaced by '_' */
- if (match[URL_RE_AUTHORITY].rm_so != -1 &&
- match[URL_RE_AUTHORITY].rm_so !=
- match[URL_RE_AUTHORITY].rm_eo) {
- *result = malloc(match[URL_RE_AUTHORITY].rm_eo -
- match[URL_RE_AUTHORITY].rm_so + 1);
- if (!*result) {
- LOG(("malloc failed"));
- return NSERROR_NOMEM;
- }
- strncpy(*result, url + match[URL_RE_AUTHORITY].rm_so,
- match[URL_RE_AUTHORITY].rm_eo -
- match[URL_RE_AUTHORITY].rm_so);
- (*result)[match[URL_RE_AUTHORITY].rm_eo -
- match[URL_RE_AUTHORITY].rm_so] = 0;
-
- for (i = 0; (*result)[i]; i++)
- if ((*result)[i] == '.')
- (*result)[i] = '_';
-
- return NSERROR_OK;
- }
-
- return NSERROR_NOT_FOUND;
-}
-
-
-/* exported interface documented in utils/url.h */
nserror url_unescape(const char *str, char **result)
{
char *curlstr;
diff --git a/utils/url.h b/utils/url.h
index a2efbecec..d05ac0580 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -56,16 +56,6 @@ bool url_host_is_ip_address(const char *host);
/**
- * Attempt to find a nice filename for a URL.
- *
- * \param url an absolute URL
- * \param result pointer to pointer to buffer to hold filename
- * \param remove_extensions remove any extensions from the filename
- * \return NSERROR_OK on success
- */
-nserror url_nice(const char *url, char **result, bool remove_extensions);
-
-/**
* Escape a string suitable for inclusion in an URL.
*
* \param unescaped the unescaped string