Annotation of embedaddon/php/ext/xmlwriter/php_xmlwriter.c, revision 1.1.1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>