b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: main ] [ index: main ] [ all elements ]

Source for file _xmlrpcs.inc.php

Documentation is available at _xmlrpcs.inc.php

  1. <?php
  2. // b2evo mods: added logIO() calls
  3.  
  4. // by Edd Dumbill (C) 1999-2002
  5. // <edd@usefulinc.com>
  6. // $Id: _xmlrpcs.inc.php,v 1.8 2010/02/26 22:15:47 fplanque Exp $
  7.  
  8. // Copyright (c) 1999,2000,2002 Edd Dumbill.
  9. // All rights reserved.
  10. //
  11. // Redistribution and use in source and binary forms, with or without
  12. // modification, are permitted provided that the following conditions
  13. // are met:
  14. //
  15. //    * Redistributions of source code must retain the above copyright
  16. //      notice, this list of conditions and the following disclaimer.
  17. //
  18. //    * Redistributions in binary form must reproduce the above
  19. //      copyright notice, this list of conditions and the following
  20. //      disclaimer in the documentation and/or other materials provided
  21. //      with the distribution.
  22. //
  23. //    * Neither the name of the "XML-RPC for PHP" nor the names of its
  24. //      contributors may be used to endorse or promote products derived
  25. //      from this software without specific prior written permission.
  26. //
  27. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. // REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  33. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  34. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  38. // OF THE POSSIBILITY OF SUCH DAMAGE.
  39.  
  40.     // XML RPC Server class
  41.     // requires: xmlrpc.inc
  42.  
  43.     $GLOBALS['xmlrpcs_capabilities'array(
  44.         // xmlrpc spec: always supported
  45.         'xmlrpc' => new xmlrpcval(array(
  46.             'specUrl' => new xmlrpcval('http://www.xmlrpc.com/spec''string'),
  47.             'specVersion' => new xmlrpcval(1'int')
  48.         )'struct'),
  49.         // if we support system.xxx functions, we always support multicall, too...
  50.         // Note that, as of 2006/09/17, the following URL does not respond anymore
  51.         'system.multicall' => new xmlrpcval(array(
  52.             'specUrl' => new xmlrpcval('http://www.xmlrpc.com/discuss/msgReader$1208''string'),
  53.             'specVersion' => new xmlrpcval(1'int')
  54.         )'struct'),
  55.         // introspection: version 2! we support 'mixed', too
  56.         'introspection' => new xmlrpcval(array(
  57.             'specUrl' => new xmlrpcval('http://phpxmlrpc.sourceforge.net/doc-2/ch10.html''string'),
  58.             'specVersion' => new xmlrpcval(2'int')
  59.         )'struct')
  60.     );
  61.  
  62.     /* Functions that implement system.XXX methods of xmlrpc servers */
  63.     $_xmlrpcs_getCapabilities_sig=array(array($GLOBALS['xmlrpcStruct']));
  64.     $_xmlrpcs_getCapabilities_doc='This method lists all the capabilites that the XML-RPC server has: the (more or less standard) extensions to the xmlrpc spec that it adheres to';
  65.     $_xmlrpcs_getCapabilities_sdoc=array(array('list of capabilities, described as structs with a version number and url for the spec'));
  66.     function _xmlrpcs_getCapabilities($server$m=null)
  67.     {
  68.         $outAr $GLOBALS['xmlrpcs_capabilities'];
  69.         // NIL extension
  70.         if ($GLOBALS['xmlrpc_null_extension']{
  71.             $outAr['nil'new xmlrpcval(array(
  72.                 'specUrl' => new xmlrpcval('http://www.ontosys.com/xml-rpc/extensions.php''string'),
  73.                 'specVersion' => new xmlrpcval(1'int')
  74.             )'struct');
  75.         }
  76.         return new xmlrpcresp(new xmlrpcval($outAr'struct'));
  77.     }
  78.  
  79.     // listMethods: signature was either a string, or nothing.
  80.     // The useless string variant has been removed
  81.     $_xmlrpcs_listMethods_sig=array(array($GLOBALS['xmlrpcArray']));
  82.     $_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';
  83.     $_xmlrpcs_listMethods_sdoc=array(array('list of method names'));
  84.     function _xmlrpcs_listMethods($server$m=null// if called in plain php values mode, second param is missing
  85.     {
  86.  
  87.         $outAr=array();
  88.         foreach($server->dmap as $key => $val)
  89.         {
  90.             $outAr[new xmlrpcval($key'string');
  91.         }
  92.         if($server->allow_system_funcs)
  93.         {
  94.             foreach($GLOBALS['_xmlrpcs_dmap'as $key => $val)
  95.             {
  96.                 $outAr[new xmlrpcval($key'string');
  97.             }
  98.         }
  99.         return new xmlrpcresp(new xmlrpcval($outAr'array'));
  100.     }
  101.  
  102.     $_xmlrpcs_methodSignature_sig=array(array($GLOBALS['xmlrpcArray']$GLOBALS['xmlrpcString']));
  103.     $_xmlrpcs_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)';
  104.     $_xmlrpcs_methodSignature_sdoc=array(array('list of known signatures, each sig being an array of xmlrpc type names''name of method to be described'));
  105.     function _xmlrpcs_methodSignature($server$m)
  106.     {
  107.         // let accept as parameter both an xmlrpcval or string
  108.         if (is_object($m))
  109.         {
  110.             $methName=$m->getParam(0);
  111.             $methName=$methName->scalarval();
  112.         }
  113.         else
  114.         {
  115.             $methName=$m;
  116.         }
  117.         if(strpos($methName"system."=== 0)
  118.         {
  119.             $dmap=$GLOBALS['_xmlrpcs_dmap']$sysCall=1;
  120.         }
  121.         else
  122.         {
  123.             $dmap=$server->dmap$sysCall=0;
  124.         }
  125.         if(isset($dmap[$methName]))
  126.         {
  127.             if(isset($dmap[$methName]['signature']))
  128.             {
  129.                 $sigs=array();
  130.                 foreach($dmap[$methName]['signature'as $inSig)
  131.                 {
  132.                     $cursig=array();
  133.                     foreach($inSig as $sig)
  134.                     {
  135.                         $cursig[new xmlrpcval($sig'string');
  136.                     }
  137.                     $sigs[new xmlrpcval($cursig'array');
  138.                 }
  139.                 $r new xmlrpcresp(new xmlrpcval($sigs'array'));
  140.             }
  141.             else
  142.             {
  143.                 // NB: according to the official docs, we should be returning a
  144.                 // "none-array" here, which means not-an-array
  145.                 $r new xmlrpcresp(new xmlrpcval('undef''string'));
  146.             }
  147.         }
  148.         else
  149.         {
  150.             $r new xmlrpcresp(0,$GLOBALS['xmlrpcerr']['introspect_unknown']$GLOBALS['xmlrpcstr']['introspect_unknown']);
  151.         }
  152.         return $r;
  153.     }
  154.  
  155.     $_xmlrpcs_methodHelp_sig=array(array($GLOBALS['xmlrpcString']$GLOBALS['xmlrpcString']));
  156.     $_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';
  157.     $_xmlrpcs_methodHelp_sdoc=array(array('method description''name of the method to be described'));
  158.     function _xmlrpcs_methodHelp($server$m)
  159.     {
  160.         // let accept as parameter both an xmlrpcval or string
  161.         if (is_object($m))
  162.         {
  163.             $methName=$m->getParam(0);
  164.             $methName=$methName->scalarval();
  165.         }
  166.         else
  167.         {
  168.             $methName=$m;
  169.         }
  170.         if(strpos($methName"system."=== 0)
  171.         {
  172.             $dmap=$GLOBALS['_xmlrpcs_dmap']$sysCall=1;
  173.         }
  174.         else
  175.         {
  176.             $dmap=$server->dmap$sysCall=0;
  177.         }
  178.         if(isset($dmap[$methName]))
  179.         {
  180.             if(isset($dmap[$methName]['docstring']))
  181.             {
  182.                 $r new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring'])'string');
  183.             }
  184.             else
  185.             {
  186.                 $r new xmlrpcresp(new xmlrpcval('''string'));
  187.             }
  188.         }
  189.         else
  190.         {
  191.             $r new xmlrpcresp(0$GLOBALS['xmlrpcerr']['introspect_unknown']$GLOBALS['xmlrpcstr']['introspect_unknown']);
  192.         }
  193.         return $r;
  194.     }
  195.  
  196.     $_xmlrpcs_multicall_sig array(array($GLOBALS['xmlrpcArray']$GLOBALS['xmlrpcArray']));
  197.     $_xmlrpcs_multicall_doc 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details';
  198.     $_xmlrpcs_multicall_sdoc array(array('list of response structs, where each struct has the usual members''list of calls, with each call being represented as a struct, with members "methodname" and "params"'));
  199.     function _xmlrpcs_multicall_error($err)
  200.     {
  201.         if(is_string($err))
  202.         {
  203.             $str $GLOBALS['xmlrpcstr']["multicall_${err}"];
  204.             $code $GLOBALS['xmlrpcerr']["multicall_${err}"];
  205.         }
  206.         else
  207.         {
  208.             $code $err->faultCode();
  209.             $str $err->faultString();
  210.         }
  211.         $struct array();
  212.         $struct['faultCode'new xmlrpcval($code'int');
  213.         $struct['faultString'new xmlrpcval($str'string');
  214.         return new xmlrpcval($struct'struct');
  215.     }
  216.  
  217.     function _xmlrpcs_multicall_do_call($server$call)
  218.     {
  219.         if($call->kindOf(!= 'struct')
  220.         {
  221.             return _xmlrpcs_multicall_error('notstruct');
  222.         }
  223.         $methName @$call->structmem('methodName');
  224.         if(!$methName)
  225.         {
  226.             return _xmlrpcs_multicall_error('nomethod');
  227.         }
  228.         if($methName->kindOf(!= 'scalar' || $methName->scalartyp(!= 'string')
  229.         {
  230.             return _xmlrpcs_multicall_error('notstring');
  231.         }
  232.         if($methName->scalarval(== 'system.multicall')
  233.         {
  234.             return _xmlrpcs_multicall_error('recursion');
  235.         }
  236.  
  237.         $params @$call->structmem('params');
  238.         if(!$params)
  239.         {
  240.             return _xmlrpcs_multicall_error('noparams');
  241.         }
  242.         if($params->kindOf(!= 'array')
  243.         {
  244.             return _xmlrpcs_multicall_error('notarray');
  245.         }
  246.         $numParams $params->arraysize();
  247.  
  248.         $msg new xmlrpcmsg($methName->scalarval());
  249.         for($i 0$i $numParams$i++)
  250.         {
  251.             if(!$msg->addParam($params->arraymem($i)))
  252.             {
  253.                 $i++;
  254.                 return _xmlrpcs_multicall_error(new xmlrpcresp(0,
  255.                     $GLOBALS['xmlrpcerr']['incorrect_params'],
  256.                     $GLOBALS['xmlrpcstr']['incorrect_params'": probable xml error in param " $i));
  257.             }
  258.         }
  259.  
  260.         $result $server->execute($msg);
  261.  
  262.         if($result->faultCode(!= 0)
  263.         {
  264.             return _xmlrpcs_multicall_error($result);        // Method returned fault.
  265.         }
  266.  
  267.         return new xmlrpcval(array($result->value())'array');
  268.     }
  269.  
  270.     function _xmlrpcs_multicall_do_call_phpvals($server$call)
  271.     {
  272.         if(!is_array($call))
  273.         {
  274.             return _xmlrpcs_multicall_error('notstruct');
  275.         }
  276.         if(!array_key_exists('methodName'$call))
  277.         {
  278.             return _xmlrpcs_multicall_error('nomethod');
  279.         }
  280.         if (!is_string($call['methodName']))
  281.         {
  282.             return _xmlrpcs_multicall_error('notstring');
  283.         }
  284.         if($call['methodName'== 'system.multicall')
  285.         {
  286.             return _xmlrpcs_multicall_error('recursion');
  287.         }
  288.         if(!array_key_exists('params'$call))
  289.         {
  290.             return _xmlrpcs_multicall_error('noparams');
  291.         }
  292.         if(!is_array($call['params']))
  293.         {
  294.             return _xmlrpcs_multicall_error('notarray');
  295.         }
  296.  
  297.         // this is a real dirty and simplistic hack, since we might have received a
  298.         // base64 or datetime values, but they will be listed as strings here...
  299.         $numParams count($call['params']);
  300.         $pt array();
  301.         foreach($call['params'as $val)
  302.             $pt[php_2_xmlrpc_type(gettype($val));
  303.  
  304.         $result $server->execute($call['methodName']$call['params']$pt);
  305.  
  306.         if($result->faultCode(!= 0)
  307.         {
  308.             return _xmlrpcs_multicall_error($result);        // Method returned fault.
  309.         }
  310.  
  311.         return new xmlrpcval(array($result->value())'array');
  312.     }
  313.  
  314.     function _xmlrpcs_multicall($server$m)
  315.     {
  316.         $result array();
  317.         // let accept a plain list of php parameters, beside a single xmlrpc msg object
  318.         if (is_object($m))
  319.         {
  320.             $calls $m->getParam(0);
  321.             $numCalls $calls->arraysize();
  322.             for($i 0$i $numCalls$i++)
  323.             {
  324.                 $call $calls->arraymem($i);
  325.                 $result[$i_xmlrpcs_multicall_do_call($server$call);
  326.             }
  327.         }
  328.         else
  329.         {
  330.             $numCalls=count($m);
  331.             for($i 0$i $numCalls$i++)
  332.             {
  333.                 $result[$i_xmlrpcs_multicall_do_call_phpvals($server$m[$i]);
  334.             }
  335.         }
  336.  
  337.         return new xmlrpcresp(new xmlrpcval($result'array'));
  338.     }
  339.  
  340.     $GLOBALS['_xmlrpcs_dmap']=array(
  341.         'system.listMethods' => array(
  342.             'function' => '_xmlrpcs_listMethods',
  343.             'signature' => $_xmlrpcs_listMethods_sig,
  344.             'docstring' => $_xmlrpcs_listMethods_doc,
  345.             'signature_docs' => $_xmlrpcs_listMethods_sdoc),
  346.         'system.methodHelp' => array(
  347.             'function' => '_xmlrpcs_methodHelp',
  348.             'signature' => $_xmlrpcs_methodHelp_sig,
  349.             'docstring' => $_xmlrpcs_methodHelp_doc,
  350.             'signature_docs' => $_xmlrpcs_methodHelp_sdoc),
  351.         'system.methodSignature' => array(
  352.             'function' => '_xmlrpcs_methodSignature',
  353.             'signature' => $_xmlrpcs_methodSignature_sig,
  354.             'docstring' => $_xmlrpcs_methodSignature_doc,
  355.             'signature_docs' => $_xmlrpcs_methodSignature_sdoc),
  356.         'system.multicall' => array(
  357.             'function' => '_xmlrpcs_multicall',
  358.             'signature' => $_xmlrpcs_multicall_sig,
  359.             'docstring' => $_xmlrpcs_multicall_doc,
  360.             'signature_docs' => $_xmlrpcs_multicall_sdoc),
  361.         'system.getCapabilities' => array(
  362.             'function' => '_xmlrpcs_getCapabilities',
  363.             'signature' => $_xmlrpcs_getCapabilities_sig,
  364.             'docstring' => $_xmlrpcs_getCapabilities_doc,
  365.             'signature_docs' => $_xmlrpcs_getCapabilities_sdoc)
  366.     );
  367.  
  368.     $GLOBALS['_xmlrpcs_occurred_errors''';
  369.     $GLOBALS['_xmlrpcs_prev_ehandler''';
  370.     /**
  371.     * Error handler used to track errors that occur during server-side execution of PHP code.
  372.     * This allows to report back to the client whether an internal error has occurred or not
  373.     * using an xmlrpc response object, instead of letting the client deal with the html junk
  374.     * that a PHP execution error on the server generally entails.
  375.     *
  376.     * NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors.
  377.     *
  378.     */
  379.     function _xmlrpcs_errorHandler($errcode$errstring$filename=null$lineno=null$context=null)
  380.     {
  381.         // obey the @ protocol
  382.         if (error_reporting(== 0)
  383.             return;
  384.  
  385.         //if($errcode != E_NOTICE && $errcode != E_WARNING && $errcode != E_USER_NOTICE && $errcode != E_USER_WARNING)
  386.         if($errcode != 2048// do not use E_STRICT by name, since on PHP 4 it will not be defined
  387.         {
  388.             $GLOBALS['_xmlrpcs_occurred_errors'$GLOBALS['_xmlrpcs_occurred_errors'$errstring "\n";
  389.         }
  390.         // Try to avoid as much as possible disruption to the previous error handling
  391.         // mechanism in place
  392.         if($GLOBALS['_xmlrpcs_prev_ehandler'== '')
  393.         {
  394.             // The previous error handler was the default: all we should do is log error
  395.             // to the default error log (if level high enough)
  396.             if(ini_get('log_errors'&& (intval(ini_get('error_reporting')) $errcode))
  397.             {
  398.                 error_log($errstring);
  399.             }
  400.         }
  401.         else
  402.         {
  403.             // Pass control on to previous error handler, trying to avoid loops...
  404.             if($GLOBALS['_xmlrpcs_prev_ehandler'!= '_xmlrpcs_errorHandler')
  405.             {
  406.                 // NB: this code will NOT work on php < 4.0.2: only 2 params were used for error handlers
  407.                 if(is_array($GLOBALS['_xmlrpcs_prev_ehandler']))
  408.                 {
  409.                     // the following works both with static class methods and plain object methods as error handler
  410.                     call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler']array($errcode$errstring$filename$lineno$context));
  411.                 }
  412.                 else
  413.                 {
  414.                     $GLOBALS['_xmlrpcs_prev_ehandler']($errcode$errstring$filename$lineno$context);
  415.                 }
  416.             }
  417.         }
  418.     }
  419.  
  420.     $GLOBALS['_xmlrpc_debuginfo']='';
  421.  
  422.     /**
  423.     * Add a string to the debug info that can be later seralized by the server
  424.     * as part of the response message.
  425.     * Note that for best compatbility, the debug string should be encoded using
  426.     * the $GLOBALS['xmlrpc_internalencoding'] character set.
  427.     * @param string $m 
  428.     * @access public
  429.     */
  430.     function xmlrpc_debugmsg($m)
  431.     {
  432.         $GLOBALS['_xmlrpc_debuginfo'.= $m "\n";
  433.     }
  434.  
  435.     class xmlrpc_server
  436.     {
  437.         /// array defining php functions exposed as xmlrpc methods by this server
  438.         var $dmap=array();
  439.         /**
  440.         * Defines how functions in dmap will be invokde: either using an xmlrpc msg object
  441.         * or plain php values.
  442.         * valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'
  443.         */
  444.         var $functions_parameters_type='xmlrpcvals';
  445.         /// controls wether the server is going to echo debugging messages back to the client as comments in response body. valid values: 0,1,2,3
  446.         var $debug = 1;
  447.         /**
  448.         * When set to true, it will enable HTTP compression of the response, in case
  449.         * the client has declared its support for compression in the request.
  450.         */
  451.         var $compress_response = false;
  452.         /**
  453.         * List of http compression methods accepted by the server for requests.
  454.         * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
  455.         */
  456.         var $accepted_compression = array();
  457.         /// shall we serve calls to system.* methods?
  458.         var $allow_system_funcs = true;
  459.         /// list of charset encodings natively accepted for requests
  460.         var $accepted_charset_encodings = array();
  461.         /**
  462.         * charset encoding to be used for response.
  463.         * NB: if we can, we will convert the generated response from internal_encoding to the intended one.
  464.         * can be: a supported xml encoding (only UTF-8 and ISO-8859-1 at present, unless mbstring is enabled),
  465.         * null (leave unspecified in response, convert output stream to US_ASCII),
  466.         * 'default' (use xmlrpc library default as specified in xmlrpc.inc, convert output stream if needed),
  467.         * or 'auto' (use client-specified charset encoding or same as request if request headers do not specify it (unless request is US-ASCII: then use library default anyway).
  468.         * NB: pretty dangerous if you accept every charset and do not have mbstring enabled)
  469.         */
  470.         var $response_charset_encoding = '';
  471.         /// storage for internal debug info
  472.         var $debug_info = '';
  473.         /// extra data passed at runtime to method handling functions. Used only by EPI layer
  474.         var $user_data = null;
  475.  
  476.         /**
  477.         * @param array $dispmap the dispatch map withd efinition of exposed services
  478.         * @param boolean $servicenow set to false to prevent the server from runnung upon construction
  479.         */
  480.         function xmlrpc_server($dispMap=null$serviceNow=true)
  481.         {
  482.             // if ZLIB is enabled, let the server by default accept compressed requests,
  483.             // and compress responses sent to clients that support them
  484.             if(function_exists('gzinflate'))
  485.             {
  486.                 $this->accepted_compression = array('gzip''deflate');
  487.                 $this->compress_response = true;
  488.             }
  489.  
  490.             // by default the xml parser can support these 3 charset encodings
  491.             $this->accepted_charset_encodings = array('UTF-8''ISO-8859-1''US-ASCII');
  492.  
  493.             // dispMap is a dispatch array of methods
  494.             // mapped to function names and signatures
  495.             // if a method
  496.             // doesn't appear in the map then an unknown
  497.             // method error is generated
  498.             /* milosch - changed to make passing dispMap optional.
  499.              * instead, you can use the class add_to_map() function
  500.              * to add functions manually (borrowed from SOAPX4)
  501.              */
  502.             if($dispMap)
  503.             {
  504.                 $this->dmap = $dispMap;
  505.                 if($serviceNow)
  506.                 {
  507.                     $this->service();
  508.                 }
  509.             }
  510.         }
  511.  
  512.         /**
  513.         * Set debug level of server.
  514.         * @param integer $in debug lvl: determines info added to xmlrpc responses (as xml comments)
  515.         *  0 = no debug info,
  516.         *  1 = msgs set from user with debugmsg(),
  517.         *  2 = add complete xmlrpc request (headers and body),
  518.         *  3 = add also all processing warnings happened during method processing
  519.         *  (NB: this involves setting a custom error handler, and might interfere
  520.         *  with the standard processing of the php function exposed as method. In
  521.         *  particular, triggering an USER_ERROR level error will not halt script
  522.         *  execution anymore, but just end up logged in the xmlrpc response)
  523.         *  Note that info added at elevel 2 and 3 will be base64 encoded
  524.         * @access public
  525.         */
  526.         function setDebug($in)
  527.         {
  528.             $this->debug=$in;
  529.         }
  530.  
  531.         /**
  532.         * Return a string with the serialized representation of all debug info
  533.         * @param string $charset_encoding the target charset encoding for the serialization
  534.         * @return string an XML comment (or two)
  535.         */
  536.         function serializeDebug($charset_encoding='')
  537.         {
  538.             // Tough encoding problem: which internal charset should we assume for debug info?
  539.             // It might contain a copy of raw data received from client, ie with unknown encoding,
  540.             // intermixed with php generated data and user generated data...
  541.             // so we split it: system debug is base 64 encoded,
  542.             // user debug info should be encoded by the end user using the INTERNAL_ENCODING
  543.             $out '';
  544.             if ($this->debug_info != '')
  545.             {
  546.                 $out .= "<!-- SERVER DEBUG INFO (BASE64 ENCODED):\n".base64_encode($this->debug_info)."\n-->\n";
  547.             }
  548.             if($GLOBALS['_xmlrpc_debuginfo']!='')
  549.             {
  550.  
  551.                 $out .= "<!-- DEBUG INFO:\n" xmlrpc_encode_entitites(str_replace('--''_-'$GLOBALS['_xmlrpc_debuginfo'])$GLOBALS['xmlrpc_internalencoding']$charset_encoding"\n-->\n";
  552.                 // NB: a better solution MIGHT be to use CDATA, but we need to insert it
  553.                 // into return payload AFTER the beginning tag
  554.                 //$out .= "<![CDATA[ DEBUG INFO:\n\n" . str_replace(']]>', ']_]_>', $GLOBALS['_xmlrpc_debuginfo']) . "\n]]>\n";
  555.             }
  556.             return $out;
  557.         }
  558.  
  559.         /**
  560.         * Execute the xmlrpc request, printing the response
  561.         * @param string $data the request body. If null, the http POST request will be examined
  562.         * @return xmlrpcresp the response object (usually not used by caller...)
  563.         * @access public
  564.         */
  565.         function service($data=null$return_payload=false)
  566.         {
  567.             if ($data === null)
  568.             {
  569.                 // workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA
  570.                 $ver phpversion();
  571.                 if ($ver[0>= 5)
  572.                 {
  573.                     $data file_get_contents('php://input');
  574.                 }
  575.                 else
  576.                 {
  577.                     $data = isset($GLOBALS['HTTP_RAW_POST_DATA']$GLOBALS['HTTP_RAW_POST_DATA''';
  578.                 }
  579.             }
  580.             $raw_data $data;
  581.  
  582.             // reset internal debug info
  583.             $this->debug_info = '';
  584.  
  585.             // Echo back what we received, before parsing it
  586.             if($this->debug > 1)
  587.             {
  588.                 $this->debugmsg("+++GOT+++\n" $data "\n+++END+++");
  589.             }
  590.  
  591.             $r $this->parseRequestHeaders($data$req_charset$resp_charset$resp_encoding);
  592.             if (!$r)
  593.             {
  594.                 $r=$this->parseRequest($data$req_charset);
  595.             }
  596.  
  597.             // save full body of request into response, for more debugging usages
  598.             $r->raw_data $raw_data;
  599.  
  600.             if($this->debug > && $GLOBALS['_xmlrpcs_occurred_errors'])
  601.             {
  602.                 $this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
  603.                     $GLOBALS['_xmlrpcs_occurred_errors'"+++END+++");
  604.             }
  605.  
  606.             $payload=$this->xml_header($resp_charset);
  607.             if($this->debug > 0)
  608.             {
  609.                 $payload $payload $this->serializeDebug($resp_charset);
  610.             }
  611.  
  612.             // G. Giunta 2006-01-27: do not create response serialization if it has
  613.             // already happened. Helps building json magic
  614.             if (empty($r->payload))
  615.             {
  616.                 $r->serialize($resp_charset);
  617.             }
  618.             $payload $payload $r->payload;
  619.  
  620.             if ($return_payload)
  621.             {
  622.                 return $payload;
  623.             }
  624.  
  625.             // if we get a warning/error that has output some text before here, then we cannot
  626.             // add a new header. We cannot say we are sending xml, either...
  627.             if(!headers_sent())
  628.             {
  629.                 header('Content-Type: '.$r->content_type);
  630.                 // we do not know if client actually told us an accepted charset, but if he did
  631.                 // we have to tell him what we did
  632.                 header("Vary: Accept-Charset");
  633.  
  634.                 // http compression of output: only
  635.                 // if we can do it, and we want to do it, and client asked us to,
  636.                 // and php ini settings do not force it already
  637.                 $php_no_self_compress !ini_get('zlib.output_compression'&& (ini_get('output_handler'!= 'ob_gzhandler');
  638.                 if($this->compress_response && function_exists('gzencode'&& $resp_encoding != ''
  639.                     && $php_no_self_compress)
  640.                 {
  641.                     if(strpos($resp_encoding'gzip'!== false)
  642.                     {
  643.                         $payload gzencode($payload);
  644.                         header("Content-Encoding: gzip");
  645.                         header("Vary: Accept-Encoding");
  646.                     }
  647.                     elseif (strpos($resp_encoding'deflate'!== false)
  648.                     {
  649.                         $payload gzcompress($payload);
  650.                         header("Content-Encoding: deflate");
  651.                         header("Vary: Accept-Encoding");
  652.                     }
  653.                 }
  654.  
  655.                 // do not ouput content-length header if php is compressing output for us:
  656.                 // it will mess up measurements
  657.                 if($php_no_self_compress)
  658.                 {
  659.                     header('Content-Length: ' . (int)strlen($payload));
  660.                 }
  661.             }
  662.             else
  663.             {
  664.                 error_log('XML-RPC: xmlrpc_server::service: http headers already sent before response is fully generated. Check for php warning or error messages');
  665.             }
  666.  
  667.             print $payload;
  668.  
  669.             // return request, in case subclasses want it
  670.             return $r;
  671.         }
  672.  
  673.         /**
  674.         * Add a method to the dispatch map
  675.         * @param string $methodname the name with which the method will be made available
  676.         * @param string $function the php function that will get invoked
  677.         * @param array $sig the array of valid method signatures
  678.         * @param string $doc method documentation
  679.         * @param array $sigdoc the array of valid method signatures docs (one string per param, one for return type)
  680.         * @access public
  681.         */
  682.         function add_to_map($methodname,$function,$sig=null,$doc=false,$sigdoc=false)
  683.         {
  684.             $this->dmap[$methodnamearray(
  685.                 'function'    => $function,
  686.                 'docstring' => $doc
  687.             );
  688.             if ($sig)
  689.             {
  690.                 $this->dmap[$methodname]['signature'$sig;
  691.             }
  692.             if ($sigdoc)
  693.             {
  694.                 $this->dmap[$methodname]['signature_docs'$sigdoc;
  695.             }
  696.         }
  697.  
  698.         /**
  699.         * Verify type and number of parameters received against a list of known signatures
  700.         * @param array $in array of either xmlrpcval objects or xmlrpc type definitions
  701.         * @param array $sig array of known signatures to match against
  702.         * @access private
  703.         */
  704.         function verifySignature($in$sig)
  705.         {
  706.             // check each possible signature in turn
  707.             if (is_object($in))
  708.             {
  709.                 $numParams $in->getNumParams();
  710.             }
  711.             else
  712.             {
  713.                 $numParams count($in);
  714.             }
  715.             foreach($sig as $cursig)
  716.             {
  717.                 if(count($cursig)==$numParams+1)
  718.                 {
  719.                     $itsOK=1;
  720.                     for($n=0$n<$numParams$n++)
  721.                     {
  722.                         if (is_object($in))
  723.                         {
  724.                             $p=$in->getParam($n);
  725.                             if($p->kindOf(== 'scalar')
  726.                             {
  727.                                 $pt=$p->scalartyp();
  728.                             }
  729.                             else
  730.                             {
  731.                                 $pt=$p->kindOf();
  732.                             }
  733.                         }
  734.                         else
  735.                         {
  736.                             $pt$in[$n== 'i4' 'int' $in[$n]// dispatch maps never use i4...
  737.                         }
  738.  
  739.                         // param index is $n+1, as first member of sig is return type
  740.                         if($pt != $cursig[$n+1&& $cursig[$n+1!= $GLOBALS['xmlrpcValue'])
  741.                         {
  742.                             $itsOK=0;
  743.                             $pno=$n+1;
  744.                             $wanted=$cursig[$n+1];
  745.                             $got=$pt;
  746.                             break;
  747.                         }
  748.                     }
  749.                     if($itsOK)
  750.                     {
  751.                         return array(1,'');
  752.                     }
  753.                 }
  754.             }
  755.             if(isset($wanted))
  756.             {
  757.                 return array(0"Wanted ${wanted}, got ${got} at param ${pno}");
  758.             }
  759.             else
  760.             {
  761.                 return array(0"No method signature matches number of parameters");
  762.             }
  763.         }
  764.  
  765.         /**
  766.         * Parse http headers received along with xmlrpc request. If needed, inflate request
  767.         * @return null on success or an xmlrpcresp
  768.         * @access private
  769.         */
  770.         function parseRequestHeaders(&$data&$req_encoding&$resp_encoding&$resp_compression)
  771.         {
  772.             // Play nice to PHP 4.0.x: superglobals were not yet invented...
  773.             if(!isset($_SERVER))
  774.             {
  775.                 $_SERVER $GLOBALS['HTTP_SERVER_VARS'];
  776.             }
  777.  
  778.             if($this->debug > 1)
  779.             {
  780.                 if(function_exists('getallheaders'))
  781.                 {
  782.                     $this->debugmsg('')// empty line
  783.                     foreach(getallheaders(as $name => $val)
  784.                     {
  785.                         $this->debugmsg("HEADER: $name$val");
  786.                     }
  787.                 }
  788.  
  789.             }
  790.  
  791.             if(isset($_SERVER['HTTP_CONTENT_ENCODING']))
  792.             {
  793.                 $content_encoding str_replace('x-'''$_SERVER['HTTP_CONTENT_ENCODING']);
  794.             }
  795.             else
  796.             {
  797.                 $content_encoding '';
  798.             }
  799.  
  800.             // check if request body has been compressed and decompress it
  801.             if($content_encoding != '' && strlen($data))
  802.             {
  803.                 if($content_encoding == 'deflate' || $content_encoding == 'gzip')
  804.                 {
  805.                     // if decoding works, use it. else assume data wasn't gzencoded
  806.                     if(function_exists('gzinflate'&& in_array($content_encoding$this->accepted_compression))
  807.                     {
  808.                         if($content_encoding == 'deflate' && $degzdata @gzuncompress($data))
  809.                         {
  810.                             $data $degzdata;
  811.                             if($this->debug > 1)
  812.                             {
  813.                                 $this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" $data "\n+++END+++");
  814.                             }
  815.                         }
  816.                         elseif($content_encoding == 'gzip' && $degzdata @gzinflate(substr($data10)))
  817.                         {
  818.                             $data $degzdata;
  819.                             if($this->debug > 1)
  820.                                 $this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" $data "\n+++END+++");
  821.                         }
  822.                         else
  823.                         {
  824.                             $r new xmlrpcresp(0$GLOBALS['xmlrpcerr']['server_decompress_fail']$GLOBALS['xmlrpcstr']['server_decompress_fail']);
  825.                             return $r;
  826.                         }
  827.                     }
  828.                     else
  829.                     {
  830.                         //error_log('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
  831.                         $r new xmlrpcresp(0$GLOBALS['xmlrpcerr']['server_cannot_decompress']$GLOBALS['xmlrpcstr']['server_cannot_decompress']);
  832.                         return $r;
  833.                     }
  834.                 }
  835.             }
  836.  
  837.             // check if client specified accepted charsets, and if we know how to fulfill
  838.             // the request
  839.             if ($this->response_charset_encoding == 'auto')
  840.             {
  841.                 $resp_encoding '';
  842.                 if (isset($_SERVER['HTTP_ACCEPT_CHARSET']))
  843.                 {
  844.                     // here we should check if we can match the client-requested encoding
  845.                     // with the encodings we know we can generate.
  846.                     /// @todo we should parse q=0.x preferences instead of getting first charset specified...
  847.                     $client_accepted_charsets explode(','strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']));
  848.                     // Give preference to internal encoding
  849.                     $known_charsets array($GLOBALS['xmlrpc_internalencoding']'UTF-8''ISO-8859-1''US-ASCII');
  850.                     foreach ($known_charsets as $charset)
  851.                     {
  852.                         foreach ($client_accepted_charsets as $accepted)
  853.                             if (strpos($accepted$charset=== 0)
  854.                             {
  855.                                 $resp_encoding $charset;
  856.                                 break;
  857.                             }
  858.                         if ($resp_encoding)
  859.                             break;
  860.                     }
  861.                 }
  862.             }
  863.             else
  864.             {
  865.                 $resp_encoding $this->response_charset_encoding;
  866.             }
  867.  
  868.             if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
  869.             {
  870.                 $resp_compression $_SERVER['HTTP_ACCEPT_ENCODING'];
  871.             }
  872.             else
  873.             {
  874.                 $resp_compression '';
  875.             }
  876.  
  877.             // 'guestimate' request encoding
  878.             /// @todo check if mbstring is enabled and automagic input conversion is on: it might mingle with this check???
  879.             $req_encoding guess_encoding(isset($_SERVER['CONTENT_TYPE']$_SERVER['CONTENT_TYPE''',
  880.                 $data);
  881.  
  882.             return null;
  883.         }
  884.  
  885.         /**
  886.         * Parse an xml chunk containing an xmlrpc request and execute the corresponding
  887.         * php function registered with the server
  888.         * @param string $data the xml request
  889.         * @param string $req_encoding (optional) the charset encoding of the xml request
  890.         * @return xmlrpcresp 
  891.         * @access private
  892.         */
  893.         function parseRequest($data$req_encoding='')
  894.         {
  895.             // 2005/05/07 commented and moved into caller function code
  896.             //if($data=='')
  897.             //{
  898.             //    $data=$GLOBALS['HTTP_RAW_POST_DATA'];
  899.             //}
  900.  
  901.             // G. Giunta 2005/02/13: we do NOT expect to receive html entities
  902.             // so we do not try to convert them into xml character entities
  903.             //$data = xmlrpc_html_entity_xlate($data);
  904.  
  905.             $GLOBALS['_xh']=array();
  906.             $GLOBALS['_xh']['ac']='';
  907.             $GLOBALS['_xh']['stack']=array();
  908.             $GLOBALS['_xh']['valuestack'array();
  909.             $GLOBALS['_xh']['params']=array();
  910.             $GLOBALS['_xh']['pt']=array();
  911.             $GLOBALS['_xh']['isf']=0;
  912.             $GLOBALS['_xh']['isf_reason']='';
  913.             $GLOBALS['_xh']['method']=false// so we can check later if we got a methodname or not
  914.             $GLOBALS['_xh']['rt']='';
  915.  
  916.             // decompose incoming XML into request structure
  917.             if ($req_encoding != '')
  918.             {
  919.                 if (!in_array($req_encodingarray('UTF-8''ISO-8859-1''US-ASCII')))
  920.                 // the following code might be better for mb_string enabled installs, but
  921.                 // makes the lib about 200% slower...
  922.                 //if (!is_valid_charset($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
  923.                 {
  924.                     error_log('XML-RPC: xmlrpc_server::parseRequest: invalid charset encoding of received request: '.$req_encoding);
  925.                     $req_encoding $GLOBALS['xmlrpc_defencoding'];
  926.                 }
  927.                 /// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue,
  928.                 // the encoding is not UTF8 and there are non-ascii chars in the text...
  929.                 /// @todo use an ampty string for php 5 ???
  930.                 $parser xml_parser_create($req_encoding);
  931.             }
  932.             else
  933.             {
  934.                 $parser xml_parser_create();
  935.             }
  936.  
  937.             xml_parser_set_option($parserXML_OPTION_CASE_FOLDINGtrue);
  938.             // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
  939.             // the xml parser to give us back data in the expected charset
  940.             // What if internal encoding is not in one of the 3 allowed?
  941.             // we use the broadest one, ie. utf8
  942.             // This allows to send data which is native in various charset,
  943.             // by extending xmlrpc_encode_entitites() and setting xmlrpc_internalencoding
  944.             if (!in_array($GLOBALS['xmlrpc_internalencoding']array('UTF-8''ISO-8859-1''US-ASCII')))
  945.             {
  946.                 xml_parser_set_option($parserXML_OPTION_TARGET_ENCODING'UTF-8');
  947.             }
  948.             else
  949.             {
  950.                 xml_parser_set_option($parserXML_OPTION_TARGET_ENCODING$GLOBALS['xmlrpc_internalencoding']);
  951.             }
  952.  
  953.             if ($this->functions_parameters_type != 'xmlrpcvals')
  954.                 xml_set_element_handler($parser'xmlrpc_se''xmlrpc_ee_fast');
  955.             else
  956.                 xml_set_element_handler($parser'xmlrpc_se''xmlrpc_ee');
  957.             xml_set_character_data_handler($parser'xmlrpc_cd');
  958.             xml_set_default_handler($parser'xmlrpc_dh');
  959.             if(!xml_parse($parser$data1))
  960.             {
  961.                 // return XML error as a faultCode
  962.                 $r new xmlrpcresp(0,
  963.                 $GLOBALS['xmlrpcerrxml']+xml_get_error_code($parser),
  964.                 sprintf('XML error: %s at line %d, column %d',
  965.                     xml_error_string(xml_get_error_code($parser)),
  966.                     xml_get_current_line_number($parser)xml_get_current_column_number($parser)));
  967.                 xml_parser_free($parser);
  968.             }
  969.             elseif ($GLOBALS['_xh']['isf'])
  970.             {
  971.                 xml_parser_free($parser);
  972.                 $r new xmlrpcresp(0,
  973.                     $GLOBALS['xmlrpcerr']['invalid_request'],
  974.                     $GLOBALS['xmlrpcstr']['invalid_request'' ' $GLOBALS['_xh']['isf_reason']);
  975.             }
  976.             else
  977.             {
  978.                 xml_parser_free($parser);
  979.                 if ($this->functions_parameters_type != 'xmlrpcvals')
  980.                 {
  981.                     if($this->debug > 1)
  982.                     {
  983.                         $this->debugmsg("\n+++PARSED+++\n".var_export($GLOBALS['_xh']['params']true)."\n+++END+++");
  984.                     }
  985.                     $r $this->execute($GLOBALS['_xh']['method']$GLOBALS['_xh']['params']$GLOBALS['_xh']['pt']);
  986.                 }
  987.                 else
  988.                 {
  989.                     // build an xmlrpcmsg object with data parsed from xml
  990.                     $m new xmlrpcmsg($GLOBALS['_xh']['method']);
  991.                     // now add parameters in
  992.                     for($i=0$i<count($GLOBALS['_xh']['params'])$i++)
  993.                     {
  994.                         $m->addParam($GLOBALS['_xh']['params'][$i]);
  995.                     }
  996.  
  997.                     if($this->debug > 1)
  998.                     {
  999.                         $this->debugmsg("\n+++PARSED+++\n".var_export($mtrue)."\n+++END+++");
  1000.                     }
  1001.                     $r $this->execute($m);
  1002.                 }
  1003.             }
  1004.             return $r;
  1005.         }
  1006.  
  1007.         /**
  1008.         * Execute a method invoked by the client, checking parameters used
  1009.         * @param mixed $m either an xmlrpcmsg obj or a method name
  1010.         * @param array $params array with method parameters as php types (if m is method name only)
  1011.         * @param array $paramtypes array with xmlrpc types of method parameters (if m is method name only)
  1012.         * @return xmlrpcresp 
  1013.         * @access private
  1014.         */
  1015.         function execute($m$params=null$paramtypes=null)
  1016.         {
  1017.             if (is_object($m))
  1018.             {
  1019.                 $methName $m->method();
  1020.             }
  1021.             else
  1022.             {
  1023.                 $methName $m;
  1024.             }
  1025.             logIO$methNametrue );
  1026.  
  1027.             $sysCall $this->allow_system_funcs && (strpos($methName"system."=== 0);
  1028.             $dmap $sysCall $GLOBALS['_xmlrpcs_dmap'$this->dmap;
  1029.  
  1030.             if(!isset($dmap[$methName]['function']))
  1031.             {
  1032.                 // No such method
  1033.                 logIO'No such method:'.$methName );
  1034.                 return new xmlrpcresp(0,
  1035.                     $GLOBALS['xmlrpcerr']['unknown_method'],
  1036.                     $GLOBALS['xmlrpcstr']['unknown_method']);
  1037.             }
  1038.  
  1039.             // Check signature
  1040.             if(isset($dmap[$methName]['signature']))
  1041.             {
  1042.                 $sig $dmap[$methName]['signature'];
  1043.                 if (is_object($m))
  1044.                 {
  1045.                     list($ok$errstr$this->verifySignature($m$sig);
  1046.                 }
  1047.                 else
  1048.                 {
  1049.                     list($ok$errstr$this->verifySignature($paramtypes$sig);
  1050.                 }
  1051.                 if(!$ok)
  1052.                 {
  1053.                     // Didn't match.
  1054.                     logIO'Invalid signature.' );
  1055.                     return new xmlrpcresp(
  1056.                         0,
  1057.                         $GLOBALS['xmlrpcerr']['incorrect_params'],
  1058.                         $GLOBALS['xmlrpcstr']['incorrect_params'": ${errstr}"
  1059.                     );
  1060.                 }
  1061.             }
  1062.  
  1063.             $func $dmap[$methName]['function'];
  1064.             // let the 'class::function' syntax be accepted in dispatch maps
  1065.             if(is_string($func&& strpos($func'::'))
  1066.             {
  1067.                 $func explode('::'$func);
  1068.             }
  1069.             // verify that function to be invoked is in fact callable
  1070.             if(!is_callable($func))
  1071.             {
  1072.                 error_log("XML-RPC: xmlrpc_server::execute: function $func registered as method handler is not callable");
  1073.                 return new xmlrpcresp(
  1074.                     0,
  1075.                     $GLOBALS['xmlrpcerr']['server_error'],
  1076.                     $GLOBALS['xmlrpcstr']['server_error'": no function matches method"
  1077.                 );
  1078.             }
  1079.  
  1080.             // If debug level is 3, we should catch all errors generated during
  1081.             // processing of user function, and log them as part of response
  1082.             if($this->debug > 2)
  1083.             {
  1084.                 $GLOBALS['_xmlrpcs_prev_ehandler'set_error_handler('_xmlrpcs_errorHandler');
  1085.             }
  1086.             if (is_object($m))
  1087.             {
  1088.                 if($sysCall)
  1089.                 {
  1090.                     $r call_user_func($func$this$m);
  1091.                 }
  1092.                 else
  1093.                 {
  1094.                     $r call_user_func($func$m);
  1095.                 }
  1096.                 if (!is_a($r'xmlrpcresp'))
  1097.                 {
  1098.                     error_log("XML-RPC: xmlrpc_server::execute: function $func registered as method handler does not return an xmlrpcresp object");
  1099.                     if (is_a($r'xmlrpcval'))
  1100.                     {
  1101.                         $r new xmlrpcresp($r);
  1102.                     }
  1103.                     else
  1104.                     {
  1105.                         $r new xmlrpcresp(
  1106.                             0,
  1107.                             $GLOBALS['xmlrpcerr']['server_error'],
  1108.                             $GLOBALS['xmlrpcstr']['server_error'": function does not return xmlrpcresp object"
  1109.                         );
  1110.                     }
  1111.                 }
  1112.             }
  1113.             else
  1114.             {
  1115.                 // call a 'plain php' function
  1116.                 if($sysCall)
  1117.                 {
  1118.                     array_unshift($params$this);
  1119.                     $r call_user_func_array($func$params);
  1120.                 }
  1121.                 else
  1122.                 {
  1123.                     // 3rd API convention for method-handling functions: EPI-style
  1124.                     if ($this->functions_parameters_type == 'epivals')
  1125.                     {
  1126.                         $r call_user_func_array($funcarray($methName$params$this->user_data));
  1127.                         // mimic EPI behaviour: if we get an array that looks like an error, make it
  1128.                         // an eror response
  1129.                         if (is_array($r&& array_key_exists('faultCode'$r&& array_key_exists('faultString'$r))
  1130.                         {
  1131.                             $r new xmlrpcresp(0(integer)$r['faultCode'](string)$r['faultString']);
  1132.                         }
  1133.                         else
  1134.                         {
  1135.                             // functions using EPI api should NOT return resp objects,
  1136.                             // so make sure we encode the return type correctly
  1137.                             $r new xmlrpcresp(php_xmlrpc_encode($rarray('extension_api')));
  1138.                         }
  1139.                     }
  1140.                     else
  1141.                     {
  1142.                         $r call_user_func_array($func$params);
  1143.                     }
  1144.                 }
  1145.                 // the return type can be either an xmlrpcresp object or a plain php value...
  1146.                 if (!is_a($r'xmlrpcresp'))
  1147.                 {
  1148.                     // what should we assume here about automatic encoding of datetimes
  1149.                     // and php classes instances???
  1150.                     $r new xmlrpcresp(php_xmlrpc_encode($rarray('auto_dates')));
  1151.                 }
  1152.             }
  1153.             if($this->debug > 2)
  1154.             {
  1155.                 // note: restore the error handler we found before calling the
  1156.                 // user func, even if it has been changed inside the func itself
  1157.                 if($GLOBALS['_xmlrpcs_prev_ehandler'])
  1158.                 {
  1159.                     set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
  1160.                 }
  1161.                 else
  1162.                 {
  1163.                     restore_error_handler();
  1164.                 }
  1165.             }
  1166.             return $r;
  1167.         }
  1168.  
  1169.         /**
  1170.         * add a string to the 'internal debug message' (separate from 'user debug message')
  1171.         * @param string $strings 
  1172.         * @access private
  1173.         */
  1174.         function debugmsg($string)
  1175.         {
  1176.             $this->debug_info .= $string."\n";
  1177.         }
  1178.  
  1179.         /**
  1180.         * @access private
  1181.         */
  1182.         function xml_header($charset_encoding='')
  1183.         {
  1184.             if ($charset_encoding != '')
  1185.             {
  1186.                 return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?">\n";
  1187.             }
  1188.             else
  1189.             {
  1190.                 return "<?xml version=\"1.0\"?" ">\n";
  1191.             }
  1192.         }
  1193.  
  1194.         /**
  1195.         * A debugging routine: just echoes back the input packet as a string value
  1196.         * DEPRECATED!
  1197.         */
  1198.         function echoInput()
  1199.         {
  1200.             $r=new xmlrpcresp(new xmlrpcval"'Aha said I: '" $GLOBALS['HTTP_RAW_POST_DATA']'string'));
  1201.             print $r->serialize();
  1202.         }
  1203.     }
  1204.  
  1205. /*
  1206.  * $Log: _xmlrpcs.inc.php,v $
  1207.  * Revision 1.8  2010/02/26 22:15:47  fplanque
  1208.  * whitespace/doc/minor
  1209.  *
  1210.  *
  1211.  * Revision 1.6  2010/02/09 17:20:39  efy-yury
  1212.  * &new -> new
  1213.  *
  1214.  * Revision 1.5  2010/01/31 18:11:49  blueyed
  1215.  * Fix previous &new replacements.
  1216.  *
  1217.  * Revision 1.4  2010/01/30 18:55:19  blueyed
  1218.  * Fix "Assigning the return value of new by reference is deprecated" (PHP 5.3)
  1219.  *
  1220.  * Revision 1.3  2009/08/28 18:22:05  waltercruz
  1221.  * Updating xmlrpc to 2.2.2
  1222.  *
  1223.  * Revision 1.2  2009/01/28 22:32:29  afwas
  1224.  * - Bumped to version 2.2.1 - March 6, 2008
  1225.  * - Added check for installed zlib in _xmlrpc.inc.php from line 1073. See http://forums.b2evolution.net/viewtopic.php?t=17029
  1226.  *
  1227.  * Revision 1.1  2008/01/14 07:17:32  fplanque
  1228.  * Upgraded XML-RPC for PHP library
  1229.  *
  1230.  */
  1231. ?>

Documentation generated on Sat, 06 Mar 2010 04:29:24 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).