XML_RPC
[ class tree: XML_RPC ] [ index: XML_RPC ] [ all elements ]

Source for file Server.php

Documentation is available at Server.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Server commands for our PHP implementation of the XML-RPC protocol
  7.  *
  8.  * This is a PEAR-ified version of Useful inc's XML-RPC for PHP.
  9.  * It has support for HTTP transport, proxies and authentication.
  10.  *
  11.  * PHP versions 4 and 5
  12.  *
  13.  * LICENSE: License is granted to use or modify this software
  14.  * ("XML-RPC for PHP") for commercial or non-commercial use provided the
  15.  * copyright of the author is preserved in any distributed or derivative work.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * @category   Web Services
  29.  * @package    XML_RPC
  30.  * @author     Edd Dumbill <edd@usefulinc.com>
  31.  * @author     Stig Bakken <stig@php.net>
  32.  * @author     Martin Jansen <mj@php.net>
  33.  * @author     Daniel Convissor <danielc@php.net>
  34.  * @copyright  1999-2001 Edd Dumbill, 2001-2006 The PHP Group
  35.  * @version    CVS: $Id: Server.php 222479 2006-10-28 16:42:34Z danielc $
  36.  * @link       http://pear.php.net/package/XML_RPC
  37.  */
  38.  
  39.  
  40. /**
  41.  * Pull in the XML_RPC class
  42.  */
  43. require_once 'XML/RPC.php';
  44.  
  45.  
  46. /**
  47.  * signature for system.listMethods: return = array,
  48.  * parameters = a string or nothing
  49.  * @global array $GLOBALS['XML_RPC_Server_listMethods_sig'] 
  50.  */
  51. $GLOBALS['XML_RPC_Server_listMethods_sig'= array(
  52.     array($GLOBALS['XML_RPC_Array'],
  53.           $GLOBALS['XML_RPC_String']
  54.     ),
  55.     array($GLOBALS['XML_RPC_Array'])
  56. );
  57.  
  58. /**
  59.  * docstring for system.listMethods
  60.  * @global string $GLOBALS['XML_RPC_Server_listMethods_doc'] 
  61.  */
  62. $GLOBALS['XML_RPC_Server_listMethods_doc''This method lists all the'
  63.         . ' methods that the XML-RPC server knows how to dispatch';
  64.  
  65. /**
  66.  * signature for system.methodSignature: return = array,
  67.  * parameters = string
  68.  * @global array $GLOBALS['XML_RPC_Server_methodSignature_sig'] 
  69.  */
  70. $GLOBALS['XML_RPC_Server_methodSignature_sig'= array(
  71.     array($GLOBALS['XML_RPC_Array'],
  72.           $GLOBALS['XML_RPC_String']
  73.     )
  74. );
  75.  
  76. /**
  77.  * docstring for system.methodSignature
  78.  * @global string $GLOBALS['XML_RPC_Server_methodSignature_doc'] 
  79.  */
  80. $GLOBALS['XML_RPC_Server_methodSignature_doc''Returns an array of known'
  81.         . ' signatures (an array of arrays) for the method name passed. If'
  82.         . ' no signatures are known, returns a none-array (test for type !='
  83.         . ' array to detect missing signature)';
  84.  
  85. /**
  86.  * signature for system.methodHelp: return = string,
  87.  * parameters = string
  88.  * @global array $GLOBALS['XML_RPC_Server_methodHelp_sig'] 
  89.  */
  90. $GLOBALS['XML_RPC_Server_methodHelp_sig'= array(
  91.     array($GLOBALS['XML_RPC_String'],
  92.           $GLOBALS['XML_RPC_String']
  93.     )
  94. );
  95.  
  96. /**
  97.  * docstring for methodHelp
  98.  * @global string $GLOBALS['XML_RPC_Server_methodHelp_doc'] 
  99.  */
  100. $GLOBALS['XML_RPC_Server_methodHelp_doc''Returns help text if defined'
  101.         . ' for the method passed, otherwise returns an empty string';
  102.  
  103. /**
  104.  * dispatch map for the automatically declared XML-RPC methods.
  105.  * @global array $GLOBALS['XML_RPC_Server_dmap'] 
  106.  */
  107. $GLOBALS['XML_RPC_Server_dmap'= array(
  108.     'system.listMethods' => array(
  109.         'function'  => 'XML_RPC_Server_listMethods',
  110.         'signature' => $GLOBALS['XML_RPC_Server_listMethods_sig'],
  111.         'docstring' => $GLOBALS['XML_RPC_Server_listMethods_doc']
  112.     ),
  113.     'system.methodHelp' => array(
  114.         'function'  => 'XML_RPC_Server_methodHelp',
  115.         'signature' => $GLOBALS['XML_RPC_Server_methodHelp_sig'],
  116.         'docstring' => $GLOBALS['XML_RPC_Server_methodHelp_doc']
  117.     ),
  118.     'system.methodSignature' => array(
  119.         'function'  => 'XML_RPC_Server_methodSignature',
  120.         'signature' => $GLOBALS['XML_RPC_Server_methodSignature_sig'],
  121.         'docstring' => $GLOBALS['XML_RPC_Server_methodSignature_doc']
  122.     )
  123. );
  124.  
  125. /**
  126.  * @global string $GLOBALS['XML_RPC_Server_debuginfo'] 
  127.  */
  128. $GLOBALS['XML_RPC_Server_debuginfo''';
  129.  
  130.  
  131. /**
  132.  * Lists all the methods that the XML-RPC server knows how to dispatch
  133.  *
  134.  * @return object  new XML_RPC_Response object
  135.  */
  136. function XML_RPC_Server_listMethods($server$m)
  137. {
  138.     global $XML_RPC_err$XML_RPC_str$XML_RPC_Server_dmap;
  139.  
  140.     $v = new XML_RPC_Value();
  141.     $outAr = array();
  142.     foreach ($server->dmap as $key => $val{
  143.         $outAr[= new XML_RPC_Value($key'string');
  144.     }
  145.     foreach ($XML_RPC_Server_dmap as $key => $val{
  146.         $outAr[= new XML_RPC_Value($key'string');
  147.     }
  148.     $v->addArray($outAr);
  149.     return new XML_RPC_Response($v);
  150. }
  151.  
  152. /**
  153.  * Returns an array of known signatures (an array of arrays)
  154.  * for the given method
  155.  *
  156.  * If no signatures are known, returns a none-array
  157.  * (test for type != array to detect missing signature)
  158.  *
  159.  * @return object  new XML_RPC_Response object
  160.  */
  161. function XML_RPC_Server_methodSignature($server$m)
  162. {
  163.     global $XML_RPC_err$XML_RPC_str$XML_RPC_Server_dmap;
  164.  
  165.     $methName $m->getParam(0);
  166.     $methName $methName->scalarval();
  167.     if (strpos($methName'system.'=== 0{
  168.         $dmap $XML_RPC_Server_dmap;
  169.         $sysCall = 1;
  170.     else {
  171.         $dmap $server->dmap;
  172.         $sysCall = 0;
  173.     }
  174.     //  print "<!-- ${methName} -->\n";
  175.     if (isset($dmap[$methName])) {
  176.         if ($dmap[$methName]['signature']{
  177.             $sigs = array();
  178.             $thesigs $dmap[$methName]['signature'];
  179.             for ($i = 0; $i sizeof($thesigs)$i++{
  180.                 $cursig = array();
  181.                 $inSig $thesigs[$i];
  182.                 for ($j = 0; $j sizeof($inSig)$j++{
  183.                     $cursig[= new XML_RPC_Value($inSig[$j]'string');
  184.                 }
  185.                 $sigs[= new XML_RPC_Value($cursig'array');
  186.             }
  187.             $r = new XML_RPC_Response(new XML_RPC_Value($sigs'array'));
  188.         else {
  189.             $r = new XML_RPC_Response(new XML_RPC_Value('undef''string'));
  190.         }
  191.     else {
  192.         $r = new XML_RPC_Response(0$XML_RPC_err['introspect_unknown'],
  193.                                   $XML_RPC_str['introspect_unknown']);
  194.     }
  195.     return $r;
  196. }
  197.  
  198. /**
  199.  * Returns help text if defined for the method passed, otherwise returns
  200.  * an empty string
  201.  *
  202.  * @return object  new XML_RPC_Response object
  203.  */
  204. function XML_RPC_Server_methodHelp($server$m)
  205. {
  206.     global $XML_RPC_err$XML_RPC_str$XML_RPC_Server_dmap;
  207.  
  208.     $methName $m->getParam(0);
  209.     $methName $methName->scalarval();
  210.     if (strpos($methName'system.'=== 0{
  211.         $dmap $XML_RPC_Server_dmap;
  212.         $sysCall = 1;
  213.     else {
  214.         $dmap $server->dmap;
  215.         $sysCall = 0;
  216.     }
  217.  
  218.     if (isset($dmap[$methName])) {
  219.         if ($dmap[$methName]['docstring']{
  220.             $r = new XML_RPC_Response(new XML_RPC_Value($dmap[$methName]['docstring']),
  221.                                                         'string');
  222.         else {
  223.             $r = new XML_RPC_Response(new XML_RPC_Value('''string'));
  224.         }
  225.     else {
  226.         $r = new XML_RPC_Response(0$XML_RPC_err['introspect_unknown'],
  227.                                      $XML_RPC_str['introspect_unknown']);
  228.     }
  229.     return $r;
  230. }
  231.  
  232. /**
  233.  * @return void 
  234.  */
  235. {
  236.     global $XML_RPC_Server_debuginfo;
  237.     $XML_RPC_Server_debuginfo $XML_RPC_Server_debuginfo $m "\n";
  238. }
  239.  
  240.  
  241. /**
  242.  * A server for receiving and replying to XML RPC requests
  243.  *
  244.  * <code>
  245.  * $server = new XML_RPC_Server(
  246.  *     array(
  247.  *         'isan8' =>
  248.  *             array(
  249.  *                 'function' => 'is_8',
  250.  *                 'signature' =>
  251.  *                      array(
  252.  *                          array('boolean', 'int'),
  253.  *                          array('boolean', 'int', 'boolean'),
  254.  *                          array('boolean', 'string'),
  255.  *                          array('boolean', 'string', 'boolean'),
  256.  *                      ),
  257.  *                 'docstring' => 'Is the value an 8?'
  258.  *             ),
  259.  *     ),
  260.  *     1,
  261.  *     0
  262.  * );
  263.  * </code>
  264.  *
  265.  * @category   Web Services
  266.  * @package    XML_RPC
  267.  * @author     Edd Dumbill <edd@usefulinc.com>
  268.  * @author     Stig Bakken <stig@php.net>
  269.  * @author     Martin Jansen <mj@php.net>
  270.  * @author     Daniel Convissor <danielc@php.net>
  271.  * @copyright  1999-2001 Edd Dumbill, 2001-2006 The PHP Group
  272.  * @version    Release: 1.5.2
  273.  * @link       http://pear.php.net/package/XML_RPC
  274.  */
  275. {
  276.     /**
  277.      * Should the payload's content be passed through mb_convert_encoding()?
  278.      *
  279.      * @see XML_RPC_Server::setConvertPayloadEncoding()
  280.      * @since Property available since Release 1.5.1
  281.      * @var boolean 
  282.      */
  283.     var $convert_payload_encoding = false;
  284.  
  285.     /**
  286.      * The dispatch map, listing the methods this server provides.
  287.      * @var array 
  288.      */
  289.     var $dmap = array();
  290.  
  291.     /**
  292.      * The present response's encoding
  293.      * @var string 
  294.      * @see XML_RPC_Message::getEncoding()
  295.      */
  296.     var $encoding = '';
  297.  
  298.     /**
  299.      * Debug mode (0 = off, 1 = on)
  300.      * @var integer 
  301.      */
  302.     var $debug = 0;
  303.  
  304.     /**
  305.      * The response's HTTP headers
  306.      * @var string 
  307.      */
  308.     var $server_headers = '';
  309.  
  310.     /**
  311.      * The response's XML payload
  312.      * @var string 
  313.      */
  314.     var $server_payload = '';
  315.  
  316.  
  317.     /**
  318.      * Constructor for the XML_RPC_Server class
  319.      *
  320.      * @param array $dispMap   the dispatch map. An associative array
  321.      *                           explaining each function. The keys of the main
  322.      *                           array are the procedure names used by the
  323.      *                           clients. The value is another associative array
  324.      *                           that contains up to three elements:
  325.      *                             + The 'function' element's value is the name
  326.      *                               of the function or method that gets called.
  327.      *                               To define a class' method: 'class::method'.
  328.      *                             + The 'signature' element (optional) is an
  329.      *                               array describing the return values and
  330.      *                               parameters
  331.      *                             + The 'docstring' element (optional) is a
  332.      *                               string describing what the method does
  333.      * @param int $serviceNow  should the HTTP response be sent now?
  334.      *                           (1 = yes, 0 = no)
  335.      * @param int $debug       should debug output be displayed?
  336.      *                           (1 = yes, 0 = no)
  337.      *
  338.      * @return void 
  339.      */
  340.     function XML_RPC_Server($dispMap$serviceNow = 1$debug = 0)
  341.     {
  342.         global $HTTP_RAW_POST_DATA;
  343.  
  344.         if ($debug{
  345.             $this->debug = 1;
  346.         else {
  347.             $this->debug = 0;
  348.         }
  349.  
  350.         $this->dmap = $dispMap;
  351.  
  352.         if ($serviceNow{
  353.             $this->service();
  354.         else {
  355.             $this->createServerPayload();
  356.             $this->createServerHeaders();
  357.         }
  358.     }
  359.  
  360.     /**
  361.      * @return string  the debug information if debug debug mode is on
  362.      */
  363.     function serializeDebug()
  364.     {
  365.         global $XML_RPC_Server_debuginfo$HTTP_RAW_POST_DATA;
  366.  
  367.         if ($this->debug{
  368.             XML_RPC_Server_debugmsg('vvv POST DATA RECEIVED BY SERVER vvv' "\n"
  369.                                     . $HTTP_RAW_POST_DATA
  370.                                     . "\n" '^^^ END POST DATA ^^^');
  371.         }
  372.  
  373.         if ($XML_RPC_Server_debuginfo != ''{
  374.             return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n"
  375.                    . $GLOBALS['XML_RPC_func_ereg_replace']('--''- - '$XML_RPC_Server_debuginfo)
  376.                    . "-->\n";
  377.         else {
  378.             return '';
  379.         }
  380.     }
  381.  
  382.     /**
  383.      * Sets whether the payload's content gets passed through
  384.      * mb_convert_encoding()
  385.      *
  386.      * Returns PEAR_ERROR object if mb_convert_encoding() isn't available.
  387.      *
  388.      * @param int $in  where 1 = on, 0 = off
  389.      *
  390.      * @return void 
  391.      *
  392.      * @see XML_RPC_Message::getEncoding()
  393.      * @since Method available since Release 1.5.1
  394.      */
  395.     function setConvertPayloadEncoding($in)
  396.     {
  397.         if ($in && !function_exists('mb_convert_encoding')) {
  398.             return $this->raiseError('mb_convert_encoding() is not available',
  399.                               XML_RPC_ERROR_PROGRAMMING);
  400.         }
  401.         $this->convert_payload_encoding = $in;
  402.     }
  403.  
  404.     /**
  405.      * Sends the response
  406.      *
  407.      * The encoding and content-type are determined by
  408.      * XML_RPC_Message::getEncoding()
  409.      *
  410.      * @return void 
  411.      *
  412.      * @uses XML_RPC_Server::createServerPayload(),
  413.      *        XML_RPC_Server::createServerHeaders()
  414.      */
  415.     function service()
  416.     {
  417.         if (!$this->server_payload{
  418.             $this->createServerPayload();
  419.         }
  420.         if (!$this->server_headers{
  421.             $this->createServerHeaders();
  422.         }
  423.  
  424.         /*
  425.          * $server_headers needs to remain a string for compatibility with
  426.          * old scripts using this package, but PHP 4.4.2 no longer allows
  427.          * line breaks in header() calls.  So, we split each header into
  428.          * an individual call.  The initial replace handles the off chance
  429.          * that someone composed a single header with multiple lines, which
  430.          * the RFCs allow.
  431.          */
  432.         $this->server_headers = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+[ \t]+",
  433.                                 ' 'trim($this->server_headers));
  434.         $headers $GLOBALS['XML_RPC_func_split']("[\r\n]+"$this->server_headers);
  435.         foreach ($headers as $header)
  436.         {
  437.             header($header);
  438.         }
  439.  
  440.         print $this->server_payload;
  441.     }
  442.  
  443.     /**
  444.      * Generates the payload and puts it in the $server_payload property
  445.      *
  446.      * If XML_RPC_Server::setConvertPayloadEncoding() was set to true,
  447.      * the payload gets passed through mb_convert_encoding()
  448.      * to ensure the payload matches the encoding set in the
  449.      * XML declaration.  The encoding type can be manually set via
  450.      * XML_RPC_Message::setSendEncoding().
  451.      *
  452.      * @return void 
  453.      *
  454.      * @uses XML_RPC_Server::parseRequest(), XML_RPC_Server::$encoding,
  455.      *        XML_RPC_Response::serialize(), XML_RPC_Server::serializeDebug()
  456.      * @see  XML_RPC_Server::setConvertPayloadEncoding()
  457.      */
  458.     function createServerPayload()
  459.     {
  460.         $r $this->parseRequest();
  461.         $this->server_payload = '<?xml version="1.0" encoding="'
  462.                               . $this->encoding . '"?>' "\n"
  463.                               . $this->serializeDebug()
  464.                               . $r->serialize();
  465.         if ($this->convert_payload_encoding{
  466.             $this->server_payload = mb_convert_encoding($this->server_payload,
  467.                                                         $this->encoding);
  468.         }
  469.     }
  470.  
  471.     /**
  472.      * Determines the HTTP headers and puts them in the $server_headers
  473.      * property
  474.      *
  475.      * @return boolean  TRUE if okay, FALSE if $server_payload isn't set.
  476.      *
  477.      * @uses XML_RPC_Server::createServerPayload(),
  478.      *        XML_RPC_Server::$server_headers
  479.      */
  480.     function createServerHeaders()
  481.     {
  482.         if (!$this->server_payload{
  483.             return false;
  484.         }
  485.         $this->server_headers = 'Content-Length: '
  486.                               . strlen($this->server_payload"\r\n"
  487.                               . 'Content-Type: text/xml;'
  488.                               . ' charset=' $this->encoding;
  489.         return true;
  490.     }
  491.  
  492.     /**
  493.      * @return array 
  494.      */
  495.     function verifySignature($in$sig)
  496.     {
  497.         for ($i = 0; $i sizeof($sig)$i++{
  498.             // check each possible signature in turn
  499.             $cursig $sig[$i];
  500.             if (sizeof($cursig== $in->getNumParams(+ 1{
  501.                 $itsOK = 1;
  502.                 for ($n = 0; $n $in->getNumParams()$n++{
  503.                     $p $in->getParam($n);
  504.                     // print "<!-- $p -->\n";
  505.                     if ($p->kindOf(== 'scalar'{
  506.                         $pt $p->scalartyp();
  507.                     else {
  508.                         $pt $p->kindOf();
  509.                     }
  510.                     // $n+1 as first type of sig is return type
  511.                     if ($pt != $cursig[$n+1]{
  512.                         $itsOK = 0;
  513.                         $pno $n+1;
  514.                         $wanted $cursig[$n+1];
  515.                         $got $pt;
  516.                         break;
  517.                     }
  518.                 }
  519.                 if ($itsOK{
  520.                     return array(1);
  521.                 }
  522.             }
  523.         }
  524.         if (isset($wanted)) {
  525.             return array(0"Wanted ${wanted}, got ${got} at param ${pno}");
  526.         else {
  527.             $allowed = array();
  528.             foreach ($sig as $val{
  529.                 end($val);
  530.                 $allowed[key($val);
  531.             }
  532.             $allowed array_unique($allowed);
  533.             $last count($allowed- 1;
  534.             if ($last > 0{
  535.                 $allowed[$last'or ' $allowed[$last];
  536.             }
  537.             return array(0,
  538.                          'Signature permits ' implode(', '$allowed)
  539.                                 . ' parameters but the request had '
  540.                                 . $in->getNumParams());
  541.         }
  542.     }
  543.  
  544.     /**
  545.      * @return object  new XML_RPC_Response object
  546.      *
  547.      * @uses XML_RPC_Message::getEncoding(), XML_RPC_Server::$encoding
  548.      */
  549.     function parseRequest($data '')
  550.     {
  551.         global $XML_RPC_xh$HTTP_RAW_POST_DATA,
  552.                 $XML_RPC_err$XML_RPC_str$XML_RPC_errxml,
  553.                 $XML_RPC_defencoding$XML_RPC_Server_dmap;
  554.  
  555.         if ($data == ''{
  556.             $data $HTTP_RAW_POST_DATA;
  557.         }
  558.  
  559.         $this->encoding = XML_RPC_Message::getEncoding($data);
  560.         $parser_resource xml_parser_create($this->encoding);
  561.         $parser = (int) $parser_resource;
  562.  
  563.         $XML_RPC_xh[$parser= array();
  564.         $XML_RPC_xh[$parser]['cm']     = 0;
  565.         $XML_RPC_xh[$parser]['isf']    = 0;
  566.         $XML_RPC_xh[$parser]['params'= array();
  567.         $XML_RPC_xh[$parser]['method''';
  568.         $XML_RPC_xh[$parser]['stack'= array();    
  569.         $XML_RPC_xh[$parser]['valuestack'= array();    
  570.  
  571.         $plist '';
  572.  
  573.         // decompose incoming XML into request structure
  574.  
  575.         xml_parser_set_option($parser_resourceXML_OPTION_CASE_FOLDINGtrue);
  576.         xml_set_element_handler($parser_resource'XML_RPC_se''XML_RPC_ee');
  577.         xml_set_character_data_handler($parser_resource'XML_RPC_cd');
  578.         if (!xml_parse($parser_resource$data1)) {
  579.             // return XML error as a faultCode
  580.             $r = new XML_RPC_Response(0,
  581.                                       $XML_RPC_errxml+xml_get_error_code($parser_resource),
  582.                                       sprintf('XML error: %s at line %d',
  583.                                               xml_error_string(xml_get_error_code($parser_resource)),
  584.                                               xml_get_current_line_number($parser_resource)));
  585.             xml_parser_free($parser_resource);
  586.         elseif ($XML_RPC_xh[$parser]['isf']>1{
  587.             $r = new XML_RPC_Response(0,
  588.                                       $XML_RPC_err['invalid_request'],
  589.                                       $XML_RPC_str['invalid_request']
  590.                                       . ': '
  591.                                       . $XML_RPC_xh[$parser]['isf_reason']);
  592.             xml_parser_free($parser_resource);
  593.         else {
  594.             xml_parser_free($parser_resource);
  595.             $m = new XML_RPC_Message($XML_RPC_xh[$parser]['method']);
  596.             // now add parameters in
  597.             for ($i = 0; $i sizeof($XML_RPC_xh[$parser]['params'])$i++{
  598.                 // print '<!-- ' . $XML_RPC_xh[$parser]['params'][$i]. "-->\n";
  599.                 $plist .= "$i - " . var_export($XML_RPC_xh[$parser]['params'][$i]true" \n";
  600.                 $m->addParam($XML_RPC_xh[$parser]['params'][$i]);
  601.             }
  602.  
  603.             if ($this->debug{
  604.                 XML_RPC_Server_debugmsg($plist);
  605.             }
  606.  
  607.             // now to deal with the method
  608.             $methName $XML_RPC_xh[$parser]['method'];
  609.             if (strpos($methName'system.'=== 0{
  610.                 $dmap $XML_RPC_Server_dmap;
  611.                 $sysCall = 1;
  612.             else {
  613.                 $dmap $this->dmap;
  614.                 $sysCall = 0;
  615.             }
  616.  
  617.             if (isset($dmap[$methName]['function'])
  618.                 && is_string($dmap[$methName]['function'])
  619.                 && strpos($dmap[$methName]['function']'::'!== false)
  620.             {
  621.                 $dmap[$methName]['function'=
  622.                         explode('::'$dmap[$methName]['function']);
  623.             }
  624.  
  625.             if (isset($dmap[$methName]['function'])
  626.                 && is_callable($dmap[$methName]['function']))
  627.             {
  628.                 // dispatch if exists
  629.                 if (isset($dmap[$methName]['signature'])) {
  630.                     $sr $this->verifySignature($m,
  631.                                                  $dmap[$methName]['signature');
  632.                 }
  633.                 if (!isset($dmap[$methName]['signature']|| $sr[0]{
  634.                     // if no signature or correct signature
  635.                     if ($sysCall{
  636.                         $r call_user_func($dmap[$methName]['function']$this$m);
  637.                     else {
  638.                         $r call_user_func($dmap[$methName]['function']$m);
  639.                     }
  640.                     if (!is_a($r'XML_RPC_Response')) {
  641.                         $r = new XML_RPC_Response(0$XML_RPC_err['not_response_object'],
  642.                                                   $XML_RPC_str['not_response_object']);
  643.                     }
  644.                 else {
  645.                     $r = new XML_RPC_Response(0$XML_RPC_err['incorrect_params'],
  646.                                               $XML_RPC_str['incorrect_params']
  647.                                               . ': ' $sr[1]);
  648.                 }
  649.             else {
  650.                 // else prepare error response
  651.                 $r = new XML_RPC_Response(0$XML_RPC_err['unknown_method'],
  652.                                           $XML_RPC_str['unknown_method']);
  653.             }
  654.         }
  655.         return $r;
  656.     }
  657.  
  658.     /**
  659.      * Echos back the input packet as a string value
  660.      *
  661.      * @return void 
  662.      *
  663.      *  Useful for debugging.
  664.      */
  665.     function echoInput()
  666.     {
  667.         global $HTTP_RAW_POST_DATA;
  668.  
  669.         $r = new XML_RPC_Response(0);
  670.         $r->xv = new XML_RPC_Value("'Aha said I: '" $HTTP_RAW_POST_DATA'string');
  671.         print $r->serialize();
  672.     }
  673. }
  674.  
  675. /*
  676.  * Local variables:
  677.  * tab-width: 4
  678.  * c-basic-offset: 4
  679.  * c-hanging-comment-ender-p: nil
  680.  * End:
  681.  */
  682.  
  683. ?>

Documentation generated on Tue, 18 Aug 2009 17:30:04 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.