From ce3d99191842ded7687dc23c3ccb5f5ccc843558 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 31 Oct 2014 00:24:57 +0000 Subject: 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. --- utils/url.c | 103 ------------------------------------------------------------ 1 file changed, 103 deletions(-) (limited to 'utils/url.c') diff --git a/utils/url.c b/utils/url.c index e1903a816..92e956b55 100644 --- a/utils/url.c +++ b/utils/url.c @@ -146,109 +146,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) { -- cgit v1.2.3