php_xmlwriter.c 53 KB

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