From a718223585cd54bf9a7e2fad9749dc5301a9002d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 1 Apr 2015 23:27:44 +0200 Subject: [PATCH 1/3] Remove workaround that is no longer needed This workaround was required previously but breaks the code with the corrections to the XML-RPC response. --- docs/XMLRPC/xmlrpc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/XMLRPC/xmlrpc.php b/docs/XMLRPC/xmlrpc.php index c469ab05a..ef5e9a00c 100644 --- a/docs/XMLRPC/xmlrpc.php +++ b/docs/XMLRPC/xmlrpc.php @@ -33,8 +33,8 @@ class AnopeXMLRPC $inbuf = file_get_contents($this->Host, false, $context); $response = xmlrpc_decode($inbuf); - if (isset($response[0])) - return $response[0]; + if (isset($response)) + return $response; return NULL; } From dd8dd3b4a09543bd0ab8496580c971d6e614a926 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 1 Apr 2015 23:28:41 +0200 Subject: [PATCH 2/3] Make xmlrpc.php comply with PSR-2 coding standard --- docs/XMLRPC/xmlrpc.php | 136 +++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/docs/XMLRPC/xmlrpc.php b/docs/XMLRPC/xmlrpc.php index ef5e9a00c..90e7a09c3 100644 --- a/docs/XMLRPC/xmlrpc.php +++ b/docs/XMLRPC/xmlrpc.php @@ -8,83 +8,85 @@ class AnopeXMLRPC { - private $Host; + private $Host; - function __construct($Host) - { - $this->Host = $Host; - } + public function __construct($Host) + { + $this->Host = $Host; + } - /** Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: - * $this->RunXMLRPC("checkAuthentication", array("adam", "qwerty")); - * If successful returns back an array of useful information. - * - * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. - * If you do, the same ID will be passed back with the reply from Anope. - */ - function RunXMLRPC($name, $params) - { - $xmlquery = xmlrpc_encode_request($name, $params); - $context = stream_context_create(array("http" => array( - "method" => "POST", - "header" => "Content-Type: text/xml", - "content" => $xmlquery))); + /** Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: + * $this->RunXMLRPC("checkAuthentication", array("adam", "qwerty")); + * If successful returns back an array of useful information. + * + * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. + * If you do, the same ID will be passed back with the reply from Anope. + */ + public function RunXMLRPC($name, $params) + { + $xmlquery = xmlrpc_encode_request($name, $params); + $context = stream_context_create(array("http" => array( + "method" => "POST", + "header" => "Content-Type: text/xml", + "content" => $xmlquery))); - $inbuf = file_get_contents($this->Host, false, $context); - $response = xmlrpc_decode($inbuf); + $inbuf = file_get_contents($this->Host, false, $context); + $response = xmlrpc_decode($inbuf); - if (isset($response)) - return $response; - return NULL; - } + if (isset($response)) { + return $response; + } - /** Do Command on Service as User, eg: - * $anope->DoCommand("ChanServ", "Adam", "REGISTER #adam"); - * Returns an array of information regarding the command execution, if - * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. - * If 'online' is set to no, then the reply to the command is in the array member 'return' - */ - function DoCommand($Service, $User, $Command) - { - return $this->RunXMLRPC("command", array($Service, $User, $Command)); - } + return null; + } - /** Check an account/nick name and password to see if they are valid - * Returns the account display name if valid - */ - function CheckAuthentication($Account, $Pass) - { - $ret = $this->RunXMLRPC("checkAuthentication", array($Account, $Pass)); + /** Do Command on Service as User, eg: + * $anope->DoCommand("ChanServ", "Adam", "REGISTER #adam"); + * Returns an array of information regarding the command execution, if + * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. + * If 'online' is set to no, then the reply to the command is in the array member 'return' + */ + public function DoCommand($Service, $User, $Command) + { + return $this->RunXMLRPC("command", array($Service, $User, $Command)); + } - if ($ret && $ret["result"] == "Success") - return $ret["account"]; - return NULL; - } + /** Check an account/nick name and password to see if they are valid + * Returns the account display name if valid + */ + public function CheckAuthentication($Account, $Pass) + { + $ret = $this->RunXMLRPC("checkAuthentication", array($Account, $Pass)); - /* Returns an array of misc stats regarding Anope - */ - function DoStats() - { - return $this->RunXMLRPC("stats", NULL); - } + if ($ret && $ret["result"] == "Success") { + return $ret["account"]; + } - /* Look up data for a channel - * Returns an array containing channel information, or an array of size one - * (just containing the name) if the channel does not exist - */ - function DoChannel($Channel) - { - return $this->RunXMLRPC("channel", array($Channel)); - } + return null; + } - /* Like DoChannel(), but different. - */ - function DoUser($User) - { - return $this->RunXMLRPC("user", array($User)); - } + /* Returns an array of misc stats regarding Anope + */ + public function DoStats() + { + return $this->RunXMLRPC("stats", null); + } + + /* Look up data for a channel + * Returns an array containing channel information, or an array of size one + * (just containing the name) if the channel does not exist + */ + public function DoChannel($Channel) + { + return $this->RunXMLRPC("channel", array($Channel)); + } + + /* Like DoChannel(), but different. + */ + public function DoUser($User) + { + return $this->RunXMLRPC("user", array($User)); + } } $anopexmlrpc = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc"); - -?> From 41f4c7dab66765e4e759559b97b4a37317a32090 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 4 Apr 2015 09:43:51 +0200 Subject: [PATCH 3/3] A variety of small improvements to xmlrpc.php Pretty simple stuff. * Better method names * Better DocBlocks * Lowercase variables --- docs/XMLRPC/xmlrpc.php | 103 ++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 33 deletions(-) diff --git a/docs/XMLRPC/xmlrpc.php b/docs/XMLRPC/xmlrpc.php index 90e7a09c3..2b5645ca7 100644 --- a/docs/XMLRPC/xmlrpc.php +++ b/docs/XMLRPC/xmlrpc.php @@ -1,62 +1,88 @@ Host = $Host; + $this->host = $host; } - /** Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: - * $this->RunXMLRPC("checkAuthentication", array("adam", "qwerty")); + /** + * Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: + * $this->raw("checkAuthentication", ["adam", "qwerty"]); * If successful returns back an array of useful information. * * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. * If you do, the same ID will be passed back with the reply from Anope. + * + * @param $name + * @param $params + * @return array|null */ - public function RunXMLRPC($name, $params) + public function run($name, $params) { $xmlquery = xmlrpc_encode_request($name, $params); - $context = stream_context_create(array("http" => array( + $context = stream_context_create(["http" => [ "method" => "POST", "header" => "Content-Type: text/xml", - "content" => $xmlquery))); + "content" => $xmlquery]]); - $inbuf = file_get_contents($this->Host, false, $context); + $inbuf = file_get_contents($this->host, false, $context); $response = xmlrpc_decode($inbuf); - if (isset($response)) { + if ($response) { return $response; } return null; } - /** Do Command on Service as User, eg: - * $anope->DoCommand("ChanServ", "Adam", "REGISTER #adam"); + /** + * Do Command on Service as User, eg: + * $anope->command("ChanServ", "Adam", "REGISTER #adam"); * Returns an array of information regarding the command execution, if * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. * If 'online' is set to no, then the reply to the command is in the array member 'return' + * + * @param $service + * @param $user + * @param $command + * @return array|null */ - public function DoCommand($Service, $User, $Command) + public function command($service, $user, $command) { - return $this->RunXMLRPC("command", array($Service, $User, $Command)); + return $this->run("command", [$service, $user, $command]); } - /** Check an account/nick name and password to see if they are valid + /** + * Check an account/nick name and password to see if they are valid * Returns the account display name if valid + * + * @param $account + * @param $pass + * @return string|null */ - public function CheckAuthentication($Account, $Pass) + public function auth($account, $pass) { - $ret = $this->RunXMLRPC("checkAuthentication", array($Account, $Pass)); + $ret = $this->run("checkAuthentication", [$account, $pass]); if ($ret && $ret["result"] == "Success") { return $ret["account"]; @@ -65,28 +91,39 @@ class AnopeXMLRPC return null; } - /* Returns an array of misc stats regarding Anope + /** + * Returns an array of misc stats regarding Anope + * + * @return array|null */ - public function DoStats() + public function stats() { - return $this->RunXMLRPC("stats", null); + return $this->run("stats", null); } - /* Look up data for a channel + /** + * Look up data for a channel * Returns an array containing channel information, or an array of size one * (just containing the name) if the channel does not exist + * + * @param $channel + * @return array|null */ - public function DoChannel($Channel) + public function channel($channel) { - return $this->RunXMLRPC("channel", array($Channel)); + return $this->run("channel", [$channel]); } - /* Like DoChannel(), but different. + /** + * Like channel(), but different. + * + * @param $user + * @return array|null */ - public function DoUser($User) + public function user($user) { - return $this->RunXMLRPC("user", array($User)); + return $this->run("user", [$user]); } } -$anopexmlrpc = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc"); +$anope = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc");