Back to index

php5  5.3.10
php_xmlwriter.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt.                                 |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Rob Richards <rrichards@php.net>                             |
00016   |         Pierre-A. Joye <pajoye@php.net>                              |
00017   +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: php_xmlwriter.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025 
00026 
00027 #include "php.h"
00028 #include "php_ini.h"
00029 #include "ext/standard/info.h"
00030 #include "php_xmlwriter.h"
00031 #include "ext/standard/php_string.h"
00032 
00033 #if LIBXML_VERSION >= 20605
00034 static PHP_FUNCTION(xmlwriter_set_indent);
00035 static PHP_FUNCTION(xmlwriter_set_indent_string);
00036 #endif
00037 static PHP_FUNCTION(xmlwriter_start_attribute);
00038 static PHP_FUNCTION(xmlwriter_end_attribute);
00039 static PHP_FUNCTION(xmlwriter_write_attribute);
00040 #if LIBXML_VERSION > 20617
00041 static PHP_FUNCTION(xmlwriter_start_attribute_ns);
00042 static PHP_FUNCTION(xmlwriter_write_attribute_ns);
00043 #endif
00044 static PHP_FUNCTION(xmlwriter_start_element);
00045 static PHP_FUNCTION(xmlwriter_end_element);
00046 static PHP_FUNCTION(xmlwriter_full_end_element);
00047 static PHP_FUNCTION(xmlwriter_start_element_ns);
00048 static PHP_FUNCTION(xmlwriter_write_element);
00049 static PHP_FUNCTION(xmlwriter_write_element_ns);
00050 static PHP_FUNCTION(xmlwriter_start_pi);
00051 static PHP_FUNCTION(xmlwriter_end_pi);
00052 static PHP_FUNCTION(xmlwriter_write_pi);
00053 static PHP_FUNCTION(xmlwriter_start_cdata);
00054 static PHP_FUNCTION(xmlwriter_end_cdata);
00055 static PHP_FUNCTION(xmlwriter_write_cdata);
00056 static PHP_FUNCTION(xmlwriter_text);
00057 static PHP_FUNCTION(xmlwriter_write_raw);
00058 static PHP_FUNCTION(xmlwriter_start_document);
00059 static PHP_FUNCTION(xmlwriter_end_document);
00060 #if LIBXML_VERSION >= 20607
00061 static PHP_FUNCTION(xmlwriter_start_comment);
00062 static PHP_FUNCTION(xmlwriter_end_comment);
00063 #endif
00064 static PHP_FUNCTION(xmlwriter_write_comment);
00065 static PHP_FUNCTION(xmlwriter_start_dtd);
00066 static PHP_FUNCTION(xmlwriter_end_dtd);
00067 static PHP_FUNCTION(xmlwriter_write_dtd);
00068 static PHP_FUNCTION(xmlwriter_start_dtd_element);
00069 static PHP_FUNCTION(xmlwriter_end_dtd_element);
00070 static PHP_FUNCTION(xmlwriter_write_dtd_element);
00071 #if LIBXML_VERSION > 20608
00072 static PHP_FUNCTION(xmlwriter_start_dtd_attlist);
00073 static PHP_FUNCTION(xmlwriter_end_dtd_attlist);
00074 static PHP_FUNCTION(xmlwriter_write_dtd_attlist);
00075 static PHP_FUNCTION(xmlwriter_start_dtd_entity);
00076 static PHP_FUNCTION(xmlwriter_end_dtd_entity);
00077 static PHP_FUNCTION(xmlwriter_write_dtd_entity);
00078 #endif
00079 static PHP_FUNCTION(xmlwriter_open_uri);
00080 static PHP_FUNCTION(xmlwriter_open_memory);
00081 static PHP_FUNCTION(xmlwriter_output_memory);
00082 static PHP_FUNCTION(xmlwriter_flush);
00083 
00084 static zend_class_entry *xmlwriter_class_entry_ce;
00085 
00086 static void xmlwriter_free_resource_ptr(xmlwriter_object *intern TSRMLS_DC);
00087 static void xmlwriter_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
00088 
00089 typedef int (*xmlwriter_read_one_char_t)(xmlTextWriterPtr writer, const xmlChar *content);
00090 typedef int (*xmlwriter_read_int_t)(xmlTextWriterPtr writer);
00091 
00092 /* {{{ xmlwriter_object_free_storage */
00093 static void xmlwriter_free_resource_ptr(xmlwriter_object *intern TSRMLS_DC) 
00094 {
00095        if (intern) {
00096               if (intern->ptr) {
00097                      xmlFreeTextWriter(intern->ptr);
00098                      intern->ptr = NULL;
00099               }
00100               if (intern->output) {
00101                      xmlBufferFree(intern->output);
00102                      intern->output = NULL;
00103               }
00104               efree(intern);
00105        }
00106 }
00107 /* }}} */
00108 
00109 #ifdef ZEND_ENGINE_2
00110 /* {{{ XMLWRITER_FROM_OBJECT */
00111 #define XMLWRITER_FROM_OBJECT(intern, object) \
00112        { \
00113               ze_xmlwriter_object *obj = (ze_xmlwriter_object*) zend_object_store_get_object(object TSRMLS_CC); \
00114               intern = obj->xmlwriter_ptr; \
00115               if (!intern) { \
00116                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or unitialized XMLWriter object"); \
00117                      RETURN_FALSE; \
00118               } \
00119        }
00120 /* }}} */
00121 
00122 static zend_object_handlers xmlwriter_object_handlers;
00123 
00124 /* {{{ xmlwriter_object_free_storage */
00125 static void xmlwriter_object_free_storage(void *object TSRMLS_DC)
00126 {
00127        ze_xmlwriter_object * intern = (ze_xmlwriter_object *) object;
00128        if (!intern) {
00129               return;
00130        }
00131        if (intern->xmlwriter_ptr) {
00132               xmlwriter_free_resource_ptr(intern->xmlwriter_ptr TSRMLS_CC);
00133        }
00134        intern->xmlwriter_ptr = NULL;
00135        zend_object_std_dtor(&intern->zo TSRMLS_CC);
00136        
00137        efree(intern);
00138 }
00139 /* }}} */
00140 
00141 
00142 /* {{{ xmlwriter_object_new */
00143 static zend_object_value xmlwriter_object_new(zend_class_entry *class_type TSRMLS_DC)
00144 {
00145        ze_xmlwriter_object *intern;
00146        zval *tmp;
00147        zend_object_value retval;
00148 
00149        intern = emalloc(sizeof(ze_xmlwriter_object));
00150        memset(&intern->zo, 0, sizeof(zend_object));
00151        intern->xmlwriter_ptr = NULL;
00152        
00153        zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
00154        zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,
00155                                    (void *) &tmp, sizeof(zval *));
00156 
00157        retval.handle = zend_objects_store_put(intern,
00158                                           NULL,
00159                                           (zend_objects_free_object_storage_t) xmlwriter_object_free_storage,
00160                                           NULL TSRMLS_CC);
00161        
00162        retval.handlers = (zend_object_handlers *) & xmlwriter_object_handlers;
00163        
00164        return retval;
00165 }
00166 /* }}} */
00167 #endif
00168 
00169 #define XMLW_NAME_CHK(__err) \
00170        if (xmlValidateName((xmlChar *) name, 0) != 0) { \
00171               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", __err);      \
00172               RETURN_FALSE; \
00173        }      \
00174        
00175 /* {{{ arginfo */
00176 ZEND_BEGIN_ARG_INFO(arginfo_xmlwriter_void, 0)
00177 ZEND_END_ARG_INFO()
00178 
00179 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_resource, 0, 0, 1)
00180        ZEND_ARG_INFO(0, xmlwriter)
00181 ZEND_END_ARG_INFO()
00182 
00183 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_open_uri, 0, 0, 1)
00184        ZEND_ARG_INFO(0, uri)
00185 ZEND_END_ARG_INFO()
00186 
00187 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_set_indent, 0, 0, 2)
00188        ZEND_ARG_INFO(0, xmlwriter)
00189        ZEND_ARG_INFO(0, indent)
00190 ZEND_END_ARG_INFO()
00191 
00192 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_set_indent, 0, 0, 1)
00193        ZEND_ARG_INFO(0, indent)
00194 ZEND_END_ARG_INFO()
00195 
00196 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_set_indent_string, 0, 0, 2)
00197        ZEND_ARG_INFO(0, xmlwriter)
00198        ZEND_ARG_INFO(0, indentString)
00199 ZEND_END_ARG_INFO()
00200 
00201 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_set_indent_string, 0, 0, 1)
00202        ZEND_ARG_INFO(0, indentString)
00203 ZEND_END_ARG_INFO()
00204 
00205 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_attribute, 0, 0, 2)
00206        ZEND_ARG_INFO(0, xmlwriter)
00207        ZEND_ARG_INFO(0, name)
00208 ZEND_END_ARG_INFO()
00209 
00210 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_attribute, 0, 0, 1)
00211        ZEND_ARG_INFO(0, name)
00212 ZEND_END_ARG_INFO()
00213 
00214 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_attribute_ns, 0, 0, 4)
00215        ZEND_ARG_INFO(0, xmlwriter)
00216        ZEND_ARG_INFO(0, prefix)
00217        ZEND_ARG_INFO(0, name)
00218        ZEND_ARG_INFO(0, uri)
00219 ZEND_END_ARG_INFO()
00220 
00221 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_attribute_ns, 0, 0, 3)
00222        ZEND_ARG_INFO(0, prefix)
00223        ZEND_ARG_INFO(0, name)
00224        ZEND_ARG_INFO(0, uri)
00225 ZEND_END_ARG_INFO()
00226 
00227 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_attribute_ns, 0, 0, 5)
00228        ZEND_ARG_INFO(0, xmlwriter)
00229        ZEND_ARG_INFO(0, prefix)
00230        ZEND_ARG_INFO(0, name)
00231        ZEND_ARG_INFO(0, uri)
00232        ZEND_ARG_INFO(0, content)
00233 ZEND_END_ARG_INFO()
00234 
00235 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_attribute_ns, 0, 0, 4)
00236        ZEND_ARG_INFO(0, prefix)
00237        ZEND_ARG_INFO(0, name)
00238        ZEND_ARG_INFO(0, uri)
00239        ZEND_ARG_INFO(0, content)
00240 ZEND_END_ARG_INFO()
00241 
00242 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_attribute, 0, 0, 3)
00243        ZEND_ARG_INFO(0, xmlwriter)
00244        ZEND_ARG_INFO(0, name)
00245        ZEND_ARG_INFO(0, value)
00246 ZEND_END_ARG_INFO()
00247 
00248 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_attribute, 0, 0, 2)
00249        ZEND_ARG_INFO(0, name)
00250        ZEND_ARG_INFO(0, value)
00251 ZEND_END_ARG_INFO()
00252 
00253 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_element, 0, 0, 2)
00254        ZEND_ARG_INFO(0, xmlwriter)
00255        ZEND_ARG_INFO(0, name)
00256 ZEND_END_ARG_INFO()
00257 
00258 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_element, 0, 0, 1)
00259        ZEND_ARG_INFO(0, name)
00260 ZEND_END_ARG_INFO()
00261 
00262 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_element_ns, 0, 0, 4)
00263        ZEND_ARG_INFO(0, xmlwriter)
00264        ZEND_ARG_INFO(0, prefix)
00265        ZEND_ARG_INFO(0, name)
00266        ZEND_ARG_INFO(0, uri)
00267 ZEND_END_ARG_INFO()
00268 
00269 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_element_ns, 0, 0, 3)
00270        ZEND_ARG_INFO(0, prefix)
00271        ZEND_ARG_INFO(0, name)
00272        ZEND_ARG_INFO(0, uri)
00273 ZEND_END_ARG_INFO()
00274 
00275 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_element, 0, 0, 2)
00276        ZEND_ARG_INFO(0, xmlwriter)
00277        ZEND_ARG_INFO(0, name)
00278        ZEND_ARG_INFO(0, content)
00279 ZEND_END_ARG_INFO()
00280 
00281 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_element, 0, 0, 1)
00282        ZEND_ARG_INFO(0, name)
00283        ZEND_ARG_INFO(0, content)
00284 ZEND_END_ARG_INFO()
00285 
00286 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_element_ns, 0, 0, 4)
00287        ZEND_ARG_INFO(0, xmlwriter)
00288        ZEND_ARG_INFO(0, prefix)
00289        ZEND_ARG_INFO(0, name)
00290        ZEND_ARG_INFO(0, uri)
00291        ZEND_ARG_INFO(0, content)
00292 ZEND_END_ARG_INFO()
00293 
00294 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_element_ns, 0, 0, 3)
00295        ZEND_ARG_INFO(0, prefix)
00296        ZEND_ARG_INFO(0, name)
00297        ZEND_ARG_INFO(0, uri)
00298        ZEND_ARG_INFO(0, content)
00299 ZEND_END_ARG_INFO()
00300 
00301 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_pi, 0, 0, 2)
00302        ZEND_ARG_INFO(0, xmlwriter)
00303        ZEND_ARG_INFO(0, target)
00304 ZEND_END_ARG_INFO()
00305 
00306 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_pi, 0, 0, 1)
00307        ZEND_ARG_INFO(0, target)
00308 ZEND_END_ARG_INFO()
00309 
00310 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_pi, 0, 0, 3)
00311        ZEND_ARG_INFO(0, xmlwriter)
00312        ZEND_ARG_INFO(0, target)
00313        ZEND_ARG_INFO(0, content)
00314 ZEND_END_ARG_INFO()
00315 
00316 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_pi, 0, 0, 2)
00317        ZEND_ARG_INFO(0, target)
00318        ZEND_ARG_INFO(0, content)
00319 ZEND_END_ARG_INFO()
00320 
00321 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_cdata, 0, 0, 2)
00322        ZEND_ARG_INFO(0, xmlwriter)
00323        ZEND_ARG_INFO(0, content)
00324 ZEND_END_ARG_INFO()
00325 
00326 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_cdata, 0, 0, 1)
00327        ZEND_ARG_INFO(0, content)
00328 ZEND_END_ARG_INFO()
00329 
00330 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_text, 0, 0, 2)
00331        ZEND_ARG_INFO(0, xmlwriter)
00332        ZEND_ARG_INFO(0, content)
00333 ZEND_END_ARG_INFO()
00334 
00335 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_text, 0, 0, 1)
00336        ZEND_ARG_INFO(0, content)
00337 ZEND_END_ARG_INFO()
00338 
00339 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_raw, 0, 0, 2)
00340        ZEND_ARG_INFO(0, xmlwriter)
00341        ZEND_ARG_INFO(0, content)
00342 ZEND_END_ARG_INFO()
00343 
00344 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_raw, 0, 0, 1)
00345        ZEND_ARG_INFO(0, content)
00346 ZEND_END_ARG_INFO()
00347 
00348 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_document, 0, 0, 1)
00349        ZEND_ARG_INFO(0, xmlwriter)
00350        ZEND_ARG_INFO(0, version)
00351        ZEND_ARG_INFO(0, encoding)
00352        ZEND_ARG_INFO(0, standalone)
00353 ZEND_END_ARG_INFO()
00354 
00355 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_document, 0, 0, 0)
00356        ZEND_ARG_INFO(0, version)
00357        ZEND_ARG_INFO(0, encoding)
00358        ZEND_ARG_INFO(0, standalone)
00359 ZEND_END_ARG_INFO()
00360 
00361 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_comment, 0, 0, 2)
00362        ZEND_ARG_INFO(0, xmlwriter)
00363        ZEND_ARG_INFO(0, content)
00364 ZEND_END_ARG_INFO()
00365 
00366 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_comment, 0, 0, 1)
00367        ZEND_ARG_INFO(0, content)
00368 ZEND_END_ARG_INFO()
00369 
00370 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd, 0, 0, 2)
00371        ZEND_ARG_INFO(0, xmlwriter)
00372        ZEND_ARG_INFO(0, qualifiedName)
00373        ZEND_ARG_INFO(0, publicId)
00374        ZEND_ARG_INFO(0, systemId)
00375 ZEND_END_ARG_INFO()
00376 
00377 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd, 0, 0, 1)
00378        ZEND_ARG_INFO(0, qualifiedName)
00379        ZEND_ARG_INFO(0, publicId)
00380        ZEND_ARG_INFO(0, systemId)
00381 ZEND_END_ARG_INFO()
00382 
00383 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd, 0, 0, 2)
00384        ZEND_ARG_INFO(0, xmlwriter)
00385        ZEND_ARG_INFO(0, name)
00386        ZEND_ARG_INFO(0, publicId)
00387        ZEND_ARG_INFO(0, systemId)
00388        ZEND_ARG_INFO(0, subset)
00389 ZEND_END_ARG_INFO()
00390 
00391 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd, 0, 0, 1)
00392        ZEND_ARG_INFO(0, name)
00393        ZEND_ARG_INFO(0, publicId)
00394        ZEND_ARG_INFO(0, systemId)
00395        ZEND_ARG_INFO(0, subset)
00396 ZEND_END_ARG_INFO()
00397 
00398 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_element, 0, 0, 2)
00399        ZEND_ARG_INFO(0, xmlwriter)
00400        ZEND_ARG_INFO(0, qualifiedName)
00401 ZEND_END_ARG_INFO()
00402 
00403 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_element, 0, 0, 1)
00404        ZEND_ARG_INFO(0, qualifiedName)
00405 ZEND_END_ARG_INFO()
00406 
00407 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_element, 0, 0, 3)
00408        ZEND_ARG_INFO(0, xmlwriter)
00409        ZEND_ARG_INFO(0, name)
00410        ZEND_ARG_INFO(0, content)
00411 ZEND_END_ARG_INFO()
00412 
00413 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_element, 0, 0, 2)
00414        ZEND_ARG_INFO(0, name)
00415        ZEND_ARG_INFO(0, content)
00416 ZEND_END_ARG_INFO()
00417 
00418 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_attlist, 0, 0, 2)
00419        ZEND_ARG_INFO(0, xmlwriter)
00420        ZEND_ARG_INFO(0, name)
00421 ZEND_END_ARG_INFO()
00422 
00423 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_attlist, 0, 0, 1)
00424        ZEND_ARG_INFO(0, name)
00425 ZEND_END_ARG_INFO()
00426 
00427 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_attlist, 0, 0, 3)
00428        ZEND_ARG_INFO(0, xmlwriter)
00429        ZEND_ARG_INFO(0, name)
00430        ZEND_ARG_INFO(0, content)
00431 ZEND_END_ARG_INFO()
00432 
00433 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_attlist, 0, 0, 2)
00434        ZEND_ARG_INFO(0, name)
00435        ZEND_ARG_INFO(0, content)
00436 ZEND_END_ARG_INFO()
00437 
00438 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_entity, 0, 0, 3)
00439        ZEND_ARG_INFO(0, xmlwriter)
00440        ZEND_ARG_INFO(0, name)
00441        ZEND_ARG_INFO(0, isparam)
00442 ZEND_END_ARG_INFO()
00443 
00444 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_entity, 0, 0, 2)
00445        ZEND_ARG_INFO(0, name)
00446        ZEND_ARG_INFO(0, isparam)
00447 ZEND_END_ARG_INFO()
00448 
00449 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_entity, 0, 0, 3)
00450        ZEND_ARG_INFO(0, xmlwriter)
00451        ZEND_ARG_INFO(0, name)
00452        ZEND_ARG_INFO(0, content)
00453 ZEND_END_ARG_INFO()
00454 
00455 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_entity, 0, 0, 2)
00456        ZEND_ARG_INFO(0, name)
00457        ZEND_ARG_INFO(0, content)
00458 ZEND_END_ARG_INFO()
00459 
00460 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_output_memory, 0, 0, 1)
00461        ZEND_ARG_INFO(0, xmlwriter)
00462        ZEND_ARG_INFO(0, flush)
00463 ZEND_END_ARG_INFO()
00464 
00465 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_output_memory, 0, 0, 0)
00466        ZEND_ARG_INFO(0, flush)
00467 ZEND_END_ARG_INFO()
00468 
00469 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_flush, 0, 0, 1)
00470        ZEND_ARG_INFO(0, xmlwriter)
00471        ZEND_ARG_INFO(0, empty)
00472 ZEND_END_ARG_INFO()
00473 
00474 ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_flush, 0, 0, 0)
00475        ZEND_ARG_INFO(0, empty)
00476 ZEND_END_ARG_INFO()
00477 /* }}} */
00478 
00479 /* {{{ xmlwriter_functions */
00480 static const zend_function_entry xmlwriter_functions[] = {
00481        PHP_FE(xmlwriter_open_uri,                arginfo_xmlwriter_open_uri)
00482        PHP_FE(xmlwriter_open_memory,             arginfo_xmlwriter_void)
00483 #if LIBXML_VERSION >= 20605
00484        PHP_FE(xmlwriter_set_indent,              arginfo_xmlwriter_set_indent)
00485        PHP_FE(xmlwriter_set_indent_string, arginfo_xmlwriter_set_indent_string)
00486 #endif
00487 #if LIBXML_VERSION >= 20607
00488        PHP_FE(xmlwriter_start_comment,           arginfo_xmlwriter_resource)
00489        PHP_FE(xmlwriter_end_comment,             arginfo_xmlwriter_resource)
00490 #endif
00491        PHP_FE(xmlwriter_start_attribute,  arginfo_xmlwriter_start_attribute)
00492        PHP_FE(xmlwriter_end_attribute,           arginfo_xmlwriter_resource)
00493        PHP_FE(xmlwriter_write_attribute,  arginfo_xmlwriter_write_attribute)
00494 #if LIBXML_VERSION > 20617
00495        PHP_FE(xmlwriter_start_attribute_ns,arginfo_xmlwriter_start_attribute_ns)
00496        PHP_FE(xmlwriter_write_attribute_ns,arginfo_xmlwriter_write_attribute_ns)
00497 #endif
00498        PHP_FE(xmlwriter_start_element,           arginfo_xmlwriter_start_element)
00499        PHP_FE(xmlwriter_end_element,             arginfo_xmlwriter_resource)
00500        PHP_FE(xmlwriter_full_end_element, arginfo_xmlwriter_resource)
00501        PHP_FE(xmlwriter_start_element_ns, arginfo_xmlwriter_start_element_ns)
00502        PHP_FE(xmlwriter_write_element,           arginfo_xmlwriter_write_element)
00503        PHP_FE(xmlwriter_write_element_ns, arginfo_xmlwriter_write_element_ns)
00504        PHP_FE(xmlwriter_start_pi,                arginfo_xmlwriter_start_pi)
00505        PHP_FE(xmlwriter_end_pi,                  arginfo_xmlwriter_resource)
00506        PHP_FE(xmlwriter_write_pi,                arginfo_xmlwriter_write_pi)
00507        PHP_FE(xmlwriter_start_cdata,             arginfo_xmlwriter_resource)
00508        PHP_FE(xmlwriter_end_cdata,               arginfo_xmlwriter_resource)
00509        PHP_FE(xmlwriter_write_cdata,             arginfo_xmlwriter_write_cdata)
00510        PHP_FE(xmlwriter_text,                           arginfo_xmlwriter_text)
00511        PHP_FE(xmlwriter_write_raw,               arginfo_xmlwriter_write_raw)
00512        PHP_FE(xmlwriter_start_document,   arginfo_xmlwriter_start_document)
00513        PHP_FE(xmlwriter_end_document,            arginfo_xmlwriter_resource)
00514        PHP_FE(xmlwriter_write_comment,           arginfo_xmlwriter_write_comment)
00515        PHP_FE(xmlwriter_start_dtd,               arginfo_xmlwriter_start_dtd)
00516        PHP_FE(xmlwriter_end_dtd,                 arginfo_xmlwriter_resource)
00517        PHP_FE(xmlwriter_write_dtd,               arginfo_xmlwriter_write_dtd)
00518        PHP_FE(xmlwriter_start_dtd_element,       arginfo_xmlwriter_start_dtd_element)
00519        PHP_FE(xmlwriter_end_dtd_element,  arginfo_xmlwriter_resource)
00520        PHP_FE(xmlwriter_write_dtd_element,       arginfo_xmlwriter_write_dtd_element)
00521 #if LIBXML_VERSION > 20608
00522        PHP_FE(xmlwriter_start_dtd_attlist,       arginfo_xmlwriter_start_dtd_attlist)
00523        PHP_FE(xmlwriter_end_dtd_attlist,  arginfo_xmlwriter_resource)
00524        PHP_FE(xmlwriter_write_dtd_attlist,       arginfo_xmlwriter_write_dtd_attlist)
00525        PHP_FE(xmlwriter_start_dtd_entity, arginfo_xmlwriter_start_dtd_entity)
00526        PHP_FE(xmlwriter_end_dtd_entity,   arginfo_xmlwriter_resource)
00527        PHP_FE(xmlwriter_write_dtd_entity, arginfo_xmlwriter_write_dtd_entity)
00528 #endif
00529        PHP_FE(xmlwriter_output_memory,           arginfo_xmlwriter_output_memory)
00530        PHP_FE(xmlwriter_flush,                          arginfo_xmlwriter_flush)
00531        PHP_FE_END
00532 };
00533 /* }}} */
00534 
00535 #ifdef ZEND_ENGINE_2
00536 /* {{{ xmlwriter_class_functions */
00537 static const zend_function_entry xmlwriter_class_functions[] = {
00538        PHP_ME_MAPPING(openUri,            xmlwriter_open_uri,         arginfo_xmlwriter_open_uri, 0)
00539        PHP_ME_MAPPING(openMemory,  xmlwriter_open_memory,      arginfo_xmlwriter_void, 0)
00540 #if LIBXML_VERSION >= 20605
00541        PHP_ME_MAPPING(setIndent,   xmlwriter_set_indent,       arginfo_xmlwriter_method_set_indent, 0)
00542        PHP_ME_MAPPING(setIndentString,    xmlwriter_set_indent_string, arginfo_xmlwriter_method_set_indent_string, 0)
00543 #endif
00544 #if LIBXML_VERSION >= 20607
00545        PHP_ME_MAPPING(startComment,       xmlwriter_start_comment,    arginfo_xmlwriter_void, 0)
00546        PHP_ME_MAPPING(endComment,         xmlwriter_end_comment,             arginfo_xmlwriter_void, 0)
00547 #endif
00548        PHP_ME_MAPPING(startAttribute,     xmlwriter_start_attribute,  arginfo_xmlwriter_method_start_attribute, 0)
00549        PHP_ME_MAPPING(endAttribute,       xmlwriter_end_attribute,    arginfo_xmlwriter_void, 0)
00550        PHP_ME_MAPPING(writeAttribute,     xmlwriter_write_attribute,  arginfo_xmlwriter_method_write_attribute, 0)
00551 #if LIBXML_VERSION > 20617
00552        PHP_ME_MAPPING(startAttributeNs,   xmlwriter_start_attribute_ns,arginfo_xmlwriter_method_start_attribute_ns, 0)
00553        PHP_ME_MAPPING(writeAttributeNs,   xmlwriter_write_attribute_ns,arginfo_xmlwriter_method_write_attribute_ns, 0)
00554 #endif
00555        PHP_ME_MAPPING(startElement,       xmlwriter_start_element,    arginfo_xmlwriter_method_start_element, 0)
00556        PHP_ME_MAPPING(endElement,         xmlwriter_end_element,             arginfo_xmlwriter_void, 0)
00557        PHP_ME_MAPPING(fullEndElement,     xmlwriter_full_end_element, arginfo_xmlwriter_void, 0)
00558        PHP_ME_MAPPING(startElementNs,     xmlwriter_start_element_ns, arginfo_xmlwriter_method_start_element_ns, 0)
00559        PHP_ME_MAPPING(writeElement,       xmlwriter_write_element,    arginfo_xmlwriter_method_write_element, 0)
00560        PHP_ME_MAPPING(writeElementNs,     xmlwriter_write_element_ns, arginfo_xmlwriter_method_write_element_ns, 0)
00561        PHP_ME_MAPPING(startPi,                   xmlwriter_start_pi,                arginfo_xmlwriter_method_start_pi, 0)
00562        PHP_ME_MAPPING(endPi,                     xmlwriter_end_pi,                  arginfo_xmlwriter_void, 0)
00563        PHP_ME_MAPPING(writePi,                   xmlwriter_write_pi,                arginfo_xmlwriter_method_write_pi, 0)
00564        PHP_ME_MAPPING(startCdata,         xmlwriter_start_cdata,             arginfo_xmlwriter_void, 0)
00565        PHP_ME_MAPPING(endCdata,           xmlwriter_end_cdata,        arginfo_xmlwriter_void, 0)
00566        PHP_ME_MAPPING(writeCdata,         xmlwriter_write_cdata,             arginfo_xmlwriter_method_write_cdata, 0)
00567        PHP_ME_MAPPING(text,               xmlwriter_text,                           arginfo_xmlwriter_method_text, 0)
00568        PHP_ME_MAPPING(writeRaw,           xmlwriter_write_raw,        arginfo_xmlwriter_method_write_raw, 0)
00569        PHP_ME_MAPPING(startDocument,      xmlwriter_start_document,   arginfo_xmlwriter_method_start_document, 0)
00570        PHP_ME_MAPPING(endDocument,        xmlwriter_end_document,            arginfo_xmlwriter_void, 0)
00571        PHP_ME_MAPPING(writeComment,       xmlwriter_write_comment,    arginfo_xmlwriter_method_write_comment, 0)
00572        PHP_ME_MAPPING(startDtd,           xmlwriter_start_dtd,        arginfo_xmlwriter_method_start_dtd, 0)
00573        PHP_ME_MAPPING(endDtd,                    xmlwriter_end_dtd,                 arginfo_xmlwriter_void, 0)
00574        PHP_ME_MAPPING(writeDtd,           xmlwriter_write_dtd,        arginfo_xmlwriter_method_write_dtd, 0)
00575        PHP_ME_MAPPING(startDtdElement,    xmlwriter_start_dtd_element,arginfo_xmlwriter_method_start_dtd_element, 0)
00576        PHP_ME_MAPPING(endDtdElement,      xmlwriter_end_dtd_element,  arginfo_xmlwriter_void, 0)
00577        PHP_ME_MAPPING(writeDtdElement,    xmlwriter_write_dtd_element,       arginfo_xmlwriter_method_write_dtd_element, 0)
00578 #if LIBXML_VERSION > 20608
00579        PHP_ME_MAPPING(startDtdAttlist,    xmlwriter_start_dtd_attlist,       arginfo_xmlwriter_method_start_dtd_attlist, 0)
00580        PHP_ME_MAPPING(endDtdAttlist,      xmlwriter_end_dtd_attlist,  arginfo_xmlwriter_void, 0)
00581        PHP_ME_MAPPING(writeDtdAttlist,    xmlwriter_write_dtd_attlist,       arginfo_xmlwriter_method_write_dtd_attlist, 0)
00582        PHP_ME_MAPPING(startDtdEntity,     xmlwriter_start_dtd_entity, arginfo_xmlwriter_method_start_dtd_entity, 0)
00583        PHP_ME_MAPPING(endDtdEntity,       xmlwriter_end_dtd_entity,   arginfo_xmlwriter_void, 0)
00584        PHP_ME_MAPPING(writeDtdEntity,     xmlwriter_write_dtd_entity, arginfo_xmlwriter_method_write_dtd_entity, 0)
00585 #endif
00586        PHP_ME_MAPPING(outputMemory,       xmlwriter_output_memory,    arginfo_xmlwriter_method_output_memory, 0)
00587        PHP_ME_MAPPING(flush,                     xmlwriter_flush,                   arginfo_xmlwriter_method_flush, 0)
00588        {NULL, NULL, NULL}
00589 };
00590 /* }}} */
00591 #endif
00592 
00593 /* {{{ function prototypes */
00594 static PHP_MINIT_FUNCTION(xmlwriter);
00595 static PHP_MSHUTDOWN_FUNCTION(xmlwriter);
00596 static PHP_MINFO_FUNCTION(xmlwriter);
00597 
00598 static int le_xmlwriter;
00599 /* }}} */
00600 
00601 /* _xmlwriter_get_valid_file_path should be made a 
00602        common function in libxml extension as code is common to a few xml extensions */
00603 /* {{{ _xmlwriter_get_valid_file_path */
00604 static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len  TSRMLS_DC) {
00605        xmlURI *uri;
00606        xmlChar *escsource;
00607        char *file_dest;
00608        int isFileUri = 0;
00609 
00610        uri = xmlCreateURI();
00611        escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *) ":");
00612        xmlParseURIReference(uri, (char *)escsource);
00613        xmlFree(escsource);
00614 
00615        if (uri->scheme != NULL) {
00616               /* absolute file uris - libxml only supports localhost or empty host */
00617               if (strncasecmp(source, "file:///", 8) == 0) {
00618                      if (source[sizeof("file:///") - 1] == '\0') {
00619                             return NULL;
00620                      }
00621                      isFileUri = 1;
00622 #ifdef PHP_WIN32
00623                      source += 8;
00624 #else
00625                      source += 7;
00626 #endif
00627               } else if (strncasecmp(source, "file://localhost/",17) == 0) {
00628                      if (source[sizeof("file://localhost/") - 1] == '\0') {
00629                             return NULL;
00630                      }
00631 
00632                      isFileUri = 1;
00633 #ifdef PHP_WIN32
00634                      source += 17;
00635 #else
00636                      source += 16;
00637 #endif
00638               }
00639        }
00640 
00641        if ((uri->scheme == NULL || isFileUri)) {
00642               char file_dirname[MAXPATHLEN];
00643               size_t dir_len;
00644 
00645               if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) {
00646                      xmlFreeURI(uri);
00647                      return NULL;
00648               }
00649 
00650               memcpy(file_dirname, source, strlen(source));
00651               dir_len = php_dirname(file_dirname, strlen(source));
00652 
00653               if (dir_len > 0) {
00654                      struct stat buf;
00655                      if (php_sys_stat(file_dirname, &buf) != 0) {
00656                             xmlFreeURI(uri);
00657                             return NULL;
00658                      }
00659               }
00660 
00661               file_dest = resolved_path;
00662        } else {
00663               file_dest = source;
00664        }
00665 
00666        xmlFreeURI(uri);
00667 
00668        return file_dest;
00669 }
00670 /* }}} */
00671 
00672 #ifndef ZEND_ENGINE_2
00673 /* Channel libxml file io layer through the PHP streams subsystem.
00674  * This allows use of ftps:// and https:// urls */
00675 
00676 /* {{{ php_xmlwriter_streams_IO_open_write_wrapper */
00677 static void *php_xmlwriter_streams_IO_open_write_wrapper(const char *filename TSRMLS_DC)
00678 {
00679        php_stream_wrapper *wrapper = NULL;
00680        void *ret_val = NULL;
00681 
00682        ret_val = php_stream_open_wrapper_ex((char *)filename, "wb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL, NULL);
00683        return ret_val;
00684 }
00685 /* }}} */
00686 
00687 /* {{{ php_xmlwriter_streams_IO_write */
00688 static int php_xmlwriter_streams_IO_write(void *context, const char *buffer, int len)
00689 {
00690        TSRMLS_FETCH();
00691        return php_stream_write((php_stream*)context, buffer, len);
00692 }
00693 /* }}} */
00694 
00695 /* {{{ php_xmlwriter_streams_IO_close */
00696 static int php_xmlwriter_streams_IO_close(void *context)
00697 {
00698        TSRMLS_FETCH();
00699        return php_stream_close((php_stream*)context);
00700 }
00701 /* }}} */
00702 #endif
00703 
00704 /* {{{ xmlwriter_module_entry
00705  */
00706 zend_module_entry xmlwriter_module_entry = {
00707        STANDARD_MODULE_HEADER,
00708        "xmlwriter",
00709        xmlwriter_functions,
00710        PHP_MINIT(xmlwriter),
00711        PHP_MSHUTDOWN(xmlwriter),
00712        NULL,
00713        NULL,
00714        PHP_MINFO(xmlwriter),
00715        "0.1",
00716        STANDARD_MODULE_PROPERTIES
00717 };
00718 /* }}} */
00719 
00720 #ifdef COMPILE_DL_XMLWRITER
00721 ZEND_GET_MODULE(xmlwriter)
00722 #endif
00723 
00724 /* {{{ xmlwriter_objects_clone 
00725 static void xmlwriter_objects_clone(void *object, void **object_clone TSRMLS_DC)
00726 {
00727        TODO
00728 }
00729 }}} */
00730 
00731 /* {{{ xmlwriter_dtor */
00732 static void xmlwriter_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
00733        xmlwriter_object *intern;
00734 
00735        intern = (xmlwriter_object *) rsrc->ptr;
00736        xmlwriter_free_resource_ptr(intern TSRMLS_CC);
00737 }
00738 /* }}} */
00739 
00740 static void php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_one_char_t internal_function, char *err_string)
00741 {
00742        zval *pind;
00743        xmlwriter_object *intern;
00744        xmlTextWriterPtr ptr;
00745        char *name;
00746        int name_len, retval;
00747 
00748 #ifdef ZEND_ENGINE_2
00749        zval *this = getThis();
00750        
00751        if (this) {
00752               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
00753                      return;
00754               }
00755               XMLWRITER_FROM_OBJECT(intern, this);
00756        } else
00757 #endif
00758        {
00759               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pind, &name, &name_len) == FAILURE) {
00760                      return;
00761               }
00762        
00763               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
00764        }
00765 
00766        if (err_string != NULL) {
00767               XMLW_NAME_CHK(err_string);
00768        }
00769 
00770        ptr = intern->ptr;
00771 
00772        if (ptr) {
00773               retval = internal_function(ptr, (xmlChar *) name);
00774               if (retval != -1) {
00775                      RETURN_TRUE;
00776               }
00777        }
00778        
00779        RETURN_FALSE;
00780 }
00781 
00782 static void php_xmlwriter_end(INTERNAL_FUNCTION_PARAMETERS, xmlwriter_read_int_t internal_function)
00783 {
00784        zval *pind;
00785        xmlwriter_object *intern;
00786        xmlTextWriterPtr ptr;
00787        int retval;
00788 #ifdef ZEND_ENGINE_2
00789        zval *this = getThis();
00790        
00791        if (this) {
00792               XMLWRITER_FROM_OBJECT(intern, this);
00793               if (zend_parse_parameters_none() == FAILURE) {
00794                      return;
00795               }
00796        } else 
00797 #endif
00798        {
00799               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
00800                      return;
00801               }
00802               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
00803        }
00804 
00805        ptr = intern->ptr;
00806 
00807        if (ptr) {
00808               retval = internal_function(ptr);
00809               if (retval != -1) {
00810                      RETURN_TRUE;
00811               }
00812        }
00813        
00814        RETURN_FALSE;
00815 }
00816 
00817 #if LIBXML_VERSION >= 20605
00818 /* {{{ proto bool xmlwriter_set_indent(resource xmlwriter, bool indent)
00819 Toggle indentation on/off - returns FALSE on error */
00820 static PHP_FUNCTION(xmlwriter_set_indent)
00821 {
00822        zval *pind;
00823        xmlwriter_object *intern;
00824        xmlTextWriterPtr ptr;
00825        int retval;
00826        zend_bool indent;
00827 
00828 #ifdef ZEND_ENGINE_2
00829        zval *this = getThis();
00830        
00831        if (this) {
00832               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &indent) == FAILURE) {
00833                      return;
00834               }
00835               XMLWRITER_FROM_OBJECT(intern, this);
00836        } else
00837 #endif
00838        {
00839               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &pind, &indent) == FAILURE) {
00840                      return;
00841               }
00842               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
00843        }
00844 
00845 
00846        ptr = intern->ptr;
00847        if (ptr) {
00848               retval = xmlTextWriterSetIndent(ptr, indent);
00849               if (retval == 0) {
00850                      RETURN_TRUE;
00851               }
00852        }
00853        
00854        RETURN_FALSE;
00855 }
00856 /* }}} */
00857 
00858 /* {{{ proto bool xmlwriter_set_indent_string(resource xmlwriter, string indentString)
00859 Set string used for indenting - returns FALSE on error */
00860 static PHP_FUNCTION(xmlwriter_set_indent_string)
00861 {
00862        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterSetIndentString, NULL);
00863 }
00864 /* }}} */
00865 
00866 #endif
00867 
00868 /* {{{ proto bool xmlwriter_start_attribute(resource xmlwriter, string name)
00869 Create start attribute - returns FALSE on error */
00870 static PHP_FUNCTION(xmlwriter_start_attribute)
00871 {
00872        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartAttribute, "Invalid Attribute Name");
00873 }
00874 /* }}} */
00875 
00876 /* {{{ proto bool xmlwriter_end_attribute(resource xmlwriter)
00877 End attribute - returns FALSE on error */
00878 static PHP_FUNCTION(xmlwriter_end_attribute)
00879 {
00880        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndAttribute);
00881 }
00882 /* }}} */
00883 
00884 #if LIBXML_VERSION > 20617
00885 /* {{{ proto bool xmlwriter_start_attribute_ns(resource xmlwriter, string prefix, string name, string uri)
00886 Create start namespaced attribute - returns FALSE on error */
00887 static PHP_FUNCTION(xmlwriter_start_attribute_ns)
00888 {
00889        zval *pind;
00890        xmlwriter_object *intern;
00891        xmlTextWriterPtr ptr;
00892        char *name, *prefix, *uri;
00893        int name_len, prefix_len, uri_len, retval;
00894 #ifdef ZEND_ENGINE_2
00895        zval *this = getThis();
00896        
00897        if (this) {
00898               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss!", 
00899                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
00900                      return;
00901               }
00902               XMLWRITER_FROM_OBJECT(intern, this);
00903        } else
00904 #endif
00905        {
00906               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss!", &pind, 
00907                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
00908                      return;
00909               }
00910               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
00911        }
00912 
00913        XMLW_NAME_CHK("Invalid Attribute Name");
00914 
00915        ptr = intern->ptr;
00916 
00917        if (ptr) {
00918               retval = xmlTextWriterStartAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
00919               if (retval != -1) {
00920                      RETURN_TRUE;
00921               }
00922        }
00923        
00924        RETURN_FALSE;
00925 }
00926 /* }}} */
00927 #endif
00928 
00929 /* {{{ proto bool xmlwriter_write_attribute(resource xmlwriter, string name, string content)
00930 Write full attribute - returns FALSE on error */
00931 static PHP_FUNCTION(xmlwriter_write_attribute)
00932 {
00933        zval *pind;
00934        xmlwriter_object *intern;
00935        xmlTextWriterPtr ptr;
00936        char *name, *content;
00937        int name_len, content_len, retval;
00938 
00939 #ifdef ZEND_ENGINE_2
00940        zval *this = getThis();
00941        
00942        if (this) {
00943               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", 
00944                      &name, &name_len, &content, &content_len) == FAILURE) {
00945                      return;
00946               }
00947               XMLWRITER_FROM_OBJECT(intern, this);
00948        } else
00949 #endif
00950        {
00951               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, 
00952                      &name, &name_len, &content, &content_len) == FAILURE) {
00953                      return;
00954               }
00955               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
00956        }
00957 
00958        XMLW_NAME_CHK("Invalid Attribute Name");
00959 
00960        ptr = intern->ptr;
00961 
00962        if (ptr) {
00963               retval = xmlTextWriterWriteAttribute(ptr, (xmlChar *)name, (xmlChar *)content);
00964               if (retval != -1) {
00965                      RETURN_TRUE;
00966               }
00967        }
00968        
00969        RETURN_FALSE;
00970 }
00971 /* }}} */
00972 
00973 #if LIBXML_VERSION > 20617
00974 /* {{{ proto bool xmlwriter_write_attribute_ns(resource xmlwriter, string prefix, string name, string uri, string content)
00975 Write full namespaced attribute - returns FALSE on error */
00976 static PHP_FUNCTION(xmlwriter_write_attribute_ns)
00977 {
00978        zval *pind;
00979        xmlwriter_object *intern;
00980        xmlTextWriterPtr ptr;
00981        char *name, *prefix, *uri, *content;
00982        int name_len, prefix_len, uri_len, content_len, retval;
00983 
00984 #ifdef ZEND_ENGINE_2
00985        zval *this = getThis();
00986        
00987        if (this) {
00988               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss!s", 
00989                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
00990                      return;
00991               }
00992               XMLWRITER_FROM_OBJECT(intern, this);
00993        } else
00994 #endif
00995        {
00996               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss!s", &pind, 
00997                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
00998                      return;
00999               }
01000               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01001        }
01002 
01003        XMLW_NAME_CHK("Invalid Attribute Name");
01004 
01005        ptr = intern->ptr;
01006 
01007        if (ptr) {
01008               retval = xmlTextWriterWriteAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
01009               if (retval != -1) {
01010                      RETURN_TRUE;
01011               }
01012        }
01013        
01014        RETURN_FALSE;
01015 }
01016 /* }}} */
01017 #endif
01018 
01019 /* {{{ proto bool xmlwriter_start_element(resource xmlwriter, string name)
01020 Create start element tag - returns FALSE on error */
01021 static PHP_FUNCTION(xmlwriter_start_element)
01022 {
01023        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartElement, "Invalid Element Name");
01024 }
01025 /* }}} */
01026 
01027 /* {{{ proto bool xmlwriter_start_element_ns(resource xmlwriter, string prefix, string name, string uri)
01028 Create start namespaced element tag - returns FALSE on error */
01029 static PHP_FUNCTION(xmlwriter_start_element_ns)
01030 {
01031        zval *pind;
01032        xmlwriter_object *intern;
01033        xmlTextWriterPtr ptr;
01034        char *name, *prefix, *uri;
01035        int name_len, prefix_len, uri_len, retval;
01036 #ifdef ZEND_ENGINE_2
01037        zval *this = getThis();
01038        
01039        if (this) {
01040               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss!",
01041                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
01042                      return;
01043               }
01044               XMLWRITER_FROM_OBJECT(intern, this);
01045        } else
01046 #endif
01047        {
01048               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!ss!", &pind, 
01049                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
01050                      return;
01051               }
01052               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01053        }
01054 
01055        XMLW_NAME_CHK("Invalid Element Name");
01056 
01057        ptr = intern->ptr;
01058 
01059        if (ptr) {
01060               retval = xmlTextWriterStartElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
01061               if (retval != -1) {
01062                      RETURN_TRUE;
01063               }
01064               
01065        }
01066        
01067        RETURN_FALSE;
01068 }
01069 /* }}} */
01070 
01071 /* {{{ proto bool xmlwriter_end_element(resource xmlwriter)
01072 End current element - returns FALSE on error */
01073 static PHP_FUNCTION(xmlwriter_end_element)
01074 {
01075        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndElement);
01076 }
01077 /* }}} */
01078 
01079 /* {{{ proto bool xmlwriter_full_end_element(resource xmlwriter)
01080 End current element - returns FALSE on error */
01081 static PHP_FUNCTION(xmlwriter_full_end_element)
01082 {
01083        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterFullEndElement);
01084 }
01085 /* }}} */
01086 
01087 /* {{{ proto bool xmlwriter_write_element(resource xmlwriter, string name[, string content])
01088 Write full element tag - returns FALSE on error */
01089 static PHP_FUNCTION(xmlwriter_write_element)
01090 {
01091        zval *pind;
01092        xmlwriter_object *intern;
01093        xmlTextWriterPtr ptr;
01094        char *name, *content = NULL;
01095        int name_len, content_len, retval;
01096 
01097 #ifdef ZEND_ENGINE_2
01098        zval *this = getThis();
01099        
01100        if (this) {
01101               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!",
01102                      &name, &name_len, &content, &content_len) == FAILURE) {
01103                      return;
01104               }
01105               XMLWRITER_FROM_OBJECT(intern, this);
01106        } else
01107 #endif
01108        {
01109               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!", &pind, 
01110                      &name, &name_len, &content, &content_len) == FAILURE) {
01111                      return;
01112               }
01113               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01114        }
01115 
01116        XMLW_NAME_CHK("Invalid Element Name");
01117 
01118        ptr = intern->ptr;
01119 
01120        if (ptr) {
01121               if (!content) {
01122                      retval = xmlTextWriterStartElement(ptr, (xmlChar *)name);
01123             if (retval == -1) {
01124                 RETURN_FALSE;
01125             }
01126                      xmlTextWriterEndElement(ptr);
01127             if (retval == -1) {
01128                 RETURN_FALSE;
01129             }
01130               } else {
01131                      retval = xmlTextWriterWriteElement(ptr, (xmlChar *)name, (xmlChar *)content);
01132               }
01133               if (retval != -1) {
01134                      RETURN_TRUE;
01135               }
01136        }
01137        
01138        RETURN_FALSE;
01139 }
01140 /* }}} */
01141 
01142 /* {{{ proto bool xmlwriter_write_element_ns(resource xmlwriter, string prefix, string name, string uri[, string content])
01143 Write full namesapced element tag - returns FALSE on error */
01144 static PHP_FUNCTION(xmlwriter_write_element_ns)
01145 {
01146        zval *pind;
01147        xmlwriter_object *intern;
01148        xmlTextWriterPtr ptr;
01149        char *name, *prefix, *uri, *content = NULL;
01150        int name_len, prefix_len, uri_len, content_len, retval;
01151 
01152 #ifdef ZEND_ENGINE_2
01153        zval *this = getThis();
01154        
01155        if (this) {
01156               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss!|s!", 
01157                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
01158                      return;
01159               }
01160               XMLWRITER_FROM_OBJECT(intern, this);
01161        } else
01162 #endif
01163        {
01164               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!ss!|s!", &pind, 
01165                      &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
01166                      return;
01167               }
01168               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01169        }
01170 
01171        XMLW_NAME_CHK("Invalid Element Name");
01172 
01173        ptr = intern->ptr;
01174 
01175        if (ptr) {
01176               if (!content) {
01177                      retval = xmlTextWriterStartElementNS(ptr,(xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
01178             if (retval == -1) {
01179                 RETURN_FALSE;
01180             }
01181                      retval = xmlTextWriterEndElement(ptr);
01182             if (retval == -1) {
01183                 RETURN_FALSE;
01184             }
01185               } else {
01186                      retval = xmlTextWriterWriteElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
01187               }
01188               if (retval != -1) {
01189                      RETURN_TRUE;
01190               }
01191        }
01192        
01193        RETURN_FALSE;
01194 }
01195 /* }}} */
01196 
01197 /* {{{ proto bool xmlwriter_start_pi(resource xmlwriter, string target)
01198 Create start PI tag - returns FALSE on error */
01199 static PHP_FUNCTION(xmlwriter_start_pi)
01200 {
01201        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartPI, "Invalid PI Target");
01202 }
01203 /* }}} */
01204 
01205 /* {{{ proto bool xmlwriter_end_pi(resource xmlwriter)
01206 End current PI - returns FALSE on error */
01207 static PHP_FUNCTION(xmlwriter_end_pi)
01208 {
01209        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndPI);
01210 }
01211 /* }}} */
01212 
01213 /* {{{ proto bool xmlwriter_write_pi(resource xmlwriter, string target, string content)
01214 Write full PI tag - returns FALSE on error */
01215 static PHP_FUNCTION(xmlwriter_write_pi)
01216 {
01217        zval *pind;
01218        xmlwriter_object *intern;
01219        xmlTextWriterPtr ptr;
01220        char *name, *content;
01221        int name_len, content_len, retval;
01222 
01223 #ifdef ZEND_ENGINE_2
01224        zval *this = getThis();
01225        
01226        if (this) {
01227               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
01228                      &name, &name_len, &content, &content_len) == FAILURE) {
01229                      return;
01230               }
01231               XMLWRITER_FROM_OBJECT(intern, this);
01232        } else
01233 #endif
01234        {
01235               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, 
01236                      &name, &name_len, &content, &content_len) == FAILURE) {
01237                      return;
01238               }
01239               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01240        }
01241 
01242        XMLW_NAME_CHK("Invalid PI Target");
01243 
01244        ptr = intern->ptr;
01245 
01246        if (ptr) {
01247               retval = xmlTextWriterWritePI(ptr, (xmlChar *)name, (xmlChar *)content);
01248               if (retval != -1) {
01249                      RETURN_TRUE;
01250               }
01251        }
01252        
01253        RETURN_FALSE;
01254 }
01255 /* }}} */
01256 
01257 /* {{{ proto bool xmlwriter_start_cdata(resource xmlwriter)
01258 Create start CDATA tag - returns FALSE on error */
01259 static PHP_FUNCTION(xmlwriter_start_cdata)
01260 {
01261        zval *pind;
01262        xmlwriter_object *intern;
01263        xmlTextWriterPtr ptr;
01264        int retval;
01265 #ifdef ZEND_ENGINE_2
01266        zval *this = getThis();
01267        
01268        if (this) {
01269               XMLWRITER_FROM_OBJECT(intern, this);
01270        } else
01271 #endif
01272        {
01273               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
01274                      return;
01275               }
01276               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01277        }
01278 
01279        ptr = intern->ptr;
01280 
01281        if (ptr) {
01282               retval = xmlTextWriterStartCDATA(ptr);
01283               if (retval != -1) {
01284                      RETURN_TRUE;
01285               }
01286        }
01287        
01288        RETURN_FALSE;
01289 }
01290 /* }}} */
01291 
01292 /* {{{ proto bool xmlwriter_end_cdata(resource xmlwriter)
01293 End current CDATA - returns FALSE on error */
01294 static PHP_FUNCTION(xmlwriter_end_cdata)
01295 {
01296        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndCDATA);
01297 }
01298 /* }}} */
01299 
01300 /* {{{ proto bool xmlwriter_write_cdata(resource xmlwriter, string content)
01301 Write full CDATA tag - returns FALSE on error */
01302 static PHP_FUNCTION(xmlwriter_write_cdata)
01303 {
01304        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteCDATA, NULL);
01305 }
01306 /* }}} */
01307 
01308 /* {{{ proto bool xmlwriter_write_raw(resource xmlwriter, string content)
01309 Write text - returns FALSE on error */
01310 static PHP_FUNCTION(xmlwriter_write_raw)
01311 {
01312        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteRaw, NULL);
01313 }
01314 /* }}} */
01315 
01316 /* {{{ proto bool xmlwriter_text(resource xmlwriter, string content)
01317 Write text - returns FALSE on error */
01318 static PHP_FUNCTION(xmlwriter_text)
01319 {
01320        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteString, NULL);
01321 }
01322 /* }}} */
01323 
01324 #if LIBXML_VERSION >= 20607
01325 /* {{{ proto bool xmlwriter_start_comment(resource xmlwriter)
01326 Create start comment - returns FALSE on error */
01327 static PHP_FUNCTION(xmlwriter_start_comment)
01328 {
01329        zval *pind;
01330        xmlwriter_object *intern;
01331        xmlTextWriterPtr ptr;
01332        int retval;
01333 #ifdef ZEND_ENGINE_2
01334        zval *this = getThis();
01335        
01336        if (this) {
01337               XMLWRITER_FROM_OBJECT(intern, this);
01338        } else
01339 #endif
01340        {
01341               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
01342                      return;
01343               }
01344               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01345        }
01346 
01347        ptr = intern->ptr;
01348 
01349        if (ptr) {
01350               retval = xmlTextWriterStartComment(ptr);
01351               if (retval != -1) {
01352                      RETURN_TRUE;
01353               }
01354        }
01355        
01356        RETURN_FALSE;
01357 }
01358 /* }}} */
01359 
01360 /* {{{ proto bool xmlwriter_end_comment(resource xmlwriter)
01361 Create end comment - returns FALSE on error */
01362 static PHP_FUNCTION(xmlwriter_end_comment)
01363 {
01364        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndComment);
01365 }
01366 /* }}} */
01367 #endif  /* LIBXML_VERSION >= 20607 */
01368 
01369 
01370 /* {{{ proto bool xmlwriter_write_comment(resource xmlwriter, string content)
01371 Write full comment tag - returns FALSE on error */
01372 static PHP_FUNCTION(xmlwriter_write_comment)
01373 {
01374        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteComment, NULL);
01375 }
01376 /* }}} */
01377 
01378 /* {{{ proto bool xmlwriter_start_document(resource xmlwriter, string version, string encoding, string standalone)
01379 Create document tag - returns FALSE on error */
01380 static PHP_FUNCTION(xmlwriter_start_document)
01381 {
01382        zval *pind;
01383        xmlwriter_object *intern;
01384        xmlTextWriterPtr ptr;
01385        char *version = NULL, *enc = NULL, *alone = NULL;
01386        int version_len, enc_len, alone_len, retval;
01387 
01388 #ifdef ZEND_ENGINE_2
01389        zval *this = getThis();
01390 
01391        if (this) {
01392               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!", &version, &version_len, &enc, &enc_len, &alone, &alone_len) == FAILURE) {
01393                      return;
01394               }
01395               XMLWRITER_FROM_OBJECT(intern, this);
01396        } else
01397 #endif
01398        {
01399               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!s!s!", &pind, &version, &version_len, &enc, &enc_len, &alone, &alone_len) == FAILURE) {
01400                      return;
01401               }
01402               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01403        }
01404 
01405        ptr = intern->ptr;
01406 
01407        if (ptr) {
01408               retval = xmlTextWriterStartDocument(ptr, version, enc, alone);
01409               if (retval != -1) {
01410                      RETURN_TRUE;
01411               }
01412        }
01413        
01414        RETURN_FALSE;
01415 }
01416 /* }}} */
01417 
01418 /* {{{ proto bool xmlwriter_end_document(resource xmlwriter)
01419 End current document - returns FALSE on error */
01420 static PHP_FUNCTION(xmlwriter_end_document)
01421 {
01422        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDocument);
01423 }
01424 /* }}} */
01425 
01426 /* {{{ proto bool xmlwriter_start_dtd(resource xmlwriter, string name, string pubid, string sysid)
01427 Create start DTD tag - returns FALSE on error */
01428 static PHP_FUNCTION(xmlwriter_start_dtd)
01429 {
01430        zval *pind;
01431        xmlwriter_object *intern;
01432        xmlTextWriterPtr ptr;
01433        char *name, *pubid = NULL, *sysid = NULL;
01434        int name_len, pubid_len, sysid_len, retval;
01435 
01436 #ifdef ZEND_ENGINE_2
01437        zval *this = getThis();
01438 
01439        if (this) {
01440               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!s!", &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len) == FAILURE) {
01441                      return;
01442               }
01443 
01444               XMLWRITER_FROM_OBJECT(intern, this);
01445        } else
01446 #endif
01447        {
01448               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!s!", &pind, &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len) == FAILURE) {
01449                      return;
01450               }
01451        
01452               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01453        }
01454        ptr = intern->ptr;
01455 
01456        if (ptr) {
01457               retval = xmlTextWriterStartDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid);
01458               if (retval != -1) {
01459                      RETURN_TRUE;
01460               }
01461        }
01462        
01463        RETURN_FALSE;
01464 }
01465 /* }}} */
01466 
01467 /* {{{ proto bool xmlwriter_end_dtd(resource xmlwriter)
01468 End current DTD - returns FALSE on error */
01469 static PHP_FUNCTION(xmlwriter_end_dtd)
01470 {
01471        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTD);
01472 }
01473 /* }}} */
01474 
01475 /* {{{ proto bool xmlwriter_write_dtd(resource xmlwriter, string name, string pubid, string sysid, string subset)
01476 Write full DTD tag - returns FALSE on error */
01477 static PHP_FUNCTION(xmlwriter_write_dtd)
01478 {
01479        zval *pind;
01480        xmlwriter_object *intern;
01481        xmlTextWriterPtr ptr;
01482        char *name, *pubid = NULL, *sysid = NULL, *subset = NULL;
01483        int name_len, pubid_len, sysid_len, subset_len, retval;
01484 
01485 #ifdef ZEND_ENGINE_2
01486        zval *this = getThis();
01487 
01488        if (this) {
01489               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) {
01490                      return;
01491               }
01492 
01493               XMLWRITER_FROM_OBJECT(intern, this);
01494        } else
01495 #endif
01496        {
01497               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) {
01498                      return;
01499               }
01500        
01501               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01502        }
01503 
01504        ptr = intern->ptr;
01505 
01506        if (ptr) {
01507               retval = xmlTextWriterWriteDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)subset);
01508               if (retval != -1) {
01509                      RETURN_TRUE;
01510               }
01511        }
01512        
01513        RETURN_FALSE;
01514 }
01515 /* }}} */
01516 
01517 /* {{{ proto bool xmlwriter_start_dtd_element(resource xmlwriter, string name)
01518 Create start DTD element - returns FALSE on error */
01519 static PHP_FUNCTION(xmlwriter_start_dtd_element)
01520 {
01521        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDElement, "Invalid Element Name");
01522 }
01523 /* }}} */
01524 
01525 /* {{{ proto bool xmlwriter_end_dtd_element(resource xmlwriter)
01526 End current DTD element - returns FALSE on error */
01527 static PHP_FUNCTION(xmlwriter_end_dtd_element)
01528 {
01529        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDElement);
01530 }
01531 /* }}} */
01532 
01533 /* {{{ proto bool xmlwriter_write_dtd_element(resource xmlwriter, string name, string content)
01534 Write full DTD element tag - returns FALSE on error */
01535 static PHP_FUNCTION(xmlwriter_write_dtd_element)
01536 {
01537        zval *pind;
01538        xmlwriter_object *intern;
01539        xmlTextWriterPtr ptr;
01540        char *name, *content;
01541        int name_len, content_len, retval;
01542 
01543 #ifdef ZEND_ENGINE_2
01544        zval *this = getThis();
01545 
01546        if (this) {
01547               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) {
01548                      return;
01549               }
01550               XMLWRITER_FROM_OBJECT(intern, this);
01551        } else
01552 #endif
01553        {
01554               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, 
01555                      &name, &name_len, &content, &content_len) == FAILURE) {
01556                      return;
01557               }
01558               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01559        }
01560 
01561        XMLW_NAME_CHK("Invalid Element Name");
01562 
01563        ptr = intern->ptr;
01564 
01565        if (ptr) {
01566               retval = xmlTextWriterWriteDTDElement(ptr, (xmlChar *)name, (xmlChar *)content);
01567               if (retval != -1) {
01568                      RETURN_TRUE;
01569               }
01570        }
01571        
01572        RETURN_FALSE;
01573 }
01574 /* }}} */
01575 
01576 #if LIBXML_VERSION > 20608
01577 /* {{{ proto bool xmlwriter_start_dtd_attlist(resource xmlwriter, string name)
01578 Create start DTD AttList - returns FALSE on error */
01579 static PHP_FUNCTION(xmlwriter_start_dtd_attlist)
01580 {
01581        php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartDTDAttlist, "Invalid Element Name");
01582 }
01583 /* }}} */
01584 
01585 /* {{{ proto bool xmlwriter_end_dtd_attlist(resource xmlwriter)
01586 End current DTD AttList - returns FALSE on error */
01587 static PHP_FUNCTION(xmlwriter_end_dtd_attlist)
01588 {
01589        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDAttlist);
01590 }
01591 /* }}} */
01592 
01593 /* {{{ proto bool xmlwriter_write_dtd_attlist(resource xmlwriter, string name, string content)
01594 Write full DTD AttList tag - returns FALSE on error */
01595 static PHP_FUNCTION(xmlwriter_write_dtd_attlist)
01596 {
01597        zval *pind;
01598        xmlwriter_object *intern;
01599        xmlTextWriterPtr ptr;
01600        char *name, *content;
01601        int name_len, content_len, retval;
01602 
01603        
01604 #ifdef ZEND_ENGINE_2
01605        zval *this = getThis();
01606 
01607        if (this) {
01608               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
01609                      &name, &name_len, &content, &content_len) == FAILURE) {
01610                      return;
01611               }
01612               XMLWRITER_FROM_OBJECT(intern, this);
01613        } else
01614 #endif
01615        {
01616               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, 
01617                      &name, &name_len, &content, &content_len) == FAILURE) {
01618                      return;
01619               }
01620               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01621        }
01622 
01623        XMLW_NAME_CHK("Invalid Element Name");
01624 
01625        ptr = intern->ptr;
01626 
01627        if (ptr) {
01628               retval = xmlTextWriterWriteDTDAttlist(ptr, (xmlChar *)name, (xmlChar *)content);
01629               if (retval != -1) {
01630                      RETURN_TRUE;
01631               }
01632        }
01633        
01634        RETURN_FALSE;
01635 }
01636 /* }}} */
01637 
01638 /* {{{ proto bool xmlwriter_start_dtd_entity(resource xmlwriter, string name, bool isparam)
01639 Create start DTD Entity - returns FALSE on error */
01640 static PHP_FUNCTION(xmlwriter_start_dtd_entity)
01641 {
01642        zval *pind;
01643        xmlwriter_object *intern;
01644        xmlTextWriterPtr ptr;
01645        char *name;
01646        int name_len, retval;
01647        zend_bool isparm;
01648 
01649        
01650 #ifdef ZEND_ENGINE_2
01651        zval *this = getThis();
01652 
01653        if (this) {
01654               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sb", &name, &name_len, &isparm) == FAILURE) {
01655                      return;
01656               }
01657               XMLWRITER_FROM_OBJECT(intern, this);
01658        } else
01659 #endif
01660        {
01661               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsb", &pind, &name, &name_len, &isparm) == FAILURE) {
01662                      return;
01663               }
01664               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01665        }
01666 
01667        XMLW_NAME_CHK("Invalid Attribute Name");
01668 
01669        ptr = intern->ptr;
01670 
01671        if (ptr) {
01672               retval = xmlTextWriterStartDTDEntity(ptr, isparm, (xmlChar *)name);
01673               if (retval != -1) {
01674                      RETURN_TRUE;
01675               }
01676        }
01677        
01678        RETURN_FALSE;
01679 }
01680 /* }}} */
01681 
01682 /* {{{ proto bool xmlwriter_end_dtd_entity(resource xmlwriter)
01683 End current DTD Entity - returns FALSE on error */
01684 static PHP_FUNCTION(xmlwriter_end_dtd_entity)
01685 {
01686        php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTDEntity);
01687 }
01688 /* }}} */
01689 
01690 /* {{{ proto bool xmlwriter_write_dtd_entity(resource xmlwriter, string name, string content [, int pe [, string pubid [, string sysid [, string ndataid]]]])
01691 Write full DTD Entity tag - returns FALSE on error */
01692 static PHP_FUNCTION(xmlwriter_write_dtd_entity)
01693 {
01694        zval *pind;
01695        xmlwriter_object *intern;
01696        xmlTextWriterPtr ptr;
01697        char *name, *content;
01698        int name_len, content_len, retval;
01699        /* Optional parameters */
01700        char *pubid = NULL, *sysid = NULL, *ndataid = NULL;
01701        zend_bool pe = 0;
01702        int pubid_len, sysid_len, ndataid_len;
01703 
01704 #ifdef ZEND_ENGINE_2
01705        zval *this = getThis();
01706 
01707        if (this) {
01708               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bsss",
01709                      &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len,
01710                      &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) {
01711                      return;
01712               }
01713               XMLWRITER_FROM_OBJECT(intern, this);
01714        } else
01715 #endif
01716        {
01717               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|bsss", &pind, 
01718                      &name, &name_len, &content, &content_len, &pe, &pubid, &pubid_len,
01719                      &sysid, &sysid_len, &ndataid, &ndataid_len) == FAILURE) {
01720                      return;
01721               }
01722               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01723        }
01724 
01725        XMLW_NAME_CHK("Invalid Element Name");
01726 
01727        ptr = intern->ptr;
01728 
01729        if (ptr) {
01730               retval = xmlTextWriterWriteDTDEntity(ptr, pe, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)ndataid, (xmlChar *)content);
01731               if (retval != -1) {
01732                      RETURN_TRUE;
01733               }
01734        }
01735        
01736        RETURN_FALSE;
01737 }
01738 /* }}} */
01739 #endif
01740 
01741 /* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
01742 Create new xmlwriter using source uri for output */
01743 static PHP_FUNCTION(xmlwriter_open_uri)
01744 {
01745        char *valid_file = NULL;
01746        xmlwriter_object *intern;
01747        xmlTextWriterPtr ptr;
01748        char *source;
01749        char resolved_path[MAXPATHLEN + 1];
01750        int source_len;
01751 
01752 #ifdef ZEND_ENGINE_2
01753        zval *this = getThis();
01754        ze_xmlwriter_object *ze_obj = NULL;
01755 #endif
01756 
01757 #ifndef ZEND_ENGINE_2
01758        xmlOutputBufferPtr out_buffer;
01759        void *ioctx;
01760 #endif
01761 
01762        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
01763               return;
01764        }
01765        
01766 #ifdef ZEND_ENGINE_2
01767        if (this) {
01768               /* We do not use XMLWRITER_FROM_OBJECT, xmlwriter init function here */
01769               ze_obj = (ze_xmlwriter_object*) zend_object_store_get_object(this TSRMLS_CC); 
01770        }
01771 #endif
01772 
01773        if (source_len == 0) {
01774               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string as source");
01775               RETURN_FALSE;
01776        }
01777 
01778        valid_file = _xmlwriter_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
01779        if (!valid_file) {
01780               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to resolve file path");
01781               RETURN_FALSE;
01782        }
01783 
01784        /* TODO: Fix either the PHP stream or libxml APIs: it can then detect when a given 
01785                path is valid and not report out of memory error. Once it is done, remove the
01786                directory check in _xmlwriter_get_valid_file_path */
01787 #ifndef ZEND_ENGINE_2
01788        ioctx = php_xmlwriter_streams_IO_open_write_wrapper(valid_file TSRMLS_CC);
01789        if (ioctx == NULL) {
01790               RETURN_FALSE;
01791        }
01792 
01793        out_buffer = xmlOutputBufferCreateIO(php_xmlwriter_streams_IO_write, 
01794               php_xmlwriter_streams_IO_close, ioctx, NULL);
01795 
01796        if (out_buffer == NULL) {
01797               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create output buffer");
01798               RETURN_FALSE;
01799        }
01800        ptr = xmlNewTextWriter(out_buffer);
01801 #else
01802        ptr = xmlNewTextWriterFilename(valid_file, 0);
01803 #endif
01804 
01805        if (!ptr) {
01806               RETURN_FALSE;
01807        }
01808 
01809        intern = emalloc(sizeof(xmlwriter_object));
01810        intern->ptr = ptr;
01811        intern->output = NULL;
01812 #ifndef ZEND_ENGINE_2
01813        intern->uri_output = out_buffer;
01814 #else
01815        if (this) {
01816               if (ze_obj->xmlwriter_ptr) {
01817                      xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr TSRMLS_CC);
01818               }
01819               ze_obj->xmlwriter_ptr = intern;
01820               RETURN_TRUE;
01821        } else
01822 #endif
01823        {
01824               ZEND_REGISTER_RESOURCE(return_value,intern,le_xmlwriter);
01825        }
01826 }
01827 /* }}} */
01828 
01829 /* {{{ proto resource xmlwriter_open_memory()
01830 Create new xmlwriter using memory for string output */
01831 static PHP_FUNCTION(xmlwriter_open_memory)
01832 {
01833        xmlwriter_object *intern;
01834        xmlTextWriterPtr ptr;
01835        xmlBufferPtr buffer;
01836 
01837 #ifdef ZEND_ENGINE_2
01838        zval *this = getThis();
01839        ze_xmlwriter_object *ze_obj = NULL;
01840 #endif
01841 
01842 #ifdef ZEND_ENGINE_2
01843        if (this) {
01844               /* We do not use XMLWRITER_FROM_OBJECT, xmlwriter init function here */
01845               ze_obj = (ze_xmlwriter_object*) zend_object_store_get_object(this TSRMLS_CC); 
01846        }
01847 #endif
01848 
01849        buffer = xmlBufferCreate();
01850 
01851        if (buffer == NULL) {
01852               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create output buffer");
01853               RETURN_FALSE;
01854        }
01855 
01856        ptr = xmlNewTextWriterMemory(buffer, 0);
01857        if (! ptr) {
01858               xmlBufferFree(buffer);
01859               RETURN_FALSE;
01860        }
01861 
01862        intern = emalloc(sizeof(xmlwriter_object));
01863        intern->ptr = ptr;
01864        intern->output = buffer;
01865 #ifndef ZEND_ENGINE_2
01866        intern->uri_output = NULL;
01867 #else
01868        if (this) {
01869               if (ze_obj->xmlwriter_ptr) {
01870                      xmlwriter_free_resource_ptr(ze_obj->xmlwriter_ptr TSRMLS_CC);
01871               }
01872               ze_obj->xmlwriter_ptr = intern;
01873               RETURN_TRUE;
01874        } else
01875 #endif
01876        {
01877               ZEND_REGISTER_RESOURCE(return_value,intern,le_xmlwriter);
01878        }
01879 
01880 }
01881 /* }}} */
01882 
01883 /* {{{ php_xmlwriter_flush */
01884 static void php_xmlwriter_flush(INTERNAL_FUNCTION_PARAMETERS, int force_string) {
01885        zval *pind;
01886        xmlwriter_object *intern;
01887        xmlTextWriterPtr ptr;
01888        xmlBufferPtr buffer;
01889        zend_bool empty = 1;
01890        int output_bytes;
01891 
01892 
01893 #ifdef ZEND_ENGINE_2
01894        zval *this = getThis();
01895 
01896        if (this) {
01897               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &empty) == FAILURE) {
01898                      return;
01899               }
01900               XMLWRITER_FROM_OBJECT(intern, this);
01901        } else
01902 #endif
01903        {
01904               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &pind, &empty) == FAILURE) {
01905                      return;
01906               }
01907 
01908               ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
01909        }
01910        ptr = intern->ptr;
01911 
01912        if (ptr) {
01913               buffer = intern->output;
01914               if (force_string == 1 && buffer == NULL) {
01915                      RETURN_EMPTY_STRING();
01916               }
01917               output_bytes = xmlTextWriterFlush(ptr);
01918               if (buffer) {
01919                      RETVAL_STRING((char *) buffer->content, 1);
01920                      if (empty) {
01921                             xmlBufferEmpty(buffer);
01922                      }
01923               } else {
01924                      RETVAL_LONG(output_bytes);
01925               }
01926               return;
01927        }
01928        
01929        RETURN_EMPTY_STRING();
01930 }
01931 /* }}} */
01932 
01933 /* {{{ proto string xmlwriter_output_memory(resource xmlwriter [,bool flush])
01934 Output current buffer as string */
01935 static PHP_FUNCTION(xmlwriter_output_memory)
01936 {
01937        php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
01938 }
01939 /* }}} */
01940 
01941 /* {{{ proto mixed xmlwriter_flush(resource xmlwriter [,bool empty])
01942 Output current buffer */
01943 static PHP_FUNCTION(xmlwriter_flush)
01944 {
01945        php_xmlwriter_flush(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
01946 }
01947 /* }}} */
01948 
01949 /* {{{ PHP_MINIT_FUNCTION
01950  */
01951 static PHP_MINIT_FUNCTION(xmlwriter)
01952 {
01953 #ifdef ZEND_ENGINE_2
01954        zend_class_entry ce;
01955 #endif
01956 
01957        le_xmlwriter = zend_register_list_destructors_ex(xmlwriter_dtor, NULL, "xmlwriter", module_number);
01958 
01959 #ifdef ZEND_ENGINE_2
01960        memcpy(&xmlwriter_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
01961        xmlwriter_object_handlers.clone_obj      = NULL;
01962        INIT_CLASS_ENTRY(ce, "XMLWriter", xmlwriter_class_functions);
01963        ce.create_object = xmlwriter_object_new;
01964        xmlwriter_class_entry_ce = zend_register_internal_class(&ce TSRMLS_CC);
01965 #endif
01966        return SUCCESS;
01967 }
01968 /* }}} */
01969 
01970 /* {{{ PHP_MSHUTDOWN_FUNCTION
01971  */
01972 static PHP_MSHUTDOWN_FUNCTION(xmlwriter)
01973 {
01974        return SUCCESS;
01975 }
01976 /* }}} */
01977 
01978 /* {{{ PHP_MINFO_FUNCTION
01979  */
01980 static PHP_MINFO_FUNCTION(xmlwriter)
01981 {
01982        php_info_print_table_start();
01983        {
01984               php_info_print_table_row(2, "XMLWriter", "enabled");
01985        }
01986        php_info_print_table_end();
01987 }
01988 /* }}} */
01989 
01990 /*
01991  * Local variables:
01992  * tab-width: 4
01993  * c-basic-offset: 4
01994  * End:
01995  * vim600: noet sw=4 ts=4 fdm=marker
01996  * vim<600: noet sw=4 ts=4
01997  */