PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/ext/xml/compat.c

http://github.com/infusion/PHP
C | 796 lines | 646 code | 110 blank | 40 comment | 122 complexity | 75988f8e6800de29d09e5d1e283aff70 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2011 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. | Authors: Sterling Hughes <sterling@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #include "php.h"
  19. #if defined(HAVE_LIBXML) && (defined(HAVE_XML) || defined(HAVE_XMLRPC)) && !defined(HAVE_LIBEXPAT)
  20. #include "expat_compat.h"
  21. typedef struct _php_xml_ns {
  22. xmlNsPtr nsptr;
  23. int ref_count;
  24. void *next;
  25. void *prev;
  26. } php_xml_ns;
  27. #ifdef LIBXML_EXPAT_COMPAT
  28. #define IS_NS_DECL(__ns) \
  29. ((__ns) != NULL && strlen(__ns) == 5 && *(__ns) == 'x' && *((__ns)+1) == 'm' && \
  30. *((__ns)+2) == 'l' && *((__ns)+3) == 'n' && *((__ns)+4) == 's')
  31. static void
  32. _qualify_namespace(XML_Parser parser, const xmlChar *name, const xmlChar *URI, xmlChar **qualified)
  33. {
  34. if (URI) {
  35. /* Use libxml functions otherwise its memory deallocation is screwed up */
  36. *qualified = xmlStrdup(URI);
  37. *qualified = xmlStrncat(*qualified, parser->_ns_seperator, 1);
  38. *qualified = xmlStrncat(*qualified, name, xmlStrlen(name));
  39. } else {
  40. *qualified = xmlStrdup(name);
  41. }
  42. }
  43. static void
  44. _start_element_handler(void *user, const xmlChar *name, const xmlChar **attributes)
  45. {
  46. XML_Parser parser = (XML_Parser) user;
  47. xmlChar *qualified_name = NULL;
  48. if (parser->h_start_element == NULL) {
  49. if (parser->h_default) {
  50. int attno = 0;
  51. qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name));
  52. if (attributes) {
  53. while (attributes[attno] != NULL) {
  54. int att_len;
  55. char *att_string, *att_name, *att_value;
  56. att_name = (char *)attributes[attno++];
  57. att_value = (char *)attributes[attno++];
  58. att_len = spprintf(&att_string, 0, " %s=\"%s\"", att_name, att_value);
  59. qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len);
  60. efree(att_string);
  61. }
  62. }
  63. qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1);
  64. parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name));
  65. xmlFree(qualified_name);
  66. }
  67. return;
  68. }
  69. qualified_name = xmlStrdup(name);
  70. parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attributes);
  71. xmlFree(qualified_name);
  72. }
  73. static void
  74. _start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, const xmlChar ** attributes)
  75. {
  76. XML_Parser parser = (XML_Parser) user;
  77. xmlChar *qualified_name = NULL;
  78. xmlChar **attrs = NULL;
  79. int i;
  80. int z = 0;
  81. int y = 0;
  82. if (nb_namespaces > 0 && parser->h_start_ns != NULL) {
  83. for (i = 0; i < nb_namespaces; i += 1) {
  84. parser->h_start_ns(parser->user, (const XML_Char *) namespaces[y], (const XML_Char *) namespaces[y+1]);
  85. y += 2;
  86. }
  87. y = 0;
  88. }
  89. if (parser->h_start_element == NULL) {
  90. if (parser->h_default) {
  91. if (prefix) {
  92. qualified_name = xmlStrncatNew((xmlChar *)"<", prefix, xmlStrlen(prefix));
  93. qualified_name = xmlStrncat(qualified_name, (xmlChar *)":", 1);
  94. qualified_name = xmlStrncat(qualified_name, name, xmlStrlen(name));
  95. } else {
  96. qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name));
  97. }
  98. if (namespaces) {
  99. int i, j;
  100. for (i = 0,j = 0;j < nb_namespaces;j++) {
  101. int ns_len;
  102. char *ns_string, *ns_prefix, *ns_url;
  103. ns_prefix = (char *) namespaces[i++];
  104. ns_url = (char *) namespaces[i++];
  105. if (ns_prefix) {
  106. ns_len = spprintf(&ns_string, 0, " xmlns:%s=\"%s\"", ns_prefix, ns_url);
  107. } else {
  108. ns_len = spprintf(&ns_string, 0, " xmlns=\"%s\"", ns_url);
  109. }
  110. qualified_name = xmlStrncat(qualified_name, (xmlChar *)ns_string, ns_len);
  111. efree(ns_string);
  112. }
  113. }
  114. if (attributes) {
  115. for (i = 0; i < nb_attributes; i += 1) {
  116. int att_len;
  117. char *att_string, *att_name, *att_value, *att_prefix, *att_valueend;
  118. att_name = (char *) attributes[y++];
  119. att_prefix = (char *)attributes[y++];
  120. y++;
  121. att_value = (char *)attributes[y++];
  122. att_valueend = (char *)attributes[y++];
  123. if (att_prefix) {
  124. att_len = spprintf(&att_string, 0, " %s:%s=\"", att_prefix, att_name);
  125. } else {
  126. att_len = spprintf(&att_string, 0, " %s=\"", att_name);
  127. }
  128. qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len);
  129. qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_value, att_valueend - att_value);
  130. qualified_name = xmlStrncat(qualified_name, (xmlChar *)"\"", 1);
  131. efree(att_string);
  132. }
  133. }
  134. qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1);
  135. parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name));
  136. xmlFree(qualified_name);
  137. }
  138. return;
  139. }
  140. _qualify_namespace(parser, name, URI, &qualified_name);
  141. if (attributes != NULL) {
  142. xmlChar *qualified_name_attr = NULL;
  143. attrs = safe_emalloc((nb_attributes * 2) + 1, sizeof(int *), 0);
  144. for (i = 0; i < nb_attributes; i += 1) {
  145. if (attributes[y+1] != NULL) {
  146. _qualify_namespace(parser, attributes[y] , attributes[y + 2], &qualified_name_attr);
  147. } else {
  148. qualified_name_attr = xmlStrdup(attributes[y]);
  149. }
  150. attrs[z] = qualified_name_attr;
  151. attrs[z + 1] = xmlStrndup(attributes[y + 3] , (int) (attributes[y + 4] - attributes[y + 3]));
  152. z += 2;
  153. y += 5;
  154. }
  155. attrs[z] = NULL;
  156. }
  157. parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attrs);
  158. if (attrs) {
  159. for (i = 0; i < z; i++) {
  160. xmlFree(attrs[i]);
  161. }
  162. efree(attrs);
  163. }
  164. xmlFree(qualified_name);
  165. }
  166. static void
  167. _namespace_handler(XML_Parser parser, xmlNsPtr nsptr)
  168. {
  169. if (nsptr != NULL) {
  170. _namespace_handler(parser, nsptr->next);
  171. parser->h_end_ns(parser->user, nsptr->prefix);
  172. }
  173. }
  174. static void
  175. _end_element_handler(void *user, const xmlChar *name)
  176. {
  177. xmlChar *qualified_name;
  178. XML_Parser parser = (XML_Parser) user;
  179. if (parser->h_end_element == NULL) {
  180. if (parser->h_default) {
  181. char *end_element;
  182. spprintf(&end_element, 0, "</%s>", (char *)name);
  183. parser->h_default(parser->user, (const XML_Char *) end_element, strlen(end_element));
  184. efree(end_element);
  185. }
  186. return;
  187. }
  188. qualified_name = xmlStrdup(name);
  189. parser->h_end_element(parser->user, (const XML_Char *) qualified_name);
  190. xmlFree(qualified_name);
  191. }
  192. static void
  193. _end_element_handler_ns(void *user, const xmlChar *name, const xmlChar * prefix, const xmlChar *URI)
  194. {
  195. xmlChar *qualified_name;
  196. XML_Parser parser = (XML_Parser) user;
  197. if (parser->h_end_element == NULL) {
  198. if (parser->h_default) {
  199. char *end_element;
  200. int end_element_len;
  201. if (prefix) {
  202. end_element_len = spprintf(&end_element, 0, "</%s:%s>", (char *) prefix, (char *)name);
  203. } else {
  204. end_element_len = spprintf(&end_element, 0, "</%s>", (char *)name);
  205. }
  206. parser->h_default(parser->user, (const XML_Char *) end_element, end_element_len);
  207. efree(end_element);
  208. }
  209. return;
  210. }
  211. _qualify_namespace(parser, name, URI, &qualified_name);
  212. parser->h_end_element(parser->user, (const XML_Char *) qualified_name);
  213. xmlFree(qualified_name);
  214. }
  215. static void
  216. _cdata_handler(void *user, const xmlChar *cdata, int cdata_len)
  217. {
  218. XML_Parser parser = (XML_Parser) user;
  219. if (parser->h_cdata == NULL) {
  220. if (parser->h_default) {
  221. parser->h_default(parser->user, (const XML_Char *) cdata, cdata_len);
  222. }
  223. return;
  224. }
  225. parser->h_cdata(parser->user, (const XML_Char *) cdata, cdata_len);
  226. }
  227. static void
  228. _pi_handler(void *user, const xmlChar *target, const xmlChar *data)
  229. {
  230. XML_Parser parser = (XML_Parser) user;
  231. if (parser->h_pi == NULL) {
  232. if (parser->h_default) {
  233. char *full_pi;
  234. spprintf(&full_pi, 0, "<?%s %s?>", (char *)target, (char *)data);
  235. parser->h_default(parser->user, (const XML_Char *) full_pi, strlen(full_pi));
  236. efree(full_pi);
  237. }
  238. return;
  239. }
  240. parser->h_pi(parser->user, (const XML_Char *) target, (const XML_Char *) data);
  241. }
  242. static void
  243. _unparsed_entity_decl_handler(void *user,
  244. const xmlChar *name,
  245. const xmlChar *pub_id,
  246. const xmlChar *sys_id,
  247. const xmlChar *notation)
  248. {
  249. XML_Parser parser = (XML_Parser) user;
  250. if (parser->h_unparsed_entity_decl == NULL) {
  251. return;
  252. }
  253. parser->h_unparsed_entity_decl(parser->user, name, NULL, sys_id, pub_id, notation);
  254. }
  255. static void
  256. _notation_decl_handler(void *user, const xmlChar *notation, const xmlChar *pub_id, const xmlChar *sys_id)
  257. {
  258. XML_Parser parser = (XML_Parser) user;
  259. if (parser->h_notation_decl == NULL) {
  260. return;
  261. }
  262. parser->h_notation_decl(parser->user, notation, NULL, sys_id, pub_id);
  263. }
  264. static void
  265. _build_comment(const xmlChar *data, int data_len, xmlChar **comment, int *comment_len)
  266. {
  267. *comment_len = data_len + 7;
  268. *comment = xmlMalloc(*comment_len + 1);
  269. memcpy(*comment, "<!--", 4);
  270. memcpy(*comment + 4, data, data_len);
  271. memcpy(*comment + 4 + data_len, "-->", 3);
  272. (*comment)[*comment_len] = '\0';
  273. }
  274. static void
  275. _comment_handler(void *user, const xmlChar *comment)
  276. {
  277. XML_Parser parser = (XML_Parser) user;
  278. if (parser->h_default) {
  279. xmlChar *d_comment;
  280. int d_comment_len;
  281. _build_comment(comment, xmlStrlen(comment), &d_comment, &d_comment_len);
  282. parser->h_default(parser->user, d_comment, d_comment_len);
  283. xmlFree(d_comment);
  284. }
  285. }
  286. static void
  287. _build_entity(const xmlChar *name, int len, xmlChar **entity, int *entity_len)
  288. {
  289. *entity_len = len + 2;
  290. *entity = xmlMalloc(*entity_len + 1);
  291. (*entity)[0] = '&';
  292. memcpy(*entity+1, name, len);
  293. (*entity)[len+1] = ';';
  294. (*entity)[*entity_len] = '\0';
  295. }
  296. static void
  297. _external_entity_ref_handler(void *user, const xmlChar *names, int type, const xmlChar *sys_id, const xmlChar *pub_id, xmlChar *content)
  298. {
  299. XML_Parser parser = (XML_Parser) user;
  300. if (parser->h_external_entity_ref == NULL) {
  301. return;
  302. }
  303. parser->h_external_entity_ref(parser, names, "", sys_id, pub_id);
  304. }
  305. static xmlEntityPtr
  306. _get_entity(void *user, const xmlChar *name)
  307. {
  308. XML_Parser parser = (XML_Parser) user;
  309. xmlEntityPtr ret = NULL;
  310. if (parser->parser->inSubset == 0) {
  311. ret = xmlGetPredefinedEntity(name);
  312. if (ret == NULL)
  313. ret = xmlGetDocEntity(parser->parser->myDoc, name);
  314. if (ret == NULL || (parser->parser->instate != XML_PARSER_ENTITY_VALUE && parser->parser->instate != XML_PARSER_ATTRIBUTE_VALUE)) {
  315. if (ret == NULL || ret->etype == XML_INTERNAL_GENERAL_ENTITY || ret->etype == XML_INTERNAL_PARAMETER_ENTITY || ret->etype == XML_INTERNAL_PREDEFINED_ENTITY) {
  316. /* Predefined entities will expand unless no cdata handler is present */
  317. if (parser->h_default && ! (ret && ret->etype == XML_INTERNAL_PREDEFINED_ENTITY && parser->h_cdata)) {
  318. xmlChar *entity;
  319. int len;
  320. _build_entity(name, xmlStrlen(name), &entity, &len);
  321. parser->h_default(parser->user, (const xmlChar *) entity, len);
  322. xmlFree(entity);
  323. } else {
  324. /* expat will not expand internal entities if default handler is present otherwise
  325. it will expand and pass them to cdata handler */
  326. if (parser->h_cdata && ret) {
  327. parser->h_cdata(parser->user, ret->content, xmlStrlen(ret->content));
  328. }
  329. }
  330. } else {
  331. if (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) {
  332. _external_entity_ref_handler(user, ret->name, ret->etype, ret->SystemID, ret->ExternalID, NULL);
  333. }
  334. }
  335. }
  336. }
  337. return ret;
  338. }
  339. static xmlSAXHandler
  340. php_xml_compat_handlers = {
  341. NULL, /* internalSubset */
  342. NULL, /* isStandalone */
  343. NULL, /* hasInternalSubset */
  344. NULL, /* hasExternalSubset */
  345. NULL, /* resolveEntity */
  346. _get_entity, /* getEntity */
  347. NULL, /* entityDecl */
  348. _notation_decl_handler,
  349. NULL, /* attributeDecl */
  350. NULL, /* elementDecl */
  351. _unparsed_entity_decl_handler, /* unparsedEntity */
  352. NULL, /* setDocumentLocator */
  353. NULL, /* startDocument */
  354. NULL, /* endDocument */
  355. _start_element_handler, /* startElement */
  356. _end_element_handler, /* endElement */
  357. NULL, /* reference */
  358. _cdata_handler,
  359. NULL, /* ignorableWhitespace */
  360. _pi_handler,
  361. _comment_handler, /* comment */
  362. NULL, /* warning */
  363. NULL, /* error */
  364. NULL, /* fatalError */
  365. NULL, /* getParameterEntity */
  366. _cdata_handler, /* cdataBlock */
  367. NULL, /* externalSubset */
  368. XML_SAX2_MAGIC,
  369. NULL,
  370. _start_element_handler_ns,
  371. _end_element_handler_ns,
  372. NULL
  373. };
  374. PHPAPI XML_Parser
  375. XML_ParserCreate(const XML_Char *encoding)
  376. {
  377. return XML_ParserCreate_MM(encoding, NULL, NULL);
  378. }
  379. PHPAPI XML_Parser
  380. XML_ParserCreateNS(const XML_Char *encoding, const XML_Char sep)
  381. {
  382. XML_Char tmp[2];
  383. tmp[0] = sep;
  384. tmp[1] = '\0';
  385. return XML_ParserCreate_MM(encoding, NULL, tmp);
  386. }
  387. PHPAPI XML_Parser
  388. XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite, const XML_Char *sep)
  389. {
  390. XML_Parser parser;
  391. parser = (XML_Parser) emalloc(sizeof(struct _XML_Parser));
  392. memset(parser, 0, sizeof(struct _XML_Parser));
  393. parser->use_namespace = 0;
  394. parser->_ns_seperator = NULL;
  395. parser->parser = xmlCreatePushParserCtxt((xmlSAXHandlerPtr) &php_xml_compat_handlers, (void *) parser, NULL, 0, NULL);
  396. if (parser->parser == NULL) {
  397. efree(parser);
  398. return NULL;
  399. }
  400. #if LIBXML_VERSION <= 20617
  401. /* for older versions of libxml2, allow correct detection of
  402. * charset in documents with a BOM: */
  403. parser->parser->charset = XML_CHAR_ENCODING_NONE;
  404. #endif
  405. #if LIBXML_VERSION >= 20703
  406. xmlCtxtUseOptions(parser->parser, XML_PARSE_OLDSAX);
  407. #endif
  408. parser->parser->replaceEntities = 1;
  409. parser->parser->wellFormed = 0;
  410. if (sep != NULL) {
  411. parser->use_namespace = 1;
  412. parser->parser->sax2 = 1;
  413. parser->_ns_seperator = xmlStrdup(sep);
  414. } else {
  415. /* Reset flag as XML_SAX2_MAGIC is needed for xmlCreatePushParserCtxt
  416. so must be set in the handlers */
  417. parser->parser->sax->initialized = 1;
  418. }
  419. return parser;
  420. }
  421. PHPAPI void
  422. XML_SetUserData(XML_Parser parser, void *user)
  423. {
  424. parser->user = user;
  425. }
  426. PHPAPI void *
  427. XML_GetUserData(XML_Parser parser)
  428. {
  429. return parser->user;
  430. }
  431. PHPAPI void
  432. XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
  433. {
  434. parser->h_start_element = start;
  435. parser->h_end_element = end;
  436. }
  437. PHPAPI void
  438. XML_SetCharacterDataHandler(XML_Parser parser, XML_CharacterDataHandler cdata)
  439. {
  440. parser->h_cdata = cdata;
  441. }
  442. PHPAPI void
  443. XML_SetProcessingInstructionHandler(XML_Parser parser, XML_ProcessingInstructionHandler pi)
  444. {
  445. parser->h_pi = pi;
  446. }
  447. PHPAPI void
  448. XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler comment)
  449. {
  450. parser->h_comment = comment;
  451. }
  452. PHPAPI void
  453. XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler d)
  454. {
  455. parser->h_default = d;
  456. }
  457. PHPAPI void
  458. XML_SetUnparsedEntityDeclHandler(XML_Parser parser, XML_UnparsedEntityDeclHandler unparsed_decl)
  459. {
  460. parser->h_unparsed_entity_decl = unparsed_decl;
  461. }
  462. PHPAPI void
  463. XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler notation_decl)
  464. {
  465. parser->h_notation_decl = notation_decl;
  466. }
  467. PHPAPI void
  468. XML_SetExternalEntityRefHandler(XML_Parser parser, XML_ExternalEntityRefHandler ext_entity)
  469. {
  470. parser->h_external_entity_ref = ext_entity;
  471. }
  472. PHPAPI void
  473. XML_SetStartNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start_ns)
  474. {
  475. parser->h_start_ns = start_ns;
  476. }
  477. PHPAPI void
  478. XML_SetEndNamespaceDeclHandler(XML_Parser parser, XML_EndNamespaceDeclHandler end_ns)
  479. {
  480. parser->h_end_ns = end_ns;
  481. }
  482. PHPAPI int
  483. XML_Parse(XML_Parser parser, const XML_Char *data, int data_len, int is_final)
  484. {
  485. int error;
  486. /* The following is a hack to keep BC with PHP 4 while avoiding
  487. the inifite loop in libxml <= 2.6.17 which occurs when no encoding
  488. has been defined and none can be detected */
  489. #if LIBXML_VERSION <= 20617
  490. if (parser->parser->charset == XML_CHAR_ENCODING_NONE) {
  491. if (data_len >= 4 || (parser->parser->input->buf->buffer->use + data_len >= 4)) {
  492. xmlChar start[4];
  493. int char_count;
  494. char_count = parser->parser->input->buf->buffer->use;
  495. if (char_count > 4) {
  496. char_count = 4;
  497. }
  498. memcpy(start, parser->parser->input->buf->buffer->content, (size_t)char_count);
  499. memcpy(start + char_count, data, (size_t)(4 - char_count));
  500. if (xmlDetectCharEncoding(&start[0], 4) == XML_CHAR_ENCODING_NONE) {
  501. parser->parser->charset = XML_CHAR_ENCODING_UTF8;
  502. }
  503. }
  504. }
  505. #endif
  506. error = xmlParseChunk(parser->parser, data, data_len, is_final);
  507. if (!error) {
  508. return 1;
  509. } else if (parser->parser->lastError.level > XML_ERR_WARNING ){
  510. return 0;
  511. } else {
  512. return 1;
  513. }
  514. }
  515. PHPAPI int
  516. XML_GetErrorCode(XML_Parser parser)
  517. {
  518. return parser->parser->errNo;
  519. }
  520. static const XML_Char *const error_mapping[] = {
  521. "No error",
  522. "No memory",
  523. "Invalid document start",
  524. "Empty document",
  525. "Not well-formed (invalid token)",
  526. "Invalid document end",
  527. "Invalid hexadecimal character reference",
  528. "Invalid decimal character reference",
  529. "Invalid character reference",
  530. "Invalid character",
  531. "XML_ERR_CHARREF_AT_EOF",
  532. "XML_ERR_CHARREF_IN_PROLOG",
  533. "XML_ERR_CHARREF_IN_EPILOG",
  534. "XML_ERR_CHARREF_IN_DTD",
  535. "XML_ERR_ENTITYREF_AT_EOF",
  536. "XML_ERR_ENTITYREF_IN_PROLOG",
  537. "XML_ERR_ENTITYREF_IN_EPILOG",
  538. "XML_ERR_ENTITYREF_IN_DTD",
  539. "PEReference at end of document",
  540. "PEReference in prolog",
  541. "PEReference in epilog",
  542. "PEReference: forbidden within markup decl in internal subset",
  543. "XML_ERR_ENTITYREF_NO_NAME",
  544. "EntityRef: expecting ';'",
  545. "PEReference: no name",
  546. "PEReference: expecting ';'",
  547. "Undeclared entity error",
  548. "Undeclared entity warning",
  549. "Unparsed Entity",
  550. "XML_ERR_ENTITY_IS_EXTERNAL",
  551. "XML_ERR_ENTITY_IS_PARAMETER",
  552. "Unknown encoding",
  553. "Unsupported encoding",
  554. "String not started expecting ' or \"",
  555. "String not closed expecting \" or '",
  556. "Namespace declaration error",
  557. "EntityValue: \" or ' expected",
  558. "EntityValue: \" or ' expected",
  559. "< in attribute",
  560. "Attribute not started",
  561. "Attribute not finished",
  562. "Attribute without value",
  563. "Attribute redefined",
  564. "SystemLiteral \" or ' expected",
  565. "SystemLiteral \" or ' expected",
  566. /* "XML_ERR_COMMENT_NOT_STARTED", <= eliminated on purpose */
  567. "Comment not finished",
  568. "Processing Instruction not started",
  569. "Processing Instruction not finished",
  570. "NOTATION: Name expected here",
  571. "'>' required to close NOTATION declaration",
  572. "'(' required to start ATTLIST enumeration",
  573. "'(' required to start ATTLIST enumeration",
  574. "MixedContentDecl : '|' or ')*' expected",
  575. "XML_ERR_MIXED_NOT_FINISHED",
  576. "ELEMENT in DTD not started",
  577. "ELEMENT in DTD not finished",
  578. "XML declaration not started",
  579. "XML declaration not finished",
  580. "XML_ERR_CONDSEC_NOT_STARTED",
  581. "XML conditional section not closed",
  582. "Content error in the external subset",
  583. "DOCTYPE not finished",
  584. "Sequence ']]>' not allowed in content",
  585. "CDATA not finished",
  586. "Reserved XML Name",
  587. "Space required",
  588. "XML_ERR_SEPARATOR_REQUIRED",
  589. "NmToken expected in ATTLIST enumeration",
  590. "XML_ERR_NAME_REQUIRED",
  591. "MixedContentDecl : '#PCDATA' expected",
  592. "SYSTEM or PUBLIC, the URI is missing",
  593. "PUBLIC, the Public Identifier is missing",
  594. "< required",
  595. "> required",
  596. "</ required",
  597. "= required",
  598. "Mismatched tag",
  599. "Tag not finished",
  600. "standalone accepts only 'yes' or 'no'",
  601. "Invalid XML encoding name",
  602. "Comment must not contain '--' (double-hyphen)",
  603. "Invalid encoding",
  604. "external parsed entities cannot be standalone",
  605. "XML conditional section '[' expected",
  606. "Entity value required",
  607. "chunk is not well balanced",
  608. "extra content at the end of well balanced chunk",
  609. "XML_ERR_ENTITY_CHAR_ERROR",
  610. "PEReferences forbidden in internal subset",
  611. "Detected an entity reference loop",
  612. "XML_ERR_ENTITY_BOUNDARY",
  613. "Invalid URI",
  614. "Fragment not allowed",
  615. "XML_WAR_CATALOG_PI",
  616. "XML_ERR_NO_DTD",
  617. "conditional section INCLUDE or IGNORE keyword expected", /* 95 */
  618. "Version in XML Declaration missing", /* 96 */
  619. "XML_WAR_UNKNOWN_VERSION", /* 97 */
  620. "XML_WAR_LANG_VALUE", /* 98 */
  621. "XML_WAR_NS_URI", /* 99 */
  622. "XML_WAR_NS_URI_RELATIVE", /* 100 */
  623. "Missing encoding in text declaration" /* 101 */
  624. };
  625. PHPAPI const XML_Char *
  626. XML_ErrorString(int code)
  627. {
  628. if (code < 0 || code >= (int)(sizeof(error_mapping) / sizeof(error_mapping[0]))) {
  629. return "Unknown";
  630. }
  631. return error_mapping[code];
  632. }
  633. PHPAPI int
  634. XML_GetCurrentLineNumber(XML_Parser parser)
  635. {
  636. return parser->parser->input->line;
  637. }
  638. PHPAPI int
  639. XML_GetCurrentColumnNumber(XML_Parser parser)
  640. {
  641. return parser->parser->input->col;
  642. }
  643. PHPAPI int
  644. XML_GetCurrentByteIndex(XML_Parser parser)
  645. {
  646. return parser->parser->input->consumed +
  647. (parser->parser->input->cur - parser->parser->input->base);
  648. }
  649. PHPAPI int
  650. XML_GetCurrentByteCount(XML_Parser parser)
  651. {
  652. /* WARNING: this is identical to ByteIndex; it should probably
  653. * be different */
  654. return parser->parser->input->consumed +
  655. (parser->parser->input->cur - parser->parser->input->base);
  656. }
  657. PHPAPI const XML_Char *XML_ExpatVersion(void)
  658. {
  659. return "1.0";
  660. }
  661. PHPAPI void
  662. XML_ParserFree(XML_Parser parser)
  663. {
  664. if (parser->use_namespace) {
  665. if (parser->_ns_seperator) {
  666. xmlFree(parser->_ns_seperator);
  667. }
  668. }
  669. if (parser->parser->myDoc) {
  670. xmlFreeDoc(parser->parser->myDoc);
  671. parser->parser->myDoc = NULL;
  672. }
  673. xmlFreeParserCtxt(parser->parser);
  674. efree(parser);
  675. }
  676. #endif /* LIBXML_EXPAT_COMPAT */
  677. #endif
  678. /**
  679. * Local Variables:
  680. * tab-width: 4
  681. * c-basic-offset: 4
  682. * indent-tabs-mode: t
  683. * End:
  684. * vim600: fdm=marker
  685. * vim: ts=4 noet sw=4
  686. */