1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

Move is_in_domain from cookies/cookies.c to protocol/uri.c and export

This commit is contained in:
Miciah Dashiel Butler Masters 2007-08-29 13:33:19 +00:00 committed by Laurent MONIN
parent e07354f5d5
commit a46379a931
3 changed files with 28 additions and 26 deletions

View File

@ -601,32 +601,6 @@ accept_cookie_never(void *idp)
}
#endif
/* Check whether domain is matching server
* Ie.
* example.com matches www.example.com/
* example.com doesn't match www.example.com.org/
* example.com doesn't match www.example.comm/
* example.com doesn't match example.co
*/
static int
is_in_domain(unsigned char *domain, unsigned char *server, int server_len)
{
int domain_len = strlen(domain);
int len;
if (domain_len > server_len)
return 0;
if (domain_len == server_len)
return !strncasecmp(domain, server, server_len);
len = server_len - domain_len;
if (server[len - 1] != '.')
return 0;
return !strncasecmp(domain, server + len, domain_len);
}
static inline int
is_path_prefix(unsigned char *d, unsigned char *s)

View File

@ -57,6 +57,25 @@ is_uri_dir_sep(const struct uri *uri, unsigned char pos)
}
int
is_in_domain(unsigned char *domain, unsigned char *server, int server_len)
{
int domain_len = strlen(domain);
int len;
if (domain_len > server_len)
return 0;
if (domain_len == server_len)
return !strncasecmp(domain, server, server_len);
len = server_len - domain_len;
if (server[len - 1] != '.')
return 0;
return !strncasecmp(domain, server + len, domain_len);
}
int
is_ip_address(const unsigned char *address, int addresslen)
{

View File

@ -319,4 +319,13 @@ get_real_uri_length(struct uri *uri)
/* Checks if @address contains a valid IP address. */
int is_ip_address(const unsigned char *address, int addresslen);
/* Check whether domain is matching server
* Ie.
* example.com matches www.example.com/
* example.com doesn't match www.example.com.org/
* example.com doesn't match www.example.comm/
* example.com doesn't match example.co
*/
int is_in_domain(unsigned char *domain, unsigned char *server, int server_len);
#endif