]> granicus.if.org Git - php/commitdiff
# sorry for the mixing of different things in this commit
authorChristian Stocker <chregu@php.net>
Fri, 18 Jan 2002 07:58:47 +0000 (07:58 +0000)
committerChristian Stocker <chregu@php.net>
Fri, 18 Jan 2002 07:58:47 +0000 (07:58 +0000)
- added DOMXML_PARAM_THREE macro
- renamed domxml_dumpmem to domxml_dump_mem, added alias for
  domxml_dumpmem
- domxml_has_attributes was missing in in zend_function_entry
@- added function domxml_dump_file($filename,[$compression]). Dumps XML to
@  a file and uses compression, if specified (chregu)
@- added exslt integration (see http://exslt.org for details). To be
@  configured with --with-dom-exslt[=DIR] (and --with-dom-xslt) (chregu, jaroslaw)

ext/domxml/config.m4
ext/domxml/php_domxml.c
ext/domxml/php_domxml.h

index 7005a4b9c3f03519f63f92730eb4ab786a93b4a0..cbe6d9ad5c5f1130fd0f002ba1a1f56bf6499716 100644 (file)
@@ -82,10 +82,31 @@ AC_DEFUN(PHP_DOM_XSLT_CHECK_VERSION,[
   CPPFLAGS=$old_CPPFLAGS
 ])
 
+AC_DEFUN(PHP_DOM_EXSLT_CHECK_VERSION,[
+  old_CPPFLAGS=$CPPFLAGS
+  CPPFLAGS=-I$DOMEXSLT_DIR/include
+  AC_MSG_CHECKING(for libexslt version)
+  AC_EGREP_CPP(yes,[
+  #include <libexslt/exsltconfig.h>
+  #if LIBEXSLT_VERSION >= 600
+  yes
+  #endif
+  ],[
+    AC_MSG_RESULT(>= 1.0.3)
+  ],[
+    AC_MSG_ERROR(libxslt version 1.0.3 or greater required.)
+  ])
+  CPPFLAGS=$old_CPPFLAGS
+])
+
 PHP_ARG_WITH(dom-xslt, for DOM XSLT support,
 [  --with-dom-xslt[=DIR]   Include DOM XSLT support (requires libxslt >= 1.0.3).
                           DIR is the libxslt install directory.])
 
+PHP_ARG_WITH(dom-exslt, for DOM EXSLT support,
+[  --with-dom-exslt[=DIR]   Include DOM EXSLT support (requires libxslt >= 1.0.3).
+                          DIR is the libexslt install directory.])
+
 if test "$PHP_DOM_XSLT" != "no"; then
 
   if test -r $PHP_DOM_XSLT/include/libxslt/transform.h; then
@@ -104,12 +125,48 @@ if test "$PHP_DOM_XSLT" != "no"; then
   PHP_DOM_XSLT_CHECK_VERSION
 
   PHP_ADD_LIBRARY_WITH_PATH(xslt, $DOMXSLT_DIR/lib, DOMXML_SHARED_LIBADD)
+
   PHP_ADD_INCLUDE($DOMXSLT_DIR/include)
 
-  if test "$DOMXML_DIR" = "no"; then
+  if test "$PHP_DOM" = "no"; then
     AC_MSG_ERROR(DOMXSLT requires DOMXML. Use --with-dom=<DIR>)
   fi
   
   AC_DEFINE(HAVE_DOMXSLT,1,[ ])
+  
+  PHP_SUBST(DOMXML_SHARED_LIBADD)
+fi
+
+if test "$PHP_DOM_EXSLT" != "no"; then
+  if test "$PHP_DOM" = "no"; then
+    AC_MSG_ERROR(DOMEXSLT requires DOMXML. Use --with-dom=<DIR>)
+  fi
+
+  if test "$PHP_DOM_XSLT" = "no"; then
+    AC_MSG_ERROR(DOMEXSLT requires DOMXSLT. Use --with-dom-xslt=<DIR>)
+  fi
+  
+  if test -r $PHP_DOM_EXSLT/include/libexslt/exslt.h; then
+    DOMEXSLT_DIR=$PHP_DOM_EXSLT
+  else
+    for i in /usr/local /usr; do
+      test -r $i/include/libexslt/exslt.h && DOMEXSLT_DIR=$i
+    done
+  fi
+
+  if test -z "$DOMEXSLT_DIR"; then
+    AC_MSG_RESULT(not found)
+    AC_MSG_ERROR(Please reinstall the libxslt >= 1.0.3 distribution)
+  fi
+
+  PHP_DOM_EXSLT_CHECK_VERSION
+
+  PHP_ADD_LIBRARY_WITH_PATH(exslt, $DOMEXSLT_DIR/lib, DOMXML_SHARED_LIBADD)
+
+  PHP_ADD_INCLUDE($DOMEXSLT_DIR/include)
+
+  AC_DEFINE(HAVE_DOMEXSLT,1,[ ])
+
   PHP_SUBST(DOMXML_SHARED_LIBADD)
+
 fi
index 08340312e88032b18b7086501820dfbbbfa46f8f..53e2280f898c00e8e568f4d63364980769692ab1 100644 (file)
                                                                                                        } \
                                                                                                        DOMXML_GET_OBJ(ret, zval, le);
 
+#define DOMXML_PARAM_THREE(ret, zval, le, s, p1, p2, p3)               if (NULL == (zval = getThis())) { \
+                                                                                                                                       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o"s, &zval, p1, p2, p3) == FAILURE) { \
+                                                                                                                                               return; \
+                                                                                                                                       } \
+                                                                                                                               } else { \
+                                                                                                                                       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, p1, p2, p3) == FAILURE) { \
+                                                                                                                                               return; \
+                                                                                                                                       } \
+                                                                                                                               } \
+                                                                                                                               DOMXML_GET_OBJ(ret, zval, le);
+
+
 #define DOMXML_PARAM_FOUR(ret, zval, le, s, p1, p2, p3, p4)            if (NULL == (zval = getThis())) { \
                                                                                                                                        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o"s, &zval, p1, p2, p3, p4) == FAILURE) { \
                                                                                                                                                return; \
                                                                                                                                } \
                                                                                                                                DOMXML_GET_OBJ(ret, zval, le);
 
+
 static int le_domxmldocp;
 static int le_domxmldoctypep;
 static int le_domxmldtdp;
@@ -165,7 +178,8 @@ static zend_function_entry domxml_functions[] = {
 #endif
        PHP_FE(xmltree,                                                                                                         NULL)
        PHP_FE(domxml_add_root,                                                                                         NULL)
-       PHP_FE(domxml_dumpmem,                                                                                          NULL)
+       PHP_FE(domxml_dump_mem,                                                                                         NULL)
+       PHP_FE(domxml_dump_mem_file,                                        NULL)
 #if defined(LIBXML_HTML_ENABLED)
        PHP_FE(domxml_html_dump_mem,                                                                                            NULL)
 #endif
@@ -173,6 +187,8 @@ static zend_function_entry domxml_functions[] = {
        PHP_FE(domxml_elem_get_attribute,                                                                       NULL)
        PHP_FE(domxml_elem_set_attribute,                                                                       NULL)
        PHP_FE(domxml_node_children,                                                                            NULL)
+       PHP_FE(domxml_node_has_attributes,                                                                              NULL)
+
        PHP_FE(domxml_node_new_child,                                                                           NULL)
        PHP_FE(domxml_node,                                                                                                     NULL)
        PHP_FE(domxml_node_unlink_node,                                                                         NULL)
@@ -208,6 +224,8 @@ static zend_function_entry domxml_functions[] = {
        PHP_FALIAS(domxml_unlink_node,          domxml_node_unlink_node,                NULL)
        PHP_FALIAS(set_content,                         domxml_node_set_content,                NULL)
        PHP_FALIAS(new_xmldoc,                          domxml_new_xmldoc,                              NULL)
+       PHP_FALIAS(domxml_dumpmem,         domxml_dump_mem,                                     NULL)
+
        {NULL, NULL, NULL}
 };
 
@@ -231,7 +249,9 @@ static function_entry php_domxmldoc_class_functions[] = {
        PHP_FALIAS(add_root,                            domxml_add_root,                                NULL)
        PHP_FALIAS(imported_node,                       domxml_doc_imported_node,               NULL)
        PHP_FALIAS(dtd,                                         domxml_intdtd,                                  NULL)
-       PHP_FALIAS(dumpmem,                                     domxml_dumpmem,                                 NULL)
+       PHP_FALIAS(dumpmem,                                     domxml_dump_mem,                                NULL)
+       PHP_FALIAS(dump_mem,                            domxml_dump_mem,                                NULL)
+       PHP_FALIAS(dump_mem_file,                       domxml_dump_mem_file,                   NULL)
 #if defined(LIBXML_HTML_ENABLED)
        PHP_FALIAS(html_dump_mem,                                       domxml_html_dump_mem,                                   NULL)
 #endif
@@ -245,13 +265,13 @@ static function_entry php_domxmldoc_class_functions[] = {
 
 static function_entry php_domxmldoctype_class_functions[] = {
        PHP_FALIAS(name,                                        domxml_doctype_name,                    NULL)
-/*     
+/*
        PHP_FALIAS(entities,                            domxml_doctype_entities,                NULL)
        PHP_FALIAS(notations,                           domxml_doctype_notations,               NULL)
        PHP_FALIAS(system_id,                           domxml_doctype_system_id,               NULL)
        PHP_FALIAS(public_id,                           domxml_doctype_public_id,               NULL)
        PHP_FALIAS(internal_subset,                     domxml_doctype_internal_subset, NULL)
-*/ 
+*/
        {NULL, NULL, NULL}
 };
 
@@ -277,6 +297,7 @@ static zend_function_entry php_domxmlnode_class_functions[] = {
        PHP_FALIAS(owner_document,                      domxml_node_owner_document,             NULL)
        PHP_FALIAS(new_child,                           domxml_node_new_child,                  NULL)
        PHP_FALIAS(attributes,                          domxml_node_attributes,                 NULL)
+       PHP_FALIAS(has_attributes,                              domxml_node_has_attributes,                     NULL)
        PHP_FALIAS(node,                                        domxml_node,                                    NULL)
        PHP_FALIAS(unlink,                                      domxml_node_unlink_node,                NULL)
        PHP_FALIAS(replace_node,                                domxml_node_replace_node,                       NULL)
@@ -328,7 +349,7 @@ static zend_function_entry php_domxmlentityref_class_functions[] = {
 };
 
 static zend_function_entry php_domxmlentity_class_functions[] = {
-/*     
+/*
        PHP_FALIAS(public_id,                           domxml_entity_public_id,                NULL)
        PHP_FALIAS(system_id,                           domxml_entity_system_id,                NULL)
        PHP_FALIAS(notation_name,                       domxml_entity_notation_name,    NULL)
@@ -359,7 +380,7 @@ static zend_function_entry php_domxmlattr_class_functions[] = {
        PHP_FALIAS(name,                                        domxml_attr_name,                               NULL)
        PHP_FALIAS(value,                                       domxml_attr_value,                              NULL)
        PHP_FALIAS(specified,                           domxml_attr_specified,                  NULL)
-/*     
+/*
        PHP_FALIAS(owner_element,                       domxml_attr_owner_element,              NULL)
 */
        {NULL, NULL, NULL}
@@ -408,14 +429,14 @@ static void dom_object_set_data(void *obj, zval *wrapper)
 
 static zval *dom_object_get_data(void *obj)
 {
-/*  
+/*
        char tmp[20];
        sprintf(tmp, "%08X", obj);
        fprintf(stderr, "Trying getting %s from object ...", tmp);
        if(((xmlNodePtr) obj)->_private)
                fprintf(stderr, " found\n");
        else
-               fprintf(stderr, " not found\n"); 
+               fprintf(stderr, " not found\n");
 */
        return ((zval *) (((xmlNodePtr) obj)->_private));
 }
@@ -541,14 +562,14 @@ static void xsltstylesheet_set_data(void *obj, zval *wrapper)
 
 static zval *xsltstylesheet_get_data(void *obj)
 {
-/*  
+/*
        char tmp[20];
        sprintf(tmp, "%08X", obj);
        fprintf(stderr, "Trying getting %s from object ...", tmp);
        if(((xmlNodePtr) obj)->_private)
                fprintf(stderr, " found\n");
        else
-               fprintf(stderr, " not found\n"); 
+               fprintf(stderr, " not found\n");
 */
        return ((zval *) (((xsltStylesheetPtr) obj)->_private));
 }
@@ -636,7 +657,7 @@ void *php_xpath_get_object(zval *wrapper, int rsrc_type1, int rsrc_type2 TSRMLS_
 
 static void xpath_object_set_data(void *obj, zval *wrapper)
 {
-/*     
+/*
        char tmp[20];
        sprintf(tmp, "%08X", obj);
        fprintf(stderr, "Adding %s to hash\n", tmp);
@@ -647,12 +668,12 @@ static void xpath_object_set_data(void *obj, zval *wrapper)
 
 static zval *xpath_object_get_data(void *obj)
 {
-/*     
+/*
        char tmp[20];
        sprintf(tmp, "%08X", obj);
-       fprintf(stderr, "Trying getting %s from hash ...", tmp); 
+       fprintf(stderr, "Trying getting %s from hash ...", tmp);
        if(((xmlXPathObjectPtr) obj)->user)
-               fprintf(stderr, " found\n"); 
+               fprintf(stderr, " found\n");
        else
                fprintf(stderr, " not found\n");
 */
@@ -703,7 +724,7 @@ static zval *php_xpathobject_new(xmlXPathObjectPtr obj, int *found TSRMLS_DC)
 
 /*
        rsrc_type = le_xpathobjectp;
-       php_xpath_set_object(wrapper, (void *) obj, rsrc_type); 
+       php_xpath_set_object(wrapper, (void *) obj, rsrc_type);
 */
 
        php_xpath_set_object(wrapper, (void *) obj, le_xpathobjectp);
@@ -757,9 +778,9 @@ static zval *xpath_context_get_data(void *obj)
 /*
        char tmp[20];
        sprintf(tmp, "%08X", obj);
-       fprintf(stderr, "Trying getting %s from hash ...", tmp); 
+       fprintf(stderr, "Trying getting %s from hash ...", tmp);
        if(((xmlXPathContextPtr) obj)->user)
-               fprintf(stderr, " found\n"); 
+               fprintf(stderr, " found\n");
        else
                fprintf(stderr, " not found\n");
 */
@@ -806,8 +827,8 @@ static zval *php_xpathcontext_new(xmlXPathContextPtr obj, int *found TSRMLS_DC)
        }
 
        MAKE_STD_ZVAL(wrapper);
-/*     
-       fprintf(stderr, "Adding new XPath Context\n"); 
+/*
+       fprintf(stderr, "Adding new XPath Context\n");
 */
        object_init_ex(wrapper, xpathctx_class_entry);
        rsrc_type = le_xpathctxp;
@@ -1033,7 +1054,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
                        break;
                }
 
-               default: 
+               default:
                        php_error(E_WARNING, "%s(): unsupported node type: %d\n", get_active_function_name(TSRMLS_C), Z_TYPE_P(obj));
                        FREE_ZVAL(wrapper);
                        return NULL;
@@ -1196,8 +1217,12 @@ PHP_MINIT_FUNCTION(domxml)
        xmlSetGenericErrorFunc(xmlGenericErrorContext, (xmlGenericErrorFunc)domxml_error);
 #if HAVE_DOMXSLT
        xsltSetGenericErrorFunc(xsltGenericErrorContext, (xmlGenericErrorFunc)domxml_error);
+#if HAVE_DOMEXSLT
+       exsltRegisterAll();
+#endif
 #endif
 
+
        return SUCCESS;
 }
 
@@ -1235,7 +1260,12 @@ PHP_MINFO_FUNCTION(domxml)
 #if HAVE_DOMXSLT
        php_info_print_table_row(2, "DOM/XSLT", "enabled");
        php_info_print_table_row(2, "libxslt Version", LIBXSLT_DOTTED_VERSION);
+#if HAVE_DOMEXSLT
+       php_info_print_table_row(2, "DOM/EXSLT", "enabled");
+       php_info_print_table_row(2, "libexslt Version", LIBEXSLT_DOTTED_VERSION);
+#endif
 #endif
+
        php_info_print_table_end();
 }
 
@@ -1698,7 +1728,7 @@ PHP_FUNCTION(domxml_node_parent)
        int ret;
 
        DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
-       
+
        DOMXML_NO_ARGS();
 
        last = nodep->parent;
@@ -2173,7 +2203,7 @@ PHP_FUNCTION(domxml_elem_set_attribute_node)
        xmlAttr *attrp;
 
        DOMXML_NOT_IMPLEMENTED();
-       
+
        if ((ZEND_NUM_ARGS() == 1) && getParameters(ht, 1, &arg1) == SUCCESS) {
                id = getThis();
                nodep = php_dom_get_object(id, le_domxmlelementp, 0 TSRMLS_CC);
@@ -2538,9 +2568,9 @@ PHP_FUNCTION(domxml_intdtd)
 }
 /* }}} */
 
-/* {{{ proto string domxml_dumpmem([object doc_handle])
+/* {{{ proto string domxml_dump_mem([object doc_handle])
    Dumps document into string */
-PHP_FUNCTION(domxml_dumpmem)
+PHP_FUNCTION(domxml_dump_mem)
 {
        zval *id;
        xmlDoc *docp;
@@ -2548,7 +2578,6 @@ PHP_FUNCTION(domxml_dumpmem)
        int size;
 
        DOMXML_PARAM_NONE(docp, id, le_domxmldocp);
-
        xmlDocDumpMemory(docp, &mem, &size);
        if (!size) {
                RETURN_FALSE;
@@ -2557,6 +2586,30 @@ PHP_FUNCTION(domxml_dumpmem)
 }
 /* }}} */
 
+/* {{{ proto int domxml_dump_mem_file([object doc_handle],filename,compressmode)
+   Dumps document into file and uses compression if specified
+   Returns false on error, otherwise the length of the xml-document (uncompressed)
+   */
+PHP_FUNCTION(domxml_dump_mem_file)
+{
+       zval *id;
+       xmlDoc *docp;
+       int file_len, bytes;
+    int compressmode = 0;
+    char *file;
+       DOMXML_PARAM_THREE(docp, id, le_domxmldocp, "s|l", &file, &file_len, &compressmode);
+
+    xmlSetCompressMode (compressmode);
+       bytes = xmlSaveFile(file,docp);
+    if (bytes == -1)
+    {
+        RETURN_FALSE;
+    }
+       RETURN_LONG(bytes);
+}
+/* }}} */
+
+
 /* {{{ proto object xmldoc(string xmldoc [, bool from_file])
    Creates DOM object of XML document */
 PHP_FUNCTION(xmldoc)
@@ -2714,7 +2767,7 @@ PHP_FUNCTION(domxml_node_text_concat)
        xmlNode *nodep;
        char *content;
        int content_len;
-       
+
        DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &content, &content_len) == FAILURE) {
@@ -2882,7 +2935,7 @@ static int node_children(zval **children, xmlNode *nodep TSRMLS_DC)
 
                        /* Get the namespace of the current node and add it as a property */
                        /* XXX FIXME XXX */
-/*             
+/*
                        if(!node_namespace(&namespace, last))
                                zend_hash_update(Z_OBJPROP_P(child), "namespace", sizeof("namespace"), (void *) &namespace, sizeof(zval *), NULL);
 */
@@ -2912,7 +2965,7 @@ PHP_FUNCTION(xmltree)
        xmlNode *root;
        int ret, buf_len;
        char *buf;
-       
+
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) == FAILURE) {
                return;
        }
@@ -3227,7 +3280,7 @@ static zval *php_xsltstylesheet_new(xsltStylesheetPtr obj, int *found TSRMLS_DC)
    Translates a PHP array to a libxslt character array */
 static void _php_libxslt_ht_char(HashTable *php, char **arr)
 {
-/* TODO: 
+/* TODO:
     - make parameters array('key'=>'string',...) instead of array('key'=>'XPathExpression')
     - change error reporting
 */
@@ -3235,7 +3288,7 @@ static void _php_libxslt_ht_char(HashTable *php, char **arr)
     char *string_key = NULL;
     ulong num_key;
     int i = 0;
-    
+
     for (zend_hash_internal_pointer_reset(php);
          zend_hash_get_current_data(php, (void **)&value) == SUCCESS;
          zend_hash_move_forward(php)) {
@@ -3384,7 +3437,7 @@ PHP_FUNCTION(domxml_xslt_process)
 
 /* ???: */
        efree(params);
-       
+
        if (!docp) {
                RETURN_FALSE;
        }
index 3d31e6adebddbfcf82ee3234ca0697e688654656..e58e1d3a81f61b55fde2cbdae316bfd33efadbf4 100644 (file)
 #include <libxslt/xsltInternals.h>
 #include <libxslt/xsltutils.h>
 #include <libxslt/transform.h>
+#if HAVE_DOMEXSLT
+#include <libexslt/exslt.h>
+#include <libexslt/exsltconfig.h>
+#endif
 #endif
 
 extern zend_module_entry domxml_module_entry;
@@ -74,7 +78,9 @@ PHP_FUNCTION(domxml_doc_create_entity_reference);
 PHP_FUNCTION(domxml_doc_imported_node);
 PHP_FUNCTION(domxml_add_root);
 PHP_FUNCTION(domxml_intdtd);
-PHP_FUNCTION(domxml_dumpmem);
+PHP_FUNCTION(domxml_dump_mem);
+PHP_FUNCTION(domxml_dump_mem_file);
+
 #if defined(LIBXML_HTML_ENABLED)
 PHP_FUNCTION(domxml_html_dump_mem);
 #endif