php_dom.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Christian Stocker <chregu@php.net> |
  14. | Rob Richards <rrichards@php.net> |
  15. | Marcus Borger <helly@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef PHP_DOM_H
  19. #define PHP_DOM_H
  20. extern zend_module_entry dom_module_entry;
  21. #define phpext_dom_ptr &dom_module_entry
  22. #ifdef ZTS
  23. #include "TSRM.h"
  24. #endif
  25. #include <libxml/parser.h>
  26. #include <libxml/parserInternals.h>
  27. #include <libxml/tree.h>
  28. #include <libxml/uri.h>
  29. #include <libxml/xmlerror.h>
  30. #include <libxml/xinclude.h>
  31. #include <libxml/hash.h>
  32. #include <libxml/c14n.h>
  33. #ifdef LIBXML_HTML_ENABLED
  34. #include <libxml/HTMLparser.h>
  35. #include <libxml/HTMLtree.h>
  36. #endif
  37. #ifdef LIBXML_XPATH_ENABLED
  38. #include <libxml/xpath.h>
  39. #include <libxml/xpathInternals.h>
  40. #endif
  41. #ifdef LIBXML_XPTR_ENABLED
  42. #include <libxml/xpointer.h>
  43. #endif
  44. #ifdef PHP_WIN32
  45. #ifndef DOM_EXPORTS
  46. #define DOM_EXPORTS
  47. #endif
  48. #endif
  49. #include "xml_common.h"
  50. #include "ext/libxml/php_libxml.h"
  51. #include "zend_exceptions.h"
  52. #include "dom_ce.h"
  53. /* DOM API_VERSION, please bump it up, if you change anything in the API
  54. therefore it's easier for the script-programmers to check, what's working how
  55. Can be checked with phpversion("dom");
  56. */
  57. #define DOM_API_VERSION "20031129"
  58. /* Define a custom type for iterating using an unused nodetype */
  59. #define DOM_NODESET XML_XINCLUDE_START
  60. typedef struct _dom_xpath_object {
  61. int registerPhpFunctions;
  62. int register_node_ns;
  63. HashTable *registered_phpfunctions;
  64. HashTable *node_list;
  65. dom_object dom;
  66. } dom_xpath_object;
  67. static inline dom_xpath_object *php_xpath_obj_from_obj(zend_object *obj) {
  68. return (dom_xpath_object*)((char*)(obj)
  69. - XtOffsetOf(dom_xpath_object, dom) - XtOffsetOf(dom_object, std));
  70. }
  71. #define Z_XPATHOBJ_P(zv) php_xpath_obj_from_obj(Z_OBJ_P((zv)))
  72. typedef struct _dom_nnodemap_object {
  73. dom_object *baseobj;
  74. zval baseobj_zv;
  75. int nodetype;
  76. xmlHashTable *ht;
  77. xmlChar *local;
  78. xmlChar *ns;
  79. } dom_nnodemap_object;
  80. typedef struct {
  81. zend_object_iterator intern;
  82. zval curobj;
  83. HashPosition pos;
  84. } php_dom_iterator;
  85. #include "domexception.h"
  86. dom_object *dom_object_get_data(xmlNodePtr obj);
  87. dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document);
  88. zend_object *dom_objects_new(zend_class_entry *class_type);
  89. zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type);
  90. #ifdef LIBXML_XPATH_ENABLED
  91. zend_object *dom_xpath_objects_new(zend_class_entry *class_type);
  92. #endif
  93. int dom_get_strict_error(php_libxml_ref_obj *document);
  94. void php_dom_throw_error(int error_code, int strict_error);
  95. void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error);
  96. void node_list_unlink(xmlNodePtr node);
  97. int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len);
  98. xmlNsPtr dom_get_ns(xmlNodePtr node, char *uri, int *errorcode, char *prefix);
  99. void dom_set_old_ns(xmlDoc *doc, xmlNs *ns);
  100. void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep);
  101. xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName);
  102. void dom_normalize (xmlNodePtr nodep);
  103. xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, int *cur, int index);
  104. void php_dom_create_implementation(zval *retval);
  105. int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child);
  106. bool dom_has_feature(zend_string *feature, zend_string *version);
  107. int dom_node_is_read_only(xmlNodePtr node);
  108. int dom_node_children_valid(xmlNodePtr node);
  109. void php_dom_create_iterator(zval *return_value, int ce_type);
  110. void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns);
  111. xmlNodePtr create_notation(const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID);
  112. xmlNode *php_dom_libxml_hash_iter(xmlHashTable *ht, int index);
  113. xmlNode *php_dom_libxml_notation_iter(xmlHashTable *ht, int index);
  114. zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, int by_ref);
  115. void dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_class_entry *ce);
  116. void dom_parent_node_prepend(dom_object *context, zval *nodes, int nodesc);
  117. void dom_parent_node_append(dom_object *context, zval *nodes, int nodesc);
  118. void dom_parent_node_after(dom_object *context, zval *nodes, int nodesc);
  119. void dom_parent_node_before(dom_object *context, zval *nodes, int nodesc);
  120. void dom_child_node_remove(dom_object *context);
  121. #define DOM_GET_OBJ(__ptr, __id, __prtype, __intern) { \
  122. __intern = Z_DOMOBJ_P(__id); \
  123. if (__intern->ptr == NULL || !(__ptr = (__prtype)((php_libxml_node_ptr *)__intern->ptr)->node)) { \
  124. zend_throw_error(NULL, "Couldn't fetch %s", ZSTR_VAL(__intern->std.ce->name));\
  125. RETURN_THROWS();\
  126. } \
  127. }
  128. #define DOM_NO_ARGS() \
  129. if (zend_parse_parameters_none() == FAILURE) { \
  130. RETURN_THROWS(); \
  131. }
  132. #define DOM_NOT_IMPLEMENTED() \
  133. zend_throw_error(NULL, "Not yet implemented"); \
  134. RETURN_THROWS();
  135. #define DOM_NODELIST 0
  136. #define DOM_NAMEDNODEMAP 1
  137. PHP_MINIT_FUNCTION(dom);
  138. PHP_MSHUTDOWN_FUNCTION(dom);
  139. PHP_MINFO_FUNCTION(dom);
  140. #endif /* PHP_DOM_H */