summaryrefslogtreecommitdiff
path: root/utils/url.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-05-09 10:30:24 +0100
committerVincent Sanders <vince@kyllikki.org>2014-05-09 10:30:24 +0100
commit429d6e20f7989bb65736fb6f0058c33add7b0ac5 (patch)
treec51afb4e32393054c11eecde6f72614bb282f932 /utils/url.c
parent162e97cf019f501d37247094972b903b9de12960 (diff)
downloadnetsurf-429d6e20f7989bb65736fb6f0058c33add7b0ac5.tar.gz
netsurf-429d6e20f7989bb65736fb6f0058c33add7b0ac5.tar.bz2
remove unused url operations
Diffstat (limited to 'utils/url.c')
-rw-r--r--utils/url.c354
1 files changed, 0 insertions, 354 deletions
diff --git a/utils/url.c b/utils/url.c
index b0e23d7f0..37fa93967 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -265,63 +265,6 @@ url_get_components(const char *url, struct url_components *result)
/**
- * Reform a URL from separate components
- *
- * See RFC 3986 for reference.
- *
- * \param components The components to reform into a URL.
- * \return A new URL allocated on the heap, or NULL on failure
- */
-static char *url_reform_components(const struct url_components *components)
-{
- int scheme_len = 0, authority_len = 0, path_len = 0, query_len = 0,
- fragment_len = 0;
- char *result, *url;
-
- /* 5.3 */
- if (components->scheme)
- scheme_len = strlen(components->scheme) + 1;
- if (components->authority)
- authority_len = strlen(components->authority) + 2;
- if (components->path)
- path_len = strlen(components->path);
- if (components->query)
- query_len = strlen(components->query) + 1;
- if (components->fragment)
- fragment_len = strlen(components->fragment) + 1;
-
- /* claim memory */
- url = result = malloc(scheme_len + authority_len + path_len +
- query_len + fragment_len + 1);
- if (!url) {
- LOG(("malloc failed"));
- return NULL;
- }
-
- /* rebuild URL */
- if (components->scheme) {
- sprintf(url, "%s:", components->scheme);
- url += scheme_len;
- }
- if (components->authority) {
- sprintf(url, "//%s", components->authority);
- url += authority_len;
- }
- if (components->path) {
- sprintf(url, "%s", components->path);
- url += path_len;
- }
- if (components->query) {
- sprintf(url, "?%s", components->query);
- url += query_len;
- }
- if (components->fragment)
- sprintf(url, "#%s", components->fragment);
- return result;
-}
-
-
-/**
* Release some url components from memory
*
* \param result pointer to buffer containing components
@@ -337,238 +280,6 @@ static void url_destroy_components(const struct url_components *components)
free(internal->buffer);
}
-/* exported interface documented in utils/url.h */
-nserror url_join(const char *rel, const char *base, char **result)
-{
- nserror status = NSERROR_NOMEM;
- struct url_components_internal base_components = {0,0,0,0,0,0};
- struct url_components_internal *base_ptr = &base_components;
- struct url_components_internal rel_components = {0,0,0,0,0,0};
- struct url_components_internal *rel_ptr = &rel_components;
- struct url_components_internal merged_components = {0,0,0,0,0,0};
- struct url_components_internal *merged_ptr = &merged_components;
- char *merge_path = NULL, *split_point;
- char *input, *output, *start = NULL;
- int len, buf_len;
-
- (*result) = 0;
-
- assert(base);
- assert(rel);
-
-
- /* break down the relative URL (not cached, corruptable) */
- status = url_get_components(rel, (struct url_components *) rel_ptr);
- if (status != NSERROR_OK) {
- LOG(("relative url '%s' failed to get components", rel));
- return NSERROR_NOT_FOUND;
- }
-
- /* [1] relative URL is absolute, use it entirely */
- merged_components = rel_components;
- if (rel_components.scheme)
- goto url_join_reform_url;
-
- /* break down the base URL (possibly cached, not corruptable) */
- status = url_get_components(base, (struct url_components *) base_ptr);
- if (status != NSERROR_OK) {
- url_destroy_components((struct url_components *) rel_ptr);
- LOG(("base url '%s' failed to get components", base));
- return NSERROR_NOT_FOUND;
- }
-
- /* [2] relative authority takes presidence */
- merged_components.scheme = base_components.scheme;
- if (rel_components.authority)
- goto url_join_reform_url;
-
- /* [3] handle empty paths */
- merged_components.authority = base_components.authority;
- if (!rel_components.path) {
- merged_components.path = base_components.path;
- if (!rel_components.query)
- merged_components.query = base_components.query;
- goto url_join_reform_url;
- }
-
- /* [4] handle valid paths */
- if (rel_components.path[0] == '/')
- merged_components.path = rel_components.path;
- else {
- /* 5.2.3 */
- if ((base_components.authority) && (!base_components.path)) {
- merge_path = malloc(strlen(rel_components.path) + 2);
- if (!merge_path) {
- LOG(("malloc failed"));
- goto url_join_no_mem;
- }
- sprintf(merge_path, "/%s", rel_components.path);
- merged_components.path = merge_path;
- } else {
- split_point = base_components.path ?
- strrchr(base_components.path, '/') :
- NULL;
- if (!split_point) {
- merged_components.path = rel_components.path;
- } else {
- len = ++split_point - base_components.path;
- buf_len = len + 1 + strlen(rel_components.path);
- merge_path = malloc(buf_len);
- if (!merge_path) {
- LOG(("malloc failed"));
- goto url_join_no_mem;
- }
- memcpy(merge_path, base_components.path, len);
- memcpy(merge_path + len, rel_components.path,
- strlen(rel_components.path));
- merge_path[buf_len - 1] = '\0';
- merged_components.path = merge_path;
- }
- }
- }
-
-url_join_reform_url:
- /* 5.2.4 */
- input = merged_components.path;
- if ((input) && (strchr(input, '.'))) {
- /* [1] remove all dot references */
- output = start = malloc(strlen(input) + 1);
- if (!output) {
- LOG(("malloc failed"));
- goto url_join_no_mem;
- }
- merged_components.path = output;
- *output = '\0';
-
- while (*input != '\0') {
- /* [2A] */
- if (input[0] == '.') {
- if (input[1] == '/') {
- input = input + 2;
- continue;
- } else if ((input[1] == '.') &&
- (input[2] == '/')) {
- input = input + 3;
- continue;
- }
- }
-
- /* [2B] */
- if ((input[0] == '/') && (input[1] == '.')) {
- if (input[2] == '/') {
- input = input + 2;
- continue;
- } else if (input[2] == '\0') {
- input = input + 1;
- *input = '/';
- continue;
- }
-
- /* [2C] */
- if ((input[2] == '.') && ((input[3] == '/') ||
- (input[3] == '\0'))) {
- if (input[3] == '/') {
- input = input + 3;
- } else {
- input = input + 2;
- *input = '/';
- }
-
- if ((output > start) &&
- (output[-1] == '/'))
- *--output = '\0';
- split_point = strrchr(start, '/');
- if (!split_point)
- output = start;
- else
- output = split_point;
- *output = '\0';
- continue;
- }
- }
-
-
- /* [2D] */
- if (input[0] == '.') {
- if (input[1] == '\0') {
- input = input + 1;
- continue;
- } else if ((input[1] == '.') &&
- (input[2] == '\0')) {
- input = input + 2;
- continue;
- }
- }
-
- /* [2E] */
- if (*input == '/')
- *output++ = *input++;
- while ((*input != '/') && (*input != '\0'))
- *output++ = *input++;
- *output = '\0';
- }
- /* [3] */
- merged_components.path = start;
- }
-
- /* 5.3 */
- *result = url_reform_components((struct url_components *) merged_ptr);
- if (!(*result))
- goto url_join_no_mem;
-
- /* return success */
- status = NSERROR_OK;
-
-url_join_no_mem:
- free(start);
- free(merge_path);
- url_destroy_components((struct url_components *) base_ptr);
- url_destroy_components((struct url_components *) rel_ptr);
- return status;
-}
-
-
-/* exported interface documented in utils/url.h */
-nserror url_host(const char *url, char **result)
-{
- nserror status;
- struct url_components components;
- const char *host_start, *host_end;
-
- assert(url);
-
- status = url_get_components(url, &components);
- if (status == NSERROR_OK) {
- if (!components.authority) {
- url_destroy_components(&components);
- return NSERROR_NOT_FOUND;
- }
- host_start = strchr(components.authority, '@');
- host_start = host_start ? host_start + 1 : components.authority;
-
- /* skip over an IPv6 address if there is one */
- if (host_start[0] == '[') {
- host_end = strchr(host_start, ']') + 1;
- } else {
- host_end = strchr(host_start, ':');
- }
-
- if (!host_end)
- host_end = components.authority +
- strlen(components.authority);
-
- *result = malloc(host_end - host_start + 1);
- if (!(*result)) {
- url_destroy_components(&components);
- return NSERROR_NOT_FOUND;
- }
- memcpy((*result), host_start, host_end - host_start);
- (*result)[host_end - host_start] = '\0';
- }
- url_destroy_components(&components);
- return status;
-}
-
/* exported interface documented in utils/url.h */
nserror url_scheme(const char *url, char **result)
@@ -803,68 +514,3 @@ nserror url_escape(const char *unescaped, size_t toskip,
return NSERROR_OK;
}
-
-
-#ifdef TEST
-
-int main(int argc, char *argv[])
-{
- int i;
- nserror res;
- char *s;
- url_init();
- for (i = 1; i != argc; i++) {
-/* printf("==> '%s'\n", argv[i]);
- res = url_normalize(argv[i], &s);
- if (res == NSERROR_OK) {
- printf("<== '%s'\n", s);
- free(s);
- }*/
-/* printf("==> '%s'\n", argv[i]);
- res = url_host(argv[i], &s);
- if (res == NSERROR_OK) {
- printf("<== '%s'\n", s);
- free(s);
- }*/
- if (1 != i) {
- res = url_join(argv[i], argv[1], &s);
- if (res == NSERROR_OK) {
- printf("'%s' + '%s' \t= '%s'\n", argv[1],
- argv[i], s);
- free(s);
- }
- }
-/* printf("'%s' => ", argv[i]);
- res = url_nice(argv[i], &s, true);
- if (res == NSERROR_OK) {
- printf("'%s', ", s);
- free(s);
- } else {
- printf("failed %u, ", res);
- }
- res = url_nice(argv[i], &s, false);
- if (res == NSERROR_OK) {
- printf("'%s', ", s);
- free(s);
- } else {
- printf("failed %u, ", res);
- }
- printf("\n");*/
- }
- return 0;
-}
-
-void regcomp_wrapper(regex_t *preg, const char *regex, int cflags)
-{
- char errbuf[200];
- int r;
- r = regcomp(preg, regex, cflags);
- if (r) {
- regerror(r, preg, errbuf, sizeof errbuf);
- fprintf(stderr, "Failed to compile regexp '%s'\n", regex);
- fprintf(stderr, "error: %s\n", errbuf);
- exit(1);
- }
-}
-
-#endif