From 610e564c2f50c01f06e4cd0333c84498e41188c0 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 15 Jan 2014 16:28:26 +0100 Subject: [PATCH] [IMPROVED] Further improvements on error handling --- public/include/classes/bitcoin.class.php | 5 +---- public/include/classes/bitcoinwrapper.class.php | 9 +++++---- public/include/lib/jsonRPCClient.php | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/public/include/classes/bitcoin.class.php b/public/include/classes/bitcoin.class.php index a26d05b1..f1512c70 100644 --- a/public/include/classes/bitcoin.class.php +++ b/public/include/classes/bitcoin.class.php @@ -266,7 +266,7 @@ class BitcoinClient extends jsonRPCClient { * @access public * @throws BitcoinClientException */ - public function __construct($scheme, $username, $password, $address = "localhost", $port = 8332, $certificate_path = '', $debug = true) { + public function __construct($scheme, $username, $password, $address = "localhost", $certificate_path = '', $debug = false) { $scheme = strtolower($scheme); if ($scheme != "http" && $scheme != "https") throw new Exception("Scheme must be http or https"); @@ -274,9 +274,6 @@ class BitcoinClient extends jsonRPCClient { throw new Exception("Username must be non-blank"); if (empty($password)) throw new Exception("Password must be non-blank"); - $port = (string) $port; - if (!$port || empty($port) || !is_numeric($port) || $port < 1 || $port > 65535 || floatval($port) != intval($port)) - throw new Exception("Port must be an integer and between 1 and 65535"); if (!empty($certificate_path) && !is_readable($certificate_path)) throw new Exception("Certificate file " . $certificate_path . " is not readable"); $uri = $scheme . "://" . $username . ":" . $password . "@" . $address . "/"; diff --git a/public/include/classes/bitcoinwrapper.class.php b/public/include/classes/bitcoinwrapper.class.php index ed4c09a8..b2167611 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -9,15 +9,16 @@ if (!defined('SECURITY')) * some basic caching functionality and some debugging **/ class BitcoinWrapper extends BitcoinClient { - public function __construct($type, $username, $password, $host, $debug, $memcache) { + public function __construct($type, $username, $password, $host, $debug_level, $debug_object, $memcache) { $this->type = $type; $this->username = $username; $this->password = $password; $this->host = $host; // $this->debug is already used - $this->oDebug = $debug; + $this->oDebug = $debug_object; $this->memcache = $memcache; - return parent::__construct($this->type, $this->username, $this->password, $this->host); + $debug_level > 0 ? $debug_level = true : $debug_level = false; + return parent::__construct($this->type, $this->username, $this->password, $this->host, '', $debug_level); } /** * Wrap variouns methods to add caching @@ -75,4 +76,4 @@ class BitcoinWrapper extends BitcoinClient { } // Load this wrapper -$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], $debug, $memcache); +$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], DEBUG, $debug, $memcache); diff --git a/public/include/lib/jsonRPCClient.php b/public/include/lib/jsonRPCClient.php index 8385b30e..f25fb0b9 100644 --- a/public/include/lib/jsonRPCClient.php +++ b/public/include/lib/jsonRPCClient.php @@ -35,7 +35,7 @@ class jsonRPCClient { * @var boolean */ private $debug; - private $debug_output; + private $debug_output = NULL; /** * The server URL @@ -69,7 +69,8 @@ class jsonRPCClient { * @return array Debug data **/ public function getDebugData() { - return $this->debug_output; + if ($this->debug) return $this->debug_output; + return false; } /** @@ -108,7 +109,6 @@ class jsonRPCClient { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); $response = curl_exec($ch); - $this->debug = true; if ($this->debug) $this->debug_output[] = 'Response: ' . $response; $response = json_decode($response, true); $resultStatus = curl_getinfo($ch);