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

LTP GCOV extension - code coverage report
Current view: directory - xmlwriter - php_xmlwriter.c
Test: PHP Code Coverage
Date: 2009-11-23 Instrumented lines: 544
Code covered: 82.2 % Executed lines: 447
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Mon, 23 Nov 2009 17:39:44 +0000 (33 hours ago)

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