PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/lib/xmlrpc/xmlrpcs.inc

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