Back to index

php5  5.3.10
php_xmlreader.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Rob Richards <rrichards@php.net>                             |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_xmlreader.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "config.h"
00023 #endif
00024 
00025 
00026 #include "php.h"
00027 #include "php_ini.h"
00028 #include "ext/standard/info.h"
00029 #include "php_xmlreader.h"
00030 #ifdef HAVE_DOM
00031 #include "ext/dom/xml_common.h"
00032 #endif
00033 #include <libxml/uri.h>
00034 
00035 zend_class_entry *xmlreader_class_entry;
00036 
00037 static zend_object_handlers xmlreader_object_handlers;
00038 
00039 static HashTable xmlreader_prop_handlers;
00040 
00041 typedef int (*xmlreader_read_int_t)(xmlTextReaderPtr reader);
00042 typedef unsigned char *(*xmlreader_read_char_t)(xmlTextReaderPtr reader);
00043 typedef const unsigned char *(*xmlreader_read_const_char_t)(xmlTextReaderPtr reader);
00044 typedef int (*xmlreader_write_t)(xmlreader_object *obj, zval *newval TSRMLS_DC);
00045 
00046 typedef unsigned char *(*xmlreader_read_one_char_t)(xmlTextReaderPtr reader, const unsigned char *);
00047 
00048 typedef struct _xmlreader_prop_handler {
00049        xmlreader_read_int_t read_int_func;
00050        xmlreader_read_const_char_t read_char_func;
00051        xmlreader_write_t write_func;
00052        int type;
00053 } xmlreader_prop_handler;
00054 
00055 #define XMLREADER_LOAD_STRING 0
00056 #define XMLREADER_LOAD_FILE 1
00057 
00058 /* {{{ xmlreader_register_prop_handler */
00059 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)
00060 {
00061        xmlreader_prop_handler hnd;
00062        
00063        hnd.read_char_func = read_char_func;
00064        hnd.read_int_func = read_int_func;
00065        hnd.type = rettype;
00066        zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(xmlreader_prop_handler), NULL);
00067 }
00068 /* }}} */
00069 
00070 /* {{{ xmlreader_property_reader */
00071 static int xmlreader_property_reader(xmlreader_object *obj, xmlreader_prop_handler *hnd, zval **retval TSRMLS_DC)
00072 {
00073        const xmlChar *retchar = NULL;
00074        int retint = 0;
00075 
00076        if (obj->ptr != NULL) {
00077               if (hnd->read_char_func) {
00078                      retchar = hnd->read_char_func(obj->ptr);
00079               } else {
00080                      if (hnd->read_int_func) {
00081                             retint = hnd->read_int_func(obj->ptr);
00082                             if (retint == -1) {
00083                                    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal libxml error returned");
00084                                    return FAILURE;
00085                             }
00086                      }
00087               }
00088        }
00089 
00090        ALLOC_ZVAL(*retval);
00091 
00092        switch (hnd->type) {
00093               case IS_STRING:
00094                      if (retchar) {
00095                             ZVAL_STRING(*retval, (char *) retchar, 1);
00096                      } else {
00097                             ZVAL_EMPTY_STRING(*retval);
00098                      }
00099                      break;
00100               case IS_BOOL:
00101                      ZVAL_BOOL(*retval, retint);
00102                      break;
00103               case IS_LONG:
00104                      ZVAL_LONG(*retval, retint);
00105                      break;
00106               default:
00107                      ZVAL_NULL(*retval);
00108        }
00109 
00110        return SUCCESS;
00111 }
00112 /* }}} */
00113 
00114 /* {{{ xmlreader_get_property_ptr_ptr */
00115 zval **xmlreader_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC)
00116 {
00117        xmlreader_object *obj;
00118        zval tmp_member;
00119        zval **retval = NULL;
00120        xmlreader_prop_handler *hnd;
00121        zend_object_handlers *std_hnd;
00122        int ret = FAILURE;
00123 
00124        if (member->type != IS_STRING) {
00125               tmp_member = *member;
00126               zval_copy_ctor(&tmp_member);
00127               convert_to_string(&tmp_member);
00128               member = &tmp_member;
00129        }
00130 
00131        obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC);
00132 
00133        if (obj->prop_handler != NULL) {
00134               ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00135        }
00136        if (ret == FAILURE) {
00137               std_hnd = zend_get_std_object_handlers();
00138               retval = std_hnd->get_property_ptr_ptr(object, member TSRMLS_CC);
00139        }
00140 
00141        if (member == &tmp_member) {
00142               zval_dtor(member);
00143        }
00144        return retval;
00145 }
00146 /* }}} */
00147 
00148 /* {{{ xmlreader_read_property */
00149 zval *xmlreader_read_property(zval *object, zval *member, int type TSRMLS_DC)
00150 {
00151        xmlreader_object *obj;
00152        zval tmp_member;
00153        zval *retval;
00154        xmlreader_prop_handler *hnd;
00155        zend_object_handlers *std_hnd;
00156        int ret;
00157 
00158        if (member->type != IS_STRING) {
00159               tmp_member = *member;
00160               zval_copy_ctor(&tmp_member);
00161               convert_to_string(&tmp_member);
00162               member = &tmp_member;
00163        }
00164 
00165        ret = FAILURE;
00166        obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC);
00167 
00168        if (obj->prop_handler != NULL) {
00169               ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00170        }
00171        if (ret == SUCCESS) {
00172               ret = xmlreader_property_reader(obj, hnd, &retval TSRMLS_CC);
00173               if (ret == SUCCESS) {
00174                      /* ensure we're creating a temporary variable */
00175                      Z_SET_REFCOUNT_P(retval, 0);
00176               } else {
00177                      retval = EG(uninitialized_zval_ptr);
00178               }
00179        } else {
00180               std_hnd = zend_get_std_object_handlers();
00181               retval = std_hnd->read_property(object, member, type TSRMLS_CC);
00182        }
00183 
00184        if (member == &tmp_member) {
00185               zval_dtor(member);
00186        }
00187        return retval;
00188 }
00189 /* }}} */
00190 
00191 /* {{{ xmlreader_write_property */
00192 void xmlreader_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
00193 {
00194        xmlreader_object *obj;
00195        zval tmp_member;
00196        xmlreader_prop_handler *hnd;
00197        zend_object_handlers *std_hnd;
00198        int ret;
00199 
00200        if (member->type != IS_STRING) {
00201               tmp_member = *member;
00202               zval_copy_ctor(&tmp_member);
00203               convert_to_string(&tmp_member);
00204               member = &tmp_member;
00205        }
00206 
00207        ret = FAILURE;
00208        obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC);
00209 
00210        if (obj->prop_handler != NULL) {
00211               ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00212        }
00213        if (ret == SUCCESS) {
00214               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot write to read-only property");
00215        } else {
00216               std_hnd = zend_get_std_object_handlers();
00217               std_hnd->write_property(object, member, value TSRMLS_CC);
00218        }
00219 
00220        if (member == &tmp_member) {
00221               zval_dtor(member);
00222        }
00223 }
00224 /* }}} */
00225 
00226 /* {{{ _xmlreader_get_valid_file_path */
00227 /* _xmlreader_get_valid_file_path and _xmlreader_get_relaxNG should be made a 
00228        common function in libxml extension as code is common to a few xml extensions */
00229 char *_xmlreader_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len  TSRMLS_DC) {
00230        xmlURI *uri;
00231        xmlChar *escsource;
00232        char *file_dest;
00233        int isFileUri = 0;
00234 
00235        uri = xmlCreateURI();
00236        escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *)":");
00237        xmlParseURIReference(uri, (const char *)escsource);
00238        xmlFree(escsource);
00239 
00240        if (uri->scheme != NULL) {
00241               /* absolute file uris - libxml only supports localhost or empty host */
00242               if (strncasecmp(source, "file:///",8) == 0) {
00243                      isFileUri = 1;
00244 #ifdef PHP_WIN32
00245                      source += 8;
00246 #else
00247                      source += 7;
00248 #endif
00249               } else if (strncasecmp(source, "file://localhost/",17) == 0) {
00250                      isFileUri = 1;
00251 #ifdef PHP_WIN32
00252                      source += 17;
00253 #else
00254                      source += 16;
00255 #endif
00256               }
00257        }
00258 
00259        file_dest = source;
00260 
00261        if ((uri->scheme == NULL || isFileUri)) {
00262               if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) {
00263                      xmlFreeURI(uri);
00264                      return NULL;
00265               }
00266               file_dest = resolved_path;
00267        }
00268 
00269        xmlFreeURI(uri);
00270 
00271        return file_dest;
00272 }
00273 /* }}} */
00274 
00275 #ifdef LIBXML_SCHEMAS_ENABLED
00276 /* {{{ _xmlreader_get_relaxNG */
00277 static xmlRelaxNGPtr _xmlreader_get_relaxNG(char *source, int source_len, int type, 
00278                                                                              xmlRelaxNGValidityErrorFunc error_func, 
00279                                                                              xmlRelaxNGValidityWarningFunc warn_func TSRMLS_DC)
00280 {
00281        char *valid_file = NULL;
00282        xmlRelaxNGParserCtxtPtr parser = NULL;
00283        xmlRelaxNGPtr           sptr;
00284        char resolved_path[MAXPATHLEN + 1];
00285 
00286        switch (type) {
00287        case XMLREADER_LOAD_FILE:
00288               valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);
00289               if (!valid_file) {
00290                      return NULL;
00291               }
00292               parser = xmlRelaxNGNewParserCtxt(valid_file);
00293               break;
00294        case XMLREADER_LOAD_STRING:
00295               parser = xmlRelaxNGNewMemParserCtxt(source, source_len);
00296               /* If loading from memory, we need to set the base directory for the document 
00297                  but it is not apparent how to do that for schema's */
00298               break;
00299        default:
00300               return NULL;
00301        }
00302 
00303        if (parser == NULL) {
00304               return NULL;
00305        }
00306 
00307        if (error_func || warn_func) {
00308               xmlRelaxNGSetParserErrors(parser,
00309                      (xmlRelaxNGValidityErrorFunc) error_func,
00310                      (xmlRelaxNGValidityWarningFunc) warn_func,
00311                      parser);
00312        }
00313        sptr = xmlRelaxNGParse(parser);
00314        xmlRelaxNGFreeParserCtxt(parser);
00315 
00316        return sptr;
00317 }
00318 /* }}} */
00319 #endif
00320 
00321 static const zend_module_dep xmlreader_deps[] = {
00322        ZEND_MOD_REQUIRED("libxml")
00323        ZEND_MOD_END
00324 };
00325 
00326 /* {{{ xmlreader_module_entry
00327  */
00328 zend_module_entry xmlreader_module_entry = {
00329        STANDARD_MODULE_HEADER_EX, NULL,
00330        xmlreader_deps,
00331        "xmlreader",
00332        NULL,
00333        PHP_MINIT(xmlreader),
00334        PHP_MSHUTDOWN(xmlreader),
00335        NULL,
00336        NULL,
00337        PHP_MINFO(xmlreader),
00338        "0.1", /* Replace with version number for your extension */
00339        STANDARD_MODULE_PROPERTIES
00340 };
00341 /* }}} */
00342 
00343 #ifdef COMPILE_DL_XMLREADER
00344 ZEND_GET_MODULE(xmlreader)
00345 #endif
00346 
00347 /* {{{ xmlreader_objects_clone */
00348 void xmlreader_objects_clone(void *object, void **object_clone TSRMLS_DC)
00349 {
00350        /* TODO */
00351 }
00352 /* }}} */
00353 
00354 /* {{{ xmlreader_free_resources */
00355 static void xmlreader_free_resources(xmlreader_object *intern) {
00356        if (intern) {
00357               if (intern->input) {
00358                      xmlFreeParserInputBuffer(intern->input);
00359                      intern->input = NULL;
00360               }
00361 
00362               if (intern->ptr) {
00363                      xmlFreeTextReader(intern->ptr);
00364                      intern->ptr = NULL;
00365               }
00366 #ifdef LIBXML_SCHEMAS_ENABLED
00367               if (intern->schema) {
00368                      xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema);
00369                      intern->schema = NULL;
00370               }
00371 #endif
00372        }
00373 }
00374 /* }}} */
00375 
00376 /* {{{ xmlreader_objects_free_storage */
00377 void xmlreader_objects_free_storage(void *object TSRMLS_DC)
00378 {
00379        xmlreader_object *intern = (xmlreader_object *)object;
00380 
00381        zend_object_std_dtor(&intern->std TSRMLS_CC);
00382        
00383        xmlreader_free_resources(intern);
00384 
00385        efree(object);
00386 }
00387 /* }}} */
00388 
00389 /* {{{ xmlreader_objects_new */
00390 zend_object_value xmlreader_objects_new(zend_class_entry *class_type TSRMLS_DC)
00391 {
00392        zend_object_value retval;
00393        xmlreader_object *intern;
00394        zval *tmp;
00395 
00396        intern = emalloc(sizeof(xmlreader_object));
00397        memset(&intern->std, 0, sizeof(zend_object));
00398        intern->ptr = NULL;
00399        intern->input = NULL;
00400        intern->schema = NULL;
00401        intern->prop_handler = &xmlreader_prop_handlers;
00402 
00403        zend_object_std_init(&intern->std, class_type TSRMLS_CC);
00404        zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
00405        retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) xmlreader_objects_free_storage, xmlreader_objects_clone TSRMLS_CC);
00406        intern->handle = retval.handle;
00407        retval.handlers = &xmlreader_object_handlers;
00408        return retval;
00409 }
00410 /* }}} */
00411 
00412 /* {{{ php_xmlreader_string_arg */
00413 static void php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_one_char_t internal_function) {
00414        zval *id;
00415        int name_len = 0;
00416        char *retchar = NULL;
00417        xmlreader_object *intern;
00418        char *name;
00419 
00420        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
00421               return;
00422        }
00423 
00424        if (!name_len) {
00425               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument cannot be an empty string");
00426               RETURN_FALSE;
00427        }
00428 
00429        id = getThis();
00430 
00431        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00432        if (intern && intern->ptr) {
00433               retchar = (char *)internal_function(intern->ptr, (const unsigned char *)name);
00434        }
00435        if (retchar) {
00436               RETVAL_STRING(retchar, 1);
00437               xmlFree(retchar);
00438               return;
00439        } else {
00440               RETVAL_NULL();
00441        }
00442 }
00443 /* }}} */
00444 
00445 /* {{{ php_xmlreader_no_arg */
00446 static void php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_int_t internal_function) {
00447        zval *id;
00448        int retval;
00449        xmlreader_object *intern;
00450 
00451        id = getThis();
00452 
00453        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00454        if (intern && intern->ptr) {
00455               retval = internal_function(intern->ptr);
00456               if (retval == 1) {
00457                      RETURN_TRUE;
00458               }
00459        }
00460 
00461        RETURN_FALSE;
00462 }
00463 /* }}} */
00464 
00465 #if LIBXML_VERSION >= 20620
00466 /* {{{ php_xmlreader_no_arg_string */
00467 static void php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_char_t internal_function) {
00468        zval *id;
00469        char *retchar = NULL;
00470        xmlreader_object *intern;
00471 
00472        id = getThis();
00473 
00474        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00475        if (intern && intern->ptr) {
00476               retchar = (char *)internal_function(intern->ptr);
00477        }
00478        if (retchar) {
00479               RETVAL_STRING(retchar, 1);
00480               xmlFree(retchar);
00481               return;
00482        } else {
00483               RETVAL_EMPTY_STRING();
00484        }
00485 }
00486 /* }}} */
00487 #endif
00488 
00489 /* {{{ php_xmlreader_set_relaxng_schema */
00490 static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int type) {
00491 #ifdef LIBXML_SCHEMAS_ENABLED
00492        zval *id;
00493        int source_len = 0, retval = -1;
00494        xmlreader_object *intern;
00495        xmlRelaxNGPtr schema = NULL;
00496        char *source;
00497 
00498        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &source, &source_len) == FAILURE) {
00499               return;
00500        }
00501 
00502        if (source != NULL && !source_len) {
00503               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Schema data source is required");
00504               RETURN_FALSE;
00505        }
00506 
00507        id = getThis();
00508 
00509        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00510        if (intern && intern->ptr) {
00511               if (source) {
00512                      schema =  _xmlreader_get_relaxNG(source, source_len, type, NULL, NULL TSRMLS_CC);
00513                      if (schema) {
00514                             retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, schema);
00515                      }
00516               } else {
00517                      /* unset the associated relaxNG context and schema if one exists */
00518                      retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, NULL);
00519               }
00520 
00521               if (retval == 0) {
00522                      if (intern->schema) {
00523                             xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema);
00524                      }
00525 
00526                      intern->schema = schema;
00527 
00528                      RETURN_TRUE;
00529               }
00530        }
00531        
00532        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors.");
00533 
00534        RETURN_FALSE;
00535 #else
00536        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Schema support built into libxml.");
00537 
00538        RETURN_FALSE;
00539 #endif
00540 }
00541 /* }}} */
00542 
00543 /* {{{ proto boolean XMLReader::close()
00544 Closes xmlreader - current frees resources until xmlTextReaderClose is fixed in libxml */
00545 PHP_METHOD(xmlreader, close)
00546 {
00547        zval *id;
00548        xmlreader_object *intern;
00549 
00550        id = getThis();
00551        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00552        /* libxml is segfaulting in versions up to 2.6.8 using xmlTextReaderClose so for 
00553        now we will free the whole reader when close is called as it would get rebuilt on 
00554        a new load anyways */
00555        xmlreader_free_resources(intern);
00556        
00557        RETURN_TRUE;
00558 }
00559 /* }}} */
00560 
00561 /* {{{ proto string XMLReader::getAttribute(string name)
00562 Get value of an attribute from current element */
00563 PHP_METHOD(xmlreader, getAttribute)
00564 {
00565        php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderGetAttribute);
00566 }
00567 /* }}} */
00568 
00569 /* {{{ proto string XMLReader::getAttributeNo(int index)
00570 Get value of an attribute at index from current element */
00571 PHP_METHOD(xmlreader, getAttributeNo)
00572 {
00573        zval *id;
00574        long attr_pos;
00575        char *retchar = NULL;
00576        xmlreader_object *intern;
00577 
00578        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr_pos) == FAILURE) {
00579               return;
00580        }
00581 
00582        id = getThis();
00583 
00584        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00585        if (intern && intern->ptr) {
00586               retchar = (char *)xmlTextReaderGetAttributeNo(intern->ptr, attr_pos);
00587        }
00588        if (retchar) {
00589               RETVAL_STRING(retchar, 1);
00590               xmlFree(retchar);
00591               return;
00592        } else {
00593               RETURN_EMPTY_STRING();
00594        }
00595 }
00596 /* }}} */
00597 
00598 /* {{{ proto string XMLReader::getAttributeNs(string name, string namespaceURI)
00599 Get value of a attribute via name and namespace from current element */
00600 PHP_METHOD(xmlreader, getAttributeNs)
00601 {
00602        zval *id;
00603        int name_len = 0, ns_uri_len = 0;
00604        xmlreader_object *intern;
00605        char *name, *ns_uri, *retchar = NULL;
00606 
00607        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) {
00608               return;
00609        }
00610 
00611        if (name_len == 0 || ns_uri_len == 0) {
00612               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name and Namespace URI cannot be empty");
00613               RETURN_FALSE;
00614        }
00615 
00616        id = getThis();
00617 
00618        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00619        if (intern && intern->ptr) {
00620               retchar = (char *)xmlTextReaderGetAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri);
00621        }
00622        if (retchar) {
00623               RETVAL_STRING(retchar, 1);
00624               xmlFree(retchar);
00625               return;
00626        } else {
00627               RETURN_EMPTY_STRING();
00628        }
00629 }
00630 /* }}} */
00631 
00632 /* {{{ proto boolean XMLReader::getParserProperty(int property)
00633 Indicates whether given property (one of the parser option constants) is set or not on parser */
00634 PHP_METHOD(xmlreader, getParserProperty)
00635 {
00636        zval *id;
00637        long property;
00638        int retval = -1;
00639        xmlreader_object *intern;
00640 
00641        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &property) == FAILURE) {
00642               return;
00643        }
00644 
00645        id = getThis();
00646 
00647        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00648        if (intern && intern->ptr) {
00649               retval = xmlTextReaderGetParserProp(intern->ptr,property);
00650        }
00651        if (retval == -1) {
00652               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parser property");
00653               RETURN_FALSE;
00654        }
00655 
00656        RETURN_BOOL(retval);
00657 }
00658 /* }}} */
00659 
00660 /* {{{ proto boolean XMLReader::isValid()
00661 Returns boolean indicating if parsed document is valid or not.
00662 Must set XMLREADER_LOADDTD or XMLREADER_VALIDATE parser option prior to the first call to read 
00663 or this method will always return FALSE */
00664 PHP_METHOD(xmlreader, isValid)
00665 {
00666        php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderIsValid);
00667 }
00668 /* }}} */
00669 
00670 /* {{{ proto string XMLReader::lookupNamespace(string prefix)
00671 Return namespaceURI for associated prefix on current node */
00672 PHP_METHOD(xmlreader, lookupNamespace)
00673 {
00674        php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderLookupNamespace);
00675 }
00676 /* }}} */
00677 
00678 /* {{{ proto boolean XMLReader::moveToAttribute(string name)
00679 Positions reader at specified attribute - Returns TRUE on success and FALSE on failure */
00680 PHP_METHOD(xmlreader, moveToAttribute)
00681 {
00682        zval *id;
00683        int name_len = 0, retval;
00684        xmlreader_object *intern;
00685        char *name;
00686 
00687        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
00688               return;
00689        }
00690 
00691        if (name_len == 0) {
00692               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required");
00693               RETURN_FALSE;
00694        }
00695 
00696        id = getThis();
00697 
00698        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00699        if (intern && intern->ptr) {
00700               retval = xmlTextReaderMoveToAttribute(intern->ptr, (xmlChar *)name);
00701               if (retval == 1) {
00702                      RETURN_TRUE;
00703               }
00704        }
00705 
00706        RETURN_FALSE;
00707 }
00708 /* }}} */
00709 
00710 /* {{{ proto boolean XMLReader::moveToAttributeNo(int index)
00711 Positions reader at attribute at spcecified index.
00712 Returns TRUE on success and FALSE on failure */
00713 PHP_METHOD(xmlreader, moveToAttributeNo)
00714 {
00715        zval *id;
00716        long attr_pos;
00717        int retval;
00718        xmlreader_object *intern;
00719 
00720        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr_pos) == FAILURE) {
00721               return;
00722        }
00723 
00724        id = getThis();
00725 
00726        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00727        if (intern && intern->ptr) {
00728               retval = xmlTextReaderMoveToAttributeNo(intern->ptr, attr_pos);
00729               if (retval == 1) {
00730                      RETURN_TRUE;
00731               }
00732        }
00733 
00734        RETURN_FALSE;
00735 }
00736 /* }}} */
00737 
00738 /* {{{ proto boolean XMLReader::moveToAttributeNs(string name, string namespaceURI)
00739 Positions reader at attribute spcified by name and namespaceURI.
00740 Returns TRUE on success and FALSE on failure */
00741 PHP_METHOD(xmlreader, moveToAttributeNs)
00742 {
00743        zval *id;
00744        int name_len=0, ns_uri_len=0, retval;
00745        xmlreader_object *intern;
00746        char *name, *ns_uri;
00747 
00748        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) {
00749               return;
00750        }
00751 
00752        if (name_len == 0 || ns_uri_len == 0) {
00753               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name and Namespace URI cannot be empty");
00754               RETURN_FALSE;
00755        }
00756 
00757        id = getThis();
00758 
00759        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00760        if (intern && intern->ptr) {
00761               retval = xmlTextReaderMoveToAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri);
00762               if (retval == 1) {
00763                      RETURN_TRUE;
00764               }
00765        }
00766 
00767        RETURN_FALSE;
00768 }
00769 /* }}} */
00770 
00771 /* {{{ proto boolean XMLReader::moveToElement()
00772 Moves the position of the current instance to the node that contains the current Attribute node. */
00773 PHP_METHOD(xmlreader, moveToElement)
00774 {
00775        php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToElement);
00776 }
00777 /* }}} */
00778 
00779 /* {{{ proto boolean XMLReader::moveToFirstAttribute()
00780 Moves the position of the current instance to the first attribute associated with the current node. */
00781 PHP_METHOD(xmlreader, moveToFirstAttribute)
00782 {
00783        php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToFirstAttribute);
00784 }
00785 /* }}} */
00786 
00787 /* {{{ proto boolean XMLReader::moveToNextAttribute()
00788 Moves the position of the current instance to the next attribute associated with the current node. */
00789 PHP_METHOD(xmlreader, moveToNextAttribute)
00790 {
00791        php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToNextAttribute);
00792 }
00793 /* }}} */
00794 
00795 /* {{{ proto boolean XMLReader::read()
00796 Moves the position of the current instance to the next node in the stream. */
00797 PHP_METHOD(xmlreader, read)
00798 {
00799        zval *id;
00800        int retval;
00801        xmlreader_object *intern;
00802 
00803        id = getThis();
00804        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00805        if (intern != NULL && intern->ptr != NULL) {
00806               retval = xmlTextReaderRead(intern->ptr);
00807               if (retval == -1) {
00808                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading");
00809                      RETURN_FALSE;
00810               } else {
00811                      RETURN_BOOL(retval);
00812               }
00813        }
00814        
00815        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to read");
00816        RETURN_FALSE;
00817 }
00818 /* }}} */
00819 
00820 /* {{{ proto boolean XMLReader::next([string localname])
00821 Moves the position of the current instance to the next node in the stream. */
00822 PHP_METHOD(xmlreader, next)
00823 {
00824        zval *id;
00825        int retval, name_len=0;
00826        xmlreader_object *intern;
00827        char *name = NULL;
00828 
00829        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
00830               return;
00831        }
00832 
00833        id = getThis();
00834        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00835        if (intern != NULL && intern->ptr != NULL) {
00836 #if LIBXML_VERSION <= 20617
00837               /* Bug in libxml prevents a next in certain cases when positioned on end of element */
00838               if (xmlTextReaderNodeType(intern->ptr) == XML_READER_TYPE_END_ELEMENT) {
00839                      retval = xmlTextReaderRead(intern->ptr);
00840               } else
00841 #endif
00842               retval = xmlTextReaderNext(intern->ptr);
00843               while (name != NULL && retval == 1) {
00844                      if (xmlStrEqual(xmlTextReaderConstLocalName(intern->ptr), (xmlChar *)name)) {
00845                             RETURN_TRUE;
00846                      }
00847                      retval = xmlTextReaderNext(intern->ptr); 
00848               }
00849               if (retval == -1) {
00850                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading");
00851                      RETURN_FALSE;
00852               } else {
00853                      RETURN_BOOL(retval);
00854               }
00855        }
00856        
00857        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to read");
00858        RETURN_FALSE;
00859 }
00860 /* }}} */
00861 
00862 /* {{{ proto boolean XMLReader::open(string URI [, string encoding [, int options]])
00863 Sets the URI that the XMLReader will parse. */
00864 PHP_METHOD(xmlreader, open)
00865 {
00866        zval *id;
00867        int source_len = 0, encoding_len = 0;
00868        long options = 0;
00869        xmlreader_object *intern = NULL;
00870        char *source, *valid_file = NULL;
00871        char *encoding = NULL;
00872        char resolved_path[MAXPATHLEN + 1];
00873        xmlTextReaderPtr reader = NULL;
00874 
00875        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
00876               return;
00877        }
00878 
00879        id = getThis();
00880        if (id != NULL) {
00881               if (! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry TSRMLS_CC)) {
00882                      id = NULL;
00883               } else {
00884                      intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00885                      xmlreader_free_resources(intern);
00886               }
00887        }
00888 
00889        if (!source_len) {
00890               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
00891               RETURN_FALSE;
00892        }
00893 
00894        valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);
00895 
00896        if (valid_file) {
00897               reader = xmlReaderForFile(valid_file, encoding, options);
00898        }
00899 
00900        if (reader == NULL) {
00901               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open source data");
00902               RETURN_FALSE;
00903        }
00904 
00905        if (id == NULL) {
00906               object_init_ex(return_value, xmlreader_class_entry);
00907               intern = (xmlreader_object *)zend_objects_get_address(return_value TSRMLS_CC);
00908               intern->ptr = reader;
00909               return;
00910        }
00911 
00912        intern->ptr = reader;
00913 
00914        RETURN_TRUE;
00915 
00916 }
00917 /* }}} */
00918 
00919 /* Not Yet Implemented in libxml - functions exist just not coded
00920 PHP_METHOD(xmlreader, resetState)
00921 {
00922 
00923 }
00924 */
00925 
00926 #if LIBXML_VERSION >= 20620
00927 /* {{{ proto string XMLReader::readInnerXml()
00928 Reads the contents of the current node, including child nodes and markup. */
00929 PHP_METHOD(xmlreader, readInnerXml)
00930 {
00931        php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadInnerXml);
00932 }
00933 /* }}} */
00934 
00935 /* {{{ proto boolean XMLReader::readOuterXml()
00936 Reads the contents of the current node, including child nodes and markup. */
00937 PHP_METHOD(xmlreader, readOuterXml)
00938 {
00939        php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadOuterXml);
00940 }
00941 /* }}} */
00942 
00943 /* {{{ proto boolean XMLReader::readString()
00944 Reads the contents of an element or a text node as a string. */
00945 PHP_METHOD(xmlreader, readString)
00946 {
00947        php_xmlreader_no_arg_string(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderReadString);
00948 }
00949 /* }}} */
00950 
00951 /* {{{ proto boolean XMLReader::setSchema(string filename)
00952 Use W3C XSD schema to validate the document as it is processed. Activation is only possible before the first Read(). */
00953 PHP_METHOD(xmlreader, setSchema)
00954 {
00955 #ifdef LIBXML_SCHEMAS_ENABLED
00956        zval *id;
00957        int source_len = 0, retval = -1;
00958        xmlreader_object *intern;
00959        char *source;
00960 
00961        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &source, &source_len) == FAILURE) {
00962               return;
00963        }
00964 
00965        if (source != NULL && !source_len) {
00966               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Schema data source is required");
00967               RETURN_FALSE;
00968        }
00969 
00970        id = getThis();
00971 
00972        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
00973        if (intern && intern->ptr) {
00974               retval = xmlTextReaderSchemaValidate(intern->ptr, source);
00975 
00976               if (retval == 0) {
00977                      RETURN_TRUE;
00978               }
00979        }
00980        
00981        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors.");
00982 
00983        RETURN_FALSE;
00984 #else
00985        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Schema support built into libxml.");
00986 
00987        RETURN_FALSE;
00988 #endif
00989 }
00990 /* }}} */
00991 #endif
00992 
00993 /* {{{ proto boolean XMLReader::setParserProperty(int property, boolean value)
00994 Sets parser property (one of the parser option constants).
00995 Properties must be set after open() or XML() and before the first read() is called */
00996 PHP_METHOD(xmlreader, setParserProperty)
00997 {
00998        zval *id;
00999        long property;
01000        int retval = -1;
01001        zend_bool value;
01002        xmlreader_object *intern;
01003 
01004        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &property, &value) == FAILURE) {
01005               return;
01006        }
01007 
01008        id = getThis();
01009 
01010        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
01011        if (intern && intern->ptr) {
01012               retval = xmlTextReaderSetParserProp(intern->ptr,property, value);
01013        }
01014        if (retval == -1) {
01015               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parser property");
01016               RETURN_FALSE;
01017        }
01018 
01019        RETURN_TRUE;
01020 }
01021 /* }}} */
01022 
01023 /* {{{ proto boolean XMLReader::setRelaxNGSchema(string filename)
01024 Sets the string that the XMLReader will parse. */
01025 PHP_METHOD(xmlreader, setRelaxNGSchema)
01026 {
01027        php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAM_PASSTHRU, XMLREADER_LOAD_FILE);
01028 }
01029 /* }}} */
01030 
01031 /* {{{ proto boolean XMLReader::setRelaxNGSchemaSource(string source)
01032 Sets the string that the XMLReader will parse. */
01033 PHP_METHOD(xmlreader, setRelaxNGSchemaSource)
01034 {
01035        php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAM_PASSTHRU, XMLREADER_LOAD_STRING);
01036 }
01037 /* }}} */
01038 
01039 /* TODO
01040 XMLPUBFUN int XMLCALL              
01041                   xmlTextReaderSetSchema  (xmlTextReaderPtr reader,
01042                                            xmlSchemaPtr schema);
01043 */
01044 
01045 /* {{{ proto boolean XMLReader::XML(string source [, string encoding [, int options]])
01046 Sets the string that the XMLReader will parse. */
01047 PHP_METHOD(xmlreader, XML)
01048 {
01049        zval *id;
01050        int source_len = 0, encoding_len = 0;
01051        long options = 0;
01052        xmlreader_object *intern = NULL;
01053        char *source, *uri = NULL, *encoding = NULL;
01054        int resolved_path_len, ret = 0;
01055        char *directory=NULL, resolved_path[MAXPATHLEN];
01056        xmlParserInputBufferPtr inputbfr;
01057        xmlTextReaderPtr reader;
01058 
01059        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
01060               return;
01061        }
01062 
01063        id = getThis();
01064        if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry TSRMLS_CC)) {
01065               id = NULL;
01066        }
01067        if (id != NULL) {
01068               intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
01069               xmlreader_free_resources(intern);
01070        }
01071 
01072        if (!source_len) {
01073               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
01074               RETURN_FALSE;
01075        }
01076 
01077        inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE);
01078 
01079     if (inputbfr != NULL) {
01080 /* Get the URI of the current script so that we can set the base directory in libxml */
01081 #if HAVE_GETCWD
01082               directory = VCWD_GETCWD(resolved_path, MAXPATHLEN);
01083 #elif HAVE_GETWD
01084               directory = VCWD_GETWD(resolved_path);
01085 #endif
01086               if (directory) {
01087                      resolved_path_len = strlen(resolved_path);
01088                      if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) {
01089                             resolved_path[resolved_path_len] = DEFAULT_SLASH;
01090                             resolved_path[++resolved_path_len] = '\0';
01091                      }
01092                      uri = (char *) xmlCanonicPath((const xmlChar *) resolved_path);
01093               }
01094               reader = xmlNewTextReader(inputbfr, uri);
01095 
01096               if (reader != NULL) {
01097 #if LIBXML_VERSION >= 20628
01098                      ret = xmlTextReaderSetup(reader, NULL, uri, encoding, options);
01099 #endif
01100                      if (ret == 0) {
01101                             if (id == NULL) {
01102                                    object_init_ex(return_value, xmlreader_class_entry);
01103                                    intern = (xmlreader_object *)zend_objects_get_address(return_value TSRMLS_CC);
01104                             } else {
01105                                    RETVAL_TRUE;
01106                             }
01107                             intern->input = inputbfr;
01108                             intern->ptr = reader;
01109 
01110                             if (uri) {
01111                                    xmlFree(uri);
01112                             }
01113 
01114                             return;
01115                      }
01116               }
01117        }
01118 
01119        if (uri) {
01120               xmlFree(uri);
01121        }
01122 
01123        if (inputbfr) {
01124               xmlFreeParserInputBuffer(inputbfr);
01125        }
01126        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load source data");
01127        RETURN_FALSE;
01128 }
01129 /* }}} */
01130 
01131 /* {{{ proto boolean XMLReader::expand()
01132 Moves the position of the current instance to the next node in the stream. */
01133 PHP_METHOD(xmlreader, expand)
01134 {
01135 #ifdef HAVE_DOM
01136        zval *id, *rv = NULL, *basenode = NULL;
01137        int ret;
01138        xmlreader_object *intern;
01139        xmlNode *node, *nodec;
01140        xmlDocPtr docp = NULL;
01141        php_libxml_node_object *domobj = NULL;
01142 
01143        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O!", &id, xmlreader_class_entry, &basenode, dom_node_class_entry) == FAILURE) {
01144               return;
01145        }
01146        
01147        if (basenode != NULL) {
01148               NODE_GET_OBJ(node, basenode, xmlNodePtr, domobj);
01149               docp = node->doc;
01150        }
01151 
01152        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
01153 
01154        if (intern && intern->ptr) {
01155               node = xmlTextReaderExpand(intern->ptr);
01156               
01157               if (node == NULL) {
01158                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while expanding ");
01159                      RETURN_FALSE;
01160               } else {
01161                      nodec = xmlDocCopyNode(node, docp, 1);
01162                      if (nodec == NULL) {
01163                             php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot expand this node type");
01164                             RETURN_FALSE;
01165                      } else {
01166                             DOM_RET_OBJ(rv, nodec, &ret, (dom_object *)domobj);
01167                      }
01168               }
01169        } else {
01170               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to expand");
01171               RETURN_FALSE;
01172        }
01173 #else
01174        php_error(E_WARNING, "DOM support is not enabled");
01175        return;
01176 #endif
01177 }
01178 /* }}} */
01179 /* {{{ arginfo */
01180 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_close, 0)
01181 ZEND_END_ARG_INFO()
01182 
01183 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttribute, 0)
01184        ZEND_ARG_INFO(0, name)
01185 ZEND_END_ARG_INFO()
01186 
01187 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttributeNo, 0)
01188        ZEND_ARG_INFO(0, index)
01189 ZEND_END_ARG_INFO()
01190 
01191 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getAttributeNs, 0)
01192        ZEND_ARG_INFO(0, name)
01193        ZEND_ARG_INFO(0, namespaceURI)
01194 ZEND_END_ARG_INFO()
01195 
01196 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_getParserProperty, 0)
01197        ZEND_ARG_INFO(0, property)
01198 ZEND_END_ARG_INFO()
01199 
01200 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_isValid, 0)
01201 ZEND_END_ARG_INFO()
01202 
01203 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_lookupNamespace, 0)
01204 ZEND_ARG_INFO(0, prefix)
01205 ZEND_END_ARG_INFO()
01206 
01207 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttribute, 0)
01208        ZEND_ARG_INFO(0, name)
01209 ZEND_END_ARG_INFO()
01210 
01211 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttributeNo, 0)
01212        ZEND_ARG_INFO(0, index)
01213 ZEND_END_ARG_INFO()
01214 
01215 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToAttributeNs, 0)
01216        ZEND_ARG_INFO(0, name)
01217        ZEND_ARG_INFO(0, namespaceURI)
01218 ZEND_END_ARG_INFO()
01219 
01220 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToElement, 0)
01221 ZEND_END_ARG_INFO()
01222 
01223 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToFirstAttribute, 0)
01224 ZEND_END_ARG_INFO()
01225 
01226 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_moveToNextAttribute, 0)
01227 ZEND_END_ARG_INFO()
01228 
01229 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_read, 0)
01230 ZEND_END_ARG_INFO()
01231 
01232 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_next, 0, 0, 0)
01233        ZEND_ARG_INFO(0, localname)
01234 ZEND_END_ARG_INFO()
01235 
01236 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_open, 0, 0, 1)
01237        ZEND_ARG_INFO(0, URI)
01238        ZEND_ARG_INFO(0, encoding)
01239        ZEND_ARG_INFO(0, options)
01240 ZEND_END_ARG_INFO()
01241 
01242 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readInnerXml, 0)
01243 ZEND_END_ARG_INFO()
01244 
01245 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readOuterXml, 0)
01246 ZEND_END_ARG_INFO()
01247 
01248 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_readString, 0)
01249 ZEND_END_ARG_INFO()
01250 
01251 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setSchema, 0)
01252        ZEND_ARG_INFO(0, filename)
01253 ZEND_END_ARG_INFO()
01254 
01255 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setParserProperty, 0)
01256        ZEND_ARG_INFO(0, property)
01257        ZEND_ARG_INFO(0, value)
01258 ZEND_END_ARG_INFO()
01259 
01260 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setRelaxNGSchema, 0)
01261        ZEND_ARG_INFO(0, filename)
01262 ZEND_END_ARG_INFO()
01263 
01264 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_setRelaxNGSchemaSource, 0)
01265        ZEND_ARG_INFO(0, source)
01266 ZEND_END_ARG_INFO()
01267 
01268 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlreader_XML, 0, 0, 1)
01269        ZEND_ARG_INFO(0, source)
01270        ZEND_ARG_INFO(0, encoding)
01271        ZEND_ARG_INFO(0, options)
01272 ZEND_END_ARG_INFO()
01273 
01274 ZEND_BEGIN_ARG_INFO(arginfo_xmlreader_expand, 0)
01275 ZEND_END_ARG_INFO()
01276 /* }}} */
01277 
01278 static const zend_function_entry xmlreader_functions[] = {
01279        PHP_ME(xmlreader, close, arginfo_xmlreader_close, ZEND_ACC_PUBLIC)
01280        PHP_ME(xmlreader, getAttribute, arginfo_xmlreader_getAttribute, ZEND_ACC_PUBLIC)
01281        PHP_ME(xmlreader, getAttributeNo, arginfo_xmlreader_getAttributeNo, ZEND_ACC_PUBLIC)
01282        PHP_ME(xmlreader, getAttributeNs, arginfo_xmlreader_getAttributeNs, ZEND_ACC_PUBLIC)
01283        PHP_ME(xmlreader, getParserProperty, arginfo_xmlreader_getParserProperty, ZEND_ACC_PUBLIC)
01284        PHP_ME(xmlreader, isValid, arginfo_xmlreader_isValid, ZEND_ACC_PUBLIC)
01285        PHP_ME(xmlreader, lookupNamespace, arginfo_xmlreader_lookupNamespace, ZEND_ACC_PUBLIC)
01286        PHP_ME(xmlreader, moveToAttributeNo, arginfo_xmlreader_moveToAttributeNo, ZEND_ACC_PUBLIC)
01287        PHP_ME(xmlreader, moveToAttribute, arginfo_xmlreader_moveToAttribute, ZEND_ACC_PUBLIC)
01288        PHP_ME(xmlreader, moveToAttributeNs, arginfo_xmlreader_moveToAttributeNs, ZEND_ACC_PUBLIC)
01289        PHP_ME(xmlreader, moveToElement, arginfo_xmlreader_moveToElement, ZEND_ACC_PUBLIC)
01290        PHP_ME(xmlreader, moveToFirstAttribute, arginfo_xmlreader_moveToFirstAttribute, ZEND_ACC_PUBLIC)
01291        PHP_ME(xmlreader, moveToNextAttribute, arginfo_xmlreader_moveToNextAttribute, ZEND_ACC_PUBLIC)
01292        PHP_ME(xmlreader, open, arginfo_xmlreader_open, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
01293        PHP_ME(xmlreader, read, arginfo_xmlreader_read, ZEND_ACC_PUBLIC)
01294        PHP_ME(xmlreader, next, arginfo_xmlreader_next, ZEND_ACC_PUBLIC)
01295 #if LIBXML_VERSION >= 20620
01296        PHP_ME(xmlreader, readInnerXml, arginfo_xmlreader_readInnerXml, ZEND_ACC_PUBLIC)
01297        PHP_ME(xmlreader, readOuterXml, arginfo_xmlreader_readOuterXml, ZEND_ACC_PUBLIC)
01298        PHP_ME(xmlreader, readString, arginfo_xmlreader_readString, ZEND_ACC_PUBLIC)
01299        PHP_ME(xmlreader, setSchema, arginfo_xmlreader_setSchema, ZEND_ACC_PUBLIC)
01300 #endif
01301 /* Not Yet Implemented though defined in libxml as of 2.6.9dev
01302        PHP_ME(xmlreader, resetState, NULL, ZEND_ACC_PUBLIC)
01303 */
01304        PHP_ME(xmlreader, setParserProperty, arginfo_xmlreader_setParserProperty, ZEND_ACC_PUBLIC)
01305        PHP_ME(xmlreader, setRelaxNGSchema, arginfo_xmlreader_setRelaxNGSchema, ZEND_ACC_PUBLIC)
01306        PHP_ME(xmlreader, setRelaxNGSchemaSource, arginfo_xmlreader_setRelaxNGSchemaSource, ZEND_ACC_PUBLIC)
01307        PHP_ME(xmlreader, XML, arginfo_xmlreader_XML, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
01308        PHP_ME(xmlreader, expand, arginfo_xmlreader_expand, ZEND_ACC_PUBLIC)
01309        PHP_FE_END
01310 };
01311 
01312 /* {{{ PHP_MINIT_FUNCTION
01313  */
01314 PHP_MINIT_FUNCTION(xmlreader)
01315 {
01316        
01317        zend_class_entry ce;
01318        
01319        memcpy(&xmlreader_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
01320        xmlreader_object_handlers.read_property = xmlreader_read_property;
01321        xmlreader_object_handlers.write_property = xmlreader_write_property;
01322        xmlreader_object_handlers.get_property_ptr_ptr = xmlreader_get_property_ptr_ptr;
01323 
01324        INIT_CLASS_ENTRY(ce, "XMLReader", xmlreader_functions);
01325        ce.create_object = xmlreader_objects_new;
01326        xmlreader_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
01327 
01328        zend_hash_init(&xmlreader_prop_handlers, 0, NULL, NULL, 1);
01329        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "attributeCount", xmlTextReaderAttributeCount, NULL, IS_LONG TSRMLS_CC);
01330        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "baseURI", NULL, xmlTextReaderConstBaseUri, IS_STRING TSRMLS_CC);
01331        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "depth", xmlTextReaderDepth, NULL, IS_LONG TSRMLS_CC);
01332        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasAttributes", xmlTextReaderHasAttributes, NULL, IS_BOOL TSRMLS_CC);
01333        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasValue", xmlTextReaderHasValue, NULL, IS_BOOL TSRMLS_CC);
01334        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isDefault", xmlTextReaderIsDefault, NULL, IS_BOOL TSRMLS_CC);
01335        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isEmptyElement", xmlTextReaderIsEmptyElement, NULL, IS_BOOL TSRMLS_CC);
01336        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "localName", NULL, xmlTextReaderConstLocalName, IS_STRING TSRMLS_CC);
01337        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "name", NULL, xmlTextReaderConstName, IS_STRING TSRMLS_CC);
01338        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "namespaceURI", NULL, xmlTextReaderConstNamespaceUri, IS_STRING TSRMLS_CC);
01339        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "nodeType", xmlTextReaderNodeType, NULL, IS_LONG TSRMLS_CC);
01340        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "prefix", NULL, xmlTextReaderConstPrefix, IS_STRING TSRMLS_CC);
01341        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "value", NULL, xmlTextReaderConstValue, IS_STRING TSRMLS_CC);
01342        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "xmlLang", NULL, xmlTextReaderConstXmlLang, IS_STRING TSRMLS_CC);
01343 
01344        /* Constants for NodeType - cannot define common types to share with dom as there are differences in these types */
01345 
01346        REGISTER_XMLREADER_CLASS_CONST_LONG("NONE",      XML_READER_TYPE_NONE);
01347        REGISTER_XMLREADER_CLASS_CONST_LONG("ELEMENT",   XML_READER_TYPE_ELEMENT);
01348        REGISTER_XMLREADER_CLASS_CONST_LONG("ATTRIBUTE", XML_READER_TYPE_ATTRIBUTE);
01349        REGISTER_XMLREADER_CLASS_CONST_LONG("TEXT",      XML_READER_TYPE_TEXT);
01350        REGISTER_XMLREADER_CLASS_CONST_LONG("CDATA",     XML_READER_TYPE_CDATA);
01351        REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY_REF",       XML_READER_TYPE_ENTITY_REFERENCE);
01352        REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY",    XML_READER_TYPE_ENTITY);
01353        REGISTER_XMLREADER_CLASS_CONST_LONG("PI", XML_READER_TYPE_PROCESSING_INSTRUCTION);
01354        REGISTER_XMLREADER_CLASS_CONST_LONG("COMMENT",   XML_READER_TYPE_COMMENT);
01355        REGISTER_XMLREADER_CLASS_CONST_LONG("DOC",       XML_READER_TYPE_DOCUMENT);
01356        REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_TYPE",  XML_READER_TYPE_DOCUMENT_TYPE);
01357        REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_FRAGMENT",     XML_READER_TYPE_DOCUMENT_FRAGMENT);
01358        REGISTER_XMLREADER_CLASS_CONST_LONG("NOTATION",  XML_READER_TYPE_NOTATION);
01359        REGISTER_XMLREADER_CLASS_CONST_LONG("WHITESPACE",       XML_READER_TYPE_WHITESPACE);
01360        REGISTER_XMLREADER_CLASS_CONST_LONG("SIGNIFICANT_WHITESPACE",  XML_READER_TYPE_SIGNIFICANT_WHITESPACE);
01361        REGISTER_XMLREADER_CLASS_CONST_LONG("END_ELEMENT",      XML_READER_TYPE_END_ELEMENT);
01362        REGISTER_XMLREADER_CLASS_CONST_LONG("END_ENTITY",       XML_READER_TYPE_END_ENTITY);
01363        REGISTER_XMLREADER_CLASS_CONST_LONG("XML_DECLARATION",  XML_READER_TYPE_XML_DECLARATION);
01364 
01365        /* Constants for Parser options */
01366        REGISTER_XMLREADER_CLASS_CONST_LONG("LOADDTD",   XML_PARSER_LOADDTD);
01367        REGISTER_XMLREADER_CLASS_CONST_LONG("DEFAULTATTRS",     XML_PARSER_DEFAULTATTRS);
01368        REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDATE",  XML_PARSER_VALIDATE);
01369        REGISTER_XMLREADER_CLASS_CONST_LONG("SUBST_ENTITIES",   XML_PARSER_SUBST_ENTITIES);
01370 
01371        /* Constants for Errors when loading - not yet used until we implement custom error handling
01372        REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_WARNING",        XML_PARSER_SEVERITY_VALIDITY_WARNING,     CONST_CS | CONST_PERSISTENT);
01373        REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_ERROR",          XML_PARSER_SEVERITY_VALIDITY_ERROR,              CONST_CS | CONST_PERSISTENT);
01374        REGISTER_XMLREADER_CLASS_CONST_LONG("WARNING",                        XML_PARSER_SEVERITY_WARNING,                     CONST_CS | CONST_PERSISTENT);
01375        REGISTER_XMLREADER_CLASS_CONST_LONG("ERROR",                          XML_PARSER_SEVERITY_ERROR,                       CONST_CS | CONST_PERSISTENT);
01376        */
01377 
01378        return SUCCESS;
01379 }
01380 /* }}} */
01381 
01382 /* {{{ PHP_MSHUTDOWN_FUNCTION
01383  */
01384 PHP_MSHUTDOWN_FUNCTION(xmlreader)
01385 {
01386        zend_hash_destroy(&xmlreader_prop_handlers);
01387        return SUCCESS;
01388 }
01389 /* }}} */
01390 
01391 /* {{{ PHP_MINFO_FUNCTION
01392  */
01393 PHP_MINFO_FUNCTION(xmlreader)
01394 {
01395        php_info_print_table_start();
01396        {
01397               php_info_print_table_row(2, "XMLReader", "enabled");
01398        }
01399        php_info_print_table_end();
01400 }
01401 /* }}} */
01402 
01403 /*
01404  * Local variables:
01405  * tab-width: 4
01406  * c-basic-offset: 4
01407  * End:
01408  * vim600: noet sw=4 ts=4 fdm=marker
01409  * vim<600: noet sw=4 ts=4
01410  */