2004-05-22 18:44:45 +02:00
|
|
|
<?php
|
2007-12-20 23:28:54 +01:00
|
|
|
/**
|
2010-09-13 18:36:08 +02:00
|
|
|
* IXR - The Incutio XML-RPC Library
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Incutio Ltd.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* - Neither the name of Incutio Ltd. nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
|
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-12-20 23:28:54 +01:00
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*
|
2010-09-13 18:36:08 +02:00
|
|
|
* @copyright Incutio Ltd 2010 (http://www.incutio.com)
|
|
|
|
* @version 1.7.4 7th September 2010
|
|
|
|
* @author Simon Willison
|
|
|
|
* @link http://scripts.incutio.com/xmlrpc/ Site/manual
|
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD
|
2007-12-20 23:28:54 +01:00
|
|
|
*/
|
2004-05-22 18:44:45 +02:00
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Value
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2004-05-22 18:44:45 +02:00
|
|
|
class IXR_Value {
|
|
|
|
var $data;
|
|
|
|
var $type;
|
2008-07-19 19:56:35 +02:00
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
function IXR_Value($data, $type = false)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->data = $data;
|
|
|
|
if (!$type) {
|
|
|
|
$type = $this->calculateType();
|
|
|
|
}
|
|
|
|
$this->type = $type;
|
|
|
|
if ($type == 'struct') {
|
2010-09-13 18:36:08 +02:00
|
|
|
// Turn all the values in the array in to new IXR_Value objects
|
2004-05-22 18:44:45 +02:00
|
|
|
foreach ($this->data as $key => $value) {
|
|
|
|
$this->data[$key] = new IXR_Value($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($type == 'array') {
|
|
|
|
for ($i = 0, $j = count($this->data); $i < $j; $i++) {
|
|
|
|
$this->data[$i] = new IXR_Value($this->data[$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-19 19:56:35 +02:00
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
function calculateType()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
if ($this->data === true || $this->data === false) {
|
|
|
|
return 'boolean';
|
|
|
|
}
|
|
|
|
if (is_integer($this->data)) {
|
|
|
|
return 'int';
|
|
|
|
}
|
|
|
|
if (is_double($this->data)) {
|
|
|
|
return 'double';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Deal with IXR object types base64 and date
|
|
|
|
if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
|
|
|
|
return 'date';
|
|
|
|
}
|
|
|
|
if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
|
|
|
|
return 'base64';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// If it is a normal PHP object convert it in to a struct
|
|
|
|
if (is_object($this->data)) {
|
|
|
|
$this->data = get_object_vars($this->data);
|
|
|
|
return 'struct';
|
|
|
|
}
|
|
|
|
if (!is_array($this->data)) {
|
|
|
|
return 'string';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
// We have an array - is it an array or a struct?
|
2004-05-22 18:44:45 +02:00
|
|
|
if ($this->isStruct($this->data)) {
|
|
|
|
return 'struct';
|
|
|
|
} else {
|
|
|
|
return 'array';
|
|
|
|
}
|
|
|
|
}
|
2008-07-19 19:56:35 +02:00
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
function getXml()
|
|
|
|
{
|
|
|
|
// Return XML for this value
|
2004-05-22 18:44:45 +02:00
|
|
|
switch ($this->type) {
|
|
|
|
case 'boolean':
|
|
|
|
return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
|
|
|
|
break;
|
|
|
|
case 'int':
|
|
|
|
return '<int>'.$this->data.'</int>';
|
|
|
|
break;
|
|
|
|
case 'double':
|
|
|
|
return '<double>'.$this->data.'</double>';
|
|
|
|
break;
|
|
|
|
case 'string':
|
|
|
|
return '<string>'.htmlspecialchars($this->data).'</string>';
|
|
|
|
break;
|
|
|
|
case 'array':
|
|
|
|
$return = '<array><data>'."\n";
|
|
|
|
foreach ($this->data as $item) {
|
|
|
|
$return .= ' <value>'.$item->getXml()."</value>\n";
|
|
|
|
}
|
|
|
|
$return .= '</data></array>';
|
|
|
|
return $return;
|
|
|
|
break;
|
|
|
|
case 'struct':
|
|
|
|
$return = '<struct>'."\n";
|
|
|
|
foreach ($this->data as $name => $value) {
|
2005-06-07 09:39:39 +02:00
|
|
|
$name = htmlspecialchars($name);
|
2004-05-22 18:44:45 +02:00
|
|
|
$return .= " <member><name>$name</name><value>";
|
|
|
|
$return .= $value->getXml()."</value></member>\n";
|
|
|
|
}
|
|
|
|
$return .= '</struct>';
|
|
|
|
return $return;
|
|
|
|
break;
|
|
|
|
case 'date':
|
|
|
|
case 'base64':
|
|
|
|
return $this->data->getXml();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-19 19:56:35 +02:00
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
/**
|
|
|
|
* Checks whether or not the supplied array is a struct or not
|
|
|
|
*
|
|
|
|
* @param unknown_type $array
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function isStruct($array)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$expected = 0;
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
if ((string)$key != (string)$expected) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$expected++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
2010-09-13 18:36:08 +02:00
|
|
|
* IXR_MESSAGE
|
2008-06-14 18:50:55 +02:00
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
2010-09-13 18:36:08 +02:00
|
|
|
*
|
2008-06-14 18:50:55 +02:00
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_Message
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $message;
|
|
|
|
var $messageType; // methodCall / methodResponse / fault
|
|
|
|
var $faultCode;
|
|
|
|
var $faultString;
|
|
|
|
var $methodName;
|
|
|
|
var $params;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Current variable stacks
|
|
|
|
var $_arraystructs = array(); // The stack used to keep track of the current array/struct
|
|
|
|
var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
|
|
|
|
var $_currentStructName = array(); // A stack as well
|
|
|
|
var $_param;
|
|
|
|
var $_value;
|
|
|
|
var $_currentTag;
|
|
|
|
var $_currentTagContents;
|
|
|
|
// The XML parser
|
|
|
|
var $_parser;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Message($message)
|
|
|
|
{
|
|
|
|
$this->message =& $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse()
|
|
|
|
{
|
|
|
|
// first remove the XML declaration
|
|
|
|
// merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
|
|
|
|
$header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1);
|
|
|
|
$this->message = substr_replace($this->message, $header, 0, 100);
|
2004-05-22 18:44:45 +02:00
|
|
|
if (trim($this->message) == '') {
|
|
|
|
return false;
|
2010-09-13 18:36:08 +02:00
|
|
|
}
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->_parser = xml_parser_create();
|
|
|
|
// Set XML parser to take the case of tags in to account
|
|
|
|
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
// Set XML parser callback functions
|
|
|
|
xml_set_object($this->_parser, $this);
|
|
|
|
xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
|
2010-09-13 18:36:08 +02:00
|
|
|
xml_set_character_data_handler($this->_parser, 'cdata');
|
|
|
|
$chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages
|
2010-12-07 19:55:13 +01:00
|
|
|
$final = false;
|
2010-09-13 18:36:08 +02:00
|
|
|
do {
|
|
|
|
if (strlen($this->message) <= $chunk_size) {
|
|
|
|
$final = true;
|
|
|
|
}
|
|
|
|
$part = substr($this->message, 0, $chunk_size);
|
|
|
|
$this->message = substr($this->message, $chunk_size);
|
|
|
|
if (!xml_parse($this->_parser, $part, $final)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($final) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
xml_parser_free($this->_parser);
|
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Grab the error messages, if any
|
|
|
|
if ($this->messageType == 'fault') {
|
|
|
|
$this->faultCode = $this->params[0]['faultCode'];
|
|
|
|
$this->faultString = $this->params[0]['faultString'];
|
2010-09-13 18:36:08 +02:00
|
|
|
}
|
2004-05-22 18:44:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function tag_open($parser, $tag, $attr)
|
|
|
|
{
|
2008-07-19 19:56:35 +02:00
|
|
|
$this->_currentTagContents = '';
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->currentTag = $tag;
|
|
|
|
switch($tag) {
|
|
|
|
case 'methodCall':
|
|
|
|
case 'methodResponse':
|
|
|
|
case 'fault':
|
|
|
|
$this->messageType = $tag;
|
|
|
|
break;
|
2010-09-13 18:36:08 +02:00
|
|
|
/* Deal with stacks of arrays and structs */
|
2004-05-22 18:44:45 +02:00
|
|
|
case 'data': // data is to all intents and puposes more interesting than array
|
|
|
|
$this->_arraystructstypes[] = 'array';
|
|
|
|
$this->_arraystructs[] = array();
|
|
|
|
break;
|
|
|
|
case 'struct':
|
|
|
|
$this->_arraystructstypes[] = 'struct';
|
|
|
|
$this->_arraystructs[] = array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function cdata($parser, $cdata)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->_currentTagContents .= $cdata;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function tag_close($parser, $tag)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$valueFlag = false;
|
|
|
|
switch($tag) {
|
|
|
|
case 'int':
|
|
|
|
case 'i4':
|
2010-09-13 18:36:08 +02:00
|
|
|
$value = (int)trim($this->_currentTagContents);
|
2004-05-22 18:44:45 +02:00
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
|
|
|
case 'double':
|
2010-09-13 18:36:08 +02:00
|
|
|
$value = (double)trim($this->_currentTagContents);
|
2004-05-22 18:44:45 +02:00
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
|
|
|
case 'string':
|
2010-09-13 18:36:08 +02:00
|
|
|
$value = (string)trim($this->_currentTagContents);
|
2004-05-22 18:44:45 +02:00
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
|
|
|
case 'dateTime.iso8601':
|
|
|
|
$value = new IXR_Date(trim($this->_currentTagContents));
|
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
|
|
|
case 'value':
|
|
|
|
// "If no type is indicated, the type is string."
|
|
|
|
if (trim($this->_currentTagContents) != '') {
|
|
|
|
$value = (string)$this->_currentTagContents;
|
|
|
|
$valueFlag = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'boolean':
|
2010-09-13 18:36:08 +02:00
|
|
|
$value = (boolean)trim($this->_currentTagContents);
|
2004-05-22 18:44:45 +02:00
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
|
|
|
case 'base64':
|
2010-09-13 18:36:08 +02:00
|
|
|
$value = base64_decode($this->_currentTagContents);
|
2004-05-22 18:44:45 +02:00
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
2010-09-13 18:36:08 +02:00
|
|
|
/* Deal with stacks of arrays and structs */
|
2004-05-22 18:44:45 +02:00
|
|
|
case 'data':
|
|
|
|
case 'struct':
|
|
|
|
$value = array_pop($this->_arraystructs);
|
|
|
|
array_pop($this->_arraystructstypes);
|
|
|
|
$valueFlag = true;
|
|
|
|
break;
|
|
|
|
case 'member':
|
|
|
|
array_pop($this->_currentStructName);
|
|
|
|
break;
|
|
|
|
case 'name':
|
|
|
|
$this->_currentStructName[] = trim($this->_currentTagContents);
|
|
|
|
break;
|
|
|
|
case 'methodName':
|
|
|
|
$this->methodName = trim($this->_currentTagContents);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
if ($valueFlag) {
|
|
|
|
if (count($this->_arraystructs) > 0) {
|
|
|
|
// Add value to struct or array
|
|
|
|
if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
|
|
|
|
// Add to struct
|
|
|
|
$this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
|
|
|
|
} else {
|
|
|
|
// Add to array
|
|
|
|
$this->_arraystructs[count($this->_arraystructs)-1][] = $value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Just add as a paramater
|
|
|
|
$this->params[] = $value;
|
|
|
|
}
|
|
|
|
}
|
2008-07-19 19:56:35 +02:00
|
|
|
$this->_currentTagContents = '';
|
2007-09-04 01:32:58 +02:00
|
|
|
}
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Server
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_Server
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $data;
|
|
|
|
var $callbacks = array();
|
|
|
|
var $message;
|
|
|
|
var $capabilities;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Server($callbacks = false, $data = false, $wait = false)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->setCapabilities();
|
|
|
|
if ($callbacks) {
|
|
|
|
$this->callbacks = $callbacks;
|
|
|
|
}
|
|
|
|
$this->setCallbacks();
|
2010-09-13 18:36:08 +02:00
|
|
|
if (!$wait) {
|
|
|
|
$this->serve($data);
|
|
|
|
}
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function serve($data = false)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
if (!$data) {
|
2010-09-13 18:36:08 +02:00
|
|
|
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
|
|
header('Content-Type: text/plain'); // merged from WP #9093
|
|
|
|
die('XML-RPC server accepts POST requests only.');
|
|
|
|
}
|
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
global $HTTP_RAW_POST_DATA;
|
2010-09-13 18:36:08 +02:00
|
|
|
if (empty($HTTP_RAW_POST_DATA)) {
|
|
|
|
// workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293
|
|
|
|
$data = file_get_contents('php://input');
|
|
|
|
} else {
|
|
|
|
$data =& $HTTP_RAW_POST_DATA;
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->message = new IXR_Message($data);
|
|
|
|
if (!$this->message->parse()) {
|
|
|
|
$this->error(-32700, 'parse error. not well formed');
|
|
|
|
}
|
|
|
|
if ($this->message->messageType != 'methodCall') {
|
|
|
|
$this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
|
|
|
|
}
|
|
|
|
$result = $this->call($this->message->methodName, $this->message->params);
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Is the result an error?
|
|
|
|
if (is_a($result, 'IXR_Error')) {
|
|
|
|
$this->error($result);
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Encode the result
|
|
|
|
$r = new IXR_Value($result);
|
|
|
|
$resultxml = $r->getXml();
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Create the XML
|
|
|
|
$xml = <<<EOD
|
|
|
|
<methodResponse>
|
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value>
|
2010-09-13 18:36:08 +02:00
|
|
|
$resultxml
|
2004-05-22 18:44:45 +02:00
|
|
|
</value>
|
|
|
|
</param>
|
|
|
|
</params>
|
|
|
|
</methodResponse>
|
|
|
|
|
|
|
|
EOD;
|
2010-09-13 18:36:08 +02:00
|
|
|
// Send it
|
|
|
|
$this->output($xml);
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function call($methodname, $args)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
if (!$this->hasMethod($methodname)) {
|
2010-09-13 18:36:08 +02:00
|
|
|
return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
|
|
|
$method = $this->callbacks[$methodname];
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Perform the callback and send the response
|
|
|
|
if (count($args) == 1) {
|
|
|
|
// If only one paramater just send that instead of the whole array
|
|
|
|
$args = $args[0];
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Are we dealing with a function or a method?
|
2010-09-13 18:36:08 +02:00
|
|
|
if (is_string($method) && substr($method, 0, 5) == 'this:') {
|
2004-05-22 18:44:45 +02:00
|
|
|
// It's a class method - check it exists
|
|
|
|
$method = substr($method, 5);
|
|
|
|
if (!method_exists($this, $method)) {
|
2010-09-13 18:36:08 +02:00
|
|
|
return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
//Call the method
|
2004-05-22 18:44:45 +02:00
|
|
|
$result = $this->$method($args);
|
|
|
|
} else {
|
|
|
|
// It's a function - does it exist?
|
2005-01-18 07:12:23 +01:00
|
|
|
if (is_array($method)) {
|
2010-12-08 20:27:49 +01:00
|
|
|
if (!is_callable(array($method[0], $method[1]))) {
|
2010-09-13 18:36:08 +02:00
|
|
|
return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
|
2008-07-19 19:56:35 +02:00
|
|
|
}
|
2005-01-18 07:12:23 +01:00
|
|
|
} else if (!function_exists($method)) {
|
2010-09-13 18:36:08 +02:00
|
|
|
return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Call the function
|
2005-01-18 07:12:23 +01:00
|
|
|
$result = call_user_func($method, $args);
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
function error($error, $message = false)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// Accepts either an error object or an error code and message
|
|
|
|
if ($message && !is_object($error)) {
|
|
|
|
$error = new IXR_Error($error, $message);
|
|
|
|
}
|
|
|
|
$this->output($error->getXml());
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function output($xml)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$xml = '<?xml version="1.0"?>'."\n".$xml;
|
|
|
|
$length = strlen($xml);
|
|
|
|
header('Connection: close');
|
|
|
|
header('Content-Length: '.$length);
|
|
|
|
header('Content-Type: text/xml');
|
|
|
|
header('Date: '.date('r'));
|
|
|
|
echo $xml;
|
|
|
|
exit;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function hasMethod($method)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return in_array($method, array_keys($this->callbacks));
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function setCapabilities()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// Initialises capabilities array
|
|
|
|
$this->capabilities = array(
|
|
|
|
'xmlrpc' => array(
|
|
|
|
'specUrl' => 'http://www.xmlrpc.com/spec',
|
|
|
|
'specVersion' => 1
|
2010-09-13 18:36:08 +02:00
|
|
|
),
|
2004-05-22 18:44:45 +02:00
|
|
|
'faults_interop' => array(
|
|
|
|
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
|
|
|
|
'specVersion' => 20010516
|
2010-09-13 18:36:08 +02:00
|
|
|
),
|
2004-05-22 18:44:45 +02:00
|
|
|
'system.multicall' => array(
|
|
|
|
'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
|
|
|
|
'specVersion' => 1
|
2010-09-13 18:36:08 +02:00
|
|
|
),
|
2007-09-04 01:32:58 +02:00
|
|
|
);
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getCapabilities($args)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return $this->capabilities;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function setCallbacks()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
|
|
|
|
$this->callbacks['system.listMethods'] = 'this:listMethods';
|
|
|
|
$this->callbacks['system.multicall'] = 'this:multiCall';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function listMethods($args)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// Returns a list of methods - uses array_reverse to ensure user defined
|
|
|
|
// methods are listed before server defined methods
|
|
|
|
return array_reverse(array_keys($this->callbacks));
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function multiCall($methodcalls)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// See http://www.xmlrpc.com/discuss/msgReader$1208
|
|
|
|
$return = array();
|
|
|
|
foreach ($methodcalls as $call) {
|
|
|
|
$method = $call['methodName'];
|
|
|
|
$params = $call['params'];
|
|
|
|
if ($method == 'system.multicall') {
|
|
|
|
$result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');
|
|
|
|
} else {
|
|
|
|
$result = $this->call($method, $params);
|
|
|
|
}
|
|
|
|
if (is_a($result, 'IXR_Error')) {
|
|
|
|
$return[] = array(
|
|
|
|
'faultCode' => $result->code,
|
|
|
|
'faultString' => $result->message
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$return[] = array($result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Request
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_Request
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $method;
|
|
|
|
var $args;
|
|
|
|
var $xml;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Request($method, $args)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->method = $method;
|
|
|
|
$this->args = $args;
|
|
|
|
$this->xml = <<<EOD
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<methodCall>
|
|
|
|
<methodName>{$this->method}</methodName>
|
|
|
|
<params>
|
|
|
|
|
|
|
|
EOD;
|
|
|
|
foreach ($this->args as $arg) {
|
|
|
|
$this->xml .= '<param><value>';
|
|
|
|
$v = new IXR_Value($arg);
|
|
|
|
$this->xml .= $v->getXml();
|
|
|
|
$this->xml .= "</value></param>\n";
|
|
|
|
}
|
|
|
|
$this->xml .= '</params></methodCall>';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getLength()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return strlen($this->xml);
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getXml()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return $this->xml;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Client
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
2010-09-13 18:36:08 +02:00
|
|
|
*
|
2008-06-14 18:50:55 +02:00
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_Client
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $server;
|
|
|
|
var $port;
|
|
|
|
var $path;
|
|
|
|
var $useragent;
|
|
|
|
var $response;
|
|
|
|
var $message = false;
|
|
|
|
var $debug = false;
|
2008-07-19 19:56:35 +02:00
|
|
|
var $timeout;
|
2010-10-29 00:11:16 +02:00
|
|
|
var $headers = array();
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Storage place for an error message
|
|
|
|
var $error = false;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Client($server, $path = false, $port = 80, $timeout = 15)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
if (!$path) {
|
|
|
|
// Assume we have been given a URL instead
|
|
|
|
$bits = parse_url($server);
|
|
|
|
$this->server = $bits['host'];
|
|
|
|
$this->port = isset($bits['port']) ? $bits['port'] : 80;
|
|
|
|
$this->path = isset($bits['path']) ? $bits['path'] : '/';
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Make absolutely sure we have a path
|
|
|
|
if (!$this->path) {
|
|
|
|
$this->path = '/';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->server = $server;
|
|
|
|
$this->path = $path;
|
|
|
|
$this->port = $port;
|
|
|
|
}
|
2008-07-19 19:56:35 +02:00
|
|
|
$this->useragent = 'The Incutio XML-RPC PHP Library';
|
|
|
|
$this->timeout = $timeout;
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function query()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$args = func_get_args();
|
|
|
|
$method = array_shift($args);
|
|
|
|
$request = new IXR_Request($method, $args);
|
|
|
|
$length = $request->getLength();
|
|
|
|
$xml = $request->getXml();
|
|
|
|
$r = "\r\n";
|
|
|
|
$request = "POST {$this->path} HTTP/1.0$r";
|
2009-01-05 22:32:04 +01:00
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
// Merged from WP #8145 - allow custom headers
|
|
|
|
$this->headers['Host'] = $this->server;
|
|
|
|
$this->headers['Content-Type'] = 'text/xml';
|
|
|
|
$this->headers['User-Agent'] = $this->useragent;
|
|
|
|
$this->headers['Content-Length']= $length;
|
2009-01-05 22:32:04 +01:00
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
foreach( $this->headers as $header => $value ) {
|
|
|
|
$request .= "{$header}: {$value}{$r}";
|
|
|
|
}
|
|
|
|
$request .= $r;
|
2009-01-05 22:32:04 +01:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
$request .= $xml;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Now send the request
|
|
|
|
if ($this->debug) {
|
2009-01-23 23:30:23 +01:00
|
|
|
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2005-06-07 09:39:39 +02:00
|
|
|
if ($this->timeout) {
|
|
|
|
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
|
|
|
|
} else {
|
|
|
|
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
|
|
|
|
}
|
2004-05-22 18:44:45 +02:00
|
|
|
if (!$fp) {
|
2010-09-13 18:36:08 +02:00
|
|
|
$this->error = new IXR_Error(-32300, 'transport error - could not open socket');
|
2004-05-22 18:44:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fputs($fp, $request);
|
|
|
|
$contents = '';
|
2010-09-13 18:36:08 +02:00
|
|
|
$debugContents = '';
|
2004-05-22 18:44:45 +02:00
|
|
|
$gotFirstLine = false;
|
|
|
|
$gettingHeaders = true;
|
|
|
|
while (!feof($fp)) {
|
|
|
|
$line = fgets($fp, 4096);
|
|
|
|
if (!$gotFirstLine) {
|
|
|
|
// Check line for '200'
|
|
|
|
if (strstr($line, '200') === false) {
|
2010-09-13 18:36:08 +02:00
|
|
|
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
|
2004-05-22 18:44:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$gotFirstLine = true;
|
|
|
|
}
|
|
|
|
if (trim($line) == '') {
|
|
|
|
$gettingHeaders = false;
|
|
|
|
}
|
|
|
|
if (!$gettingHeaders) {
|
2010-09-13 18:36:08 +02:00
|
|
|
// merged from WP #12559 - remove trim
|
2010-05-15 23:04:26 +02:00
|
|
|
$contents .= $line;
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2009-01-23 23:30:23 +01:00
|
|
|
if ($this->debug) {
|
2010-09-13 18:36:08 +02:00
|
|
|
$debugContents .= $line;
|
2009-01-23 23:30:23 +01:00
|
|
|
}
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
|
|
|
if ($this->debug) {
|
2010-09-13 18:36:08 +02:00
|
|
|
echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Now parse what we've got back
|
|
|
|
$this->message = new IXR_Message($contents);
|
|
|
|
if (!$this->message->parse()) {
|
|
|
|
// XML error
|
|
|
|
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Is the message a fault?
|
|
|
|
if ($this->message->messageType == 'fault') {
|
|
|
|
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Message must be OK
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getResponse()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// methodResponses can only have one param - return that
|
|
|
|
return $this->message->params[0];
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function isError()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return (is_object($this->error));
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getErrorCode()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return $this->error->code;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getErrorMessage()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return $this->error->message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Error
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_Error
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $code;
|
|
|
|
var $message;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Error($code, $message)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->code = $code;
|
2008-07-19 21:01:35 +02:00
|
|
|
$this->message = htmlspecialchars($message);
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getXml()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$xml = <<<EOD
|
|
|
|
<methodResponse>
|
|
|
|
<fault>
|
|
|
|
<value>
|
|
|
|
<struct>
|
|
|
|
<member>
|
|
|
|
<name>faultCode</name>
|
|
|
|
<value><int>{$this->code}</int></value>
|
|
|
|
</member>
|
|
|
|
<member>
|
|
|
|
<name>faultString</name>
|
|
|
|
<value><string>{$this->message}</string></value>
|
|
|
|
</member>
|
|
|
|
</struct>
|
|
|
|
</value>
|
|
|
|
</fault>
|
2007-09-04 01:32:58 +02:00
|
|
|
</methodResponse>
|
2004-05-22 18:44:45 +02:00
|
|
|
|
|
|
|
EOD;
|
|
|
|
return $xml;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Date
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2004-05-22 18:44:45 +02:00
|
|
|
class IXR_Date {
|
|
|
|
var $year;
|
|
|
|
var $month;
|
|
|
|
var $day;
|
|
|
|
var $hour;
|
|
|
|
var $minute;
|
|
|
|
var $second;
|
2008-07-22 21:53:03 +02:00
|
|
|
var $timezone;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Date($time)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// $time can be a PHP timestamp or an ISO one
|
|
|
|
if (is_numeric($time)) {
|
|
|
|
$this->parseTimestamp($time);
|
|
|
|
} else {
|
|
|
|
$this->parseIso($time);
|
|
|
|
}
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function parseTimestamp($timestamp)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->year = date('Y', $timestamp);
|
2005-06-07 09:39:39 +02:00
|
|
|
$this->month = date('m', $timestamp);
|
|
|
|
$this->day = date('d', $timestamp);
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->hour = date('H', $timestamp);
|
|
|
|
$this->minute = date('i', $timestamp);
|
|
|
|
$this->second = date('s', $timestamp);
|
2008-07-22 21:53:03 +02:00
|
|
|
$this->timezone = '';
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function parseIso($iso)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->year = substr($iso, 0, 4);
|
2004-08-26 14:40:48 +02:00
|
|
|
$this->month = substr($iso, 4, 2);
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->day = substr($iso, 6, 2);
|
|
|
|
$this->hour = substr($iso, 9, 2);
|
|
|
|
$this->minute = substr($iso, 12, 2);
|
|
|
|
$this->second = substr($iso, 15, 2);
|
2008-07-22 21:53:03 +02:00
|
|
|
$this->timezone = substr($iso, 17);
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getIso()
|
|
|
|
{
|
2008-07-22 21:53:03 +02:00
|
|
|
return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
|
2004-05-22 18:44:45 +02:00
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getXml()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getTimestamp()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_Base64
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_Base64
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $data;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_Base64($data)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->data = $data;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function getXml()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return '<base64>'.base64_encode($this->data).'</base64>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_IntrospectionServer
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_IntrospectionServer extends IXR_Server
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $signatures;
|
|
|
|
var $help;
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_IntrospectionServer()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->setCallbacks();
|
|
|
|
$this->setCapabilities();
|
|
|
|
$this->capabilities['introspection'] = array(
|
|
|
|
'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
|
|
|
|
'specVersion' => 1
|
|
|
|
);
|
|
|
|
$this->addCallback(
|
2007-09-04 01:32:58 +02:00
|
|
|
'system.methodSignature',
|
|
|
|
'this:methodSignature',
|
|
|
|
array('array', 'string'),
|
2004-05-22 18:44:45 +02:00
|
|
|
'Returns an array describing the return type and required parameters of a method'
|
|
|
|
);
|
|
|
|
$this->addCallback(
|
2007-09-04 01:32:58 +02:00
|
|
|
'system.getCapabilities',
|
|
|
|
'this:getCapabilities',
|
|
|
|
array('struct'),
|
2004-05-22 18:44:45 +02:00
|
|
|
'Returns a struct describing the XML-RPC specifications supported by this server'
|
|
|
|
);
|
|
|
|
$this->addCallback(
|
2007-09-04 01:32:58 +02:00
|
|
|
'system.listMethods',
|
|
|
|
'this:listMethods',
|
|
|
|
array('array'),
|
2004-05-22 18:44:45 +02:00
|
|
|
'Returns an array of available methods on this server'
|
|
|
|
);
|
|
|
|
$this->addCallback(
|
2007-09-04 01:32:58 +02:00
|
|
|
'system.methodHelp',
|
|
|
|
'this:methodHelp',
|
|
|
|
array('string', 'string'),
|
2004-05-22 18:44:45 +02:00
|
|
|
'Returns a documentation string for the specified method'
|
|
|
|
);
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function addCallback($method, $callback, $args, $help)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$this->callbacks[$method] = $callback;
|
|
|
|
$this->signatures[$method] = $args;
|
|
|
|
$this->help[$method] = $help;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function call($methodname, $args)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// Make sure it's in an array
|
|
|
|
if ($args && !is_array($args)) {
|
|
|
|
$args = array($args);
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Over-rides default call method, adds signature check
|
|
|
|
if (!$this->hasMethod($methodname)) {
|
|
|
|
return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
|
|
|
|
}
|
|
|
|
$method = $this->callbacks[$methodname];
|
|
|
|
$signature = $this->signatures[$methodname];
|
|
|
|
$returnType = array_shift($signature);
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Check the number of arguments
|
|
|
|
if (count($args) != count($signature)) {
|
|
|
|
return new IXR_Error(-32602, 'server error. wrong number of method parameters');
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
2004-05-22 18:44:45 +02:00
|
|
|
// Check the argument types
|
|
|
|
$ok = true;
|
|
|
|
$argsbackup = $args;
|
|
|
|
for ($i = 0, $j = count($args); $i < $j; $i++) {
|
|
|
|
$arg = array_shift($args);
|
|
|
|
$type = array_shift($signature);
|
|
|
|
switch ($type) {
|
|
|
|
case 'int':
|
|
|
|
case 'i4':
|
|
|
|
if (is_array($arg) || !is_int($arg)) {
|
|
|
|
$ok = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'base64':
|
|
|
|
case 'string':
|
|
|
|
if (!is_string($arg)) {
|
|
|
|
$ok = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'boolean':
|
|
|
|
if ($arg !== false && $arg !== true) {
|
|
|
|
$ok = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'float':
|
|
|
|
case 'double':
|
|
|
|
if (!is_float($arg)) {
|
|
|
|
$ok = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'date':
|
|
|
|
case 'dateTime.iso8601':
|
|
|
|
if (!is_a($arg, 'IXR_Date')) {
|
|
|
|
$ok = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!$ok) {
|
|
|
|
return new IXR_Error(-32602, 'server error. invalid method parameters');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// It passed the test - run the "real" method call
|
|
|
|
return parent::call($methodname, $argsbackup);
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function methodSignature($method)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
if (!$this->hasMethod($method)) {
|
|
|
|
return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
|
|
|
|
}
|
|
|
|
// We should be returning an array of types
|
|
|
|
$types = $this->signatures[$method];
|
|
|
|
$return = array();
|
|
|
|
foreach ($types as $type) {
|
|
|
|
switch ($type) {
|
|
|
|
case 'string':
|
|
|
|
$return[] = 'string';
|
|
|
|
break;
|
|
|
|
case 'int':
|
|
|
|
case 'i4':
|
|
|
|
$return[] = 42;
|
|
|
|
break;
|
|
|
|
case 'double':
|
|
|
|
$return[] = 3.1415;
|
|
|
|
break;
|
|
|
|
case 'dateTime.iso8601':
|
|
|
|
$return[] = new IXR_Date(time());
|
|
|
|
break;
|
|
|
|
case 'boolean':
|
|
|
|
$return[] = true;
|
|
|
|
break;
|
|
|
|
case 'base64':
|
|
|
|
$return[] = new IXR_Base64('base64');
|
|
|
|
break;
|
|
|
|
case 'array':
|
|
|
|
$return[] = array('array');
|
|
|
|
break;
|
|
|
|
case 'struct':
|
|
|
|
$return[] = array('struct' => 'struct');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function methodHelp($method)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
return $this->help[$method];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:50:55 +02:00
|
|
|
/**
|
|
|
|
* IXR_ClientMulticall
|
|
|
|
*
|
|
|
|
* @package IXR
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
2010-09-13 18:36:08 +02:00
|
|
|
class IXR_ClientMulticall extends IXR_Client
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
var $calls = array();
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function IXR_ClientMulticall($server, $path = false, $port = 80)
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
parent::IXR_Client($server, $path, $port);
|
|
|
|
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function addCall()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
$args = func_get_args();
|
|
|
|
$methodName = array_shift($args);
|
|
|
|
$struct = array(
|
|
|
|
'methodName' => $methodName,
|
|
|
|
'params' => $args
|
|
|
|
);
|
|
|
|
$this->calls[] = $struct;
|
|
|
|
}
|
2010-09-13 18:36:08 +02:00
|
|
|
|
|
|
|
function query()
|
|
|
|
{
|
2004-05-22 18:44:45 +02:00
|
|
|
// Prepare multicall, then call the parent::query() method
|
|
|
|
return parent::query('system.multicall', $this->calls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-20 23:28:54 +01:00
|
|
|
?>
|