Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
php_xmlreader.c File Reference
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_xmlreader.h"
#include <libxml/uri.h>

Go to the source code of this file.

Classes

struct  _xmlreader_prop_handler

Defines

#define XMLREADER_LOAD_STRING   0
#define XMLREADER_LOAD_FILE   1

Typedefs

typedef int(* xmlreader_read_int_t )(xmlTextReaderPtr reader)
typedef unsigned char *(* xmlreader_read_char_t )(xmlTextReaderPtr reader)
typedef const unsigned char *(* xmlreader_read_const_char_t )(xmlTextReaderPtr reader)
typedef int(* xmlreader_write_t )(xmlreader_object *obj, zval *newval TSRMLS_DC)
typedef unsigned char *(* xmlreader_read_one_char_t )(xmlTextReaderPtr reader, const unsigned char *)
typedef struct
_xmlreader_prop_handler 
xmlreader_prop_handler

Functions

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)
static int xmlreader_property_reader (xmlreader_object *obj, xmlreader_prop_handler *hnd, zval **retval TSRMLS_DC)
zval ** xmlreader_get_property_ptr_ptr (zval *object, zval *member TSRMLS_DC)
zval * xmlreader_read_property (zval *object, zval *member, int type TSRMLS_DC)
void xmlreader_write_property (zval *object, zval *member, zval *value TSRMLS_DC)
char * _xmlreader_get_valid_file_path (char *source, char *resolved_path, int resolved_path_len TSRMLS_DC)
void xmlreader_objects_clone (void *object, void **object_clone TSRMLS_DC)
static void xmlreader_free_resources (xmlreader_object *intern)
void xmlreader_objects_free_storage (void *object TSRMLS_DC)
zend_object_value xmlreader_objects_new (zend_class_entry *class_type TSRMLS_DC)
static void php_xmlreader_string_arg (INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_one_char_t internal_function)
static void php_xmlreader_no_arg (INTERNAL_FUNCTION_PARAMETERS, xmlreader_read_int_t internal_function)
static void php_xmlreader_set_relaxng_schema (INTERNAL_FUNCTION_PARAMETERS, int type)
 PHP_METHOD (xmlreader, close)
 PHP_METHOD (xmlreader, getAttribute)
 PHP_METHOD (xmlreader, getAttributeNo)
 PHP_METHOD (xmlreader, getAttributeNs)
 PHP_METHOD (xmlreader, getParserProperty)
 PHP_METHOD (xmlreader, isValid)
 PHP_METHOD (xmlreader, lookupNamespace)
 PHP_METHOD (xmlreader, moveToAttribute)
 PHP_METHOD (xmlreader, moveToAttributeNo)
 PHP_METHOD (xmlreader, moveToAttributeNs)
 PHP_METHOD (xmlreader, moveToElement)
 PHP_METHOD (xmlreader, moveToFirstAttribute)
 PHP_METHOD (xmlreader, moveToNextAttribute)
 PHP_METHOD (xmlreader, read)
 PHP_METHOD (xmlreader, next)
 PHP_METHOD (xmlreader, open)
 PHP_METHOD (xmlreader, setParserProperty)
 PHP_METHOD (xmlreader, setRelaxNGSchema)
 PHP_METHOD (xmlreader, setRelaxNGSchemaSource)
 PHP_METHOD (xmlreader, XML)
 PHP_METHOD (xmlreader, expand)
 PHP_MINIT_FUNCTION (xmlreader)
 PHP_MSHUTDOWN_FUNCTION (xmlreader)
 PHP_MINFO_FUNCTION (xmlreader)

Variables

zend_class_entry * xmlreader_class_entry
static zend_object_handlers xmlreader_object_handlers
static HashTable xmlreader_prop_handlers
static const zend_module_dep xmlreader_deps []
zend_module_entry xmlreader_module_entry
static const zend_function_entry xmlreader_functions []

Class Documentation

struct _xmlreader_prop_handler

Definition at line 48 of file php_xmlreader.c.

Collaboration diagram for _xmlreader_prop_handler:
Class Members
xmlreader_read_const_char_t read_char_func
xmlreader_read_int_t read_int_func
int type
xmlreader_write_t write_func

Define Documentation

#define XMLREADER_LOAD_FILE   1

Definition at line 56 of file php_xmlreader.c.

#define XMLREADER_LOAD_STRING   0

Definition at line 55 of file php_xmlreader.c.


Typedef Documentation

typedef unsigned char*(* xmlreader_read_char_t)(xmlTextReaderPtr reader)

Definition at line 42 of file php_xmlreader.c.

typedef const unsigned char*(* xmlreader_read_const_char_t)(xmlTextReaderPtr reader)

Definition at line 43 of file php_xmlreader.c.

typedef int(* xmlreader_read_int_t)(xmlTextReaderPtr reader)

Definition at line 41 of file php_xmlreader.c.

typedef unsigned char*(* xmlreader_read_one_char_t)(xmlTextReaderPtr reader, const unsigned char *)

Definition at line 46 of file php_xmlreader.c.

typedef int(* xmlreader_write_t)(xmlreader_object *obj, zval *newval TSRMLS_DC)

Definition at line 44 of file php_xmlreader.c.


Function Documentation

char* _xmlreader_get_valid_file_path ( char *  source,
char *  resolved_path,
int resolved_path_len  TSRMLS_DC 
)

Definition at line 229 of file php_xmlreader.c.

                                                                                                          {
       xmlURI *uri;
       xmlChar *escsource;
       char *file_dest;
       int isFileUri = 0;

       uri = xmlCreateURI();
       escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *)":");
       xmlParseURIReference(uri, (const char *)escsource);
       xmlFree(escsource);

       if (uri->scheme != NULL) {
              /* absolute file uris - libxml only supports localhost or empty host */
              if (strncasecmp(source, "file:///",8) == 0) {
                     isFileUri = 1;
#ifdef PHP_WIN32
                     source += 8;
#else
                     source += 7;
#endif
              } else if (strncasecmp(source, "file://localhost/",17) == 0) {
                     isFileUri = 1;
#ifdef PHP_WIN32
                     source += 17;
#else
                     source += 16;
#endif
              }
       }

       file_dest = source;

       if ((uri->scheme == NULL || isFileUri)) {
              if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) {
                     xmlFreeURI(uri);
                     return NULL;
              }
              file_dest = resolved_path;
       }

       xmlFreeURI(uri);

       return file_dest;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_METHOD ( xmlreader  ,
close   
)

Definition at line 545 of file php_xmlreader.c.

{
       zval *id;
       xmlreader_object *intern;

       id = getThis();
       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       /* libxml is segfaulting in versions up to 2.6.8 using xmlTextReaderClose so for 
       now we will free the whole reader when close is called as it would get rebuilt on 
       a new load anyways */
       xmlreader_free_resources(intern);
       
       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
getAttribute   
)

Definition at line 563 of file php_xmlreader.c.

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
getAttributeNo   
)

Definition at line 571 of file php_xmlreader.c.

{
       zval *id;
       long attr_pos;
       char *retchar = NULL;
       xmlreader_object *intern;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr_pos) == FAILURE) {
              return;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retchar = (char *)xmlTextReaderGetAttributeNo(intern->ptr, attr_pos);
       }
       if (retchar) {
              RETVAL_STRING(retchar, 1);
              xmlFree(retchar);
              return;
       } else {
              RETURN_EMPTY_STRING();
       }
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
getAttributeNs   
)

Definition at line 600 of file php_xmlreader.c.

{
       zval *id;
       int name_len = 0, ns_uri_len = 0;
       xmlreader_object *intern;
       char *name, *ns_uri, *retchar = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) {
              return;
       }

       if (name_len == 0 || ns_uri_len == 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name and Namespace URI cannot be empty");
              RETURN_FALSE;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retchar = (char *)xmlTextReaderGetAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri);
       }
       if (retchar) {
              RETVAL_STRING(retchar, 1);
              xmlFree(retchar);
              return;
       } else {
              RETURN_EMPTY_STRING();
       }
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
getParserProperty   
)

Definition at line 634 of file php_xmlreader.c.

{
       zval *id;
       long property;
       int retval = -1;
       xmlreader_object *intern;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &property) == FAILURE) {
              return;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retval = xmlTextReaderGetParserProp(intern->ptr,property);
       }
       if (retval == -1) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parser property");
              RETURN_FALSE;
       }

       RETURN_BOOL(retval);
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
isValid   
)

Definition at line 664 of file php_xmlreader.c.

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
lookupNamespace   
)

Definition at line 672 of file php_xmlreader.c.

{
       php_xmlreader_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderLookupNamespace);
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
moveToAttribute   
)

Definition at line 680 of file php_xmlreader.c.

{
       zval *id;
       int name_len = 0, retval;
       xmlreader_object *intern;
       char *name;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
              return;
       }

       if (name_len == 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name is required");
              RETURN_FALSE;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retval = xmlTextReaderMoveToAttribute(intern->ptr, (xmlChar *)name);
              if (retval == 1) {
                     RETURN_TRUE;
              }
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
moveToAttributeNo   
)

Definition at line 713 of file php_xmlreader.c.

{
       zval *id;
       long attr_pos;
       int retval;
       xmlreader_object *intern;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr_pos) == FAILURE) {
              return;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retval = xmlTextReaderMoveToAttributeNo(intern->ptr, attr_pos);
              if (retval == 1) {
                     RETURN_TRUE;
              }
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
moveToAttributeNs   
)

Definition at line 741 of file php_xmlreader.c.

{
       zval *id;
       int name_len=0, ns_uri_len=0, retval;
       xmlreader_object *intern;
       char *name, *ns_uri;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &ns_uri, &ns_uri_len) == FAILURE) {
              return;
       }

       if (name_len == 0 || ns_uri_len == 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute Name and Namespace URI cannot be empty");
              RETURN_FALSE;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retval = xmlTextReaderMoveToAttributeNs(intern->ptr, (xmlChar *)name, (xmlChar *)ns_uri);
              if (retval == 1) {
                     RETURN_TRUE;
              }
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
moveToElement   
)

Definition at line 773 of file php_xmlreader.c.

{
       php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToElement);
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
moveToFirstAttribute   
)

Definition at line 781 of file php_xmlreader.c.

{
       php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToFirstAttribute);
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
moveToNextAttribute   
)

Definition at line 789 of file php_xmlreader.c.

{
       php_xmlreader_no_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextReaderMoveToNextAttribute);
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
read   
)

Definition at line 797 of file php_xmlreader.c.

{
       zval *id;
       int retval;
       xmlreader_object *intern;

       id = getThis();
       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern != NULL && intern->ptr != NULL) {
              retval = xmlTextReaderRead(intern->ptr);
              if (retval == -1) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading");
                     RETURN_FALSE;
              } else {
                     RETURN_BOOL(retval);
              }
       }
       
       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to read");
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
next   
)

Definition at line 822 of file php_xmlreader.c.

{
       zval *id;
       int retval, name_len=0;
       xmlreader_object *intern;
       char *name = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
              return;
       }

       id = getThis();
       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern != NULL && intern->ptr != NULL) {
#if LIBXML_VERSION <= 20617
              /* Bug in libxml prevents a next in certain cases when positioned on end of element */
              if (xmlTextReaderNodeType(intern->ptr) == XML_READER_TYPE_END_ELEMENT) {
                     retval = xmlTextReaderRead(intern->ptr);
              } else
#endif
              retval = xmlTextReaderNext(intern->ptr);
              while (name != NULL && retval == 1) {
                     if (xmlStrEqual(xmlTextReaderConstLocalName(intern->ptr), (xmlChar *)name)) {
                            RETURN_TRUE;
                     }
                     retval = xmlTextReaderNext(intern->ptr); 
              }
              if (retval == -1) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading");
                     RETURN_FALSE;
              } else {
                     RETURN_BOOL(retval);
              }
       }
       
       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to read");
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
open   
)

Definition at line 864 of file php_xmlreader.c.

{
       zval *id;
       int source_len = 0, encoding_len = 0;
       long options = 0;
       xmlreader_object *intern = NULL;
       char *source, *valid_file = NULL;
       char *encoding = NULL;
       char resolved_path[MAXPATHLEN + 1];
       xmlTextReaderPtr reader = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
              return;
       }

       id = getThis();
       if (id != NULL) {
              if (! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry TSRMLS_CC)) {
                     id = NULL;
              } else {
                     intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
                     xmlreader_free_resources(intern);
              }
       }

       if (!source_len) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
              RETURN_FALSE;
       }

       valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);

       if (valid_file) {
              reader = xmlReaderForFile(valid_file, encoding, options);
       }

       if (reader == NULL) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open source data");
              RETURN_FALSE;
       }

       if (id == NULL) {
              object_init_ex(return_value, xmlreader_class_entry);
              intern = (xmlreader_object *)zend_objects_get_address(return_value TSRMLS_CC);
              intern->ptr = reader;
              return;
       }

       intern->ptr = reader;

       RETURN_TRUE;

}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
setParserProperty   
)

Definition at line 996 of file php_xmlreader.c.

{
       zval *id;
       long property;
       int retval = -1;
       zend_bool value;
       xmlreader_object *intern;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &property, &value) == FAILURE) {
              return;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retval = xmlTextReaderSetParserProp(intern->ptr,property, value);
       }
       if (retval == -1) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parser property");
              RETURN_FALSE;
       }

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
setRelaxNGSchema   
)

Definition at line 1025 of file php_xmlreader.c.

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
setRelaxNGSchemaSource   
)

Definition at line 1033 of file php_xmlreader.c.

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
XML   
)

Definition at line 1047 of file php_xmlreader.c.

{
       zval *id;
       int source_len = 0, encoding_len = 0;
       long options = 0;
       xmlreader_object *intern = NULL;
       char *source, *uri = NULL, *encoding = NULL;
       int resolved_path_len, ret = 0;
       char *directory=NULL, resolved_path[MAXPATHLEN];
       xmlParserInputBufferPtr inputbfr;
       xmlTextReaderPtr reader;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!l", &source, &source_len, &encoding, &encoding_len, &options) == FAILURE) {
              return;
       }

       id = getThis();
       if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), xmlreader_class_entry TSRMLS_CC)) {
              id = NULL;
       }
       if (id != NULL) {
              intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
              xmlreader_free_resources(intern);
       }

       if (!source_len) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
              RETURN_FALSE;
       }

       inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE);

    if (inputbfr != NULL) {
/* Get the URI of the current script so that we can set the base directory in libxml */
#if HAVE_GETCWD
              directory = VCWD_GETCWD(resolved_path, MAXPATHLEN);
#elif HAVE_GETWD
              directory = VCWD_GETWD(resolved_path);
#endif
              if (directory) {
                     resolved_path_len = strlen(resolved_path);
                     if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) {
                            resolved_path[resolved_path_len] = DEFAULT_SLASH;
                            resolved_path[++resolved_path_len] = '\0';
                     }
                     uri = (char *) xmlCanonicPath((const xmlChar *) resolved_path);
              }
              reader = xmlNewTextReader(inputbfr, uri);

              if (reader != NULL) {
#if LIBXML_VERSION >= 20628
                     ret = xmlTextReaderSetup(reader, NULL, uri, encoding, options);
#endif
                     if (ret == 0) {
                            if (id == NULL) {
                                   object_init_ex(return_value, xmlreader_class_entry);
                                   intern = (xmlreader_object *)zend_objects_get_address(return_value TSRMLS_CC);
                            } else {
                                   RETVAL_TRUE;
                            }
                            intern->input = inputbfr;
                            intern->ptr = reader;

                            if (uri) {
                                   xmlFree(uri);
                            }

                            return;
                     }
              }
       }

       if (uri) {
              xmlFree(uri);
       }

       if (inputbfr) {
              xmlFreeParserInputBuffer(inputbfr);
       }
       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load source data");
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_METHOD ( xmlreader  ,
expand   
)

Definition at line 1133 of file php_xmlreader.c.

{
#ifdef HAVE_DOM
       zval *id, *rv = NULL, *basenode = NULL;
       int ret;
       xmlreader_object *intern;
       xmlNode *node, *nodec;
       xmlDocPtr docp = NULL;
       php_libxml_node_object *domobj = NULL;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O!", &id, xmlreader_class_entry, &basenode, dom_node_class_entry) == FAILURE) {
              return;
       }
       
       if (basenode != NULL) {
              NODE_GET_OBJ(node, basenode, xmlNodePtr, domobj);
              docp = node->doc;
       }

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);

       if (intern && intern->ptr) {
              node = xmlTextReaderExpand(intern->ptr);
              
              if (node == NULL) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while expanding ");
                     RETURN_FALSE;
              } else {
                     nodec = xmlDocCopyNode(node, docp, 1);
                     if (nodec == NULL) {
                            php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot expand this node type");
                            RETURN_FALSE;
                     } else {
                            DOM_RET_OBJ(rv, nodec, &ret, (dom_object *)domobj);
                     }
              }
       } else {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Load Data before trying to expand");
              RETURN_FALSE;
       }
#else
       php_error(E_WARNING, "DOM support is not enabled");
       return;
#endif
}

Here is the call graph for this function:

PHP_MINFO_FUNCTION ( xmlreader  )

Definition at line 1393 of file php_xmlreader.c.

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( xmlreader  )

Definition at line 1314 of file php_xmlreader.c.

{
       
       zend_class_entry ce;
       
       memcpy(&xmlreader_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
       xmlreader_object_handlers.read_property = xmlreader_read_property;
       xmlreader_object_handlers.write_property = xmlreader_write_property;
       xmlreader_object_handlers.get_property_ptr_ptr = xmlreader_get_property_ptr_ptr;

       INIT_CLASS_ENTRY(ce, "XMLReader", xmlreader_functions);
       ce.create_object = xmlreader_objects_new;
       xmlreader_class_entry = zend_register_internal_class(&ce TSRMLS_CC);

       zend_hash_init(&xmlreader_prop_handlers, 0, NULL, NULL, 1);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "attributeCount", xmlTextReaderAttributeCount, NULL, IS_LONG TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "baseURI", NULL, xmlTextReaderConstBaseUri, IS_STRING TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "depth", xmlTextReaderDepth, NULL, IS_LONG TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasAttributes", xmlTextReaderHasAttributes, NULL, IS_BOOL TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasValue", xmlTextReaderHasValue, NULL, IS_BOOL TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isDefault", xmlTextReaderIsDefault, NULL, IS_BOOL TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isEmptyElement", xmlTextReaderIsEmptyElement, NULL, IS_BOOL TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "localName", NULL, xmlTextReaderConstLocalName, IS_STRING TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "name", NULL, xmlTextReaderConstName, IS_STRING TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "namespaceURI", NULL, xmlTextReaderConstNamespaceUri, IS_STRING TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "nodeType", xmlTextReaderNodeType, NULL, IS_LONG TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "prefix", NULL, xmlTextReaderConstPrefix, IS_STRING TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "value", NULL, xmlTextReaderConstValue, IS_STRING TSRMLS_CC);
       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "xmlLang", NULL, xmlTextReaderConstXmlLang, IS_STRING TSRMLS_CC);

       /* Constants for NodeType - cannot define common types to share with dom as there are differences in these types */

       REGISTER_XMLREADER_CLASS_CONST_LONG("NONE",      XML_READER_TYPE_NONE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("ELEMENT",   XML_READER_TYPE_ELEMENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("ATTRIBUTE", XML_READER_TYPE_ATTRIBUTE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("TEXT",      XML_READER_TYPE_TEXT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("CDATA",     XML_READER_TYPE_CDATA);
       REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY_REF",       XML_READER_TYPE_ENTITY_REFERENCE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("ENTITY",    XML_READER_TYPE_ENTITY);
       REGISTER_XMLREADER_CLASS_CONST_LONG("PI", XML_READER_TYPE_PROCESSING_INSTRUCTION);
       REGISTER_XMLREADER_CLASS_CONST_LONG("COMMENT",   XML_READER_TYPE_COMMENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("DOC",       XML_READER_TYPE_DOCUMENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_TYPE",  XML_READER_TYPE_DOCUMENT_TYPE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("DOC_FRAGMENT",     XML_READER_TYPE_DOCUMENT_FRAGMENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("NOTATION",  XML_READER_TYPE_NOTATION);
       REGISTER_XMLREADER_CLASS_CONST_LONG("WHITESPACE",       XML_READER_TYPE_WHITESPACE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("SIGNIFICANT_WHITESPACE",  XML_READER_TYPE_SIGNIFICANT_WHITESPACE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("END_ELEMENT",      XML_READER_TYPE_END_ELEMENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("END_ENTITY",       XML_READER_TYPE_END_ENTITY);
       REGISTER_XMLREADER_CLASS_CONST_LONG("XML_DECLARATION",  XML_READER_TYPE_XML_DECLARATION);

       /* Constants for Parser options */
       REGISTER_XMLREADER_CLASS_CONST_LONG("LOADDTD",   XML_PARSER_LOADDTD);
       REGISTER_XMLREADER_CLASS_CONST_LONG("DEFAULTATTRS",     XML_PARSER_DEFAULTATTRS);
       REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDATE",  XML_PARSER_VALIDATE);
       REGISTER_XMLREADER_CLASS_CONST_LONG("SUBST_ENTITIES",   XML_PARSER_SUBST_ENTITIES);

       /* Constants for Errors when loading - not yet used until we implement custom error handling
       REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_WARNING",        XML_PARSER_SEVERITY_VALIDITY_WARNING,     CONST_CS | CONST_PERSISTENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("VALIDITY_ERROR",          XML_PARSER_SEVERITY_VALIDITY_ERROR,              CONST_CS | CONST_PERSISTENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("WARNING",                        XML_PARSER_SEVERITY_WARNING,                     CONST_CS | CONST_PERSISTENT);
       REGISTER_XMLREADER_CLASS_CONST_LONG("ERROR",                          XML_PARSER_SEVERITY_ERROR,                       CONST_CS | CONST_PERSISTENT);
       */

       return SUCCESS;
}

Here is the call graph for this function:

PHP_MSHUTDOWN_FUNCTION ( xmlreader  )

Definition at line 1384 of file php_xmlreader.c.

Here is the call graph for this function:

static void php_xmlreader_no_arg ( INTERNAL_FUNCTION_PARAMETERS  ,
xmlreader_read_int_t  internal_function 
) [static]

Definition at line 446 of file php_xmlreader.c.

                                                                                                       {
       zval *id;
       int retval;
       xmlreader_object *intern;

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retval = internal_function(intern->ptr);
              if (retval == 1) {
                     RETURN_TRUE;
              }
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void php_xmlreader_set_relaxng_schema ( INTERNAL_FUNCTION_PARAMETERS  ,
int  type 
) [static]

Definition at line 490 of file php_xmlreader.c.

                                                                                     {
#ifdef LIBXML_SCHEMAS_ENABLED
       zval *id;
       int source_len = 0, retval = -1;
       xmlreader_object *intern;
       xmlRelaxNGPtr schema = NULL;
       char *source;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &source, &source_len) == FAILURE) {
              return;
       }

       if (source != NULL && !source_len) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Schema data source is required");
              RETURN_FALSE;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              if (source) {
                     schema =  _xmlreader_get_relaxNG(source, source_len, type, NULL, NULL TSRMLS_CC);
                     if (schema) {
                            retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, schema);
                     }
              } else {
                     /* unset the associated relaxNG context and schema if one exists */
                     retval = xmlTextReaderRelaxNGSetSchema(intern->ptr, NULL);
              }

              if (retval == 0) {
                     if (intern->schema) {
                            xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema);
                     }

                     intern->schema = schema;

                     RETURN_TRUE;
              }
       }
       
       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors.");

       RETURN_FALSE;
#else
       php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Schema support built into libxml.");

       RETURN_FALSE;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void php_xmlreader_string_arg ( INTERNAL_FUNCTION_PARAMETERS  ,
xmlreader_read_one_char_t  internal_function 
) [static]

Definition at line 413 of file php_xmlreader.c.

                                                                                                                {
       zval *id;
       int name_len = 0;
       char *retchar = NULL;
       xmlreader_object *intern;
       char *name;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
              return;
       }

       if (!name_len) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument cannot be an empty string");
              RETURN_FALSE;
       }

       id = getThis();

       intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
       if (intern && intern->ptr) {
              retchar = (char *)internal_function(intern->ptr, (const unsigned char *)name);
       }
       if (retchar) {
              RETVAL_STRING(retchar, 1);
              xmlFree(retchar);
              return;
       } else {
              RETVAL_NULL();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xmlreader_free_resources ( xmlreader_object intern) [static]

Definition at line 355 of file php_xmlreader.c.

                                                               {
       if (intern) {
              if (intern->input) {
                     xmlFreeParserInputBuffer(intern->input);
                     intern->input = NULL;
              }

              if (intern->ptr) {
                     xmlFreeTextReader(intern->ptr);
                     intern->ptr = NULL;
              }
#ifdef LIBXML_SCHEMAS_ENABLED
              if (intern->schema) {
                     xmlRelaxNGFree((xmlRelaxNGPtr) intern->schema);
                     intern->schema = NULL;
              }
#endif
       }
}

Here is the caller graph for this function:

zval** xmlreader_get_property_ptr_ptr ( zval *  object,
zval *member  TSRMLS_DC 
)

Definition at line 115 of file php_xmlreader.c.

{
       xmlreader_object *obj;
       zval tmp_member;
       zval **retval = NULL;
       xmlreader_prop_handler *hnd;
       zend_object_handlers *std_hnd;
       int ret = FAILURE;

       if (member->type != IS_STRING) {
              tmp_member = *member;
              zval_copy_ctor(&tmp_member);
              convert_to_string(&tmp_member);
              member = &tmp_member;
       }

       obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC);

       if (obj->prop_handler != NULL) {
              ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
       }
       if (ret == FAILURE) {
              std_hnd = zend_get_std_object_handlers();
              retval = std_hnd->get_property_ptr_ptr(object, member TSRMLS_CC);
       }

       if (member == &tmp_member) {
              zval_dtor(member);
       }
       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xmlreader_objects_clone ( void *  object,
void **object_clone  TSRMLS_DC 
)

Definition at line 348 of file php_xmlreader.c.

{
       /* TODO */
}

Here is the caller graph for this function:

void xmlreader_objects_free_storage ( void *object  TSRMLS_DC)

Definition at line 377 of file php_xmlreader.c.

Here is the call graph for this function:

Here is the caller graph for this function:

zend_object_value xmlreader_objects_new ( zend_class_entry *class_type  TSRMLS_DC)

Definition at line 390 of file php_xmlreader.c.

{
       zend_object_value retval;
       xmlreader_object *intern;
       zval *tmp;

       intern = emalloc(sizeof(xmlreader_object));
       memset(&intern->std, 0, sizeof(zend_object));
       intern->ptr = NULL;
       intern->input = NULL;
       intern->schema = NULL;
       intern->prop_handler = &xmlreader_prop_handlers;

       zend_object_std_init(&intern->std, class_type TSRMLS_CC);
       zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
       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);
       intern->handle = retval.handle;
       retval.handlers = &xmlreader_object_handlers;
       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xmlreader_property_reader ( xmlreader_object obj,
xmlreader_prop_handler hnd,
zval **retval  TSRMLS_DC 
) [static]

Definition at line 71 of file php_xmlreader.c.

{
       const xmlChar *retchar = NULL;
       int retint = 0;

       if (obj->ptr != NULL) {
              if (hnd->read_char_func) {
                     retchar = hnd->read_char_func(obj->ptr);
              } else {
                     if (hnd->read_int_func) {
                            retint = hnd->read_int_func(obj->ptr);
                            if (retint == -1) {
                                   php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal libxml error returned");
                                   return FAILURE;
                            }
                     }
              }
       }

       ALLOC_ZVAL(*retval);

       switch (hnd->type) {
              case IS_STRING:
                     if (retchar) {
                            ZVAL_STRING(*retval, (char *) retchar, 1);
                     } else {
                            ZVAL_EMPTY_STRING(*retval);
                     }
                     break;
              case IS_BOOL:
                     ZVAL_BOOL(*retval, retint);
                     break;
              case IS_LONG:
                     ZVAL_LONG(*retval, retint);
                     break;
              default:
                     ZVAL_NULL(*retval);
       }

       return SUCCESS;
}

Here is the caller graph for this function:

zval* xmlreader_read_property ( zval *  object,
zval *  member,
int type  TSRMLS_DC 
)

Definition at line 149 of file php_xmlreader.c.

{
       xmlreader_object *obj;
       zval tmp_member;
       zval *retval;
       xmlreader_prop_handler *hnd;
       zend_object_handlers *std_hnd;
       int ret;

       if (member->type != IS_STRING) {
              tmp_member = *member;
              zval_copy_ctor(&tmp_member);
              convert_to_string(&tmp_member);
              member = &tmp_member;
       }

       ret = FAILURE;
       obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC);

       if (obj->prop_handler != NULL) {
              ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
       }
       if (ret == SUCCESS) {
              ret = xmlreader_property_reader(obj, hnd, &retval TSRMLS_CC);
              if (ret == SUCCESS) {
                     /* ensure we're creating a temporary variable */
                     Z_SET_REFCOUNT_P(retval, 0);
              } else {
                     retval = EG(uninitialized_zval_ptr);
              }
       } else {
              std_hnd = zend_get_std_object_handlers();
              retval = std_hnd->read_property(object, member, type TSRMLS_CC);
       }

       if (member == &tmp_member) {
              zval_dtor(member);
       }
       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 
) [static]

Definition at line 59 of file php_xmlreader.c.

{
       xmlreader_prop_handler hnd;
       
       hnd.read_char_func = read_char_func;
       hnd.read_int_func = read_int_func;
       hnd.type = rettype;
       zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(xmlreader_prop_handler), NULL);
}

Here is the caller graph for this function:

void xmlreader_write_property ( zval *  object,
zval *  member,
zval *value  TSRMLS_DC 
)

Definition at line 192 of file php_xmlreader.c.

{
       xmlreader_object *obj;
       zval tmp_member;
       xmlreader_prop_handler *hnd;
       zend_object_handlers *std_hnd;
       int ret;

       if (member->type != IS_STRING) {
              tmp_member = *member;
              zval_copy_ctor(&tmp_member);
              convert_to_string(&tmp_member);
              member = &tmp_member;
       }

       ret = FAILURE;
       obj = (xmlreader_object *)zend_objects_get_address(object TSRMLS_CC);

       if (obj->prop_handler != NULL) {
              ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
       }
       if (ret == SUCCESS) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot write to read-only property");
       } else {
              std_hnd = zend_get_std_object_handlers();
              std_hnd->write_property(object, member, value TSRMLS_CC);
       }

       if (member == &tmp_member) {
              zval_dtor(member);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

zend_class_entry* xmlreader_class_entry

Definition at line 35 of file php_xmlreader.c.

const zend_module_dep xmlreader_deps[] [static]
Initial value:

Definition at line 321 of file php_xmlreader.c.

Definition at line 1278 of file php_xmlreader.c.

zend_module_entry xmlreader_module_entry
Initial value:
 {
       STANDARD_MODULE_HEADER_EX, NULL,
       xmlreader_deps,
       "xmlreader",
       NULL,
       PHP_MINIT(xmlreader),
       PHP_MSHUTDOWN(xmlreader),
       NULL,
       NULL,
       PHP_MINFO(xmlreader),
       "0.1", 
       STANDARD_MODULE_PROPERTIES
}

Definition at line 328 of file php_xmlreader.c.

zend_object_handlers xmlreader_object_handlers [static]

Definition at line 37 of file php_xmlreader.c.

Definition at line 39 of file php_xmlreader.c.