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

Generated by: LCOV version 1.10

Generated at Tue, 27 Sep 2016 10:26:10 +0000 (2 days ago)

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