xmlrpcs.inc 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. <?php
  2. // by Edd Dumbill (C) 1999-2002
  3. // <edd@usefulinc.com>
  4. // $Id: xmlrpcs.inc,v 1.69 2007/09/20 20:14:25 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 != 2048) // do not use E_STRICT by name, since on PHP 4 it will not be defined
  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. /// array defining php functions exposed as xmlrpc methods by this server
  408. var $dmap=array();
  409. /**
  410. * Defines how functions in dmap will be invokde: either using an xmlrpc msg object
  411. * or plain php values.
  412. * valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'
  413. */
  414. var $functions_parameters_type='xmlrpcvals';
  415. /// 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
  416. var $debug = 1;
  417. /**
  418. * When set to true, it will enable HTTP compression of the response, in case
  419. * the client has declared its support for compression in the request.
  420. */
  421. var $compress_response = false;
  422. /**
  423. * List of http compression methods accepted by the server for requests.
  424. * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
  425. */
  426. var $accepted_compression = array();
  427. /// shall we serve calls to system.* methods?
  428. var $allow_system_funcs = true;
  429. /// list of charset encodings natively accepted for requests
  430. var $accepted_charset_encodings = array();
  431. /**
  432. * charset encoding to be used for response.
  433. * NB: if we can, we will convert the generated response from internal_encoding to the intended one.
  434. * can be: a supported xml encoding (only UTF-8 and ISO-8859-1 at present, unless mbstring is enabled),
  435. * null (leave unspecified in response, convert output stream to US_ASCII),
  436. * 'default' (use xmlrpc library default as specified in xmlrpc.inc, convert output stream if needed),
  437. * 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).
  438. * NB: pretty dangerous if you accept every charset and do not have mbstring enabled)
  439. */
  440. var $response_charset_encoding = '';
  441. /// storage for internal debug info
  442. var $debug_info = '';
  443. /// extra data passed at runtime to method handling functions. Used only by EPI layer
  444. var $user_data = null;
  445. /**
  446. * @param array $dispmap the dispatch map withd efinition of exposed services
  447. * @param boolean $servicenow set to false to prevent the server from runnung upon construction
  448. */
  449. function xmlrpc_server($dispMap=null, $serviceNow=true)
  450. {
  451. // if ZLIB is enabled, let the server by default accept compressed requests,
  452. // and compress responses sent to clients that support them
  453. if(function_exists('gzinflate'))
  454. {
  455. $this->accepted_compression = array('gzip', 'deflate');
  456. $this->compress_response = true;
  457. }
  458. // by default the xml parser can support these 3 charset encodings
  459. $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
  460. // dispMap is a dispatch array of methods
  461. // mapped to function names and signatures
  462. // if a method
  463. // doesn't appear in the map then an unknown
  464. // method error is generated
  465. /* milosch - changed to make passing dispMap optional.
  466. * instead, you can use the class add_to_map() function
  467. * to add functions manually (borrowed from SOAPX4)
  468. */
  469. if($dispMap)
  470. {
  471. $this->dmap = $dispMap;
  472. if($serviceNow)
  473. {
  474. $this->service();
  475. }
  476. }
  477. }
  478. /**
  479. * Set debug level of server.
  480. * @param integer $in debug lvl: determines info added to xmlrpc responses (as xml comments)
  481. * 0 = no debug info,
  482. * 1 = msgs set from user with debugmsg(),
  483. * 2 = add complete xmlrpc request (headers and body),
  484. * 3 = add also all processing warnings happened during method processing
  485. * (NB: this involves setting a custom error handler, and might interfere
  486. * with the standard processing of the php function exposed as method. In
  487. * particular, triggering an USER_ERROR level error will not halt script
  488. * execution anymore, but just end up logged in the xmlrpc response)
  489. * Note that info added at elevel 2 and 3 will be base64 encoded
  490. * @access public
  491. */
  492. function setDebug($in)
  493. {
  494. $this->debug=$in;
  495. }
  496. /**
  497. * Return a string with the serialized representation of all debug info
  498. * @param string $charset_encoding the target charset encoding for the serialization
  499. * @return string an XML comment (or two)
  500. */
  501. function serializeDebug($charset_encoding='')
  502. {
  503. // Tough encoding problem: which internal charset should we assume for debug info?
  504. // It might contain a copy of raw data received from client, ie with unknown encoding,
  505. // intermixed with php generated data and user generated data...
  506. // so we split it: system debug is base 64 encoded,
  507. // user debug info should be encoded by the end user using the INTERNAL_ENCODING
  508. $out = '';
  509. if ($this->debug_info != '')
  510. {
  511. $out .= "<!-- SERVER DEBUG INFO (BASE64 ENCODED):\n".base64_encode($this->debug_info)."\n-->\n";
  512. }
  513. if($GLOBALS['_xmlrpc_debuginfo']!='')
  514. {
  515. $out .= "<!-- DEBUG INFO:\n" . xmlrpc_encode_entitites(str_replace('--', '_-', $GLOBALS['_xmlrpc_debuginfo']), $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "\n-->\n";
  516. // NB: a better solution MIGHT be to use CDATA, but we need to insert it
  517. // into return payload AFTER the beginning tag
  518. //$out .= "<![CDATA[ DEBUG INFO:\n\n" . str_replace(']]>', ']_]_>', $GLOBALS['_xmlrpc_debuginfo']) . "\n]]>\n";
  519. }
  520. return $out;
  521. }
  522. /**
  523. * Execute the xmlrpc request, printing the response
  524. * @param string $data the request body. If null, the http POST request will be examined
  525. * @return xmlrpcresp the response object (usually not used by caller...)
  526. * @access public
  527. */
  528. function service($data=null, $return_payload=false)
  529. {
  530. if ($data === null)
  531. {
  532. // workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA
  533. $ver = phpversion();
  534. if ($ver[0] >= 5)
  535. {
  536. $data = file_get_contents('php://input');
  537. }
  538. else
  539. {
  540. $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
  541. }
  542. }
  543. $raw_data = $data;
  544. // reset internal debug info
  545. $this->debug_info = '';
  546. // Echo back what we received, before parsing it
  547. if($this->debug > 1)
  548. {
  549. $this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++");
  550. }
  551. if (isset($GLOBALS['req_charset'])) $req_charset = $GLOBALS['req_charset'];
  552. if (isset($GLOBALS['resp_charset'])) $resp_charset = $GLOBALS['resp_charset'];
  553. if (isset($GLOBALS['resp_encoding'])) $resp_encoding = $GLOBALS['resp_encoding'];
  554. $r = $this->parseRequestHeaders($data, $req_charset, $resp_charset, $resp_encoding);
  555. if (!$r)
  556. {
  557. $r=$this->parseRequest($data, $req_charset);
  558. }
  559. // save full body of request into response, for more debugging usages
  560. $r->raw_data = $raw_data;
  561. if($this->debug > 2 && $GLOBALS['_xmlrpcs_occurred_errors'])
  562. {
  563. $this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
  564. $GLOBALS['_xmlrpcs_occurred_errors'] . "+++END+++");
  565. }
  566. $payload=$this->xml_header($resp_charset);
  567. if($this->debug > 0)
  568. {
  569. $payload = $payload . $this->serializeDebug($resp_charset);
  570. }
  571. // G. Giunta 2006-01-27: do not create response serialization if it has
  572. // already happened. Helps building json magic
  573. if (empty($r->payload))
  574. {
  575. $r->serialize($resp_charset);
  576. }
  577. $payload = $payload . $r->payload;
  578. if ($return_payload)
  579. {
  580. return $payload;
  581. }
  582. // if we get a warning/error that has output some text before here, then we cannot
  583. // add a new header. We cannot say we are sending xml, either...
  584. if(!headers_sent())
  585. {
  586. header('Content-Type: '.$r->content_type);
  587. // we do not know if client actually told us an accepted charset, but if he did
  588. // we have to tell him what we did
  589. header("Vary: Accept-Charset");
  590. // http compression of output: only
  591. // if we can do it, and we want to do it, and client asked us to,
  592. // and php ini settings do not force it already
  593. $php_no_self_compress = ini_get('zlib.output_compression') == '' && (ini_get('output_handler') != 'ob_gzhandler');
  594. if($this->compress_response && function_exists('gzencode') && $resp_encoding != ''
  595. && $php_no_self_compress)
  596. {
  597. if(strpos($resp_encoding, 'gzip') !== false)
  598. {
  599. $payload = gzencode($payload);
  600. header("Content-Encoding: gzip");
  601. header("Vary: Accept-Encoding");
  602. }
  603. elseif (strpos($resp_encoding, 'deflate') !== false)
  604. {
  605. $payload = gzcompress($payload);
  606. header("Content-Encoding: deflate");
  607. header("Vary: Accept-Encoding");
  608. }
  609. }
  610. // do not ouput content-length header if php is compressing output for us:
  611. // it will mess up measurements
  612. if($php_no_self_compress)
  613. {
  614. header('Content-Length: ' . (int)strlen($payload));
  615. }
  616. }
  617. else
  618. {
  619. error_log('XML-RPC: xmlrpc_server::service: http headers already sent before response is fully generated. Check for php warning or error messages');
  620. }
  621. print $payload;
  622. // return request, in case subclasses want it
  623. return $r;
  624. }
  625. /**
  626. * Add a method to the dispatch map
  627. * @param string $methodname the name with which the method will be made available
  628. * @param string $function the php function that will get invoked
  629. * @param array $sig the array of valid method signatures
  630. * @param string $doc method documentation
  631. * @access public
  632. */
  633. function add_to_map($methodname,$function,$sig=null,$doc='')
  634. {
  635. $this->dmap[$methodname] = array(
  636. 'function' => $function,
  637. 'docstring' => $doc
  638. );
  639. if ($sig)
  640. {
  641. $this->dmap[$methodname]['signature'] = $sig;
  642. }
  643. }
  644. /**
  645. * Verify type and number of parameters received against a list of known signatures
  646. * @param array $in array of either xmlrpcval objects or xmlrpc type definitions
  647. * @param array $sig array of known signatures to match against
  648. * @access private
  649. */
  650. function verifySignature($in, $sig)
  651. {
  652. // check each possible signature in turn
  653. if (is_object($in))
  654. {
  655. $numParams = $in->getNumParams();
  656. }
  657. else
  658. {
  659. $numParams = count($in);
  660. }
  661. foreach($sig as $cursig)
  662. {
  663. if(count($cursig)==$numParams+1)
  664. {
  665. $itsOK=1;
  666. for($n=0; $n<$numParams; $n++)
  667. {
  668. if (is_object($in))
  669. {
  670. $p=$in->getParam($n);
  671. if($p->kindOf() == 'scalar')
  672. {
  673. $pt=$p->scalartyp();
  674. }
  675. else
  676. {
  677. $pt=$p->kindOf();
  678. }
  679. }
  680. else
  681. {
  682. $pt= $in[$n] == 'i4' ? 'int' : $in[$n]; // dispatch maps never use i4...
  683. }
  684. // param index is $n+1, as first member of sig is return type
  685. if($pt != $cursig[$n+1] && $cursig[$n+1] != $GLOBALS['xmlrpcValue'])
  686. {
  687. $itsOK=0;
  688. $pno=$n+1;
  689. $wanted=$cursig[$n+1];
  690. $got=$pt;
  691. break;
  692. }
  693. }
  694. if($itsOK)
  695. {
  696. return array(1,'');
  697. }
  698. }
  699. }
  700. if(isset($wanted))
  701. {
  702. return array(0, "Wanted ${wanted}, got ${got} at param ${pno}");
  703. }
  704. else
  705. {
  706. return array(0, "No method signature matches number of parameters");
  707. }
  708. }
  709. /**
  710. * Parse http headers received along with xmlrpc request. If needed, inflate request
  711. * @return null on success or an xmlrpcresp
  712. * @access private
  713. */
  714. function parseRequestHeaders(&$data, &$req_encoding, &$resp_encoding, &$resp_compression)
  715. {
  716. // Play nice to PHP 4.0.x: superglobals were not yet invented...
  717. if(!isset($_SERVER))
  718. {
  719. $_SERVER = $GLOBALS['HTTP_SERVER_VARS'];
  720. }
  721. if($this->debug > 1)
  722. {
  723. if(function_exists('getallheaders'))
  724. {
  725. $this->debugmsg(''); // empty line
  726. foreach(getallheaders() as $name => $val)
  727. {
  728. $this->debugmsg("HEADER: $name: $val");
  729. }
  730. }
  731. }
  732. if(isset($_SERVER['HTTP_CONTENT_ENCODING']))
  733. {
  734. $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
  735. }
  736. else
  737. {
  738. $content_encoding = '';
  739. }
  740. // check if request body has been compressed and decompress it
  741. if($content_encoding != '' && strlen($data))
  742. {
  743. if($content_encoding == 'deflate' || $content_encoding == 'gzip')
  744. {
  745. // if decoding works, use it. else assume data wasn't gzencoded
  746. if(function_exists('gzinflate') && in_array($content_encoding, $this->accepted_compression))
  747. {
  748. if($content_encoding == 'deflate' && $degzdata = @gzuncompress($data))
  749. {
  750. $data = $degzdata;
  751. if($this->debug > 1)
  752. {
  753. $this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
  754. }
  755. }
  756. elseif($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
  757. {
  758. $data = $degzdata;
  759. if($this->debug > 1)
  760. $this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
  761. }
  762. else
  763. {
  764. $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_decompress_fail'], $GLOBALS['xmlrpcstr']['server_decompress_fail']);
  765. return $r;
  766. }
  767. }
  768. else
  769. {
  770. //error_log('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
  771. $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_cannot_decompress'], $GLOBALS['xmlrpcstr']['server_cannot_decompress']);
  772. return $r;
  773. }
  774. }
  775. }
  776. // check if client specified accepted charsets, and if we know how to fulfill
  777. // the request
  778. if ($this->response_charset_encoding == 'auto')
  779. {
  780. $resp_encoding = '';
  781. if (isset($_SERVER['HTTP_ACCEPT_CHARSET']))
  782. {
  783. // here we should check if we can match the client-requested encoding
  784. // with the encodings we know we can generate.
  785. /// @todo we should parse q=0.x preferences instead of getting first charset specified...
  786. $client_accepted_charsets = explode(',', strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']));
  787. // Give preference to internal encoding
  788. $known_charsets = array($GLOBALS['xmlrpc_internalencoding'], 'UTF-8', 'ISO-8859-1', 'US-ASCII');
  789. foreach ($known_charsets as $charset)
  790. {
  791. foreach ($client_accepted_charsets as $accepted)
  792. if (strpos($accepted, $charset) === 0)
  793. {
  794. $resp_encoding = $charset;
  795. break;
  796. }
  797. if ($resp_encoding)
  798. break;
  799. }
  800. }
  801. }
  802. else
  803. {
  804. $resp_encoding = $this->response_charset_encoding;
  805. }
  806. if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
  807. {
  808. $resp_compression = $_SERVER['HTTP_ACCEPT_ENCODING'];
  809. }
  810. else
  811. {
  812. $resp_compression = '';
  813. }
  814. // 'guestimate' request encoding
  815. /// @todo check if mbstring is enabled and automagic input conversion is on: it might mingle with this check???
  816. $req_encoding = guess_encoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '',
  817. $data);
  818. return null;
  819. }
  820. /**
  821. * Parse an xml chunk containing an xmlrpc request and execute the corresponding
  822. * php function registered with the server
  823. * @param string $data the xml request
  824. * @param string $req_encoding (optional) the charset encoding of the xml request
  825. * @return xmlrpcresp
  826. * @access private
  827. */
  828. function parseRequest($data, $req_encoding='')
  829. {
  830. // 2005/05/07 commented and moved into caller function code
  831. //if($data=='')
  832. //{
  833. // $data=$GLOBALS['HTTP_RAW_POST_DATA'];
  834. //}
  835. // G. Giunta 2005/02/13: we do NOT expect to receive html entities
  836. // so we do not try to convert them into xml character entities
  837. //$data = xmlrpc_html_entity_xlate($data);
  838. $GLOBALS['_xh']=array();
  839. $GLOBALS['_xh']['ac']='';
  840. $GLOBALS['_xh']['stack']=array();
  841. $GLOBALS['_xh']['valuestack'] = array();
  842. $GLOBALS['_xh']['params']=array();
  843. $GLOBALS['_xh']['pt']=array();
  844. $GLOBALS['_xh']['isf']=0;
  845. $GLOBALS['_xh']['isf_reason']='';
  846. $GLOBALS['_xh']['method']=false; // so we can check later if we got a methodname or not
  847. $GLOBALS['_xh']['rt']='';
  848. // decompose incoming XML into request structure
  849. if ($req_encoding != '')
  850. {
  851. if (!in_array($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
  852. // the following code might be better for mb_string enabled installs, but
  853. // makes the lib about 200% slower...
  854. //if (!is_valid_charset($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
  855. {
  856. error_log('XML-RPC: xmlrpc_server::parseRequest: invalid charset encoding of received request: '.$req_encoding);
  857. $req_encoding = $GLOBALS['xmlrpc_defencoding'];
  858. }
  859. /// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue,
  860. // the encoding is not UTF8 and there are non-ascii chars in the text...
  861. /// @todo use an ampty string for php 5 ???
  862. $parser = xml_parser_create($req_encoding);
  863. }
  864. else
  865. {
  866. $parser = xml_parser_create();
  867. }
  868. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
  869. // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
  870. // the xml parser to give us back data in the expected charset
  871. // What if internal encoding is not in one of the 3 allowed?
  872. // we use the broadest one, ie. utf8
  873. // This allows to send data which is native in various charset,
  874. // by extending xmlrpc_encode_entitites() and setting xmlrpc_internalencoding
  875. if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
  876. {
  877. xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
  878. }
  879. else
  880. {
  881. xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
  882. }
  883. if ($this->functions_parameters_type != 'xmlrpcvals')
  884. xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
  885. else
  886. xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
  887. xml_set_character_data_handler($parser, 'xmlrpc_cd');
  888. xml_set_default_handler($parser, 'xmlrpc_dh');
  889. if(!xml_parse($parser, $data, 1))
  890. {
  891. // return XML error as a faultCode
  892. $r= new xmlrpcresp(0,
  893. $GLOBALS['xmlrpcerrxml']+xml_get_error_code($parser),
  894. sprintf('XML error: %s at line %d, column %d',
  895. xml_error_string(xml_get_error_code($parser)),
  896. xml_get_current_line_number($parser), xml_get_current_column_number($parser)));
  897. xml_parser_free($parser);
  898. }
  899. elseif ($GLOBALS['_xh']['isf'])
  900. {
  901. xml_parser_free($parser);
  902. $r= new xmlrpcresp(0,
  903. $GLOBALS['xmlrpcerr']['invalid_request'],
  904. $GLOBALS['xmlrpcstr']['invalid_request'] . ' ' . $GLOBALS['_xh']['isf_reason']);
  905. }
  906. else
  907. {
  908. xml_parser_free($parser);
  909. if ($this->functions_parameters_type != 'xmlrpcvals')
  910. {
  911. if($this->debug > 1)
  912. {
  913. $this->debugmsg("\n+++PARSED+++\n".var_export($GLOBALS['_xh']['params'], true)."\n+++END+++");
  914. }
  915. $r = $this->execute($GLOBALS['_xh']['method'], $GLOBALS['_xh']['params'], $GLOBALS['_xh']['pt']);
  916. }
  917. else
  918. {
  919. // build an xmlrpcmsg object with data parsed from xml
  920. $m= new xmlrpcmsg($GLOBALS['_xh']['method']);
  921. // now add parameters in
  922. for($i=0; $i<count($GLOBALS['_xh']['params']); $i++)
  923. {
  924. $m->addParam($GLOBALS['_xh']['params'][$i]);
  925. }
  926. if($this->debug > 1)
  927. {
  928. $this->debugmsg("\n+++PARSED+++\n".var_export($m, true)."\n+++END+++");
  929. }
  930. $r = $this->execute($m);
  931. }
  932. }
  933. return $r;
  934. }
  935. /**
  936. * Execute a method invoked by the client, checking parameters used
  937. * @param mixed $m either an xmlrpcmsg obj or a method name
  938. * @param array $params array with method parameters as php types (if m is method name only)
  939. * @param array $paramtypes array with xmlrpc types of method parameters (if m is method name only)
  940. * @return xmlrpcresp
  941. * @access private
  942. */
  943. function execute($m, $params=null, $paramtypes=null)
  944. {
  945. if (is_object($m))
  946. {
  947. $methName = $m->method();
  948. }
  949. else
  950. {
  951. $methName = $m;
  952. }
  953. $sysCall = $this->allow_system_funcs && (strpos($methName, "system.") === 0);
  954. $dmap = $sysCall ? $GLOBALS['_xmlrpcs_dmap'] : $this->dmap;
  955. if(!isset($dmap[$methName]['function']))
  956. {
  957. // No such method
  958. return new xmlrpcresp(0,
  959. $GLOBALS['xmlrpcerr']['unknown_method'],
  960. $GLOBALS['xmlrpcstr']['unknown_method']);
  961. }
  962. // Check signature
  963. if(isset($dmap[$methName]['signature']))
  964. {
  965. $sig = $dmap[$methName]['signature'];
  966. if (is_object($m))
  967. {
  968. list($ok, $errstr) = $this->verifySignature($m, $sig);
  969. }
  970. else
  971. {
  972. list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
  973. }
  974. if(!$ok)
  975. {
  976. // Didn't match.
  977. return new xmlrpcresp(
  978. 0,
  979. $GLOBALS['xmlrpcerr']['incorrect_params'],
  980. $GLOBALS['xmlrpcstr']['incorrect_params'] . ": ${errstr}"
  981. );
  982. }
  983. }
  984. $func = $dmap[$methName]['function'];
  985. // let the 'class::function' syntax be accepted in dispatch maps
  986. if(is_string($func) && strpos($func, '::'))
  987. {
  988. $func = explode('::', $func);
  989. }
  990. // verify that function to be invoked is in fact callable
  991. if(!is_callable($func))
  992. {
  993. error_log("XML-RPC: xmlrpc_server::execute: function $func registered as method handler is not callable");
  994. return new xmlrpcresp(
  995. 0,
  996. $GLOBALS['xmlrpcerr']['server_error'],
  997. $GLOBALS['xmlrpcstr']['server_error'] . ": no function matches method"
  998. );
  999. }
  1000. // If debug level is 3, we should catch all errors generated during
  1001. // processing of user function, and log them as part of response
  1002. if($this->debug > 2)
  1003. {
  1004. $GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');
  1005. }
  1006. if (is_object($m))
  1007. {
  1008. if($sysCall)
  1009. {
  1010. $r = call_user_func($func, $this, $m);
  1011. }
  1012. else
  1013. {
  1014. $r = call_user_func($func, $m);
  1015. }
  1016. if (!($r instanceof xmlrpcresp))
  1017. {
  1018. error_log("XML-RPC: xmlrpc_server::execute: function $func registered as method handler does not return an xmlrpcresp object");
  1019. if ($r instanceof xmlrpcval)
  1020. {
  1021. $r = new xmlrpcresp($r);
  1022. }
  1023. else
  1024. {
  1025. $r = new xmlrpcresp(
  1026. 0,
  1027. $GLOBALS['xmlrpcerr']['server_error'],
  1028. $GLOBALS['xmlrpcstr']['server_error'] . ": function does not return xmlrpcresp object"
  1029. );
  1030. }
  1031. }
  1032. }
  1033. else
  1034. {
  1035. // call a 'plain php' function
  1036. if($sysCall)
  1037. {
  1038. array_unshift($params, $this);
  1039. $r = call_user_func_array($func, $params);
  1040. }
  1041. else
  1042. {
  1043. // 3rd API convention for method-handling functions: EPI-style
  1044. if ($this->functions_parameters_type == 'epivals')
  1045. {
  1046. $r = call_user_func_array($func, array($methName, $params, $this->user_data));
  1047. // mimic EPI behaviour: if we get an array that looks like an error, make it
  1048. // an eror response
  1049. if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r))
  1050. {
  1051. $r = new xmlrpcresp(0, (integer)$r['faultCode'], (string)$r['faultString']);
  1052. }
  1053. else
  1054. {
  1055. // functions using EPI api should NOT return resp objects,
  1056. // so make sure we encode the return type correctly
  1057. $r = new xmlrpcresp(php_xmlrpc_encode($r, array('extension_api')));
  1058. }
  1059. }
  1060. else
  1061. {
  1062. $r = call_user_func_array($func, $params);
  1063. }
  1064. }
  1065. // the return type can be either an xmlrpcresp object or a plain php value...
  1066. if (!($r instanceof xmlrpcresp))
  1067. {
  1068. // what should we assume here about automatic encoding of datetimes
  1069. // and php classes instances???
  1070. $r = new xmlrpcresp(php_xmlrpc_encode($r, array('auto_dates')));
  1071. }
  1072. }
  1073. if($this->debug > 2)
  1074. {
  1075. // note: restore the error handler we found before calling the
  1076. // user func, even if it has been changed inside the func itself
  1077. if($GLOBALS['_xmlrpcs_prev_ehandler'])
  1078. {
  1079. set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
  1080. }
  1081. else
  1082. {
  1083. restore_error_handler();
  1084. }
  1085. }
  1086. return $r;
  1087. }
  1088. /**
  1089. * add a string to the 'internal debug message' (separate from 'user debug message')
  1090. * @param string $strings
  1091. * @access private
  1092. */
  1093. function debugmsg($string)
  1094. {
  1095. $this->debug_info .= $string."\n";
  1096. }
  1097. /**
  1098. * @access private
  1099. */
  1100. function xml_header($charset_encoding='')
  1101. {
  1102. if ($charset_encoding != '')
  1103. {
  1104. return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?" . ">\n";
  1105. }
  1106. else
  1107. {
  1108. return "<?xml version=\"1.0\"?" . ">\n";
  1109. }
  1110. }
  1111. /**
  1112. * A debugging routine: just echoes back the input packet as a string value
  1113. * DEPRECATED!
  1114. */
  1115. function echoInput()
  1116. {
  1117. $r= new xmlrpcresp(new xmlrpcval( "'Aha said I: '" . $GLOBALS['HTTP_RAW_POST_DATA'], 'string'));
  1118. print $r->serialize();
  1119. }
  1120. }
  1121. ?>