mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-02-16 22:43:58 +03:00
Remove unused url_components stuff.
This commit is contained in:
parent
1ccfcfe953
commit
64d591676b
141
utils/url.c
141
utils/url.c
@ -31,15 +31,6 @@
|
||||
#include "utils/utils.h"
|
||||
#include "utils/url.h"
|
||||
|
||||
struct url_components_internal {
|
||||
char *buffer; /* buffer used for all the following data */
|
||||
char *scheme;
|
||||
char *authority;
|
||||
char *path;
|
||||
char *query;
|
||||
char *fragment;
|
||||
};
|
||||
|
||||
|
||||
regex_t url_re, url_up_re;
|
||||
|
||||
@ -154,138 +145,6 @@ out_true:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a URL into separate components
|
||||
*
|
||||
* URLs passed to this function are assumed to be valid and no error checking
|
||||
* or recovery is attempted.
|
||||
*
|
||||
* See RFC 3986 for reference.
|
||||
*
|
||||
* \param url A valid absolute or relative URL.
|
||||
* \param result Pointer to buffer to hold components.
|
||||
* \return NSERROR_OK on success
|
||||
*/
|
||||
static nserror
|
||||
url_get_components(const char *url, struct url_components *result)
|
||||
{
|
||||
int storage_length;
|
||||
char *storage_end;
|
||||
const char *scheme;
|
||||
const char *authority;
|
||||
const char *path;
|
||||
const char *query;
|
||||
const char *fragment;
|
||||
struct url_components_internal *internal;
|
||||
|
||||
assert(url);
|
||||
|
||||
/* clear our return value */
|
||||
internal = (struct url_components_internal *)result;
|
||||
memset(result, 0x00, sizeof(struct url_components));
|
||||
|
||||
/* get enough storage space for a URL with termination at each node */
|
||||
storage_length = strlen(url) + 8;
|
||||
internal->buffer = malloc(storage_length);
|
||||
if (!internal->buffer)
|
||||
return NSERROR_NOMEM;
|
||||
storage_end = internal->buffer;
|
||||
|
||||
/* look for a valid scheme */
|
||||
scheme = url;
|
||||
if (isalpha(*scheme)) {
|
||||
for (scheme = url + 1;
|
||||
((*scheme != ':') && (*scheme != '\0'));
|
||||
scheme++) {
|
||||
if (!isalnum(*scheme) && (*scheme != '+') &&
|
||||
(*scheme != '-') && (*scheme != '.'))
|
||||
break;
|
||||
}
|
||||
|
||||
if (*scheme == ':') {
|
||||
memcpy(storage_end, url, scheme - url);
|
||||
storage_end[scheme - url] = '\0';
|
||||
result->scheme = storage_end;
|
||||
storage_end += scheme - url + 1;
|
||||
scheme++;
|
||||
} else {
|
||||
scheme = url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* look for an authority */
|
||||
authority = scheme;
|
||||
if ((authority[0] == '/') && (authority[1] == '/')) {
|
||||
authority = strpbrk(scheme + 2, "/?#");
|
||||
if (!authority)
|
||||
authority = scheme + strlen(scheme);
|
||||
memcpy(storage_end, scheme + 2, authority - scheme - 2);
|
||||
storage_end[authority - scheme - 2] = '\0';
|
||||
result->authority = storage_end;
|
||||
storage_end += authority - scheme - 1;
|
||||
}
|
||||
|
||||
|
||||
/* look for a path */
|
||||
path = authority;
|
||||
if ((*path != '?') && (*path != '#') && (*path != '\0')) {
|
||||
path = strpbrk(path, "?#");
|
||||
if (!path)
|
||||
path = authority + strlen(authority);
|
||||
memcpy(storage_end, authority, path - authority);
|
||||
storage_end[path - authority] = '\0';
|
||||
result->path = storage_end;
|
||||
storage_end += path - authority + 1;
|
||||
}
|
||||
|
||||
|
||||
/* look for a query */
|
||||
query = path;
|
||||
if (*query == '?') {
|
||||
query = strchr(query, '#');
|
||||
if (!query)
|
||||
query = path + strlen(path);
|
||||
memcpy(storage_end, path + 1, query - path - 1);
|
||||
storage_end[query - path - 1] = '\0';
|
||||
result->query = storage_end;
|
||||
storage_end += query - path;
|
||||
}
|
||||
|
||||
|
||||
/* look for a fragment */
|
||||
fragment = query;
|
||||
if (*fragment == '#') {
|
||||
fragment = query + strlen(query);
|
||||
|
||||
/* make a copy of the result for the caller */
|
||||
memcpy(storage_end, query + 1, fragment - query - 1);
|
||||
storage_end[fragment - query - 1] = '\0';
|
||||
result->fragment = storage_end;
|
||||
storage_end += fragment - query;
|
||||
}
|
||||
|
||||
assert((result->buffer + storage_length) >= storage_end);
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Release some url components from memory
|
||||
*
|
||||
* \param result pointer to buffer containing components
|
||||
*/
|
||||
static void url_destroy_components(const struct url_components *components)
|
||||
{
|
||||
const struct url_components_internal *internal;
|
||||
|
||||
assert(components);
|
||||
|
||||
internal = (const struct url_components_internal *)components;
|
||||
if (internal->buffer)
|
||||
free(internal->buffer);
|
||||
}
|
||||
|
||||
|
||||
/* exported interface documented in utils/url.h */
|
||||
nserror url_nice(const char *url, char **result,
|
||||
|
10
utils/url.h
10
utils/url.h
@ -33,16 +33,6 @@
|
||||
/** File url prefix length. */
|
||||
#define FILE_SCHEME_PREFIX_LEN 8
|
||||
|
||||
/** Split out components of a url. */
|
||||
struct url_components {
|
||||
const char *buffer;
|
||||
const char *scheme;
|
||||
const char *authority;
|
||||
const char *path;
|
||||
const char *query;
|
||||
const char *fragment;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initialise URL routines.
|
||||
|
Loading…
x
Reference in New Issue
Block a user