From 56e3214d8e05d3b74bf728c675ce0691399b3867 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 18:36:31 +0200 Subject: Improve the Xmlrpcs library --- system/libraries/Xmlrpcs.php | 144 ++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 76 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 587b75040..893e51873 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,13 +1,13 @@ -methods = array( 'system.listMethods' => array( - 'function' => 'this.listMethods', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), - 'docstring' => 'Returns an array of available methods on this server'), - 'system.methodHelp' => array( - 'function' => 'this.methodHelp', - 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), - 'docstring' => 'Returns a documentation string for the specified method'), + 'function' => 'this.listMethods', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), + 'docstring' => 'Returns an array of available methods on this server'), + 'system.methodHelp' => array( + 'function' => 'this.methodHelp', + 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), + 'docstring' => 'Returns a documentation string for the specified method'), 'system.methodSignature' => array( - 'function' => 'this.methodSignature', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), - 'docstring' => 'Returns an array describing the return type and required parameters of a method'), - 'system.multicall' => array( - 'function' => 'this.multicall', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), - 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') - ); + 'function' => 'this.methodSignature', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), + 'docstring' => 'Returns an array describing the return type and required parameters of a method'), + 'system.multicall' => array( + 'function' => 'this.multicall', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), + 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') + ); } // -------------------------------------------------------------------- @@ -141,12 +140,10 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @access public * @return void */ - function serve() + public function serve() { $r = $this->parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; - $payload .= $this->debug_msg; - $payload .= $r->prepare_response(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response(); header("Content-Type: text/xml"); header("Content-Length: ".strlen($payload)); @@ -165,7 +162,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param string docstring * @return void */ - function add_to_map($methodname, $function, $sig, $doc) + public function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( 'function' => $function, @@ -183,7 +180,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param string data * @return object xmlrpc response */ - function parseRequest($data='') + public function parseRequest($data = '') { global $HTTP_RAW_POST_DATA; @@ -203,13 +200,14 @@ class CI_Xmlrpcs extends CI_Xmlrpc $parser = xml_parser_create($this->xmlrpc_defencoding); $parser_object = new XML_RPC_Message("filler"); - $parser_object->xh[$parser] = array(); - $parser_object->xh[$parser]['isf'] = 0; - $parser_object->xh[$parser]['isf_reason'] = ''; - $parser_object->xh[$parser]['params'] = array(); - $parser_object->xh[$parser]['stack'] = array(); - $parser_object->xh[$parser]['valuestack'] = array(); - $parser_object->xh[$parser]['method'] = ''; + $parser_object->xh[$parser] = array( + 'isf' => 0, + 'isf_reason' => '', + 'params' => array(), + 'stack' => array(), + 'valuestack' => array(), + 'method' => '' + ); xml_set_object($parser, $parser_object); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); @@ -243,7 +241,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); $plist=''; - for ($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) + for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++) { if ($this->debug === TRUE) { @@ -255,9 +253,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc if ($this->debug === TRUE) { - echo "
";
-				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
-				echo "
"; + echo "
---PLIST---\n".$plist."\n---PLIST END---\n\n
"; } $r = $this->_execute($m); @@ -284,12 +280,12 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param object * @return mixed */ - function _execute($m) + protected function _execute($m) { $methName = $m->method_name; // Check to see if it is a system call - $system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE; + $system_call = (strncmp($methName, 'system', 5) === 0); if ($this->xss_clean == FALSE) { @@ -310,22 +306,20 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- $method_parts = explode(".", $this->methods[$methName]['function']); - $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE; + $objectCall = (isset($method_parts[1]) && $method_parts[1] != ''); if ($system_call === TRUE) { - if ( ! is_callable(array($this,$method_parts['1']))) + if ( ! is_callable(array($this,$method_parts[1]))) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } } else { - if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1']))) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) + if (($objectCall AND ! is_callable(array($method_parts[0], $method_parts[1]))) + OR ( ! $objectCall AND ! is_callable($this->methods[$methName]['function'])) + ) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } @@ -338,13 +332,13 @@ class CI_Xmlrpcs extends CI_Xmlrpc if (isset($this->methods[$methName]['signature'])) { $sig = $this->methods[$methName]['signature']; - for ($i=0; $iparams)+1) + if (count($current_sig) === count($m->params)+1) { - for ($n=0; $n < count($m->params); $n++) + for ($n = 0, $mc = count($m->params); $n < $mc; $n++) { $p = $m->params[$n]; $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); @@ -370,7 +364,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc if ($objectCall === TRUE) { - if ($method_parts[0] == "this" && $system_call == TRUE) + if ($method_parts[0] === 'this' && $system_call === TRUE) { return call_user_func(array($this, $method_parts[1]), $m); } @@ -379,11 +373,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc if ($this->object === FALSE) { $CI =& get_instance(); - return $CI->$method_parts['1']($m); + return $CI->$method_parts[1]($m); } else { - return $this->object->$method_parts['1']($m); + return $this->object->$method_parts[1]($m); //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); } } @@ -393,7 +387,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - + // -------------------------------------------------------------------- /** @@ -403,7 +397,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param mixed * @return object */ - function listMethods($m) + public function listMethods($m) { $v = new XML_RPC_Values(); $output = array(); @@ -421,7 +415,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + // -------------------------------------------------------------------- /** @@ -431,7 +425,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param mixed * @return object */ - function methodSignature($m) + public function methodSignature($m) { $parameters = $m->output_parameters(); $method_name = $parameters[0]; @@ -443,15 +437,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc $sigs = array(); $signature = $this->methods[$method_name]['signature']; - for ($i=0; $i < count($signature); $i++) + for ($i = 0, $c = count($signature); $i < $c; $i++) { $cursig = array(); $inSig = $signature[$i]; - for ($j=0; $joutput_parameters(); $method_name = $parameters[0]; @@ -492,7 +486,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } - + // -------------------------------------------------------------------- /** @@ -502,7 +496,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param mixed * @return object */ - function multicall($m) + public function multicall($m) { // Disabled return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); @@ -519,7 +513,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $m = new XML_RPC_Message($value[0]); $plist=''; - for ($i=0; $i < count($value[1]); $i++) + for ($i = 0, $c = count($value[1]); $i < $c; $i++) { $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); } @@ -546,7 +540,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param mixed * @return object */ - function multicall_error($err) + public function multicall_error($err) { $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); @@ -566,7 +560,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc * @param mixed * @return object */ - function do_multicall($call) + public function do_multicall($call) { if ($call->kindOf() != 'struct') { @@ -597,11 +591,10 @@ class CI_Xmlrpcs extends CI_Xmlrpc return $this->multicall_error('notarray'); } - list($a,$b)=each($params->me); - $numParams = count($b); + list($a,$b) = each($params->me); $msg = new XML_RPC_Message($scalar_value); - for ($i = 0; $i < $numParams; $i++) + for ($i = 0, $numParams = count($b); $i < $numParams; $i++) { $msg->params[] = $params->me['array'][$i]; } @@ -619,6 +612,5 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class - /* End of file Xmlrpcs.php */ -/* Location: ./system/libraries/Xmlrpcs.php */ \ No newline at end of file +/* Location: ./system/libraries/Xmlrpcs.php */ -- cgit v1.2.3-24-g4f1b