X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fresolver.class.php;h=aca38bb87560fc31304b019731204aa7a756dc91;hb=35fd597b272983427fd88f541ea55642e0b42c9e;hp=2677ca6f86cb5b9793d4da3690f8378ec65584d2;hpb=ff9e8f739bd4b6e184b2a6bf427334196e501da8;p=mailer.git diff --git a/inc/classes/resolver.class.php b/inc/classes/resolver.class.php index 2677ca6f86..aca38bb875 100644 --- a/inc/classes/resolver.class.php +++ b/inc/classes/resolver.class.php @@ -14,12 +14,10 @@ * $Date:: $ * * $Tag:: 0.2.1-FINAL $ * * $Author:: $ * - * Needs to be in all Files and every File needs "svn propset * - * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * - * For more information visit: http://www.mxchange.org * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * + * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -46,7 +44,7 @@ if (!defined('__SECURITY')) { class HostnameResolver { // Resolve hostname -> IP address function resolveHostname ($hostname) { - // If sql_patches is not at least 0.7.0, abort here and return the hostname (gethostbyname() may return something unwanted) + // If ext-sql_patches is not at least 0.7.0, abort here and return the hostname (gethostbyname() may return something unwanted) if (!isExtensionInstalledAndNewer('sql_patches', '0.7.0')) { // Abort here return $hostname; @@ -68,13 +66,13 @@ class HostnameResolver { $ret = '0.0.0.0'; // Search for hostname in cache - $result = SQL_QUERY_ESC("SELECT `ip` FROM `{?_MYSQL_PREFIX?}_dns_cache` WHERE `hostname`='%s' LIMIT 1", + $result = sqlQueryEscaped("SELECT `ip` FROM `{?_MYSQL_PREFIX?}_dns_cache` WHERE `hostname`='%s' LIMIT 1", array($hostname), __METHOD__, __LINE__); // Does an entry exist? - if (SQL_NUMROWS($result) == 1) { + if (sqlNumRows($result) == 1) { // Then load the hostname - list($ip) = SQL_FETCHROW($result); + list($ip) = sqlFetchRow($result); // Count cache hit incrementStatsEntry('dns_cache_hits'); @@ -85,6 +83,7 @@ class HostnameResolver { } else { // Get IP address $ip = gethostbyname($hostname); + //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, 'ip=' . $ip . ',hostname=' . $hostname . ' - RESOLVED!'); // Count lookup hit incrementStatsEntry('dns_lookup_hits'); @@ -94,11 +93,12 @@ class HostnameResolver { // Seems to be an IP! Now check deeper... if (($matches[0] == $ip) && ($matches[1] >= 0) && ($matches[1] <= 255) && ($matches[2] >= 0) && ($matches[2] <= 255) && ($matches[3] >= 0) && ($matches[3] <= 255) && ($matches[4] > 0) && ($matches[4] < 255)) { // We also cache IP addresses - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_dns_cache` (`ip`, `hostname`, `added`) VALUES('%s', '%s', NOW())", + sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_dns_cache` (`ip`, `hostname`, `added`) VALUES ('%s', '%s', NOW())", array($ip, $hostname), __METHOD__, __LINE__); // Set return value to $ip //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, sprintf("IP detected, cache entry written: %s->%s", $hostname, $ip)); + $ret = $ip; } else { // Network address or broadcast address found //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, sprintf("IP %s is possibly a network or broadcast address.", $ip)); @@ -108,7 +108,7 @@ class HostnameResolver { //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, sprintf("Cannot lookup: %s", $hostname)); } else { // Put entry in DB - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_dns_cache` (`ip`, `hostname`, `added`) VALUES('%s', '%s', NOW())", + sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_dns_cache` (`ip`, `hostname`, `added`) VALUES ('%s', '%s', NOW())", array($ip, $hostname), __METHOD__, __LINE__); // Set return value to $ip @@ -118,16 +118,16 @@ class HostnameResolver { } // Free result - SQL_FREERESULT($result); + sqlFreeResult($result); - // Return IP number (let's hope it! + // Return IP number (let's hope it) return $ret; } // Purge old entries function purgeEntries() { // SQL for cleaning up - SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_dns_cache` WHERE UNIX_TIMESTAMP(`added`) < (UNIX_TIMESTAMP() - {?dns_cache_timeout?})', + sqlQuery('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_dns_cache` WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`added`) >= {?dns_cache_timeout?})', __METHOD__, __LINE__); } }