Source for file RPC.php
Documentation is available at RPC.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* PHP implementation of the XML-RPC protocol
* This is a PEAR-ified version of Useful inc's XML-RPC for PHP.
* It has support for HTTP transport, proxies and authentication.
* LICENSE: License is granted to use or modify this software
* ("XML-RPC for PHP") for commercial or non-commercial use provided the
* copyright of the author is preserved in any distributed or derivative work.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED 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 AUTHOR 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.
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version CVS: $Id: RPC.php 222479 2006-10-28 16:42:34Z danielc $
* @link http://pear.php.net/package/XML_RPC
PEAR ::loadExtension ('xml');
* Parameter values don't match parameter types
define('XML_RPC_ERROR_INVALID_TYPE', 101 );
* Parameter declared to be numeric but the values are not
define('XML_RPC_ERROR_NON_NUMERIC_FOUND', 102 );
define('XML_RPC_ERROR_CONNECTION_FAILED', 103 );
* The array or struct has already been started
define('XML_RPC_ERROR_ALREADY_INITIALIZED', 104 );
* Incorrect parameters submitted
define('XML_RPC_ERROR_INCORRECT_PARAMS', 105 );
* Programming error by developer
define('XML_RPC_ERROR_PROGRAMMING', 106 );
* @global string $GLOBALS['XML_RPC_I4']
$GLOBALS['XML_RPC_I4'] = 'i4';
* @global string $GLOBALS['XML_RPC_Int']
$GLOBALS['XML_RPC_Int'] = 'int';
* @global string $GLOBALS['XML_RPC_Boolean']
$GLOBALS['XML_RPC_Boolean'] = 'boolean';
* @global string $GLOBALS['XML_RPC_Double']
$GLOBALS['XML_RPC_Double'] = 'double';
* @global string $GLOBALS['XML_RPC_String']
$GLOBALS['XML_RPC_String'] = 'string';
* @global string $GLOBALS['XML_RPC_DateTime']
$GLOBALS['XML_RPC_DateTime'] = 'dateTime.iso8601';
* @global string $GLOBALS['XML_RPC_Base64']
$GLOBALS['XML_RPC_Base64'] = 'base64';
* @global string $GLOBALS['XML_RPC_Array']
$GLOBALS['XML_RPC_Array'] = 'array';
* @global string $GLOBALS['XML_RPC_Struct']
$GLOBALS['XML_RPC_Struct'] = 'struct';
* @global array $GLOBALS['XML_RPC_Types']
$GLOBALS['XML_RPC_Types'] = array (
$GLOBALS['XML_RPC_I4'] => 1 ,
$GLOBALS['XML_RPC_Int'] => 1 ,
$GLOBALS['XML_RPC_Boolean'] => 1 ,
$GLOBALS['XML_RPC_String'] => 1 ,
$GLOBALS['XML_RPC_Double'] => 1 ,
$GLOBALS['XML_RPC_DateTime'] => 1 ,
$GLOBALS['XML_RPC_Base64'] => 1 ,
$GLOBALS['XML_RPC_Array'] => 2 ,
$GLOBALS['XML_RPC_Struct'] => 3 ,
* @global array $GLOBALS['XML_RPC_err']
$GLOBALS['XML_RPC_err'] = array (
'introspect_unknown' => 4 ,
'not_response_object' => 6 ,
* @global array $GLOBALS['XML_RPC_str']
$GLOBALS['XML_RPC_str'] = array (
'unknown_method' => 'Unknown method',
'invalid_return' => 'Invalid return payload: enable debugging to examine incoming payload',
'incorrect_params' => 'Incorrect parameters passed to method',
'introspect_unknown' => 'Can\'t introspect: method unknown',
'http_error' => 'Didn\'t receive 200 OK from remote server.',
'not_response_object' => 'The requested method didn\'t return an XML_RPC_Response object.',
'invalid_request' => 'Invalid request payload',
* Default XML encoding (ISO-8859-1, UTF-8 or US-ASCII)
* @global string $GLOBALS['XML_RPC_defencoding']
$GLOBALS['XML_RPC_defencoding'] = 'UTF-8';
* User error codes start at 800
* @global int $GLOBALS['XML_RPC_erruser']
$GLOBALS['XML_RPC_erruser'] = 800;
* XML parse error codes start at 100
* @global int $GLOBALS['XML_RPC_errxml']
$GLOBALS['XML_RPC_errxml'] = 100;
* Compose backslashes for escaping regexp
* @global string $GLOBALS['XML_RPC_backslash']
$GLOBALS['XML_RPC_backslash'] = chr(92 ) . chr(92 );
* Which functions to use, depending on whether mbstring is enabled or not.
/** @global string $GLOBALS['XML_RPC_func_ereg'] */
$GLOBALS['XML_RPC_func_ereg'] = 'mb_eregi';
/** @global string $GLOBALS['XML_RPC_func_ereg_replace'] */
$GLOBALS['XML_RPC_func_ereg_replace'] = 'mb_eregi_replace';
/** @global string $GLOBALS['XML_RPC_func_split'] */
$GLOBALS['XML_RPC_func_split'] = 'mb_split';
$GLOBALS['XML_RPC_func_ereg'] = 'eregi';
$GLOBALS['XML_RPC_func_ereg_replace'] = 'eregi_replace';
$GLOBALS['XML_RPC_func_split'] = 'split';
* Should we automatically base64 encode strings that contain characters
* which can cause PHP's SAX-based XML parser to break?
* @global boolean $GLOBALS['XML_RPC_auto_base64']
$GLOBALS['XML_RPC_auto_base64'] = false;
* Valid parents of XML elements
* @global array $GLOBALS['XML_RPC_valid_parents']
$GLOBALS['XML_RPC_valid_parents'] = array (
'BOOLEAN' => array ('VALUE'),
'STRING' => array ('VALUE'),
'DOUBLE' => array ('VALUE'),
'DATETIME.ISO8601' => array ('VALUE'),
'BASE64' => array ('VALUE'),
'ARRAY' => array ('VALUE'),
'STRUCT' => array ('VALUE'),
'PARAM' => array ('PARAMS'),
'METHODNAME' => array ('METHODCALL'),
'PARAMS' => array ('METHODCALL', 'METHODRESPONSE'),
'MEMBER' => array ('STRUCT'),
'NAME' => array ('MEMBER'),
'DATA' => array ('ARRAY'),
'FAULT' => array ('METHODRESPONSE'),
'VALUE' => array ('MEMBER', 'DATA', 'PARAM', 'FAULT'),
* Stores state during parsing
* quick explanation of components:
* + ac = accumulates values
* + qt = decides if quotes are needed for evaluation
* + cm = denotes struct or array (comma needed)
* + isf = indicates a fault
* + lv = indicates "looking for a value": implements the logic
* to allow values with no types to be strings
* + params = stores parameters in method calls
* + method = stores method name
* @global array $GLOBALS['XML_RPC_xh']
$GLOBALS['XML_RPC_xh'] = array ();
* Start element handler for the XML parser
function XML_RPC_se($parser_resource, $name, $attrs)
global $XML_RPC_xh, $XML_RPC_valid_parents;
$parser = (int) $parser_resource;
// if invalid xmlrpc already detected, skip all processing
if ($XML_RPC_xh[$parser]['isf'] >= 2 ) {
// check for correct element nesting
// top level element can only be of 2 types
if (count($XML_RPC_xh[$parser]['stack']) == 0 ) {
if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') {
$XML_RPC_xh[$parser]['isf'] = 2;
$XML_RPC_xh[$parser]['isf_reason'] = 'missing top level xmlrpc element';
// not top level element: see if parent is OK
if (!in_array($XML_RPC_xh[$parser]['stack'][0 ], $XML_RPC_valid_parents[$name])) {
$name = $GLOBALS['XML_RPC_func_ereg_replace']('[^a-zA-Z0-9._-]', '', $name);
$XML_RPC_xh[$parser]['isf'] = 2;
$XML_RPC_xh[$parser]['isf_reason'] = " xmlrpc element $name cannot be child of {$XML_RPC_xh[$parser]['stack'][0]}";
$XML_RPC_xh[$parser]['cm']++;
$XML_RPC_xh[$parser]['qt'] = 0;
$cur_val['value'] = array ();
$XML_RPC_xh[$parser]['cm']++;
$XML_RPC_xh[$parser]['qt'] = 0;
$cur_val['value'] = array ();
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['isf'] = 1;
$XML_RPC_xh[$parser]['valuestack'] = array ();
$XML_RPC_xh[$parser]['lv'] = 1;
$XML_RPC_xh[$parser]['vt'] = $GLOBALS['XML_RPC_String'];
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['qt'] = 0;
// look for a value: if this is still 1 by the
// time we reach the first data segment then the type is string
// by implication and we need to add in a quote
$XML_RPC_xh[$parser]['ac'] = ''; // reset the accumulator
if ($name == 'DATETIME.ISO8601' || $name == 'STRING') {
$XML_RPC_xh[$parser]['qt'] = 1;
if ($name == 'DATETIME.ISO8601') {
$XML_RPC_xh[$parser]['vt'] = $GLOBALS['XML_RPC_DateTime'];
} elseif ($name == 'BASE64') {
$XML_RPC_xh[$parser]['qt'] = 2;
// No quoting is required here -- but
// at the end of the element we must check
// for data format errors.
$XML_RPC_xh[$parser]['qt'] = 0;
$XML_RPC_xh[$parser]['ac'] = '';
// valid elements that add little to processing
// Save current element to stack
$XML_RPC_xh[$parser]['lv'] = 0;
* End element handler for the XML parser
$parser = (int) $parser_resource;
if ($XML_RPC_xh[$parser]['isf'] >= 2 ) {
// push this element from stack
// NB: if XML validates, correct opening/closing is guaranteed and
// we do not have to check for $name == $curr_elem.
// we also checked for proper nesting at start of elements...
$curr_elem = array_shift($XML_RPC_xh[$parser]['stack']);
$cur_val = array_shift($XML_RPC_xh[$parser]['valuestack']);
$XML_RPC_xh[$parser]['value'] = $cur_val['value'];
$XML_RPC_xh[$parser]['cm']--;
$XML_RPC_xh[$parser]['valuestack'][0 ]['name'] = $XML_RPC_xh[$parser]['ac'];
// special case here: we translate boolean 1 or 0 into PHP
// constants true or false
if ($XML_RPC_xh[$parser]['ac'] == '1') {
$XML_RPC_xh[$parser]['ac'] = 'true';
$XML_RPC_xh[$parser]['ac'] = 'false';
// Drop through intentionally.
if ($XML_RPC_xh[$parser]['qt'] == 1 ) {
// we use double quotes rather than single so backslashification works OK
$XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
} elseif ($XML_RPC_xh[$parser]['qt'] == 2 ) {
$XML_RPC_xh[$parser]['value'] = base64_decode($XML_RPC_xh[$parser]['ac']);
} elseif ($name == 'BOOLEAN') {
$XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
// we have an I4, INT or a DOUBLE
// we must check that only 0123456789-.<space> are characters here
if (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) {
$XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['qt'] = 0;
$XML_RPC_xh[$parser]['lv'] = 3; // indicate we've found a value
if ($XML_RPC_xh[$parser]['vt'] == $GLOBALS['XML_RPC_String']) {
if (strlen($XML_RPC_xh[$parser]['ac']) > 0 ) {
$XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
} elseif ($XML_RPC_xh[$parser]['lv'] == 1 ) {
// The <value> element was empty.
$XML_RPC_xh[$parser]['value'] = '';
$temp = new XML_RPC_Value($XML_RPC_xh[$parser]['value'], $XML_RPC_xh[$parser]['vt']);
$cur_val = array_shift($XML_RPC_xh[$parser]['valuestack']);
if ($cur_val['members']==0 ) {
$cur_val['value'][] = $temp;
$XML_RPC_xh[$parser]['value'] = $temp;
$XML_RPC_xh[$parser]['value'] = $temp;
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['qt'] = 0;
$cur_val = array_shift($XML_RPC_xh[$parser]['valuestack']);
if ($cur_val['members']==1 ) {
$cur_val['value'][$cur_val['name']] = $XML_RPC_xh[$parser]['value'];
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['qt'] = 0;
$XML_RPC_xh[$parser]['params'][] = $XML_RPC_xh[$parser]['value'];
$XML_RPC_xh[$parser]['method'] = $GLOBALS['XML_RPC_func_ereg_replace']("^[\n\r\t ]+", '',
$XML_RPC_xh[$parser]['ac']);
// if it's a valid type name, set the type
if (isset ($GLOBALS['XML_RPC_Types'][strtolower($name)])) {
* Character data handler for the XML parser
global $XML_RPC_xh, $XML_RPC_backslash;
$parser = (int) $parser_resource;
if ($XML_RPC_xh[$parser]['lv'] != 3 ) {
// "lookforvalue==3" means that we've found an entire value
// and should discard any further character data
if ($XML_RPC_xh[$parser]['lv'] == 1 ) {
// if we've found text and we're just in a <value> then
// turn quoting on, as this will be a string
$XML_RPC_xh[$parser]['qt'] = 1;
// and say we've found a value
$XML_RPC_xh[$parser]['lv'] = 2;
// replace characters that eval would
// do special things with
if (!isset ($XML_RPC_xh[$parser]['ac'])) {
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['ac'] .= $data;
* The common methods and properties for all of the XML_RPC classes
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version Release: 1.5.2
* @link http://pear.php.net/package/XML_RPC
* @return object PEAR_Error object
return PEAR ::raiseError (get_class($this) . ': ' . $msg, $code);
return PEAR ::raiseError ('XML_RPC: ' . $msg, $code);
* Tell whether something is a PEAR_Error object
* @param mixed $value the item to check
* @return bool whether $value is a PEAR_Error object or not
return is_a($value, 'PEAR_Error');
* The methods and properties for submitting XML RPC requests
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version Release: 1.5.2
* @link http://pear.php.net/package/XML_RPC
* The path and name of the RPC server script you want the request to go to
* The name of the remote server to connect to
* The protocol to use in contacting the remote server
* The port for connecting to the remote server
* The default is 80 for http:// connections
* and 443 for https:// and ssl:// connections.
* A user name for accessing the RPC server
* @see XML_RPC_Client::setCredentials()
* A password for accessing the RPC server
* @see XML_RPC_Client::setCredentials()
* The name of the proxy server to use, if any
* The protocol to use in contacting the proxy server, if any
* The port for connecting to the proxy server
* The default is 8080 for http:// connections
* and 443 for https:// and ssl:// connections.
* A user name for accessing the proxy server
* A password for accessing the proxy server
* The error number, if any
* The error message, if any
* The current debug mode (1 = on, 0 = off)
* The HTTP headers for the current request.
* Sets the object's properties
* @param string $path the path and name of the RPC server script
* you want the request to go to
* @param string $server the URL of the remote server to connect to.
* If this parameter doesn't specify a
* protocol and $port is 443, ssl:// is
* @param integer $port a port for connecting to the remote server.
* Defaults to 80 for http:// connections and
* 443 for https:// and ssl:// connections.
* @param string $proxy the URL of the proxy server to use, if any.
* If this parameter doesn't specify a
* protocol and $port is 443, ssl:// is
* @param integer $proxy_port a port for connecting to the remote server.
* Defaults to 8080 for http:// connections and
* 443 for https:// and ssl:// connections.
* @param string $proxy_user a user name for accessing the proxy server
* @param string $proxy_pass a password for accessing the proxy server
$proxy = '', $proxy_port = 0 ,
$proxy_user = '', $proxy_pass = '')
$GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $server, $match);
} elseif ($match[1 ] == 'http://') {
$GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $proxy, $match);
if ($proxy_port == 443 ) {
$this->proxy = $match[2 ];
$this->proxy = $match[2 ];
} elseif ($match[1 ] == 'http://') {
$this->proxy = $match[2 ];
$this->proxy = $match[2 ];
* Change the current debug mode
* @param int $in where 1 = on, 0 = off
* Sets whether strings that contain characters which may cause PHP's
* SAX-based XML parser to break should be automatically base64 encoded
* This is is a workaround for systems that don't have PHP's mbstring
* @param int $in where 1 = on, 0 = off
$GLOBALS['XML_RPC_auto_base64'] = true;
$GLOBALS['XML_RPC_auto_base64'] = false;
* Set username and password properties for connecting to the RPC server
* @param string $u the user name
* @param string $p the password
* @see XML_RPC_Client::$username, XML_RPC_Client::$password
* Transmit the RPC request via HTTP 1.0 protocol
* @param object $msg the XML_RPC_Message object
* @param int $timeout how many seconds to wait for the request
* @return object an XML_RPC_Response object. 0 is returned if any
* @see XML_RPC_Message, XML_RPC_Client::XML_RPC_Client(),
* XML_RPC_Client::setCredentials()
function send($msg, $timeout = 0 )
if (!is_a($msg, 'XML_RPC_Message')) {
$this->errstr = 'send()\'s $msg parameter must be an'
. ' XML_RPC_Message object.';
$msg->debug = $this->debug;
* Transmit the RPC request via HTTP 1.0 protocol
* Requests should be sent using XML_RPC_Client send() rather than
* calling this method directly.
* @param object $msg the XML_RPC_Message object
* @param string $server the server to send the request to
* @param int $port the server port send the request to
* @param int $timeout how many seconds to wait for the request
* @param string $username a user name for accessing the RPC server
* @param string $password a password for accessing the RPC server
* @return object an XML_RPC_Response object. 0 is returned if any
* @see XML_RPC_Client::send()
$username = '', $password = '')
* If we're using a proxy open a socket to the proxy server
* instead to the xml-rpc server
* Just raising the error without returning it is strange,
* but keep it here for backwards compatibility.
if (!$fp && $this->proxy) {
. ' failed. ' . $this->errstr,
. ' failed. ' . $this->errstr,
* Using socket_set_timeout() because stream_set_timeout()
* was introduced in 4.3.0, but we need to support 4.2.0.
// Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly
// Only create the payload if it was not created previously
if (empty ($msg->payload )) {
$this->errstr = 'Write error';
$resp = $msg->parseResponseFile ($fp);
if ($meta['timed_out']) {
$this->errstr = 'RPC server did not send response before timeout.';
* Determines the HTTP headers and puts it in the $headers property
* @param object $msg the XML_RPC_Message object
* @return boolean TRUE if okay, FALSE if the message payload isn't set.
if (empty ($msg->payload )) {
$this->headers .= "User-Agent: PEAR XML_RPC\r\n";
$this->headers .= 'Proxy-Authorization: Basic '
// thanks to Grant Rauscher <grant7@firstworld.net> for this
$this->headers .= 'Authorization: Basic '
$this->headers .= "Content-Type: text/xml\r\n";
* The methods and properties for interpreting responses to XML RPC requests
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version Release: 1.5.2
* @link http://pear.php.net/package/XML_RPC
* @return int the error code
* @return string the error string
* @return mixed the value
* @return string the error message in XML format
$rs = "<methodResponse>\n";
<value><int>" . $this->fn . "</int></value>
<value><string>" . $this->fs . "</string></value>
$rs .= "<params>\n<param>\n" . $this->xv->serialize () .
$rs .= "\n</methodResponse>";
* The methods and properties for composing XML RPC messages
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version Release: 1.5.2
* @link http://pear.php.net/package/XML_RPC
* Should the payload's content be passed through mb_convert_encoding()?
* @see XML_RPC_Message::setConvertPayloadEncoding()
* @since Property available since Release 1.5.1
* The current debug mode (1 = on, 0 = off)
* The encoding to be used for outgoing messages
* Defaults to the value of <var>$GLOBALS['XML_RPC_defencoding']</var>
* @see XML_RPC_Message::setSendEncoding(),
* $GLOBALS['XML_RPC_defencoding'], XML_RPC_Message::xml_header()
* The method presently being evaluated
* The XML message being generated
* Should extra line breaks be removed from the payload?
* @since Property available since Release 1.4.6
* The XML response from the remote server
* @since Property available since Release 1.4.6
for ($i = 0; $i < sizeof($pars); $i++ ) {
* Produces the XML declaration including the encoding attribute
* The encoding is determined by this class' <var>$send_encoding</var>
* property. If the <var>$send_encoding</var> property is not set, use
* <var>$GLOBALS['XML_RPC_defencoding']</var>.
* @return string the XML declaration and <methodCall> element
* @see XML_RPC_Message::setSendEncoding(),
* XML_RPC_Message::$send_encoding, $GLOBALS['XML_RPC_defencoding']
global $XML_RPC_defencoding;
return '<?xml version="1.0" encoding="' . $this->send_encoding . '"?>'
* @return string the closing </methodCall> tag
return "</methodCall>\n";
* Fills the XML_RPC_Message::$payload property
* Part of the process makes sure all line endings are in DOS format
* (CRLF), which is probably required by specifications.
* If XML_RPC_Message::setConvertPayloadEncoding() was set to true,
* the payload gets passed through mb_convert_encoding()
* to ensure the payload matches the encoding set in the
* XML declaration. The encoding type can be manually set via
* XML_RPC_Message::setSendEncoding().
* @uses XML_RPC_Message::xml_header(), XML_RPC_Message::xml_footer()
* @see XML_RPC_Message::setSendEncoding(), $GLOBALS['XML_RPC_defencoding'],
* XML_RPC_Message::setConvertPayloadEncoding()
$this->payload .= "<param>\n" . $p->serialize () . "</param>\n";
$this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+", "\r\n", $this->payload);
$this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("\r\n|\n|\r|\n\r", "\r\n", $this->payload);
* @return string the name of the method
* @return string the payload
* Obtains an XML_RPC_Value object for the given parameter
* @param int $i the index number of the parameter to obtain
* @return object the XML_RPC_Value object.
* If the parameter doesn't exist, an XML_RPC_Response object.
* @since Returns XML_RPC_Response object on error since Release 1.3.0
global $XML_RPC_err, $XML_RPC_str;
if (isset ($this->params[$i])) {
$this->raiseError('The submitted request did not contain this parameter',
$XML_RPC_str['incorrect_params']);
* @return int the number of parameters
* Sets whether the payload's content gets passed through
* Returns PEAR_ERROR object if mb_convert_encoding() isn't available.
* @param int $in where 1 = on, 0 = off
* @see XML_RPC_Message::setSendEncoding()
* @since Method available since Release 1.5.1
return $this->raiseError('mb_convert_encoding() is not available',
* Sets the XML declaration's encoding attribute
* @param string $type the encoding type (ISO-8859-1, UTF-8 or US-ASCII)
* @see XML_RPC_Message::setConvertPayloadEncoding(), XML_RPC_Message::xml_header()
* @since Method available since Release 1.2.0
* Determine the XML's encoding via the encoding attribute
* If the encoding parameter is not set or is not ISO-8859-1, UTF-8
* or US-ASCII, $XML_RPC_defencoding will be returned.
* @param string $data the XML that will be parsed
* @return string the encoding to be used
* @link http://php.net/xml_parser_create
* @since Method available since Release 1.2.0
global $XML_RPC_defencoding;
if ($GLOBALS['XML_RPC_func_ereg']('<\?xml[^>]*[:space:]*encoding[:space:]*=[:space:]*[\'"]([^"\']*)[\'"]',
return $XML_RPC_defencoding;
return $XML_RPC_defencoding;
* @return object a new XML_RPC_Response object
while ($data = @fread($fp, 8192 )) {
* @return object a new XML_RPC_Response object
global $XML_RPC_xh, $XML_RPC_err, $XML_RPC_str, $XML_RPC_defencoding;
$parser = (int) $parser_resource;
$XML_RPC_xh[$parser] = array ();
$XML_RPC_xh[$parser]['cm'] = 0;
$XML_RPC_xh[$parser]['isf'] = 0;
$XML_RPC_xh[$parser]['ac'] = '';
$XML_RPC_xh[$parser]['qt'] = '';
$XML_RPC_xh[$parser]['stack'] = array ();
$XML_RPC_xh[$parser]['valuestack'] = array ();
print "\n<pre>---GOT---\n";
print "\n---END---</pre>\n";
// See if response is a 200 or a 100 then a 200, else raise error.
// But only do this if we're using the HTTP protocol.
if ($GLOBALS['XML_RPC_func_ereg']('^HTTP', $data) &&
!$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 200 ', $data) &&
!$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200', $data))
error_log('HTTP error, got response: ' . $errstr);
$XML_RPC_str['http_error'] . ' (' .
// gotta get rid of headers here
if (!$hdrfnd && ($brpos = strpos($data,"\r\n\r\n"))) {
$XML_RPC_xh[$parser]['ha'] = substr($data, 0 , $brpos);
$data = substr($data, $brpos + 4 );
* be tolerant of junk after methodResponse
* (e.g. javascript automatically inserted by free hosts)
* thanks to Luca Mariano <luca.mariano@email.it>
$data = substr($data, 0 , strpos($data, "</methodResponse>") + 17 );
// thanks to Peter Kocks <peter.kocks@baygate.com>
$errstr = 'XML error at line 1, check URL';
$errstr = sprintf('XML error: %s at line %d',
$XML_RPC_str['invalid_return']);
print "\n<pre>---PARSED---\n";
var_dump($XML_RPC_xh[$parser]['value']);
print "---END---</pre>\n";
if ($XML_RPC_xh[$parser]['isf'] > 1 ) {
$XML_RPC_str['invalid_return']. ' '. $XML_RPC_xh[$parser]['isf_reason']);
} elseif (!is_object($XML_RPC_xh[$parser]['value'])) {
// then something odd has happened
// and it's time to generate a client side error
// indicating something odd went on
$XML_RPC_str['invalid_return']);
$v = $XML_RPC_xh[$parser]['value'];
if ($XML_RPC_xh[$parser]['isf']) {
$f = $v->structmem ('faultCode');
$fs = $v->structmem ('faultString');
$r->hdrs = split("\r?\n", $XML_RPC_xh[$parser]['ha'][1 ]);
* The methods and properties that represent data in XML RPC format
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version Release: 1.5.2
* @link http://pear.php.net/package/XML_RPC
if ($val != -1 || $type != '') {
// need some way to report this error
} elseif ($GLOBALS['XML_RPC_Types'][$type] == 1 ) {
} elseif ($GLOBALS['XML_RPC_Types'][$type] == 2 ) {
} elseif ($GLOBALS['XML_RPC_Types'][$type] == 3 ) {
* @return int returns 1 if successful or 0 if there are problems
$this->raiseError('Scalar can have only one value',
$typeof = $GLOBALS['XML_RPC_Types'][$type];
$this->raiseError(" Not a scalar type (${typeof})" ,
if ($type == $GLOBALS['XML_RPC_Boolean']) {
// we're adding to an array here
$ar = $this->me['array'];
$this->me['array'] = $ar;
// a scalar, so set the value and remember we're scalar
* @return int returns 1 if successful or 0 if there are problems
'Already initialized as a [' . $this->kindOf() . ']',
$this->mytype = $GLOBALS['XML_RPC_Types']['array'];
$this->me['array'] = $vals;
* @return int returns 1 if successful or 0 if there are problems
'Already initialized as a [' . $this->kindOf() . ']',
$this->mytype = $GLOBALS['XML_RPC_Types']['struct'];
$this->me['struct'] = $vals;
foreach ($ar as $key => $val) {
echo " $key => $val<br />";
foreach ($val as $key2 => $val2) {
echo " -- $key2 => $val2<br />";
* @return string the data type of the current value
* @return string the data in XML format
// need some way to report this error
switch ($GLOBALS['XML_RPC_Types'][$typ]) {
foreach ($val as $key2 => $val2) {
$rs .= " <member><name>${key2}</name>\n";
$rs .= "<array>\n<data>\n";
for ($i = 0; $i < sizeof($val); $i++ ) {
$rs .= "</data>\n</array>";
case $GLOBALS['XML_RPC_Base64']:
case $GLOBALS['XML_RPC_Boolean']:
$rs .= " <${typ}>" . ($val ? '1' : '0') . " </${typ}>";
case $GLOBALS['XML_RPC_String']:
$rs .= " <${typ}>${val}</${typ}>";
* @return string the data in XML format
* @return string the data in XML format
list ($typ, $val) = each($ar);
return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
* @return mixed the contents of the element requested
return $this->me['struct'][$m];
* @return the key/value pair of the struct's current element
return each($this->me['struct']);
* @return mixed the current value
// contributed by I Sofer, 2001-03-24
// add support for nested arrays to scalarval
// i've created a new method here, so as to
// preserve back compatibility
foreach ($b as $id => $cont) {
$b[$id] = $cont->scalarval ();
// add support for structures directly encoding php objects
foreach ($t as $id => $cont) {
$t[$id] = $cont->scalarval ();
foreach ($t as $id => $cont) {
* @return mixed the current element's scalar value. If the value is
* not scalar, FALSE is returned.
if ($a == $GLOBALS['XML_RPC_I4']) {
$a = $GLOBALS['XML_RPC_Int'];
* @return mixed the struct's current element
return $this->me['array'][$m];
* @return int the number of elements in the array
list ($a, $b) = each($this->me);
* Determines if the item submitted is an XML_RPC_Value object
* @param mixed $val the variable to be evaluated
* @return bool TRUE if the item is an XML_RPC_Value object
* @since Method available since Release 1.3.0
* Return an ISO8601 encoded string
* While timezones ought to be supported, the XML-RPC spec says:
* "Don't assume a timezone. It should be specified by the server in its
* documentation what assumptions it makes about timezones."
* This routine always assumes localtime unless $utc is set to 1, in which
* case UTC is assumed and an adjustment for locale is made when encoding.
* @return string the formatted date
$t = strftime('%Y%m%dT%H:%M:%S', $timet);
// gmstrftime doesn't exist in some versions
* Convert a datetime string into a Unix timestamp
* While timezones ought to be supported, the XML-RPC spec says:
* "Don't assume a timezone. It should be specified by the server in its
* documentation what assumptions it makes about timezones."
* This routine always assumes localtime unless $utc is set to 1, in which
* case UTC is assumed and an adjustment for locale is made when encoding.
* @return int the unix timestamp of the date submitted
if ($GLOBALS['XML_RPC_func_ereg']('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) {
$t = gmmktime($regs[4 ], $regs[5 ], $regs[6 ], $regs[2 ], $regs[3 ], $regs[1 ]);
$t = mktime($regs[4 ], $regs[5 ], $regs[6 ], $regs[2 ], $regs[3 ], $regs[1 ]);
* Converts an XML_RPC_Value object into native PHP types
* @param object $XML_RPC_val the XML_RPC_Value object to decode
* @return mixed the PHP values
$kind = $XML_RPC_val->kindOf();
} elseif ($kind == 'array') {
for ($i = 0; $i < $size; $i++ ) {
} elseif ($kind == 'struct') {
while (list ($key, $value) = $XML_RPC_val->structeach()) {
* Converts native PHP types into an XML_RPC_Value object
* @param mixed $php_val the PHP value or variable you want encoded
* @return object the XML_RPC_Value object
foreach ($php_val as $k => $v) {
// fall though if it's not an enumerated array
foreach ($php_val as $k => $v) {
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Int']);
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Double']);
if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) {
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_DateTime']);
} elseif ($GLOBALS['XML_RPC_auto_base64']
&& $GLOBALS['XML_RPC_func_ereg']("[^ -~\t\r\n]", $php_val))
// Characters other than alpha-numeric, punctuation, SP, TAB,
// LF and CR break the XML parser, encode value via Base 64.
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Base64']);
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_String']);
// Add support for encoding/decoding of booleans, since they
// by <G_Giunta_2001-02-29>
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Boolean']);
* c-hanging-comment-ender-p: nil
Documentation generated on Tue, 18 Aug 2009 17:30:04 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.
|