Commit bc3aaa44 authored by Kai Vehmanen's avatar Kai Vehmanen

Added host_is_local() to bnf module.

darcs-hash:20060615144657-7659e-d8a6a2e9b5291d50f695604313639282d8e590f9.gz
parent 8c245499
......@@ -18,6 +18,10 @@ API/ABI changes and versioning
other important information to developers;
- and should be updated _continuously_! />
[libsofia-sip-ua]
- Added sofia-sip/hostdomain.h:host_is_local() (implemented
by the bnf module).
[libsofia-sip-ua-glib]
- Applications must now separately check for libsofia-sip-ua-glib
with pkg-config. The pkg-config dependency 'libsofia-sip-ua ->
......
2006-06-15 Kai Vehmanen <kai.vehmanen@nokia.com>
* sofia-sip/hostdomain.h (host_is_local): Function added.
2005-07-18 Kai Vehmanen <kai.vehmanen@nokia.com>
* Initial import of the module to Sofia-SIP tree.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
* Copyright (C) 2005,2006 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
......@@ -26,6 +26,7 @@
* @brief Character syntax table for HTTP-like protocols.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Kai Vehmanen <Kai.Vehmanen@nokia.com>
*
* @date Created: Thu Jun 8 19:28:55 2000 ppessi
*/
......@@ -724,6 +725,24 @@ int host_is_valid(char const *string)
return n > 0 && string[n] == '\0';
}
/** Returns true if @a string is describing a local address.
*
* Uses the definitions of local addresses found in RFC1700 and
* RFC4291.
*/
int host_is_local(char const *host)
{
if (host_ip6_reference(host))
return (strcmp(host, "[::1]") == 0);
else if (host_is_ip6_address(host))
return (strcmp(host, "::1") == 0);
else if (host_is_ip4_address(host))
return (strncmp(host, "127.", 4) == 0);
else
return (strcmp(host, "localhost") == 0 ||
strcmp(host, "localhost.localdomain") == 0);
}
/** Return true if @a string has domain name in "invalid." domain.
*
*/
......
......@@ -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 const *string);
SOFIAPUBFUN int host_is_valid(char const *string);
SOFIAPUBFUN int host_is_local(char const *string);
SOFIAPUBFUN int host_has_domain_invalid(char const *string);
SOFIA_END_DECLS
......
......@@ -289,6 +289,18 @@ int host_test(void)
TEST(span_domain("a.b.-"), 0);
TEST(span_domain("a.b-"), 0);
TEST(host_is_localhost("126.0.0.0"), 0);
TEST(host_is_localhost("127.0.0.0"), 1);
TEST(host_is_localhost("0.0.0.0"), 0);
TEST(host_is_localhost("::1"), 1);
TEST(host_is_localhost("::1"), 1);
TEST(host_is_localhost("::1:3fff"), 0);
TEST(host_is_localhost("[::1]"), 1);
TEST(host_is_localhost("localdomain.domain.org"), 0);
TEST(host_is_localhost("localhost.domain.org"), 0);
TEST(host_is_localhost("localhost"), 1);
TEST(host_is_localhost("localhost.localdomain"), 1);
TEST(host_has_domain_invalid("invalid"), 1);
TEST(host_has_domain_invalid("invalid."), 1);
TEST(host_has_domain_invalid("1.invalid"), 1);
......
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