From c5b6b3c567edc64b0e80db0a7602289d2471edf7 Mon Sep 17 00:00:00 2001 From: Jean Paul Galea Date: Fri, 17 Jul 2015 22:25:42 +0200 Subject: [PATCH] Refactor. - retrieveURLasync() always returns FALSE on failure now, before it might have returned a string. - use array_shift($a) to pop first element, safer than $a[0]; - this commit might affect what is written to LOG_DEBUG, since now we only write the YK-KSM message when we are certain to have a valid response. --- ykval-common.php | 14 ++++++-------- ykval-synclib.php | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ykval-common.php b/ykval-common.php index 0885839..681e09b 100644 --- a/ykval-common.php +++ b/ykval-common.php @@ -161,7 +161,6 @@ function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $ret $ch[$handle] = $handle; } - $str = false; $ans_arr = array(); do @@ -223,7 +222,7 @@ function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $ret if (count($ans_arr) > 0) return $ans_arr; - return $str; + return false; } function KSMdecryptOTP($urls, $logger, $curlopts) @@ -237,15 +236,14 @@ function KSMdecryptOTP($urls, $logger, $curlopts) $response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=False, $timeout=10, $curlopts); - if (is_array($response)) + if ($response === FALSE) { - $response = $response[0]; + return false; } - if ($response) - { - $logger->log(LOG_DEBUG, log_format('YK-KSM response: ', $response)); - } + $response = array_shift($response); + + $logger->log(LOG_DEBUG, log_format('YK-KSM response: ', $response)); if (sscanf($response, 'OK counter=%04x low=%04x high=%02x use=%02x', diff --git a/ykval-synclib.php b/ykval-synclib.php index 3e6e947..e335736 100644 --- a/ykval-synclib.php +++ b/ykval-synclib.php @@ -454,9 +454,9 @@ class SyncLib */ $ans_arr = retrieveURLasync('YK-VAL sync', $urls, $this->myLog, $ans_req, $match='status=OK', $returl=True, $timeout, $this->curlopts); - if (!is_array($ans_arr)) { + if ($ans_arr === FALSE) { $this->log(LOG_WARNING, 'No responses from validation server pool'); - $ans_arr=array(); + $ans_arr = array(); } /*