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