php_xmlreader.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Rob Richards <rrichards@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include "php.h"
  22. #include "php_ini.h"
  23. #include "ext/standard/info.h"
  24. #include "php_xmlreader.h"
  25. #ifdef HAVE_DOM
  26. #include "ext/dom/xml_common.h"
  27. #include "ext/dom/dom_ce.h"
  28. #endif
  29. #include <libxml/xmlreader.h>
  30. #include <libxml/uri.h>
  31. zend_class_entry *xmlreader_class_entry;
  32. static zend_object_handlers xmlreader_object_handlers;
  33. static HashTable xmlreader_prop_handlers;
  34. typedef int (*xmlreader_read_int_t)(xmlTextReaderPtr reader);
  35. typedef unsigned char *(*xmlreader_read_char_t)(xmlTextReaderPtr reader);
  36. typedef const unsigned char *(*xmlreader_read_const_char_t)(xmlTextReaderPtr reader);
  37. typedef int (*xmlreader_write_t)(xmlreader_object *obj, zval *newval);
  38. typedef unsigned char *(*xmlreader_read_one_char_t)(xmlTextReaderPtr reader, const unsigned char *);
  39. typedef struct _xmlreader_prop_handler {
  40. xmlreader_read_int_t read_int_func;
  41. xmlreader_read_const_char_t read_char_func;
  42. xmlreader_write_t write_func;
  43. int type;
  44. } xmlreader_prop_handler;
  45. #define XMLREADER_LOAD_STRING 0
  46. #define XMLREADER_LOAD_FILE 1
  47. /* {{{ xmlreader_register_prop_handler */
  48. static void xmlreader_register_prop_handler(HashTable *prop_handler, char *name, xmlreader_read_int_t read_int_func, xmlreader_read_const_char_t read_char_func, int rettype)
  49. {
  50. xmlreader_prop_handler hnd;
  51. zend_string *str;
  52. hnd.read_char_func = read_char_func;
  53. hnd.read_int_func = read_int_func;
  54. hnd.type = rettype;
  55. str = zend_string_init_interned(name, strlen(name), 1);
  56. zend_hash_add_mem(prop_handler, str, &hnd, sizeof(xmlreader_prop_handler));
  57. zend_string_release_ex(str, 1);
  58. }
  59. /* }}} */
  60. /* {{{ xmlreader_property_reader */
  61. static int xmlreader_property_reader(xmlreader_object *obj, xmlreader_prop_handler *hnd, zval *rv)
  62. {
  63. const xmlChar *retchar = NULL;
  64. int retint = 0;
  65. if (obj->ptr != NULL) {
  66. if (hnd->read_char_func) {
  67. retchar = hnd->read_char_func(obj->ptr);
  68. } else {
  69. if (hnd->read_int_func) {
  70. retint = hnd->read_int_func(obj->ptr);
  71. if (retint == -1) {
  72. php_error_docref(NULL, E_WARNING, "Internal libxml error returned");
  73. return FAILURE;
  74. }
  75. }
  76. }
  77. }
  78. switch (hnd->type) {
  79. case IS_STRING:
  80. if (retchar) {
  81. ZVAL_STRING(rv, (char *) retchar);
  82. } else {
  83. ZVAL_EMPTY_STRING(rv);
  84. }
  85. break;
  86. /* this IS_FALSE actually means it's a BOOL type */
  87. case IS_FALSE:
  88. ZVAL_BOOL(rv, retint);
  89. break;
  90. case IS_LONG:
  91. ZVAL_LONG(rv, retint);
  92. break;
  93. default:
  94. ZVAL_NULL(rv);
  95. }
  96. return SUCCESS;
  97. }
  98. /* }}} */
  99. /* {{{ xmlreader_get_property_ptr_ptr */
  100. zval *xmlreader_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot)
  101. {
  102. xmlreader_object *obj;
  103. zval tmp_member;
  104. zval *retval = NULL;
  105. xmlreader_prop_handler *hnd = NULL;
  106. if (Z_TYPE_P(member) != IS_STRING) {
  107. ZVAL_STR(&tmp_member, zval_get_string_func(member));
  108. member = &tmp_member;
  109. }
  110. obj = Z_XMLREADER_P(object);
  111. if (obj->prop_handler != NULL) {
  112. hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
  113. }
  114. if (hnd == NULL) {
  115. retval = zend_std_get_property_ptr_ptr(object, member, type, cache_slot);
  116. }
  117. if (member == &tmp_member) {
  118. zval_ptr_dtor_str(&tmp_member);
  119. }
  120. return retval;
  121. }
  122. /* }}} */
  123. /* {{{ xmlreader_read_property */
  124. zval *xmlreader_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv)
  125. {
  126. xmlreader_object *obj;
  127. zval tmp_member;
  128. zval *retval = NULL;
  129. xmlreader_prop_handler *hnd = NULL;
  130. if (Z_TYPE_P(member) != IS_STRING) {
  131. ZVAL_STR(&tmp_member, zval_get_string_func(member));
  132. member = &tmp_member;
  133. }
  134. obj = Z_XMLREADER_P(object);
  135. if (obj->prop_handler != NULL) {
  136. hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
  137. }
  138. if (hnd != NULL) {
  139. if (xmlreader_property_reader(obj, hnd, rv) == FAILURE) {
  140. retval = &EG(uninitialized_zval);
  141. } else {
  142. retval = rv;
  143. }
  144. } else {
  145. retval = zend_std_read_property(object, member, type, cache_slot, rv);
  146. }
  147. if (member == &tmp_member) {
  148. zval_ptr_dtor_str(&tmp_member);
  149. }
  150. return retval;
  151. }
  152. /* }}} */
  153. /* {{{ xmlreader_write_property */
  154. void xmlreader_write_property(zval *object, zval *member, zval *value, void **cache_slot)
  155. {
  156. xmlreader_object *obj;
  157. zval tmp_member;
  158. xmlreader_prop_handler *hnd = NULL;
  159. if (Z_TYPE_P(member) != IS_STRING) {
  160. ZVAL_STR(&tmp_member, zval_get_string_func(member));
  161. member = &tmp_member;
  162. }
  163. obj = Z_XMLREADER_P(object);
  164. if (obj->prop_handler != NULL) {
  165. hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
  166. }
  167. if (hnd != NULL) {
  168. php_error_docref(NULL, E_WARNING, "Cannot write to read-only property");
  169. } else {
  170. zend_std_write_property(object, member, value, cache_slot);
  171. }
  172. if (member == &tmp_member) {
  173. zval_ptr_dtor_str(&tmp_member);
  174. }
  175. }
  176. /* }}} */
  177. /* {{{ _xmlreader_get_valid_file_path */
  178. /* _xmlreader_get_valid_file_path and _xmlreader_get_relaxNG should be made a
  179. common function in libxml extension as code is common to a few xml extensions */
  180. char *_xmlreader_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) {
  181. xmlURI *uri;
  182. xmlChar *escsource;
  183. char *file_dest;
  184. int isFileUri = 0;
  185. uri = xmlCreateURI();
  186. escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *)":");
  187. xmlParseURIReference(uri, (const char *)escsource);
  188. xmlFree(escsource);
  189. if (uri->scheme != NULL) {
  190. /* absolute file uris - libxml only supports localhost or empty host */
  191. if (strncasecmp(source, "file:///",8) == 0) {
  192. isFileUri = 1;
  193. #ifdef PHP_WIN32
  194. source += 8;
  195. #else
  196. source += 7;
  197. #endif
  198. } else if (strncasecmp(source, "file://localhost/",17) == 0) {
  199. isFileUri = 1;
  200. #ifdef PHP_WIN32
  201. source += 17;
  202. #else
  203. source += 16;
  204. #endif
  205. }
  206. }
  207. file_dest = source;
  208. if ((uri->scheme == NULL || isFileUri)) {
  209. if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) {
  210. xmlFreeURI(uri);
  211. return NULL;
  212. }
  213. file_dest = resolved_path;
  214. }
  215. xmlFreeURI(uri);
  216. return file_dest;
  217. }
  218. /* }}} */
  219. #ifdef LIBXML_SCHEMAS_ENABLED
  220. /* {{{ _xmlreader_get_relaxNG */
  221. static xmlRelaxNGPtr _xmlreader_get_relaxNG(char *source, size_t source_len, size_t type,
  222. xmlRelaxNGValidityErrorFunc error_func,
  223. xmlRelaxNGValidityWarningFunc warn_func)
  224. {
  225. char *valid_file = NULL;
  226. xmlRelaxNGParserCtxtPtr parser = NULL;
  227. xmlRelaxNGPtr sptr;
  228. char resolved_path[MAXPATHLEN + 1];
  229. switch (type) {
  230. case XMLREADER_LOAD_FILE:
  231. valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN );
  232. if (!valid_file) {
  233. return NULL;
  234. }
  235. parser = xmlRelaxNGNewParserCtxt(valid_file);
  236. break;
  237. case XMLREADER_LOAD_STRING:
  238. parser = xmlRelaxNGNewMemParserCtxt(source, source_len);
  239. /* If loading from memory, we need to set the base directory for the document
  240. but it is not apparent how to do that for schema's */
  241. break;
  242. default:
  243. return NULL;
  244. }
  245. if (parser == NULL) {
  246. return NULL;
  247. }
  248. if (error_func || warn_func) {
  249. xmlRelaxNGSetParserErrors(parser,
  250. (xmlRelaxNGValidityErrorFunc) error_func,
  251. (xmlRelaxNGValidityWarningFunc) warn_func,
  252. parser);
  253. }
  254. sptr = xmlRelaxNGParse(parser);
  255. xmlRelaxNGFreeParserCtxt(parser);
  256. return sptr;
  257. }
  258. /* }}} */
  259. #endif
  260. static const zend_module_dep xmlreader_deps[] = {
  261. ZEND_MOD_REQUIRED("libxml")
  262. ZEND_MOD_END
  263. };
  264. /* {{{ xmlreader_module_entry
  265. */
  266. zend_module_entry xmlreader_module_entry = {
  267. STANDARD_MODULE_HEADER_EX, NULL,
  268. xmlreader_deps,
  269. "xmlreader",
  270. NULL,
  271. PHP_MINIT(xmlreader),
  272. PHP_MSHUTDOWN(xmlreader),
  273. NULL,
  274. NULL,
  275. PHP_MINFO(xmlreader),
  276. PHP_XMLREADER_VERSION,
  277. STANDARD_MODULE_PROPERTIES
  278. };
  279. /* }}} */
  280. #ifdef COMPILE_DL_XMLREADER
  281. ZEND_GET_MODULE(xmlreader)
  282. #endif
  283. /* {{{ xmlreader_objects_clone */
  284. void xmlreader_objects_clone(void *object, void **object_clone)
  285. {
  286. /* TODO */
  287. }
  288. /* }}} */
  289. /* {{{ xmlreader_free_resources */
  290. static void xmlreader_free_resources(xmlreader_object *intern) {
  291. if (intern) {
  292. if (intern->input) {
  293. xmlFreeParserInputBuffer(intern->input);
  294. intern->input = NULL;
  295. }
  296. if (intern->ptr) {
  297. xmlFreeTextReader(intern->ptr);
  298. intern->ptr = NULL;
  299. }
  300. #ifdef LIBXML_SCHEMAS_ENABLED
  301. if (intern->schema) {
  302. xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema);
  303. intern->schema = NULL;
  304. }
  305. #endif
  306. }
  307. }
  308. /* }}} */
  309. /* {{{ xmlreader_objects_free_storage */
  310. void xmlreader_objects_free_storage(zend_object *object)
  311. {
  312. xmlreader_object *intern = php_xmlreader_fetch_object(object);
  313. zend_object_std_dtor(&intern->std);
  314. xmlreader_free_resources(intern);
  315. }
  316. /* }}} */
  317. /* {{{ xmlreader_objects_new */
  318. zend_object *xmlreader_objects_new(zend_class_entry *class_type)
  319. {
  320. xmlreader_object *intern;
  321. intern = zend_object_alloc(sizeof(xmlreader_object), class_type);
  322. zend_object_std_init(&intern->std, class_type);
  323. object_properties_init(&intern->std, class_type);
  324. intern->prop_handler = &xmlreader_prop_handlers;
  325. intern->std.handlers = &xmlreader_object_handlers;
  326. return &intern->std;
  327. }
  328. /* }}} */
  329. /* {{{ php_xmlreader_string_arg */
  330. static void php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_one_char_t internal_function) {
  331. zval *id;
  332. size_t name_len = 0;
  333. char *retchar = NULL;
  334. xmlreader_object *intern;
  335. char *name;
  336. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  337. return;
  338. }
  339. if (!name_len) {
  340. php_error_docref(NULL, E_WARNING, "Argument cannot be an empty string");
  341. RETURN_FALSE;
  342. }
  343. id = getThis();
  344. intern = Z_XMLREADER_P(id);
  345. if (intern && intern->ptr) {
  346. retchar = (char *)internal_function(intern->ptr, (const unsigned char *)name);
  347. }
  348. if (retchar) {
  349. RETVAL_STRING(retchar);
  350. xmlFree(retchar);
  351. return;
  352. } else {
  353. RETVAL_NULL();
  354. }
  355. }
  356. /* }}} */
  357. /* {{{ php_xmlreader_no_arg */
  358. static void php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_int_t internal_function) {
  359. zval *id;
  360. int retval;
  361. xmlreader_object *intern;
  362. id = getThis();
  363. intern = Z_XMLREADER_P(id);
  364. if (intern && intern->ptr) {
  365. retval = internal_function(intern->ptr);
  366. if (retval == 1) {
  367. RETURN_TRUE;
  368. }
  369. }
  370. RETURN_FALSE;
  371. }
  372. /* }}} */
  373. static void php_xmlreader_free_prop_handler(zval *el) /* {{{ */ {
  374. pefree(Z_PTR_P(el), 1);
  375. } /* }}} */
  376. #if LIBXML_VERSION >= 20620
  377. /* {{{ php_xmlreader_no_arg_string */
  378. static void php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_char_t internal_function) {
  379. zval *id;
  380. char *retchar = NULL;
  381. xmlreader_object *intern;
  382. id = getThis();
  383. intern = Z_XMLREADER_P(id);
  384. if (intern && intern->ptr) {
  385. retchar = (char *)internal_function(intern->ptr);
  386. }
  387. if (retchar) {
  388. RETVAL_STRING(retchar);
  389. xmlFree(retchar);
  390. return;
  391. } else {
  392. RETVAL_EMPTY_STRING();
  393. }
  394. }
  395. /* }}} */
  396. #endif
  397. /* {{{ php_xmlreader_set_relaxng_schema */
  398. static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int type) {
  399. #ifdef LIBXML_SCHEMAS_ENABLED
  400. zval *id;
  401. size_t source_len = 0;
  402. int retval = -1;
  403. xmlreader_object *intern;
  404. xmlRelaxNGPtr schema = NULL;
  405. char *source;
  406. if (zend_parse_parameters(ZEND_NUM_ARGS(), "p!", &source, &source_len) == FAILURE) {
  407. return;
  408. }
  409. if (source != NULL && !source_len) {
  410. php_error_docref(NULL, E_WARNING, "Schema data source is required");
  411. RETURN_FALSE;
  412. }
  413. id = getThis();
  414. intern = Z_XMLREADER_P(id);
  415. if (intern && intern->ptr) {
  416. if (source) {
  417. schema = _xmlreader_get_relaxNG(source, source_len, type, NULL, NULL);
  418. if (schema) {
  419. retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, schema);
  420. }
  421. } else {
  422. /* unset the associated relaxNG context and schema if one exists */
  423. retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, NULL);
  424. }
  425. if (retval == 0) {
  426. if (intern->schema) {
  427. xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema);
  428. }
  429. intern->schema = schema;
  430. RETURN_TRUE;
  431. }
  432. }
  433. php_error_docref(NULL, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors.");
  434. RETURN_FALSE;
  435. #else
  436. php_error_docref(NULL, E_WARNING, "No Schema support built into libxml.");
  437. RETURN_FALSE;
  438. #endif
  439. }
  440. /* }}} */
  441. /* {{{ proto bool XMLReader::close()
  442. Closes xmlreader - current frees resources until xmlTextReaderClose is fixed in libxml */
  443. PHP_METHOD(xmlreader, close)
  444. {
  445. zval *id;
  446. xmlreader_object *intern;
  447. id = getThis();
  448. intern = Z_XMLREADER_P(id);
  449. /* libxml is segfaulting in versions up to 2.6.8 using xmlTextReaderClose so for
  450. now we will free the whole reader when close is called as it would get rebuilt on
  451. a new load anyways */
  452. xmlreader_free_resources(intern);
  453. RETURN_TRUE;
  454. }
  455. /* }}} */
  456. /* {{{ proto string XMLReader::getAttribute(string name)
  457. Get value of an attribute from current element */
  458. PHP_METHOD(xmlreader, getAttribute)
  459. {
  460. php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderGetAttribute);
  461. }
  462. /* }}} */
  463. /* {{{ proto string XMLReader::getAttributeNo(int index)
  464. Get value of an attribute at index from current element */
  465. PHP_METHOD(xmlreader, getAttributeNo)
  466. {
  467. zval *id;
  468. zend_long attr_pos;
  469. char *retchar = NULL;
  470. xmlreader_object *intern;
  471. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &attr_pos) == FAILURE) {
  472. return;
  473. }
  474. id = getThis();
  475. intern = Z_XMLREADER_P(id);
  476. if (intern && intern->ptr) {
  477. retchar = (char *)xmlTextReaderGetAttributeNo(intern->ptr, attr_pos);
  478. }
  479. if (retchar) {
  480. RETVAL_STRING(retchar);
  481. xmlFree(retchar);
  482. }
  483. }
  484. /* }}} */
  485. /* {{{ proto string XMLReader::getAttributeNs(string name, string namespaceURI)
  486. Get value of a attribute via name and namespace from current element */
  487. PHP_METHOD(xmlreader, getAttributeNs)
  488. {
  489. zval *id;
  490. size_t name_len = 0, ns_uri_len = 0;
  491. xmlreader_object *intern;
  492. char *name, *ns_uri, *retchar = NULL;
  493. if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) {
  494. return;
  495. }
  496. if (name_len == 0 || ns_uri_len == 0) {
  497. php_error_docref(NULL, E_WARNING, "Attribute Name and Namespace URI cannot be empty");
  498. RETURN_FALSE;
  499. }
  500. id = getThis();
  501. intern = Z_XMLREADER_P(id);
  502. if (intern && intern->ptr) {
  503. retchar = (char *)xmlTextReaderGetAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri);
  504. }
  505. if (retchar) {
  506. RETVAL_STRING(retchar);
  507. xmlFree(retchar);
  508. }
  509. }
  510. /* }}} */
  511. /* {{{ proto bool XMLReader::getParserProperty(int property)
  512. Indicates whether given property (one of the parser option constants) is set or not on parser */
  513. PHP_METHOD(xmlreader, getParserProperty)
  514. {
  515. zval *id;
  516. zend_long property;
  517. int retval = -1;
  518. xmlreader_object *intern;
  519. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &property) == FAILURE) {
  520. return;
  521. }
  522. id = getThis();
  523. intern = Z_XMLREADER_P(id);
  524. if (intern && intern->ptr) {
  525. retval = xmlTextReaderGetParserProp(intern->ptr,property);
  526. }
  527. if (retval == -1) {
  528. php_error_docref(NULL, E_WARNING, "Invalid parser property");
  529. RETURN_FALSE;
  530. }
  531. RETURN_BOOL(retval);
  532. }
  533. /* }}} */
  534. /* {{{ proto bool XMLReader::isValid()
  535. Returns boolean indicating if parsed document is valid or not.
  536. Must set XMLREADER_LOADDTD or XMLREADER_VALIDATE parser option prior to the first call to read
  537. or this method will always return FALSE */
  538. PHP_METHOD(xmlreader, isValid)
  539. {
  540. php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderIsValid);
  541. }
  542. /* }}} */
  543. /* {{{ proto string XMLReader::lookupNamespace(string prefix)
  544. Return namespaceURI for associated prefix on current node */
  545. PHP_METHOD(xmlreader, lookupNamespace)
  546. {
  547. php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderLookupNamespace);
  548. }
  549. /* }}} */
  550. /* {{{ proto bool XMLReader::moveToAttribute(string name)
  551. Positions reader at specified attribute - Returns TRUE on success and FALSE on failure */
  552. PHP_METHOD(xmlreader, moveToAttribute)
  553. {
  554. zval *id;
  555. size_t name_len = 0;
  556. int retval;
  557. xmlreader_object *intern;
  558. char *name;
  559. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
  560. return;
  561. }
  562. if (name_len == 0) {
  563. php_error_docref(NULL, E_WARNING, "Attribute Name is required");
  564. RETURN_FALSE;
  565. }
  566. id = getThis();
  567. intern = Z_XMLREADER_P(id);
  568. if (intern && intern->ptr) {
  569. retval = xmlTextReaderMoveToAttribute(intern->ptr, (xmlChar *)name);
  570. if (retval == 1) {
  571. RETURN_TRUE;
  572. }
  573. }
  574. RETURN_FALSE;
  575. }
  576. /* }}} */
  577. /* {{{ proto bool XMLReader::moveToAttributeNo(int index)
  578. Positions reader at attribute at specified index.
  579. Returns TRUE on success and FALSE on failure */
  580. PHP_METHOD(xmlreader, moveToAttributeNo)
  581. {
  582. zval *id;
  583. zend_long attr_pos;
  584. int retval;
  585. xmlreader_object *intern;
  586. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &attr_pos) == FAILURE) {
  587. return;
  588. }
  589. id = getThis();
  590. intern = Z_XMLREADER_P(id);
  591. if (intern && intern->ptr) {
  592. retval = xmlTextReaderMoveToAttributeNo(intern->ptr, attr_pos);
  593. if (retval == 1) {
  594. RETURN_TRUE;
  595. }
  596. }
  597. RETURN_FALSE;
  598. }
  599. /* }}} */
  600. /* {{{ proto bool XMLReader::moveToAttributeNs(string name, string namespaceURI)
  601. Positions reader at attribute spcified by name and namespaceURI.
  602. Returns TRUE on success and FALSE on failure */
  603. PHP_METHOD(xmlreader, moveToAttributeNs)
  604. {
  605. zval *id;
  606. size_t name_len=0, ns_uri_len=0;
  607. int retval;
  608. xmlreader_object *intern;
  609. char *name, *ns_uri;
  610. if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) {
  611. return;
  612. }
  613. if (name_len == 0 || ns_uri_len == 0) {
  614. php_error_docref(NULL, E_WARNING, "Attribute Name and Namespace URI cannot be empty");
  615. RETURN_FALSE;
  616. }
  617. id = getThis();
  618. intern = Z_XMLREADER_P(id);
  619. if (intern && intern->ptr) {
  620. retval = xmlTextReaderMoveToAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri);
  621. if (retval == 1) {
  622. RETURN_TRUE;
  623. }
  624. }
  625. RETURN_FALSE;
  626. }
  627. /* }}} */
  628. /* {{{ proto bool XMLReader::moveToElement()
  629. Moves the position of the current instance to the node that contains the current Attribute node. */
  630. PHP_METHOD(xmlreader, moveToElement)
  631. {
  632. php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToElement);
  633. }
  634. /* }}} */
  635. /* {{{ proto bool XMLReader::moveToFirstAttribute()
  636. Moves the position of the current instance to the first attribute associated with the current node. */
  637. PHP_METHOD(xmlreader, moveToFirstAttribute)
  638. {
  639. php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToFirstAttribute);
  640. }
  641. /* }}} */
  642. /* {{{ proto bool XMLReader::moveToNextAttribute()
  643. Moves the position of the current instance to the next attribute associated with the current node. */
  644. PHP_METHOD(xmlreader, moveToNextAttribute)
  645. {
  646. php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToNextAttribute);
  647. }
  648. /* }}} */
  649. /* {{{ proto bool XMLReader::read()
  650. Moves the position of the current instance to the next node in the stream. */
  651. PHP_METHOD(xmlreader, read)
  652. {
  653. zval *id;
  654. int retval;
  655. xmlreader_object *intern;
  656. id = getThis();
  657. intern = Z_XMLREADER_P(id);
  658. if (intern != NULL && intern->ptr != NULL) {
  659. retval = xmlTextReaderRead(intern->ptr);
  660. if (retval == -1) {
  661. RETURN_FALSE;
  662. } else {
  663. RETURN_BOOL(retval);
  664. }
  665. }
  666. php_error_docref(NULL, E_WARNING, "Load Data before trying to read");
  667. RETURN_FALSE;
  668. }
  669. /* }}} */
  670. /* {{{ proto bool XMLReader::next([string localname])
  671. Moves the position of the current instance to the next node in the stream. */
  672. PHP_METHOD(xmlreader, next)
  673. {
  674. zval *id;
  675. int retval;
  676. size_t name_len=0;
  677. xmlreader_object *intern;
  678. char *name = NULL;
  679. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &name, &name_len) == FAILURE) {
  680. return;
  681. }
  682. id = getThis();
  683. intern = Z_XMLREADER_P(id);
  684. if (intern != NULL && intern->ptr != NULL) {
  685. #if LIBXML_VERSION <= 20617
  686. /* Bug in libxml prevents a next in certain cases when positioned on end of element */
  687. if (xmlTextReaderNodeType(intern->ptr) == XML_READER_TYPE_END_ELEMENT) {
  688. retval = xmlTextReaderRead(intern->ptr);
  689. } else
  690. #endif
  691. retval = xmlTextReaderNext(intern->ptr);
  692. while (name != NULL && retval == 1) {
  693. if (xmlStrEqual(xmlTextReaderConstLocalName(intern->ptr), (xmlChar *)name)) {
  694. RETURN_TRUE;
  695. }
  696. retval = xmlTextReaderNext(intern->ptr);
  697. }
  698. if (retval == -1) {
  699. RETURN_FALSE;
  700. } else {
  701. RETURN_BOOL(retval);
  702. }
  703. }
  704. php_error_docref(NULL, E_WARNING, "Load Data before trying to read");
  705. RETURN_FALSE;
  706. }
  707. /* }}} */
  708. /* {{{ proto bool XMLReader::open(string URI [, string encoding [, int options]])
  709. Sets the URI that the XMLReader will parse. */
  710. PHP_METHOD(xmlreader, open)
  711. {
  712. zval *id;
  713. size_t source_len = 0, encoding_len = 0;
  714. zend_long options = 0;
  715. xmlreader_object *intern = NULL;
  716. char *source, *valid_file = NULL;
  717. char *encoding = NULL;
  718. char resolved_path[MAXPATHLEN + 1];
  719. xmlTextReaderPtr reader = NULL;
  720. if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
  721. return;
  722. }
  723. id = getThis();
  724. if (id != NULL) {
  725. if (! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry)) {
  726. id = NULL;
  727. } else {
  728. intern = Z_XMLREADER_P(id);
  729. xmlreader_free_resources(intern);
  730. }
  731. }
  732. if (!source_len) {
  733. php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
  734. RETURN_FALSE;
  735. }
  736. valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN );
  737. if (valid_file) {
  738. reader = xmlReaderForFile(valid_file, encoding, options);
  739. }
  740. if (reader == NULL) {
  741. php_error_docref(NULL, E_WARNING, "Unable to open source data");
  742. RETURN_FALSE;
  743. }
  744. if (id == NULL) {
  745. object_init_ex(return_value, xmlreader_class_entry);
  746. intern = Z_XMLREADER_P(return_value);
  747. intern->ptr = reader;
  748. return;
  749. }
  750. intern->ptr = reader;
  751. RETURN_TRUE;
  752. }
  753. /* }}} */
  754. /* Not Yet Implemented in libxml - functions exist just not coded
  755. PHP_METHOD(xmlreader, resetState)
  756. {
  757. }
  758. */
  759. #if LIBXML_VERSION >= 20620
  760. /* {{{ proto string XMLReader::readInnerXml()
  761. Reads the contents of the current node, including child nodes and markup. */
  762. PHP_METHOD(xmlreader, readInnerXml)
  763. {
  764. php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadInnerXml);
  765. }
  766. /* }}} */
  767. /* {{{ proto bool XMLReader::readOuterXml()
  768. Reads the contents of the current node, including child nodes and markup. */
  769. PHP_METHOD(xmlreader, readOuterXml)
  770. {
  771. php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadOuterXml);
  772. }
  773. /* }}} */
  774. /* {{{ proto bool XMLReader::readString()
  775. Reads the contents of an element or a text node as a string. */
  776. PHP_METHOD(xmlreader, readString)
  777. {
  778. php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadString);
  779. }
  780. /* }}} */
  781. /* {{{ proto bool XMLReader::setSchema(string filename)
  782. Use W3C XSD schema to validate the document as it is processed. Activation is only possible before the first Read(). */
  783. PHP_METHOD(xmlreader, setSchema)
  784. {
  785. #ifdef LIBXML_SCHEMAS_ENABLED
  786. zval *id;
  787. size_t source_len = 0;
  788. int retval = -1;
  789. xmlreader_object *intern;
  790. char *source;
  791. if (zend_parse_parameters(ZEND_NUM_ARGS(), "p!", &source, &source_len) == FAILURE) {
  792. return;
  793. }
  794. if (source != NULL && !source_len) {
  795. php_error_docref(NULL, E_WARNING, "Schema data source is required");
  796. RETURN_FALSE;
  797. }
  798. id = getThis();
  799. intern = Z_XMLREADER_P(id);
  800. if (intern && intern->ptr) {
  801. retval = xmlTextReaderSchemaValidate(intern->ptr, source);
  802. if (retval == 0) {
  803. RETURN_TRUE;
  804. }
  805. }
  806. php_error_docref(NULL, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors.");
  807. RETURN_FALSE;
  808. #else
  809. php_error_docref(NULL, E_WARNING, "No Schema support built into libxml.");
  810. RETURN_FALSE;
  811. #endif
  812. }
  813. /* }}} */
  814. #endif
  815. /* {{{ proto bool XMLReader::setParserProperty(int property, bool value)
  816. Sets parser property (one of the parser option constants).
  817. Properties must be set after open() or XML() and before the first read() is called */
  818. PHP_METHOD(xmlreader, setParserProperty)
  819. {
  820. zval *id;
  821. zend_long property;
  822. int retval = -1;
  823. zend_bool value;
  824. xmlreader_object *intern;
  825. if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &property, &value) == FAILURE) {
  826. return;
  827. }
  828. id = getThis();
  829. intern = Z_XMLREADER_P(id);
  830. if (intern && intern->ptr) {
  831. retval = xmlTextReaderSetParserProp(intern->ptr,property, value);
  832. }
  833. if (retval == -1) {
  834. php_error_docref(NULL, E_WARNING, "Invalid parser property");
  835. RETURN_FALSE;
  836. }
  837. RETURN_TRUE;
  838. }
  839. /* }}} */
  840. /* {{{ proto bool XMLReader::setRelaxNGSchema(string filename)
  841. Sets the string that the XMLReader will parse. */
  842. PHP_METHOD(xmlreader, setRelaxNGSchema)
  843. {
  844. php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAM_PASSTHRU, XMLREADER_LOAD_FILE);
  845. }
  846. /* }}} */
  847. /* {{{ proto bool XMLReader::setRelaxNGSchemaSource(string source)
  848. Sets the string that the XMLReader will parse. */
  849. PHP_METHOD(xmlreader, setRelaxNGSchemaSource)
  850. {
  851. php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAM_PASSTHRU, XMLREADER_LOAD_STRING);
  852. }
  853. /* }}} */
  854. /* TODO
  855. XMLPUBFUN int XMLCALL
  856. xmlTextReaderSetSchema (xmlTextReaderPtr reader,
  857. xmlSchemaPtr schema);
  858. */
  859. /* {{{ proto bool XMLReader::XML(string source [, string encoding [, int options]])
  860. Sets the string that the XMLReader will parse. */
  861. PHP_METHOD(xmlreader, XML)
  862. {
  863. zval *id;
  864. size_t source_len = 0, encoding_len = 0;
  865. zend_long options = 0;
  866. xmlreader_object *intern = NULL;
  867. char *source, *uri = NULL, *encoding = NULL;
  868. int resolved_path_len, ret = 0;
  869. char *directory=NULL, resolved_path[MAXPATHLEN];
  870. xmlParserInputBufferPtr inputbfr;
  871. xmlTextReaderPtr reader;
  872. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
  873. return;
  874. }
  875. id = getThis();
  876. if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry)) {
  877. id = NULL;
  878. }
  879. if (id != NULL) {
  880. intern = Z_XMLREADER_P(id);
  881. xmlreader_free_resources(intern);
  882. }
  883. if (!source_len) {
  884. php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
  885. RETURN_FALSE;
  886. }
  887. inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE);
  888. if (inputbfr != NULL) {
  889. /* Get the URI of the current script so that we can set the base directory in libxml */
  890. #if HAVE_GETCWD
  891. directory = VCWD_GETCWD(resolved_path, MAXPATHLEN);
  892. #elif HAVE_GETWD
  893. directory = VCWD_GETWD(resolved_path);
  894. #endif
  895. if (directory) {
  896. resolved_path_len = strlen(resolved_path);
  897. if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) {
  898. resolved_path[resolved_path_len] = DEFAULT_SLASH;
  899. resolved_path[++resolved_path_len] = '\0';
  900. }
  901. uri = (char *) xmlCanonicPath((const xmlChar *) resolved_path);
  902. }
  903. reader = xmlNewTextReader(inputbfr, uri);
  904. if (reader != NULL) {
  905. #if LIBXML_VERSION >= 20628
  906. ret = xmlTextReaderSetup(reader, NULL, uri, encoding, options);
  907. #endif
  908. if (ret == 0) {
  909. if (id == NULL) {
  910. object_init_ex(return_value, xmlreader_class_entry);
  911. intern = Z_XMLREADER_P(return_value);
  912. } else {
  913. RETVAL_TRUE;
  914. }
  915. intern->input = inputbfr;
  916. intern->ptr = reader;
  917. if (uri) {
  918. xmlFree(uri);
  919. }
  920. return;
  921. }
  922. }
  923. }
  924. if (uri) {
  925. xmlFree(uri);
  926. }
  927. if (inputbfr) {
  928. xmlFreeParserInputBuffer(inputbfr);
  929. }
  930. php_error_docref(NULL, E_WARNING, "Unable to load source data");
  931. RETURN_FALSE;
  932. }
  933. /* }}} */
  934. /* {{{ proto bool XMLReader::expand()
  935. Moves the position of the current instance to the next node in the stream. */
  936. PHP_METHOD(xmlreader, expand)
  937. {
  938. #ifdef HAVE_DOM
  939. zval *id, *basenode = NULL;
  940. int ret;
  941. xmlreader_object *intern;
  942. xmlNode *node, *nodec;
  943. xmlDocPtr docp = NULL;
  944. php_libxml_node_object *domobj = NULL;
  945. if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!", &id, xmlreader_class_entry, &basenode, dom_node_class_entry) == FAILURE) {
  946. return;
  947. }
  948. if (basenode != NULL) {
  949. NODE_GET_OBJ(node, basenode, xmlNodePtr, domobj);
  950. docp = node->doc;
  951. }
  952. intern = Z_XMLREADER_P(id);
  953. if (intern && intern->ptr) {
  954. node = xmlTextReaderExpand(intern->ptr);
  955. if (node == NULL) {
  956. php_error_docref(NULL, E_WARNING, "An Error Occurred while expanding ");
  957. RETURN_FALSE;
  958. } else {
  959. nodec = xmlDocCopyNode(node, docp, 1);
  960. if (nodec == NULL) {
  961. php_error_docref(NULL, E_NOTICE, "Cannot expand this node type");
  962. RETURN_FALSE;
  963. } else {
  964. DOM_RET_OBJ(nodec, &ret, (dom_object *)domobj);
  965. }
  966. }
  967. } else {
  968. php_error_docref(NULL, E_WARNING, "Load Data before trying to expand");
  969. RETURN_FALSE;
  970. }
  971. #else
  972. php_error(E_WARNING, "DOM support is not enabled");
  973. return;
  974. #endif
  975. }
  976. /* }}} */
  977. /* {{{ arginfo */
  978. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_close, 0)
  979. ZEND_END_ARG_INFO()
  980. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttribute, 0)
  981. ZEND_ARG_INFO(0, name)
  982. ZEND_END_ARG_INFO()
  983. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttributeNo, 0)
  984. ZEND_ARG_INFO(0, index)
  985. ZEND_END_ARG_INFO()
  986. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttributeNs, 0)
  987. ZEND_ARG_INFO(0, name)
  988. ZEND_ARG_INFO(0, namespaceURI)
  989. ZEND_END_ARG_INFO()
  990. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getParserProperty, 0)
  991. ZEND_ARG_INFO(0, property)
  992. ZEND_END_ARG_INFO()
  993. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_isValid, 0)
  994. ZEND_END_ARG_INFO()
  995. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_lookupNamespace, 0)
  996. ZEND_ARG_INFO(0, prefix)
  997. ZEND_END_ARG_INFO()
  998. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttribute, 0)
  999. ZEND_ARG_INFO(0, name)
  1000. ZEND_END_ARG_INFO()
  1001. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttributeNo, 0)
  1002. ZEND_ARG_INFO(0, index)
  1003. ZEND_END_ARG_INFO()
  1004. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttributeNs, 0)
  1005. ZEND_ARG_INFO(0, name)
  1006. ZEND_ARG_INFO(0, namespaceURI)
  1007. ZEND_END_ARG_INFO()
  1008. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToElement, 0)
  1009. ZEND_END_ARG_INFO()
  1010. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToFirstAttribute, 0)
  1011. ZEND_END_ARG_INFO()
  1012. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToNextAttribute, 0)
  1013. ZEND_END_ARG_INFO()
  1014. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_read, 0)
  1015. ZEND_END_ARG_INFO()
  1016. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_next, 0, 0, 0)
  1017. ZEND_ARG_INFO(0, localname)
  1018. ZEND_END_ARG_INFO()
  1019. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_open, 0, 0, 1)
  1020. ZEND_ARG_INFO(0, URI)
  1021. ZEND_ARG_INFO(0, encoding)
  1022. ZEND_ARG_INFO(0, options)
  1023. ZEND_END_ARG_INFO()
  1024. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readInnerXml, 0)
  1025. ZEND_END_ARG_INFO()
  1026. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readOuterXml, 0)
  1027. ZEND_END_ARG_INFO()
  1028. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readString, 0)
  1029. ZEND_END_ARG_INFO()
  1030. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setSchema, 0)
  1031. ZEND_ARG_INFO(0, filename)
  1032. ZEND_END_ARG_INFO()
  1033. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setParserProperty, 0)
  1034. ZEND_ARG_INFO(0, property)
  1035. ZEND_ARG_INFO(0, value)
  1036. ZEND_END_ARG_INFO()
  1037. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setRelaxNGSchema, 0)
  1038. ZEND_ARG_INFO(0, filename)
  1039. ZEND_END_ARG_INFO()
  1040. ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setRelaxNGSchemaSource, 0)
  1041. ZEND_ARG_INFO(0, source)
  1042. ZEND_END_ARG_INFO()
  1043. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_XML, 0, 0, 1)
  1044. ZEND_ARG_INFO(0, source)
  1045. ZEND_ARG_INFO(0, encoding)
  1046. ZEND_ARG_INFO(0, options)
  1047. ZEND_END_ARG_INFO()
  1048. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_expand, 0, 0, 0)
  1049. ZEND_ARG_INFO(0, basenode)
  1050. ZEND_END_ARG_INFO()
  1051. /* }}} */
  1052. static const zend_function_entry xmlreader_functions[] /* {{{ */ = {
  1053. PHP_ME(xmlreader, close, arginfo_xmlreader_close, ZEND_ACC_PUBLIC)
  1054. PHP_ME(xmlreader, getAttribute, arginfo_xmlreader_getAttribute, ZEND_ACC_PUBLIC)
  1055. PHP_ME(xmlreader, getAttributeNo, arginfo_xmlreader_getAttributeNo, ZEND_ACC_PUBLIC)
  1056. PHP_ME(xmlreader, getAttributeNs, arginfo_xmlreader_getAttributeNs, ZEND_ACC_PUBLIC)
  1057. PHP_ME(xmlreader, getParserProperty, arginfo_xmlreader_getParserProperty, ZEND_ACC_PUBLIC)
  1058. PHP_ME(xmlreader, isValid, arginfo_xmlreader_isValid, ZEND_ACC_PUBLIC)
  1059. PHP_ME(xmlreader, lookupNamespace, arginfo_xmlreader_lookupNamespace, ZEND_ACC_PUBLIC)
  1060. PHP_ME(xmlreader, moveToAttributeNo, arginfo_xmlreader_moveToAttributeNo, ZEND_ACC_PUBLIC)
  1061. PHP_ME(xmlreader, moveToAttribute, arginfo_xmlreader_moveToAttribute, ZEND_ACC_PUBLIC)
  1062. PHP_ME(xmlreader, moveToAttributeNs, arginfo_xmlreader_moveToAttributeNs, ZEND_ACC_PUBLIC)
  1063. PHP_ME(xmlreader, moveToElement, arginfo_xmlreader_moveToElement, ZEND_ACC_PUBLIC)
  1064. PHP_ME(xmlreader, moveToFirstAttribute, arginfo_xmlreader_moveToFirstAttribute, ZEND_ACC_PUBLIC)
  1065. PHP_ME(xmlreader, moveToNextAttribute, arginfo_xmlreader_moveToNextAttribute, ZEND_ACC_PUBLIC)
  1066. PHP_ME(xmlreader, open, arginfo_xmlreader_open, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
  1067. PHP_ME(xmlreader, read, arginfo_xmlreader_read, ZEND_ACC_PUBLIC)
  1068. PHP_ME(xmlreader, next, arginfo_xmlreader_next, ZEND_ACC_PUBLIC)
  1069. #if LIBXML_VERSION >= 20620
  1070. PHP_ME(xmlreader, readInnerXml, arginfo_xmlreader_readInnerXml, ZEND_ACC_PUBLIC)
  1071. PHP_ME(xmlreader, readOuterXml, arginfo_xmlreader_readOuterXml, ZEND_ACC_PUBLIC)
  1072. PHP_ME(xmlreader, readString, arginfo_xmlreader_readString, ZEND_ACC_PUBLIC)
  1073. PHP_ME(xmlreader, setSchema, arginfo_xmlreader_setSchema, ZEND_ACC_PUBLIC)
  1074. #endif
  1075. /* Not Yet Implemented though defined in libxml as of 2.6.9dev
  1076. PHP_ME(xmlreader, resetState, NULL, ZEND_ACC_PUBLIC)
  1077. */
  1078. PHP_ME(xmlreader, setParserProperty, arginfo_xmlreader_setParserProperty, ZEND_ACC_PUBLIC)
  1079. PHP_ME(xmlreader, setRelaxNGSchema, arginfo_xmlreader_setRelaxNGSchema, ZEND_ACC_PUBLIC)
  1080. PHP_ME(xmlreader, setRelaxNGSchemaSource, arginfo_xmlreader_setRelaxNGSchemaSource, ZEND_ACC_PUBLIC)
  1081. PHP_ME(xmlreader, XML, arginfo_xmlreader_XML, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
  1082. PHP_ME(xmlreader, expand, arginfo_xmlreader_expand, ZEND_ACC_PUBLIC)
  1083. PHP_FE_END
  1084. }; /* }}} */
  1085. /* {{{ PHP_MINIT_FUNCTION
  1086. */
  1087. PHP_MINIT_FUNCTION(xmlreader)
  1088. {
  1089. zend_class_entry ce;
  1090. memcpy(&xmlreader_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
  1091. xmlreader_object_handlers.offset = XtOffsetOf(xmlreader_object, std);
  1092. xmlreader_object_handlers.dtor_obj = zend_objects_destroy_object;
  1093. xmlreader_object_handlers.free_obj = xmlreader_objects_free_storage;
  1094. xmlreader_object_handlers.read_property = xmlreader_read_property;
  1095. xmlreader_object_handlers.write_property = xmlreader_write_property;
  1096. xmlreader_object_handlers.get_property_ptr_ptr = xmlreader_get_property_ptr_ptr;
  1097. xmlreader_object_handlers.clone_obj = NULL;
  1098. INIT_CLASS_ENTRY(ce, "XMLReader", xmlreader_functions);
  1099. ce.create_object = xmlreader_objects_new;
  1100. xmlreader_class_entry = zend_register_internal_class(&ce);
  1101. zend_hash_init(&xmlreader_prop_handlers, 0, NULL, php_xmlreader_free_prop_handler, 1);
  1102. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "attributeCount", xmlTextReaderAttributeCount, NULL, IS_LONG);
  1103. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "baseURI", NULL, xmlTextReaderConstBaseUri, IS_STRING);
  1104. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "depth", xmlTextReaderDepth, NULL, IS_LONG);
  1105. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasAttributes", xmlTextReaderHasAttributes, NULL, IS_FALSE);
  1106. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasValue", xmlTextReaderHasValue, NULL, IS_FALSE);
  1107. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isDefault", xmlTextReaderIsDefault, NULL, IS_FALSE);
  1108. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isEmptyElement", xmlTextReaderIsEmptyElement, NULL, IS_FALSE);
  1109. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "localName", NULL, xmlTextReaderConstLocalName, IS_STRING);
  1110. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "name", NULL, xmlTextReaderConstName, IS_STRING);
  1111. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "namespaceURI", NULL, xmlTextReaderConstNamespaceUri, IS_STRING);
  1112. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "nodeType", xmlTextReaderNodeType, NULL, IS_LONG);
  1113. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "prefix", NULL, xmlTextReaderConstPrefix, IS_STRING);
  1114. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "value", NULL, xmlTextReaderConstValue, IS_STRING);
  1115. xmlreader_register_prop_handler(&xmlreader_prop_handlers, "xmlLang", NULL, xmlTextReaderConstXmlLang, IS_STRING);
  1116. /* Constants for NodeType - cannot define common types to share with dom as there are differences in these types */
  1117. REGISTER_XMLREADER_CLASS_CONST_LONG("NONE", XML_READER_TYPE_NONE);
  1118. REGISTER_XMLREADER_CLASS_CONST_LONG("ELEMENT", XML_READER_TYPE_ELEMENT);
  1119. REGISTER_XMLREADER_CLASS_CONST_LONG("ATTRIBUTE", XML_READER_TYPE_ATTRIBUTE);
  1120. REGISTER_XMLREADER_CLASS_CONST_LONG("TEXT", XML_READER_TYPE_TEXT);
  1121. REGISTER_XMLREADER_CLASS_CONST_LONG("CDATA", XML_READER_TYPE_CDATA);
  1122. REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY_REF", XML_READER_TYPE_ENTITY_REFERENCE);
  1123. REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY", XML_READER_TYPE_ENTITY);
  1124. REGISTER_XMLREADER_CLASS_CONST_LONG("PI", XML_READER_TYPE_PROCESSING_INSTRUCTION);
  1125. REGISTER_XMLREADER_CLASS_CONST_LONG("COMMENT", XML_READER_TYPE_COMMENT);
  1126. REGISTER_XMLREADER_CLASS_CONST_LONG("DOC", XML_READER_TYPE_DOCUMENT);
  1127. REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_TYPE", XML_READER_TYPE_DOCUMENT_TYPE);
  1128. REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_FRAGMENT", XML_READER_TYPE_DOCUMENT_FRAGMENT);
  1129. REGISTER_XMLREADER_CLASS_CONST_LONG("NOTATION", XML_READER_TYPE_NOTATION);
  1130. REGISTER_XMLREADER_CLASS_CONST_LONG("WHITESPACE", XML_READER_TYPE_WHITESPACE);
  1131. REGISTER_XMLREADER_CLASS_CONST_LONG("SIGNIFICANT_WHITESPACE", XML_READER_TYPE_SIGNIFICANT_WHITESPACE);
  1132. REGISTER_XMLREADER_CLASS_CONST_LONG("END_ELEMENT", XML_READER_TYPE_END_ELEMENT);
  1133. REGISTER_XMLREADER_CLASS_CONST_LONG("END_ENTITY", XML_READER_TYPE_END_ENTITY);
  1134. REGISTER_XMLREADER_CLASS_CONST_LONG("XML_DECLARATION", XML_READER_TYPE_XML_DECLARATION);
  1135. /* Constants for Parser options */
  1136. REGISTER_XMLREADER_CLASS_CONST_LONG("LOADDTD", XML_PARSER_LOADDTD);
  1137. REGISTER_XMLREADER_CLASS_CONST_LONG("DEFAULTATTRS", XML_PARSER_DEFAULTATTRS);
  1138. REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDATE", XML_PARSER_VALIDATE);
  1139. REGISTER_XMLREADER_CLASS_CONST_LONG("SUBST_ENTITIES", XML_PARSER_SUBST_ENTITIES);
  1140. /* Constants for Errors when loading - not yet used until we implement custom error handling
  1141. REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_WARNING", XML_PARSER_SEVERITY_VALIDITY_WARNING, CONST_CS | CONST_PERSISTENT);
  1142. REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_ERROR", XML_PARSER_SEVERITY_VALIDITY_ERROR, CONST_CS | CONST_PERSISTENT);
  1143. REGISTER_XMLREADER_CLASS_CONST_LONG("WARNING", XML_PARSER_SEVERITY_WARNING, CONST_CS | CONST_PERSISTENT);
  1144. REGISTER_XMLREADER_CLASS_CONST_LONG("ERROR", XML_PARSER_SEVERITY_ERROR, CONST_CS | CONST_PERSISTENT);
  1145. */
  1146. return SUCCESS;
  1147. }
  1148. /* }}} */
  1149. /* {{{ PHP_MSHUTDOWN_FUNCTION
  1150. */
  1151. PHP_MSHUTDOWN_FUNCTION(xmlreader)
  1152. {
  1153. zend_hash_destroy(&xmlreader_prop_handlers);
  1154. return SUCCESS;
  1155. }
  1156. /* }}} */
  1157. /* {{{ PHP_MINFO_FUNCTION
  1158. */
  1159. PHP_MINFO_FUNCTION(xmlreader)
  1160. {
  1161. php_info_print_table_start();
  1162. {
  1163. php_info_print_table_row(2, "XMLReader", "enabled");
  1164. }
  1165. php_info_print_table_end();
  1166. }
  1167. /* }}} */
  1168. /*
  1169. * Local variables:
  1170. * tab-width: 4
  1171. * c-basic-offset: 4
  1172. * End:
  1173. * vim600: noet sw=4 ts=4 fdm=marker
  1174. * vim<600: noet sw=4 ts=4
  1175. */