Skip to content

Commit

Permalink
Merge pull request bcit-ci#2025 from vkeranov/develop
Browse files Browse the repository at this point in the history
Some minor changes to Xmlrpc.php and Xmlrpcs.php
  • Loading branch information
narfbg committed Nov 23, 2012
2 parents 44c3463 + 52de379 commit a815dbf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 43 deletions.
25 changes: 12 additions & 13 deletions system/libraries/Xmlrpc.php
Expand Up @@ -231,7 +231,7 @@ class CI_Xmlrpc {
*
* @var array
*/
public $response = array(); // Response from remote server
public $response = array(); // Response from remote server

/**
* XSS Filter flag
Expand Down Expand Up @@ -265,7 +265,7 @@ public function __construct($config = array())
$this->xmlrpcBase64 => '1',
$this->xmlrpcArray => '2',
$this->xmlrpcStruct => '3'
);
);

// Array of Valid Parents for Various XML-RPC elements
$this->valid_parents = array('BOOLEAN' => array('VALUE'),
Expand All @@ -285,22 +285,21 @@ public function __construct($config = array())
'DATA' => array('ARRAY'),
'FAULT' => array('METHODRESPONSE'),
'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT')
);

);

// XML-RPC Responses
$this->xmlrpcerr['unknown_method'] = '1';
$this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server';
$this->xmlrpcerr['invalid_return'] = '2';
$this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.';
$this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.';
$this->xmlrpcerr['incorrect_params'] = '3';
$this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method';
$this->xmlrpcerr['introspect_unknown'] = '4';
$this->xmlrpcstr['introspect_unknown'] = 'Cannot inspect signature for request: method unknown';
$this->xmlrpcerr['http_error'] = '5';
$this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server.";
$this->xmlrpcerr['no_data'] = '6';
$this->xmlrpcstr['no_data'] ='No data received from server.';
$this->xmlrpcstr['no_data'] = 'No data received from server.';

$this->initialize($config);

Expand Down Expand Up @@ -946,7 +945,7 @@ public function xmlrpc_decoder($xmlrpc_val)
*/
public function iso8601_decode($time, $utc = FALSE)
{
// return a time in the localtime, or UTC
// Return a time in the localtime, or UTC
$t = 0;
if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs))
{
Expand Down Expand Up @@ -1081,7 +1080,7 @@ public function parseResponse($fp)
}

//-------------------------------------
// Create and Set Up XML Parser
// Create and Set Up XML Parser
//-------------------------------------

$parser = xml_parser_create($this->xmlrpc_defencoding);
Expand Down Expand Up @@ -1119,7 +1118,7 @@ public function parseResponse($fp)
$errstr = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser));
//error_log($errstr);

$r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
xml_parser_free($parser);
return $r;
Expand Down Expand Up @@ -1230,7 +1229,7 @@ public function open_tag($the_parser, $name)
elseif ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE))
{
$this->xh[$the_parser]['isf'] = 2;
$this->xh[$the_parser]['isf_reason'] = 'XML-RPC element $name cannot be child of '.$this->xh[$the_parser]['stack'][0];
$this->xh[$the_parser]['isf_reason'] = 'XML-RPC element '.$name.' cannot be child of '.$this->xh[$the_parser]['stack'][0];
return;
}

Expand Down Expand Up @@ -1268,7 +1267,7 @@ public function open_tag($the_parser, $name)
{
//two data elements inside a value: an error occurred!
$this->xh[$the_parser]['isf'] = 2;
$this->xh[$the_parser]['isf_reason'] = "'Twas a ".$name.' element following a '
$this->xh[$the_parser]['isf_reason'] = 'There is a '.$name.' element following a '
.$this->xh[$the_parser]['vt'].' element inside a single value';
return;
}
Expand Down Expand Up @@ -1380,7 +1379,7 @@ public function closing_tag($the_parser, $name)
break;
case 'VALUE':
// This if() detects if no scalar was inside <VALUE></VALUE>
if ($this->xh[$the_parser]['vt']=='value')
if ($this->xh[$the_parser]['vt'] == 'value')
{
$this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
$this->xh[$the_parser]['vt'] = $this->xmlrpcString;
Expand Down Expand Up @@ -1613,7 +1612,7 @@ public function __construct($val = -1, $type = '')

if ($this->xmlrpcTypes[$type] == 1)
{
$this->addScalar($val,$type);
$this->addScalar($val, $type);
}
elseif ($this->xmlrpcTypes[$type] == 2)
{
Expand Down
57 changes: 27 additions & 30 deletions system/libraries/Xmlrpcs.php
Expand Up @@ -47,10 +47,10 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
*/
class CI_Xmlrpcs extends CI_Xmlrpc
{
class CI_Xmlrpcs extends CI_Xmlrpc {

/**
* array of methods mapped to function names and signatures
* Array of methods mapped to function names and signatures
*
* @var array
*/
Expand Down Expand Up @@ -187,9 +187,9 @@ public function serve()
public function add_to_map($methodname, $function, $sig, $doc)
{
$this->methods[$methodname] = array(
'function' => $function,
'signature' => $sig,
'docstring' => $doc
'function' => $function,
'signature' => $sig,
'docstring' => $doc
);
}

Expand Down Expand Up @@ -237,15 +237,15 @@ public function parseRequest($data = '')
//xml_set_default_handler($parser, 'default_handler');

//-------------------------------------
// PARSE + PROCESS XML DATA
// PARSE + PROCESS XML DATA
//-------------------------------------

if ( ! xml_parse($parser, $data, 1))
{
// return XML error as a faultCode
// Return XML error as a faultCode
$r = new XML_RPC_Response(0,
$this->xmlrpcerrxml + xml_get_error_code($parser),
sprintf('XML error: %s at line %d',
$this->xmlrpcerrxml + xml_get_error_code($parser),
sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
xml_parser_free($parser);
Expand All @@ -259,7 +259,7 @@ public function parseRequest($data = '')
xml_parser_free($parser);

$m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
$plist='';
$plist = '';

for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++)
{
Expand All @@ -280,7 +280,7 @@ public function parseRequest($data = '')
}

//-------------------------------------
// SET DEBUGGING MESSAGE
// SET DEBUGGING MESSAGE
//-------------------------------------

if ($this->debug === TRUE)
Expand Down Expand Up @@ -312,7 +312,7 @@ protected function _execute($m)
}

//-------------------------------------
// Valid Method
// Valid Method
//-------------------------------------

if ( ! isset($this->methods[$methName]['function']))
Expand All @@ -321,7 +321,7 @@ protected function _execute($m)
}

//-------------------------------------
// Check for Method (and Object)
// Check for Method (and Object)
//-------------------------------------

$method_parts = explode('.', $this->methods[$methName]['function']);
Expand All @@ -342,7 +342,7 @@ protected function _execute($m)
}

//-------------------------------------
// Checking Methods Signature
// Checking Methods Signature
//-------------------------------------

if (isset($this->methods[$methName]['signature']))
Expand Down Expand Up @@ -375,7 +375,7 @@ protected function _execute($m)
}

//-------------------------------------
// Calls the Function
// Calls the Function
//-------------------------------------

if ($objectCall === TRUE)
Expand All @@ -394,7 +394,6 @@ protected function _execute($m)
else
{
return $this->object->$method_parts[1]($m);
//return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
}
}
}
Expand All @@ -407,7 +406,7 @@ protected function _execute($m)
// --------------------------------------------------------------------

/**
* Server Function: List Methods
* Server Function: List Methods
*
* @param mixed
* @return object
Expand All @@ -434,7 +433,7 @@ public function listMethods($m)
// --------------------------------------------------------------------

/**
* Server Function: Return Signature for Method
* Server Function: Return Signature for Method
*
* @param mixed
* @return object
Expand Down Expand Up @@ -468,13 +467,13 @@ public function methodSignature($m)
return new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
}

return new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
}

// --------------------------------------------------------------------

/**
* Server Function: Doc String for Method
* Server Function: Doc String for Method
*
* @param mixed
* @return object
Expand All @@ -499,7 +498,7 @@ public function methodHelp($m)
// --------------------------------------------------------------------

/**
* Server Function: Multi-call
* Server Function: Multi-call
*
* @param mixed
* @return object
Expand All @@ -516,10 +515,8 @@ public function multicall($m)

foreach ($calls as $value)
{
//$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1]));

$m = new XML_RPC_Message($value[0]);
$plist='';
$plist = '';

for ($i = 0, $c = count($value[1]); $i < $c; $i++)
{
Expand All @@ -542,14 +539,14 @@ public function multicall($m)
// --------------------------------------------------------------------

/**
* Multi-call Function: Error Handling
* Multi-call Function: Error Handling
*
* @param mixed
* @return object
*/
public function multicall_error($err)
{
$str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
$str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
$code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();

$struct['faultCode'] = new XML_RPC_Values($code, 'int');
Expand All @@ -561,7 +558,7 @@ public function multicall_error($err)
// --------------------------------------------------------------------

/**
* Multi-call Function: Processes method
* Multi-call Function: Processes method
*
* @param mixed
* @return object
Expand All @@ -577,7 +574,7 @@ public function do_multicall($call)
return $this->multicall_error('nomethod');
}

list($scalar_type,$scalar_value)=each($methName->me);
list($scalar_type, $scalar_value) = each($methName->me);
$scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;

if ($methName->kindOf() !== 'scalar' OR $scalar_type !== 'string')
Expand All @@ -597,7 +594,7 @@ public function do_multicall($call)
return $this->multicall_error('notarray');
}

list($a,$b) = each($params->me);
list($a, $b) = each($params->me);

$msg = new XML_RPC_Message($scalar_value);
for ($i = 0, $numParams = count($b); $i < $numParams; $i++)
Expand Down

0 comments on commit a815dbf

Please sign in to comment.