mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
More const in URI functions.
Not yet all of them, though.
This commit is contained in:
parent
c6b8fa7151
commit
b48a2d660d
@ -47,14 +47,14 @@ end_of_dir(unsigned char c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
is_uri_dir_sep(struct uri *uri, unsigned char pos)
|
is_uri_dir_sep(const struct uri *uri, unsigned char pos)
|
||||||
{
|
{
|
||||||
return (uri->protocol == PROTOCOL_FILE ? dir_sep(pos) : pos == '/');
|
return (uri->protocol == PROTOCOL_FILE ? dir_sep(pos) : pos == '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
is_ip_address(unsigned char *address, int addresslen)
|
is_ip_address(const unsigned char *address, int addresslen)
|
||||||
{
|
{
|
||||||
/* The @address has well defined limits so it would be a shame to
|
/* The @address has well defined limits so it would be a shame to
|
||||||
* allocate it. */
|
* allocate it. */
|
||||||
@ -90,7 +90,7 @@ is_ip_address(unsigned char *address, int addresslen)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
end_with_known_tld(unsigned char *s, int slen)
|
end_with_known_tld(const unsigned char *s, int slen)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static const unsigned char *const tld[] =
|
static const unsigned char *const tld[] =
|
||||||
@ -146,7 +146,7 @@ check_whether_file_exists(unsigned char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
check_uri_file(unsigned char *name)
|
check_uri_file(const unsigned char *name)
|
||||||
{
|
{
|
||||||
/* Check POST_CHAR etc ... */
|
/* Check POST_CHAR etc ... */
|
||||||
static const unsigned char chars[] = POST_CHAR_S "#?";
|
static const unsigned char chars[] = POST_CHAR_S "#?";
|
||||||
@ -409,10 +409,10 @@ parse_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
get_uri_port(struct uri *uri)
|
get_uri_port(const struct uri *uri)
|
||||||
{
|
{
|
||||||
if (uri->port && uri->portlen) {
|
if (uri->port && uri->portlen) {
|
||||||
unsigned char *end = uri->port;
|
const unsigned char *end = uri->port;
|
||||||
int port = strtol(uri->port, (char **) &end, 10);
|
int port = strtol(uri->port, (char **) &end, 10);
|
||||||
|
|
||||||
if (end != uri->port) {
|
if (end != uri->port) {
|
||||||
@ -427,7 +427,8 @@ get_uri_port(struct uri *uri)
|
|||||||
#define can_compare_uri_components(comp) !(((comp) & (URI_SPECIAL | URI_IDN)))
|
#define can_compare_uri_components(comp) !(((comp) & (URI_SPECIAL | URI_IDN)))
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
compare_component(unsigned char *a, int alen, unsigned char *b, int blen)
|
compare_component(const unsigned char *a, int alen,
|
||||||
|
const unsigned char *b, int blen)
|
||||||
{
|
{
|
||||||
/* Check that the length and the strings are both set or unset */
|
/* Check that the length and the strings are both set or unset */
|
||||||
if (alen != blen || !!a != !!b) return 0;
|
if (alen != blen || !!a != !!b) return 0;
|
||||||
@ -442,7 +443,8 @@ compare_component(unsigned char *a, int alen, unsigned char *b, int blen)
|
|||||||
#define wants(x) (components & (x))
|
#define wants(x) (components & (x))
|
||||||
|
|
||||||
int
|
int
|
||||||
compare_uri(struct uri *a, struct uri *b, enum uri_component components)
|
compare_uri(const struct uri *a, const struct uri *b,
|
||||||
|
enum uri_component components)
|
||||||
{
|
{
|
||||||
if (a == b) return 1;
|
if (a == b) return 1;
|
||||||
if (!components) return 0;
|
if (!components) return 0;
|
||||||
@ -471,7 +473,7 @@ compare_uri(struct uri *a, struct uri *b, enum uri_component components)
|
|||||||
|
|
||||||
/* We might need something more intelligent than this Swiss army knife. */
|
/* We might need something more intelligent than this Swiss army knife. */
|
||||||
struct string *
|
struct string *
|
||||||
add_uri_to_string(struct string *string, struct uri *uri,
|
add_uri_to_string(struct string *string, const struct uri *uri,
|
||||||
enum uri_component components)
|
enum uri_component components)
|
||||||
{
|
{
|
||||||
/* Custom or unknown keep the URI untouched. */
|
/* Custom or unknown keep the URI untouched. */
|
||||||
@ -578,8 +580,8 @@ add_uri_to_string(struct string *string, struct uri *uri,
|
|||||||
/* We can not test uri->datalen here since we need to always
|
/* We can not test uri->datalen here since we need to always
|
||||||
* add '/'. */
|
* add '/'. */
|
||||||
if (wants(URI_PATH) || wants(URI_FILENAME)) {
|
if (wants(URI_PATH) || wants(URI_FILENAME)) {
|
||||||
unsigned char *filename = uri->data;
|
const unsigned char *filename = uri->data;
|
||||||
unsigned char *pos;
|
const unsigned char *pos;
|
||||||
|
|
||||||
assertm(!wants(URI_FILENAME) || components == URI_FILENAME,
|
assertm(!wants(URI_FILENAME) || components == URI_FILENAME,
|
||||||
"URI_FILENAME should be used alone %d", components);
|
"URI_FILENAME should be used alone %d", components);
|
||||||
@ -602,7 +604,7 @@ add_uri_to_string(struct string *string, struct uri *uri,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wants(URI_QUERY) && uri->datalen) {
|
if (wants(URI_QUERY) && uri->datalen) {
|
||||||
unsigned char *query = memchr(uri->data, '?', uri->datalen);
|
const unsigned char *query = memchr(uri->data, '?', uri->datalen);
|
||||||
|
|
||||||
assertm(URI_QUERY == components,
|
assertm(URI_QUERY == components,
|
||||||
"URI_QUERY should be used alone %d", components);
|
"URI_QUERY should be used alone %d", components);
|
||||||
@ -642,7 +644,7 @@ add_uri_to_string(struct string *string, struct uri *uri,
|
|||||||
#undef wants
|
#undef wants
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
get_uri_string(struct uri *uri, enum uri_component components)
|
get_uri_string(const struct uri *uri, enum uri_component components)
|
||||||
{
|
{
|
||||||
struct string string;
|
struct string string;
|
||||||
|
|
||||||
@ -785,7 +787,7 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
* backend can understand. No host parts etc, that is what this function is
|
* backend can understand. No host parts etc, that is what this function is
|
||||||
* supposed to chew. */
|
* supposed to chew. */
|
||||||
static struct uri *
|
static struct uri *
|
||||||
transform_file_url(struct uri *uri, unsigned char *cwd)
|
transform_file_url(struct uri *uri, const unsigned char *cwd)
|
||||||
{
|
{
|
||||||
unsigned char *path = uri->data;
|
unsigned char *path = uri->data;
|
||||||
|
|
||||||
|
@ -247,25 +247,28 @@ unsigned char *normalize_uri(struct uri *uri, unsigned char *uristring);
|
|||||||
|
|
||||||
/* Check if two URIs are equal. If @components are 0 simply compare the whole
|
/* Check if two URIs are equal. If @components are 0 simply compare the whole
|
||||||
* URI else only compare the specific parts. */
|
* URI else only compare the specific parts. */
|
||||||
int compare_uri(struct uri *uri1, struct uri *uri2, enum uri_component components);
|
int compare_uri(const struct uri *uri1, const struct uri *uri2,
|
||||||
|
enum uri_component components);
|
||||||
|
|
||||||
/* These functions recreate the URI string part by part. */
|
/* These functions recreate the URI string part by part. */
|
||||||
/* The @components bitmask describes the set of URI components used for
|
/* The @components bitmask describes the set of URI components used for
|
||||||
* construction of the URI string. */
|
* construction of the URI string. */
|
||||||
|
|
||||||
/* Adds the components to an already initialized string. */
|
/* Adds the components to an already initialized string. */
|
||||||
struct string *add_uri_to_string(struct string *string, struct uri *uri, enum uri_component components);
|
struct string *add_uri_to_string(struct string *string, const struct uri *uri,
|
||||||
|
enum uri_component components);
|
||||||
|
|
||||||
/* Takes an uri string, parses it and adds the desired components. Useful if
|
/* Takes an uri string, parses it and adds the desired components. Useful if
|
||||||
* there is no struct uri around. */
|
* there is no struct uri around. */
|
||||||
struct string *add_string_uri_to_string(struct string *string, unsigned char *uristring, enum uri_component components);
|
struct string *add_string_uri_to_string(struct string *string, unsigned char *uristring, enum uri_component components);
|
||||||
|
|
||||||
/* Returns the new URI string or NULL upon an error. */
|
/* Returns the new URI string or NULL upon an error. */
|
||||||
unsigned char *get_uri_string(struct uri *uri, enum uri_component components);
|
unsigned char *get_uri_string(const struct uri *uri,
|
||||||
|
enum uri_component components);
|
||||||
|
|
||||||
/* Returns either the uri's port number if available or the protocol's
|
/* Returns either the uri's port number if available or the protocol's
|
||||||
* default port. It is zarro for user protocols. */
|
* default port. It is zarro for user protocols. */
|
||||||
int get_uri_port(struct uri *uri);
|
int get_uri_port(const struct uri *uri);
|
||||||
|
|
||||||
/* Tcp port range */
|
/* Tcp port range */
|
||||||
#define LOWEST_PORT 0
|
#define LOWEST_PORT 0
|
||||||
@ -304,7 +307,7 @@ unsigned char *join_urls(struct uri *base, unsigned char *relative);
|
|||||||
/* Return position if end of string @s matches a known tld or -1 if not.
|
/* Return position if end of string @s matches a known tld or -1 if not.
|
||||||
* If @slen < 0, then string length will be obtained by a strlen() call,
|
* If @slen < 0, then string length will be obtained by a strlen() call,
|
||||||
* else @slen is used as @s length. */
|
* else @slen is used as @s length. */
|
||||||
int end_with_known_tld(unsigned char *s, int slen);
|
int end_with_known_tld(const unsigned char *s, int slen);
|
||||||
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
@ -314,6 +317,6 @@ get_real_uri_length(struct uri *uri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Checks if @address contains a valid IP address. */
|
/* Checks if @address contains a valid IP address. */
|
||||||
int is_ip_address(unsigned char *address, int addresslen);
|
int is_ip_address(const unsigned char *address, int addresslen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user