Skip to content

Commit

Permalink
Move DNS/HTTP to public so that they can be loaded on-demand
Browse files Browse the repository at this point in the history
Also, allows easier alteration of base drivers.
  • Loading branch information
slusarz committed May 17, 2014
1 parent 1bf8c80 commit 7c3808f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 57 deletions.
Expand Up @@ -22,31 +22,18 @@
*/
class Horde_Mail_Autoconfig_Driver_Guess extends Horde_Mail_Autoconfig_Driver
{
/**
* Low priority: shot-in-the dark technique that has no formalized
* standard.
*/
public $priority = 30;

/**
* DNS resolver.
*
* @var Net_DNS2_Resolver
*/
protected $_dns;
public $dns;

/**
* Constructor.
*
* @param Net_DNS2_Resolver $dns Use this DNS object instead of creating
* one internally.
* Low priority: shot-in-the dark technique that has no formalized
* standard.
*/
public function __construct($dns = null)
{
$this->_dns = is_null($dns)
? new Net_DNS2_Resolver()
: $dns;
}
public $priority = 30;

/**
*/
Expand Down Expand Up @@ -126,9 +113,13 @@ protected function _resolveHosts($hosts)
{
$out = array();

if (is_null($this->dns)) {
$this->dns = new Net_DNS2_Resolver();
}

foreach ($hosts as $val) {
try {
$this->_dns->query($val->host, 'A');
$this->dns->query($val->host, 'A');
$out[] = $val;
} catch (Net_DNS2_Exception $e) {
// Not found; ignore.
Expand Down
27 changes: 9 additions & 18 deletions framework/Mail_Autoconfig/lib/Horde/Mail/Autoconfig/Driver/Srv.php
Expand Up @@ -22,31 +22,18 @@
*/
class Horde_Mail_Autoconfig_Driver_Srv extends Horde_Mail_Autoconfig_Driver
{
/**
* High priority: this is a standardized (RFC) method of determining
* configuration values.
*/
public $priority = 10;

/**
* DNS resolver.
*
* @var Net_DNS2_Resolver
*/
protected $_dns;
public $dns;

/**
* Constructor.
*
* @param Net_DNS2_Resolver $dns Use this DNS object instead of creating
* one internally.
* High priority: this is a standardized (RFC) method of determining
* configuration values.
*/
public function __construct($dns = null)
{
$this->_dns = is_null($dns)
? new Net_DNS2_Resolver()
: $dns;
}
public $priority = 10;

/**
*/
Expand Down Expand Up @@ -86,10 +73,14 @@ protected function _srvSearch($domains, $queries)
{
$obs = $out = array();

if (is_null($this->dns)) {
$this->dns = new Net_DNS2_Resolver();
}

foreach ($domains as $val) {
foreach ($queries as $val2) {
try {
$res = $this->_dns->query($val2 . '._tcp.' . $val, 'SRV');
$res = $this->dns->query($val2 . '._tcp.' . $val, 'SRV');
foreach ($res->answer as $val3) {
if (strlen($val3->target)) {
$val3->query = $val2;
Expand Down
Expand Up @@ -26,6 +26,13 @@
class Horde_Mail_Autoconfig_Driver_Thunderbird
extends Horde_Mail_Autoconfig_Driver
{
/**
* Http client.
*
* @var Horde_Http_Client
*/
public $http;

/**
* URL of Mozilla ISPDB server lookup.
*
Expand All @@ -39,26 +46,6 @@ class Horde_Mail_Autoconfig_Driver_Thunderbird
*/
public $priority = 20;

/**
* Http client.
*
* @var Horde_Http_Client
*/
protected $_http;

/**
* Constructor.
*
* @param Horde_Http_Client $http Use this HTTP object instead of
* creating one internally.
*/
public function __construct($http = null)
{
$this->_http = is_null($http)
? new Horde_Http_Client()
: $http;
}

/**
*/
public function msaSearch($domains, array $opts = array())
Expand Down Expand Up @@ -127,9 +114,13 @@ protected function _process($domain, $tag, $types, $email)
);
}

if (is_null($this->http)) {
$this->http = new Horde_Http_Client();
}

foreach ($urls as $url) {
try {
$get = $this->_http->get($url);
$get = $this->http->get($url);
if ($get->code == 404) {
continue;
}
Expand Down

0 comments on commit 7c3808f

Please sign in to comment.