From 514b943945e7596224cd67ca4f5fe15275aec00f Mon Sep 17 00:00:00 2001 From: Jean Paul Galea Date: Wed, 15 Jul 2015 17:52:26 +0200 Subject: [PATCH] Cosmetic changes. - remove last remaining tabs, so now the whole file is using the same indentation convention. --- ykval-synclib.php | 143 ++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 67 deletions(-) diff --git a/ykval-synclib.php b/ykval-synclib.php index 7690e9c..d234615 100644 --- a/ykval-synclib.php +++ b/ykval-synclib.php @@ -353,95 +353,104 @@ class SyncLib $ch = curl_init(); while ($entry=$this->db->fetchArray($res)) { - $this->log(LOG_INFO, "server=" . $entry['server'] . ", server_nonce=" . $entry['server_nonce'] . ", info=" . $entry['info']); - $url=$entry['server'] . - "?otp=" . $entry['otp'] . - "&modified=" . $entry['modified'] . - "&" . $this->otpPartFromInfoString($entry['info']); + $this->log(LOG_INFO, "server=" . $entry['server'] . ", server_nonce=" . $entry['server_nonce'] . ", info=" . $entry['info']); + $url=$entry['server'] . + "?otp=" . $entry['otp'] . + "&modified=" . $entry['modified'] . + "&" . $this->otpPartFromInfoString($entry['info']); - /* Send out sync request */ + /* Send out sync request */ - curl_settings($this, "YK-VAL resync", $ch, $url, $timeout, $this->curlopts); + curl_settings($this, "YK-VAL resync", $ch, $url, $timeout, $this->curlopts); - $response = curl_exec($ch); + $response = curl_exec($ch); - if ($response==False) { - $this->log(LOG_NOTICE, 'Timeout. Stopping queue resync for server ' . $entry['server']); - break; - } + if ($response==False) { + $this->log(LOG_NOTICE, 'Timeout. Stopping queue resync for server ' . $entry['server']); + break; + } - if (preg_match("/status=OK/", $response)) { - $resParams=$this->parseParamsFromMultiLineString($response); - $this->log(LOG_DEBUG, "response contains ", $resParams); + if (preg_match("/status=OK/", $response)) { + $resParams=$this->parseParamsFromMultiLineString($response); + $this->log(LOG_DEBUG, "response contains ", $resParams); - /* Update database counters */ - $this->updateDbCounters($resParams); + /* Update database counters */ + $this->updateDbCounters($resParams); - /* Retrieve info from entry info string */ + /* Retrieve info from entry info string */ - /* This is the counter values we had in our database *before* processing the current OTP. */ - $validationParams=$this->localParamsFromInfoString($entry['info']); - /* This is the data from the current OTP. */ - $otpParams=$this->otpParamsFromInfoString($entry['info']); + /* This is the counter values we had in our database *before* processing the current OTP. */ + $validationParams=$this->localParamsFromInfoString($entry['info']); + /* This is the data from the current OTP. */ + $otpParams=$this->otpParamsFromInfoString($entry['info']); - /* Fetch current information from our database */ - $localParams=$this->getLocalParams($otpParams['yk_publicname']); + /* Fetch current information from our database */ + $localParams=$this->getLocalParams($otpParams['yk_publicname']); - $this->log(LOG_DEBUG, "validation params: ", $validationParams); - $this->log(LOG_DEBUG, "OTP params: ", $otpParams); + $this->log(LOG_DEBUG, "validation params: ", $validationParams); + $this->log(LOG_DEBUG, "OTP params: ", $otpParams); - /* Check for warnings */ + /* Check for warnings */ - if ($this->countersHigherThan($validationParams, $resParams)) { - $this->log(LOG_NOTICE, "Remote server out of sync compared to counters at validation request time. "); - } + if ($this->countersHigherThan($validationParams, $resParams)) { + $this->log(LOG_NOTICE, "Remote server out of sync compared to counters at validation request time. "); + } - if ($this->countersHigherThan($resParams, $validationParams)) { - if ($this->countersEqual($resParams, $otpParams)) { - $this->log(LOG_INFO, "Remote server had received the current counter values already. "); - } else { - $this->log(LOG_NOTICE, "Local server out of sync compared to counters at validation request time. "); - } - } + if ($this->countersHigherThan($resParams, $validationParams)) { + if ($this->countersEqual($resParams, $otpParams)) { + $this->log(LOG_INFO, "Remote server had received the current counter values already. "); + } else { + $this->log(LOG_NOTICE, "Local server out of sync compared to counters at validation request time. "); + } + } - if ($this->countersHigherThan($localParams, $resParams)) { - $this->log(LOG_WARNING, "Remote server out of sync compared to current local counters. "); - } + if ($this->countersHigherThan($localParams, $resParams)) { + $this->log(LOG_WARNING, "Remote server out of sync compared to current local counters. "); + } - if ($this->countersHigherThan($resParams, $localParams)) { - $this->log(LOG_WARNING, "Local server out of sync compared to current local counters. Local server updated. "); - } + if ($this->countersHigherThan($resParams, $localParams)) { + $this->log(LOG_WARNING, "Local server out of sync compared to current local counters. Local server updated. "); + } - if ($this->countersHigherThan($resParams, $otpParams)) { - $this->log(LOG_ERR, "Remote server has higher counters than OTP. This response would have marked the OTP as invalid. "); - } - elseif ($this->countersEqual($resParams, $otpParams) && - $resParams['nonce']!=$otpParams['nonce']) { - $this->log(LOG_ERR, "Remote server has equal counters as OTP and nonce differs. This response would have marked the OTP as invalid."); - } + if ($this->countersHigherThan($resParams, $otpParams)) { + $this->log(LOG_ERR, "Remote server has higher counters than OTP. This response would have marked the OTP as invalid. "); + } + elseif ($this->countersEqual($resParams, $otpParams) + && $resParams['nonce']!=$otpParams['nonce']) { + $this->log(LOG_ERR, "Remote server has equal counters as OTP and nonce differs. This response would have marked the OTP as invalid."); + } - /* Deletion */ - $this->log(LOG_DEBUG, 'deleting queue entry with modified=' . $entry['modified'] . - ' server_nonce=' . $entry['server_nonce'] . - ' server=' . $entry['server']); - $this->db->deleteByMultiple('queue', - array("modified"=>$entry['modified'], - "server_nonce"=>$entry['server_nonce'], - 'server'=>$entry['server'])); - } else if (preg_match("/status=BAD_OTP/", $response)) { - $this->log(LOG_WARNING, "Remote server says BAD_OTP, pointless to try again, removing from queue."); - $this->db->deleteByMultiple('queue', - array("modified"=>$entry['modified'], - "server_nonce"=>$entry['server_nonce'], - 'server'=>$entry['server'])); - } else { - $this->log(LOG_ERR, "Remote server refused our sync request. Check remote server logs."); - } + /* Deletion */ + $this->log(LOG_DEBUG, 'deleting queue entry with modified=' . $entry['modified'] . + ' server_nonce=' . $entry['server_nonce'] . + ' server=' . $entry['server']); + + $this->db->deleteByMultiple('queue', array( + 'modified' => $entry['modified'], + 'server_nonce' => $entry['server_nonce'], + 'server' => $entry['server'] + )); + + } + else if (preg_match("/status=BAD_OTP/", $response)) { + $this->log(LOG_WARNING, "Remote server says BAD_OTP, pointless to try again, removing from queue."); + $this->db->deleteByMultiple('queue', array( + 'modified' => $entry['modified'], + 'server_nonce' => $entry['server_nonce'], + 'server' => $entry['server'] + )); + } + else { + $this->log(LOG_ERR, "Remote server refused our sync request. Check remote server logs."); + } } /* End of loop over each queue entry for a server */ + curl_close($ch); $this->db->closeCursor($res); + } /* End of loop over each distinct server in queue */ + $this->db->closeCursor($server_res); return true; }