Source for file Server.php
Documentation is available at Server.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* Server commands for our 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: Server.php 222479 2006-10-28 16:42:34Z danielc $
* @link http://pear.php.net/package/XML_RPC
* Pull in the XML_RPC class
require_once 'XML/RPC.php';
* signature for system.listMethods: return = array,
* parameters = a string or nothing
* @global array $GLOBALS['XML_RPC_Server_listMethods_sig']
$GLOBALS['XML_RPC_Server_listMethods_sig'] = array (
array ($GLOBALS['XML_RPC_Array'],
$GLOBALS['XML_RPC_String']
array ($GLOBALS['XML_RPC_Array'])
* docstring for system.listMethods
* @global string $GLOBALS['XML_RPC_Server_listMethods_doc']
$GLOBALS['XML_RPC_Server_listMethods_doc'] = 'This method lists all the'
. ' methods that the XML-RPC server knows how to dispatch';
* signature for system.methodSignature: return = array,
* @global array $GLOBALS['XML_RPC_Server_methodSignature_sig']
$GLOBALS['XML_RPC_Server_methodSignature_sig'] = array (
array ($GLOBALS['XML_RPC_Array'],
$GLOBALS['XML_RPC_String']
* docstring for system.methodSignature
* @global string $GLOBALS['XML_RPC_Server_methodSignature_doc']
$GLOBALS['XML_RPC_Server_methodSignature_doc'] = 'Returns an array of known'
. ' signatures (an array of arrays) for the method name passed. If'
. ' no signatures are known, returns a none-array (test for type !='
. ' array to detect missing signature)';
* signature for system.methodHelp: return = string,
* @global array $GLOBALS['XML_RPC_Server_methodHelp_sig']
$GLOBALS['XML_RPC_Server_methodHelp_sig'] = array (
array ($GLOBALS['XML_RPC_String'],
$GLOBALS['XML_RPC_String']
* docstring for methodHelp
* @global string $GLOBALS['XML_RPC_Server_methodHelp_doc']
$GLOBALS['XML_RPC_Server_methodHelp_doc'] = 'Returns help text if defined'
. ' for the method passed, otherwise returns an empty string';
* dispatch map for the automatically declared XML-RPC methods.
* @global array $GLOBALS['XML_RPC_Server_dmap']
$GLOBALS['XML_RPC_Server_dmap'] = array (
'system.listMethods' => array (
'function' => 'XML_RPC_Server_listMethods',
'signature' => $GLOBALS['XML_RPC_Server_listMethods_sig'],
'docstring' => $GLOBALS['XML_RPC_Server_listMethods_doc']
'system.methodHelp' => array (
'function' => 'XML_RPC_Server_methodHelp',
'signature' => $GLOBALS['XML_RPC_Server_methodHelp_sig'],
'docstring' => $GLOBALS['XML_RPC_Server_methodHelp_doc']
'system.methodSignature' => array (
'function' => 'XML_RPC_Server_methodSignature',
'signature' => $GLOBALS['XML_RPC_Server_methodSignature_sig'],
'docstring' => $GLOBALS['XML_RPC_Server_methodSignature_doc']
* @global string $GLOBALS['XML_RPC_Server_debuginfo']
$GLOBALS['XML_RPC_Server_debuginfo'] = '';
* Lists all the methods that the XML-RPC server knows how to dispatch
* @return object a new XML_RPC_Response object
global $XML_RPC_err, $XML_RPC_str, $XML_RPC_Server_dmap;
foreach ($server->dmap as $key => $val) {
foreach ($XML_RPC_Server_dmap as $key => $val) {
* Returns an array of known signatures (an array of arrays)
* If no signatures are known, returns a none-array
* (test for type != array to detect missing signature)
* @return object a new XML_RPC_Response object
global $XML_RPC_err, $XML_RPC_str, $XML_RPC_Server_dmap;
$methName = $m->getParam (0 );
$methName = $methName->scalarval ();
if (strpos($methName, 'system.') === 0 ) {
$dmap = $XML_RPC_Server_dmap;
// print "<!-- ${methName} -->\n";
if (isset ($dmap[$methName])) {
if ($dmap[$methName]['signature']) {
$thesigs = $dmap[$methName]['signature'];
for ($i = 0; $i < sizeof($thesigs); $i++ ) {
for ($j = 0; $j < sizeof($inSig); $j++ ) {
$XML_RPC_str['introspect_unknown']);
* Returns help text if defined for the method passed, otherwise returns
* @return object a new XML_RPC_Response object
global $XML_RPC_err, $XML_RPC_str, $XML_RPC_Server_dmap;
$methName = $m->getParam (0 );
$methName = $methName->scalarval ();
if (strpos($methName, 'system.') === 0 ) {
$dmap = $XML_RPC_Server_dmap;
if (isset ($dmap[$methName])) {
if ($dmap[$methName]['docstring']) {
$XML_RPC_str['introspect_unknown']);
global $XML_RPC_Server_debuginfo;
$XML_RPC_Server_debuginfo = $XML_RPC_Server_debuginfo . $m . "\n";
* A server for receiving and replying to XML RPC requests
* $server = new XML_RPC_Server(
* array('boolean', 'int'),
* array('boolean', 'int', 'boolean'),
* array('boolean', 'string'),
* array('boolean', 'string', 'boolean'),
* 'docstring' => 'Is the value an 8?'
* @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_Server::setConvertPayloadEncoding()
* @since Property available since Release 1.5.1
* The dispatch map, listing the methods this server provides.
* The present response's encoding
* @see XML_RPC_Message::getEncoding()
* Debug mode (0 = off, 1 = on)
* The response's HTTP headers
* The response's XML payload
* Constructor for the XML_RPC_Server class
* @param array $dispMap the dispatch map. An associative array
* explaining each function. The keys of the main
* array are the procedure names used by the
* clients. The value is another associative array
* that contains up to three elements:
* + The 'function' element's value is the name
* of the function or method that gets called.
* To define a class' method: 'class::method'.
* + The 'signature' element (optional) is an
* array describing the return values and
* + The 'docstring' element (optional) is a
* string describing what the method does
* @param int $serviceNow should the HTTP response be sent now?
* @param int $debug should debug output be displayed?
global $HTTP_RAW_POST_DATA;
* @return string the debug information if debug debug mode is on
global $XML_RPC_Server_debuginfo, $HTTP_RAW_POST_DATA;
. "\n" . '^^^ END POST DATA ^^^');
if ($XML_RPC_Server_debuginfo != '') {
return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n"
. $GLOBALS['XML_RPC_func_ereg_replace']('--', '- - ', $XML_RPC_Server_debuginfo)
* 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::getEncoding()
* @since Method available since Release 1.5.1
return $this->raiseError ('mb_convert_encoding() is not available',
* The encoding and content-type are determined by
* XML_RPC_Message::getEncoding()
* @uses XML_RPC_Server::createServerPayload(),
* XML_RPC_Server::createServerHeaders()
* $server_headers needs to remain a string for compatibility with
* old scripts using this package, but PHP 4.4.2 no longer allows
* line breaks in header() calls. So, we split each header into
* an individual call. The initial replace handles the off chance
* that someone composed a single header with multiple lines, which
$this->server_headers = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+[ \t]+",
$headers = $GLOBALS['XML_RPC_func_split']("[\r\n]+", $this->server_headers);
foreach ($headers as $header)
* Generates the payload and puts it in the $server_payload property
* If XML_RPC_Server::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_Server::parseRequest(), XML_RPC_Server::$encoding,
* XML_RPC_Response::serialize(), XML_RPC_Server::serializeDebug()
* @see XML_RPC_Server::setConvertPayloadEncoding()
* Determines the HTTP headers and puts them in the $server_headers
* @return boolean TRUE if okay, FALSE if $server_payload isn't set.
* @uses XML_RPC_Server::createServerPayload(),
* XML_RPC_Server::$server_headers
. 'Content-Type: text/xml;'
for ($i = 0; $i < sizeof($sig); $i++ ) {
// check each possible signature in turn
if (sizeof($cursig) == $in->getNumParams () + 1 ) {
for ($n = 0; $n < $in->getNumParams (); $n++ ) {
// print "<!-- $p -->\n";
if ($p->kindOf () == 'scalar') {
// $n+1 as first type of sig is return type
if ($pt != $cursig[$n+1 ]) {
return array (0 , " Wanted ${wanted}, got ${got} at param ${pno}" );
$last = count($allowed) - 1;
$allowed[$last] = 'or ' . $allowed[$last];
'Signature permits ' . implode(', ', $allowed)
. ' parameters but the request had '
* @return object a new XML_RPC_Response object
* @uses XML_RPC_Message::getEncoding(), XML_RPC_Server::$encoding
global $XML_RPC_xh, $HTTP_RAW_POST_DATA,
$XML_RPC_err, $XML_RPC_str, $XML_RPC_errxml,
$XML_RPC_defencoding, $XML_RPC_Server_dmap;
$data = $HTTP_RAW_POST_DATA;
$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]['params'] = array ();
$XML_RPC_xh[$parser]['method'] = '';
$XML_RPC_xh[$parser]['stack'] = array ();
$XML_RPC_xh[$parser]['valuestack'] = array ();
// decompose incoming XML into request structure
if (!xml_parse($parser_resource, $data, 1 )) {
// return XML error as a faultCode
sprintf('XML error: %s at line %d',
} elseif ($XML_RPC_xh[$parser]['isf']>1 ) {
$XML_RPC_err['invalid_request'],
$XML_RPC_str['invalid_request']
. $XML_RPC_xh[$parser]['isf_reason']);
for ($i = 0; $i < sizeof($XML_RPC_xh[$parser]['params']); $i++ ) {
// print '<!-- ' . $XML_RPC_xh[$parser]['params'][$i]. "-->\n";
$plist .= " $i - " . var_export($XML_RPC_xh[$parser]['params'][$i], true ) . " \n";
$m->addParam ($XML_RPC_xh[$parser]['params'][$i]);
// now to deal with the method
$methName = $XML_RPC_xh[$parser]['method'];
if (strpos($methName, 'system.') === 0 ) {
$dmap = $XML_RPC_Server_dmap;
if (isset ($dmap[$methName]['function'])
&& strpos($dmap[$methName]['function'], '::') !== false )
$dmap[$methName]['function'] =
explode('::', $dmap[$methName]['function']);
if (isset ($dmap[$methName]['function'])
if (isset ($dmap[$methName]['signature'])) {
$dmap[$methName]['signature'] );
if (!isset ($dmap[$methName]['signature']) || $sr[0 ]) {
// if no signature or correct signature
if (!is_a($r, 'XML_RPC_Response')) {
$XML_RPC_str['not_response_object']);
$XML_RPC_str['incorrect_params']
// else prepare error response
$XML_RPC_str['unknown_method']);
* Echos back the input packet as a string value
global $HTTP_RAW_POST_DATA;
$r->xv = new XML_RPC_Value("'Aha said I: '" . $HTTP_RAW_POST_DATA, 'string');
* 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.
|