Commit c493b26b authored by Pekka Pessi's avatar Pekka Pessi

Added host_has_domain_invalid().

darcs-hash:20060315150405-65a35-76d861b0b9b510221605394f77dccdcb251e907f.gz
parent e4eba7f3
......@@ -446,7 +446,7 @@ int span_ip6_reference(char const *host)
{
/* IPv6reference = "[" IPv6address "]" */
if (host[0] == '[') {
if (host && host[0] == '[') {
int n = span_ip6_address(host + 1);
if (n > 0 && host[n + 1] == ']')
return n + 2;
......@@ -710,8 +710,8 @@ int host_is_ip_address(char const *string)
*/
int host_is_domain(char *string)
{
int n = span_domain(string);
return n > 0 && string[n] == '\0';
int n = string ? span_domain(string) : 0;
return string && n > 0 && string[n] == '\0';
}
/** Return true if @a string is valid a host name.
......@@ -723,3 +723,23 @@ int host_is_valid(char const *string)
int n = span_host(string);
return n > 0 && string[n] == '\0';
}
/** Return true if @a string has domain name in "invalid." domain.
*
*/
int host_has_domain_invalid(char const *string)
{
int n = span_domain(string);
if (n >= 7 && string[n] == '\0') {
static char const invalid[] = ".invalid";
if (string[n - 1] == '.') /* .invalid. perhaps? */
n--;
if (n == 7 /* strlen("invalid") */)
return strncasecmp(string, invalid + 1, 7) == 0;
else
return strncasecmp(string + n - 8, invalid, 8) == 0;
}
return 0;
}
......@@ -47,6 +47,7 @@ SOFIAPUBFUN int host_ip6_reference(char const *string);
SOFIAPUBFUN int host_is_ip_address(char const *string);
SOFIAPUBFUN int host_is_domain(char *string);
SOFIAPUBFUN int host_is_valid(char const *string);
SOFIAPUBFUN int host_has_domain_invalid(char const *string);
SOFIA_END_DECLS
......
......@@ -240,10 +240,20 @@ int ip_test(void)
int n = sizeof(input) - sizeof(output); \
TEST(scanner(&s), n); TEST_S(s, output); TEST_S(s0, canonic); } while(0)
#include <sofia-sip/hostdomain.h>
int host_test(void)
{
BEGIN();
TEST(host_is_ip4_address(NULL), 0);
TEST(host_is_ip6_address(NULL), 0);
TEST(host_ip6_reference(NULL), 0);
TEST(host_is_ip_address(NULL), 0);
TEST(host_is_domain(NULL), 0);
TEST(host_is_valid(NULL), 0);
TEST(host_has_domain_invalid(NULL), 0);
TEST(span_host("rama"), 4);
TEST(span_host("ra-ma.1-2.3-4.a4-9."), 19);
TEST(span_host("a.1.b"), 5);
......@@ -279,6 +289,14 @@ int host_test(void)
TEST(span_domain("a.b.-"), 0);
TEST(span_domain("a.b-"), 0);
TEST(host_has_domain_invalid("invalid"), 1);
TEST(host_has_domain_invalid("invalid."), 1);
TEST(host_has_domain_invalid("1.invalid"), 1);
TEST(host_has_domain_invalid("1.invalid."), 1);
TEST(host_has_domain_invalid("1invalid"), 0);
TEST(host_has_domain_invalid("valid."), 0);
TEST(host_has_domain_invalid("1-.invalid."), 0);
END();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment