PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/xmlreader - php_xmlreader.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 402 532 75.6 %
Date: 2014-10-30 Functions: 38 44 86.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Thu, 30 Oct 2014 07:41:43 +0000 (29 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.