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

LCOV - code coverage report
Current view: top level - ext/xmlwriter - php_xmlwriter.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 457 554 82.5 %
Date: 2018-09-14 Functions: 51 53 96.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2018 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt.                                 |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: Rob Richards <rrichards@php.net>                             |
      16             :   |         Pierre-A. Joye <pajoye@php.net>                              |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : #ifdef HAVE_CONFIG_H
      21             : #include "config.h"
      22             : #endif
      23             : 
      24             : 
      25             : #include "php.h"
      26             : #include "php_ini.h"
      27             : #include "ext/standard/info.h"
      28             : #include "php_xmlwriter.h"
      29             : #include "ext/standard/php_string.h"
      30             : 
      31             : #if LIBXML_VERSION >= 20605
      32             : static PHP_FUNCTION(xmlwriter_set_indent);
      33             : static PHP_FUNCTION(xmlwriter_set_indent_string);
      34             : #endif
      35             : static PHP_FUNCTION(xmlwriter_start_attribute);
      36             : static PHP_FUNCTION(xmlwriter_end_attribute);
      37             : static PHP_FUNCTION(xmlwriter_write_attribute);
      38             : #if LIBXML_VERSION > 20617
      39             : static PHP_FUNCTION(xmlwriter_start_attribute_ns);
      40             : static PHP_FUNCTION(xmlwriter_write_attribute_ns);
      41             : #endif
      42             : static PHP_FUNCTION(xmlwriter_start_element);
      43             : static PHP_FUNCTION(xmlwriter_end_element);
      44             : static PHP_FUNCTION(xmlwriter_full_end_element);
      45             : static PHP_FUNCTION(xmlwriter_start_element_ns);
      46             : static PHP_FUNCTION(xmlwriter_write_element);
      47             : static PHP_FUNCTION(xmlwriter_write_element_ns);
      48             : static PHP_FUNCTION(xmlwriter_start_pi);
      49             : static PHP_FUNCTION(xmlwriter_end_pi);
      50             : static PHP_FUNCTION(xmlwriter_write_pi);
      51             : static PHP_FUNCTION(xmlwriter_start_cdata);
      52             : static PHP_FUNCTION(xmlwriter_end_cdata);
      53             : static PHP_FUNCTION(xmlwriter_write_cdata);
      54             : static PHP_FUNCTION(xmlwriter_text);
      55             : static PHP_FUNCTION(xmlwriter_write_raw);
      56             : static PHP_FUNCTION(xmlwriter_start_document);
      57             : static PHP_FUNCTION(xmlwriter_end_document);
      58             : #if LIBXML_VERSION >= 20607
      59             : static PHP_FUNCTION(xmlwriter_start_comment);
      60             : static PHP_FUNCTION(xmlwriter_end_comment);
      61             : #endif
      62             : static PHP_FUNCTION(xmlwriter_write_comment);
      63             : static PHP_FUNCTION(xmlwriter_start_dtd);
      64             : static PHP_FUNCTION(xmlwriter_end_dtd);
      65             : static PHP_FUNCTION(xmlwriter_write_dtd);
      66             : static PHP_FUNCTION(xmlwriter_start_dtd_element);
      67             : static PHP_FUNCTION(xmlwriter_end_dtd_element);
      68             : static PHP_FUNCTION(xmlwriter_write_dtd_element);
      69             : #if LIBXML_VERSION > 20608
      70             : static PHP_FUNCTION(xmlwriter_start_dtd_attlist);
      71             : static PHP_FUNCTION(xmlwriter_end_dtd_attlist);
      72             : static PHP_FUNCTION(xmlwriter_write_dtd_attlist);
      73             : static PHP_FUNCTION(xmlwriter_start_dtd_entity);
      74             : static PHP_FUNCTION(xmlwriter_end_dtd_entity);
      75             : static PHP_FUNCTION(xmlwriter_write_dtd_entity);
      76             : #endif
      77             : static PHP_FUNCTION(xmlwriter_open_uri);
      78             : static PHP_FUNCTION(xmlwriter_open_memory);
      79             : static PHP_FUNCTION(xmlwriter_output_memory);
      80             : static PHP_FUNCTION(xmlwriter_flush);
      81             : 
      82             : static zend_class_entry *xmlwriter_class_entry_ce;
      83             : 
      84             : static void xmlwriter_free_resource_ptr(xmlwriter_object *intern);
      85             : static void xmlwriter_dtor(zend_resource *rsrc);
      86             : 
      87             : typedef int (*xmlwriter_read_one_char_t)(xmlTextWriterPtr writer, const xmlChar *content);
      88             : typedef int (*xmlwriter_read_int_t)(xmlTextWriterPtr writer);
      89             : 
      90             : /* {{{ xmlwriter_object_free_storage */
      91          37 : static void xmlwriter_free_resource_ptr(xmlwriter_object *intern)
      92             : {
      93          37 :         if (intern) {
      94          37 :                 if (intern->ptr) {
      95          37 :                         xmlFreeTextWriter(intern->ptr);
      96          37 :                         intern->ptr = NULL;
      97             :                 }
      98          37 :                 if (intern->output) {
      99          25 :                         xmlBufferFree(intern->output);
     100          25 :                         intern->output = NULL;
     101             :                 }
     102          37 :                 efree(intern);
     103             :         }
     104          37 : }
     105             : /* }}} */
     106             : 
     107             : /* {{{ XMLWRITER_FROM_OBJECT */
     108             : #define XMLWRITER_FROM_OBJECT(intern, object) \
     109             :         { \
     110             :                 ze_xmlwriter_object *obj = Z_XMLWRITER_P(object); \
     111             :                 intern = obj->xmlwriter_ptr; \
     112             :                 if (!intern) { \
     113             :                         php_error_docref(NULL, E_WARNING, "Invalid or uninitialized XMLWriter object"); \
     114             :                         RETURN_FALSE; \
     115             :                 } \
     116             :         }
     117             : /* }}} */
     118             : 
     119             : static zend_object_handlers xmlwriter_object_handlers;
     120             : 
     121             : /* {{{ xmlwriter_object_free_storage */
     122          18 : static void xmlwriter_object_free_storage(zend_object *object)
     123             : {
     124          18 :         ze_xmlwriter_object *intern = php_xmlwriter_fetch_object(object);
     125          18 :         if (!intern) {
     126           0 :                 return;
     127             :         }
     128          18 :         if (intern->xmlwriter_ptr) {
     129          15 :                 xmlwriter_free_resource_ptr(intern->xmlwriter_ptr);
     130             :         }
     131          18 :         intern->xmlwriter_ptr = NULL;
     132          18 :         zend_object_std_dtor(&intern->std);
     133             : }
     134             : /* }}} */
     135             : 
     136             : 
     137             : /* {{{ xmlwriter_object_new */
     138          18 : static zend_object *xmlwriter_object_new(zend_class_entry *class_type)
     139             : {
     140             :         ze_xmlwriter_object *intern;
     141             : 
     142          18 :         intern = zend_object_alloc(sizeof(ze_xmlwriter_object), class_type);
     143          18 :         zend_object_std_init(&intern->std, class_type);
     144          18 :         object_properties_init(&intern->std, class_type);
     145          18 :         intern->std.handlers = &xmlwriter_object_handlers;
     146             : 
     147          18 :         return &intern->std;
     148             : }
     149             : /* }}} */
     150             : 
     151             : #define XMLW_NAME_CHK(__err) \
     152             :         if (xmlValidateName((xmlChar *) name, 0) != 0) {        \
     153             :                 php_error_docref(NULL, E_WARNING, "%s", __err);       \
     154             :                 RETURN_FALSE;   \
     155             :         }       \
     156             : 
     157             : /* {{{ arginfo */
     158             : ZEND_BEGIN_ARG_INFO(arginfo_xmlwriter_void, 0)
     159             : ZEND_END_ARG_INFO()
     160             : 
     161             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_resource, 0, 0, 1)
     162             :         ZEND_ARG_INFO(0, xmlwriter)
     163             : ZEND_END_ARG_INFO()
     164             : 
     165             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_open_uri, 0, 0, 1)
     166             :         ZEND_ARG_INFO(0, uri)
     167             : ZEND_END_ARG_INFO()
     168             : 
     169             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_set_indent, 0, 0, 2)
     170             :         ZEND_ARG_INFO(0, xmlwriter)
     171             :         ZEND_ARG_INFO(0, indent)
     172             : ZEND_END_ARG_INFO()
     173             : 
     174             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_set_indent, 0, 0, 1)
     175             :         ZEND_ARG_INFO(0, indent)
     176             : ZEND_END_ARG_INFO()
     177             : 
     178             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_set_indent_string, 0, 0, 2)
     179             :         ZEND_ARG_INFO(0, xmlwriter)
     180             :         ZEND_ARG_INFO(0, indentString)
     181             : ZEND_END_ARG_INFO()
     182             : 
     183             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_set_indent_string, 0, 0, 1)
     184             :         ZEND_ARG_INFO(0, indentString)
     185             : ZEND_END_ARG_INFO()
     186             : 
     187             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_attribute, 0, 0, 2)
     188             :         ZEND_ARG_INFO(0, xmlwriter)
     189             :         ZEND_ARG_INFO(0, name)
     190             : ZEND_END_ARG_INFO()
     191             : 
     192             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_attribute, 0, 0, 1)
     193             :         ZEND_ARG_INFO(0, name)
     194             : ZEND_END_ARG_INFO()
     195             : 
     196             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_attribute_ns, 0, 0, 4)
     197             :         ZEND_ARG_INFO(0, xmlwriter)
     198             :         ZEND_ARG_INFO(0, prefix)
     199             :         ZEND_ARG_INFO(0, name)
     200             :         ZEND_ARG_INFO(0, uri)
     201             : ZEND_END_ARG_INFO()
     202             : 
     203             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_attribute_ns, 0, 0, 3)
     204             :         ZEND_ARG_INFO(0, prefix)
     205             :         ZEND_ARG_INFO(0, name)
     206             :         ZEND_ARG_INFO(0, uri)
     207             : ZEND_END_ARG_INFO()
     208             : 
     209             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_attribute_ns, 0, 0, 5)
     210             :         ZEND_ARG_INFO(0, xmlwriter)
     211             :         ZEND_ARG_INFO(0, prefix)
     212             :         ZEND_ARG_INFO(0, name)
     213             :         ZEND_ARG_INFO(0, uri)
     214             :         ZEND_ARG_INFO(0, content)
     215             : ZEND_END_ARG_INFO()
     216             : 
     217             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_attribute_ns, 0, 0, 4)
     218             :         ZEND_ARG_INFO(0, prefix)
     219             :         ZEND_ARG_INFO(0, name)
     220             :         ZEND_ARG_INFO(0, uri)
     221             :         ZEND_ARG_INFO(0, content)
     222             : ZEND_END_ARG_INFO()
     223             : 
     224             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_attribute, 0, 0, 3)
     225             :         ZEND_ARG_INFO(0, xmlwriter)
     226             :         ZEND_ARG_INFO(0, name)
     227             :         ZEND_ARG_INFO(0, value)
     228             : ZEND_END_ARG_INFO()
     229             : 
     230             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_attribute, 0, 0, 2)
     231             :         ZEND_ARG_INFO(0, name)
     232             :         ZEND_ARG_INFO(0, value)
     233             : ZEND_END_ARG_INFO()
     234             : 
     235             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_element, 0, 0, 2)
     236             :         ZEND_ARG_INFO(0, xmlwriter)
     237             :         ZEND_ARG_INFO(0, name)
     238             : ZEND_END_ARG_INFO()
     239             : 
     240             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_element, 0, 0, 1)
     241             :         ZEND_ARG_INFO(0, name)
     242             : ZEND_END_ARG_INFO()
     243             : 
     244             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_element_ns, 0, 0, 4)
     245             :         ZEND_ARG_INFO(0, xmlwriter)
     246             :         ZEND_ARG_INFO(0, prefix)
     247             :         ZEND_ARG_INFO(0, name)
     248             :         ZEND_ARG_INFO(0, uri)
     249             : ZEND_END_ARG_INFO()
     250             : 
     251             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_element_ns, 0, 0, 3)
     252             :         ZEND_ARG_INFO(0, prefix)
     253             :         ZEND_ARG_INFO(0, name)
     254             :         ZEND_ARG_INFO(0, uri)
     255             : ZEND_END_ARG_INFO()
     256             : 
     257             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_element, 0, 0, 2)
     258             :         ZEND_ARG_INFO(0, xmlwriter)
     259             :         ZEND_ARG_INFO(0, name)
     260             :         ZEND_ARG_INFO(0, content)
     261             : ZEND_END_ARG_INFO()
     262             : 
     263             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_element, 0, 0, 1)
     264             :         ZEND_ARG_INFO(0, name)
     265             :         ZEND_ARG_INFO(0, content)
     266             : ZEND_END_ARG_INFO()
     267             : 
     268             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_element_ns, 0, 0, 4)
     269             :         ZEND_ARG_INFO(0, xmlwriter)
     270             :         ZEND_ARG_INFO(0, prefix)
     271             :         ZEND_ARG_INFO(0, name)
     272             :         ZEND_ARG_INFO(0, uri)
     273             :         ZEND_ARG_INFO(0, content)
     274             : ZEND_END_ARG_INFO()
     275             : 
     276             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_element_ns, 0, 0, 3)
     277             :         ZEND_ARG_INFO(0, prefix)
     278             :         ZEND_ARG_INFO(0, name)
     279             :         ZEND_ARG_INFO(0, uri)
     280             :         ZEND_ARG_INFO(0, content)
     281             : ZEND_END_ARG_INFO()
     282             : 
     283             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_pi, 0, 0, 2)
     284             :         ZEND_ARG_INFO(0, xmlwriter)
     285             :         ZEND_ARG_INFO(0, target)
     286             : ZEND_END_ARG_INFO()
     287             : 
     288             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_pi, 0, 0, 1)
     289             :         ZEND_ARG_INFO(0, target)
     290             : ZEND_END_ARG_INFO()
     291             : 
     292             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_pi, 0, 0, 3)
     293             :         ZEND_ARG_INFO(0, xmlwriter)
     294             :         ZEND_ARG_INFO(0, target)
     295             :         ZEND_ARG_INFO(0, content)
     296             : ZEND_END_ARG_INFO()
     297             : 
     298             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_pi, 0, 0, 2)
     299             :         ZEND_ARG_INFO(0, target)
     300             :         ZEND_ARG_INFO(0, content)
     301             : ZEND_END_ARG_INFO()
     302             : 
     303             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_cdata, 0, 0, 2)
     304             :         ZEND_ARG_INFO(0, xmlwriter)
     305             :         ZEND_ARG_INFO(0, content)
     306             : ZEND_END_ARG_INFO()
     307             : 
     308             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_cdata, 0, 0, 1)
     309             :         ZEND_ARG_INFO(0, content)
     310             : ZEND_END_ARG_INFO()
     311             : 
     312             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_text, 0, 0, 2)
     313             :         ZEND_ARG_INFO(0, xmlwriter)
     314             :         ZEND_ARG_INFO(0, content)
     315             : ZEND_END_ARG_INFO()
     316             : 
     317             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_text, 0, 0, 1)
     318             :         ZEND_ARG_INFO(0, content)
     319             : ZEND_END_ARG_INFO()
     320             : 
     321             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_raw, 0, 0, 2)
     322             :         ZEND_ARG_INFO(0, xmlwriter)
     323             :         ZEND_ARG_INFO(0, content)
     324             : ZEND_END_ARG_INFO()
     325             : 
     326             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_raw, 0, 0, 1)
     327             :         ZEND_ARG_INFO(0, content)
     328             : ZEND_END_ARG_INFO()
     329             : 
     330             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_document, 0, 0, 1)
     331             :         ZEND_ARG_INFO(0, xmlwriter)
     332             :         ZEND_ARG_INFO(0, version)
     333             :         ZEND_ARG_INFO(0, encoding)
     334             :         ZEND_ARG_INFO(0, standalone)
     335             : ZEND_END_ARG_INFO()
     336             : 
     337             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_document, 0, 0, 0)
     338             :         ZEND_ARG_INFO(0, version)
     339             :         ZEND_ARG_INFO(0, encoding)
     340             :         ZEND_ARG_INFO(0, standalone)
     341             : ZEND_END_ARG_INFO()
     342             : 
     343             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_comment, 0, 0, 2)
     344             :         ZEND_ARG_INFO(0, xmlwriter)
     345             :         ZEND_ARG_INFO(0, content)
     346             : ZEND_END_ARG_INFO()
     347             : 
     348             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_comment, 0, 0, 1)
     349             :         ZEND_ARG_INFO(0, content)
     350             : ZEND_END_ARG_INFO()
     351             : 
     352             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd, 0, 0, 2)
     353             :         ZEND_ARG_INFO(0, xmlwriter)
     354             :         ZEND_ARG_INFO(0, qualifiedName)
     355             :         ZEND_ARG_INFO(0, publicId)
     356             :         ZEND_ARG_INFO(0, systemId)
     357             : ZEND_END_ARG_INFO()
     358             : 
     359             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd, 0, 0, 1)
     360             :         ZEND_ARG_INFO(0, qualifiedName)
     361             :         ZEND_ARG_INFO(0, publicId)
     362             :         ZEND_ARG_INFO(0, systemId)
     363             : ZEND_END_ARG_INFO()
     364             : 
     365             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd, 0, 0, 2)
     366             :         ZEND_ARG_INFO(0, xmlwriter)
     367             :         ZEND_ARG_INFO(0, name)
     368             :         ZEND_ARG_INFO(0, publicId)
     369             :         ZEND_ARG_INFO(0, systemId)
     370             :         ZEND_ARG_INFO(0, subset)
     371             : ZEND_END_ARG_INFO()
     372             : 
     373             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd, 0, 0, 1)
     374             :         ZEND_ARG_INFO(0, name)
     375             :         ZEND_ARG_INFO(0, publicId)
     376             :         ZEND_ARG_INFO(0, systemId)
     377             :         ZEND_ARG_INFO(0, subset)
     378             : ZEND_END_ARG_INFO()
     379             : 
     380             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_element, 0, 0, 2)
     381             :         ZEND_ARG_INFO(0, xmlwriter)
     382             :         ZEND_ARG_INFO(0, qualifiedName)
     383             : ZEND_END_ARG_INFO()
     384             : 
     385             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_element, 0, 0, 1)
     386             :         ZEND_ARG_INFO(0, qualifiedName)
     387             : ZEND_END_ARG_INFO()
     388             : 
     389             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_element, 0, 0, 3)
     390             :         ZEND_ARG_INFO(0, xmlwriter)
     391             :         ZEND_ARG_INFO(0, name)
     392             :         ZEND_ARG_INFO(0, content)
     393             : ZEND_END_ARG_INFO()
     394             : 
     395             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_element, 0, 0, 2)
     396             :         ZEND_ARG_INFO(0, name)
     397             :         ZEND_ARG_INFO(0, content)
     398             : ZEND_END_ARG_INFO()
     399             : 
     400             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_attlist, 0, 0, 2)
     401             :         ZEND_ARG_INFO(0, xmlwriter)
     402             :         ZEND_ARG_INFO(0, name)
     403             : ZEND_END_ARG_INFO()
     404             : 
     405             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_attlist, 0, 0, 1)
     406             :         ZEND_ARG_INFO(0, name)
     407             : ZEND_END_ARG_INFO()
     408             : 
     409             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_attlist, 0, 0, 3)
     410             :         ZEND_ARG_INFO(0, xmlwriter)
     411             :         ZEND_ARG_INFO(0, name)
     412             :         ZEND_ARG_INFO(0, content)
     413             : ZEND_END_ARG_INFO()
     414             : 
     415             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_attlist, 0, 0, 2)
     416             :         ZEND_ARG_INFO(0, name)
     417             :         ZEND_ARG_INFO(0, content)
     418             : ZEND_END_ARG_INFO()
     419             : 
     420             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_entity, 0, 0, 3)
     421             :         ZEND_ARG_INFO(0, xmlwriter)
     422             :         ZEND_ARG_INFO(0, name)
     423             :         ZEND_ARG_INFO(0, isparam)
     424             : ZEND_END_ARG_INFO()
     425             : 
     426             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_entity, 0, 0, 2)
     427             :         ZEND_ARG_INFO(0, name)
     428             :         ZEND_ARG_INFO(0, isparam)
     429             : ZEND_END_ARG_INFO()
     430             : 
     431             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_entity, 0, 0, 3)
     432             :         ZEND_ARG_INFO(0, xmlwriter)
     433             :         ZEND_ARG_INFO(0, name)
     434             :         ZEND_ARG_INFO(0, content)
     435             : ZEND_END_ARG_INFO()
     436             : 
     437             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_entity, 0, 0, 2)
     438             :         ZEND_ARG_INFO(0, name)
     439             :         ZEND_ARG_INFO(0, content)
     440             : ZEND_END_ARG_INFO()
     441             : 
     442             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_output_memory, 0, 0, 1)
     443             :         ZEND_ARG_INFO(0, xmlwriter)
     444             :         ZEND_ARG_INFO(0, flush)
     445             : ZEND_END_ARG_INFO()
     446             : 
     447             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_output_memory, 0, 0, 0)
     448             :         ZEND_ARG_INFO(0, flush)
     449             : ZEND_END_ARG_INFO()
     450             : 
     451             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_flush, 0, 0, 1)
     452             :         ZEND_ARG_INFO(0, xmlwriter)
     453             :         ZEND_ARG_INFO(0, empty)
     454             : ZEND_END_ARG_INFO()
     455             : 
     456             : ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_flush, 0, 0, 0)
     457             :         ZEND_ARG_INFO(0, empty)
     458             : ZEND_END_ARG_INFO()
     459             : /* }}} */
     460             : 
     461             : /* {{{ xmlwriter_functions */
     462             : static const zend_function_entry xmlwriter_functions[] = {
     463             :         PHP_FE(xmlwriter_open_uri,                      arginfo_xmlwriter_open_uri)
     464             :         PHP_FE(xmlwriter_open_memory,           arginfo_xmlwriter_void)
     465             : #if LIBXML_VERSION >= 20605
     466             :         PHP_FE(xmlwriter_set_indent,            arginfo_xmlwriter_set_indent)
     467             :         PHP_FE(xmlwriter_set_indent_string, arginfo_xmlwriter_set_indent_string)
     468             : #endif
     469             : #if LIBXML_VERSION >= 20607
     470             :         PHP_FE(xmlwriter_start_comment,         arginfo_xmlwriter_resource)
     471             :         PHP_FE(xmlwriter_end_comment,           arginfo_xmlwriter_resource)
     472             : #endif
     473             :         PHP_FE(xmlwriter_start_attribute,       arginfo_xmlwriter_start_attribute)
     474             :         PHP_FE(xmlwriter_end_attribute,         arginfo_xmlwriter_resource)
     475             :         PHP_FE(xmlwriter_write_attribute,       arginfo_xmlwriter_write_attribute)
     476             : #if LIBXML_VERSION > 20617
     477             :         PHP_FE(xmlwriter_start_attribute_ns,arginfo_xmlwriter_start_attribute_ns)
     478             :         PHP_FE(xmlwriter_write_attribute_ns,arginfo_xmlwriter_write_attribute_ns)
     479             : #endif
     480             :         PHP_FE(xmlwriter_start_element,         arginfo_xmlwriter_start_element)
     481             :         PHP_FE(xmlwriter_end_element,           arginfo_xmlwriter_resource)
     482             :         PHP_FE(xmlwriter_full_end_element,      arginfo_xmlwriter_resource)
     483             :         PHP_FE(xmlwriter_start_element_ns,      arginfo_xmlwriter_start_element_ns)
     484             :         PHP_FE(xmlwriter_write_element,         arginfo_xmlwriter_write_element)
     485             :         PHP_FE(xmlwriter_write_element_ns,      arginfo_xmlwriter_write_element_ns)
     486             :         PHP_FE(xmlwriter_start_pi,                      arginfo_xmlwriter_start_pi)
     487             :         PHP_FE(xmlwriter_end_pi,                        arginfo_xmlwriter_resource)
     488             :         PHP_FE(xmlwriter_write_pi,                      arginfo_xmlwriter_write_pi)
     489             :         PHP_FE(xmlwriter_start_cdata,           arginfo_xmlwriter_resource)
     490             :         PHP_FE(xmlwriter_end_cdata,                     arginfo_xmlwriter_resource)
     491             :         PHP_FE(xmlwriter_write_cdata,           arginfo_xmlwriter_write_cdata)
     492             :         PHP_FE(xmlwriter_text,                          arginfo_xmlwriter_text)
     493             :         PHP_FE(xmlwriter_write_raw,                     arginfo_xmlwriter_write_raw)
     494             :         PHP_FE(xmlwriter_start_document,        arginfo_xmlwriter_start_document)
     495             :         PHP_FE(xmlwriter_end_document,          arginfo_xmlwriter_resource)
     496             :         PHP_FE(xmlwriter_write_comment,         arginfo_xmlwriter_write_comment)
     497             :         PHP_FE(xmlwriter_start_dtd,                     arginfo_xmlwriter_start_dtd)
     498             :         PHP_FE(xmlwriter_end_dtd,                       arginfo_xmlwriter_resource)
     499             :         PHP_FE(xmlwriter_write_dtd,                     arginfo_xmlwriter_write_dtd)
     500             :         PHP_FE(xmlwriter_start_dtd_element,     arginfo_xmlwriter_start_dtd_element)
     501             :         PHP_FE(xmlwriter_end_dtd_element,       arginfo_xmlwriter_resource)
     502             :         PHP_FE(xmlwriter_write_dtd_element,     arginfo_xmlwriter_write_dtd_element)
     503             : #if LIBXML_VERSION > 20608
     504             :         PHP_FE(xmlwriter_start_dtd_attlist,     arginfo_xmlwriter_start_dtd_attlist)
     505             :         PHP_FE(xmlwriter_end_dtd_attlist,       arginfo_xmlwriter_resource)
     506             :         PHP_FE(xmlwriter_write_dtd_attlist,     arginfo_xmlwriter_write_dtd_attlist)
     507             :         PHP_FE(xmlwriter_start_dtd_entity,      arginfo_xmlwriter_start_dtd_entity)
     508             :         PHP_FE(xmlwriter_end_dtd_entity,        arginfo_xmlwriter_resource)
     509             :         PHP_FE(xmlwriter_write_dtd_entity,      arginfo_xmlwriter_write_dtd_entity)
     510             : #endif
     511             :         PHP_FE(xmlwriter_output_memory,         arginfo_xmlwriter_output_memory)
     512             :         PHP_FE(xmlwriter_flush,                         arginfo_xmlwriter_flush)
     513             :         PHP_FE_END
     514             : };
     515             : /* }}} */
     516             : 
     517             : /* {{{ xmlwriter_class_functions */
     518             : static const zend_function_entry xmlwriter_class_functions[] = {
     519             :         PHP_ME_MAPPING(openUri,         xmlwriter_open_uri,             arginfo_xmlwriter_open_uri, 0)
     520             :         PHP_ME_MAPPING(openMemory,      xmlwriter_open_memory,  arginfo_xmlwriter_void, 0)
     521             : #if LIBXML_VERSION >= 20605
     522             :         PHP_ME_MAPPING(setIndent,       xmlwriter_set_indent,   arginfo_xmlwriter_method_set_indent, 0)
     523             :         PHP_ME_MAPPING(setIndentString, xmlwriter_set_indent_string, arginfo_xmlwriter_method_set_indent_string, 0)
     524             : #endif
     525             : #if LIBXML_VERSION >= 20607
     526             :         PHP_ME_MAPPING(startComment,    xmlwriter_start_comment,        arginfo_xmlwriter_void, 0)
     527             :         PHP_ME_MAPPING(endComment,              xmlwriter_end_comment,          arginfo_xmlwriter_void, 0)
     528             : #endif
     529             :         PHP_ME_MAPPING(startAttribute,  xmlwriter_start_attribute,      arginfo_xmlwriter_method_start_attribute, 0)
     530             :         PHP_ME_MAPPING(endAttribute,    xmlwriter_end_attribute,        arginfo_xmlwriter_void, 0)
     531             :         PHP_ME_MAPPING(writeAttribute,  xmlwriter_write_attribute,      arginfo_xmlwriter_method_write_attribute, 0)
     532             : #if LIBXML_VERSION > 20617
     533             :         PHP_ME_MAPPING(startAttributeNs,        xmlwriter_start_attribute_ns,arginfo_xmlwriter_method_start_attribute_ns, 0)
     534             :         PHP_ME_MAPPING(writeAttributeNs,        xmlwriter_write_attribute_ns,arginfo_xmlwriter_method_write_attribute_ns, 0)
     535             : #endif
     536             :         PHP_ME_MAPPING(startElement,    xmlwriter_start_element,        arginfo_xmlwriter_method_start_element, 0)
     537             :         PHP_ME_MAPPING(endElement,              xmlwriter_end_element,          arginfo_xmlwriter_void, 0)
     538             :         PHP_ME_MAPPING(fullEndElement,  xmlwriter_full_end_element,     arginfo_xmlwriter_void, 0)
     539             :         PHP_ME_MAPPING(startElementNs,  xmlwriter_start_element_ns,     arginfo_xmlwriter_method_start_element_ns, 0)
     540             :         PHP_ME_MAPPING(writeElement,    xmlwriter_write_element,        arginfo_xmlwriter_method_write_element, 0)
     541             :         PHP_ME_MAPPING(writeElementNs,  xmlwriter_write_element_ns,     arginfo_xmlwriter_method_write_element_ns, 0)
     542             :         PHP_ME_MAPPING(startPi,                 xmlwriter_start_pi,                     arginfo_xmlwriter_method_start_pi, 0)
     543             :         PHP_ME_MAPPING(endPi,                   xmlwriter_end_pi,                       arginfo_xmlwriter_void, 0)
     544             :         PHP_ME_MAPPING(writePi,                 xmlwriter_write_pi,                     arginfo_xmlwriter_method_write_pi, 0)
     545             :         PHP_ME_MAPPING(startCdata,              xmlwriter_start_cdata,          arginfo_xmlwriter_void, 0)
     546             :         PHP_ME_MAPPING(endCdata,                xmlwriter_end_cdata,            arginfo_xmlwriter_void, 0)
     547             :         PHP_ME_MAPPING(writeCdata,              xmlwriter_write_cdata,          arginfo_xmlwriter_method_write_cdata, 0)
     548             :         PHP_ME_MAPPING(text,                    xmlwriter_text,                         arginfo_xmlwriter_method_text, 0)
     549             :         PHP_ME_MAPPING(writeRaw,                xmlwriter_write_raw,            arginfo_xmlwriter_method_write_raw, 0)
     550             :         PHP_ME_MAPPING(startDocument,   xmlwriter_start_document,       arginfo_xmlwriter_method_start_document, 0)
     551             :         PHP_ME_MAPPING(endDocument,             xmlwriter_end_document,         arginfo_xmlwriter_void, 0)
     552             :         PHP_ME_MAPPING(writeComment,    xmlwriter_write_comment,        arginfo_xmlwriter_method_write_comment, 0)
     553             :         PHP_ME_MAPPING(startDtd,                xmlwriter_start_dtd,            arginfo_xmlwriter_method_start_dtd, 0)
     554             :         PHP_ME_MAPPING(endDtd,                  xmlwriter_end_dtd,                      arginfo_xmlwriter_void, 0)
     555             :         PHP_ME_MAPPING(writeDtd,                xmlwriter_write_dtd,            arginfo_xmlwriter_method_write_dtd, 0)
     556             :         PHP_ME_MAPPING(startDtdElement, xmlwriter_start_dtd_element,arginfo_xmlwriter_method_start_dtd_element, 0)
     557             :         PHP_ME_MAPPING(endDtdElement,   xmlwriter_end_dtd_element,      arginfo_xmlwriter_void, 0)
     558             :         PHP_ME_MAPPING(writeDtdElement, xmlwriter_write_dtd_element,    arginfo_xmlwriter_method_write_dtd_element, 0)
     559             : #if LIBXML_VERSION > 20608
     560             :         PHP_ME_MAPPING(startDtdAttlist, xmlwriter_start_dtd_attlist,    arginfo_xmlwriter_method_start_dtd_attlist, 0)
     561             :         PHP_ME_MAPPING(endDtdAttlist,   xmlwriter_end_dtd_attlist,      arginfo_xmlwriter_void, 0)
     562             :         PHP_ME_MAPPING(writeDtdAttlist, xmlwriter_write_dtd_attlist,    arginfo_xmlwriter_method_write_dtd_attlist, 0)
     563             :         PHP_ME_MAPPING(startDtdEntity,  xmlwriter_start_dtd_entity,     arginfo_xmlwriter_method_start_dtd_entity, 0)
     564             :         PHP_ME_MAPPING(endDtdEntity,    xmlwriter_end_dtd_entity,       arginfo_xmlwriter_void, 0)
     565             :         PHP_ME_MAPPING(writeDtdEntity,  xmlwriter_write_dtd_entity,     arginfo_xmlwriter_method_write_dtd_entity, 0)
     566             : #endif
     567             :         PHP_ME_MAPPING(outputMemory,    xmlwriter_output_memory,        arginfo_xmlwriter_method_output_memory, 0)
     568             :         PHP_ME_MAPPING(flush,                   xmlwriter_flush,                        arginfo_xmlwriter_method_flush, 0)
     569             :         PHP_FE_END
     570             : };
     571             : /* }}} */
     572             : 
     573             : /* {{{ function prototypes */
     574             : static PHP_MINIT_FUNCTION(xmlwriter);
     575             : static PHP_MSHUTDOWN_FUNCTION(xmlwriter);
     576             : static PHP_MINFO_FUNCTION(xmlwriter);
     577             : 
     578             : static int le_xmlwriter;
     579             : /* }}} */
     580             : 
     581             : /* _xmlwriter_get_valid_file_path should be made a
     582             :         common function in libxml extension as code is common to a few xml extensions */
     583             : /* {{{ _xmlwriter_get_valid_file_path */
     584          16 : static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) {
     585             :         xmlURI *uri;
     586             :         xmlChar *escsource;
     587             :         char *file_dest;
     588          16 :         int isFileUri = 0;
     589             : 
     590          16 :         uri = xmlCreateURI();
     591          16 :         escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *) ":");
     592          16 :         xmlParseURIReference(uri, (char *)escsource);
     593          16 :         xmlFree(escsource);
     594             : 
     595          16 :         if (uri->scheme != NULL) {
     596             :                 /* absolute file uris - libxml only supports localhost or empty host */
     597           3 :                 if (strncasecmp(source, "file:///", 8) == 0) {
     598           2 :                         if (source[sizeof("file:///") - 1] == '\0') {
     599           1 :                                 xmlFreeURI(uri);
     600           1 :                                 return NULL;
     601             :                         }
     602           1 :                         isFileUri = 1;
     603             : #ifdef PHP_WIN32
     604             :                         source += 8;
     605             : #else
     606           1 :                         source += 7;
     607             : #endif
     608           1 :                 } else if (strncasecmp(source, "file://localhost/",17) == 0) {
     609           1 :                         if (source[sizeof("file://localhost/") - 1] == '\0') {
     610           1 :                                 xmlFreeURI(uri);
     611           1 :                                 return NULL;
     612             :                         }
     613             : 
     614           0 :                         isFileUri = 1;
     615             : #ifdef PHP_WIN32
     616             :                         source += 17;
     617             : #else
     618           0 :                         source += 16;
     619             : #endif
     620             :                 }
     621             :         }
     622             : 
     623          26 :         if ((uri->scheme == NULL || isFileUri)) {
     624             :                 char file_dirname[MAXPATHLEN];
     625             :                 size_t dir_len;
     626             : 
     627          14 :                 if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) {
     628           1 :                         xmlFreeURI(uri);
     629           3 :                         return NULL;
     630             :                 }
     631             : 
     632          13 :                 memcpy(file_dirname, source, strlen(source));
     633          13 :                 dir_len = php_dirname(file_dirname, strlen(source));
     634             : 
     635          13 :                 if (dir_len > 0) {
     636             :                         zend_stat_t buf;
     637          13 :                         if (php_sys_stat(file_dirname, &buf) != 0) {
     638           1 :                                 xmlFreeURI(uri);
     639           1 :                                 return NULL;
     640             :                         }
     641             :                 }
     642             : 
     643          12 :                 file_dest = resolved_path;
     644             :         } else {
     645           0 :                 file_dest = source;
     646             :         }
     647             : 
     648          12 :         xmlFreeURI(uri);
     649             : 
     650          12 :         return file_dest;
     651             : }
     652             : /* }}} */
     653             : 
     654             : /* {{{ xmlwriter_module_entry
     655             :  */
     656             : zend_module_entry xmlwriter_module_entry = {
     657             :         STANDARD_MODULE_HEADER,
     658             :         "xmlwriter",
     659             :         xmlwriter_functions,
     660             :         PHP_MINIT(xmlwriter),
     661             :         PHP_MSHUTDOWN(xmlwriter),
     662             :         NULL,
     663             :         NULL,
     664             :         PHP_MINFO(xmlwriter),
     665             :         PHP_XMLWRITER_VERSION,
     666             :         STANDARD_MODULE_PROPERTIES
     667             : };
     668             : /* }}} */
     669             : 
     670             : #ifdef COMPILE_DL_XMLWRITER
     671             : ZEND_GET_MODULE(xmlwriter)
     672             : #endif
     673             : 
     674             : /* {{{ xmlwriter_objects_clone
     675             : static void xmlwriter_objects_clone(void *object, void **object_clone)
     676             : {
     677             :         TODO
     678             : }
     679             : }}} */
     680             : 
     681             : /* {{{ xmlwriter_dtor */
     682          22 : static void xmlwriter_dtor(zend_resource *rsrc) {
     683             :         xmlwriter_object *intern;
     684             : 
     685          22 :         intern = (xmlwriter_object *) rsrc->ptr;
     686          22 :         xmlwriter_free_resource_ptr(intern);
     687          22 : }
     688             : /* }}} */
     689             : 
     690          88 : static void php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_one_char_t internal_function, char *err_string)
     691             : {
     692             :         zval *pind;
     693             :         xmlwriter_object *intern;
     694             :         xmlTextWriterPtr ptr;
     695             :         char *name;
     696             :         size_t name_len;
     697             :         int retval;
     698             : 
     699         176 :         zval *self = getThis();
     700             : 
     701          88 :         if (self) {
     702          39 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
     703           0 :                         return;
     704             :                 }
     705          39 :                 XMLWRITER_FROM_OBJECT(intern, self);
     706             :         } else {
     707          49 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &pind, &name, &name_len) == FAILURE) {
     708           1 :                         return;
     709             :                 }
     710             : 
     711          48 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     712           0 :                         RETURN_FALSE;
     713             :                 }
     714             :         }
     715             : 
     716          87 :         if (err_string != NULL) {
     717          52 :                 XMLW_NAME_CHK(err_string);
     718             :         }
     719             : 
     720          85 :         ptr = intern->ptr;
     721             : 
     722          85 :         if (ptr) {
     723          85 :                 retval = internal_function(ptr, (xmlChar *) name);
     724          85 :                 if (retval != -1) {
     725          85 :                         RETURN_TRUE;
     726             :                 }
     727             :         }
     728             : 
     729           0 :         RETURN_FALSE;
     730             : }
     731             : 
     732          83 : static void php_xmlwriter_end(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_int_t internal_function)
     733             : {
     734             :         zval *pind;
     735             :         xmlwriter_object *intern;
     736             :         xmlTextWriterPtr ptr;
     737             :         int retval;
     738         166 :         zval *self = getThis();
     739             : 
     740          83 :         if (self) {
     741          38 :                 XMLWRITER_FROM_OBJECT(intern, self);
     742          38 :                 if (zend_parse_parameters_none() == FAILURE) {
     743           1 :                         return;
     744             :                 }
     745             :         } else {
     746          45 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pind) == FAILURE) {
     747           0 :                         return;
     748             :                 }
     749          45 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     750           0 :                         RETURN_FALSE;
     751             :                 }
     752             :         }
     753             : 
     754          82 :         ptr = intern->ptr;
     755             : 
     756          82 :         if (ptr) {
     757          82 :                 retval = internal_function(ptr);
     758          82 :                 if (retval != -1) {
     759          80 :                         RETURN_TRUE;
     760             :                 }
     761             :         }
     762             : 
     763           2 :         RETURN_FALSE;
     764             : }
     765             : 
     766             : #if LIBXML_VERSION >= 20605
     767             : /* {{{ proto bool xmlwriter_set_indent(resource xmlwriter, bool indent)
     768             : Toggle indentation on/off - returns FALSE on error */
     769          16 : static PHP_FUNCTION(xmlwriter_set_indent)
     770             : {
     771             :         zval *pind;
     772             :         xmlwriter_object *intern;
     773             :         xmlTextWriterPtr ptr;
     774             :         int retval;
     775             :         zend_bool indent;
     776             : 
     777          32 :         zval *self = getThis();
     778             : 
     779          16 :         if (self) {
     780           8 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &indent) == FAILURE) {
     781           0 :                         return;
     782             :                 }
     783           8 :                 XMLWRITER_FROM_OBJECT(intern, self);
     784             :         } else {
     785           8 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &pind, &indent) == FAILURE) {
     786           0 :                         return;
     787             :                 }
     788           8 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     789           0 :                         RETURN_FALSE;
     790             :                 }
     791             :         }
     792             : 
     793             : 
     794          16 :         ptr = intern->ptr;
     795          16 :         if (ptr) {
     796          16 :                 retval = xmlTextWriterSetIndent(ptr, indent);
     797          16 :                 if (retval == 0) {
     798          16 :                         RETURN_TRUE;
     799             :                 }
     800             :         }
     801             : 
     802           0 :         RETURN_FALSE;
     803             : }
     804             : /* }}} */
     805             : 
     806             : /* {{{ proto bool xmlwriter_set_indent_string(resource xmlwriter, string indentString)
     807             : Set string used for indenting - returns FALSE on error */
     808           8 : static PHP_FUNCTION(xmlwriter_set_indent_string)
     809             : {
     810           8 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterSetIndentString, NULL);
     811           8 : }
     812             : /* }}} */
     813             : 
     814             : #endif
     815             : 
     816             : /* {{{ proto bool xmlwriter_start_attribute(resource xmlwriter, string name)
     817             : Create start attribute - returns FALSE on error */
     818           6 : static PHP_FUNCTION(xmlwriter_start_attribute)
     819             : {
     820           6 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartAttribute, "Invalid Attribute Name");
     821           6 : }
     822             : /* }}} */
     823             : 
     824             : /* {{{ proto bool xmlwriter_end_attribute(resource xmlwriter)
     825             : End attribute - returns FALSE on error */
     826          10 : static PHP_FUNCTION(xmlwriter_end_attribute)
     827             : {
     828          10 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndAttribute);
     829          10 : }
     830             : /* }}} */
     831             : 
     832             : #if LIBXML_VERSION > 20617
     833             : /* {{{ proto bool xmlwriter_start_attribute_ns(resource xmlwriter, string prefix, string name, string uri)
     834             : Create start namespaced attribute - returns FALSE on error */
     835           4 : static PHP_FUNCTION(xmlwriter_start_attribute_ns)
     836             : {
     837             :         zval *pind;
     838             :         xmlwriter_object *intern;
     839             :         xmlTextWriterPtr ptr;
     840             :         char *name, *prefix, *uri;
     841             :         size_t name_len, prefix_len, uri_len;
     842             :         int retval;
     843           8 :         zval *self = getThis();
     844             : 
     845           4 :         if (self) {
     846           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss!",
     847             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     848           0 :                         return;
     849             :                 }
     850           2 :                 XMLWRITER_FROM_OBJECT(intern, self);
     851             :         } else {
     852           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss!", &pind,
     853             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     854           0 :                         return;
     855             :                 }
     856           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     857           0 :                         RETURN_FALSE;
     858             :                 }
     859             :         }
     860             : 
     861           4 :         XMLW_NAME_CHK("Invalid Attribute Name");
     862             : 
     863           4 :         ptr = intern->ptr;
     864             : 
     865           4 :         if (ptr) {
     866           4 :                 retval = xmlTextWriterStartAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
     867           4 :                 if (retval != -1) {
     868           4 :                         RETURN_TRUE;
     869             :                 }
     870             :         }
     871             : 
     872           0 :         RETURN_FALSE;
     873             : }
     874             : /* }}} */
     875             : #endif
     876             : 
     877             : /* {{{ proto bool xmlwriter_write_attribute(resource xmlwriter, string name, string content)
     878             : Write full attribute - returns FALSE on error */
     879           9 : static PHP_FUNCTION(xmlwriter_write_attribute)
     880             : {
     881             :         zval *pind;
     882             :         xmlwriter_object *intern;
     883             :         xmlTextWriterPtr ptr;
     884             :         char *name, *content;
     885             :         size_t name_len, content_len;
     886             :         int retval;
     887          18 :         zval *self = getThis();
     888             : 
     889           9 :         if (self) {
     890           3 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
     891             :                         &name, &name_len, &content, &content_len) == FAILURE) {
     892           0 :                         return;
     893             :                 }
     894           3 :                 XMLWRITER_FROM_OBJECT(intern, self);
     895             :         } else {
     896           6 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
     897             :                         &name, &name_len, &content, &content_len) == FAILURE) {
     898           0 :                         return;
     899             :                 }
     900           6 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     901           0 :                         RETURN_FALSE;
     902             :                 }
     903             :         }
     904             : 
     905           9 :         XMLW_NAME_CHK("Invalid Attribute Name");
     906             : 
     907           9 :         ptr = intern->ptr;
     908             : 
     909           9 :         if (ptr) {
     910           9 :                 retval = xmlTextWriterWriteAttribute(ptr, (xmlChar *)name, (xmlChar *)content);
     911           9 :                 if (retval != -1) {
     912           9 :                         RETURN_TRUE;
     913             :                 }
     914             :         }
     915             : 
     916           0 :         RETURN_FALSE;
     917             : }
     918             : /* }}} */
     919             : 
     920             : #if LIBXML_VERSION > 20617
     921             : /* {{{ proto bool xmlwriter_write_attribute_ns(resource xmlwriter, string prefix, string name, string uri, string content)
     922             : Write full namespaced attribute - returns FALSE on error */
     923           7 : static PHP_FUNCTION(xmlwriter_write_attribute_ns)
     924             : {
     925             :         zval *pind;
     926             :         xmlwriter_object *intern;
     927             :         xmlTextWriterPtr ptr;
     928             :         char *name, *prefix, *uri, *content;
     929             :         size_t name_len, prefix_len, uri_len, content_len;
     930             :         int retval;
     931             : 
     932          14 :         zval *self = getThis();
     933             : 
     934           7 :         if (self) {
     935           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss!s",
     936             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
     937           0 :                         return;
     938             :                 }
     939           2 :                 XMLWRITER_FROM_OBJECT(intern, self);
     940             :         } else {
     941           5 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss!s", &pind,
     942             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
     943           1 :                         return;
     944             :                 }
     945           4 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     946           0 :                         RETURN_FALSE;
     947             :                 }
     948             :         }
     949             : 
     950           6 :         XMLW_NAME_CHK("Invalid Attribute Name");
     951             : 
     952           6 :         ptr = intern->ptr;
     953             : 
     954           6 :         if (ptr) {
     955           6 :                 retval = xmlTextWriterWriteAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
     956           6 :                 if (retval != -1) {
     957           5 :                         RETURN_TRUE;
     958             :                 }
     959             :         }
     960             : 
     961           1 :         RETURN_FALSE;
     962             : }
     963             : /* }}} */
     964             : #endif
     965             : 
     966             : /* {{{ proto bool xmlwriter_start_element(resource xmlwriter, string name)
     967             : Create start element tag - returns FALSE on error */
     968          40 : static PHP_FUNCTION(xmlwriter_start_element)
     969             : {
     970          40 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartElement, "Invalid Element Name");
     971          40 : }
     972             : /* }}} */
     973             : 
     974             : /* {{{ proto bool xmlwriter_start_element_ns(resource xmlwriter, string prefix, string name, string uri)
     975             : Create start namespaced element tag - returns FALSE on error */
     976           9 : static PHP_FUNCTION(xmlwriter_start_element_ns)
     977             : {
     978             :         zval *pind;
     979             :         xmlwriter_object *intern;
     980             :         xmlTextWriterPtr ptr;
     981             :         char *name, *prefix, *uri;
     982             :         size_t name_len, prefix_len, uri_len;
     983             :         int retval;
     984          18 :         zval *self = getThis();
     985             : 
     986           9 :         if (self) {
     987           5 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!ss!",
     988             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     989           0 :                         return;
     990             :                 }
     991           5 :                 XMLWRITER_FROM_OBJECT(intern, self);
     992             :         } else {
     993           4 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs!ss!", &pind,
     994             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     995           0 :                         return;
     996             :                 }
     997           4 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     998           0 :                         RETURN_FALSE;
     999             :                 }
    1000             :         }
    1001             : 
    1002           9 :         XMLW_NAME_CHK("Invalid Element Name");
    1003             : 
    1004           9 :         ptr = intern->ptr;
    1005             : 
    1006           9 :         if (ptr) {
    1007           9 :                 retval = xmlTextWriterStartElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
    1008           9 :                 if (retval != -1) {
    1009           9 :                         RETURN_TRUE;
    1010             :                 }
    1011             : 
    1012             :         }
    1013             : 
    1014           0 :         RETURN_FALSE;
    1015             : }
    1016             : /* }}} */
    1017             : 
    1018             : /* {{{ proto bool xmlwriter_end_element(resource xmlwriter)
    1019             : End current element - returns FALSE on error */
    1020          25 : static PHP_FUNCTION(xmlwriter_end_element)
    1021             : {
    1022          25 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndElement);
    1023          25 : }
    1024             : /* }}} */
    1025             : 
    1026             : /* {{{ proto bool xmlwriter_full_end_element(resource xmlwriter)
    1027             : End current element - returns FALSE on error */
    1028           6 : static PHP_FUNCTION(xmlwriter_full_end_element)
    1029             : {
    1030           6 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterFullEndElement);
    1031           6 : }
    1032             : /* }}} */
    1033             : 
    1034             : /* {{{ proto bool xmlwriter_write_element(resource xmlwriter, string name[, string content])
    1035             : Write full element tag - returns FALSE on error */
    1036           9 : static PHP_FUNCTION(xmlwriter_write_element)
    1037             : {
    1038             :         zval *pind;
    1039             :         xmlwriter_object *intern;
    1040             :         xmlTextWriterPtr ptr;
    1041           9 :         char *name, *content = NULL;
    1042             :         size_t name_len, content_len;
    1043             :         int retval;
    1044          18 :         zval *self = getThis();
    1045             : 
    1046           9 :         if (self) {
    1047           6 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!",
    1048             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1049           0 :                         return;
    1050             :                 }
    1051           6 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1052             :         } else {
    1053           3 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!", &pind,
    1054             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1055           0 :                         return;
    1056             :                 }
    1057           3 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1058           0 :                         RETURN_FALSE;
    1059             :                 }
    1060             :         }
    1061             : 
    1062           9 :         XMLW_NAME_CHK("Invalid Element Name");
    1063             : 
    1064           9 :         ptr = intern->ptr;
    1065             : 
    1066           9 :         if (ptr) {
    1067           9 :                 if (!content) {
    1068           2 :                         retval = xmlTextWriterStartElement(ptr, (xmlChar *)name);
    1069           2 :             if (retval == -1) {
    1070           0 :                 RETURN_FALSE;
    1071             :             }
    1072           2 :                         xmlTextWriterEndElement(ptr);
    1073           2 :             if (retval == -1) {
    1074           0 :                 RETURN_FALSE;
    1075             :             }
    1076             :                 } else {
    1077           7 :                         retval = xmlTextWriterWriteElement(ptr, (xmlChar *)name, (xmlChar *)content);
    1078             :                 }
    1079           9 :                 if (retval != -1) {
    1080           9 :                         RETURN_TRUE;
    1081             :                 }
    1082             :         }
    1083             : 
    1084           0 :         RETURN_FALSE;
    1085             : }
    1086             : /* }}} */
    1087             : 
    1088             : /* {{{ proto bool xmlwriter_write_element_ns(resource xmlwriter, string prefix, string name, string uri[, string content])
    1089             : Write full namesapced element tag - returns FALSE on error */
    1090          13 : static PHP_FUNCTION(xmlwriter_write_element_ns)
    1091             : {
    1092             :         zval *pind;
    1093             :         xmlwriter_object *intern;
    1094             :         xmlTextWriterPtr ptr;
    1095          13 :         char *name, *prefix, *uri, *content = NULL;
    1096             :         size_t name_len, prefix_len, uri_len, content_len;
    1097             :         int retval;
    1098          26 :         zval *self = getThis();
    1099             : 
    1100          13 :         if (self) {
    1101           9 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!ss!|s!",
    1102             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
    1103           0 :                         return;
    1104             :                 }
    1105           9 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1106             :         } else {
    1107           4 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs!ss!|s!", &pind,
    1108             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
    1109           0 :                         return;
    1110             :                 }
    1111           4 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1112           0 :                         RETURN_FALSE;
    1113             :                 }
    1114             :         }
    1115             : 
    1116          13 :         XMLW_NAME_CHK("Invalid Element Name");
    1117             : 
    1118          13 :         ptr = intern->ptr;
    1119             : 
    1120          13 :         if (ptr) {
    1121          13 :                 if (!content) {
    1122           2 :                         retval = xmlTextWriterStartElementNS(ptr,(xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
    1123           2 :             if (retval == -1) {
    1124           0 :                 RETURN_FALSE;
    1125             :             }
    1126           2 :                         retval = xmlTextWriterEndElement(ptr);
    1127           2 :             if (retval == -1) {
    1128           0 :                 RETURN_FALSE;
    1129             :             }
    1130             :                 } else {
    1131          11 :                         retval = xmlTextWriterWriteElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
    1132             :                 }
    1133          13 :                 if (retval != -1) {
    1134          13 :                         RETURN_TRUE;
    1135             :                 }
    1136             :         }
    1137             : 
    1138           0 :         RETURN_FALSE;
    1139             : }
    1140             : /* }}} */
    1141             : 
    1142             : /* {{{ proto bool xmlwriter_start_pi(resource xmlwriter, string target)
    1143             : Create start PI tag - returns FALSE on error */
    1144           2 : static PHP_FUNCTION(xmlwriter_start_pi)
    1145             : {
    1146           2 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartPI, "Invalid PI Target");
    1147           2 : }
    1148             : /* }}} */
    1149             : 
    1150             : /* {{{ proto bool xmlwriter_end_pi(resource xmlwriter)
    1151             : End current PI - returns FALSE on error */
    1152           2 : static PHP_FUNCTION(xmlwriter_end_pi)
    1153             : {
    1154           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndPI);
    1155           2 : }
    1156             : /* }}} */
    1157             : 
    1158             : /* {{{ proto bool xmlwriter_write_pi(resource xmlwriter, string target, string content)
    1159             : Write full PI tag - returns FALSE on error */
    1160           2 : static PHP_FUNCTION(xmlwriter_write_pi)
    1161             : {
    1162             :         zval *pind;
    1163             :         xmlwriter_object *intern;
    1164             :         xmlTextWriterPtr ptr;
    1165             :         char *name, *content;
    1166             :         size_t name_len, content_len;
    1167             :         int retval;
    1168             : 
    1169           4 :         zval *self = getThis();
    1170             : 
    1171           2 :         if (self) {
    1172           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
    1173             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1174           0 :                         return;
    1175             :                 }
    1176           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1177             :         } else {
    1178           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
    1179             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1180           0 :                         return;
    1181             :                 }
    1182           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1183           0 :                         RETURN_FALSE;
    1184             :                 }
    1185             :         }
    1186             : 
    1187           2 :         XMLW_NAME_CHK("Invalid PI Target");
    1188             : 
    1189           2 :         ptr = intern->ptr;
    1190             : 
    1191           2 :         if (ptr) {
    1192           2 :                 retval = xmlTextWriterWritePI(ptr, (xmlChar *)name, (xmlChar *)content);
    1193           2 :                 if (retval != -1) {
    1194           2 :                         RETURN_TRUE;
    1195             :                 }
    1196             :         }
    1197             : 
    1198           0 :         RETURN_FALSE;
    1199             : }
    1200             : /* }}} */
    1201             : 
    1202             : /* {{{ proto bool xmlwriter_start_cdata(resource xmlwriter)
    1203             : Create start CDATA tag - returns FALSE on error */
    1204           2 : static PHP_FUNCTION(xmlwriter_start_cdata)
    1205             : {
    1206             :         zval *pind;
    1207             :         xmlwriter_object *intern;
    1208             :         xmlTextWriterPtr ptr;
    1209             :         int retval;
    1210           4 :         zval *self = getThis();
    1211             : 
    1212           2 :         if (self) {
    1213           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1214             :         } else {
    1215           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pind) == FAILURE) {
    1216           0 :                         return;
    1217             :                 }
    1218           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1219           0 :                         RETURN_FALSE;
    1220             :                 }
    1221             :         }
    1222             : 
    1223           2 :         ptr = intern->ptr;
    1224             : 
    1225           2 :         if (ptr) {
    1226           2 :                 retval = xmlTextWriterStartCDATA(ptr);
    1227           2 :                 if (retval != -1) {
    1228           2 :                         RETURN_TRUE;
    1229             :                 }
    1230             :         }
    1231             : 
    1232           0 :         RETURN_FALSE;
    1233             : }
    1234             : /* }}} */
    1235             : 
    1236             : /* {{{ proto bool xmlwriter_end_cdata(resource xmlwriter)
    1237             : End current CDATA - returns FALSE on error */
    1238           2 : static PHP_FUNCTION(xmlwriter_end_cdata)
    1239             : {
    1240           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndCDATA);
    1241           2 : }
    1242             : /* }}} */
    1243             : 
    1244             : /* {{{ proto bool xmlwriter_write_cdata(resource xmlwriter, string content)
    1245             : Write full CDATA tag - returns FALSE on error */
    1246           0 : static PHP_FUNCTION(xmlwriter_write_cdata)
    1247             : {
    1248           0 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteCDATA, NULL);
    1249           0 : }
    1250             : /* }}} */
    1251             : 
    1252             : /* {{{ proto bool xmlwriter_write_raw(resource xmlwriter, string content)
    1253             : Write text - returns FALSE on error */
    1254           0 : static PHP_FUNCTION(xmlwriter_write_raw)
    1255             : {
    1256           0 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteRaw, NULL);
    1257           0 : }
    1258             : /* }}} */
    1259             : 
    1260             : /* {{{ proto bool xmlwriter_text(resource xmlwriter, string content)
    1261             : Write text - returns FALSE on error */
    1262          23 : static PHP_FUNCTION(xmlwriter_text)
    1263             : {
    1264          23 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteString, NULL);
    1265          23 : }
    1266             : /* }}} */
    1267             : 
    1268             : #if LIBXML_VERSION >= 20607
    1269             : /* {{{ proto bool xmlwriter_start_comment(resource xmlwriter)
    1270             : Create start comment - returns FALSE on error */
    1271           3 : static PHP_FUNCTION(xmlwriter_start_comment)
    1272             : {
    1273             :         zval *pind;
    1274             :         xmlwriter_object *intern;
    1275             :         xmlTextWriterPtr ptr;
    1276             :         int retval;
    1277           6 :         zval *self = getThis();
    1278             : 
    1279           3 :         if (self) {
    1280           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1281             :         } else {
    1282           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pind) == FAILURE) {
    1283           0 :                         return;
    1284             :                 }
    1285           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1286           0 :                         RETURN_FALSE;
    1287             :                 }
    1288             :         }
    1289             : 
    1290           3 :         ptr = intern->ptr;
    1291             : 
    1292           3 :         if (ptr) {
    1293           3 :                 retval = xmlTextWriterStartComment(ptr);
    1294           3 :                 if (retval != -1) {
    1295           3 :                         RETURN_TRUE;
    1296             :                 }
    1297             :         }
    1298             : 
    1299           0 :         RETURN_FALSE;
    1300             : }
    1301             : /* }}} */
    1302             : 
    1303             : /* {{{ proto bool xmlwriter_end_comment(resource xmlwriter)
    1304             : Create end comment - returns FALSE on error */
    1305           3 : static PHP_FUNCTION(xmlwriter_end_comment)
    1306             : {
    1307           3 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndComment);
    1308           3 : }
    1309             : /* }}} */
    1310             : #endif  /* LIBXML_VERSION >= 20607 */
    1311             : 
    1312             : 
    1313             : /* {{{ proto bool xmlwriter_write_comment(resource xmlwriter, string content)
    1314             : Write full comment tag - returns FALSE on error */
    1315           5 : static PHP_FUNCTION(xmlwriter_write_comment)
    1316             : {
    1317           5 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteComment, NULL);
    1318           5 : }
    1319             : /* }}} */
    1320             : 
    1321             : /* {{{ proto bool xmlwriter_start_document(resource xmlwriter, string version, string encoding, string standalone)
    1322             : Create document tag - returns FALSE on error */
    1323          29 : static PHP_FUNCTION(xmlwriter_start_document)
    1324             : {
    1325             :         zval *pind;
    1326             :         xmlwriter_object *intern;
    1327             :         xmlTextWriterPtr ptr;
    1328          29 :         char *version = NULL, *enc = NULL, *alone = NULL;
    1329             :         size_t version_len, enc_len, alone_len;
    1330             :         int retval;
    1331             : 
    1332          58 :         zval *self = getThis();
    1333             : 
    1334          29 :         if (self) {
    1335          14 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!", &version, &version_len, &enc, &enc_len, &alone, &alone_len) == FAILURE) {
    1336           0 :                         return;
    1337             :                 }
    1338          14 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1339             :         } else {
    1340          15 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!s!", &pind, &version, &version_len, &enc, &enc_len, &alone, &alone_len) == FAILURE) {
    1341           0 :                         return;
    1342             :                 }
    1343          15 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1344           0 :                         RETURN_FALSE;
    1345             :                 }
    1346             :         }
    1347             : 
    1348          29 :         ptr = intern->ptr;
    1349             : 
    1350          29 :         if (ptr) {
    1351          29 :                 retval = xmlTextWriterStartDocument(ptr, version, enc, alone);
    1352          29 :                 if (retval != -1) {
    1353          29 :                         RETURN_TRUE;
    1354             :                 }
    1355             :         }
    1356             : 
    1357           0 :         RETURN_FALSE;
    1358             : }
    1359             : /* }}} */
    1360             : 
    1361             : /* {{{ proto bool xmlwriter_end_document(resource xmlwriter)
    1362             : End current document - returns FALSE on error */
    1363          26 : static PHP_FUNCTION(xmlwriter_end_document)
    1364             : {
    1365          26 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDocument);
    1366          26 : }
    1367             : /* }}} */
    1368             : 
    1369             : /* {{{ proto bool xmlwriter_start_dtd(resource xmlwriter, string name, string pubid, string sysid)
    1370             : Create start DTD tag - returns FALSE on error */
    1371           4 : static PHP_FUNCTION(xmlwriter_start_dtd)
    1372             : {
    1373             :         zval *pind;
    1374             :         xmlwriter_object *intern;
    1375             :         xmlTextWriterPtr ptr;
    1376           4 :         char *name, *pubid = NULL, *sysid = NULL;
    1377             :         size_t name_len, pubid_len, sysid_len;
    1378             :         int retval;
    1379           8 :         zval *self = getThis();
    1380             : 
    1381           4 :         if (self) {
    1382           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!", &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len) == FAILURE) {
    1383           0 :                         return;
    1384             :                 }
    1385             : 
    1386           2 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1387             :         } else {
    1388           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!s!", &pind, &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len) == FAILURE) {
    1389           0 :                         return;
    1390             :                 }
    1391           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1392           0 :                         RETURN_FALSE;
    1393             :                 }
    1394             :         }
    1395           4 :         ptr = intern->ptr;
    1396             : 
    1397           4 :         if (ptr) {
    1398           4 :                 retval = xmlTextWriterStartDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid);
    1399           4 :                 if (retval != -1) {
    1400           4 :                         RETURN_TRUE;
    1401             :                 }
    1402             :         }
    1403             : 
    1404           0 :         RETURN_FALSE;
    1405             : }
    1406             : /* }}} */
    1407             : 
    1408             : /* {{{ proto bool xmlwriter_end_dtd(resource xmlwriter)
    1409             : End current DTD - returns FALSE on error */
    1410           4 : static PHP_FUNCTION(xmlwriter_end_dtd)
    1411             : {
    1412           4 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTD);
    1413           4 : }
    1414             : /* }}} */
    1415             : 
    1416             : /* {{{ proto bool xmlwriter_write_dtd(resource xmlwriter, string name, string pubid, string sysid, string subset)
    1417             : Write full DTD tag - returns FALSE on error */
    1418           3 : static PHP_FUNCTION(xmlwriter_write_dtd)
    1419             : {
    1420             :         zval *pind;
    1421             :         xmlwriter_object *intern;
    1422             :         xmlTextWriterPtr ptr;
    1423           3 :         char *name, *pubid = NULL, *sysid = NULL, *subset = NULL;
    1424             :         size_t name_len, pubid_len, sysid_len, subset_len;
    1425             :         int retval;
    1426           6 :         zval *self = getThis();
    1427             : 
    1428           3 :         if (self) {
    1429           0 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!s!", &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len, &subset, &subset_len) == FAILURE) {
    1430           0 :                         return;
    1431             :                 }
    1432             : 
    1433           0 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1434             :         } else {
    1435           3 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!s!s!", &pind, &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len, &subset, &subset_len) == FAILURE) {
    1436           1 :                         return;
    1437             :                 }
    1438             : 
    1439           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1440           0 :                         RETURN_FALSE;
    1441             :                 }
    1442             :         }
    1443             : 
    1444           2 :         ptr = intern->ptr;
    1445             : 
    1446           2 :         if (ptr) {
    1447           2 :                 retval = xmlTextWriterWriteDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)subset);
    1448           2 :                 if (retval != -1) {
    1449           1 :                         RETURN_TRUE;
    1450             :                 }
    1451             :         }
    1452             : 
    1453           1 :         RETURN_FALSE;
    1454             : }
    1455             : /* }}} */
    1456             : 
    1457             : /* {{{ proto bool xmlwriter_start_dtd_element(resource xmlwriter, string name)
    1458             : Create start DTD element - returns FALSE on error */
    1459           2 : static PHP_FUNCTION(xmlwriter_start_dtd_element)
    1460             : {
    1461           2 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDElement, "Invalid Element Name");
    1462           2 : }
    1463             : /* }}} */
    1464             : 
    1465             : /* {{{ proto bool xmlwriter_end_dtd_element(resource xmlwriter)
    1466             : End current DTD element - returns FALSE on error */
    1467           2 : static PHP_FUNCTION(xmlwriter_end_dtd_element)
    1468             : {
    1469           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDElement);
    1470           2 : }
    1471             : /* }}} */
    1472             : 
    1473             : /* {{{ proto bool xmlwriter_write_dtd_element(resource xmlwriter, string name, string content)
    1474             : Write full DTD element tag - returns FALSE on error */
    1475           2 : static PHP_FUNCTION(xmlwriter_write_dtd_element)
    1476             : {
    1477             :         zval *pind;
    1478             :         xmlwriter_object *intern;
    1479             :         xmlTextWriterPtr ptr;
    1480             :         char *name, *content;
    1481             :         size_t name_len, content_len;
    1482             :         int retval;
    1483           4 :         zval *self = getThis();
    1484             : 
    1485           2 :         if (self) {
    1486           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &content, &content_len) == FAILURE) {
    1487           0 :                         return;
    1488             :                 }
    1489           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1490             :         } else {
    1491           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
    1492             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1493           0 :                         return;
    1494             :                 }
    1495           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1496           0 :                         RETURN_FALSE;
    1497             :                 }
    1498             :         }
    1499             : 
    1500           2 :         XMLW_NAME_CHK("Invalid Element Name");
    1501             : 
    1502           2 :         ptr = intern->ptr;
    1503             : 
    1504           2 :         if (ptr) {
    1505           2 :                 retval = xmlTextWriterWriteDTDElement(ptr, (xmlChar *)name, (xmlChar *)content);
    1506           2 :                 if (retval != -1) {
    1507           2 :                         RETURN_TRUE;
    1508             :                 }
    1509             :         }
    1510             : 
    1511           0 :         RETURN_FALSE;
    1512             : }
    1513             : /* }}} */
    1514             : 
    1515             : #if LIBXML_VERSION > 20608
    1516             : /* {{{ proto bool xmlwriter_start_dtd_attlist(resource xmlwriter, string name)
    1517             : Create start DTD AttList - returns FALSE on error */
    1518           2 : static PHP_FUNCTION(xmlwriter_start_dtd_attlist)
    1519             : {
    1520           2 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDAttlist, "Invalid Element Name");
    1521           2 : }
    1522             : /* }}} */
    1523             : 
    1524             : /* {{{ proto bool xmlwriter_end_dtd_attlist(resource xmlwriter)
    1525             : End current DTD AttList - returns FALSE on error */
    1526           2 : static PHP_FUNCTION(xmlwriter_end_dtd_attlist)
    1527             : {
    1528           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDAttlist);
    1529           2 : }
    1530             : /* }}} */
    1531             : 
    1532             : /* {{{ proto bool xmlwriter_write_dtd_attlist(resource xmlwriter, string name, string content)
    1533             : Write full DTD AttList tag - returns FALSE on error */
    1534           2 : static PHP_FUNCTION(xmlwriter_write_dtd_attlist)
    1535             : {
    1536             :         zval *pind;
    1537             :         xmlwriter_object *intern;
    1538             :         xmlTextWriterPtr ptr;
    1539             :         char *name, *content;
    1540             :         size_t name_len, content_len;
    1541             :         int retval;
    1542           4 :         zval *self = getThis();
    1543             : 
    1544           2 :         if (self) {
    1545           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
    1546             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1547           0 :                         return;
    1548             :                 }
    1549           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1550             :         } else {
    1551           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
    1552             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1553           0 :                         return;
    1554             :                 }
    1555           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1556           0 :                         RETURN_FALSE;
    1557             :                 }
    1558             :         }
    1559             : 
    1560           2 :         XMLW_NAME_CHK("Invalid Element Name");
    1561             : 
    1562           2 :         ptr = intern->ptr;
    1563             : 
    1564           2 :         if (ptr) {
    1565           2 :                 retval = xmlTextWriterWriteDTDAttlist(ptr, (xmlChar *)name, (xmlChar *)content);
    1566           2 :                 if (retval != -1) {
    1567           2 :                         RETURN_TRUE;
    1568             :                 }
    1569             :         }
    1570             : 
    1571           0 :         RETURN_FALSE;
    1572             : }
    1573             : /* }}} */
    1574             : 
    1575             : /* {{{ proto bool xmlwriter_start_dtd_entity(resource xmlwriter, string name, bool isparam)
    1576             : Create start DTD Entity - returns FALSE on error */
    1577           1 : static PHP_FUNCTION(xmlwriter_start_dtd_entity)
    1578             : {
    1579             :         zval *pind;
    1580             :         xmlwriter_object *intern;
    1581             :         xmlTextWriterPtr ptr;
    1582             :         char *name;
    1583             :         size_t name_len;
    1584             :         int retval;
    1585             :         zend_bool isparm;
    1586           2 :         zval *self = getThis();
    1587             : 
    1588           1 :         if (self) {
    1589           0 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "sb", &name, &name_len, &isparm) == FAILURE) {
    1590           0 :                         return;
    1591             :                 }
    1592           0 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1593             :         } else {
    1594           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsb", &pind, &name, &name_len, &isparm) == FAILURE) {
    1595           0 :                         return;
    1596             :                 }
    1597           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1598           0 :                         RETURN_FALSE;
    1599             :                 }
    1600             :         }
    1601             : 
    1602           1 :         XMLW_NAME_CHK("Invalid Attribute Name");
    1603             : 
    1604           1 :         ptr = intern->ptr;
    1605             : 
    1606           1 :         if (ptr) {
    1607           1 :                 retval = xmlTextWriterStartDTDEntity(ptr, isparm, (xmlChar *)name);
    1608           1 :                 if (retval != -1) {
    1609           1 :                         RETURN_TRUE;
    1610             :                 }
    1611             :         }
    1612             : 
    1613           0 :         RETURN_FALSE;
    1614             : }
    1615             : /* }}} */
    1616             : 
    1617             : /* {{{ proto bool xmlwriter_end_dtd_entity(resource xmlwriter)
    1618             : End current DTD Entity - returns FALSE on error */
    1619           1 : static PHP_FUNCTION(xmlwriter_end_dtd_entity)
    1620             : {
    1621           1 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDEntity);
    1622           1 : }
    1623             : /* }}} */
    1624             : 
    1625             : /* {{{ proto bool xmlwriter_write_dtd_entity(resource xmlwriter, string name, string content [, bool pe [, string pubid [, string sysid [, string ndataid]]]])
    1626             : Write full DTD Entity tag - returns FALSE on error */
    1627           3 : static PHP_FUNCTION(xmlwriter_write_dtd_entity)
    1628             : {
    1629             :         zval *pind;
    1630             :         xmlwriter_object *intern;
    1631             :         xmlTextWriterPtr ptr;
    1632             :         char *name, *content;
    1633             :         size_t name_len, content_len;
    1634             :         int retval;
    1635             :         /* Optional parameters */
    1636           3 :         char *pubid = NULL, *sysid = NULL, *ndataid = NULL;
    1637           3 :         zend_bool pe = 0;
    1638             :         size_t pubid_len, sysid_len, ndataid_len;
    1639           6 :         zval *self = getThis();
    1640             : 
    1641           3 :         if (self) {
    1642           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bsss",
    1643             :                         &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len,
    1644             :                         &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) {
    1645           0 :                         return;
    1646             :                 }
    1647           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1648             :         } else {
    1649           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss|bsss", &pind,
    1650             :                         &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len,
    1651             :                         &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) {
    1652           0 :                         return;
    1653             :                 }
    1654           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1655           0 :                         RETURN_FALSE;
    1656             :                 }
    1657             :         }
    1658             : 
    1659           3 :         XMLW_NAME_CHK("Invalid Element Name");
    1660             : 
    1661           3 :         ptr = intern->ptr;
    1662             : 
    1663           3 :         if (ptr) {
    1664           3 :                 retval = xmlTextWriterWriteDTDEntity(ptr, pe, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)ndataid, (xmlChar *)content);
    1665           3 :                 if (retval != -1) {
    1666           3 :                         RETURN_TRUE;
    1667             :                 }
    1668             :         }
    1669             : 
    1670           0 :         RETURN_FALSE;
    1671             : }
    1672             : /* }}} */
    1673             : #endif
    1674             : 
    1675             : /* {{{ proto resource xmlwriter_open_uri(string source)
    1676             : Create new xmlwriter using source uri for output */
    1677          18 : static PHP_FUNCTION(xmlwriter_open_uri)
    1678             : {
    1679          18 :         char *valid_file = NULL;
    1680             :         xmlwriter_object *intern;
    1681             :         xmlTextWriterPtr ptr;
    1682             :         char *source;
    1683             :         char resolved_path[MAXPATHLEN + 1];
    1684             :         size_t source_len;
    1685          36 :         zval *self = getThis();
    1686          18 :         ze_xmlwriter_object *ze_obj = NULL;
    1687             : 
    1688          18 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &source, &source_len) == FAILURE) {
    1689           1 :                 return;
    1690             :         }
    1691             : 
    1692          17 :         if (self) {
    1693             :                 /* We do not use XMLWRITER_FROM_OBJECT, xmlwriter init function here */
    1694           4 :                 ze_obj = Z_XMLWRITER_P(self);
    1695             :         }
    1696             : 
    1697          17 :         if (source_len == 0) {
    1698           1 :                 php_error_docref(NULL, E_WARNING, "Empty string as source");
    1699           1 :                 RETURN_FALSE;
    1700             :         }
    1701             : 
    1702          16 :         valid_file = _xmlwriter_get_valid_file_path(source, resolved_path, MAXPATHLEN);
    1703          16 :         if (!valid_file) {
    1704           4 :                 php_error_docref(NULL, E_WARNING, "Unable to resolve file path");
    1705           4 :                 RETURN_FALSE;
    1706             :         }
    1707             : 
    1708          12 :         ptr = xmlNewTextWriterFilename(valid_file, 0);
    1709             : 
    1710          12 :         if (!ptr) {
    1711           0 :                 RETURN_FALSE;
    1712             :         }
    1713             : 
    1714          12 :         intern = emalloc(sizeof(xmlwriter_object));
    1715          12 :         intern->ptr = ptr;
    1716          12 :         intern->output = NULL;
    1717          12 :         if (self) {
    1718           4 :                 if (ze_obj->xmlwriter_ptr) {
    1719           0 :                         xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr);
    1720             :                 }
    1721           4 :                 ze_obj->xmlwriter_ptr = intern;
    1722           4 :                 RETURN_TRUE;
    1723             :         } else {
    1724           8 :                 RETURN_RES(zend_register_resource(intern, le_xmlwriter));
    1725             :         }
    1726             : }
    1727             : /* }}} */
    1728             : 
    1729             : /* {{{ proto resource xmlwriter_open_memory()
    1730             : Create new xmlwriter using memory for string output */
    1731          25 : static PHP_FUNCTION(xmlwriter_open_memory)
    1732             : {
    1733             :         xmlwriter_object *intern;
    1734             :         xmlTextWriterPtr ptr;
    1735             :         xmlBufferPtr buffer;
    1736          50 :         zval *self = getThis();
    1737          25 :         ze_xmlwriter_object *ze_obj = NULL;
    1738             : 
    1739          25 :         if (self) {
    1740             :                 /* We do not use XMLWRITER_FROM_OBJECT, xmlwriter init function here */
    1741          11 :                 ze_obj = Z_XMLWRITER_P(self);
    1742             :         }
    1743             : 
    1744          25 :         buffer = xmlBufferCreate();
    1745             : 
    1746          25 :         if (buffer == NULL) {
    1747           0 :                 php_error_docref(NULL, E_WARNING, "Unable to create output buffer");
    1748           0 :                 RETURN_FALSE;
    1749             :         }
    1750             : 
    1751          25 :         ptr = xmlNewTextWriterMemory(buffer, 0);
    1752          25 :         if (! ptr) {
    1753           0 :                 xmlBufferFree(buffer);
    1754           0 :                 RETURN_FALSE;
    1755             :         }
    1756             : 
    1757          25 :         intern = emalloc(sizeof(xmlwriter_object));
    1758          25 :         intern->ptr = ptr;
    1759          25 :         intern->output = buffer;
    1760          25 :         if (self) {
    1761          11 :                 if (ze_obj->xmlwriter_ptr) {
    1762           0 :                         xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr);
    1763             :                 }
    1764          11 :                 ze_obj->xmlwriter_ptr = intern;
    1765          11 :                 RETURN_TRUE;
    1766             :         } else {
    1767          14 :                 RETURN_RES(zend_register_resource(intern, le_xmlwriter));
    1768             :         }
    1769             : 
    1770             : }
    1771             : /* }}} */
    1772             : 
    1773             : /* {{{ php_xmlwriter_flush */
    1774          34 : static void php_xmlwriter_flush(INTERNAL_FUNCTION_PARAMETERS, int force_string) {
    1775             :         zval *pind;
    1776             :         xmlwriter_object *intern;
    1777             :         xmlTextWriterPtr ptr;
    1778             :         xmlBufferPtr buffer;
    1779          34 :         zend_bool empty = 1;
    1780             :         int output_bytes;
    1781          68 :         zval *self = getThis();
    1782             : 
    1783          34 :         if (self) {
    1784          15 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &empty) == FAILURE) {
    1785           0 :                         return;
    1786             :                 }
    1787          15 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1788             :         } else {
    1789          19 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b", &pind, &empty) == FAILURE) {
    1790           0 :                         return;
    1791             :                 }
    1792             : 
    1793          19 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1794           0 :                         RETURN_FALSE;
    1795             :                 }
    1796             :         }
    1797          34 :         ptr = intern->ptr;
    1798             : 
    1799          34 :         if (ptr) {
    1800          34 :                 buffer = intern->output;
    1801          34 :                 if (force_string == 1 && buffer == NULL) {
    1802           0 :                         RETURN_EMPTY_STRING();
    1803             :                 }
    1804          34 :                 output_bytes = xmlTextWriterFlush(ptr);
    1805          34 :                 if (buffer) {
    1806          50 :                         RETVAL_STRING((char *) buffer->content);
    1807          25 :                         if (empty) {
    1808          25 :                                 xmlBufferEmpty(buffer);
    1809             :                         }
    1810             :                 } else {
    1811           9 :                         RETVAL_LONG(output_bytes);
    1812             :                 }
    1813          34 :                 return;
    1814             :         }
    1815             : 
    1816           0 :         RETURN_EMPTY_STRING();
    1817             : }
    1818             : /* }}} */
    1819             : 
    1820             : /* {{{ proto string xmlwriter_output_memory(resource xmlwriter [,bool flush])
    1821             : Output current buffer as string */
    1822           1 : static PHP_FUNCTION(xmlwriter_output_memory)
    1823             : {
    1824           1 :         php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    1825           1 : }
    1826             : /* }}} */
    1827             : 
    1828             : /* {{{ proto mixed xmlwriter_flush(resource xmlwriter [,bool empty])
    1829             : Output current buffer */
    1830          33 : static PHP_FUNCTION(xmlwriter_flush)
    1831             : {
    1832          33 :         php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    1833          33 : }
    1834             : /* }}} */
    1835             : 
    1836             : /* {{{ PHP_MINIT_FUNCTION
    1837             :  */
    1838       25189 : static PHP_MINIT_FUNCTION(xmlwriter)
    1839             : {
    1840             :         zend_class_entry ce;
    1841       25189 :         le_xmlwriter = zend_register_list_destructors_ex(xmlwriter_dtor, NULL, "xmlwriter", module_number);
    1842             : 
    1843       25189 :         memcpy(&xmlwriter_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
    1844       25189 :         xmlwriter_object_handlers.offset = XtOffsetOf(ze_xmlwriter_object, std);
    1845       25189 :         xmlwriter_object_handlers.free_obj = xmlwriter_object_free_storage;
    1846       25189 :         xmlwriter_object_handlers.clone_obj = NULL;
    1847       25189 :         INIT_CLASS_ENTRY(ce, "XMLWriter", xmlwriter_class_functions);
    1848       25189 :         ce.create_object = xmlwriter_object_new;
    1849       25189 :         xmlwriter_class_entry_ce = zend_register_internal_class(&ce);
    1850             : 
    1851       25189 :         return SUCCESS;
    1852             : }
    1853             : /* }}} */
    1854             : 
    1855             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    1856             :  */
    1857       25247 : static PHP_MSHUTDOWN_FUNCTION(xmlwriter)
    1858             : {
    1859       25247 :         return SUCCESS;
    1860             : }
    1861             : /* }}} */
    1862             : 
    1863             : /* {{{ PHP_MINFO_FUNCTION
    1864             :  */
    1865         146 : static PHP_MINFO_FUNCTION(xmlwriter)
    1866             : {
    1867         146 :         php_info_print_table_start();
    1868             :         {
    1869         146 :                 php_info_print_table_row(2, "XMLWriter", "enabled");
    1870             :         }
    1871         146 :         php_info_print_table_end();
    1872         146 : }
    1873             : /* }}} */
    1874             : 
    1875             : /*
    1876             :  * Local variables:
    1877             :  * tab-width: 4
    1878             :  * c-basic-offset: 4
    1879             :  * End:
    1880             :  * vim600: noet sw=4 ts=4 fdm=marker
    1881             :  * vim<600: noet sw=4 ts=4
    1882             :  */

Generated by: LCOV version 1.10

Generated at Sat, 15 Sep 2018 00:36:48 +0000 (7 days ago)

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