You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1997 lines
56 KiB

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