dns: make ctor private
This ensures one can't instanciate a DNSResolver object by mistake, but uses the singleton. A separate create static function is added for cases where a new object is explicitely needed.
This commit is contained in:
parent
a1af0feb06
commit
5990344cb0
|
@ -334,6 +334,11 @@ DNSResolver& DNSResolver::instance()
|
||||||
return *staticInstance;
|
return *staticInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DNSResolver DNSResolver::create()
|
||||||
|
{
|
||||||
|
return DNSResolver();
|
||||||
|
}
|
||||||
|
|
||||||
bool DNSResolver::check_address_syntax(const char *addr)
|
bool DNSResolver::check_address_syntax(const char *addr)
|
||||||
{
|
{
|
||||||
// if string doesn't contain a dot, we won't consider it a url for now.
|
// if string doesn't contain a dot, we won't consider it a url for now.
|
||||||
|
|
|
@ -49,7 +49,7 @@ struct DNSResolverData;
|
||||||
*/
|
*/
|
||||||
class DNSResolver
|
class DNSResolver
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs an instance of DNSResolver
|
* @brief Constructs an instance of DNSResolver
|
||||||
|
@ -58,6 +58,8 @@ public:
|
||||||
*/
|
*/
|
||||||
DNSResolver();
|
DNSResolver();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief takes care of freeing C pointers and such
|
* @brief takes care of freeing C pointers and such
|
||||||
*/
|
*/
|
||||||
|
@ -119,6 +121,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static DNSResolver& instance();
|
static DNSResolver& instance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets a new instance of DNSResolver
|
||||||
|
*
|
||||||
|
* @return returns a pointer to the new object
|
||||||
|
*/
|
||||||
|
static DNSResolver create();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
TEST(DNSResolver, IPv4Success)
|
TEST(DNSResolver, IPv4Success)
|
||||||
{
|
{
|
||||||
tools::DNSResolver resolver;
|
tools::DNSResolver resolver = tools::DNSResolver::create();
|
||||||
|
|
||||||
bool avail, valid;
|
bool avail, valid;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ TEST(DNSResolver, IPv4Success)
|
||||||
TEST(DNSResolver, IPv4Failure)
|
TEST(DNSResolver, IPv4Failure)
|
||||||
{
|
{
|
||||||
// guaranteed by IANA/ICANN/RFC to be invalid
|
// guaranteed by IANA/ICANN/RFC to be invalid
|
||||||
tools::DNSResolver resolver;
|
tools::DNSResolver resolver = tools::DNSResolver::create();
|
||||||
|
|
||||||
bool avail, valid;
|
bool avail, valid;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ TEST(DNSResolver, IPv4Failure)
|
||||||
|
|
||||||
TEST(DNSResolver, DNSSECSuccess)
|
TEST(DNSResolver, DNSSECSuccess)
|
||||||
{
|
{
|
||||||
tools::DNSResolver resolver;
|
tools::DNSResolver resolver = tools::DNSResolver::create();
|
||||||
|
|
||||||
bool avail, valid;
|
bool avail, valid;
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ TEST(DNSResolver, DNSSECSuccess)
|
||||||
|
|
||||||
TEST(DNSResolver, DNSSECFailure)
|
TEST(DNSResolver, DNSSECFailure)
|
||||||
{
|
{
|
||||||
tools::DNSResolver resolver;
|
tools::DNSResolver resolver = tools::DNSResolver::create();
|
||||||
|
|
||||||
bool avail, valid;
|
bool avail, valid;
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ TEST(DNSResolver, DNSSECFailure)
|
||||||
// It would be great to include an IPv6 test and assume it'll pass, but not every ISP / resolver plays nicely with IPv6;)
|
// It would be great to include an IPv6 test and assume it'll pass, but not every ISP / resolver plays nicely with IPv6;)
|
||||||
/*TEST(DNSResolver, IPv6Success)
|
/*TEST(DNSResolver, IPv6Success)
|
||||||
{
|
{
|
||||||
tools::DNSResolver resolver;
|
tools::DNSResolver resolver = tools::DNSResolver::create();
|
||||||
|
|
||||||
bool avail, valid;
|
bool avail, valid;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ TEST(DNSResolver, DNSSECFailure)
|
||||||
TEST(DNSResolver, IPv6Failure)
|
TEST(DNSResolver, IPv6Failure)
|
||||||
{
|
{
|
||||||
// guaranteed by IANA/ICANN/RFC to be invalid
|
// guaranteed by IANA/ICANN/RFC to be invalid
|
||||||
tools::DNSResolver resolver;
|
tools::DNSResolver resolver = tools::DNSResolver::create();
|
||||||
|
|
||||||
bool avail, valid;
|
bool avail, valid;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue