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: 2015-08-04 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-2015 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          36 : static void xmlwriter_free_resource_ptr(xmlwriter_object *intern)
      94             : {
      95          36 :         if (intern) {
      96          36 :                 if (intern->ptr) {
      97          36 :                         xmlFreeTextWriter(intern->ptr);
      98          36 :                         intern->ptr = NULL;
      99             :                 }
     100          36 :                 if (intern->output) {
     101          25 :                         xmlBufferFree(intern->output);
     102          25 :                         intern->output = NULL;
     103             :                 }
     104          36 :                 efree(intern);
     105             :         }
     106          36 : }
     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             :         {NULL, NULL, NULL}
     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          15 : 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          15 :         int isFileUri = 0;
     591             : 
     592          15 :         uri = xmlCreateURI();
     593          15 :         escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *) ":");
     594          15 :         xmlParseURIReference(uri, (char *)escsource);
     595          15 :         xmlFree(escsource);
     596             : 
     597          15 :         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          24 :         if ((uri->scheme == NULL || isFileUri)) {
     626             :                 char file_dirname[MAXPATHLEN];
     627             :                 size_t dir_len;
     628             : 
     629          13 :                 if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) {
     630           1 :                         xmlFreeURI(uri);
     631           1 :                         return NULL;
     632             :                 }
     633             : 
     634          12 :                 memcpy(file_dirname, source, strlen(source));
     635          12 :                 dir_len = php_dirname(file_dirname, strlen(source));
     636             : 
     637          12 :                 if (dir_len > 0) {
     638             :                         zend_stat_t buf;
     639          12 :                         if (php_sys_stat(file_dirname, &buf) != 0) {
     640           1 :                                 xmlFreeURI(uri);
     641           1 :                                 return NULL;
     642             :                         }
     643             :                 }
     644             : 
     645          11 :                 file_dest = resolved_path;
     646             :         } else {
     647           0 :                 file_dest = source;
     648             :         }
     649             : 
     650          11 :         xmlFreeURI(uri);
     651             : 
     652          11 :         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          21 : static void xmlwriter_dtor(zend_resource *rsrc) {
     685             :         xmlwriter_object *intern;
     686             : 
     687          21 :         intern = (xmlwriter_object *) rsrc->ptr;
     688          21 :         xmlwriter_free_resource_ptr(intern);
     689          21 : }
     690             : /* }}} */
     691             : 
     692          85 : 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, retval;
     699             : 
     700          85 :         zval *self = getThis();
     701             : 
     702          85 :         if (self) {
     703          39 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
     704           0 :                         return;
     705             :                 }
     706          39 :                 XMLWRITER_FROM_OBJECT(intern, self);
     707             :         } else {
     708          46 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &pind, &name, &name_len) == FAILURE) {
     709           1 :                         return;
     710             :                 }
     711             : 
     712          45 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     713           0 :                         RETURN_FALSE;
     714             :                 }
     715             :         }
     716             : 
     717          84 :         if (err_string != NULL) {
     718          51 :                 XMLW_NAME_CHK(err_string);
     719             :         }
     720             : 
     721          82 :         ptr = intern->ptr;
     722             : 
     723          82 :         if (ptr) {
     724          82 :                 retval = internal_function(ptr, (xmlChar *) name);
     725          82 :                 if (retval != -1) {
     726          82 :                         RETURN_TRUE;
     727             :                 }
     728             :         }
     729             : 
     730           0 :         RETURN_FALSE;
     731             : }
     732             : 
     733          81 : static void php_xmlwriter_end(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_int_t internal_function)
     734             : {
     735             :         zval *pind;
     736             :         xmlwriter_object *intern;
     737             :         xmlTextWriterPtr ptr;
     738             :         int retval;
     739          81 :         zval *self = getThis();
     740             : 
     741          81 :         if (self) {
     742          38 :                 XMLWRITER_FROM_OBJECT(intern, self);
     743          38 :                 if (zend_parse_parameters_none() == FAILURE) {
     744           1 :                         return;
     745             :                 }
     746             :         } else {
     747          43 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pind) == FAILURE) {
     748           0 :                         return;
     749             :                 }
     750          43 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     751           0 :                         RETURN_FALSE;
     752             :                 }
     753             :         }
     754             : 
     755          80 :         ptr = intern->ptr;
     756             : 
     757          80 :         if (ptr) {
     758          80 :                 retval = internal_function(ptr);
     759          80 :                 if (retval != -1) {
     760          78 :                         RETURN_TRUE;
     761             :                 }
     762             :         }
     763             : 
     764           2 :         RETURN_FALSE;
     765             : }
     766             : 
     767             : #if LIBXML_VERSION >= 20605
     768             : /* {{{ proto bool xmlwriter_set_indent(resource xmlwriter, bool indent)
     769             : Toggle indentation on/off - returns FALSE on error */
     770          16 : static PHP_FUNCTION(xmlwriter_set_indent)
     771             : {
     772             :         zval *pind;
     773             :         xmlwriter_object *intern;
     774             :         xmlTextWriterPtr ptr;
     775             :         int retval;
     776             :         zend_bool indent;
     777             : 
     778          16 :         zval *self = getThis();
     779             : 
     780          16 :         if (self) {
     781           8 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &indent) == FAILURE) {
     782           0 :                         return;
     783             :                 }
     784           8 :                 XMLWRITER_FROM_OBJECT(intern, self);
     785             :         } else {
     786           8 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &pind, &indent) == FAILURE) {
     787           0 :                         return;
     788             :                 }
     789           8 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     790           0 :                         RETURN_FALSE;
     791             :                 }
     792             :         }
     793             : 
     794             : 
     795          16 :         ptr = intern->ptr;
     796          16 :         if (ptr) {
     797          16 :                 retval = xmlTextWriterSetIndent(ptr, indent);
     798          16 :                 if (retval == 0) {
     799          16 :                         RETURN_TRUE;
     800             :                 }
     801             :         }
     802             : 
     803           0 :         RETURN_FALSE;
     804             : }
     805             : /* }}} */
     806             : 
     807             : /* {{{ proto bool xmlwriter_set_indent_string(resource xmlwriter, string indentString)
     808             : Set string used for indenting - returns FALSE on error */
     809           8 : static PHP_FUNCTION(xmlwriter_set_indent_string)
     810             : {
     811           8 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterSetIndentString, NULL);
     812           8 : }
     813             : /* }}} */
     814             : 
     815             : #endif
     816             : 
     817             : /* {{{ proto bool xmlwriter_start_attribute(resource xmlwriter, string name)
     818             : Create start attribute - returns FALSE on error */
     819           6 : static PHP_FUNCTION(xmlwriter_start_attribute)
     820             : {
     821           6 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartAttribute, "Invalid Attribute Name");
     822           6 : }
     823             : /* }}} */
     824             : 
     825             : /* {{{ proto bool xmlwriter_end_attribute(resource xmlwriter)
     826             : End attribute - returns FALSE on error */
     827          10 : static PHP_FUNCTION(xmlwriter_end_attribute)
     828             : {
     829          10 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndAttribute);
     830          10 : }
     831             : /* }}} */
     832             : 
     833             : #if LIBXML_VERSION > 20617
     834             : /* {{{ proto bool xmlwriter_start_attribute_ns(resource xmlwriter, string prefix, string name, string uri)
     835             : Create start namespaced attribute - returns FALSE on error */
     836           4 : static PHP_FUNCTION(xmlwriter_start_attribute_ns)
     837             : {
     838             :         zval *pind;
     839             :         xmlwriter_object *intern;
     840             :         xmlTextWriterPtr ptr;
     841             :         char *name, *prefix, *uri;
     842             :         size_t name_len, prefix_len, uri_len;
     843             :         int retval;
     844           4 :         zval *self = getThis();
     845             : 
     846           4 :         if (self) {
     847           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss!",
     848             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     849           0 :                         return;
     850             :                 }
     851           2 :                 XMLWRITER_FROM_OBJECT(intern, self);
     852             :         } else {
     853           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss!", &pind,
     854             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     855           0 :                         return;
     856             :                 }
     857           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     858           0 :                         RETURN_FALSE;
     859             :                 }
     860             :         }
     861             : 
     862           4 :         XMLW_NAME_CHK("Invalid Attribute Name");
     863             : 
     864           4 :         ptr = intern->ptr;
     865             : 
     866           4 :         if (ptr) {
     867           4 :                 retval = xmlTextWriterStartAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
     868           4 :                 if (retval != -1) {
     869           4 :                         RETURN_TRUE;
     870             :                 }
     871             :         }
     872             : 
     873           0 :         RETURN_FALSE;
     874             : }
     875             : /* }}} */
     876             : #endif
     877             : 
     878             : /* {{{ proto bool xmlwriter_write_attribute(resource xmlwriter, string name, string content)
     879             : Write full attribute - returns FALSE on error */
     880           9 : static PHP_FUNCTION(xmlwriter_write_attribute)
     881             : {
     882             :         zval *pind;
     883             :         xmlwriter_object *intern;
     884             :         xmlTextWriterPtr ptr;
     885             :         char *name, *content;
     886             :         size_t name_len, content_len;
     887             :         int retval;
     888           9 :         zval *self = getThis();
     889             : 
     890           9 :         if (self) {
     891           3 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
     892             :                         &name, &name_len, &content, &content_len) == FAILURE) {
     893           0 :                         return;
     894             :                 }
     895           3 :                 XMLWRITER_FROM_OBJECT(intern, self);
     896             :         } else {
     897           6 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
     898             :                         &name, &name_len, &content, &content_len) == FAILURE) {
     899           0 :                         return;
     900             :                 }
     901           6 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     902           0 :                         RETURN_FALSE;
     903             :                 }
     904             :         }
     905             : 
     906           9 :         XMLW_NAME_CHK("Invalid Attribute Name");
     907             : 
     908           9 :         ptr = intern->ptr;
     909             : 
     910           9 :         if (ptr) {
     911           9 :                 retval = xmlTextWriterWriteAttribute(ptr, (xmlChar *)name, (xmlChar *)content);
     912           9 :                 if (retval != -1) {
     913           9 :                         RETURN_TRUE;
     914             :                 }
     915             :         }
     916             : 
     917           0 :         RETURN_FALSE;
     918             : }
     919             : /* }}} */
     920             : 
     921             : #if LIBXML_VERSION > 20617
     922             : /* {{{ proto bool xmlwriter_write_attribute_ns(resource xmlwriter, string prefix, string name, string uri, string content)
     923             : Write full namespaced attribute - returns FALSE on error */
     924           7 : static PHP_FUNCTION(xmlwriter_write_attribute_ns)
     925             : {
     926             :         zval *pind;
     927             :         xmlwriter_object *intern;
     928             :         xmlTextWriterPtr ptr;
     929             :         char *name, *prefix, *uri, *content;
     930             :         size_t name_len, prefix_len, uri_len, content_len;
     931             :         int retval;
     932             : 
     933           7 :         zval *self = getThis();
     934             : 
     935           7 :         if (self) {
     936           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss!s",
     937             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
     938           0 :                         return;
     939             :                 }
     940           2 :                 XMLWRITER_FROM_OBJECT(intern, self);
     941             :         } else {
     942           5 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss!s", &pind,
     943             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
     944           1 :                         return;
     945             :                 }
     946           4 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     947           0 :                         RETURN_FALSE;
     948             :                 }
     949             :         }
     950             : 
     951           6 :         XMLW_NAME_CHK("Invalid Attribute Name");
     952             : 
     953           6 :         ptr = intern->ptr;
     954             : 
     955           6 :         if (ptr) {
     956           6 :                 retval = xmlTextWriterWriteAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
     957           6 :                 if (retval != -1) {
     958           5 :                         RETURN_TRUE;
     959             :                 }
     960             :         }
     961             : 
     962           1 :         RETURN_FALSE;
     963             : }
     964             : /* }}} */
     965             : #endif
     966             : 
     967             : /* {{{ proto bool xmlwriter_start_element(resource xmlwriter, string name)
     968             : Create start element tag - returns FALSE on error */
     969          39 : static PHP_FUNCTION(xmlwriter_start_element)
     970             : {
     971          39 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartElement, "Invalid Element Name");
     972          39 : }
     973             : /* }}} */
     974             : 
     975             : /* {{{ proto bool xmlwriter_start_element_ns(resource xmlwriter, string prefix, string name, string uri)
     976             : Create start namespaced element tag - returns FALSE on error */
     977           9 : static PHP_FUNCTION(xmlwriter_start_element_ns)
     978             : {
     979             :         zval *pind;
     980             :         xmlwriter_object *intern;
     981             :         xmlTextWriterPtr ptr;
     982             :         char *name, *prefix, *uri;
     983             :         size_t name_len, prefix_len, uri_len;
     984             :         int retval;
     985           9 :         zval *self = getThis();
     986             : 
     987           9 :         if (self) {
     988           5 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!ss!",
     989             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     990           0 :                         return;
     991             :                 }
     992           5 :                 XMLWRITER_FROM_OBJECT(intern, self);
     993             :         } else {
     994           4 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs!ss!", &pind,
     995             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
     996           0 :                         return;
     997             :                 }
     998           4 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
     999           0 :                         RETURN_FALSE;
    1000             :                 }
    1001             :         }
    1002             : 
    1003           9 :         XMLW_NAME_CHK("Invalid Element Name");
    1004             : 
    1005           9 :         ptr = intern->ptr;
    1006             : 
    1007           9 :         if (ptr) {
    1008           9 :                 retval = xmlTextWriterStartElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
    1009           9 :                 if (retval != -1) {
    1010           9 :                         RETURN_TRUE;
    1011             :                 }
    1012             : 
    1013             :         }
    1014             : 
    1015           0 :         RETURN_FALSE;
    1016             : }
    1017             : /* }}} */
    1018             : 
    1019             : /* {{{ proto bool xmlwriter_end_element(resource xmlwriter)
    1020             : End current element - returns FALSE on error */
    1021          25 : static PHP_FUNCTION(xmlwriter_end_element)
    1022             : {
    1023          25 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndElement);
    1024          25 : }
    1025             : /* }}} */
    1026             : 
    1027             : /* {{{ proto bool xmlwriter_full_end_element(resource xmlwriter)
    1028             : End current element - returns FALSE on error */
    1029           6 : static PHP_FUNCTION(xmlwriter_full_end_element)
    1030             : {
    1031           6 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterFullEndElement);
    1032           6 : }
    1033             : /* }}} */
    1034             : 
    1035             : /* {{{ proto bool xmlwriter_write_element(resource xmlwriter, string name[, string content])
    1036             : Write full element tag - returns FALSE on error */
    1037           9 : static PHP_FUNCTION(xmlwriter_write_element)
    1038             : {
    1039             :         zval *pind;
    1040             :         xmlwriter_object *intern;
    1041             :         xmlTextWriterPtr ptr;
    1042           9 :         char *name, *content = NULL;
    1043             :         size_t name_len, content_len;
    1044             :         int retval;
    1045           9 :         zval *self = getThis();
    1046             : 
    1047           9 :         if (self) {
    1048           6 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!",
    1049             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1050           0 :                         return;
    1051             :                 }
    1052           6 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1053             :         } else {
    1054           3 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!", &pind,
    1055             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1056           0 :                         return;
    1057             :                 }
    1058           3 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1059           0 :                         RETURN_FALSE;
    1060             :                 }
    1061             :         }
    1062             : 
    1063           9 :         XMLW_NAME_CHK("Invalid Element Name");
    1064             : 
    1065           9 :         ptr = intern->ptr;
    1066             : 
    1067           9 :         if (ptr) {
    1068           9 :                 if (!content) {
    1069           2 :                         retval = xmlTextWriterStartElement(ptr, (xmlChar *)name);
    1070           2 :             if (retval == -1) {
    1071           0 :                 RETURN_FALSE;
    1072             :             }
    1073           2 :                         xmlTextWriterEndElement(ptr);
    1074           2 :             if (retval == -1) {
    1075           0 :                 RETURN_FALSE;
    1076             :             }
    1077             :                 } else {
    1078           7 :                         retval = xmlTextWriterWriteElement(ptr, (xmlChar *)name, (xmlChar *)content);
    1079             :                 }
    1080           9 :                 if (retval != -1) {
    1081           9 :                         RETURN_TRUE;
    1082             :                 }
    1083             :         }
    1084             : 
    1085           0 :         RETURN_FALSE;
    1086             : }
    1087             : /* }}} */
    1088             : 
    1089             : /* {{{ proto bool xmlwriter_write_element_ns(resource xmlwriter, string prefix, string name, string uri[, string content])
    1090             : Write full namesapced element tag - returns FALSE on error */
    1091          13 : static PHP_FUNCTION(xmlwriter_write_element_ns)
    1092             : {
    1093             :         zval *pind;
    1094             :         xmlwriter_object *intern;
    1095             :         xmlTextWriterPtr ptr;
    1096          13 :         char *name, *prefix, *uri, *content = NULL;
    1097             :         size_t name_len, prefix_len, uri_len, content_len;
    1098             :         int retval;
    1099          13 :         zval *self = getThis();
    1100             : 
    1101          13 :         if (self) {
    1102           9 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!ss!|s!",
    1103             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
    1104           0 :                         return;
    1105             :                 }
    1106           9 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1107             :         } else {
    1108           4 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs!ss!|s!", &pind,
    1109             :                         &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
    1110           0 :                         return;
    1111             :                 }
    1112           4 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1113           0 :                         RETURN_FALSE;
    1114             :                 }
    1115             :         }
    1116             : 
    1117          13 :         XMLW_NAME_CHK("Invalid Element Name");
    1118             : 
    1119          13 :         ptr = intern->ptr;
    1120             : 
    1121          13 :         if (ptr) {
    1122          13 :                 if (!content) {
    1123           2 :                         retval = xmlTextWriterStartElementNS(ptr,(xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
    1124           2 :             if (retval == -1) {
    1125           0 :                 RETURN_FALSE;
    1126             :             }
    1127           2 :                         retval = xmlTextWriterEndElement(ptr);
    1128           2 :             if (retval == -1) {
    1129           0 :                 RETURN_FALSE;
    1130             :             }
    1131             :                 } else {
    1132          11 :                         retval = xmlTextWriterWriteElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
    1133             :                 }
    1134          13 :                 if (retval != -1) {
    1135          13 :                         RETURN_TRUE;
    1136             :                 }
    1137             :         }
    1138             : 
    1139           0 :         RETURN_FALSE;
    1140             : }
    1141             : /* }}} */
    1142             : 
    1143             : /* {{{ proto bool xmlwriter_start_pi(resource xmlwriter, string target)
    1144             : Create start PI tag - returns FALSE on error */
    1145           2 : static PHP_FUNCTION(xmlwriter_start_pi)
    1146             : {
    1147           2 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartPI, "Invalid PI Target");
    1148           2 : }
    1149             : /* }}} */
    1150             : 
    1151             : /* {{{ proto bool xmlwriter_end_pi(resource xmlwriter)
    1152             : End current PI - returns FALSE on error */
    1153           2 : static PHP_FUNCTION(xmlwriter_end_pi)
    1154             : {
    1155           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndPI);
    1156           2 : }
    1157             : /* }}} */
    1158             : 
    1159             : /* {{{ proto bool xmlwriter_write_pi(resource xmlwriter, string target, string content)
    1160             : Write full PI tag - returns FALSE on error */
    1161           2 : static PHP_FUNCTION(xmlwriter_write_pi)
    1162             : {
    1163             :         zval *pind;
    1164             :         xmlwriter_object *intern;
    1165             :         xmlTextWriterPtr ptr;
    1166             :         char *name, *content;
    1167             :         size_t name_len, content_len;
    1168             :         int retval;
    1169             : 
    1170           2 :         zval *self = getThis();
    1171             : 
    1172           2 :         if (self) {
    1173           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
    1174             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1175           0 :                         return;
    1176             :                 }
    1177           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1178             :         } else {
    1179           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
    1180             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1181           0 :                         return;
    1182             :                 }
    1183           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1184           0 :                         RETURN_FALSE;
    1185             :                 }
    1186             :         }
    1187             : 
    1188           2 :         XMLW_NAME_CHK("Invalid PI Target");
    1189             : 
    1190           2 :         ptr = intern->ptr;
    1191             : 
    1192           2 :         if (ptr) {
    1193           2 :                 retval = xmlTextWriterWritePI(ptr, (xmlChar *)name, (xmlChar *)content);
    1194           2 :                 if (retval != -1) {
    1195           2 :                         RETURN_TRUE;
    1196             :                 }
    1197             :         }
    1198             : 
    1199           0 :         RETURN_FALSE;
    1200             : }
    1201             : /* }}} */
    1202             : 
    1203             : /* {{{ proto bool xmlwriter_start_cdata(resource xmlwriter)
    1204             : Create start CDATA tag - returns FALSE on error */
    1205           2 : static PHP_FUNCTION(xmlwriter_start_cdata)
    1206             : {
    1207             :         zval *pind;
    1208             :         xmlwriter_object *intern;
    1209             :         xmlTextWriterPtr ptr;
    1210             :         int retval;
    1211           2 :         zval *self = getThis();
    1212             : 
    1213           2 :         if (self) {
    1214           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1215             :         } else {
    1216           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pind) == FAILURE) {
    1217           0 :                         return;
    1218             :                 }
    1219           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1220           0 :                         RETURN_FALSE;
    1221             :                 }
    1222             :         }
    1223             : 
    1224           2 :         ptr = intern->ptr;
    1225             : 
    1226           2 :         if (ptr) {
    1227           2 :                 retval = xmlTextWriterStartCDATA(ptr);
    1228           2 :                 if (retval != -1) {
    1229           2 :                         RETURN_TRUE;
    1230             :                 }
    1231             :         }
    1232             : 
    1233           0 :         RETURN_FALSE;
    1234             : }
    1235             : /* }}} */
    1236             : 
    1237             : /* {{{ proto bool xmlwriter_end_cdata(resource xmlwriter)
    1238             : End current CDATA - returns FALSE on error */
    1239           2 : static PHP_FUNCTION(xmlwriter_end_cdata)
    1240             : {
    1241           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndCDATA);
    1242           2 : }
    1243             : /* }}} */
    1244             : 
    1245             : /* {{{ proto bool xmlwriter_write_cdata(resource xmlwriter, string content)
    1246             : Write full CDATA tag - returns FALSE on error */
    1247           0 : static PHP_FUNCTION(xmlwriter_write_cdata)
    1248             : {
    1249           0 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteCDATA, NULL);
    1250           0 : }
    1251             : /* }}} */
    1252             : 
    1253             : /* {{{ proto bool xmlwriter_write_raw(resource xmlwriter, string content)
    1254             : Write text - returns FALSE on error */
    1255           0 : static PHP_FUNCTION(xmlwriter_write_raw)
    1256             : {
    1257           0 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteRaw, NULL);
    1258           0 : }
    1259             : /* }}} */
    1260             : 
    1261             : /* {{{ proto bool xmlwriter_text(resource xmlwriter, string content)
    1262             : Write text - returns FALSE on error */
    1263          22 : static PHP_FUNCTION(xmlwriter_text)
    1264             : {
    1265          22 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteString, NULL);
    1266          22 : }
    1267             : /* }}} */
    1268             : 
    1269             : #if LIBXML_VERSION >= 20607
    1270             : /* {{{ proto bool xmlwriter_start_comment(resource xmlwriter)
    1271             : Create start comment - returns FALSE on error */
    1272           2 : static PHP_FUNCTION(xmlwriter_start_comment)
    1273             : {
    1274             :         zval *pind;
    1275             :         xmlwriter_object *intern;
    1276             :         xmlTextWriterPtr ptr;
    1277             :         int retval;
    1278           2 :         zval *self = getThis();
    1279             : 
    1280           2 :         if (self) {
    1281           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1282             :         } else {
    1283           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pind) == FAILURE) {
    1284           0 :                         return;
    1285             :                 }
    1286           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1287           0 :                         RETURN_FALSE;
    1288             :                 }
    1289             :         }
    1290             : 
    1291           2 :         ptr = intern->ptr;
    1292             : 
    1293           2 :         if (ptr) {
    1294           2 :                 retval = xmlTextWriterStartComment(ptr);
    1295           2 :                 if (retval != -1) {
    1296           2 :                         RETURN_TRUE;
    1297             :                 }
    1298             :         }
    1299             : 
    1300           0 :         RETURN_FALSE;
    1301             : }
    1302             : /* }}} */
    1303             : 
    1304             : /* {{{ proto bool xmlwriter_end_comment(resource xmlwriter)
    1305             : Create end comment - returns FALSE on error */
    1306           2 : static PHP_FUNCTION(xmlwriter_end_comment)
    1307             : {
    1308           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndComment);
    1309           2 : }
    1310             : /* }}} */
    1311             : #endif  /* LIBXML_VERSION >= 20607 */
    1312             : 
    1313             : 
    1314             : /* {{{ proto bool xmlwriter_write_comment(resource xmlwriter, string content)
    1315             : Write full comment tag - returns FALSE on error */
    1316           4 : static PHP_FUNCTION(xmlwriter_write_comment)
    1317             : {
    1318           4 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteComment, NULL);
    1319           4 : }
    1320             : /* }}} */
    1321             : 
    1322             : /* {{{ proto bool xmlwriter_start_document(resource xmlwriter, string version, string encoding, string standalone)
    1323             : Create document tag - returns FALSE on error */
    1324          28 : static PHP_FUNCTION(xmlwriter_start_document)
    1325             : {
    1326             :         zval *pind;
    1327             :         xmlwriter_object *intern;
    1328             :         xmlTextWriterPtr ptr;
    1329          28 :         char *version = NULL, *enc = NULL, *alone = NULL;
    1330             :         size_t version_len, enc_len, alone_len;
    1331             :         int retval;
    1332             : 
    1333          28 :         zval *self = getThis();
    1334             : 
    1335          28 :         if (self) {
    1336          14 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!", &version, &version_len, &enc, &enc_len, &alone, &alone_len) == FAILURE) {
    1337           0 :                         return;
    1338             :                 }
    1339          14 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1340             :         } else {
    1341          14 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!s!", &pind, &version, &version_len, &enc, &enc_len, &alone, &alone_len) == FAILURE) {
    1342           0 :                         return;
    1343             :                 }
    1344          14 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1345           0 :                         RETURN_FALSE;
    1346             :                 }
    1347             :         }
    1348             : 
    1349          28 :         ptr = intern->ptr;
    1350             : 
    1351          28 :         if (ptr) {
    1352          28 :                 retval = xmlTextWriterStartDocument(ptr, version, enc, alone);
    1353          28 :                 if (retval != -1) {
    1354          28 :                         RETURN_TRUE;
    1355             :                 }
    1356             :         }
    1357             : 
    1358           0 :         RETURN_FALSE;
    1359             : }
    1360             : /* }}} */
    1361             : 
    1362             : /* {{{ proto bool xmlwriter_end_document(resource xmlwriter)
    1363             : End current document - returns FALSE on error */
    1364          25 : static PHP_FUNCTION(xmlwriter_end_document)
    1365             : {
    1366          25 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDocument);
    1367          25 : }
    1368             : /* }}} */
    1369             : 
    1370             : /* {{{ proto bool xmlwriter_start_dtd(resource xmlwriter, string name, string pubid, string sysid)
    1371             : Create start DTD tag - returns FALSE on error */
    1372           4 : static PHP_FUNCTION(xmlwriter_start_dtd)
    1373             : {
    1374             :         zval *pind;
    1375             :         xmlwriter_object *intern;
    1376             :         xmlTextWriterPtr ptr;
    1377           4 :         char *name, *pubid = NULL, *sysid = NULL;
    1378             :         size_t name_len, pubid_len, sysid_len;
    1379             :         int retval;
    1380           4 :         zval *self = getThis();
    1381             : 
    1382           4 :         if (self) {
    1383           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!", &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len) == FAILURE) {
    1384           0 :                         return;
    1385             :                 }
    1386             : 
    1387           2 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1388             :         } else {
    1389           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!s!", &pind, &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len) == FAILURE) {
    1390           0 :                         return;
    1391             :                 }
    1392           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1393           0 :                         RETURN_FALSE;
    1394             :                 }
    1395             :         }
    1396           4 :         ptr = intern->ptr;
    1397             : 
    1398           4 :         if (ptr) {
    1399           4 :                 retval = xmlTextWriterStartDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid);
    1400           4 :                 if (retval != -1) {
    1401           4 :                         RETURN_TRUE;
    1402             :                 }
    1403             :         }
    1404             : 
    1405           0 :         RETURN_FALSE;
    1406             : }
    1407             : /* }}} */
    1408             : 
    1409             : /* {{{ proto bool xmlwriter_end_dtd(resource xmlwriter)
    1410             : End current DTD - returns FALSE on error */
    1411           4 : static PHP_FUNCTION(xmlwriter_end_dtd)
    1412             : {
    1413           4 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTD);
    1414           4 : }
    1415             : /* }}} */
    1416             : 
    1417             : /* {{{ proto bool xmlwriter_write_dtd(resource xmlwriter, string name, string pubid, string sysid, string subset)
    1418             : Write full DTD tag - returns FALSE on error */
    1419           3 : static PHP_FUNCTION(xmlwriter_write_dtd)
    1420             : {
    1421             :         zval *pind;
    1422             :         xmlwriter_object *intern;
    1423             :         xmlTextWriterPtr ptr;
    1424           3 :         char *name, *pubid = NULL, *sysid = NULL, *subset = NULL;
    1425             :         size_t name_len, pubid_len, sysid_len, subset_len;
    1426             :         int retval;
    1427           3 :         zval *self = getThis();
    1428             : 
    1429           3 :         if (self) {
    1430           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) {
    1431           0 :                         return;
    1432             :                 }
    1433             : 
    1434           0 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1435             :         } else {
    1436           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) {
    1437           1 :                         return;
    1438             :                 }
    1439             : 
    1440           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1441           0 :                         RETURN_FALSE;
    1442             :                 }
    1443             :         }
    1444             : 
    1445           2 :         ptr = intern->ptr;
    1446             : 
    1447           2 :         if (ptr) {
    1448           2 :                 retval = xmlTextWriterWriteDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)subset);
    1449           2 :                 if (retval != -1) {
    1450           1 :                         RETURN_TRUE;
    1451             :                 }
    1452             :         }
    1453             : 
    1454           1 :         RETURN_FALSE;
    1455             : }
    1456             : /* }}} */
    1457             : 
    1458             : /* {{{ proto bool xmlwriter_start_dtd_element(resource xmlwriter, string name)
    1459             : Create start DTD element - returns FALSE on error */
    1460           2 : static PHP_FUNCTION(xmlwriter_start_dtd_element)
    1461             : {
    1462           2 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDElement, "Invalid Element Name");
    1463           2 : }
    1464             : /* }}} */
    1465             : 
    1466             : /* {{{ proto bool xmlwriter_end_dtd_element(resource xmlwriter)
    1467             : End current DTD element - returns FALSE on error */
    1468           2 : static PHP_FUNCTION(xmlwriter_end_dtd_element)
    1469             : {
    1470           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDElement);
    1471           2 : }
    1472             : /* }}} */
    1473             : 
    1474             : /* {{{ proto bool xmlwriter_write_dtd_element(resource xmlwriter, string name, string content)
    1475             : Write full DTD element tag - returns FALSE on error */
    1476           2 : static PHP_FUNCTION(xmlwriter_write_dtd_element)
    1477             : {
    1478             :         zval *pind;
    1479             :         xmlwriter_object *intern;
    1480             :         xmlTextWriterPtr ptr;
    1481             :         char *name, *content;
    1482             :         size_t name_len, content_len;
    1483             :         int retval;
    1484           2 :         zval *self = getThis();
    1485             : 
    1486           2 :         if (self) {
    1487           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &content, &content_len) == FAILURE) {
    1488           0 :                         return;
    1489             :                 }
    1490           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1491             :         } else {
    1492           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
    1493             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1494           0 :                         return;
    1495             :                 }
    1496           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1497           0 :                         RETURN_FALSE;
    1498             :                 }
    1499             :         }
    1500             : 
    1501           2 :         XMLW_NAME_CHK("Invalid Element Name");
    1502             : 
    1503           2 :         ptr = intern->ptr;
    1504             : 
    1505           2 :         if (ptr) {
    1506           2 :                 retval = xmlTextWriterWriteDTDElement(ptr, (xmlChar *)name, (xmlChar *)content);
    1507           2 :                 if (retval != -1) {
    1508           2 :                         RETURN_TRUE;
    1509             :                 }
    1510             :         }
    1511             : 
    1512           0 :         RETURN_FALSE;
    1513             : }
    1514             : /* }}} */
    1515             : 
    1516             : #if LIBXML_VERSION > 20608
    1517             : /* {{{ proto bool xmlwriter_start_dtd_attlist(resource xmlwriter, string name)
    1518             : Create start DTD AttList - returns FALSE on error */
    1519           2 : static PHP_FUNCTION(xmlwriter_start_dtd_attlist)
    1520             : {
    1521           2 :         php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDAttlist, "Invalid Element Name");
    1522           2 : }
    1523             : /* }}} */
    1524             : 
    1525             : /* {{{ proto bool xmlwriter_end_dtd_attlist(resource xmlwriter)
    1526             : End current DTD AttList - returns FALSE on error */
    1527           2 : static PHP_FUNCTION(xmlwriter_end_dtd_attlist)
    1528             : {
    1529           2 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDAttlist);
    1530           2 : }
    1531             : /* }}} */
    1532             : 
    1533             : /* {{{ proto bool xmlwriter_write_dtd_attlist(resource xmlwriter, string name, string content)
    1534             : Write full DTD AttList tag - returns FALSE on error */
    1535           2 : static PHP_FUNCTION(xmlwriter_write_dtd_attlist)
    1536             : {
    1537             :         zval *pind;
    1538             :         xmlwriter_object *intern;
    1539             :         xmlTextWriterPtr ptr;
    1540             :         char *name, *content;
    1541             :         size_t name_len, content_len;
    1542             :         int retval;
    1543           2 :         zval *self = getThis();
    1544             : 
    1545           2 :         if (self) {
    1546           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
    1547             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1548           0 :                         return;
    1549             :                 }
    1550           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1551             :         } else {
    1552           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &pind,
    1553             :                         &name, &name_len, &content, &content_len) == FAILURE) {
    1554           0 :                         return;
    1555             :                 }
    1556           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1557           0 :                         RETURN_FALSE;
    1558             :                 }
    1559             :         }
    1560             : 
    1561           2 :         XMLW_NAME_CHK("Invalid Element Name");
    1562             : 
    1563           2 :         ptr = intern->ptr;
    1564             : 
    1565           2 :         if (ptr) {
    1566           2 :                 retval = xmlTextWriterWriteDTDAttlist(ptr, (xmlChar *)name, (xmlChar *)content);
    1567           2 :                 if (retval != -1) {
    1568           2 :                         RETURN_TRUE;
    1569             :                 }
    1570             :         }
    1571             : 
    1572           0 :         RETURN_FALSE;
    1573             : }
    1574             : /* }}} */
    1575             : 
    1576             : /* {{{ proto bool xmlwriter_start_dtd_entity(resource xmlwriter, string name, bool isparam)
    1577             : Create start DTD Entity - returns FALSE on error */
    1578           1 : static PHP_FUNCTION(xmlwriter_start_dtd_entity)
    1579             : {
    1580             :         zval *pind;
    1581             :         xmlwriter_object *intern;
    1582             :         xmlTextWriterPtr ptr;
    1583             :         char *name;
    1584             :         size_t name_len, retval;
    1585             :         zend_bool isparm;
    1586           1 :         zval *self = getThis();
    1587             : 
    1588           1 :         if (self) {
    1589           0 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "sb", &name, &name_len, &isparm) == FAILURE) {
    1590           0 :                         return;
    1591             :                 }
    1592           0 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1593             :         } else {
    1594           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsb", &pind, &name, &name_len, &isparm) == FAILURE) {
    1595           0 :                         return;
    1596             :                 }
    1597           1 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1598           0 :                         RETURN_FALSE;
    1599             :                 }
    1600             :         }
    1601             : 
    1602           1 :         XMLW_NAME_CHK("Invalid Attribute Name");
    1603             : 
    1604           1 :         ptr = intern->ptr;
    1605             : 
    1606           1 :         if (ptr) {
    1607           1 :                 retval = xmlTextWriterStartDTDEntity(ptr, isparm, (xmlChar *)name);
    1608           1 :                 if (retval != -1) {
    1609           1 :                         RETURN_TRUE;
    1610             :                 }
    1611             :         }
    1612             : 
    1613           0 :         RETURN_FALSE;
    1614             : }
    1615             : /* }}} */
    1616             : 
    1617             : /* {{{ proto bool xmlwriter_end_dtd_entity(resource xmlwriter)
    1618             : End current DTD Entity - returns FALSE on error */
    1619           1 : static PHP_FUNCTION(xmlwriter_end_dtd_entity)
    1620             : {
    1621           1 :         php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDEntity);
    1622           1 : }
    1623             : /* }}} */
    1624             : 
    1625             : /* {{{ proto bool xmlwriter_write_dtd_entity(resource xmlwriter, string name, string content [, int pe [, string pubid [, string sysid [, string ndataid]]]])
    1626             : Write full DTD Entity tag - returns FALSE on error */
    1627           3 : static PHP_FUNCTION(xmlwriter_write_dtd_entity)
    1628             : {
    1629             :         zval *pind;
    1630             :         xmlwriter_object *intern;
    1631             :         xmlTextWriterPtr ptr;
    1632             :         char *name, *content;
    1633             :         size_t name_len, content_len;
    1634             :         int retval;
    1635             :         /* Optional parameters */
    1636           3 :         char *pubid = NULL, *sysid = NULL, *ndataid = NULL;
    1637           3 :         zend_bool pe = 0;
    1638             :         size_t pubid_len, sysid_len, ndataid_len;
    1639           3 :         zval *self = getThis();
    1640             : 
    1641           3 :         if (self) {
    1642           1 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|bsss",
    1643             :                         &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len,
    1644             :                         &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) {
    1645           0 :                         return;
    1646             :                 }
    1647           1 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1648             :         } else {
    1649           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss|bsss", &pind,
    1650             :                         &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len,
    1651             :                         &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) {
    1652           0 :                         return;
    1653             :                 }
    1654           2 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1655           0 :                         RETURN_FALSE;
    1656             :                 }
    1657             :         }
    1658             : 
    1659           3 :         XMLW_NAME_CHK("Invalid Element Name");
    1660             : 
    1661           3 :         ptr = intern->ptr;
    1662             : 
    1663           3 :         if (ptr) {
    1664           3 :                 retval = xmlTextWriterWriteDTDEntity(ptr, pe, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)ndataid, (xmlChar *)content);
    1665           3 :                 if (retval != -1) {
    1666           3 :                         RETURN_TRUE;
    1667             :                 }
    1668             :         }
    1669             : 
    1670           0 :         RETURN_FALSE;
    1671             : }
    1672             : /* }}} */
    1673             : #endif
    1674             : 
    1675             : /* {{{ proto resource xmlwriter_open_uri(string source)
    1676             : Create new xmlwriter using source uri for output */
    1677          17 : static PHP_FUNCTION(xmlwriter_open_uri)
    1678             : {
    1679          17 :         char *valid_file = NULL;
    1680             :         xmlwriter_object *intern;
    1681             :         xmlTextWriterPtr ptr;
    1682             :         char *source;
    1683             :         char resolved_path[MAXPATHLEN + 1];
    1684             :         size_t source_len;
    1685          17 :         zval *self = getThis();
    1686          17 :         ze_xmlwriter_object *ze_obj = NULL;
    1687             : 
    1688          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &source, &source_len) == FAILURE) {
    1689           1 :                 return;
    1690             :         }
    1691             : 
    1692          16 :         if (self) {
    1693             :                 /* We do not use XMLWRITER_FROM_OBJECT, xmlwriter init function here */
    1694           4 :                 ze_obj = Z_XMLWRITER_P(self);
    1695             :         }
    1696             : 
    1697          16 :         if (source_len == 0) {
    1698           1 :                 php_error_docref(NULL, E_WARNING, "Empty string as source");
    1699           1 :                 RETURN_FALSE;
    1700             :         }
    1701             : 
    1702          15 :         valid_file = _xmlwriter_get_valid_file_path(source, resolved_path, MAXPATHLEN);
    1703          15 :         if (!valid_file) {
    1704           4 :                 php_error_docref(NULL, E_WARNING, "Unable to resolve file path");
    1705           4 :                 RETURN_FALSE;
    1706             :         }
    1707             : 
    1708          11 :         ptr = xmlNewTextWriterFilename(valid_file, 0);
    1709             : 
    1710          11 :         if (!ptr) {
    1711           0 :                 RETURN_FALSE;
    1712             :         }
    1713             : 
    1714          11 :         intern = emalloc(sizeof(xmlwriter_object));
    1715          11 :         intern->ptr = ptr;
    1716          11 :         intern->output = NULL;
    1717          11 :         if (self) {
    1718           4 :                 if (ze_obj->xmlwriter_ptr) {
    1719           0 :                         xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr);
    1720             :                 }
    1721           4 :                 ze_obj->xmlwriter_ptr = intern;
    1722           4 :                 RETURN_TRUE;
    1723             :         } else {
    1724           7 :                 RETURN_RES(zend_register_resource(intern, le_xmlwriter));
    1725             :         }
    1726             : }
    1727             : /* }}} */
    1728             : 
    1729             : /* {{{ proto resource xmlwriter_open_memory()
    1730             : Create new xmlwriter using memory for string output */
    1731          25 : static PHP_FUNCTION(xmlwriter_open_memory)
    1732             : {
    1733             :         xmlwriter_object *intern;
    1734             :         xmlTextWriterPtr ptr;
    1735             :         xmlBufferPtr buffer;
    1736          25 :         zval *self = getThis();
    1737          25 :         ze_xmlwriter_object *ze_obj = NULL;
    1738             : 
    1739          25 :         if (self) {
    1740             :                 /* We do not use XMLWRITER_FROM_OBJECT, xmlwriter init function here */
    1741          11 :                 ze_obj = Z_XMLWRITER_P(self);
    1742             :         }
    1743             : 
    1744          25 :         buffer = xmlBufferCreate();
    1745             : 
    1746          25 :         if (buffer == NULL) {
    1747           0 :                 php_error_docref(NULL, E_WARNING, "Unable to create output buffer");
    1748           0 :                 RETURN_FALSE;
    1749             :         }
    1750             : 
    1751          25 :         ptr = xmlNewTextWriterMemory(buffer, 0);
    1752          25 :         if (! ptr) {
    1753           0 :                 xmlBufferFree(buffer);
    1754           0 :                 RETURN_FALSE;
    1755             :         }
    1756             : 
    1757          25 :         intern = emalloc(sizeof(xmlwriter_object));
    1758          25 :         intern->ptr = ptr;
    1759          25 :         intern->output = buffer;
    1760          25 :         if (self) {
    1761          11 :                 if (ze_obj->xmlwriter_ptr) {
    1762           0 :                         xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr);
    1763             :                 }
    1764          11 :                 ze_obj->xmlwriter_ptr = intern;
    1765          11 :                 RETURN_TRUE;
    1766             :         } else {
    1767          14 :                 RETURN_RES(zend_register_resource(intern, le_xmlwriter));
    1768             :         }
    1769             : 
    1770             : }
    1771             : /* }}} */
    1772             : 
    1773             : /* {{{ php_xmlwriter_flush */
    1774          33 : static void php_xmlwriter_flush(INTERNAL_FUNCTION_PARAMETERS, int force_string) {
    1775             :         zval *pind;
    1776             :         xmlwriter_object *intern;
    1777             :         xmlTextWriterPtr ptr;
    1778             :         xmlBufferPtr buffer;
    1779          33 :         zend_bool empty = 1;
    1780             :         int output_bytes;
    1781          33 :         zval *self = getThis();
    1782             : 
    1783          33 :         if (self) {
    1784          15 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &empty) == FAILURE) {
    1785           0 :                         return;
    1786             :                 }
    1787          15 :                 XMLWRITER_FROM_OBJECT(intern, self);
    1788             :         } else {
    1789          18 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b", &pind, &empty) == FAILURE) {
    1790           0 :                         return;
    1791             :                 }
    1792             : 
    1793          18 :                 if ((intern = (xmlwriter_object *)zend_fetch_resource(Z_RES_P(pind), "XMLWriter", le_xmlwriter)) == NULL) {
    1794           0 :                         RETURN_FALSE;
    1795             :                 }
    1796             :         }
    1797          33 :         ptr = intern->ptr;
    1798             : 
    1799          33 :         if (ptr) {
    1800          33 :                 buffer = intern->output;
    1801          33 :                 if (force_string == 1 && buffer == NULL) {
    1802           0 :                         RETURN_EMPTY_STRING();
    1803             :                 }
    1804          33 :                 output_bytes = xmlTextWriterFlush(ptr);
    1805          33 :                 if (buffer) {
    1806          50 :                         RETVAL_STRING((char *) buffer->content);
    1807          25 :                         if (empty) {
    1808          25 :                                 xmlBufferEmpty(buffer);
    1809             :                         }
    1810             :                 } else {
    1811           8 :                         RETVAL_LONG(output_bytes);
    1812             :                 }
    1813          33 :                 return;
    1814             :         }
    1815             : 
    1816           0 :         RETURN_EMPTY_STRING();
    1817             : }
    1818             : /* }}} */
    1819             : 
    1820             : /* {{{ proto string xmlwriter_output_memory(resource xmlwriter [,bool flush])
    1821             : Output current buffer as string */
    1822           1 : static PHP_FUNCTION(xmlwriter_output_memory)
    1823             : {
    1824           1 :         php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    1825           1 : }
    1826             : /* }}} */
    1827             : 
    1828             : /* {{{ proto mixed xmlwriter_flush(resource xmlwriter [,bool empty])
    1829             : Output current buffer */
    1830          32 : static PHP_FUNCTION(xmlwriter_flush)
    1831             : {
    1832          32 :         php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    1833          32 : }
    1834             : /* }}} */
    1835             : 
    1836             : /* {{{ PHP_MINIT_FUNCTION
    1837             :  */
    1838       21049 : static PHP_MINIT_FUNCTION(xmlwriter)
    1839             : {
    1840             :         zend_class_entry ce;
    1841       21049 :         le_xmlwriter = zend_register_list_destructors_ex(xmlwriter_dtor, NULL, "xmlwriter", module_number);
    1842             : 
    1843       21049 :         memcpy(&xmlwriter_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
    1844       21049 :         xmlwriter_object_handlers.offset = XtOffsetOf(ze_xmlwriter_object, std);
    1845       21049 :         xmlwriter_object_handlers.free_obj = xmlwriter_object_free_storage;
    1846       21049 :         xmlwriter_object_handlers.clone_obj = NULL;
    1847       21049 :         INIT_CLASS_ENTRY(ce, "XMLWriter", xmlwriter_class_functions);
    1848       21049 :         ce.create_object = xmlwriter_object_new;
    1849       21049 :         xmlwriter_class_entry_ce = zend_register_internal_class(&ce);
    1850             : 
    1851       21049 :         return SUCCESS;
    1852             : }
    1853             : /* }}} */
    1854             : 
    1855             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    1856             :  */
    1857       21085 : static PHP_MSHUTDOWN_FUNCTION(xmlwriter)
    1858             : {
    1859       21085 :         return SUCCESS;
    1860             : }
    1861             : /* }}} */
    1862             : 
    1863             : /* {{{ PHP_MINFO_FUNCTION
    1864             :  */
    1865         142 : static PHP_MINFO_FUNCTION(xmlwriter)
    1866             : {
    1867         142 :         php_info_print_table_start();
    1868             :         {
    1869         142 :                 php_info_print_table_row(2, "XMLWriter", "enabled");
    1870             :         }
    1871         142 :         php_info_print_table_end();
    1872         142 : }
    1873             : /* }}} */
    1874             : 
    1875             : /*
    1876             :  * Local variables:
    1877             :  * tab-width: 4
    1878             :  * c-basic-offset: 4
    1879             :  * End:
    1880             :  * vim600: noet sw=4 ts=4 fdm=marker
    1881             :  * vim<600: noet sw=4 ts=4
    1882             :  */

Generated by: LCOV version 1.10

Generated at Tue, 04 Aug 2015 09:11:15 +0000 (2 hours ago)

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