php_xmlwriter.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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 uninitialized 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. zend_object_value retval;
  132. intern = emalloc(sizeof(ze_xmlwriter_object));
  133. memset(&intern->zo, 0, sizeof(zend_object));
  134. intern->xmlwriter_ptr = NULL;
  135. zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
  136. object_properties_init(&intern->zo, class_type);
  137. retval.handle = zend_objects_store_put(intern,
  138. NULL,
  139. (zend_objects_free_object_storage_t) xmlwriter_object_free_storage,
  140. NULL TSRMLS_CC);
  141. retval.handlers = (zend_object_handlers *) & xmlwriter_object_handlers;
  142. return retval;
  143. }
  144. /* }}} */
  145. #endif
  146. #define XMLW_NAME_CHK(__err) \
  147. if (xmlValidateName((xmlChar *) name, 0) != 0) { \
  148. php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", __err); \
  149. RETURN_FALSE; \
  150. } \
  151. /* {{{ arginfo */
  152. ZEND_BEGIN_ARG_INFO(arginfo_xmlwriter_void, 0)
  153. ZEND_END_ARG_INFO()
  154. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_resource, 0, 0, 1)
  155. ZEND_ARG_INFO(0, xmlwriter)
  156. ZEND_END_ARG_INFO()
  157. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_open_uri, 0, 0, 1)
  158. ZEND_ARG_INFO(0, uri)
  159. ZEND_END_ARG_INFO()
  160. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_set_indent, 0, 0, 2)
  161. ZEND_ARG_INFO(0, xmlwriter)
  162. ZEND_ARG_INFO(0, indent)
  163. ZEND_END_ARG_INFO()
  164. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_set_indent, 0, 0, 1)
  165. ZEND_ARG_INFO(0, indent)
  166. ZEND_END_ARG_INFO()
  167. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_set_indent_string, 0, 0, 2)
  168. ZEND_ARG_INFO(0, xmlwriter)
  169. ZEND_ARG_INFO(0, indentString)
  170. ZEND_END_ARG_INFO()
  171. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_set_indent_string, 0, 0, 1)
  172. ZEND_ARG_INFO(0, indentString)
  173. ZEND_END_ARG_INFO()
  174. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_attribute, 0, 0, 2)
  175. ZEND_ARG_INFO(0, xmlwriter)
  176. ZEND_ARG_INFO(0, name)
  177. ZEND_END_ARG_INFO()
  178. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_attribute, 0, 0, 1)
  179. ZEND_ARG_INFO(0, name)
  180. ZEND_END_ARG_INFO()
  181. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_attribute_ns, 0, 0, 4)
  182. ZEND_ARG_INFO(0, xmlwriter)
  183. ZEND_ARG_INFO(0, prefix)
  184. ZEND_ARG_INFO(0, name)
  185. ZEND_ARG_INFO(0, uri)
  186. ZEND_END_ARG_INFO()
  187. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_attribute_ns, 0, 0, 3)
  188. ZEND_ARG_INFO(0, prefix)
  189. ZEND_ARG_INFO(0, name)
  190. ZEND_ARG_INFO(0, uri)
  191. ZEND_END_ARG_INFO()
  192. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_attribute_ns, 0, 0, 5)
  193. ZEND_ARG_INFO(0, xmlwriter)
  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_method_write_attribute_ns, 0, 0, 4)
  200. ZEND_ARG_INFO(0, prefix)
  201. ZEND_ARG_INFO(0, name)
  202. ZEND_ARG_INFO(0, uri)
  203. ZEND_ARG_INFO(0, content)
  204. ZEND_END_ARG_INFO()
  205. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_attribute, 0, 0, 3)
  206. ZEND_ARG_INFO(0, xmlwriter)
  207. ZEND_ARG_INFO(0, name)
  208. ZEND_ARG_INFO(0, value)
  209. ZEND_END_ARG_INFO()
  210. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_attribute, 0, 0, 2)
  211. ZEND_ARG_INFO(0, name)
  212. ZEND_ARG_INFO(0, value)
  213. ZEND_END_ARG_INFO()
  214. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_element, 0, 0, 2)
  215. ZEND_ARG_INFO(0, xmlwriter)
  216. ZEND_ARG_INFO(0, name)
  217. ZEND_END_ARG_INFO()
  218. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_element, 0, 0, 1)
  219. ZEND_ARG_INFO(0, name)
  220. ZEND_END_ARG_INFO()
  221. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_element_ns, 0, 0, 4)
  222. ZEND_ARG_INFO(0, xmlwriter)
  223. ZEND_ARG_INFO(0, prefix)
  224. ZEND_ARG_INFO(0, name)
  225. ZEND_ARG_INFO(0, uri)
  226. ZEND_END_ARG_INFO()
  227. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_element_ns, 0, 0, 3)
  228. ZEND_ARG_INFO(0, prefix)
  229. ZEND_ARG_INFO(0, name)
  230. ZEND_ARG_INFO(0, uri)
  231. ZEND_END_ARG_INFO()
  232. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_element, 0, 0, 2)
  233. ZEND_ARG_INFO(0, xmlwriter)
  234. ZEND_ARG_INFO(0, name)
  235. ZEND_ARG_INFO(0, content)
  236. ZEND_END_ARG_INFO()
  237. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_element, 0, 0, 1)
  238. ZEND_ARG_INFO(0, name)
  239. ZEND_ARG_INFO(0, content)
  240. ZEND_END_ARG_INFO()
  241. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_element_ns, 0, 0, 4)
  242. ZEND_ARG_INFO(0, xmlwriter)
  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_method_write_element_ns, 0, 0, 3)
  249. ZEND_ARG_INFO(0, prefix)
  250. ZEND_ARG_INFO(0, name)
  251. ZEND_ARG_INFO(0, uri)
  252. ZEND_ARG_INFO(0, content)
  253. ZEND_END_ARG_INFO()
  254. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_pi, 0, 0, 2)
  255. ZEND_ARG_INFO(0, xmlwriter)
  256. ZEND_ARG_INFO(0, target)
  257. ZEND_END_ARG_INFO()
  258. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_pi, 0, 0, 1)
  259. ZEND_ARG_INFO(0, target)
  260. ZEND_END_ARG_INFO()
  261. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_pi, 0, 0, 3)
  262. ZEND_ARG_INFO(0, xmlwriter)
  263. ZEND_ARG_INFO(0, target)
  264. ZEND_ARG_INFO(0, content)
  265. ZEND_END_ARG_INFO()
  266. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_pi, 0, 0, 2)
  267. ZEND_ARG_INFO(0, target)
  268. ZEND_ARG_INFO(0, content)
  269. ZEND_END_ARG_INFO()
  270. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_cdata, 0, 0, 2)
  271. ZEND_ARG_INFO(0, xmlwriter)
  272. ZEND_ARG_INFO(0, content)
  273. ZEND_END_ARG_INFO()
  274. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_cdata, 0, 0, 1)
  275. ZEND_ARG_INFO(0, content)
  276. ZEND_END_ARG_INFO()
  277. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_text, 0, 0, 2)
  278. ZEND_ARG_INFO(0, xmlwriter)
  279. ZEND_ARG_INFO(0, content)
  280. ZEND_END_ARG_INFO()
  281. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_text, 0, 0, 1)
  282. ZEND_ARG_INFO(0, content)
  283. ZEND_END_ARG_INFO()
  284. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_raw, 0, 0, 2)
  285. ZEND_ARG_INFO(0, xmlwriter)
  286. ZEND_ARG_INFO(0, content)
  287. ZEND_END_ARG_INFO()
  288. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_raw, 0, 0, 1)
  289. ZEND_ARG_INFO(0, content)
  290. ZEND_END_ARG_INFO()
  291. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_document, 0, 0, 1)
  292. ZEND_ARG_INFO(0, xmlwriter)
  293. ZEND_ARG_INFO(0, version)
  294. ZEND_ARG_INFO(0, encoding)
  295. ZEND_ARG_INFO(0, standalone)
  296. ZEND_END_ARG_INFO()
  297. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_document, 0, 0, 0)
  298. ZEND_ARG_INFO(0, version)
  299. ZEND_ARG_INFO(0, encoding)
  300. ZEND_ARG_INFO(0, standalone)
  301. ZEND_END_ARG_INFO()
  302. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_comment, 0, 0, 2)
  303. ZEND_ARG_INFO(0, xmlwriter)
  304. ZEND_ARG_INFO(0, content)
  305. ZEND_END_ARG_INFO()
  306. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_comment, 0, 0, 1)
  307. ZEND_ARG_INFO(0, content)
  308. ZEND_END_ARG_INFO()
  309. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd, 0, 0, 2)
  310. ZEND_ARG_INFO(0, xmlwriter)
  311. ZEND_ARG_INFO(0, qualifiedName)
  312. ZEND_ARG_INFO(0, publicId)
  313. ZEND_ARG_INFO(0, systemId)
  314. ZEND_END_ARG_INFO()
  315. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd, 0, 0, 1)
  316. ZEND_ARG_INFO(0, qualifiedName)
  317. ZEND_ARG_INFO(0, publicId)
  318. ZEND_ARG_INFO(0, systemId)
  319. ZEND_END_ARG_INFO()
  320. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd, 0, 0, 2)
  321. ZEND_ARG_INFO(0, xmlwriter)
  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_method_write_dtd, 0, 0, 1)
  328. ZEND_ARG_INFO(0, name)
  329. ZEND_ARG_INFO(0, publicId)
  330. ZEND_ARG_INFO(0, systemId)
  331. ZEND_ARG_INFO(0, subset)
  332. ZEND_END_ARG_INFO()
  333. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_element, 0, 0, 2)
  334. ZEND_ARG_INFO(0, xmlwriter)
  335. ZEND_ARG_INFO(0, qualifiedName)
  336. ZEND_END_ARG_INFO()
  337. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_element, 0, 0, 1)
  338. ZEND_ARG_INFO(0, qualifiedName)
  339. ZEND_END_ARG_INFO()
  340. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_element, 0, 0, 3)
  341. ZEND_ARG_INFO(0, xmlwriter)
  342. ZEND_ARG_INFO(0, name)
  343. ZEND_ARG_INFO(0, content)
  344. ZEND_END_ARG_INFO()
  345. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_element, 0, 0, 2)
  346. ZEND_ARG_INFO(0, name)
  347. ZEND_ARG_INFO(0, content)
  348. ZEND_END_ARG_INFO()
  349. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_attlist, 0, 0, 2)
  350. ZEND_ARG_INFO(0, xmlwriter)
  351. ZEND_ARG_INFO(0, name)
  352. ZEND_END_ARG_INFO()
  353. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_attlist, 0, 0, 1)
  354. ZEND_ARG_INFO(0, name)
  355. ZEND_END_ARG_INFO()
  356. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_attlist, 0, 0, 3)
  357. ZEND_ARG_INFO(0, xmlwriter)
  358. ZEND_ARG_INFO(0, name)
  359. ZEND_ARG_INFO(0, content)
  360. ZEND_END_ARG_INFO()
  361. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_attlist, 0, 0, 2)
  362. ZEND_ARG_INFO(0, name)
  363. ZEND_ARG_INFO(0, content)
  364. ZEND_END_ARG_INFO()
  365. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_start_dtd_entity, 0, 0, 3)
  366. ZEND_ARG_INFO(0, xmlwriter)
  367. ZEND_ARG_INFO(0, name)
  368. ZEND_ARG_INFO(0, isparam)
  369. ZEND_END_ARG_INFO()
  370. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_start_dtd_entity, 0, 0, 2)
  371. ZEND_ARG_INFO(0, name)
  372. ZEND_ARG_INFO(0, isparam)
  373. ZEND_END_ARG_INFO()
  374. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_write_dtd_entity, 0, 0, 3)
  375. ZEND_ARG_INFO(0, xmlwriter)
  376. ZEND_ARG_INFO(0, name)
  377. ZEND_ARG_INFO(0, content)
  378. ZEND_END_ARG_INFO()
  379. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_write_dtd_entity, 0, 0, 2)
  380. ZEND_ARG_INFO(0, name)
  381. ZEND_ARG_INFO(0, content)
  382. ZEND_END_ARG_INFO()
  383. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_output_memory, 0, 0, 1)
  384. ZEND_ARG_INFO(0, xmlwriter)
  385. ZEND_ARG_INFO(0, flush)
  386. ZEND_END_ARG_INFO()
  387. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_output_memory, 0, 0, 0)
  388. ZEND_ARG_INFO(0, flush)
  389. ZEND_END_ARG_INFO()
  390. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_flush, 0, 0, 1)
  391. ZEND_ARG_INFO(0, xmlwriter)
  392. ZEND_ARG_INFO(0, empty)
  393. ZEND_END_ARG_INFO()
  394. ZEND_BEGIN_ARG_INFO_EX(arginfo_xmlwriter_method_flush, 0, 0, 0)
  395. ZEND_ARG_INFO(0, empty)
  396. ZEND_END_ARG_INFO()
  397. /* }}} */
  398. /* {{{ xmlwriter_functions */
  399. static const zend_function_entry xmlwriter_functions[] = {
  400. PHP_FE(xmlwriter_open_uri, arginfo_xmlwriter_open_uri)
  401. PHP_FE(xmlwriter_open_memory, arginfo_xmlwriter_void)
  402. #if LIBXML_VERSION >= 20605
  403. PHP_FE(xmlwriter_set_indent, arginfo_xmlwriter_set_indent)
  404. PHP_FE(xmlwriter_set_indent_string, arginfo_xmlwriter_set_indent_string)
  405. #endif
  406. #if LIBXML_VERSION >= 20607
  407. PHP_FE(xmlwriter_start_comment, arginfo_xmlwriter_resource)
  408. PHP_FE(xmlwriter_end_comment, arginfo_xmlwriter_resource)
  409. #endif
  410. PHP_FE(xmlwriter_start_attribute, arginfo_xmlwriter_start_attribute)
  411. PHP_FE(xmlwriter_end_attribute, arginfo_xmlwriter_resource)
  412. PHP_FE(xmlwriter_write_attribute, arginfo_xmlwriter_write_attribute)
  413. #if LIBXML_VERSION > 20617
  414. PHP_FE(xmlwriter_start_attribute_ns,arginfo_xmlwriter_start_attribute_ns)
  415. PHP_FE(xmlwriter_write_attribute_ns,arginfo_xmlwriter_write_attribute_ns)
  416. #endif
  417. PHP_FE(xmlwriter_start_element, arginfo_xmlwriter_start_element)
  418. PHP_FE(xmlwriter_end_element, arginfo_xmlwriter_resource)
  419. PHP_FE(xmlwriter_full_end_element, arginfo_xmlwriter_resource)
  420. PHP_FE(xmlwriter_start_element_ns, arginfo_xmlwriter_start_element_ns)
  421. PHP_FE(xmlwriter_write_element, arginfo_xmlwriter_write_element)
  422. PHP_FE(xmlwriter_write_element_ns, arginfo_xmlwriter_write_element_ns)
  423. PHP_FE(xmlwriter_start_pi, arginfo_xmlwriter_start_pi)
  424. PHP_FE(xmlwriter_end_pi, arginfo_xmlwriter_resource)
  425. PHP_FE(xmlwriter_write_pi, arginfo_xmlwriter_write_pi)
  426. PHP_FE(xmlwriter_start_cdata, arginfo_xmlwriter_resource)
  427. PHP_FE(xmlwriter_end_cdata, arginfo_xmlwriter_resource)
  428. PHP_FE(xmlwriter_write_cdata, arginfo_xmlwriter_write_cdata)
  429. PHP_FE(xmlwriter_text, arginfo_xmlwriter_text)
  430. PHP_FE(xmlwriter_write_raw, arginfo_xmlwriter_write_raw)
  431. PHP_FE(xmlwriter_start_document, arginfo_xmlwriter_start_document)
  432. PHP_FE(xmlwriter_end_document, arginfo_xmlwriter_resource)
  433. PHP_FE(xmlwriter_write_comment, arginfo_xmlwriter_write_comment)
  434. PHP_FE(xmlwriter_start_dtd, arginfo_xmlwriter_start_dtd)
  435. PHP_FE(xmlwriter_end_dtd, arginfo_xmlwriter_resource)
  436. PHP_FE(xmlwriter_write_dtd, arginfo_xmlwriter_write_dtd)
  437. PHP_FE(xmlwriter_start_dtd_element, arginfo_xmlwriter_start_dtd_element)
  438. PHP_FE(xmlwriter_end_dtd_element, arginfo_xmlwriter_resource)
  439. PHP_FE(xmlwriter_write_dtd_element, arginfo_xmlwriter_write_dtd_element)
  440. #if LIBXML_VERSION > 20608
  441. PHP_FE(xmlwriter_start_dtd_attlist, arginfo_xmlwriter_start_dtd_attlist)
  442. PHP_FE(xmlwriter_end_dtd_attlist, arginfo_xmlwriter_resource)
  443. PHP_FE(xmlwriter_write_dtd_attlist, arginfo_xmlwriter_write_dtd_attlist)
  444. PHP_FE(xmlwriter_start_dtd_entity, arginfo_xmlwriter_start_dtd_entity)
  445. PHP_FE(xmlwriter_end_dtd_entity, arginfo_xmlwriter_resource)
  446. PHP_FE(xmlwriter_write_dtd_entity, arginfo_xmlwriter_write_dtd_entity)
  447. #endif
  448. PHP_FE(xmlwriter_output_memory, arginfo_xmlwriter_output_memory)
  449. PHP_FE(xmlwriter_flush, arginfo_xmlwriter_flush)
  450. PHP_FE_END
  451. };
  452. /* }}} */
  453. #ifdef ZEND_ENGINE_2
  454. /* {{{ xmlwriter_class_functions */
  455. static const zend_function_entry xmlwriter_class_functions[] = {
  456. PHP_ME_MAPPING(openUri, xmlwriter_open_uri, arginfo_xmlwriter_open_uri, 0)
  457. PHP_ME_MAPPING(openMemory, xmlwriter_open_memory, arginfo_xmlwriter_void, 0)
  458. #if LIBXML_VERSION >= 20605
  459. PHP_ME_MAPPING(setIndent, xmlwriter_set_indent, arginfo_xmlwriter_method_set_indent, 0)
  460. PHP_ME_MAPPING(setIndentString, xmlwriter_set_indent_string, arginfo_xmlwriter_method_set_indent_string, 0)
  461. #endif
  462. #if LIBXML_VERSION >= 20607
  463. PHP_ME_MAPPING(startComment, xmlwriter_start_comment, arginfo_xmlwriter_void, 0)
  464. PHP_ME_MAPPING(endComment, xmlwriter_end_comment, arginfo_xmlwriter_void, 0)
  465. #endif
  466. PHP_ME_MAPPING(startAttribute, xmlwriter_start_attribute, arginfo_xmlwriter_method_start_attribute, 0)
  467. PHP_ME_MAPPING(endAttribute, xmlwriter_end_attribute, arginfo_xmlwriter_void, 0)
  468. PHP_ME_MAPPING(writeAttribute, xmlwriter_write_attribute, arginfo_xmlwriter_method_write_attribute, 0)
  469. #if LIBXML_VERSION > 20617
  470. PHP_ME_MAPPING(startAttributeNs, xmlwriter_start_attribute_ns,arginfo_xmlwriter_method_start_attribute_ns, 0)
  471. PHP_ME_MAPPING(writeAttributeNs, xmlwriter_write_attribute_ns,arginfo_xmlwriter_method_write_attribute_ns, 0)
  472. #endif
  473. PHP_ME_MAPPING(startElement, xmlwriter_start_element, arginfo_xmlwriter_method_start_element, 0)
  474. PHP_ME_MAPPING(endElement, xmlwriter_end_element, arginfo_xmlwriter_void, 0)
  475. PHP_ME_MAPPING(fullEndElement, xmlwriter_full_end_element, arginfo_xmlwriter_void, 0)
  476. PHP_ME_MAPPING(startElementNs, xmlwriter_start_element_ns, arginfo_xmlwriter_method_start_element_ns, 0)
  477. PHP_ME_MAPPING(writeElement, xmlwriter_write_element, arginfo_xmlwriter_method_write_element, 0)
  478. PHP_ME_MAPPING(writeElementNs, xmlwriter_write_element_ns, arginfo_xmlwriter_method_write_element_ns, 0)
  479. PHP_ME_MAPPING(startPi, xmlwriter_start_pi, arginfo_xmlwriter_method_start_pi, 0)
  480. PHP_ME_MAPPING(endPi, xmlwriter_end_pi, arginfo_xmlwriter_void, 0)
  481. PHP_ME_MAPPING(writePi, xmlwriter_write_pi, arginfo_xmlwriter_method_write_pi, 0)
  482. PHP_ME_MAPPING(startCdata, xmlwriter_start_cdata, arginfo_xmlwriter_void, 0)
  483. PHP_ME_MAPPING(endCdata, xmlwriter_end_cdata, arginfo_xmlwriter_void, 0)
  484. PHP_ME_MAPPING(writeCdata, xmlwriter_write_cdata, arginfo_xmlwriter_method_write_cdata, 0)
  485. PHP_ME_MAPPING(text, xmlwriter_text, arginfo_xmlwriter_method_text, 0)
  486. PHP_ME_MAPPING(writeRaw, xmlwriter_write_raw, arginfo_xmlwriter_method_write_raw, 0)
  487. PHP_ME_MAPPING(startDocument, xmlwriter_start_document, arginfo_xmlwriter_method_start_document, 0)
  488. PHP_ME_MAPPING(endDocument, xmlwriter_end_document, arginfo_xmlwriter_void, 0)
  489. PHP_ME_MAPPING(writeComment, xmlwriter_write_comment, arginfo_xmlwriter_method_write_comment, 0)
  490. PHP_ME_MAPPING(startDtd, xmlwriter_start_dtd, arginfo_xmlwriter_method_start_dtd, 0)
  491. PHP_ME_MAPPING(endDtd, xmlwriter_end_dtd, arginfo_xmlwriter_void, 0)
  492. PHP_ME_MAPPING(writeDtd, xmlwriter_write_dtd, arginfo_xmlwriter_method_write_dtd, 0)
  493. PHP_ME_MAPPING(startDtdElement, xmlwriter_start_dtd_element,arginfo_xmlwriter_method_start_dtd_element, 0)
  494. PHP_ME_MAPPING(endDtdElement, xmlwriter_end_dtd_element, arginfo_xmlwriter_void, 0)
  495. PHP_ME_MAPPING(writeDtdElement, xmlwriter_write_dtd_element, arginfo_xmlwriter_method_write_dtd_element, 0)
  496. #if LIBXML_VERSION > 20608
  497. PHP_ME_MAPPING(startDtdAttlist, xmlwriter_start_dtd_attlist, arginfo_xmlwriter_method_start_dtd_attlist, 0)
  498. PHP_ME_MAPPING(endDtdAttlist, xmlwriter_end_dtd_attlist, arginfo_xmlwriter_void, 0)
  499. PHP_ME_MAPPING(writeDtdAttlist, xmlwriter_write_dtd_attlist, arginfo_xmlwriter_method_write_dtd_attlist, 0)
  500. PHP_ME_MAPPING(startDtdEntity, xmlwriter_start_dtd_entity, arginfo_xmlwriter_method_start_dtd_entity, 0)
  501. PHP_ME_MAPPING(endDtdEntity, xmlwriter_end_dtd_entity, arginfo_xmlwriter_void, 0)
  502. PHP_ME_MAPPING(writeDtdEntity, xmlwriter_write_dtd_entity, arginfo_xmlwriter_method_write_dtd_entity, 0)
  503. #endif
  504. PHP_ME_MAPPING(outputMemory, xmlwriter_output_memory, arginfo_xmlwriter_method_output_memory, 0)
  505. PHP_ME_MAPPING(flush, xmlwriter_flush, arginfo_xmlwriter_method_flush, 0)
  506. {NULL, NULL, NULL}
  507. };
  508. /* }}} */
  509. #endif
  510. /* {{{ function prototypes */
  511. static PHP_MINIT_FUNCTION(xmlwriter);
  512. static PHP_MSHUTDOWN_FUNCTION(xmlwriter);
  513. static PHP_MINFO_FUNCTION(xmlwriter);
  514. static int le_xmlwriter;
  515. /* }}} */
  516. /* _xmlwriter_get_valid_file_path should be made a
  517. common function in libxml extension as code is common to a few xml extensions */
  518. /* {{{ _xmlwriter_get_valid_file_path */
  519. static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len TSRMLS_DC) {
  520. xmlURI *uri;
  521. xmlChar *escsource;
  522. char *file_dest;
  523. int isFileUri = 0;
  524. uri = xmlCreateURI();
  525. escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *) ":");
  526. xmlParseURIReference(uri, (char *)escsource);
  527. xmlFree(escsource);
  528. if (uri->scheme != NULL) {
  529. /* absolute file uris - libxml only supports localhost or empty host */
  530. if (strncasecmp(source, "file:///", 8) == 0) {
  531. if (source[sizeof("file:///") - 1] == '\0') {
  532. xmlFreeURI(uri);
  533. return NULL;
  534. }
  535. isFileUri = 1;
  536. #ifdef PHP_WIN32
  537. source += 8;
  538. #else
  539. source += 7;
  540. #endif
  541. } else if (strncasecmp(source, "file://localhost/",17) == 0) {
  542. if (source[sizeof("file://localhost/") - 1] == '\0') {
  543. xmlFreeURI(uri);
  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", 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(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, "p", &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. */