XMLParser.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. <?php
  2. namespace PhpXmlRpc\Helper;
  3. use PhpXmlRpc\PhpXmlRpc;
  4. use PhpXmlRpc\Traits\DeprecationLogger;
  5. use PhpXmlRpc\Value;
  6. /**
  7. * Deals with parsing the XML.
  8. * @see http://xmlrpc.com/spec.md
  9. *
  10. * @todo implement an interface to allow for alternative implementations
  11. * - make access to $_xh protected, return more high-level data structures
  12. * - move the private parts of $_xh to the internal-use parsing-options config
  13. * - add parseRequest, parseResponse, parseValue methods
  14. * @todo if iconv() or mb_string() are available, we could allow to convert the received xml to a custom charset encoding
  15. * while parsing, which is faster than doing it later by going over the rebuilt data structure
  16. * @todo rename? This is an xml-rpc parser, not a generic xml parser...
  17. *
  18. * @property array $xmlrpc_valid_parents deprecated - public access left in purely for BC
  19. * @property int $accept deprecated - (protected) access left in purely for BC
  20. */
  21. class XMLParser
  22. {
  23. use DeprecationLogger;
  24. const RETURN_XMLRPCVALS = 'xmlrpcvals';
  25. const RETURN_EPIVALS = 'epivals';
  26. const RETURN_PHP = 'phpvals';
  27. const ACCEPT_REQUEST = 1;
  28. const ACCEPT_RESPONSE = 2;
  29. const ACCEPT_VALUE = 4;
  30. const ACCEPT_FAULT = 8;
  31. /**
  32. * @var int
  33. * The max length beyond which data will get truncated in error messages
  34. */
  35. protected $maxLogValueLength = 100;
  36. /**
  37. * @var array
  38. * Used to store state during parsing and to pass parsing results to callers.
  39. * Quick explanation of components:
  40. * private:
  41. * ac - used to accumulate values
  42. * stack - array with genealogy of xml elements names, used to validate nesting of xml-rpc elements
  43. * valuestack - array used for parsing arrays and structs
  44. * lv - used to indicate "looking for a value": implements the logic to allow values with no types to be strings
  45. * (values: 0=not looking, 1=looking, 3=found)
  46. * public:
  47. * isf - used to indicate an xml-rpc response fault (1), invalid xml-rpc fault (2), xml parsing fault (3)
  48. * isf_reason - used for storing xml-rpc response fault string
  49. * value - used to store the value in responses
  50. * method - used to store method name in requests
  51. * params - used to store parameters in requests
  52. * pt - used to store the type of each received parameter. Useful if parameters are automatically decoded to php values
  53. * rt - 'methodcall', 'methodresponse', 'value' or 'fault' (the last one used only in EPI emulation mode)
  54. */
  55. protected $_xh = array(
  56. 'ac' => '',
  57. 'stack' => array(),
  58. 'valuestack' => array(),
  59. 'lv' => 0,
  60. 'isf' => 0,
  61. 'isf_reason' => '',
  62. 'value' => null,
  63. 'method' => false,
  64. 'params' => array(),
  65. 'pt' => array(),
  66. 'rt' => '',
  67. );
  68. /**
  69. * @var array[]
  70. */
  71. protected $xmlrpc_valid_parents = array(
  72. 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
  73. 'BOOLEAN' => array('VALUE'),
  74. 'I4' => array('VALUE'),
  75. 'I8' => array('VALUE'),
  76. 'EX:I8' => array('VALUE'),
  77. 'INT' => array('VALUE'),
  78. 'STRING' => array('VALUE'),
  79. 'DOUBLE' => array('VALUE'),
  80. 'DATETIME.ISO8601' => array('VALUE'),
  81. 'BASE64' => array('VALUE'),
  82. 'MEMBER' => array('STRUCT'),
  83. 'NAME' => array('MEMBER'),
  84. 'DATA' => array('ARRAY'),
  85. 'ARRAY' => array('VALUE'),
  86. 'STRUCT' => array('VALUE'),
  87. 'PARAM' => array('PARAMS'),
  88. 'METHODNAME' => array('METHODCALL'),
  89. 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
  90. 'FAULT' => array('METHODRESPONSE'),
  91. 'NIL' => array('VALUE'), // only used when extension activated
  92. 'EX:NIL' => array('VALUE'), // only used when extension activated
  93. );
  94. /** @var array $parsing_options */
  95. protected $parsing_options = array();
  96. /** @var int $accept self::ACCEPT_REQUEST | self::ACCEPT_RESPONSE by default */
  97. //protected $accept = 3;
  98. /** @var int $maxChunkLength 4 MB by default. Any value below 10MB should be good */
  99. protected $maxChunkLength = 4194304;
  100. /** @var array
  101. * Used keys: accept, target_charset, methodname_callback, plus the ones set here.
  102. * We initialize it partially to help keep BC with subclasses which might have reimplemented `parse()` but not
  103. * the element handler methods
  104. */
  105. protected $current_parsing_options = array(
  106. 'xmlrpc_null_extension' => false,
  107. 'xmlrpc_return_datetimes' => false,
  108. 'xmlrpc_reject_invalid_values' => false
  109. );
  110. /**
  111. * @param array $options integer keys: options passed to the inner xml parser
  112. * string keys:
  113. * - target_charset (string)
  114. * - methodname_callback (callable)
  115. * - xmlrpc_null_extension (bool)
  116. * - xmlrpc_return_datetimes (bool)
  117. * - xmlrpc_reject_invalid_values (bool)
  118. */
  119. public function __construct(array $options = array())
  120. {
  121. $this->parsing_options = $options;
  122. }
  123. /**
  124. * Parses an xml-rpc xml string. Results of the parsing are found in $this->['_xh'].
  125. * Logs to the error log any issues which do not cause the parsing to fail.
  126. *
  127. * @param string $data
  128. * @param string $returnType self::RETURN_XMLRPCVALS, self::RETURN_PHP, self::RETURN_EPIVALS
  129. * @param int $accept a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE
  130. * @param array $options integer-key options are passed to the xml parser, string-key options are used independently.
  131. * These options are added to options received in the constructor.
  132. * Note that if options xmlrpc_null_extension, xmlrpc_return_datetimes and xmlrpc_reject_invalid_values
  133. * are not set, the default settings from PhpXmlRpc\PhpXmlRpc are used
  134. * @return array see the definition of $this->_xh for the meaning of the results
  135. * @throws \Exception this can happen if a callback function is set and it does throw (i.e. we do not catch exceptions)
  136. *
  137. * @todo refactor? we could 1. return the parsed data structure, and 2. move $returnType and $accept into options
  138. * @todo feature-creep make it possible to pass in options overriding usage of PhpXmlRpc::$xmlrpc_XXX_format, so
  139. * that parsing will be completely independent of global state. Note that it might incur a small perf hit...
  140. */
  141. public function parse($data, $returnType = self::RETURN_XMLRPCVALS, $accept = 3, $options = array())
  142. {
  143. $this->_xh = array(
  144. 'ac' => '',
  145. 'stack' => array(),
  146. 'valuestack' => array(),
  147. 'lv' => 0,
  148. 'isf' => 0,
  149. 'isf_reason' => '',
  150. 'value' => null,
  151. 'method' => false, // so we can check later if we got a methodname or not
  152. 'params' => array(),
  153. 'pt' => array(),
  154. 'rt' => '',
  155. );
  156. $len = strlen($data);
  157. // we test for empty documents here to save on resource allocation and simplify the chunked-parsing loop below
  158. if ($len == 0) {
  159. $this->_xh['isf'] = 3;
  160. $this->_xh['isf_reason'] = 'XML error 5: empty document';
  161. return $this->_xh;
  162. }
  163. $this->current_parsing_options = array('accept' => $accept);
  164. $mergedOptions = $this->parsing_options;
  165. foreach ($options as $key => $val) {
  166. $mergedOptions[$key] = $val;
  167. }
  168. foreach ($mergedOptions as $key => $val) {
  169. // q: can php be built without ctype? should we use a regexp?
  170. if (is_string($key) && !ctype_digit($key)) {
  171. /// @todo on invalid options, throw/error-out instead of logging an error message?
  172. switch($key) {
  173. case 'target_charset':
  174. if (function_exists('mb_convert_encoding')) {
  175. $this->current_parsing_options['target_charset'] = $val;
  176. } else {
  177. $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": 'target_charset' option is unsupported without mbstring");
  178. }
  179. break;
  180. case 'methodname_callback':
  181. if (is_callable($val)) {
  182. $this->current_parsing_options['methodname_callback'] = $val;
  183. } else {
  184. $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": Callback passed as 'methodname_callback' is not callable");
  185. }
  186. break;
  187. case 'xmlrpc_null_extension':
  188. case 'xmlrpc_return_datetimes':
  189. case 'xmlrpc_reject_invalid_values':
  190. $this->current_parsing_options[$key] = $val;
  191. break;
  192. default:
  193. $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": unsupported option: $key");
  194. }
  195. unset($mergedOptions[$key]);
  196. }
  197. }
  198. if (!isset($this->current_parsing_options['xmlrpc_null_extension'])) {
  199. $this->current_parsing_options['xmlrpc_null_extension'] = PhpXmlRpc::$xmlrpc_null_extension;
  200. }
  201. if (!isset($this->current_parsing_options['xmlrpc_return_datetimes'])) {
  202. $this->current_parsing_options['xmlrpc_return_datetimes'] = PhpXmlRpc::$xmlrpc_return_datetimes;
  203. }
  204. if (!isset($this->current_parsing_options['xmlrpc_reject_invalid_values'])) {
  205. $this->current_parsing_options['xmlrpc_reject_invalid_values'] = PhpXmlRpc::$xmlrpc_reject_invalid_values;
  206. }
  207. // NB: we use '' instead of null to force charset detection from the xml declaration
  208. $parser = xml_parser_create('');
  209. foreach ($mergedOptions as $key => $val) {
  210. xml_parser_set_option($parser, $key, $val);
  211. }
  212. // always set this, in case someone tries to disable it via options...
  213. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1);
  214. xml_set_object($parser, $this);
  215. switch ($returnType) {
  216. case self::RETURN_PHP:
  217. xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
  218. break;
  219. case self::RETURN_EPIVALS:
  220. xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_epi');
  221. break;
  222. /// @todo log an error / throw / error-out on unsupported return type
  223. case XMLParser::RETURN_XMLRPCVALS:
  224. default:
  225. xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
  226. }
  227. xml_set_character_data_handler($parser, 'xmlrpc_cd');
  228. xml_set_default_handler($parser, 'xmlrpc_dh');
  229. try {
  230. // @see ticket #70 - we have to parse big xml docs in chunks to avoid errors
  231. for ($offset = 0; $offset < $len; $offset += $this->maxChunkLength) {
  232. $chunk = substr($data, $offset, $this->maxChunkLength);
  233. // error handling: xml not well formed
  234. if (!xml_parse($parser, $chunk, $offset + $this->maxChunkLength >= $len)) {
  235. $errCode = xml_get_error_code($parser);
  236. $errStr = sprintf('XML error %s: %s at line %d, column %d', $errCode, xml_error_string($errCode),
  237. xml_get_current_line_number($parser), xml_get_current_column_number($parser));
  238. $this->_xh['isf'] = 3;
  239. $this->_xh['isf_reason'] = $errStr;
  240. }
  241. // no need to parse further if we already have a fatal error
  242. if ($this->_xh['isf'] >= 2) {
  243. break;
  244. }
  245. }
  246. /// @todo bump minimum php version to 5.5 and use a finally clause instead of doing cleanup 3 times
  247. } catch (\Exception $e) {
  248. xml_parser_free($parser);
  249. $this->current_parsing_options = array();
  250. /// @todo should we set $this->_xh['isf'] and $this->_xh['isf_reason'] ?
  251. throw $e;
  252. } catch (\Error $e) {
  253. xml_parser_free($parser);
  254. $this->current_parsing_options = array();
  255. //$this->accept = $prevAccept;
  256. /// @todo should we set $this->_xh['isf'] and $this->_xh['isf_reason'] ?
  257. throw $e;
  258. }
  259. xml_parser_free($parser);
  260. $this->current_parsing_options = array();
  261. return $this->_xh;
  262. }
  263. /**
  264. * xml parser handler function for opening element tags.
  265. * @internal
  266. *
  267. * @param resource $parser
  268. * @param string $name
  269. * @param $attrs
  270. * @param bool $acceptSingleVals DEPRECATED use the $accept parameter instead
  271. * @return void
  272. *
  273. * @todo optimization creep: throw when setting $this->_xh['isf'] > 1, to completely avoid further xml parsing
  274. * and remove the checking for $this->_xh['isf'] >= 2 everywhere
  275. */
  276. public function xmlrpc_se($parser, $name, $attrs, $acceptSingleVals = false)
  277. {
  278. // if invalid xml-rpc already detected, skip all processing
  279. if ($this->_xh['isf'] >= 2) {
  280. return;
  281. }
  282. // check for correct element nesting
  283. if (count($this->_xh['stack']) == 0) {
  284. // top level element can only be of 2 types
  285. /// @todo optimization creep: save this check into a bool variable, instead of using count() every time:
  286. /// there is only a single top level element in xml anyway
  287. // BC
  288. if ($acceptSingleVals === false) {
  289. $accept = $this->current_parsing_options['accept'];
  290. } else {
  291. $this->logDeprecation('Using argument $acceptSingleVals for method ' . __METHOD__ . ' is deprecated');
  292. $accept = self::ACCEPT_REQUEST | self::ACCEPT_RESPONSE | self::ACCEPT_VALUE;
  293. }
  294. if (($name == 'METHODCALL' && ($accept & self::ACCEPT_REQUEST)) ||
  295. ($name == 'METHODRESPONSE' && ($accept & self::ACCEPT_RESPONSE)) ||
  296. ($name == 'VALUE' && ($accept & self::ACCEPT_VALUE)) ||
  297. ($name == 'FAULT' && ($accept & self::ACCEPT_FAULT))) {
  298. $this->_xh['rt'] = strtolower($name);
  299. } else {
  300. $this->_xh['isf'] = 2;
  301. $this->_xh['isf_reason'] = 'missing top level xmlrpc element. Found: ' . $name;
  302. return;
  303. }
  304. } else {
  305. // not top level element: see if parent is OK
  306. $parent = end($this->_xh['stack']);
  307. if (!array_key_exists($name, $this->xmlrpc_valid_parents) || !in_array($parent, $this->xmlrpc_valid_parents[$name])) {
  308. $this->_xh['isf'] = 2;
  309. $this->_xh['isf_reason'] = "xmlrpc element $name cannot be child of $parent";
  310. return;
  311. }
  312. }
  313. switch ($name) {
  314. // optimize for speed switch cases: most common cases first
  315. case 'VALUE':
  316. /// @todo we could check for 2 VALUE elements inside a MEMBER or PARAM element
  317. $this->_xh['vt'] = 'value'; // indicator: no value found yet
  318. $this->_xh['ac'] = '';
  319. $this->_xh['lv'] = 1;
  320. $this->_xh['php_class'] = null;
  321. break;
  322. case 'I8':
  323. case 'EX:I8':
  324. if (PHP_INT_SIZE === 4) {
  325. // INVALID ELEMENT: RAISE ISF so that it is later recognized!!!
  326. $this->_xh['isf'] = 2;
  327. $this->_xh['isf_reason'] = "Received i8 element but php is compiled in 32 bit mode";
  328. return;
  329. }
  330. // fall through voluntarily
  331. case 'I4':
  332. case 'INT':
  333. case 'STRING':
  334. case 'BOOLEAN':
  335. case 'DOUBLE':
  336. case 'DATETIME.ISO8601':
  337. case 'BASE64':
  338. if ($this->_xh['vt'] != 'value') {
  339. // two data elements inside a value: an error occurred!
  340. $this->_xh['isf'] = 2;
  341. $this->_xh['isf_reason'] = "$name element following a {$this->_xh['vt']} element inside a single value";
  342. return;
  343. }
  344. $this->_xh['ac'] = ''; // reset the accumulator
  345. break;
  346. case 'STRUCT':
  347. case 'ARRAY':
  348. if ($this->_xh['vt'] != 'value') {
  349. // two data elements inside a value: an error occurred!
  350. $this->_xh['isf'] = 2;
  351. $this->_xh['isf_reason'] = "$name element following a {$this->_xh['vt']} element inside a single value";
  352. return;
  353. }
  354. // create an empty array to hold child values, and push it onto appropriate stack
  355. $curVal = array(
  356. 'values' => array(),
  357. 'type' => $name,
  358. );
  359. // check for out-of-band information to rebuild php objs and, in case it is found, save it
  360. if (@isset($attrs['PHP_CLASS'])) {
  361. $curVal['php_class'] = $attrs['PHP_CLASS'];
  362. }
  363. $this->_xh['valuestack'][] = $curVal;
  364. $this->_xh['vt'] = 'data'; // be prepared for a data element next
  365. break;
  366. case 'DATA':
  367. if ($this->_xh['vt'] != 'data') {
  368. // two data elements inside a value: an error occurred!
  369. $this->_xh['isf'] = 2;
  370. $this->_xh['isf_reason'] = "found two data elements inside an array element";
  371. return;
  372. }
  373. case 'METHODCALL':
  374. case 'METHODRESPONSE':
  375. case 'PARAMS':
  376. // valid elements that add little to processing
  377. break;
  378. case 'METHODNAME':
  379. case 'NAME':
  380. /// @todo we could check for 2 NAME elements inside a MEMBER element
  381. $this->_xh['ac'] = '';
  382. break;
  383. case 'FAULT':
  384. $this->_xh['isf'] = 1;
  385. break;
  386. case 'MEMBER':
  387. // set member name to null, in case we do not find in the xml later on
  388. $this->_xh['valuestack'][count($this->_xh['valuestack']) - 1]['name'] = null;
  389. //$this->_xh['ac']='';
  390. // Drop trough intentionally
  391. case 'PARAM':
  392. // clear value type, so we can check later if no value has been passed for this param/member
  393. $this->_xh['vt'] = null;
  394. break;
  395. case 'NIL':
  396. case 'EX:NIL':
  397. if ($this->current_parsing_options['xmlrpc_null_extension']) {
  398. if ($this->_xh['vt'] != 'value') {
  399. // two data elements inside a value: an error occurred!
  400. $this->_xh['isf'] = 2;
  401. $this->_xh['isf_reason'] = "$name element following a {$this->_xh['vt']} element inside a single value";
  402. return;
  403. }
  404. // reset the accumulator - q: is this necessary at all here? we don't use it on _ee anyway for NILs
  405. $this->_xh['ac'] = '';
  406. } else {
  407. $this->_xh['isf'] = 2;
  408. $this->_xh['isf_reason'] = 'Invalid NIL value received. Support for NIL can be enabled via \\PhpXmlRpc\\PhpXmlRpc::$xmlrpc_null_extension';
  409. return;
  410. }
  411. break;
  412. default:
  413. // INVALID ELEMENT: RAISE ISF so that it is later recognized
  414. /// @todo feature creep = allow a callback instead
  415. $this->_xh['isf'] = 2;
  416. $this->_xh['isf_reason'] = "found not-xmlrpc xml element $name";
  417. return;
  418. }
  419. // Save current element name to stack, to validate nesting
  420. $this->_xh['stack'][] = $name;
  421. /// @todo optimization creep: move this inside the big switch() above
  422. if ($name != 'VALUE') {
  423. $this->_xh['lv'] = 0;
  424. }
  425. }
  426. /**
  427. * xml parser handler function for close element tags.
  428. * @internal
  429. *
  430. * @param resource $parser
  431. * @param string $name
  432. * @param int $rebuildXmlrpcvals >1 for rebuilding xmlrpcvals, 0 for rebuilding php values, -1 for xmlrpc-extension compatibility
  433. * @return void
  434. * @throws \Exception this can happen if a callback function is set and it does throw (i.e. we do not catch exceptions)
  435. *
  436. * @todo optimization creep: throw when setting $this->_xh['isf'] > 1, to completely avoid further xml parsing
  437. * and remove the checking for $this->_xh['isf'] >= 2 everywhere
  438. */
  439. public function xmlrpc_ee($parser, $name, $rebuildXmlrpcvals = 1)
  440. {
  441. if ($this->_xh['isf'] >= 2) {
  442. return;
  443. }
  444. // push this element name from stack
  445. // NB: if XML validates, correct opening/closing is guaranteed and we do not have to check for $name == $currElem.
  446. // we also checked for proper nesting at start of elements...
  447. $currElem = array_pop($this->_xh['stack']);
  448. switch ($name) {
  449. case 'VALUE':
  450. // If no scalar was inside <VALUE></VALUE>, it was a string value
  451. if ($this->_xh['vt'] == 'value') {
  452. $this->_xh['value'] = $this->_xh['ac'];
  453. $this->_xh['vt'] = Value::$xmlrpcString;
  454. }
  455. // in case there is charset conversion required, do it here, to catch both cases of string values
  456. if (isset($this->current_parsing_options['target_charset']) && $this->_xh['vt'] === Value::$xmlrpcString) {
  457. $this->_xh['value'] = mb_convert_encoding($this->_xh['value'], $this->current_parsing_options['target_charset'], 'UTF-8');
  458. }
  459. if ($rebuildXmlrpcvals > 0) {
  460. // build the xml-rpc val out of the data received, and substitute it
  461. $temp = new Value($this->_xh['value'], $this->_xh['vt']);
  462. // in case we got info about underlying php class, save it in the object we're rebuilding
  463. if (isset($this->_xh['php_class'])) {
  464. $temp->_php_class = $this->_xh['php_class'];
  465. }
  466. $this->_xh['value'] = $temp;
  467. } elseif ($rebuildXmlrpcvals < 0) {
  468. if ($this->_xh['vt'] == Value::$xmlrpcDateTime) {
  469. $this->_xh['value'] = (object)array(
  470. 'xmlrpc_type' => 'datetime',
  471. 'scalar' => $this->_xh['value'],
  472. 'timestamp' => \PhpXmlRpc\Helper\Date::iso8601Decode($this->_xh['value'])
  473. );
  474. } elseif ($this->_xh['vt'] == Value::$xmlrpcBase64) {
  475. $this->_xh['value'] = (object)array(
  476. 'xmlrpc_type' => 'base64',
  477. 'scalar' => $this->_xh['value']
  478. );
  479. }
  480. } else {
  481. /// @todo this should handle php-serialized objects, since std deserializing is done
  482. /// by php_xmlrpc_decode, which we will not be calling...
  483. //if (isset($this->_xh['php_class'])) {
  484. //}
  485. }
  486. // check if we are inside an array or struct:
  487. // if value just built is inside an array, let's move it into array on the stack
  488. $vscount = count($this->_xh['valuestack']);
  489. if ($vscount && $this->_xh['valuestack'][$vscount - 1]['type'] == 'ARRAY') {
  490. $this->_xh['valuestack'][$vscount - 1]['values'][] = $this->_xh['value'];
  491. }
  492. break;
  493. case 'STRING':
  494. $this->_xh['vt'] = Value::$xmlrpcString;
  495. $this->_xh['lv'] = 3; // indicate we've found a value
  496. $this->_xh['value'] = $this->_xh['ac'];
  497. break;
  498. case 'BOOLEAN':
  499. $this->_xh['vt'] = Value::$xmlrpcBoolean;
  500. $this->_xh['lv'] = 3; // indicate we've found a value
  501. // We translate boolean 1 or 0 into PHP constants true or false. Strings 'true' and 'false' are accepted,
  502. // even though the spec never mentions them (see e.g. Blogger api docs)
  503. // NB: this simple checks helps a lot sanitizing input, i.e. no security problems around here
  504. // Note the non-strict type check: it will allow ' 1 '
  505. /// @todo feature-creep: use a flexible regexp, the same as we do with int, double and datetime.
  506. /// Note that using a regexp would also make this test less sensitive to phpunit shenanigans, and
  507. /// to changes in the way php compares strings (since 8.0, leading and trailing newlines are
  508. /// accepted when deciding if a string numeric...)
  509. if ($this->_xh['ac'] == '1' || strcasecmp($this->_xh['ac'], 'true') === 0) {
  510. $this->_xh['value'] = true;
  511. } else {
  512. // log if receiving something strange, even though we set the value to false anyway
  513. /// @todo to be consistent with the other types, we should return a value outside the good-value domain, e.g. NULL
  514. if ($this->_xh['ac'] != '0' && strcasecmp($this->_xh['ac'], 'false') !== 0) {
  515. if (!$this->handleParsingError('invalid data received in BOOLEAN value: ' .
  516. $this->truncateValueForLog($this->_xh['ac']), __METHOD__)) {
  517. return;
  518. }
  519. }
  520. $this->_xh['value'] = false;
  521. }
  522. break;
  523. case 'EX:I8':
  524. $name = 'i8';
  525. // fall through voluntarily
  526. case 'I4':
  527. case 'I8':
  528. case 'INT':
  529. // NB: we build the Value object with the original xml element name found, except for ex:i8. The
  530. // `Value::scalarTyp()` function will do some normalization of the data
  531. $this->_xh['vt'] = strtolower($name);
  532. $this->_xh['lv'] = 3; // indicate we've found a value
  533. if (!preg_match(PhpXmlRpc::$xmlrpc_int_format, $this->_xh['ac'])) {
  534. if (!$this->handleParsingError('non numeric data received in INT value: ' .
  535. $this->truncateValueForLog($this->_xh['ac']), __METHOD__)) {
  536. return;
  537. }
  538. /// @todo: find a better way of reporting an error value than this! Use NaN?
  539. $this->_xh['value'] = 'ERROR_NON_NUMERIC_FOUND';
  540. } else {
  541. // it's ok, add it on
  542. $this->_xh['value'] = (int)$this->_xh['ac'];
  543. }
  544. break;
  545. case 'DOUBLE':
  546. $this->_xh['vt'] = Value::$xmlrpcDouble;
  547. $this->_xh['lv'] = 3; // indicate we've found a value
  548. if (!preg_match(PhpXmlRpc::$xmlrpc_double_format, $this->_xh['ac'])) {
  549. if (!$this->handleParsingError('non numeric data received in DOUBLE value: ' .
  550. $this->truncateValueForLog($this->_xh['ac']), __METHOD__)) {
  551. return;
  552. }
  553. $this->_xh['value'] = 'ERROR_NON_NUMERIC_FOUND';
  554. } else {
  555. // it's ok, add it on
  556. $this->_xh['value'] = (double)$this->_xh['ac'];
  557. }
  558. break;
  559. case 'DATETIME.ISO8601':
  560. $this->_xh['vt'] = Value::$xmlrpcDateTime;
  561. $this->_xh['lv'] = 3; // indicate we've found a value
  562. if (!preg_match(PhpXmlRpc::$xmlrpc_datetime_format, $this->_xh['ac'])) {
  563. if (!$this->handleParsingError('invalid data received in DATETIME value: ' .
  564. $this->truncateValueForLog($this->_xh['ac']), __METHOD__)) {
  565. return;
  566. }
  567. }
  568. if ($this->current_parsing_options['xmlrpc_return_datetimes']) {
  569. try {
  570. $this->_xh['value'] = new \DateTime($this->_xh['ac']);
  571. // the default regex used to validate the date string a few lines above should make this case impossible,
  572. // but one never knows...
  573. } catch(\Exception $e) {
  574. // what to do? We can not guarantee that a valid date can be created. We return null...
  575. if (!$this->handleParsingError('invalid data received in DATETIME value. Error ' .
  576. $e->getMessage(), __METHOD__)) {
  577. return;
  578. }
  579. }
  580. } else {
  581. $this->_xh['value'] = $this->_xh['ac'];
  582. }
  583. break;
  584. case 'BASE64':
  585. $this->_xh['vt'] = Value::$xmlrpcBase64;
  586. $this->_xh['lv'] = 3; // indicate we've found a value
  587. if ($this->current_parsing_options['xmlrpc_reject_invalid_values']) {
  588. $v = base64_decode($this->_xh['ac'], true);
  589. if ($v === false) {
  590. $this->_xh['isf'] = 2;
  591. $this->_xh['isf_reason'] = 'Invalid data received in BASE64 value: '. $this->truncateValueForLog($this->_xh['ac']);
  592. return;
  593. }
  594. } else {
  595. $v = base64_decode($this->_xh['ac']);
  596. if ($v === '' && $this->_xh['ac'] !== '') {
  597. // only the empty string should decode to the empty string
  598. $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': invalid data received in BASE64 value: ' .
  599. $this->truncateValueForLog($this->_xh['ac']));
  600. }
  601. }
  602. $this->_xh['value'] = $v;
  603. break;
  604. case 'NAME':
  605. $this->_xh['valuestack'][count($this->_xh['valuestack']) - 1]['name'] = $this->_xh['ac'];
  606. break;
  607. case 'MEMBER':
  608. // add to array in the stack the last element built, unless no VALUE or no NAME were found
  609. if ($this->_xh['vt']) {
  610. $vscount = count($this->_xh['valuestack']);
  611. if ($this->_xh['valuestack'][$vscount - 1]['name'] === null) {
  612. if (!$this->handleParsingError('missing NAME inside STRUCT in received xml', __METHOD__)) {
  613. return;
  614. }
  615. $this->_xh['valuestack'][$vscount - 1]['name'] = '';
  616. }
  617. $this->_xh['valuestack'][$vscount - 1]['values'][$this->_xh['valuestack'][$vscount - 1]['name']] = $this->_xh['value'];
  618. } else {
  619. if (!$this->handleParsingError('missing VALUE inside STRUCT in received xml', __METHOD__)) {
  620. return;
  621. }
  622. }
  623. break;
  624. case 'DATA':
  625. $this->_xh['vt'] = null; // reset this to check for 2 data elements in a row - even if they're empty
  626. break;
  627. case 'STRUCT':
  628. case 'ARRAY':
  629. // fetch out of stack array of values, and promote it to current value
  630. $currVal = array_pop($this->_xh['valuestack']);
  631. $this->_xh['value'] = $currVal['values'];
  632. $this->_xh['vt'] = strtolower($name);
  633. if (isset($currVal['php_class'])) {
  634. $this->_xh['php_class'] = $currVal['php_class'];
  635. }
  636. break;
  637. case 'PARAM':
  638. // add to array of params the current value, unless no VALUE was found
  639. /// @todo should we also check if there were two VALUE inside the PARAM?
  640. if ($this->_xh['vt']) {
  641. $this->_xh['params'][] = $this->_xh['value'];
  642. $this->_xh['pt'][] = $this->_xh['vt'];
  643. } else {
  644. if (!$this->handleParsingError('missing VALUE inside PARAM in received xml', __METHOD__)) {
  645. return;
  646. }
  647. }
  648. break;
  649. case 'METHODNAME':
  650. if (!preg_match(PhpXmlRpc::$xmlrpc_methodname_format, $this->_xh['ac'])) {
  651. if (!$this->handleParsingError('invalid data received in METHODNAME: '.
  652. $this->truncateValueForLog($this->_xh['ac']), __METHOD__)) {
  653. return;
  654. }
  655. }
  656. $methodName = trim($this->_xh['ac']);
  657. $this->_xh['method'] = $methodName;
  658. // we allow the callback to f.e. give us back a mangled method name by manipulating $this
  659. if (isset($this->current_parsing_options['methodname_callback'])) {
  660. call_user_func($this->current_parsing_options['methodname_callback'], $methodName, $this, $parser);
  661. }
  662. break;
  663. case 'NIL':
  664. case 'EX:NIL':
  665. // NB: if NIL support is not enabled, parsing stops at element start. So this If is redundant
  666. //if ($this->current_parsing_options['xmlrpc_null_extension']) {
  667. $this->_xh['vt'] = 'null';
  668. $this->_xh['value'] = null;
  669. $this->_xh['lv'] = 3;
  670. //}
  671. break;
  672. /// @todo add extra checking:
  673. /// - METHODRESPONSE should contain either a PARAMS with a single PARAM, or a FAULT
  674. /// - FAULT should contain a single struct with the 2 expected members (check their name and type)
  675. /// - METHODCALL should contain a methodname
  676. case 'PARAMS':
  677. case 'FAULT':
  678. case 'METHODCALL':
  679. case 'METHODRESPONSE':
  680. break;
  681. default:
  682. // End of INVALID ELEMENT
  683. // Should we add an assert here for unreachable code? When an invalid element is found in xmlrpc_se,
  684. // $this->_xh['isf'] is set to 2...
  685. break;
  686. }
  687. }
  688. /**
  689. * Used in decoding xml-rpc requests/responses without rebuilding xml-rpc Values.
  690. * @internal
  691. *
  692. * @param resource $parser
  693. * @param string $name
  694. * @return void
  695. */
  696. public function xmlrpc_ee_fast($parser, $name)
  697. {
  698. $this->xmlrpc_ee($parser, $name, 0);
  699. }
  700. /**
  701. * Used in decoding xml-rpc requests/responses while building xmlrpc-extension Values (plain php for all but base64 and datetime).
  702. * @internal
  703. *
  704. * @param resource $parser
  705. * @param string $name
  706. * @return void
  707. */
  708. public function xmlrpc_ee_epi($parser, $name)
  709. {
  710. $this->xmlrpc_ee($parser, $name, -1);
  711. }
  712. /**
  713. * xml parser handler function for character data.
  714. * @internal
  715. *
  716. * @param resource $parser
  717. * @param string $data
  718. * @return void
  719. */
  720. public function xmlrpc_cd($parser, $data)
  721. {
  722. // skip processing if xml fault already detected
  723. if ($this->_xh['isf'] >= 2) {
  724. return;
  725. }
  726. // "lookforvalue == 3" means that we've found an entire value and should discard any further character data
  727. if ($this->_xh['lv'] != 3) {
  728. $this->_xh['ac'] .= $data;
  729. }
  730. }
  731. /**
  732. * xml parser handler function for 'other stuff', i.e. not char data or element start/end tag.
  733. * In fact, it only gets called on unknown entities...
  734. * @internal
  735. *
  736. * @param $parser
  737. * @param string data
  738. * @return void
  739. */
  740. public function xmlrpc_dh($parser, $data)
  741. {
  742. // skip processing if xml fault already detected
  743. if ($this->_xh['isf'] >= 2) {
  744. return;
  745. }
  746. if (substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';') {
  747. $this->_xh['ac'] .= $data;
  748. }
  749. }
  750. /**
  751. * xml charset encoding guessing helper function.
  752. * Tries to determine the charset encoding of an XML chunk received over HTTP.
  753. *
  754. * NB: according to the spec (RFC 3023), if text/xml content-type is received over HTTP without a content-type,
  755. * we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of non-conforming (legacy?) clients/servers,
  756. * which will be most probably using UTF-8 anyway...
  757. * In order of importance checks:
  758. * 1. http headers
  759. * 2. BOM
  760. * 3. XML declaration
  761. * 4. guesses using mb_detect_encoding()
  762. *
  763. * @param string $httpHeader the http Content-type header
  764. * @param string $xmlChunk xml content buffer
  765. * @param string $encodingPrefs comma separated list of character encodings to be used as default (when mb extension is enabled).
  766. * This can also be set globally using PhpXmlRpc::$xmlrpc_detectencodings
  767. * @return string the encoding determined. Null if it can't be determined and mbstring is enabled,
  768. * PhpXmlRpc::$xmlrpc_defencoding if it can't be determined and mbstring is not enabled
  769. *
  770. * @todo as of 2023, the relevant RFC for XML Media Types is now 7303, and for HTTP it is 9110. Check if the order of
  771. * precedence implemented here is still correct
  772. * @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!
  773. * @todo feature-creep make it possible to pass in options overriding usage of PhpXmlRpc static variables, to make
  774. * the method independent of global state
  775. */
  776. public static function guessEncoding($httpHeader = '', $xmlChunk = '', $encodingPrefs = null)
  777. {
  778. // discussion: see http://www.yale.edu/pclt/encoding/
  779. // 1 - test if encoding is specified in HTTP HEADERS
  780. // Details:
  781. // LWS: (\13\10)?( |\t)+
  782. // token: (any char but excluded stuff)+
  783. // quoted string: " (any char but double quotes and control chars)* "
  784. // header: Content-type = ...; charset=value(; ...)*
  785. // where value is of type token, no LWS allowed between 'charset' and value
  786. // Note: we do not check for invalid chars in VALUE:
  787. // this had better be done using pure ereg as below
  788. // Note 2: we might be removing whitespace/tabs that ought to be left in if
  789. // the received charset is a quoted string. But nobody uses such charset names...
  790. /// @todo this test will pass if ANY header has charset specification, not only Content-Type. Fix it?
  791. $matches = array();
  792. if (preg_match('/;\s*charset\s*=([^;]+)/i', $httpHeader, $matches)) {
  793. return strtoupper(trim($matches[1], " \t\""));
  794. }
  795. // 2 - scan the first bytes of the data for a UTF-16 (or other) BOM pattern
  796. // (source: http://www.w3.org/TR/2000/REC-xml-20001006)
  797. // NOTE: actually, according to the spec, even if we find the BOM and determine
  798. // an encoding, we should check if there is an encoding specified
  799. // in the xml declaration, and verify if they match.
  800. /// @todo implement check as described above?
  801. /// @todo implement check for first bytes of string even without a BOM? (It sure looks harder than for cases WITH a BOM)
  802. if (preg_match('/^(?:\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk)) {
  803. return 'UCS-4';
  804. } elseif (preg_match('/^(?:\xFE\xFF|\xFF\xFE)/', $xmlChunk)) {
  805. return 'UTF-16';
  806. } elseif (preg_match('/^(?:\xEF\xBB\xBF)/', $xmlChunk)) {
  807. return 'UTF-8';
  808. }
  809. // 3 - test if encoding is specified in the xml declaration
  810. /// @todo this regexp will fail if $xmlChunk uses UTF-32/UCS-4, and most likely UTF-16/UCS-2 as well. In that
  811. /// case we leave the guesswork up to mbstring - which seems to be able to detect it, starting with php 5.6.
  812. /// For lower versions, we could attempt usage of mb_ereg...
  813. // Details:
  814. // SPACE: (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
  815. // EQ: SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
  816. if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
  817. '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
  818. $xmlChunk, $matches)) {
  819. return strtoupper(substr($matches[2], 1, -1));
  820. }
  821. // 4 - if mbstring is available, let it do the guesswork
  822. if (function_exists('mb_detect_encoding')) {
  823. if ($encodingPrefs == null && PhpXmlRpc::$xmlrpc_detectencodings != null) {
  824. $encodingPrefs = PhpXmlRpc::$xmlrpc_detectencodings;
  825. }
  826. if ($encodingPrefs) {
  827. $enc = mb_detect_encoding($xmlChunk, $encodingPrefs);
  828. } else {
  829. $enc = mb_detect_encoding($xmlChunk);
  830. }
  831. // NB: mb_detect likes to call it ascii, xml parser likes to call it US_ASCII...
  832. // IANA also likes better US-ASCII, so go with it
  833. if ($enc == 'ASCII') {
  834. $enc = 'US-' . $enc;
  835. }
  836. return $enc;
  837. } else {
  838. // No encoding specified: assume it is iso-8859-1, as per HTTP1.1?
  839. // Both RFC 2616 (HTTP 1.1) and RFC 1945 (HTTP 1.0) clearly state that for text/xxx content types
  840. // this should be the standard. And we should be getting text/xml as request and response.
  841. // BUT we have to be backward compatible with the lib, which always used UTF-8 as default. Moreover,
  842. // RFC 7231, which obsoletes the two RFC mentioned above, has changed the rules. It says:
  843. // "The default charset of ISO-8859-1 for text media types has been removed; the default is now whatever
  844. // the media type definition says."
  845. return PhpXmlRpc::$xmlrpc_defencoding;
  846. }
  847. }
  848. /**
  849. * Helper function: checks if an xml chunk has a charset declaration (BOM or in the xml declaration).
  850. *
  851. * @param string $xmlChunk
  852. * @return bool
  853. *
  854. * @todo rename to hasEncodingDeclaration
  855. */
  856. public static function hasEncoding($xmlChunk)
  857. {
  858. // scan the first bytes of the data for a UTF-16 (or other) BOM pattern
  859. // (source: http://www.w3.org/TR/2000/REC-xml-20001006)
  860. if (preg_match('/^(?:\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk)) {
  861. return true;
  862. } elseif (preg_match('/^(?:\xFE\xFF|\xFF\xFE)/', $xmlChunk)) {
  863. return true;
  864. } elseif (preg_match('/^(?:\xEF\xBB\xBF)/', $xmlChunk)) {
  865. return true;
  866. }
  867. // test if encoding is specified in the xml declaration
  868. // Details:
  869. // SPACE: (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
  870. // EQ: SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
  871. if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
  872. '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
  873. $xmlChunk)) {
  874. return true;
  875. }
  876. return false;
  877. }
  878. /**
  879. * @param string $message
  880. * @param string $method method/file/line info
  881. * @return bool false if the caller has to stop parsing
  882. */
  883. protected function handleParsingError($message, $method = '')
  884. {
  885. if ($this->current_parsing_options['xmlrpc_reject_invalid_values']) {
  886. $this->_xh['isf'] = 2;
  887. $this->_xh['isf_reason'] = ucfirst($message);
  888. return false;
  889. } else {
  890. $this->getLogger()->error('XML-RPC: ' . ($method != '' ? $method . ': ' : '') . $message);
  891. return true;
  892. }
  893. }
  894. /**
  895. * Truncates unsafe data
  896. * @param string $data
  897. * @return string
  898. */
  899. protected function truncateValueForLog($data)
  900. {
  901. if (strlen($data) > $this->maxLogValueLength) {
  902. return substr($data, 0, $this->maxLogValueLength - 3) . '...';
  903. }
  904. return $data;
  905. }
  906. // *** BC layer ***
  907. /**
  908. * xml parser handler function for opening element tags.
  909. * Used in decoding xml chunks that might represent single xml-rpc values as well as requests, responses.
  910. * @deprecated
  911. *
  912. * @param resource $parser
  913. * @param $name
  914. * @param $attrs
  915. * @return void
  916. */
  917. public function xmlrpc_se_any($parser, $name, $attrs)
  918. {
  919. // this will be spamming the log if this method is in use...
  920. $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
  921. $this->xmlrpc_se($parser, $name, $attrs, true);
  922. }
  923. public function &__get($name)
  924. {
  925. switch ($name) {
  926. case '_xh':
  927. case 'xmlrpc_valid_parents':
  928. $this->logDeprecation('Getting property XMLParser::' . $name . ' is deprecated');
  929. return $this->$name;
  930. default:
  931. /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
  932. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
  933. trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
  934. $result = null;
  935. return $result;
  936. }
  937. }
  938. public function __set($name, $value)
  939. {
  940. switch ($name) {
  941. // this should only ever be called by subclasses which overtook `parse()`
  942. case 'accept':
  943. $this->logDeprecation('Setting property XMLParser::' . $name . ' is deprecated');
  944. $this->current_parsing_options['accept'] = $value;
  945. break;
  946. case '_xh':
  947. case 'xmlrpc_valid_parents':
  948. $this->logDeprecation('Setting property XMLParser::' . $name . ' is deprecated');
  949. $this->$name = $value;
  950. break;
  951. default:
  952. /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
  953. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
  954. trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
  955. }
  956. }
  957. public function __isset($name)
  958. {
  959. switch ($name) {
  960. case 'accept':
  961. $this->logDeprecation('Checking property XMLParser::' . $name . ' is deprecated');
  962. return isset($this->current_parsing_options['accept']);
  963. case '_xh':
  964. case 'xmlrpc_valid_parents':
  965. $this->logDeprecation('Checking property XMLParser::' . $name . ' is deprecated');
  966. return isset($this->$name);
  967. default:
  968. return false;
  969. }
  970. }
  971. public function __unset($name)
  972. {
  973. switch ($name) {
  974. // q: does this make sense at all?
  975. case 'accept':
  976. $this->logDeprecation('Unsetting property XMLParser::' . $name . ' is deprecated');
  977. unset($this->current_parsing_options['accept']);
  978. break;
  979. case '_xh':
  980. case 'xmlrpc_valid_parents':
  981. $this->logDeprecation('Unsetting property XMLParser::' . $name . ' is deprecated');
  982. unset($this->$name);
  983. break;
  984. default:
  985. /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
  986. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
  987. trigger_error('Undefined property via __unset(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
  988. }
  989. }
  990. }