| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * parser.c : an XML 1.0 parser, namespaces and validity support are mostly | 
|  | 3 | *            implemented on top of the SAX interfaces | 
|  | 4 | * | 
|  | 5 | * References: | 
|  | 6 | *   The XML specification: | 
|  | 7 | *     http://www.w3.org/TR/REC-xml | 
|  | 8 | *   Original 1.0 version: | 
|  | 9 | *     http://www.w3.org/TR/1998/REC-xml-19980210 | 
|  | 10 | *   XML second edition working draft | 
|  | 11 | *     http://www.w3.org/TR/2000/WD-xml-2e-20000814 | 
|  | 12 | * | 
|  | 13 | * Okay this is a big file, the parser core is around 7000 lines, then it | 
|  | 14 | * is followed by the progressive parser top routines, then the various | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 15 | * high level APIs to call the parser and a few miscellaneous functions. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 16 | * A number of helper functions and deprecated ones have been moved to | 
|  | 17 | * parserInternals.c to reduce this file size. | 
|  | 18 | * As much as possible the functions are associated with their relative | 
|  | 19 | * production in the XML specification. A few productions defining the | 
|  | 20 | * different ranges of character are actually implanted either in | 
|  | 21 | * parserInternals.h or parserInternals.c | 
|  | 22 | * The DOM tree build is realized from the default SAX callbacks in | 
|  | 23 | * the module SAX.c. | 
|  | 24 | * The routines doing the validation checks are in valid.c and called either | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 25 | * from the SAX callbacks or as standalone functions using a preparsed | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 26 | * document. | 
|  | 27 | * | 
|  | 28 | * See Copyright for the status of this software. | 
|  | 29 | * | 
| Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 30 | * daniel@veillard.com | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 31 | */ | 
|  | 32 |  | 
| Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 33 | #define IN_LIBXML | 
| Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 34 | #include "libxml.h" | 
|  | 35 |  | 
| Daniel Veillard | 3c5ed91 | 2002-01-08 10:36:16 +0000 | [diff] [blame] | 36 | #if defined(WIN32) && !defined (__CYGWIN__) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 37 | #define XML_DIR_SEP '\\' | 
|  | 38 | #else | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 39 | #define XML_DIR_SEP '/' | 
|  | 40 | #endif | 
|  | 41 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 42 | #include <stdlib.h> | 
|  | 43 | #include <string.h> | 
| Aleksey Sanin | e7acf43 | 2003-10-02 20:05:27 +0000 | [diff] [blame] | 44 | #include <stdarg.h> | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 45 | #include <libxml/xmlmemory.h> | 
| Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 46 | #include <libxml/threads.h> | 
|  | 47 | #include <libxml/globals.h> | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 48 | #include <libxml/tree.h> | 
|  | 49 | #include <libxml/parser.h> | 
|  | 50 | #include <libxml/parserInternals.h> | 
|  | 51 | #include <libxml/valid.h> | 
|  | 52 | #include <libxml/entities.h> | 
|  | 53 | #include <libxml/xmlerror.h> | 
|  | 54 | #include <libxml/encoding.h> | 
|  | 55 | #include <libxml/xmlIO.h> | 
|  | 56 | #include <libxml/uri.h> | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 57 | #ifdef LIBXML_CATALOG_ENABLED | 
|  | 58 | #include <libxml/catalog.h> | 
|  | 59 | #endif | 
| William M. Brack | 1d8c9b2 | 2004-12-25 10:14:57 +0000 | [diff] [blame] | 60 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 61 | #include <libxml/xmlschemastypes.h> | 
|  | 62 | #include <libxml/relaxng.h> | 
|  | 63 | #endif | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 64 | #ifdef HAVE_CTYPE_H | 
|  | 65 | #include <ctype.h> | 
|  | 66 | #endif | 
|  | 67 | #ifdef HAVE_STDLIB_H | 
|  | 68 | #include <stdlib.h> | 
|  | 69 | #endif | 
|  | 70 | #ifdef HAVE_SYS_STAT_H | 
|  | 71 | #include <sys/stat.h> | 
|  | 72 | #endif | 
|  | 73 | #ifdef HAVE_FCNTL_H | 
|  | 74 | #include <fcntl.h> | 
|  | 75 | #endif | 
|  | 76 | #ifdef HAVE_UNISTD_H | 
|  | 77 | #include <unistd.h> | 
|  | 78 | #endif | 
|  | 79 | #ifdef HAVE_ZLIB_H | 
|  | 80 | #include <zlib.h> | 
|  | 81 | #endif | 
|  | 82 |  | 
| Daniel Veillard | 3b2e4e1 | 2003-02-03 08:52:58 +0000 | [diff] [blame] | 83 | /** | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 84 | * xmlParserMaxDepth: | 
| Daniel Veillard | 3b2e4e1 | 2003-02-03 08:52:58 +0000 | [diff] [blame] | 85 | * | 
|  | 86 | * arbitrary depth limit for the XML documents that we allow to | 
|  | 87 | * process. This is not a limitation of the parser but a safety | 
|  | 88 | * boundary feature. | 
|  | 89 | */ | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 90 | unsigned int xmlParserMaxDepth = 1024; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 91 |  | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 92 | #define SAX2 1 | 
|  | 93 |  | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 94 | #define XML_PARSER_BIG_BUFFER_SIZE 300 | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 95 | #define XML_PARSER_BUFFER_SIZE 100 | 
|  | 96 |  | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 97 | #define SAX_COMPAT_MODE BAD_CAST "SAX compatibility mode document" | 
|  | 98 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 99 | /* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 100 | * List of XML prefixed PI allowed by W3C specs | 
|  | 101 | */ | 
|  | 102 |  | 
| Daniel Veillard | b44025c | 2001-10-11 22:55:55 +0000 | [diff] [blame] | 103 | static const char *xmlW3CPIs[] = { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 104 | "xml-stylesheet", | 
|  | 105 | NULL | 
|  | 106 | }; | 
|  | 107 |  | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 108 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 109 | /* DEPR void xmlParserHandleReference(xmlParserCtxtPtr ctxt); */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 110 | xmlEntityPtr xmlParseStringPEReference(xmlParserCtxtPtr ctxt, | 
|  | 111 | const xmlChar **str); | 
|  | 112 |  | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 113 | static xmlParserErrors | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 114 | xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, | 
|  | 115 | xmlSAXHandlerPtr sax, | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 116 | void *user_data, int depth, const xmlChar *URL, | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 117 | const xmlChar *ID, xmlNodePtr *list); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 118 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 119 | #ifdef LIBXML_LEGACY_ENABLED | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 120 | static void | 
|  | 121 | xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode, | 
|  | 122 | xmlNodePtr lastNode); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 123 | #endif /* LIBXML_LEGACY_ENABLED */ | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 124 |  | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 125 | static xmlParserErrors | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 126 | xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, | 
|  | 127 | const xmlChar *string, void *user_data, xmlNodePtr *lst); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 128 |  | 
|  | 129 | /************************************************************************ | 
|  | 130 | *									* | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 131 | * 		Some factorized error routines				* | 
|  | 132 | *									* | 
|  | 133 | ************************************************************************/ | 
|  | 134 |  | 
|  | 135 | /** | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 136 | * xmlErrAttributeDup: | 
|  | 137 | * @ctxt:  an XML parser context | 
|  | 138 | * @prefix:  the attribute prefix | 
|  | 139 | * @localname:  the attribute localname | 
|  | 140 | * | 
|  | 141 | * Handle a redefinition of attribute error | 
|  | 142 | */ | 
|  | 143 | static void | 
|  | 144 | xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix, | 
|  | 145 | const xmlChar * localname) | 
|  | 146 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 147 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 148 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 149 | return; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 150 | ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED; | 
| Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 151 | if (prefix == NULL) | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 152 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 153 | ctxt->errNo, XML_ERR_FATAL, NULL, 0, | 
|  | 154 | (const char *) localname, NULL, NULL, 0, 0, | 
|  | 155 | "Attribute %s redefined\n", localname); | 
| Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 156 | else | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 157 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 158 | ctxt->errNo, XML_ERR_FATAL, NULL, 0, | 
|  | 159 | (const char *) prefix, (const char *) localname, | 
|  | 160 | NULL, 0, 0, "Attribute %s:%s redefined\n", prefix, | 
|  | 161 | localname); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 162 | ctxt->wellFormed = 0; | 
|  | 163 | if (ctxt->recovery == 0) | 
|  | 164 | ctxt->disableSAX = 1; | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | /** | 
|  | 168 | * xmlFatalErr: | 
|  | 169 | * @ctxt:  an XML parser context | 
|  | 170 | * @error:  the error number | 
|  | 171 | * @extra:  extra information string | 
|  | 172 | * | 
|  | 173 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints | 
|  | 174 | */ | 
|  | 175 | static void | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 176 | xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info) | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 177 | { | 
|  | 178 | const char *errmsg; | 
|  | 179 |  | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 180 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 181 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 182 | return; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 183 | switch (error) { | 
|  | 184 | case XML_ERR_INVALID_HEX_CHARREF: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 185 | errmsg = "CharRef: invalid hexadecimal value\n"; | 
|  | 186 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 187 | case XML_ERR_INVALID_DEC_CHARREF: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 188 | errmsg = "CharRef: invalid decimal value\n"; | 
|  | 189 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 190 | case XML_ERR_INVALID_CHARREF: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 191 | errmsg = "CharRef: invalid value\n"; | 
|  | 192 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 193 | case XML_ERR_INTERNAL_ERROR: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 194 | errmsg = "internal error"; | 
|  | 195 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 196 | case XML_ERR_PEREF_AT_EOF: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 197 | errmsg = "PEReference at end of document\n"; | 
|  | 198 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 199 | case XML_ERR_PEREF_IN_PROLOG: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 200 | errmsg = "PEReference in prolog\n"; | 
|  | 201 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 202 | case XML_ERR_PEREF_IN_EPILOG: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 203 | errmsg = "PEReference in epilog\n"; | 
|  | 204 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 205 | case XML_ERR_PEREF_NO_NAME: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 206 | errmsg = "PEReference: no name\n"; | 
|  | 207 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 208 | case XML_ERR_PEREF_SEMICOL_MISSING: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 209 | errmsg = "PEReference: expecting ';'\n"; | 
|  | 210 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 211 | case XML_ERR_ENTITY_LOOP: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 212 | errmsg = "Detected an entity reference loop\n"; | 
|  | 213 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 214 | case XML_ERR_ENTITY_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 215 | errmsg = "EntityValue: \" or ' expected\n"; | 
|  | 216 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 217 | case XML_ERR_ENTITY_PE_INTERNAL: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 218 | errmsg = "PEReferences forbidden in internal subset\n"; | 
|  | 219 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 220 | case XML_ERR_ENTITY_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 221 | errmsg = "EntityValue: \" or ' expected\n"; | 
|  | 222 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 223 | case XML_ERR_ATTRIBUTE_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 224 | errmsg = "AttValue: \" or ' expected\n"; | 
|  | 225 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 226 | case XML_ERR_LT_IN_ATTRIBUTE: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 227 | errmsg = "Unescaped '<' not allowed in attributes values\n"; | 
|  | 228 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 229 | case XML_ERR_LITERAL_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 230 | errmsg = "SystemLiteral \" or ' expected\n"; | 
|  | 231 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 232 | case XML_ERR_LITERAL_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 233 | errmsg = "Unfinished System or Public ID \" or ' expected\n"; | 
|  | 234 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 235 | case XML_ERR_MISPLACED_CDATA_END: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 236 | errmsg = "Sequence ']]>' not allowed in content\n"; | 
|  | 237 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 238 | case XML_ERR_URI_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 239 | errmsg = "SYSTEM or PUBLIC, the URI is missing\n"; | 
|  | 240 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 241 | case XML_ERR_PUBID_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 242 | errmsg = "PUBLIC, the Public Identifier is missing\n"; | 
|  | 243 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 244 | case XML_ERR_HYPHEN_IN_COMMENT: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 245 | errmsg = "Comment must not contain '--' (double-hyphen)\n"; | 
|  | 246 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 247 | case XML_ERR_PI_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 248 | errmsg = "xmlParsePI : no target name\n"; | 
|  | 249 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 250 | case XML_ERR_RESERVED_XML_NAME: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 251 | errmsg = "Invalid PI name\n"; | 
|  | 252 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 253 | case XML_ERR_NOTATION_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 254 | errmsg = "NOTATION: Name expected here\n"; | 
|  | 255 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 256 | case XML_ERR_NOTATION_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 257 | errmsg = "'>' required to close NOTATION declaration\n"; | 
|  | 258 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 259 | case XML_ERR_VALUE_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 260 | errmsg = "Entity value required\n"; | 
|  | 261 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 262 | case XML_ERR_URI_FRAGMENT: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 263 | errmsg = "Fragment not allowed"; | 
|  | 264 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 265 | case XML_ERR_ATTLIST_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 266 | errmsg = "'(' required to start ATTLIST enumeration\n"; | 
|  | 267 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 268 | case XML_ERR_NMTOKEN_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 269 | errmsg = "NmToken expected in ATTLIST enumeration\n"; | 
|  | 270 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 271 | case XML_ERR_ATTLIST_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 272 | errmsg = "')' required to finish ATTLIST enumeration\n"; | 
|  | 273 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 274 | case XML_ERR_MIXED_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 275 | errmsg = "MixedContentDecl : '|' or ')*' expected\n"; | 
|  | 276 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 277 | case XML_ERR_PCDATA_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 278 | errmsg = "MixedContentDecl : '#PCDATA' expected\n"; | 
|  | 279 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 280 | case XML_ERR_ELEMCONTENT_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 281 | errmsg = "ContentDecl : Name or '(' expected\n"; | 
|  | 282 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 283 | case XML_ERR_ELEMCONTENT_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 284 | errmsg = "ContentDecl : ',' '|' or ')' expected\n"; | 
|  | 285 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 286 | case XML_ERR_PEREF_IN_INT_SUBSET: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 287 | errmsg = | 
|  | 288 | "PEReference: forbidden within markup decl in internal subset\n"; | 
|  | 289 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 290 | case XML_ERR_GT_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 291 | errmsg = "expected '>'\n"; | 
|  | 292 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 293 | case XML_ERR_CONDSEC_INVALID: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 294 | errmsg = "XML conditional section '[' expected\n"; | 
|  | 295 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 296 | case XML_ERR_EXT_SUBSET_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 297 | errmsg = "Content error in the external subset\n"; | 
|  | 298 | break; | 
|  | 299 | case XML_ERR_CONDSEC_INVALID_KEYWORD: | 
|  | 300 | errmsg = | 
|  | 301 | "conditional section INCLUDE or IGNORE keyword expected\n"; | 
|  | 302 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 303 | case XML_ERR_CONDSEC_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 304 | errmsg = "XML conditional section not closed\n"; | 
|  | 305 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 306 | case XML_ERR_XMLDECL_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 307 | errmsg = "Text declaration '<?xml' required\n"; | 
|  | 308 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 309 | case XML_ERR_XMLDECL_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 310 | errmsg = "parsing XML declaration: '?>' expected\n"; | 
|  | 311 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 312 | case XML_ERR_EXT_ENTITY_STANDALONE: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 313 | errmsg = "external parsed entities cannot be standalone\n"; | 
|  | 314 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 315 | case XML_ERR_ENTITYREF_SEMICOL_MISSING: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 316 | errmsg = "EntityRef: expecting ';'\n"; | 
|  | 317 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 318 | case XML_ERR_DOCTYPE_NOT_FINISHED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 319 | errmsg = "DOCTYPE improperly terminated\n"; | 
|  | 320 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 321 | case XML_ERR_LTSLASH_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 322 | errmsg = "EndTag: '</' not found\n"; | 
|  | 323 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 324 | case XML_ERR_EQUAL_REQUIRED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 325 | errmsg = "expected '='\n"; | 
|  | 326 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 327 | case XML_ERR_STRING_NOT_CLOSED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 328 | errmsg = "String not closed expecting \" or '\n"; | 
|  | 329 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 330 | case XML_ERR_STRING_NOT_STARTED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 331 | errmsg = "String not started expecting ' or \"\n"; | 
|  | 332 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 333 | case XML_ERR_ENCODING_NAME: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 334 | errmsg = "Invalid XML encoding name\n"; | 
|  | 335 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 336 | case XML_ERR_STANDALONE_VALUE: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 337 | errmsg = "standalone accepts only 'yes' or 'no'\n"; | 
|  | 338 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 339 | case XML_ERR_DOCUMENT_EMPTY: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 340 | errmsg = "Document is empty\n"; | 
|  | 341 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 342 | case XML_ERR_DOCUMENT_END: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 343 | errmsg = "Extra content at the end of the document\n"; | 
|  | 344 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 345 | case XML_ERR_NOT_WELL_BALANCED: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 346 | errmsg = "chunk is not well balanced\n"; | 
|  | 347 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 348 | case XML_ERR_EXTRA_CONTENT: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 349 | errmsg = "extra content at the end of well balanced chunk\n"; | 
|  | 350 | break; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 351 | case XML_ERR_VERSION_MISSING: | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 352 | errmsg = "Malformed declaration expecting version\n"; | 
|  | 353 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 354 | #if 0 | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 355 | case: | 
|  | 356 | errmsg = "\n"; | 
|  | 357 | break; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 358 | #endif | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 359 | default: | 
|  | 360 | errmsg = "Unregistered error message\n"; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 361 | } | 
|  | 362 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 363 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 364 | XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg, | 
|  | 365 | info); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 366 | ctxt->wellFormed = 0; | 
|  | 367 | if (ctxt->recovery == 0) | 
|  | 368 | ctxt->disableSAX = 1; | 
|  | 369 | } | 
|  | 370 |  | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 371 | /** | 
|  | 372 | * xmlFatalErrMsg: | 
|  | 373 | * @ctxt:  an XML parser context | 
|  | 374 | * @error:  the error number | 
|  | 375 | * @msg:  the error message | 
|  | 376 | * | 
|  | 377 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints | 
|  | 378 | */ | 
|  | 379 | static void | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 380 | xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
|  | 381 | const char *msg) | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 382 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 383 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 384 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 385 | return; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 386 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 387 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 388 | XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg); | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 389 | ctxt->wellFormed = 0; | 
|  | 390 | if (ctxt->recovery == 0) | 
|  | 391 | ctxt->disableSAX = 1; | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | /** | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 395 | * xmlWarningMsg: | 
|  | 396 | * @ctxt:  an XML parser context | 
|  | 397 | * @error:  the error number | 
|  | 398 | * @msg:  the error message | 
|  | 399 | * @str1:  extra data | 
|  | 400 | * @str2:  extra data | 
|  | 401 | * | 
|  | 402 | * Handle a warning. | 
|  | 403 | */ | 
|  | 404 | static void | 
|  | 405 | xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
|  | 406 | const char *msg, const xmlChar *str1, const xmlChar *str2) | 
|  | 407 | { | 
| Daniel Veillard | 9bcc7c5 | 2003-10-11 10:57:05 +0000 | [diff] [blame] | 408 | xmlStructuredErrorFunc schannel = NULL; | 
| Daniel Veillard | c790bf4 | 2003-10-11 10:50:10 +0000 | [diff] [blame] | 409 |  | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 410 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 411 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 412 | return; | 
| Daniel Veillard | c790bf4 | 2003-10-11 10:50:10 +0000 | [diff] [blame] | 413 | if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) | 
| Daniel Veillard | 9bcc7c5 | 2003-10-11 10:57:05 +0000 | [diff] [blame] | 414 | schannel = ctxt->sax->serror; | 
|  | 415 | __xmlRaiseError(schannel, | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 416 | (ctxt->sax) ? ctxt->sax->warning : NULL, | 
|  | 417 | ctxt->userData, | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 418 | ctxt, NULL, XML_FROM_PARSER, error, | 
|  | 419 | XML_ERR_WARNING, NULL, 0, | 
|  | 420 | (const char *) str1, (const char *) str2, NULL, 0, 0, | 
|  | 421 | msg, (const char *) str1, (const char *) str2); | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | /** | 
|  | 425 | * xmlValidityError: | 
|  | 426 | * @ctxt:  an XML parser context | 
|  | 427 | * @error:  the error number | 
|  | 428 | * @msg:  the error message | 
|  | 429 | * @str1:  extra data | 
|  | 430 | * | 
| Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 431 | * Handle a validity error. | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 432 | */ | 
|  | 433 | static void | 
|  | 434 | xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
|  | 435 | const char *msg, const xmlChar *str1) | 
|  | 436 | { | 
| Daniel Veillard | 9bcc7c5 | 2003-10-11 10:57:05 +0000 | [diff] [blame] | 437 | xmlStructuredErrorFunc schannel = NULL; | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 438 |  | 
|  | 439 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 440 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 441 | return; | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 442 | ctxt->errNo = error; | 
| Daniel Veillard | c790bf4 | 2003-10-11 10:50:10 +0000 | [diff] [blame] | 443 | if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) | 
| Daniel Veillard | 9bcc7c5 | 2003-10-11 10:57:05 +0000 | [diff] [blame] | 444 | schannel = ctxt->sax->serror; | 
| Daniel Veillard | c790bf4 | 2003-10-11 10:50:10 +0000 | [diff] [blame] | 445 | __xmlRaiseError(schannel, | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 446 | ctxt->vctxt.error, ctxt->vctxt.userData, | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 447 | ctxt, NULL, XML_FROM_DTD, error, | 
|  | 448 | XML_ERR_ERROR, NULL, 0, (const char *) str1, | 
|  | 449 | NULL, NULL, 0, 0, | 
|  | 450 | msg, (const char *) str1); | 
|  | 451 | ctxt->valid = 0; | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | /** | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 455 | * xmlFatalErrMsgInt: | 
|  | 456 | * @ctxt:  an XML parser context | 
|  | 457 | * @error:  the error number | 
|  | 458 | * @msg:  the error message | 
|  | 459 | * @val:  an integer value | 
|  | 460 | * | 
|  | 461 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints | 
|  | 462 | */ | 
|  | 463 | static void | 
|  | 464 | xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 465 | const char *msg, int val) | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 466 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 467 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 468 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 469 | return; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 470 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 471 | __xmlRaiseError(NULL, NULL, NULL, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 472 | ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, | 
|  | 473 | NULL, 0, NULL, NULL, NULL, val, 0, msg, val); | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 474 | ctxt->wellFormed = 0; | 
|  | 475 | if (ctxt->recovery == 0) | 
|  | 476 | ctxt->disableSAX = 1; | 
|  | 477 | } | 
|  | 478 |  | 
|  | 479 | /** | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 480 | * xmlFatalErrMsgStrIntStr: | 
|  | 481 | * @ctxt:  an XML parser context | 
|  | 482 | * @error:  the error number | 
|  | 483 | * @msg:  the error message | 
|  | 484 | * @str1:  an string info | 
|  | 485 | * @val:  an integer value | 
|  | 486 | * @str2:  an string info | 
|  | 487 | * | 
|  | 488 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints | 
|  | 489 | */ | 
|  | 490 | static void | 
|  | 491 | xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
|  | 492 | const char *msg, const xmlChar *str1, int val, | 
|  | 493 | const xmlChar *str2) | 
|  | 494 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 495 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 496 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 497 | return; | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 498 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 499 | __xmlRaiseError(NULL, NULL, NULL, | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 500 | ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, | 
|  | 501 | NULL, 0, (const char *) str1, (const char *) str2, | 
|  | 502 | NULL, val, 0, msg, str1, val, str2); | 
|  | 503 | ctxt->wellFormed = 0; | 
|  | 504 | if (ctxt->recovery == 0) | 
|  | 505 | ctxt->disableSAX = 1; | 
|  | 506 | } | 
|  | 507 |  | 
|  | 508 | /** | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 509 | * xmlFatalErrMsgStr: | 
|  | 510 | * @ctxt:  an XML parser context | 
|  | 511 | * @error:  the error number | 
|  | 512 | * @msg:  the error message | 
|  | 513 | * @val:  a string value | 
|  | 514 | * | 
|  | 515 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints | 
|  | 516 | */ | 
|  | 517 | static void | 
|  | 518 | xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 519 | const char *msg, const xmlChar * val) | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 520 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 521 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 522 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 523 | return; | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 524 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 525 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 526 | XML_FROM_PARSER, error, XML_ERR_FATAL, | 
|  | 527 | NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg, | 
|  | 528 | val); | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 529 | ctxt->wellFormed = 0; | 
|  | 530 | if (ctxt->recovery == 0) | 
|  | 531 | ctxt->disableSAX = 1; | 
|  | 532 | } | 
|  | 533 |  | 
|  | 534 | /** | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 535 | * xmlErrMsgStr: | 
|  | 536 | * @ctxt:  an XML parser context | 
|  | 537 | * @error:  the error number | 
|  | 538 | * @msg:  the error message | 
|  | 539 | * @val:  a string value | 
|  | 540 | * | 
|  | 541 | * Handle a non fatal parser error | 
|  | 542 | */ | 
|  | 543 | static void | 
|  | 544 | xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
|  | 545 | const char *msg, const xmlChar * val) | 
|  | 546 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 547 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 548 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 549 | return; | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 550 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 551 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 552 | XML_FROM_PARSER, error, XML_ERR_ERROR, | 
|  | 553 | NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg, | 
|  | 554 | val); | 
|  | 555 | } | 
|  | 556 |  | 
|  | 557 | /** | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 558 | * xmlNsErr: | 
|  | 559 | * @ctxt:  an XML parser context | 
|  | 560 | * @error:  the error number | 
|  | 561 | * @msg:  the message | 
|  | 562 | * @info1:  extra information string | 
|  | 563 | * @info2:  extra information string | 
|  | 564 | * | 
|  | 565 | * Handle a fatal parser error, i.e. violating Well-Formedness constraints | 
|  | 566 | */ | 
|  | 567 | static void | 
|  | 568 | xmlNsErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, | 
|  | 569 | const char *msg, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 570 | const xmlChar * info1, const xmlChar * info2, | 
|  | 571 | const xmlChar * info3) | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 572 | { | 
| Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 573 | if ((ctxt != NULL) && (ctxt->disableSAX != 0) && | 
|  | 574 | (ctxt->instate == XML_PARSER_EOF)) | 
|  | 575 | return; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 576 | ctxt->errNo = error; | 
| Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 577 | __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, | 
| Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 578 | XML_ERR_ERROR, NULL, 0, (const char *) info1, | 
|  | 579 | (const char *) info2, (const char *) info3, 0, 0, msg, | 
|  | 580 | info1, info2, info3); | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 581 | ctxt->nsWellFormed = 0; | 
|  | 582 | } | 
|  | 583 |  | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 584 | /************************************************************************ | 
|  | 585 | *									* | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 586 | * 		SAX2 defaulted attributes handling			* | 
|  | 587 | *									* | 
|  | 588 | ************************************************************************/ | 
|  | 589 |  | 
|  | 590 | /** | 
|  | 591 | * xmlDetectSAX2: | 
|  | 592 | * @ctxt:  an XML parser context | 
|  | 593 | * | 
|  | 594 | * Do the SAX2 detection and specific intialization | 
|  | 595 | */ | 
|  | 596 | static void | 
|  | 597 | xmlDetectSAX2(xmlParserCtxtPtr ctxt) { | 
|  | 598 | if (ctxt == NULL) return; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 599 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 600 | if ((ctxt->sax) &&  (ctxt->sax->initialized == XML_SAX2_MAGIC) && | 
|  | 601 | ((ctxt->sax->startElementNs != NULL) || | 
|  | 602 | (ctxt->sax->endElementNs != NULL))) ctxt->sax2 = 1; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 603 | #else | 
|  | 604 | ctxt->sax2 = 1; | 
|  | 605 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 606 |  | 
|  | 607 | ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3); | 
|  | 608 | ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5); | 
|  | 609 | ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36); | 
| William M. Brack | 9f797ab | 2004-07-28 07:40:12 +0000 | [diff] [blame] | 610 | if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) || | 
|  | 611 | (ctxt->str_xml_ns == NULL)) { | 
|  | 612 | xmlErrMemory(ctxt, NULL); | 
|  | 613 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 614 | } | 
|  | 615 |  | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 616 | typedef struct _xmlDefAttrs xmlDefAttrs; | 
|  | 617 | typedef xmlDefAttrs *xmlDefAttrsPtr; | 
|  | 618 | struct _xmlDefAttrs { | 
|  | 619 | int nbAttrs;	/* number of defaulted attributes on that element */ | 
|  | 620 | int maxAttrs;       /* the size of the array */ | 
|  | 621 | const xmlChar *values[4]; /* array of localname/prefix/values */ | 
|  | 622 | }; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 623 |  | 
|  | 624 | /** | 
|  | 625 | * xmlAddDefAttrs: | 
|  | 626 | * @ctxt:  an XML parser context | 
|  | 627 | * @fullname:  the element fullname | 
|  | 628 | * @fullattr:  the attribute fullname | 
|  | 629 | * @value:  the attribute value | 
|  | 630 | * | 
|  | 631 | * Add a defaulted attribute for an element | 
|  | 632 | */ | 
|  | 633 | static void | 
|  | 634 | xmlAddDefAttrs(xmlParserCtxtPtr ctxt, | 
|  | 635 | const xmlChar *fullname, | 
|  | 636 | const xmlChar *fullattr, | 
|  | 637 | const xmlChar *value) { | 
|  | 638 | xmlDefAttrsPtr defaults; | 
|  | 639 | int len; | 
|  | 640 | const xmlChar *name; | 
|  | 641 | const xmlChar *prefix; | 
|  | 642 |  | 
|  | 643 | if (ctxt->attsDefault == NULL) { | 
| Daniel Veillard | 316a5c3 | 2005-01-23 22:56:39 +0000 | [diff] [blame] | 644 | ctxt->attsDefault = xmlHashCreateDict(10, ctxt->dict); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 645 | if (ctxt->attsDefault == NULL) | 
|  | 646 | goto mem_error; | 
|  | 647 | } | 
|  | 648 |  | 
|  | 649 | /* | 
| Daniel Veillard | 079f6a7 | 2004-09-23 13:15:03 +0000 | [diff] [blame] | 650 | * split the element name into prefix:localname , the string found | 
|  | 651 | * are within the DTD and then not associated to namespace names. | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 652 | */ | 
|  | 653 | name = xmlSplitQName3(fullname, &len); | 
|  | 654 | if (name == NULL) { | 
|  | 655 | name = xmlDictLookup(ctxt->dict, fullname, -1); | 
|  | 656 | prefix = NULL; | 
|  | 657 | } else { | 
|  | 658 | name = xmlDictLookup(ctxt->dict, name, -1); | 
|  | 659 | prefix = xmlDictLookup(ctxt->dict, fullname, len); | 
|  | 660 | } | 
|  | 661 |  | 
|  | 662 | /* | 
|  | 663 | * make sure there is some storage | 
|  | 664 | */ | 
|  | 665 | defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix); | 
|  | 666 | if (defaults == NULL) { | 
|  | 667 | defaults = (xmlDefAttrsPtr) xmlMalloc(sizeof(xmlDefAttrs) + | 
| Daniel Veillard | 079f6a7 | 2004-09-23 13:15:03 +0000 | [diff] [blame] | 668 | (4 * 4) * sizeof(const xmlChar *)); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 669 | if (defaults == NULL) | 
|  | 670 | goto mem_error; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 671 | defaults->nbAttrs = 0; | 
| Daniel Veillard | 079f6a7 | 2004-09-23 13:15:03 +0000 | [diff] [blame] | 672 | defaults->maxAttrs = 4; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 673 | xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL); | 
|  | 674 | } else if (defaults->nbAttrs >= defaults->maxAttrs) { | 
| Daniel Veillard | 079f6a7 | 2004-09-23 13:15:03 +0000 | [diff] [blame] | 675 | xmlDefAttrsPtr temp; | 
|  | 676 |  | 
|  | 677 | temp = (xmlDefAttrsPtr) xmlRealloc(defaults, sizeof(xmlDefAttrs) + | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 678 | (2 * defaults->maxAttrs * 4) * sizeof(const xmlChar *)); | 
| Daniel Veillard | 079f6a7 | 2004-09-23 13:15:03 +0000 | [diff] [blame] | 679 | if (temp == NULL) | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 680 | goto mem_error; | 
| Daniel Veillard | 079f6a7 | 2004-09-23 13:15:03 +0000 | [diff] [blame] | 681 | defaults = temp; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 682 | defaults->maxAttrs *= 2; | 
|  | 683 | xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL); | 
|  | 684 | } | 
|  | 685 |  | 
|  | 686 | /* | 
|  | 687 | * plit the element name into prefix:localname , the string found | 
|  | 688 | * are within the DTD and hen not associated to namespace names. | 
|  | 689 | */ | 
|  | 690 | name = xmlSplitQName3(fullattr, &len); | 
|  | 691 | if (name == NULL) { | 
|  | 692 | name = xmlDictLookup(ctxt->dict, fullattr, -1); | 
|  | 693 | prefix = NULL; | 
|  | 694 | } else { | 
|  | 695 | name = xmlDictLookup(ctxt->dict, name, -1); | 
|  | 696 | prefix = xmlDictLookup(ctxt->dict, fullattr, len); | 
|  | 697 | } | 
|  | 698 |  | 
|  | 699 | defaults->values[4 * defaults->nbAttrs] = name; | 
|  | 700 | defaults->values[4 * defaults->nbAttrs + 1] = prefix; | 
|  | 701 | /* intern the string and precompute the end */ | 
|  | 702 | len = xmlStrlen(value); | 
|  | 703 | value = xmlDictLookup(ctxt->dict, value, len); | 
|  | 704 | defaults->values[4 * defaults->nbAttrs + 2] = value; | 
|  | 705 | defaults->values[4 * defaults->nbAttrs + 3] = value + len; | 
|  | 706 | defaults->nbAttrs++; | 
|  | 707 |  | 
|  | 708 | return; | 
|  | 709 |  | 
|  | 710 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 711 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 712 | return; | 
|  | 713 | } | 
|  | 714 |  | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 715 | /** | 
|  | 716 | * xmlAddSpecialAttr: | 
|  | 717 | * @ctxt:  an XML parser context | 
|  | 718 | * @fullname:  the element fullname | 
|  | 719 | * @fullattr:  the attribute fullname | 
|  | 720 | * @type:  the attribute type | 
|  | 721 | * | 
|  | 722 | * Register that this attribute is not CDATA | 
|  | 723 | */ | 
|  | 724 | static void | 
|  | 725 | xmlAddSpecialAttr(xmlParserCtxtPtr ctxt, | 
|  | 726 | const xmlChar *fullname, | 
|  | 727 | const xmlChar *fullattr, | 
|  | 728 | int type) | 
|  | 729 | { | 
|  | 730 | if (ctxt->attsSpecial == NULL) { | 
| Daniel Veillard | 316a5c3 | 2005-01-23 22:56:39 +0000 | [diff] [blame] | 731 | ctxt->attsSpecial = xmlHashCreateDict(10, ctxt->dict); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 732 | if (ctxt->attsSpecial == NULL) | 
|  | 733 | goto mem_error; | 
|  | 734 | } | 
|  | 735 |  | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 736 | xmlHashAddEntry2(ctxt->attsSpecial, fullname, fullattr, | 
|  | 737 | (void *) (long) type); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 738 | return; | 
|  | 739 |  | 
|  | 740 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 741 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 742 | return; | 
|  | 743 | } | 
|  | 744 |  | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 745 | /** | 
|  | 746 | * xmlCheckLanguageID: | 
|  | 747 | * @lang:  pointer to the string value | 
|  | 748 | * | 
|  | 749 | * Checks that the value conforms to the LanguageID production: | 
|  | 750 | * | 
|  | 751 | * NOTE: this is somewhat deprecated, those productions were removed from | 
|  | 752 | *       the XML Second edition. | 
|  | 753 | * | 
|  | 754 | * [33] LanguageID ::= Langcode ('-' Subcode)* | 
|  | 755 | * [34] Langcode ::= ISO639Code |  IanaCode |  UserCode | 
|  | 756 | * [35] ISO639Code ::= ([a-z] | [A-Z]) ([a-z] | [A-Z]) | 
|  | 757 | * [36] IanaCode ::= ('i' | 'I') '-' ([a-z] | [A-Z])+ | 
|  | 758 | * [37] UserCode ::= ('x' | 'X') '-' ([a-z] | [A-Z])+ | 
|  | 759 | * [38] Subcode ::= ([a-z] | [A-Z])+ | 
|  | 760 | * | 
|  | 761 | * Returns 1 if correct 0 otherwise | 
|  | 762 | **/ | 
|  | 763 | int | 
|  | 764 | xmlCheckLanguageID(const xmlChar * lang) | 
|  | 765 | { | 
|  | 766 | const xmlChar *cur = lang; | 
|  | 767 |  | 
|  | 768 | if (cur == NULL) | 
|  | 769 | return (0); | 
|  | 770 | if (((cur[0] == 'i') && (cur[1] == '-')) || | 
|  | 771 | ((cur[0] == 'I') && (cur[1] == '-'))) { | 
|  | 772 | /* | 
|  | 773 | * IANA code | 
|  | 774 | */ | 
|  | 775 | cur += 2; | 
|  | 776 | while (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||  /* non input consuming */ | 
|  | 777 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) | 
|  | 778 | cur++; | 
|  | 779 | } else if (((cur[0] == 'x') && (cur[1] == '-')) || | 
|  | 780 | ((cur[0] == 'X') && (cur[1] == '-'))) { | 
|  | 781 | /* | 
|  | 782 | * User code | 
|  | 783 | */ | 
|  | 784 | cur += 2; | 
|  | 785 | while (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||  /* non input consuming */ | 
|  | 786 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) | 
|  | 787 | cur++; | 
|  | 788 | } else if (((cur[0] >= 'A') && (cur[0] <= 'Z')) || | 
|  | 789 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) { | 
|  | 790 | /* | 
|  | 791 | * ISO639 | 
|  | 792 | */ | 
|  | 793 | cur++; | 
|  | 794 | if (((cur[0] >= 'A') && (cur[0] <= 'Z')) || | 
|  | 795 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) | 
|  | 796 | cur++; | 
|  | 797 | else | 
|  | 798 | return (0); | 
|  | 799 | } else | 
|  | 800 | return (0); | 
|  | 801 | while (cur[0] != 0) {       /* non input consuming */ | 
|  | 802 | if (cur[0] != '-') | 
|  | 803 | return (0); | 
|  | 804 | cur++; | 
|  | 805 | if (((cur[0] >= 'A') && (cur[0] <= 'Z')) || | 
|  | 806 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) | 
|  | 807 | cur++; | 
|  | 808 | else | 
|  | 809 | return (0); | 
|  | 810 | while (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||  /* non input consuming */ | 
|  | 811 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) | 
|  | 812 | cur++; | 
|  | 813 | } | 
|  | 814 | return (1); | 
|  | 815 | } | 
|  | 816 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 817 | /************************************************************************ | 
|  | 818 | *									* | 
|  | 819 | * 		Parser stacks related functions and macros		* | 
|  | 820 | *									* | 
|  | 821 | ************************************************************************/ | 
|  | 822 |  | 
|  | 823 | xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, | 
|  | 824 | const xmlChar ** str); | 
|  | 825 |  | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 826 | #ifdef SAX2 | 
|  | 827 | /** | 
|  | 828 | * nsPush: | 
|  | 829 | * @ctxt:  an XML parser context | 
|  | 830 | * @prefix:  the namespace prefix or NULL | 
|  | 831 | * @URL:  the namespace name | 
|  | 832 | * | 
|  | 833 | * Pushes a new parser namespace on top of the ns stack | 
|  | 834 | * | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 835 | * Returns -1 in case of error, -2 if the namespace should be discarded | 
|  | 836 | *	   and the index in the stack otherwise. | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 837 | */ | 
|  | 838 | static int | 
|  | 839 | nsPush(xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *URL) | 
|  | 840 | { | 
| Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 841 | if (ctxt->options & XML_PARSE_NSCLEAN) { | 
|  | 842 | int i; | 
|  | 843 | for (i = 0;i < ctxt->nsNr;i += 2) { | 
|  | 844 | if (ctxt->nsTab[i] == prefix) { | 
|  | 845 | /* in scope */ | 
|  | 846 | if (ctxt->nsTab[i + 1] == URL) | 
|  | 847 | return(-2); | 
|  | 848 | /* out of scope keep it */ | 
|  | 849 | break; | 
|  | 850 | } | 
|  | 851 | } | 
|  | 852 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 853 | if ((ctxt->nsMax == 0) || (ctxt->nsTab == NULL)) { | 
|  | 854 | ctxt->nsMax = 10; | 
|  | 855 | ctxt->nsNr = 0; | 
|  | 856 | ctxt->nsTab = (const xmlChar **) | 
|  | 857 | xmlMalloc(ctxt->nsMax * sizeof(xmlChar *)); | 
|  | 858 | if (ctxt->nsTab == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 859 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 860 | ctxt->nsMax = 0; | 
|  | 861 | return (-1); | 
|  | 862 | } | 
|  | 863 | } else if (ctxt->nsNr >= ctxt->nsMax) { | 
|  | 864 | ctxt->nsMax *= 2; | 
|  | 865 | ctxt->nsTab = (const xmlChar **) | 
| Daniel Veillard | 5bb9ccd | 2004-02-09 12:39:02 +0000 | [diff] [blame] | 866 | xmlRealloc((char *) ctxt->nsTab, | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 867 | ctxt->nsMax * sizeof(ctxt->nsTab[0])); | 
|  | 868 | if (ctxt->nsTab == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 869 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 870 | ctxt->nsMax /= 2; | 
|  | 871 | return (-1); | 
|  | 872 | } | 
|  | 873 | } | 
|  | 874 | ctxt->nsTab[ctxt->nsNr++] = prefix; | 
|  | 875 | ctxt->nsTab[ctxt->nsNr++] = URL; | 
|  | 876 | return (ctxt->nsNr); | 
|  | 877 | } | 
|  | 878 | /** | 
|  | 879 | * nsPop: | 
|  | 880 | * @ctxt: an XML parser context | 
|  | 881 | * @nr:  the number to pop | 
|  | 882 | * | 
|  | 883 | * Pops the top @nr parser prefix/namespace from the ns stack | 
|  | 884 | * | 
|  | 885 | * Returns the number of namespaces removed | 
|  | 886 | */ | 
|  | 887 | static int | 
|  | 888 | nsPop(xmlParserCtxtPtr ctxt, int nr) | 
|  | 889 | { | 
|  | 890 | int i; | 
|  | 891 |  | 
|  | 892 | if (ctxt->nsTab == NULL) return(0); | 
|  | 893 | if (ctxt->nsNr < nr) { | 
|  | 894 | xmlGenericError(xmlGenericErrorContext, "Pbm popping %d NS\n", nr); | 
|  | 895 | nr = ctxt->nsNr; | 
|  | 896 | } | 
|  | 897 | if (ctxt->nsNr <= 0) | 
|  | 898 | return (0); | 
|  | 899 |  | 
|  | 900 | for (i = 0;i < nr;i++) { | 
|  | 901 | ctxt->nsNr--; | 
|  | 902 | ctxt->nsTab[ctxt->nsNr] = NULL; | 
|  | 903 | } | 
|  | 904 | return(nr); | 
|  | 905 | } | 
|  | 906 | #endif | 
|  | 907 |  | 
|  | 908 | static int | 
|  | 909 | xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr) { | 
|  | 910 | const xmlChar **atts; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 911 | int *attallocs; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 912 | int maxatts; | 
|  | 913 |  | 
|  | 914 | if (ctxt->atts == NULL) { | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 915 | maxatts = 55; /* allow for 10 attrs by default */ | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 916 | atts = (const xmlChar **) | 
|  | 917 | xmlMalloc(maxatts * sizeof(xmlChar *)); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 918 | if (atts == NULL) goto mem_error; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 919 | ctxt->atts = atts; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 920 | attallocs = (int *) xmlMalloc((maxatts / 5) * sizeof(int)); | 
|  | 921 | if (attallocs == NULL) goto mem_error; | 
|  | 922 | ctxt->attallocs = attallocs; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 923 | ctxt->maxatts = maxatts; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 924 | } else if (nr + 5 > ctxt->maxatts) { | 
|  | 925 | maxatts = (nr + 5) * 2; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 926 | atts = (const xmlChar **) xmlRealloc((void *) ctxt->atts, | 
|  | 927 | maxatts * sizeof(const xmlChar *)); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 928 | if (atts == NULL) goto mem_error; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 929 | ctxt->atts = atts; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 930 | attallocs = (int *) xmlRealloc((void *) ctxt->attallocs, | 
|  | 931 | (maxatts / 5) * sizeof(int)); | 
|  | 932 | if (attallocs == NULL) goto mem_error; | 
|  | 933 | ctxt->attallocs = attallocs; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 934 | ctxt->maxatts = maxatts; | 
|  | 935 | } | 
|  | 936 | return(ctxt->maxatts); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 937 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 938 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 939 | return(-1); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 940 | } | 
|  | 941 |  | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 942 | /** | 
|  | 943 | * inputPush: | 
|  | 944 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 945 | * @value:  the parser input | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 946 | * | 
|  | 947 | * Pushes a new parser input on top of the input stack | 
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 948 | * | 
|  | 949 | * Returns 0 in case of error, the index in the stack otherwise | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 950 | */ | 
| Daniel Veillard | 7a5e0dd | 2004-09-17 08:45:25 +0000 | [diff] [blame] | 951 | int | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 952 | inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value) | 
|  | 953 | { | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 954 | if ((ctxt == NULL) || (value == NULL)) | 
|  | 955 | return(0); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 956 | if (ctxt->inputNr >= ctxt->inputMax) { | 
|  | 957 | ctxt->inputMax *= 2; | 
|  | 958 | ctxt->inputTab = | 
|  | 959 | (xmlParserInputPtr *) xmlRealloc(ctxt->inputTab, | 
|  | 960 | ctxt->inputMax * | 
|  | 961 | sizeof(ctxt->inputTab[0])); | 
|  | 962 | if (ctxt->inputTab == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 963 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 964 | return (0); | 
|  | 965 | } | 
|  | 966 | } | 
|  | 967 | ctxt->inputTab[ctxt->inputNr] = value; | 
|  | 968 | ctxt->input = value; | 
|  | 969 | return (ctxt->inputNr++); | 
|  | 970 | } | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 971 | /** | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 972 | * inputPop: | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 973 | * @ctxt: an XML parser context | 
|  | 974 | * | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 975 | * Pops the top parser input from the input stack | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 976 | * | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 977 | * Returns the input just removed | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 978 | */ | 
| Daniel Veillard | 7a5e0dd | 2004-09-17 08:45:25 +0000 | [diff] [blame] | 979 | xmlParserInputPtr | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 980 | inputPop(xmlParserCtxtPtr ctxt) | 
|  | 981 | { | 
|  | 982 | xmlParserInputPtr ret; | 
|  | 983 |  | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 984 | if (ctxt == NULL) | 
|  | 985 | return(NULL); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 986 | if (ctxt->inputNr <= 0) | 
|  | 987 | return (0); | 
|  | 988 | ctxt->inputNr--; | 
|  | 989 | if (ctxt->inputNr > 0) | 
|  | 990 | ctxt->input = ctxt->inputTab[ctxt->inputNr - 1]; | 
|  | 991 | else | 
|  | 992 | ctxt->input = NULL; | 
|  | 993 | ret = ctxt->inputTab[ctxt->inputNr]; | 
|  | 994 | ctxt->inputTab[ctxt->inputNr] = 0; | 
|  | 995 | return (ret); | 
|  | 996 | } | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 997 | /** | 
|  | 998 | * nodePush: | 
|  | 999 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 1000 | * @value:  the element node | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1001 | * | 
|  | 1002 | * Pushes a new element node on top of the node stack | 
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 1003 | * | 
|  | 1004 | * Returns 0 in case of error, the index in the stack otherwise | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 1005 | */ | 
| Daniel Veillard | 7a5e0dd | 2004-09-17 08:45:25 +0000 | [diff] [blame] | 1006 | int | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1007 | nodePush(xmlParserCtxtPtr ctxt, xmlNodePtr value) | 
|  | 1008 | { | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1009 | if (ctxt == NULL) return(0); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1010 | if (ctxt->nodeNr >= ctxt->nodeMax) { | 
| Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 1011 | xmlNodePtr *tmp; | 
|  | 1012 |  | 
|  | 1013 | tmp = (xmlNodePtr *) xmlRealloc(ctxt->nodeTab, | 
|  | 1014 | ctxt->nodeMax * 2 * | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1015 | sizeof(ctxt->nodeTab[0])); | 
| Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 1016 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1017 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1018 | return (0); | 
|  | 1019 | } | 
| Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 1020 | ctxt->nodeTab = tmp; | 
|  | 1021 | ctxt->nodeMax *= 2; | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1022 | } | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 1023 | if (((unsigned int) ctxt->nodeNr) > xmlParserMaxDepth) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 1024 | xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR, | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 1025 | "Excessive depth in document: change xmlParserMaxDepth = %d\n", | 
|  | 1026 | xmlParserMaxDepth); | 
| Daniel Veillard | 3b2e4e1 | 2003-02-03 08:52:58 +0000 | [diff] [blame] | 1027 | ctxt->instate = XML_PARSER_EOF; | 
| Daniel Veillard | 3b2e4e1 | 2003-02-03 08:52:58 +0000 | [diff] [blame] | 1028 | return(0); | 
|  | 1029 | } | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1030 | ctxt->nodeTab[ctxt->nodeNr] = value; | 
|  | 1031 | ctxt->node = value; | 
|  | 1032 | return (ctxt->nodeNr++); | 
|  | 1033 | } | 
|  | 1034 | /** | 
|  | 1035 | * nodePop: | 
|  | 1036 | * @ctxt: an XML parser context | 
|  | 1037 | * | 
|  | 1038 | * Pops the top element node from the node stack | 
|  | 1039 | * | 
|  | 1040 | * Returns the node just removed | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1041 | */ | 
| Daniel Veillard | 7a5e0dd | 2004-09-17 08:45:25 +0000 | [diff] [blame] | 1042 | xmlNodePtr | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1043 | nodePop(xmlParserCtxtPtr ctxt) | 
|  | 1044 | { | 
|  | 1045 | xmlNodePtr ret; | 
|  | 1046 |  | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1047 | if (ctxt == NULL) return(NULL); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1048 | if (ctxt->nodeNr <= 0) | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1049 | return (NULL); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1050 | ctxt->nodeNr--; | 
|  | 1051 | if (ctxt->nodeNr > 0) | 
|  | 1052 | ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1]; | 
|  | 1053 | else | 
|  | 1054 | ctxt->node = NULL; | 
|  | 1055 | ret = ctxt->nodeTab[ctxt->nodeNr]; | 
|  | 1056 | ctxt->nodeTab[ctxt->nodeNr] = 0; | 
|  | 1057 | return (ret); | 
|  | 1058 | } | 
| Daniel Veillard | a235132 | 2004-06-27 12:08:10 +0000 | [diff] [blame] | 1059 |  | 
|  | 1060 | #ifdef LIBXML_PUSH_ENABLED | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1061 | /** | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1062 | * nameNsPush: | 
|  | 1063 | * @ctxt:  an XML parser context | 
|  | 1064 | * @value:  the element name | 
|  | 1065 | * @prefix:  the element prefix | 
|  | 1066 | * @URI:  the element namespace name | 
|  | 1067 | * | 
|  | 1068 | * Pushes a new element name/prefix/URL on top of the name stack | 
|  | 1069 | * | 
|  | 1070 | * Returns -1 in case of error, the index in the stack otherwise | 
|  | 1071 | */ | 
|  | 1072 | static int | 
|  | 1073 | nameNsPush(xmlParserCtxtPtr ctxt, const xmlChar * value, | 
|  | 1074 | const xmlChar *prefix, const xmlChar *URI, int nsNr) | 
|  | 1075 | { | 
|  | 1076 | if (ctxt->nameNr >= ctxt->nameMax) { | 
|  | 1077 | const xmlChar * *tmp; | 
|  | 1078 | void **tmp2; | 
|  | 1079 | ctxt->nameMax *= 2; | 
|  | 1080 | tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab, | 
|  | 1081 | ctxt->nameMax * | 
|  | 1082 | sizeof(ctxt->nameTab[0])); | 
|  | 1083 | if (tmp == NULL) { | 
|  | 1084 | ctxt->nameMax /= 2; | 
|  | 1085 | goto mem_error; | 
|  | 1086 | } | 
|  | 1087 | ctxt->nameTab = tmp; | 
|  | 1088 | tmp2 = (void **) xmlRealloc((void * *)ctxt->pushTab, | 
|  | 1089 | ctxt->nameMax * 3 * | 
|  | 1090 | sizeof(ctxt->pushTab[0])); | 
|  | 1091 | if (tmp2 == NULL) { | 
|  | 1092 | ctxt->nameMax /= 2; | 
|  | 1093 | goto mem_error; | 
|  | 1094 | } | 
|  | 1095 | ctxt->pushTab = tmp2; | 
|  | 1096 | } | 
|  | 1097 | ctxt->nameTab[ctxt->nameNr] = value; | 
|  | 1098 | ctxt->name = value; | 
|  | 1099 | ctxt->pushTab[ctxt->nameNr * 3] = (void *) prefix; | 
|  | 1100 | ctxt->pushTab[ctxt->nameNr * 3 + 1] = (void *) URI; | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1101 | ctxt->pushTab[ctxt->nameNr * 3 + 2] = (void *) (long) nsNr; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1102 | return (ctxt->nameNr++); | 
|  | 1103 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1104 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1105 | return (-1); | 
|  | 1106 | } | 
|  | 1107 | /** | 
|  | 1108 | * nameNsPop: | 
|  | 1109 | * @ctxt: an XML parser context | 
|  | 1110 | * | 
|  | 1111 | * Pops the top element/prefix/URI name from the name stack | 
|  | 1112 | * | 
|  | 1113 | * Returns the name just removed | 
|  | 1114 | */ | 
|  | 1115 | static const xmlChar * | 
|  | 1116 | nameNsPop(xmlParserCtxtPtr ctxt) | 
|  | 1117 | { | 
|  | 1118 | const xmlChar *ret; | 
|  | 1119 |  | 
|  | 1120 | if (ctxt->nameNr <= 0) | 
|  | 1121 | return (0); | 
|  | 1122 | ctxt->nameNr--; | 
|  | 1123 | if (ctxt->nameNr > 0) | 
|  | 1124 | ctxt->name = ctxt->nameTab[ctxt->nameNr - 1]; | 
|  | 1125 | else | 
|  | 1126 | ctxt->name = NULL; | 
|  | 1127 | ret = ctxt->nameTab[ctxt->nameNr]; | 
|  | 1128 | ctxt->nameTab[ctxt->nameNr] = NULL; | 
|  | 1129 | return (ret); | 
|  | 1130 | } | 
| Daniel Veillard | a235132 | 2004-06-27 12:08:10 +0000 | [diff] [blame] | 1131 | #endif /* LIBXML_PUSH_ENABLED */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1132 |  | 
|  | 1133 | /** | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1134 | * namePush: | 
|  | 1135 | * @ctxt:  an XML parser context | 
|  | 1136 | * @value:  the element name | 
|  | 1137 | * | 
|  | 1138 | * Pushes a new element name on top of the name stack | 
|  | 1139 | * | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1140 | * Returns -1 in case of error, the index in the stack otherwise | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1141 | */ | 
| Daniel Veillard | 7a5e0dd | 2004-09-17 08:45:25 +0000 | [diff] [blame] | 1142 | int | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 1143 | namePush(xmlParserCtxtPtr ctxt, const xmlChar * value) | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1144 | { | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1145 | if (ctxt == NULL) return (-1); | 
|  | 1146 |  | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1147 | if (ctxt->nameNr >= ctxt->nameMax) { | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1148 | const xmlChar * *tmp; | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1149 | ctxt->nameMax *= 2; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1150 | tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab, | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1151 | ctxt->nameMax * | 
|  | 1152 | sizeof(ctxt->nameTab[0])); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1153 | if (tmp == NULL) { | 
|  | 1154 | ctxt->nameMax /= 2; | 
|  | 1155 | goto mem_error; | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1156 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1157 | ctxt->nameTab = tmp; | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1158 | } | 
|  | 1159 | ctxt->nameTab[ctxt->nameNr] = value; | 
|  | 1160 | ctxt->name = value; | 
|  | 1161 | return (ctxt->nameNr++); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1162 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1163 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1164 | return (-1); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1165 | } | 
|  | 1166 | /** | 
|  | 1167 | * namePop: | 
|  | 1168 | * @ctxt: an XML parser context | 
|  | 1169 | * | 
|  | 1170 | * Pops the top element name from the name stack | 
|  | 1171 | * | 
|  | 1172 | * Returns the name just removed | 
|  | 1173 | */ | 
| Daniel Veillard | 7a5e0dd | 2004-09-17 08:45:25 +0000 | [diff] [blame] | 1174 | const xmlChar * | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1175 | namePop(xmlParserCtxtPtr ctxt) | 
|  | 1176 | { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 1177 | const xmlChar *ret; | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1178 |  | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 1179 | if ((ctxt == NULL) || (ctxt->nameNr <= 0)) | 
|  | 1180 | return (NULL); | 
| Daniel Veillard | 1c732d2 | 2002-11-30 11:22:59 +0000 | [diff] [blame] | 1181 | ctxt->nameNr--; | 
|  | 1182 | if (ctxt->nameNr > 0) | 
|  | 1183 | ctxt->name = ctxt->nameTab[ctxt->nameNr - 1]; | 
|  | 1184 | else | 
|  | 1185 | ctxt->name = NULL; | 
|  | 1186 | ret = ctxt->nameTab[ctxt->nameNr]; | 
|  | 1187 | ctxt->nameTab[ctxt->nameNr] = 0; | 
|  | 1188 | return (ret); | 
|  | 1189 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1190 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 1191 | static int spacePush(xmlParserCtxtPtr ctxt, int val) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1192 | if (ctxt->spaceNr >= ctxt->spaceMax) { | 
|  | 1193 | ctxt->spaceMax *= 2; | 
|  | 1194 | ctxt->spaceTab = (int *) xmlRealloc(ctxt->spaceTab, | 
|  | 1195 | ctxt->spaceMax * sizeof(ctxt->spaceTab[0])); | 
|  | 1196 | if (ctxt->spaceTab == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1197 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1198 | return(0); | 
|  | 1199 | } | 
|  | 1200 | } | 
|  | 1201 | ctxt->spaceTab[ctxt->spaceNr] = val; | 
|  | 1202 | ctxt->space = &ctxt->spaceTab[ctxt->spaceNr]; | 
|  | 1203 | return(ctxt->spaceNr++); | 
|  | 1204 | } | 
|  | 1205 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 1206 | static int spacePop(xmlParserCtxtPtr ctxt) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1207 | int ret; | 
|  | 1208 | if (ctxt->spaceNr <= 0) return(0); | 
|  | 1209 | ctxt->spaceNr--; | 
|  | 1210 | if (ctxt->spaceNr > 0) | 
|  | 1211 | ctxt->space = &ctxt->spaceTab[ctxt->spaceNr - 1]; | 
|  | 1212 | else | 
|  | 1213 | ctxt->space = NULL; | 
|  | 1214 | ret = ctxt->spaceTab[ctxt->spaceNr]; | 
|  | 1215 | ctxt->spaceTab[ctxt->spaceNr] = -1; | 
|  | 1216 | return(ret); | 
|  | 1217 | } | 
|  | 1218 |  | 
|  | 1219 | /* | 
|  | 1220 | * Macros for accessing the content. Those should be used only by the parser, | 
|  | 1221 | * and not exported. | 
|  | 1222 | * | 
|  | 1223 | * Dirty macros, i.e. one often need to make assumption on the context to | 
|  | 1224 | * use them | 
|  | 1225 | * | 
|  | 1226 | *   CUR_PTR return the current pointer to the xmlChar to be parsed. | 
|  | 1227 | *           To be used with extreme caution since operations consuming | 
|  | 1228 | *           characters may move the input buffer to a different location ! | 
|  | 1229 | *   CUR     returns the current xmlChar value, i.e. a 8 bit value if compiled | 
|  | 1230 | *           This should be used internally by the parser | 
|  | 1231 | *           only to compare to ASCII values otherwise it would break when | 
|  | 1232 | *           running with UTF-8 encoding. | 
|  | 1233 | *   RAW     same as CUR but in the input buffer, bypass any token | 
|  | 1234 | *           extraction that may have been done | 
|  | 1235 | *   NXT(n)  returns the n'th next xmlChar. Same as CUR is should be used only | 
|  | 1236 | *           to compare on ASCII based substring. | 
|  | 1237 | *   SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 1238 | *           strings without newlines within the parser. | 
|  | 1239 | *   NEXT1(l) Skip 1 xmlChar, and must also be used only to skip 1 non-newline ASCII | 
|  | 1240 | *           defined char within the parser. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1241 | * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding | 
|  | 1242 | * | 
|  | 1243 | *   NEXT    Skip to the next character, this does the proper decoding | 
|  | 1244 | *           in UTF-8 mode. It also pop-up unfinished entities on the fly. | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 1245 | *   NEXTL(l) Skip the current unicode character of l xmlChars long. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1246 | *   CUR_CHAR(l) returns the current unicode character (int), set l | 
|  | 1247 | *           to the number of xmlChars used for the encoding [0-5]. | 
|  | 1248 | *   CUR_SCHAR  same but operate on a string instead of the context | 
|  | 1249 | *   COPY_BUF  copy the current unicode char to the target buffer, increment | 
|  | 1250 | *            the index | 
|  | 1251 | *   GROW, SHRINK  handling of input buffers | 
|  | 1252 | */ | 
|  | 1253 |  | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 1254 | #define RAW (*ctxt->input->cur) | 
|  | 1255 | #define CUR (*ctxt->input->cur) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1256 | #define NXT(val) ctxt->input->cur[(val)] | 
|  | 1257 | #define CUR_PTR ctxt->input->cur | 
|  | 1258 |  | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 1259 | #define CMP4( s, c1, c2, c3, c4 ) \ | 
|  | 1260 | ( ((unsigned char *) s)[ 0 ] == c1 && ((unsigned char *) s)[ 1 ] == c2 && \ | 
|  | 1261 | ((unsigned char *) s)[ 2 ] == c3 && ((unsigned char *) s)[ 3 ] == c4 ) | 
|  | 1262 | #define CMP5( s, c1, c2, c3, c4, c5 ) \ | 
|  | 1263 | ( CMP4( s, c1, c2, c3, c4 ) && ((unsigned char *) s)[ 4 ] == c5 ) | 
|  | 1264 | #define CMP6( s, c1, c2, c3, c4, c5, c6 ) \ | 
|  | 1265 | ( CMP5( s, c1, c2, c3, c4, c5 ) && ((unsigned char *) s)[ 5 ] == c6 ) | 
|  | 1266 | #define CMP7( s, c1, c2, c3, c4, c5, c6, c7 ) \ | 
|  | 1267 | ( CMP6( s, c1, c2, c3, c4, c5, c6 ) && ((unsigned char *) s)[ 6 ] == c7 ) | 
|  | 1268 | #define CMP8( s, c1, c2, c3, c4, c5, c6, c7, c8 ) \ | 
|  | 1269 | ( CMP7( s, c1, c2, c3, c4, c5, c6, c7 ) && ((unsigned char *) s)[ 7 ] == c8 ) | 
|  | 1270 | #define CMP9( s, c1, c2, c3, c4, c5, c6, c7, c8, c9 ) \ | 
|  | 1271 | ( CMP8( s, c1, c2, c3, c4, c5, c6, c7, c8 ) && \ | 
|  | 1272 | ((unsigned char *) s)[ 8 ] == c9 ) | 
|  | 1273 | #define CMP10( s, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 ) \ | 
|  | 1274 | ( CMP9( s, c1, c2, c3, c4, c5, c6, c7, c8, c9 ) && \ | 
|  | 1275 | ((unsigned char *) s)[ 9 ] == c10 ) | 
|  | 1276 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1277 | #define SKIP(val) do {							\ | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 1278 | ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val);			\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1279 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);	\ | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 1280 | if ((*ctxt->input->cur == 0) &&					\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1281 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))		\ | 
|  | 1282 | xmlPopInput(ctxt);						\ | 
|  | 1283 | } while (0) | 
|  | 1284 |  | 
| Daniel Veillard | 0b787f3 | 2004-03-26 17:29:53 +0000 | [diff] [blame] | 1285 | #define SKIPL(val) do {							\ | 
|  | 1286 | int skipl;								\ | 
|  | 1287 | for(skipl=0; skipl<val; skipl++) {					\ | 
|  | 1288 | if (*(ctxt->input->cur) == '\n') {				\ | 
|  | 1289 | ctxt->input->line++; ctxt->input->col = 1;			\ | 
|  | 1290 | } else ctxt->input->col++;					\ | 
|  | 1291 | ctxt->nbChars++;						\ | 
|  | 1292 | ctxt->input->cur++;						\ | 
|  | 1293 | }									\ | 
|  | 1294 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);	\ | 
|  | 1295 | if ((*ctxt->input->cur == 0) &&					\ | 
|  | 1296 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))		\ | 
|  | 1297 | xmlPopInput(ctxt);						\ | 
|  | 1298 | } while (0) | 
|  | 1299 |  | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1300 | #define SHRINK if ((ctxt->progressive == 0) &&				\ | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 1301 | (ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \ | 
|  | 1302 | (ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \ | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 1303 | xmlSHRINK (ctxt); | 
|  | 1304 |  | 
|  | 1305 | static void xmlSHRINK (xmlParserCtxtPtr ctxt) { | 
|  | 1306 | xmlParserInputShrink(ctxt->input); | 
|  | 1307 | if ((*ctxt->input->cur == 0) && | 
|  | 1308 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) | 
|  | 1309 | xmlPopInput(ctxt); | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1310 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1311 |  | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1312 | #define GROW if ((ctxt->progressive == 0) &&				\ | 
|  | 1313 | (ctxt->input->end - ctxt->input->cur < INPUT_CHUNK))	\ | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 1314 | xmlGROW (ctxt); | 
|  | 1315 |  | 
|  | 1316 | static void xmlGROW (xmlParserCtxtPtr ctxt) { | 
|  | 1317 | xmlParserInputGrow(ctxt->input, INPUT_CHUNK); | 
|  | 1318 | if ((*ctxt->input->cur == 0) && | 
|  | 1319 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) | 
|  | 1320 | xmlPopInput(ctxt); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1321 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1322 |  | 
|  | 1323 | #define SKIP_BLANKS xmlSkipBlankChars(ctxt) | 
|  | 1324 |  | 
|  | 1325 | #define NEXT xmlNextChar(ctxt) | 
|  | 1326 |  | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 1327 | #define NEXT1 {								\ | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 1328 | ctxt->input->col++;						\ | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 1329 | ctxt->input->cur++;						\ | 
|  | 1330 | ctxt->nbChars++;						\ | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 1331 | if (*ctxt->input->cur == 0)					\ | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 1332 | xmlParserInputGrow(ctxt->input, INPUT_CHUNK);		\ | 
|  | 1333 | } | 
|  | 1334 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1335 | #define NEXTL(l) do {							\ | 
|  | 1336 | if (*(ctxt->input->cur) == '\n') {					\ | 
|  | 1337 | ctxt->input->line++; ctxt->input->col = 1;			\ | 
|  | 1338 | } else ctxt->input->col++;						\ | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 1339 | ctxt->input->cur += l;				\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1340 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);	\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1341 | } while (0) | 
|  | 1342 |  | 
|  | 1343 | #define CUR_CHAR(l) xmlCurrentChar(ctxt, &l) | 
|  | 1344 | #define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l) | 
|  | 1345 |  | 
|  | 1346 | #define COPY_BUF(l,b,i,v)						\ | 
|  | 1347 | if (l == 1) b[i++] = (xmlChar) v;					\ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 1348 | else i += xmlCopyCharMultiByte(&b[i],v) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1349 |  | 
|  | 1350 | /** | 
|  | 1351 | * xmlSkipBlankChars: | 
|  | 1352 | * @ctxt:  the XML parser context | 
|  | 1353 | * | 
|  | 1354 | * skip all blanks character found at that point in the input streams. | 
|  | 1355 | * It pops up finished entities in the process if allowable at that point. | 
|  | 1356 | * | 
|  | 1357 | * Returns the number of space chars skipped | 
|  | 1358 | */ | 
|  | 1359 |  | 
|  | 1360 | int | 
|  | 1361 | xmlSkipBlankChars(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 02141ea | 2001-04-30 11:46:40 +0000 | [diff] [blame] | 1362 | int res = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1363 |  | 
|  | 1364 | /* | 
|  | 1365 | * It's Okay to use CUR/NEXT here since all the blanks are on | 
|  | 1366 | * the ASCII range. | 
|  | 1367 | */ | 
| Daniel Veillard | 02141ea | 2001-04-30 11:46:40 +0000 | [diff] [blame] | 1368 | if ((ctxt->inputNr == 1) && (ctxt->instate != XML_PARSER_DTD)) { | 
|  | 1369 | const xmlChar *cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1370 | /* | 
| Daniel Veillard | 02141ea | 2001-04-30 11:46:40 +0000 | [diff] [blame] | 1371 | * if we are in the document content, go really fast | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1372 | */ | 
| Daniel Veillard | 02141ea | 2001-04-30 11:46:40 +0000 | [diff] [blame] | 1373 | cur = ctxt->input->cur; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1374 | while (IS_BLANK_CH(*cur)) { | 
| Daniel Veillard | 02141ea | 2001-04-30 11:46:40 +0000 | [diff] [blame] | 1375 | if (*cur == '\n') { | 
|  | 1376 | ctxt->input->line++; ctxt->input->col = 1; | 
|  | 1377 | } | 
|  | 1378 | cur++; | 
|  | 1379 | res++; | 
|  | 1380 | if (*cur == 0) { | 
|  | 1381 | ctxt->input->cur = cur; | 
|  | 1382 | xmlParserInputGrow(ctxt->input, INPUT_CHUNK); | 
|  | 1383 | cur = ctxt->input->cur; | 
|  | 1384 | } | 
|  | 1385 | } | 
|  | 1386 | ctxt->input->cur = cur; | 
|  | 1387 | } else { | 
|  | 1388 | int cur; | 
|  | 1389 | do { | 
|  | 1390 | cur = CUR; | 
| Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 1391 | while (IS_BLANK_CH(cur)) { /* CHECKED tstblanks.xml */ | 
| Daniel Veillard | 02141ea | 2001-04-30 11:46:40 +0000 | [diff] [blame] | 1392 | NEXT; | 
|  | 1393 | cur = CUR; | 
|  | 1394 | res++; | 
|  | 1395 | } | 
|  | 1396 | while ((cur == 0) && (ctxt->inputNr > 1) && | 
|  | 1397 | (ctxt->instate != XML_PARSER_COMMENT)) { | 
|  | 1398 | xmlPopInput(ctxt); | 
|  | 1399 | cur = CUR; | 
|  | 1400 | } | 
|  | 1401 | /* | 
|  | 1402 | * Need to handle support of entities branching here | 
|  | 1403 | */ | 
|  | 1404 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); | 
|  | 1405 | } while (IS_BLANK(cur)); /* CHECKED tstblanks.xml */ | 
|  | 1406 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1407 | return(res); | 
|  | 1408 | } | 
|  | 1409 |  | 
|  | 1410 | /************************************************************************ | 
|  | 1411 | *									* | 
|  | 1412 | *		Commodity functions to handle entities			* | 
|  | 1413 | *									* | 
|  | 1414 | ************************************************************************/ | 
|  | 1415 |  | 
|  | 1416 | /** | 
|  | 1417 | * xmlPopInput: | 
|  | 1418 | * @ctxt:  an XML parser context | 
|  | 1419 | * | 
|  | 1420 | * xmlPopInput: the current input pointed by ctxt->input came to an end | 
|  | 1421 | *          pop it and return the next char. | 
|  | 1422 | * | 
|  | 1423 | * Returns the current xmlChar in the parser context | 
|  | 1424 | */ | 
|  | 1425 | xmlChar | 
|  | 1426 | xmlPopInput(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 1427 | if ((ctxt == NULL) || (ctxt->inputNr <= 1)) return(0); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1428 | if (xmlParserDebugEntities) | 
|  | 1429 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1430 | "Popping input %d\n", ctxt->inputNr); | 
|  | 1431 | xmlFreeInputStream(inputPop(ctxt)); | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 1432 | if ((*ctxt->input->cur == 0) && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1433 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) | 
|  | 1434 | return(xmlPopInput(ctxt)); | 
|  | 1435 | return(CUR); | 
|  | 1436 | } | 
|  | 1437 |  | 
|  | 1438 | /** | 
|  | 1439 | * xmlPushInput: | 
|  | 1440 | * @ctxt:  an XML parser context | 
|  | 1441 | * @input:  an XML parser input fragment (entity, XML fragment ...). | 
|  | 1442 | * | 
|  | 1443 | * xmlPushInput: switch to a new input stream which is stacked on top | 
|  | 1444 | *               of the previous one(s). | 
|  | 1445 | */ | 
|  | 1446 | void | 
|  | 1447 | xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) { | 
|  | 1448 | if (input == NULL) return; | 
|  | 1449 |  | 
|  | 1450 | if (xmlParserDebugEntities) { | 
|  | 1451 | if ((ctxt->input != NULL) && (ctxt->input->filename)) | 
|  | 1452 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1453 | "%s(%d): ", ctxt->input->filename, | 
|  | 1454 | ctxt->input->line); | 
|  | 1455 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1456 | "Pushing input %d : %.30s\n", ctxt->inputNr+1, input->cur); | 
|  | 1457 | } | 
|  | 1458 | inputPush(ctxt, input); | 
|  | 1459 | GROW; | 
|  | 1460 | } | 
|  | 1461 |  | 
|  | 1462 | /** | 
|  | 1463 | * xmlParseCharRef: | 
|  | 1464 | * @ctxt:  an XML parser context | 
|  | 1465 | * | 
|  | 1466 | * parse Reference declarations | 
|  | 1467 | * | 
|  | 1468 | * [66] CharRef ::= '&#' [0-9]+ ';' | | 
|  | 1469 | *                  '&#x' [0-9a-fA-F]+ ';' | 
|  | 1470 | * | 
|  | 1471 | * [ WFC: Legal Character ] | 
|  | 1472 | * Characters referred to using character references must match the | 
|  | 1473 | * production for Char. | 
|  | 1474 | * | 
|  | 1475 | * Returns the value parsed (as an int), 0 in case of error | 
|  | 1476 | */ | 
|  | 1477 | int | 
|  | 1478 | xmlParseCharRef(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 5058211 | 2001-03-26 22:52:16 +0000 | [diff] [blame] | 1479 | unsigned int val = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1480 | int count = 0; | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1481 | unsigned int outofrange = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1482 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1483 | /* | 
|  | 1484 | * Using RAW/CUR/NEXT is okay since we are working on ASCII range here | 
|  | 1485 | */ | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 1486 | if ((RAW == '&') && (NXT(1) == '#') && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1487 | (NXT(2) == 'x')) { | 
|  | 1488 | SKIP(3); | 
|  | 1489 | GROW; | 
|  | 1490 | while (RAW != ';') { /* loop blocked by count */ | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 1491 | if (count++ > 20) { | 
|  | 1492 | count = 0; | 
|  | 1493 | GROW; | 
|  | 1494 | } | 
|  | 1495 | if ((RAW >= '0') && (RAW <= '9')) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1496 | val = val * 16 + (CUR - '0'); | 
|  | 1497 | else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20)) | 
|  | 1498 | val = val * 16 + (CUR - 'a') + 10; | 
|  | 1499 | else if ((RAW >= 'A') && (RAW <= 'F') && (count < 20)) | 
|  | 1500 | val = val * 16 + (CUR - 'A') + 10; | 
|  | 1501 | else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1502 | xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1503 | val = 0; | 
|  | 1504 | break; | 
|  | 1505 | } | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1506 | if (val > 0x10FFFF) | 
|  | 1507 | outofrange = val; | 
|  | 1508 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1509 | NEXT; | 
|  | 1510 | count++; | 
|  | 1511 | } | 
|  | 1512 | if (RAW == ';') { | 
|  | 1513 | /* on purpose to avoid reentrancy problems with NEXT and SKIP */ | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 1514 | ctxt->input->col++; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1515 | ctxt->nbChars ++; | 
|  | 1516 | ctxt->input->cur++; | 
|  | 1517 | } | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 1518 | } else if  ((RAW == '&') && (NXT(1) == '#')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1519 | SKIP(2); | 
|  | 1520 | GROW; | 
|  | 1521 | while (RAW != ';') { /* loop blocked by count */ | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 1522 | if (count++ > 20) { | 
|  | 1523 | count = 0; | 
|  | 1524 | GROW; | 
|  | 1525 | } | 
|  | 1526 | if ((RAW >= '0') && (RAW <= '9')) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1527 | val = val * 10 + (CUR - '0'); | 
|  | 1528 | else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1529 | xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1530 | val = 0; | 
|  | 1531 | break; | 
|  | 1532 | } | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1533 | if (val > 0x10FFFF) | 
|  | 1534 | outofrange = val; | 
|  | 1535 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1536 | NEXT; | 
|  | 1537 | count++; | 
|  | 1538 | } | 
|  | 1539 | if (RAW == ';') { | 
|  | 1540 | /* on purpose to avoid reentrancy problems with NEXT and SKIP */ | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 1541 | ctxt->input->col++; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1542 | ctxt->nbChars ++; | 
|  | 1543 | ctxt->input->cur++; | 
|  | 1544 | } | 
|  | 1545 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1546 | xmlFatalErr(ctxt, XML_ERR_INVALID_CHARREF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1547 | } | 
|  | 1548 |  | 
|  | 1549 | /* | 
|  | 1550 | * [ WFC: Legal Character ] | 
|  | 1551 | * Characters referred to using character references must match the | 
|  | 1552 | * production for Char. | 
|  | 1553 | */ | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1554 | if ((IS_CHAR(val) && (outofrange == 0))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1555 | return(val); | 
|  | 1556 | } else { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 1557 | xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, | 
|  | 1558 | "xmlParseCharRef: invalid xmlChar value %d\n", | 
|  | 1559 | val); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1560 | } | 
|  | 1561 | return(0); | 
|  | 1562 | } | 
|  | 1563 |  | 
|  | 1564 | /** | 
|  | 1565 | * xmlParseStringCharRef: | 
|  | 1566 | * @ctxt:  an XML parser context | 
|  | 1567 | * @str:  a pointer to an index in the string | 
|  | 1568 | * | 
|  | 1569 | * parse Reference declarations, variant parsing from a string rather | 
|  | 1570 | * than an an input flow. | 
|  | 1571 | * | 
|  | 1572 | * [66] CharRef ::= '&#' [0-9]+ ';' | | 
|  | 1573 | *                  '&#x' [0-9a-fA-F]+ ';' | 
|  | 1574 | * | 
|  | 1575 | * [ WFC: Legal Character ] | 
|  | 1576 | * Characters referred to using character references must match the | 
|  | 1577 | * production for Char. | 
|  | 1578 | * | 
|  | 1579 | * Returns the value parsed (as an int), 0 in case of error, str will be | 
|  | 1580 | *         updated to the current value of the index | 
|  | 1581 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 1582 | static int | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1583 | xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str) { | 
|  | 1584 | const xmlChar *ptr; | 
|  | 1585 | xmlChar cur; | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1586 | unsigned int val = 0; | 
|  | 1587 | unsigned int outofrange = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1588 |  | 
|  | 1589 | if ((str == NULL) || (*str == NULL)) return(0); | 
|  | 1590 | ptr = *str; | 
|  | 1591 | cur = *ptr; | 
|  | 1592 | if ((cur == '&') && (ptr[1] == '#') && (ptr[2] == 'x')) { | 
|  | 1593 | ptr += 3; | 
|  | 1594 | cur = *ptr; | 
|  | 1595 | while (cur != ';') { /* Non input consuming loop */ | 
|  | 1596 | if ((cur >= '0') && (cur <= '9')) | 
|  | 1597 | val = val * 16 + (cur - '0'); | 
|  | 1598 | else if ((cur >= 'a') && (cur <= 'f')) | 
|  | 1599 | val = val * 16 + (cur - 'a') + 10; | 
|  | 1600 | else if ((cur >= 'A') && (cur <= 'F')) | 
|  | 1601 | val = val * 16 + (cur - 'A') + 10; | 
|  | 1602 | else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1603 | xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1604 | val = 0; | 
|  | 1605 | break; | 
|  | 1606 | } | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1607 | if (val > 0x10FFFF) | 
|  | 1608 | outofrange = val; | 
|  | 1609 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1610 | ptr++; | 
|  | 1611 | cur = *ptr; | 
|  | 1612 | } | 
|  | 1613 | if (cur == ';') | 
|  | 1614 | ptr++; | 
|  | 1615 | } else if  ((cur == '&') && (ptr[1] == '#')){ | 
|  | 1616 | ptr += 2; | 
|  | 1617 | cur = *ptr; | 
|  | 1618 | while (cur != ';') { /* Non input consuming loops */ | 
|  | 1619 | if ((cur >= '0') && (cur <= '9')) | 
|  | 1620 | val = val * 10 + (cur - '0'); | 
|  | 1621 | else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1622 | xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1623 | val = 0; | 
|  | 1624 | break; | 
|  | 1625 | } | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1626 | if (val > 0x10FFFF) | 
|  | 1627 | outofrange = val; | 
|  | 1628 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1629 | ptr++; | 
|  | 1630 | cur = *ptr; | 
|  | 1631 | } | 
|  | 1632 | if (cur == ';') | 
|  | 1633 | ptr++; | 
|  | 1634 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1635 | xmlFatalErr(ctxt, XML_ERR_INVALID_CHARREF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1636 | return(0); | 
|  | 1637 | } | 
|  | 1638 | *str = ptr; | 
|  | 1639 |  | 
|  | 1640 | /* | 
|  | 1641 | * [ WFC: Legal Character ] | 
|  | 1642 | * Characters referred to using character references must match the | 
|  | 1643 | * production for Char. | 
|  | 1644 | */ | 
| Daniel Veillard | 37fd307 | 2004-06-03 11:22:31 +0000 | [diff] [blame] | 1645 | if ((IS_CHAR(val) && (outofrange == 0))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1646 | return(val); | 
|  | 1647 | } else { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 1648 | xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, | 
|  | 1649 | "xmlParseStringCharRef: invalid xmlChar value %d\n", | 
|  | 1650 | val); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1651 | } | 
|  | 1652 | return(0); | 
|  | 1653 | } | 
|  | 1654 |  | 
|  | 1655 | /** | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1656 | * xmlNewBlanksWrapperInputStream: | 
|  | 1657 | * @ctxt:  an XML parser context | 
|  | 1658 | * @entity:  an Entity pointer | 
|  | 1659 | * | 
|  | 1660 | * Create a new input stream for wrapping | 
|  | 1661 | * blanks around a PEReference | 
|  | 1662 | * | 
|  | 1663 | * Returns the new input stream or NULL | 
|  | 1664 | */ | 
|  | 1665 |  | 
|  | 1666 | static void deallocblankswrapper (xmlChar *str) {xmlFree(str);} | 
|  | 1667 |  | 
| Daniel Veillard | f4862f0 | 2002-09-10 11:13:43 +0000 | [diff] [blame] | 1668 | static xmlParserInputPtr | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1669 | xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { | 
|  | 1670 | xmlParserInputPtr input; | 
|  | 1671 | xmlChar *buffer; | 
|  | 1672 | size_t length; | 
|  | 1673 | if (entity == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1674 | xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 1675 | "xmlNewBlanksWrapperInputStream entity\n"); | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1676 | return(NULL); | 
|  | 1677 | } | 
|  | 1678 | if (xmlParserDebugEntities) | 
|  | 1679 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1680 | "new blanks wrapper for entity: %s\n", entity->name); | 
|  | 1681 | input = xmlNewInputStream(ctxt); | 
|  | 1682 | if (input == NULL) { | 
|  | 1683 | return(NULL); | 
|  | 1684 | } | 
|  | 1685 | length = xmlStrlen(entity->name) + 5; | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 1686 | buffer = xmlMallocAtomic(length); | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1687 | if (buffer == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1688 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1689 | return(NULL); | 
|  | 1690 | } | 
|  | 1691 | buffer [0] = ' '; | 
|  | 1692 | buffer [1] = '%'; | 
|  | 1693 | buffer [length-3] = ';'; | 
|  | 1694 | buffer [length-2] = ' '; | 
|  | 1695 | buffer [length-1] = 0; | 
|  | 1696 | memcpy(buffer + 2, entity->name, length - 5); | 
|  | 1697 | input->free = deallocblankswrapper; | 
|  | 1698 | input->base = buffer; | 
|  | 1699 | input->cur = buffer; | 
|  | 1700 | input->length = length; | 
|  | 1701 | input->end = &buffer[length]; | 
|  | 1702 | return(input); | 
|  | 1703 | } | 
|  | 1704 |  | 
|  | 1705 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1706 | * xmlParserHandlePEReference: | 
|  | 1707 | * @ctxt:  the parser context | 
|  | 1708 | * | 
|  | 1709 | * [69] PEReference ::= '%' Name ';' | 
|  | 1710 | * | 
|  | 1711 | * [ WFC: No Recursion ] | 
|  | 1712 | * A parsed entity must not contain a recursive | 
|  | 1713 | * reference to itself, either directly or indirectly. | 
|  | 1714 | * | 
|  | 1715 | * [ WFC: Entity Declared ] | 
|  | 1716 | * In a document without any DTD, a document with only an internal DTD | 
|  | 1717 | * subset which contains no parameter entity references, or a document | 
|  | 1718 | * with "standalone='yes'", ...  ... The declaration of a parameter | 
|  | 1719 | * entity must precede any reference to it... | 
|  | 1720 | * | 
|  | 1721 | * [ VC: Entity Declared ] | 
|  | 1722 | * In a document with an external subset or external parameter entities | 
|  | 1723 | * with "standalone='no'", ...  ... The declaration of a parameter entity | 
|  | 1724 | * must precede any reference to it... | 
|  | 1725 | * | 
|  | 1726 | * [ WFC: In DTD ] | 
|  | 1727 | * Parameter-entity references may only appear in the DTD. | 
|  | 1728 | * NOTE: misleading but this is handled. | 
|  | 1729 | * | 
|  | 1730 | * A PEReference may have been detected in the current input stream | 
|  | 1731 | * the handling is done accordingly to | 
|  | 1732 | *      http://www.w3.org/TR/REC-xml#entproc | 
|  | 1733 | * i.e. | 
|  | 1734 | *   - Included in literal in entity values | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1735 | *   - Included as Parameter Entity reference within DTDs | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1736 | */ | 
|  | 1737 | void | 
|  | 1738 | xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 1739 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1740 | xmlEntityPtr entity = NULL; | 
|  | 1741 | xmlParserInputPtr input; | 
|  | 1742 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1743 | if (RAW != '%') return; | 
|  | 1744 | switch(ctxt->instate) { | 
|  | 1745 | case XML_PARSER_CDATA_SECTION: | 
|  | 1746 | return; | 
|  | 1747 | case XML_PARSER_COMMENT: | 
|  | 1748 | return; | 
|  | 1749 | case XML_PARSER_START_TAG: | 
|  | 1750 | return; | 
|  | 1751 | case XML_PARSER_END_TAG: | 
|  | 1752 | return; | 
|  | 1753 | case XML_PARSER_EOF: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1754 | xmlFatalErr(ctxt, XML_ERR_PEREF_AT_EOF, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1755 | return; | 
|  | 1756 | case XML_PARSER_PROLOG: | 
|  | 1757 | case XML_PARSER_START: | 
|  | 1758 | case XML_PARSER_MISC: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1759 | xmlFatalErr(ctxt, XML_ERR_PEREF_IN_PROLOG, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1760 | return; | 
|  | 1761 | case XML_PARSER_ENTITY_DECL: | 
|  | 1762 | case XML_PARSER_CONTENT: | 
|  | 1763 | case XML_PARSER_ATTRIBUTE_VALUE: | 
|  | 1764 | case XML_PARSER_PI: | 
|  | 1765 | case XML_PARSER_SYSTEM_LITERAL: | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 1766 | case XML_PARSER_PUBLIC_LITERAL: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1767 | /* we just ignore it there */ | 
|  | 1768 | return; | 
|  | 1769 | case XML_PARSER_EPILOG: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1770 | xmlFatalErr(ctxt, XML_ERR_PEREF_IN_EPILOG, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1771 | return; | 
|  | 1772 | case XML_PARSER_ENTITY_VALUE: | 
|  | 1773 | /* | 
|  | 1774 | * NOTE: in the case of entity values, we don't do the | 
|  | 1775 | *       substitution here since we need the literal | 
|  | 1776 | *       entity value to be able to save the internal | 
|  | 1777 | *       subset of the document. | 
|  | 1778 | *       This will be handled by xmlStringDecodeEntities | 
|  | 1779 | */ | 
|  | 1780 | return; | 
|  | 1781 | case XML_PARSER_DTD: | 
|  | 1782 | /* | 
|  | 1783 | * [WFC: Well-Formedness Constraint: PEs in Internal Subset] | 
|  | 1784 | * In the internal DTD subset, parameter-entity references | 
|  | 1785 | * can occur only where markup declarations can occur, not | 
|  | 1786 | * within markup declarations. | 
|  | 1787 | * In that case this is handled in xmlParseMarkupDecl | 
|  | 1788 | */ | 
|  | 1789 | if ((ctxt->external == 0) && (ctxt->inputNr == 1)) | 
|  | 1790 | return; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1791 | if (IS_BLANK_CH(NXT(1)) || NXT(1) == 0) | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1792 | return; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1793 | break; | 
|  | 1794 | case XML_PARSER_IGNORE: | 
|  | 1795 | return; | 
|  | 1796 | } | 
|  | 1797 |  | 
|  | 1798 | NEXT; | 
|  | 1799 | name = xmlParseName(ctxt); | 
|  | 1800 | if (xmlParserDebugEntities) | 
|  | 1801 | xmlGenericError(xmlGenericErrorContext, | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1802 | "PEReference: %s\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1803 | if (name == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1804 | xmlFatalErr(ctxt, XML_ERR_PEREF_NO_NAME, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1805 | } else { | 
|  | 1806 | if (RAW == ';') { | 
|  | 1807 | NEXT; | 
|  | 1808 | if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL)) | 
|  | 1809 | entity = ctxt->sax->getParameterEntity(ctxt->userData, name); | 
|  | 1810 | if (entity == NULL) { | 
|  | 1811 |  | 
|  | 1812 | /* | 
|  | 1813 | * [ WFC: Entity Declared ] | 
|  | 1814 | * In a document without any DTD, a document with only an | 
|  | 1815 | * internal DTD subset which contains no parameter entity | 
|  | 1816 | * references, or a document with "standalone='yes'", ... | 
|  | 1817 | * ... The declaration of a parameter entity must precede | 
|  | 1818 | * any reference to it... | 
|  | 1819 | */ | 
|  | 1820 | if ((ctxt->standalone == 1) || | 
|  | 1821 | ((ctxt->hasExternalSubset == 0) && | 
|  | 1822 | (ctxt->hasPErefs == 0))) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 1823 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1824 | "PEReference: %%%s; not found\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1825 | } else { | 
|  | 1826 | /* | 
|  | 1827 | * [ VC: Entity Declared ] | 
|  | 1828 | * In a document with an external subset or external | 
|  | 1829 | * parameter entities with "standalone='no'", ... | 
|  | 1830 | * ... The declaration of a parameter entity must precede | 
|  | 1831 | * any reference to it... | 
|  | 1832 | */ | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 1833 | if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) { | 
|  | 1834 | xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
|  | 1835 | "PEReference: %%%s; not found\n", | 
|  | 1836 | name); | 
|  | 1837 | } else | 
|  | 1838 | xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
|  | 1839 | "PEReference: %%%s; not found\n", | 
|  | 1840 | name, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1841 | ctxt->valid = 0; | 
|  | 1842 | } | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 1843 | } else if (ctxt->input->free != deallocblankswrapper) { | 
|  | 1844 | input = xmlNewBlanksWrapperInputStream(ctxt, entity); | 
|  | 1845 | xmlPushInput(ctxt, input); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1846 | } else { | 
|  | 1847 | if ((entity->etype == XML_INTERNAL_PARAMETER_ENTITY) || | 
|  | 1848 | (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY)) { | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 1849 | xmlChar start[4]; | 
|  | 1850 | xmlCharEncoding enc; | 
|  | 1851 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1852 | /* | 
|  | 1853 | * handle the extra spaces added before and after | 
|  | 1854 | * c.f. http://www.w3.org/TR/REC-xml#as-PE | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1855 | * this is done independently. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1856 | */ | 
|  | 1857 | input = xmlNewEntityInputStream(ctxt, entity); | 
|  | 1858 | xmlPushInput(ctxt, input); | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 1859 |  | 
|  | 1860 | /* | 
|  | 1861 | * Get the 4 first bytes and decode the charset | 
|  | 1862 | * if enc != XML_CHAR_ENCODING_NONE | 
|  | 1863 | * plug some encoding conversion routines. | 
| William M. Brack | a0c48ad | 2004-04-16 15:58:29 +0000 | [diff] [blame] | 1864 | * Note that, since we may have some non-UTF8 | 
|  | 1865 | * encoding (like UTF16, bug 135229), the 'length' | 
|  | 1866 | * is not known, but we can calculate based upon | 
|  | 1867 | * the amount of data in the buffer. | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 1868 | */ | 
|  | 1869 | GROW | 
| William M. Brack | a0c48ad | 2004-04-16 15:58:29 +0000 | [diff] [blame] | 1870 | if ((ctxt->input->end - ctxt->input->cur)>=4) { | 
| Daniel Veillard | e059b89 | 2002-06-13 15:32:10 +0000 | [diff] [blame] | 1871 | start[0] = RAW; | 
|  | 1872 | start[1] = NXT(1); | 
|  | 1873 | start[2] = NXT(2); | 
|  | 1874 | start[3] = NXT(3); | 
|  | 1875 | enc = xmlDetectCharEncoding(start, 4); | 
|  | 1876 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 1877 | xmlSwitchEncoding(ctxt, enc); | 
|  | 1878 | } | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 1879 | } | 
|  | 1880 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1881 | if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 1882 | (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l' )) && | 
|  | 1883 | (IS_BLANK_CH(NXT(5)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1884 | xmlParseTextDecl(ctxt); | 
|  | 1885 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1886 | } else { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 1887 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER, | 
|  | 1888 | "PEReference: %s is not a parameter entity\n", | 
|  | 1889 | name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1890 | } | 
|  | 1891 | } | 
|  | 1892 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1893 | xmlFatalErr(ctxt, XML_ERR_PEREF_SEMICOL_MISSING, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1894 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1895 | } | 
|  | 1896 | } | 
|  | 1897 |  | 
|  | 1898 | /* | 
|  | 1899 | * Macro used to grow the current buffer. | 
|  | 1900 | */ | 
|  | 1901 | #define growBuffer(buffer) {						\ | 
| Daniel Veillard | d3999c7 | 2004-03-10 16:27:03 +0000 | [diff] [blame] | 1902 | xmlChar *tmp;							\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1903 | buffer##_size *= 2;							\ | 
| Daniel Veillard | d3999c7 | 2004-03-10 16:27:03 +0000 | [diff] [blame] | 1904 | tmp = (xmlChar *)							\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1905 | xmlRealloc(buffer, buffer##_size * sizeof(xmlChar));	\ | 
| Daniel Veillard | d3999c7 | 2004-03-10 16:27:03 +0000 | [diff] [blame] | 1906 | if (tmp == NULL) goto mem_error;					\ | 
|  | 1907 | buffer = tmp;							\ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1908 | } | 
|  | 1909 |  | 
|  | 1910 | /** | 
| Daniel Veillard | 7a02cfe | 2003-09-25 12:18:34 +0000 | [diff] [blame] | 1911 | * xmlStringLenDecodeEntities: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1912 | * @ctxt:  the parser context | 
|  | 1913 | * @str:  the input string | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1914 | * @len: the string length | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1915 | * @what:  combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF | 
|  | 1916 | * @end:  an end marker xmlChar, 0 if none | 
|  | 1917 | * @end2:  an end marker xmlChar, 0 if none | 
|  | 1918 | * @end3:  an end marker xmlChar, 0 if none | 
|  | 1919 | * | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1920 | * Takes a entity string content and process to do the adequate substitutions. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1921 | * | 
|  | 1922 | * [67] Reference ::= EntityRef | CharRef | 
|  | 1923 | * | 
|  | 1924 | * [69] PEReference ::= '%' Name ';' | 
|  | 1925 | * | 
|  | 1926 | * Returns A newly allocated string with the substitution done. The caller | 
|  | 1927 | *      must deallocate it ! | 
|  | 1928 | */ | 
|  | 1929 | xmlChar * | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1930 | xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, | 
|  | 1931 | int what, xmlChar end, xmlChar  end2, xmlChar end3) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1932 | xmlChar *buffer = NULL; | 
|  | 1933 | int buffer_size = 0; | 
|  | 1934 |  | 
|  | 1935 | xmlChar *current = NULL; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1936 | const xmlChar *last; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1937 | xmlEntityPtr ent; | 
|  | 1938 | int c,l; | 
|  | 1939 | int nbchars = 0; | 
|  | 1940 |  | 
| Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 1941 | if ((ctxt == NULL) || (str == NULL) || (len < 0)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1942 | return(NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1943 | last = str + len; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1944 |  | 
|  | 1945 | if (ctxt->depth > 40) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 1946 | xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1947 | return(NULL); | 
|  | 1948 | } | 
|  | 1949 |  | 
|  | 1950 | /* | 
|  | 1951 | * allocate a translation buffer. | 
|  | 1952 | */ | 
|  | 1953 | buffer_size = XML_PARSER_BIG_BUFFER_SIZE; | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 1954 | buffer = (xmlChar *) xmlMallocAtomic(buffer_size * sizeof(xmlChar)); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1955 | if (buffer == NULL) goto mem_error; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1956 |  | 
|  | 1957 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1958 | * OK loop until we reach one of the ending char or a size limit. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1959 | * we are operating on already parsed values. | 
|  | 1960 | */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 1961 | if (str < last) | 
|  | 1962 | c = CUR_SCHAR(str, l); | 
|  | 1963 | else | 
|  | 1964 | c = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1965 | while ((c != 0) && (c != end) && /* non input consuming loop */ | 
|  | 1966 | (c != end2) && (c != end3)) { | 
|  | 1967 |  | 
|  | 1968 | if (c == 0) break; | 
|  | 1969 | if ((c == '&') && (str[1] == '#')) { | 
|  | 1970 | int val = xmlParseStringCharRef(ctxt, &str); | 
|  | 1971 | if (val != 0) { | 
|  | 1972 | COPY_BUF(0,buffer,nbchars,val); | 
|  | 1973 | } | 
|  | 1974 | } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) { | 
|  | 1975 | if (xmlParserDebugEntities) | 
|  | 1976 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1977 | "String decoding Entity Reference: %.30s\n", | 
|  | 1978 | str); | 
|  | 1979 | ent = xmlParseStringEntityRef(ctxt, &str); | 
|  | 1980 | if ((ent != NULL) && | 
|  | 1981 | (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { | 
|  | 1982 | if (ent->content != NULL) { | 
|  | 1983 | COPY_BUF(0,buffer,nbchars,ent->content[0]); | 
|  | 1984 | } else { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 1985 | xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 1986 | "predefined entity has no content\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1987 | } | 
|  | 1988 | } else if ((ent != NULL) && (ent->content != NULL)) { | 
|  | 1989 | xmlChar *rep; | 
|  | 1990 |  | 
|  | 1991 | ctxt->depth++; | 
|  | 1992 | rep = xmlStringDecodeEntities(ctxt, ent->content, what, | 
|  | 1993 | 0, 0, 0); | 
|  | 1994 | ctxt->depth--; | 
|  | 1995 | if (rep != NULL) { | 
|  | 1996 | current = rep; | 
|  | 1997 | while (*current != 0) { /* non input consuming loop */ | 
|  | 1998 | buffer[nbchars++] = *current++; | 
|  | 1999 | if (nbchars > | 
|  | 2000 | buffer_size - XML_PARSER_BUFFER_SIZE) { | 
|  | 2001 | growBuffer(buffer); | 
|  | 2002 | } | 
|  | 2003 | } | 
|  | 2004 | xmlFree(rep); | 
|  | 2005 | } | 
|  | 2006 | } else if (ent != NULL) { | 
|  | 2007 | int i = xmlStrlen(ent->name); | 
|  | 2008 | const xmlChar *cur = ent->name; | 
|  | 2009 |  | 
|  | 2010 | buffer[nbchars++] = '&'; | 
|  | 2011 | if (nbchars > buffer_size - i - XML_PARSER_BUFFER_SIZE) { | 
|  | 2012 | growBuffer(buffer); | 
|  | 2013 | } | 
|  | 2014 | for (;i > 0;i--) | 
|  | 2015 | buffer[nbchars++] = *cur++; | 
|  | 2016 | buffer[nbchars++] = ';'; | 
|  | 2017 | } | 
|  | 2018 | } else if (c == '%' && (what & XML_SUBSTITUTE_PEREF)) { | 
|  | 2019 | if (xmlParserDebugEntities) | 
|  | 2020 | xmlGenericError(xmlGenericErrorContext, | 
|  | 2021 | "String decoding PE Reference: %.30s\n", str); | 
|  | 2022 | ent = xmlParseStringPEReference(ctxt, &str); | 
|  | 2023 | if (ent != NULL) { | 
|  | 2024 | xmlChar *rep; | 
|  | 2025 |  | 
|  | 2026 | ctxt->depth++; | 
|  | 2027 | rep = xmlStringDecodeEntities(ctxt, ent->content, what, | 
|  | 2028 | 0, 0, 0); | 
|  | 2029 | ctxt->depth--; | 
|  | 2030 | if (rep != NULL) { | 
|  | 2031 | current = rep; | 
|  | 2032 | while (*current != 0) { /* non input consuming loop */ | 
|  | 2033 | buffer[nbchars++] = *current++; | 
|  | 2034 | if (nbchars > | 
|  | 2035 | buffer_size - XML_PARSER_BUFFER_SIZE) { | 
|  | 2036 | growBuffer(buffer); | 
|  | 2037 | } | 
|  | 2038 | } | 
|  | 2039 | xmlFree(rep); | 
|  | 2040 | } | 
|  | 2041 | } | 
|  | 2042 | } else { | 
|  | 2043 | COPY_BUF(l,buffer,nbchars,c); | 
|  | 2044 | str += l; | 
|  | 2045 | if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { | 
|  | 2046 | growBuffer(buffer); | 
|  | 2047 | } | 
|  | 2048 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2049 | if (str < last) | 
|  | 2050 | c = CUR_SCHAR(str, l); | 
|  | 2051 | else | 
|  | 2052 | c = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2053 | } | 
|  | 2054 | buffer[nbchars++] = 0; | 
|  | 2055 | return(buffer); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2056 |  | 
|  | 2057 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2058 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2059 | return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2060 | } | 
|  | 2061 |  | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2062 | /** | 
|  | 2063 | * xmlStringDecodeEntities: | 
|  | 2064 | * @ctxt:  the parser context | 
|  | 2065 | * @str:  the input string | 
|  | 2066 | * @what:  combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF | 
|  | 2067 | * @end:  an end marker xmlChar, 0 if none | 
|  | 2068 | * @end2:  an end marker xmlChar, 0 if none | 
|  | 2069 | * @end3:  an end marker xmlChar, 0 if none | 
|  | 2070 | * | 
|  | 2071 | * Takes a entity string content and process to do the adequate substitutions. | 
|  | 2072 | * | 
|  | 2073 | * [67] Reference ::= EntityRef | CharRef | 
|  | 2074 | * | 
|  | 2075 | * [69] PEReference ::= '%' Name ';' | 
|  | 2076 | * | 
|  | 2077 | * Returns A newly allocated string with the substitution done. The caller | 
|  | 2078 | *      must deallocate it ! | 
|  | 2079 | */ | 
|  | 2080 | xmlChar * | 
|  | 2081 | xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, | 
|  | 2082 | xmlChar end, xmlChar  end2, xmlChar end3) { | 
| Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 2083 | if ((ctxt == NULL) || (str == NULL)) return(NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2084 | return(xmlStringLenDecodeEntities(ctxt, str, xmlStrlen(str), what, | 
|  | 2085 | end, end2, end3)); | 
|  | 2086 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2087 |  | 
|  | 2088 | /************************************************************************ | 
|  | 2089 | *									* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2090 | *		Commodity functions, cleanup needed ?			* | 
|  | 2091 | *									* | 
|  | 2092 | ************************************************************************/ | 
|  | 2093 |  | 
|  | 2094 | /** | 
|  | 2095 | * areBlanks: | 
|  | 2096 | * @ctxt:  an XML parser context | 
|  | 2097 | * @str:  a xmlChar * | 
|  | 2098 | * @len:  the size of @str | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 2099 | * @blank_chars: we know the chars are blanks | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2100 | * | 
|  | 2101 | * Is this a sequence of blank chars that one can ignore ? | 
|  | 2102 | * | 
|  | 2103 | * Returns 1 if ignorable 0 otherwise. | 
|  | 2104 | */ | 
|  | 2105 |  | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 2106 | static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, | 
|  | 2107 | int blank_chars) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2108 | int i, ret; | 
|  | 2109 | xmlNodePtr lastChild; | 
|  | 2110 |  | 
| Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 2111 | /* | 
|  | 2112 | * Don't spend time trying to differentiate them, the same callback is | 
|  | 2113 | * used ! | 
|  | 2114 | */ | 
|  | 2115 | if (ctxt->sax->ignorableWhitespace == ctxt->sax->characters) | 
| Daniel Veillard | 2f36224 | 2001-03-02 17:36:21 +0000 | [diff] [blame] | 2116 | return(0); | 
|  | 2117 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2118 | /* | 
|  | 2119 | * Check for xml:space value. | 
|  | 2120 | */ | 
|  | 2121 | if (*(ctxt->space) == 1) | 
|  | 2122 | return(0); | 
|  | 2123 |  | 
|  | 2124 | /* | 
|  | 2125 | * Check that the string is made of blanks | 
|  | 2126 | */ | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 2127 | if (blank_chars == 0) { | 
|  | 2128 | for (i = 0;i < len;i++) | 
|  | 2129 | if (!(IS_BLANK_CH(str[i]))) return(0); | 
|  | 2130 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2131 |  | 
|  | 2132 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2133 | * Look if the element is mixed content in the DTD if available | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2134 | */ | 
| Daniel Veillard | 6dd398f | 2001-07-25 22:41:03 +0000 | [diff] [blame] | 2135 | if (ctxt->node == NULL) return(0); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2136 | if (ctxt->myDoc != NULL) { | 
|  | 2137 | ret = xmlIsMixedElement(ctxt->myDoc, ctxt->node->name); | 
|  | 2138 | if (ret == 0) return(1); | 
|  | 2139 | if (ret == 1) return(0); | 
|  | 2140 | } | 
|  | 2141 |  | 
|  | 2142 | /* | 
|  | 2143 | * Otherwise, heuristic :-\ | 
|  | 2144 | */ | 
| Daniel Veillard | abac41e | 2005-07-06 15:17:38 +0000 | [diff] [blame] | 2145 | if ((RAW != '<') && (RAW != 0xD)) return(0); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2146 | if ((ctxt->node->children == NULL) && | 
|  | 2147 | (RAW == '<') && (NXT(1) == '/')) return(0); | 
|  | 2148 |  | 
|  | 2149 | lastChild = xmlGetLastChild(ctxt->node); | 
|  | 2150 | if (lastChild == NULL) { | 
| Daniel Veillard | 7db3773 | 2001-07-12 01:20:08 +0000 | [diff] [blame] | 2151 | if ((ctxt->node->type != XML_ELEMENT_NODE) && | 
|  | 2152 | (ctxt->node->content != NULL)) return(0); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2153 | } else if (xmlNodeIsText(lastChild)) | 
|  | 2154 | return(0); | 
|  | 2155 | else if ((ctxt->node->children != NULL) && | 
|  | 2156 | (xmlNodeIsText(ctxt->node->children))) | 
|  | 2157 | return(0); | 
|  | 2158 | return(1); | 
|  | 2159 | } | 
|  | 2160 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2161 | /************************************************************************ | 
|  | 2162 | *									* | 
|  | 2163 | *		Extra stuff for namespace support			* | 
|  | 2164 | *	Relates to http://www.w3.org/TR/WD-xml-names			* | 
|  | 2165 | *									* | 
|  | 2166 | ************************************************************************/ | 
|  | 2167 |  | 
|  | 2168 | /** | 
|  | 2169 | * xmlSplitQName: | 
|  | 2170 | * @ctxt:  an XML parser context | 
|  | 2171 | * @name:  an XML parser context | 
|  | 2172 | * @prefix:  a xmlChar ** | 
|  | 2173 | * | 
|  | 2174 | * parse an UTF8 encoded XML qualified name string | 
|  | 2175 | * | 
|  | 2176 | * [NS 5] QName ::= (Prefix ':')? LocalPart | 
|  | 2177 | * | 
|  | 2178 | * [NS 6] Prefix ::= NCName | 
|  | 2179 | * | 
|  | 2180 | * [NS 7] LocalPart ::= NCName | 
|  | 2181 | * | 
|  | 2182 | * Returns the local part, and prefix is updated | 
|  | 2183 | *   to get the Prefix if any. | 
|  | 2184 | */ | 
|  | 2185 |  | 
|  | 2186 | xmlChar * | 
|  | 2187 | xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { | 
|  | 2188 | xmlChar buf[XML_MAX_NAMELEN + 5]; | 
|  | 2189 | xmlChar *buffer = NULL; | 
|  | 2190 | int len = 0; | 
|  | 2191 | int max = XML_MAX_NAMELEN; | 
|  | 2192 | xmlChar *ret = NULL; | 
|  | 2193 | const xmlChar *cur = name; | 
|  | 2194 | int c; | 
|  | 2195 |  | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 2196 | if (prefix == NULL) return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2197 | *prefix = NULL; | 
|  | 2198 |  | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 2199 | if (cur == NULL) return(NULL); | 
|  | 2200 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2201 | #ifndef XML_XML_NAMESPACE | 
|  | 2202 | /* xml: prefix is not really a namespace */ | 
|  | 2203 | if ((cur[0] == 'x') && (cur[1] == 'm') && | 
|  | 2204 | (cur[2] == 'l') && (cur[3] == ':')) | 
|  | 2205 | return(xmlStrdup(name)); | 
|  | 2206 | #endif | 
|  | 2207 |  | 
| Daniel Veillard | 597bc48 | 2003-07-24 16:08:28 +0000 | [diff] [blame] | 2208 | /* nasty but well=formed */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2209 | if (cur[0] == ':') | 
|  | 2210 | return(xmlStrdup(name)); | 
|  | 2211 |  | 
|  | 2212 | c = *cur++; | 
|  | 2213 | while ((c != 0) && (c != ':') && (len < max)) { /* tested bigname.xml */ | 
|  | 2214 | buf[len++] = c; | 
|  | 2215 | c = *cur++; | 
|  | 2216 | } | 
|  | 2217 | if (len >= max) { | 
|  | 2218 | /* | 
|  | 2219 | * Okay someone managed to make a huge name, so he's ready to pay | 
|  | 2220 | * for the processing speed. | 
|  | 2221 | */ | 
|  | 2222 | max = len * 2; | 
|  | 2223 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2224 | buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2225 | if (buffer == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2226 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2227 | return(NULL); | 
|  | 2228 | } | 
|  | 2229 | memcpy(buffer, buf, len); | 
|  | 2230 | while ((c != 0) && (c != ':')) { /* tested bigname.xml */ | 
|  | 2231 | if (len + 10 > max) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2232 | xmlChar *tmp; | 
|  | 2233 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2234 | max *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2235 | tmp = (xmlChar *) xmlRealloc(buffer, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2236 | max * sizeof(xmlChar)); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2237 | if (tmp == NULL) { | 
|  | 2238 | xmlFree(tmp); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2239 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2240 | return(NULL); | 
|  | 2241 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2242 | buffer = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2243 | } | 
|  | 2244 | buffer[len++] = c; | 
|  | 2245 | c = *cur++; | 
|  | 2246 | } | 
|  | 2247 | buffer[len] = 0; | 
|  | 2248 | } | 
|  | 2249 |  | 
| Daniel Veillard | 597bc48 | 2003-07-24 16:08:28 +0000 | [diff] [blame] | 2250 | /* nasty but well=formed | 
|  | 2251 | if ((c == ':') && (*cur == 0)) { | 
|  | 2252 | return(xmlStrdup(name)); | 
|  | 2253 | } */ | 
|  | 2254 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2255 | if (buffer == NULL) | 
|  | 2256 | ret = xmlStrndup(buf, len); | 
|  | 2257 | else { | 
|  | 2258 | ret = buffer; | 
|  | 2259 | buffer = NULL; | 
|  | 2260 | max = XML_MAX_NAMELEN; | 
|  | 2261 | } | 
|  | 2262 |  | 
|  | 2263 |  | 
|  | 2264 | if (c == ':') { | 
| Daniel Veillard | bb284f4 | 2002-10-16 18:02:47 +0000 | [diff] [blame] | 2265 | c = *cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2266 | *prefix = ret; | 
| Daniel Veillard | 597bc48 | 2003-07-24 16:08:28 +0000 | [diff] [blame] | 2267 | if (c == 0) { | 
| Daniel Veillard | 8d73bcb | 2003-08-04 01:06:15 +0000 | [diff] [blame] | 2268 | return(xmlStrndup(BAD_CAST "", 0)); | 
| Daniel Veillard | 597bc48 | 2003-07-24 16:08:28 +0000 | [diff] [blame] | 2269 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2270 | len = 0; | 
|  | 2271 |  | 
| Daniel Veillard | bb284f4 | 2002-10-16 18:02:47 +0000 | [diff] [blame] | 2272 | /* | 
|  | 2273 | * Check that the first character is proper to start | 
|  | 2274 | * a new name | 
|  | 2275 | */ | 
|  | 2276 | if (!(((c >= 0x61) && (c <= 0x7A)) || | 
|  | 2277 | ((c >= 0x41) && (c <= 0x5A)) || | 
|  | 2278 | (c == '_') || (c == ':'))) { | 
|  | 2279 | int l; | 
|  | 2280 | int first = CUR_SCHAR(cur, l); | 
|  | 2281 |  | 
|  | 2282 | if (!IS_LETTER(first) && (first != '_')) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 2283 | xmlFatalErrMsgStr(ctxt, XML_NS_ERR_QNAME, | 
| Daniel Veillard | bb284f4 | 2002-10-16 18:02:47 +0000 | [diff] [blame] | 2284 | "Name %s is not XML Namespace compliant\n", | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 2285 | name); | 
| Daniel Veillard | bb284f4 | 2002-10-16 18:02:47 +0000 | [diff] [blame] | 2286 | } | 
|  | 2287 | } | 
|  | 2288 | cur++; | 
|  | 2289 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2290 | while ((c != 0) && (len < max)) { /* tested bigname2.xml */ | 
|  | 2291 | buf[len++] = c; | 
|  | 2292 | c = *cur++; | 
|  | 2293 | } | 
|  | 2294 | if (len >= max) { | 
|  | 2295 | /* | 
|  | 2296 | * Okay someone managed to make a huge name, so he's ready to pay | 
|  | 2297 | * for the processing speed. | 
|  | 2298 | */ | 
|  | 2299 | max = len * 2; | 
|  | 2300 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2301 | buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2302 | if (buffer == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2303 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2304 | return(NULL); | 
|  | 2305 | } | 
|  | 2306 | memcpy(buffer, buf, len); | 
|  | 2307 | while (c != 0) { /* tested bigname2.xml */ | 
|  | 2308 | if (len + 10 > max) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2309 | xmlChar *tmp; | 
|  | 2310 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2311 | max *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2312 | tmp = (xmlChar *) xmlRealloc(buffer, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2313 | max * sizeof(xmlChar)); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2314 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2315 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2316 | xmlFree(buffer); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2317 | return(NULL); | 
|  | 2318 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2319 | buffer = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2320 | } | 
|  | 2321 | buffer[len++] = c; | 
|  | 2322 | c = *cur++; | 
|  | 2323 | } | 
|  | 2324 | buffer[len] = 0; | 
|  | 2325 | } | 
|  | 2326 |  | 
|  | 2327 | if (buffer == NULL) | 
|  | 2328 | ret = xmlStrndup(buf, len); | 
|  | 2329 | else { | 
|  | 2330 | ret = buffer; | 
|  | 2331 | } | 
|  | 2332 | } | 
|  | 2333 |  | 
|  | 2334 | return(ret); | 
|  | 2335 | } | 
|  | 2336 |  | 
|  | 2337 | /************************************************************************ | 
|  | 2338 | *									* | 
|  | 2339 | *			The parser itself				* | 
|  | 2340 | *	Relates to http://www.w3.org/TR/REC-xml				* | 
|  | 2341 | *									* | 
|  | 2342 | ************************************************************************/ | 
|  | 2343 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2344 | static const xmlChar * xmlParseNameComplex(xmlParserCtxtPtr ctxt); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2345 | static xmlChar * xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2346 | int *len, int *alloc, int normalize); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 2347 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2348 | /** | 
|  | 2349 | * xmlParseName: | 
|  | 2350 | * @ctxt:  an XML parser context | 
|  | 2351 | * | 
|  | 2352 | * parse an XML name. | 
|  | 2353 | * | 
|  | 2354 | * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | | 
|  | 2355 | *                  CombiningChar | Extender | 
|  | 2356 | * | 
|  | 2357 | * [5] Name ::= (Letter | '_' | ':') (NameChar)* | 
|  | 2358 | * | 
| Daniel Veillard | 807b4de | 2004-09-26 14:42:56 +0000 | [diff] [blame] | 2359 | * [6] Names ::= Name (#x20 Name)* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2360 | * | 
|  | 2361 | * Returns the Name parsed or NULL | 
|  | 2362 | */ | 
|  | 2363 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2364 | const xmlChar * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2365 | xmlParseName(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2366 | const xmlChar *in; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2367 | const xmlChar *ret; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2368 | int count = 0; | 
|  | 2369 |  | 
|  | 2370 | GROW; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2371 |  | 
|  | 2372 | /* | 
|  | 2373 | * Accelerator for simple ASCII names | 
|  | 2374 | */ | 
|  | 2375 | in = ctxt->input->cur; | 
|  | 2376 | if (((*in >= 0x61) && (*in <= 0x7A)) || | 
|  | 2377 | ((*in >= 0x41) && (*in <= 0x5A)) || | 
|  | 2378 | (*in == '_') || (*in == ':')) { | 
|  | 2379 | in++; | 
|  | 2380 | while (((*in >= 0x61) && (*in <= 0x7A)) || | 
|  | 2381 | ((*in >= 0x41) && (*in <= 0x5A)) || | 
|  | 2382 | ((*in >= 0x30) && (*in <= 0x39)) || | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 2383 | (*in == '_') || (*in == '-') || | 
|  | 2384 | (*in == ':') || (*in == '.')) | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2385 | in++; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 2386 | if ((*in > 0) && (*in < 0x80)) { | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2387 | count = in - ctxt->input->cur; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2388 | ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count); | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2389 | ctxt->input->cur = in; | 
| Daniel Veillard | 77a90a7 | 2003-03-22 00:04:05 +0000 | [diff] [blame] | 2390 | ctxt->nbChars += count; | 
|  | 2391 | ctxt->input->col += count; | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2392 | if (ret == NULL) | 
|  | 2393 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2394 | return(ret); | 
|  | 2395 | } | 
|  | 2396 | } | 
| Daniel Veillard | 2f36224 | 2001-03-02 17:36:21 +0000 | [diff] [blame] | 2397 | return(xmlParseNameComplex(ctxt)); | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 2398 | } | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2399 |  | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2400 | /** | 
|  | 2401 | * xmlParseNameAndCompare: | 
|  | 2402 | * @ctxt:  an XML parser context | 
|  | 2403 | * | 
|  | 2404 | * parse an XML name and compares for match | 
|  | 2405 | * (specialized for endtag parsing) | 
|  | 2406 | * | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2407 | * Returns NULL for an illegal name, (xmlChar*) 1 for success | 
|  | 2408 | * and the name for mismatch | 
|  | 2409 | */ | 
|  | 2410 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2411 | static const xmlChar * | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2412 | xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *other) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 2413 | register const xmlChar *cmp = other; | 
|  | 2414 | register const xmlChar *in; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2415 | const xmlChar *ret; | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2416 |  | 
|  | 2417 | GROW; | 
|  | 2418 |  | 
|  | 2419 | in = ctxt->input->cur; | 
|  | 2420 | while (*in != 0 && *in == *cmp) { | 
|  | 2421 | ++in; | 
|  | 2422 | ++cmp; | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 2423 | ctxt->input->col++; | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2424 | } | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2425 | if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) { | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2426 | /* success */ | 
|  | 2427 | ctxt->input->cur = in; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2428 | return (const xmlChar*) 1; | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2429 | } | 
|  | 2430 | /* failure (or end of input buffer), check with full function */ | 
|  | 2431 | ret = xmlParseName (ctxt); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 2432 | /* strings coming from the dictionnary direct compare possible */ | 
|  | 2433 | if (ret == other) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2434 | return (const xmlChar*) 1; | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 2435 | } | 
|  | 2436 | return ret; | 
|  | 2437 | } | 
|  | 2438 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2439 | static const xmlChar * | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 2440 | xmlParseNameComplex(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 2441 | int len = 0, l; | 
|  | 2442 | int c; | 
|  | 2443 | int count = 0; | 
|  | 2444 |  | 
|  | 2445 | /* | 
|  | 2446 | * Handler for more complex cases | 
|  | 2447 | */ | 
|  | 2448 | GROW; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2449 | c = CUR_CHAR(l); | 
|  | 2450 | if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */ | 
|  | 2451 | (!IS_LETTER(c) && (c != '_') && | 
|  | 2452 | (c != ':'))) { | 
|  | 2453 | return(NULL); | 
|  | 2454 | } | 
|  | 2455 |  | 
|  | 2456 | while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */ | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2457 | ((IS_LETTER(c)) || (IS_DIGIT(c)) || | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2458 | (c == '.') || (c == '-') || | 
|  | 2459 | (c == '_') || (c == ':') || | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2460 | (IS_COMBINING(c)) || | 
|  | 2461 | (IS_EXTENDER(c)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2462 | if (count++ > 100) { | 
|  | 2463 | count = 0; | 
|  | 2464 | GROW; | 
|  | 2465 | } | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2466 | len += l; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2467 | NEXTL(l); | 
|  | 2468 | c = CUR_CHAR(l); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2469 | } | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 2470 | return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2471 | } | 
|  | 2472 |  | 
|  | 2473 | /** | 
|  | 2474 | * xmlParseStringName: | 
|  | 2475 | * @ctxt:  an XML parser context | 
|  | 2476 | * @str:  a pointer to the string pointer (IN/OUT) | 
|  | 2477 | * | 
|  | 2478 | * parse an XML name. | 
|  | 2479 | * | 
|  | 2480 | * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | | 
|  | 2481 | *                  CombiningChar | Extender | 
|  | 2482 | * | 
|  | 2483 | * [5] Name ::= (Letter | '_' | ':') (NameChar)* | 
|  | 2484 | * | 
| Daniel Veillard | 807b4de | 2004-09-26 14:42:56 +0000 | [diff] [blame] | 2485 | * [6] Names ::= Name (#x20 Name)* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2486 | * | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2487 | * Returns the Name parsed or NULL. The @str pointer | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2488 | * is updated to the current location in the string. | 
|  | 2489 | */ | 
|  | 2490 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 2491 | static xmlChar * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2492 | xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { | 
|  | 2493 | xmlChar buf[XML_MAX_NAMELEN + 5]; | 
|  | 2494 | const xmlChar *cur = *str; | 
|  | 2495 | int len = 0, l; | 
|  | 2496 | int c; | 
|  | 2497 |  | 
|  | 2498 | c = CUR_SCHAR(cur, l); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2499 | if (!IS_LETTER(c) && (c != '_') && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2500 | (c != ':')) { | 
|  | 2501 | return(NULL); | 
|  | 2502 | } | 
|  | 2503 |  | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2504 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigentname.xml */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2505 | (c == '.') || (c == '-') || | 
|  | 2506 | (c == '_') || (c == ':') || | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2507 | (IS_COMBINING(c)) || | 
|  | 2508 | (IS_EXTENDER(c))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2509 | COPY_BUF(l,buf,len,c); | 
|  | 2510 | cur += l; | 
|  | 2511 | c = CUR_SCHAR(cur, l); | 
|  | 2512 | if (len >= XML_MAX_NAMELEN) { /* test bigentname.xml */ | 
|  | 2513 | /* | 
|  | 2514 | * Okay someone managed to make a huge name, so he's ready to pay | 
|  | 2515 | * for the processing speed. | 
|  | 2516 | */ | 
|  | 2517 | xmlChar *buffer; | 
|  | 2518 | int max = len * 2; | 
|  | 2519 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2520 | buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2521 | if (buffer == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2522 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2523 | return(NULL); | 
|  | 2524 | } | 
|  | 2525 | memcpy(buffer, buf, len); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2526 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2527 | /* test bigentname.xml */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2528 | (c == '.') || (c == '-') || | 
|  | 2529 | (c == '_') || (c == ':') || | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2530 | (IS_COMBINING(c)) || | 
|  | 2531 | (IS_EXTENDER(c))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2532 | if (len + 10 > max) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2533 | xmlChar *tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2534 | max *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2535 | tmp = (xmlChar *) xmlRealloc(buffer, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2536 | max * sizeof(xmlChar)); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2537 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2538 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2539 | xmlFree(buffer); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2540 | return(NULL); | 
|  | 2541 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2542 | buffer = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2543 | } | 
|  | 2544 | COPY_BUF(l,buffer,len,c); | 
|  | 2545 | cur += l; | 
|  | 2546 | c = CUR_SCHAR(cur, l); | 
|  | 2547 | } | 
|  | 2548 | buffer[len] = 0; | 
|  | 2549 | *str = cur; | 
|  | 2550 | return(buffer); | 
|  | 2551 | } | 
|  | 2552 | } | 
|  | 2553 | *str = cur; | 
|  | 2554 | return(xmlStrndup(buf, len)); | 
|  | 2555 | } | 
|  | 2556 |  | 
|  | 2557 | /** | 
|  | 2558 | * xmlParseNmtoken: | 
|  | 2559 | * @ctxt:  an XML parser context | 
|  | 2560 | * | 
|  | 2561 | * parse an XML Nmtoken. | 
|  | 2562 | * | 
|  | 2563 | * [7] Nmtoken ::= (NameChar)+ | 
|  | 2564 | * | 
| Daniel Veillard | 807b4de | 2004-09-26 14:42:56 +0000 | [diff] [blame] | 2565 | * [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2566 | * | 
|  | 2567 | * Returns the Nmtoken parsed or NULL | 
|  | 2568 | */ | 
|  | 2569 |  | 
|  | 2570 | xmlChar * | 
|  | 2571 | xmlParseNmtoken(xmlParserCtxtPtr ctxt) { | 
|  | 2572 | xmlChar buf[XML_MAX_NAMELEN + 5]; | 
|  | 2573 | int len = 0, l; | 
|  | 2574 | int c; | 
|  | 2575 | int count = 0; | 
|  | 2576 |  | 
|  | 2577 | GROW; | 
|  | 2578 | c = CUR_CHAR(l); | 
|  | 2579 |  | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2580 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigtoken.xml */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2581 | (c == '.') || (c == '-') || | 
|  | 2582 | (c == '_') || (c == ':') || | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2583 | (IS_COMBINING(c)) || | 
|  | 2584 | (IS_EXTENDER(c))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2585 | if (count++ > 100) { | 
|  | 2586 | count = 0; | 
|  | 2587 | GROW; | 
|  | 2588 | } | 
|  | 2589 | COPY_BUF(l,buf,len,c); | 
|  | 2590 | NEXTL(l); | 
|  | 2591 | c = CUR_CHAR(l); | 
|  | 2592 | if (len >= XML_MAX_NAMELEN) { | 
|  | 2593 | /* | 
|  | 2594 | * Okay someone managed to make a huge token, so he's ready to pay | 
|  | 2595 | * for the processing speed. | 
|  | 2596 | */ | 
|  | 2597 | xmlChar *buffer; | 
|  | 2598 | int max = len * 2; | 
|  | 2599 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2600 | buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2601 | if (buffer == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2602 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2603 | return(NULL); | 
|  | 2604 | } | 
|  | 2605 | memcpy(buffer, buf, len); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2606 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigtoken.xml */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2607 | (c == '.') || (c == '-') || | 
|  | 2608 | (c == '_') || (c == ':') || | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2609 | (IS_COMBINING(c)) || | 
|  | 2610 | (IS_EXTENDER(c))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2611 | if (count++ > 100) { | 
|  | 2612 | count = 0; | 
|  | 2613 | GROW; | 
|  | 2614 | } | 
|  | 2615 | if (len + 10 > max) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2616 | xmlChar *tmp; | 
|  | 2617 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2618 | max *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2619 | tmp = (xmlChar *) xmlRealloc(buffer, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2620 | max * sizeof(xmlChar)); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2621 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2622 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2623 | xmlFree(buffer); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2624 | return(NULL); | 
|  | 2625 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2626 | buffer = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2627 | } | 
|  | 2628 | COPY_BUF(l,buffer,len,c); | 
|  | 2629 | NEXTL(l); | 
|  | 2630 | c = CUR_CHAR(l); | 
|  | 2631 | } | 
|  | 2632 | buffer[len] = 0; | 
|  | 2633 | return(buffer); | 
|  | 2634 | } | 
|  | 2635 | } | 
|  | 2636 | if (len == 0) | 
|  | 2637 | return(NULL); | 
|  | 2638 | return(xmlStrndup(buf, len)); | 
|  | 2639 | } | 
|  | 2640 |  | 
|  | 2641 | /** | 
|  | 2642 | * xmlParseEntityValue: | 
|  | 2643 | * @ctxt:  an XML parser context | 
|  | 2644 | * @orig:  if non-NULL store a copy of the original entity value | 
|  | 2645 | * | 
|  | 2646 | * parse a value for ENTITY declarations | 
|  | 2647 | * | 
|  | 2648 | * [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | | 
|  | 2649 | *	               "'" ([^%&'] | PEReference | Reference)* "'" | 
|  | 2650 | * | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2651 | * Returns the EntityValue parsed with reference substituted or NULL | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2652 | */ | 
|  | 2653 |  | 
|  | 2654 | xmlChar * | 
|  | 2655 | xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { | 
|  | 2656 | xmlChar *buf = NULL; | 
|  | 2657 | int len = 0; | 
|  | 2658 | int size = XML_PARSER_BUFFER_SIZE; | 
|  | 2659 | int c, l; | 
|  | 2660 | xmlChar stop; | 
|  | 2661 | xmlChar *ret = NULL; | 
|  | 2662 | const xmlChar *cur = NULL; | 
|  | 2663 | xmlParserInputPtr input; | 
|  | 2664 |  | 
|  | 2665 | if (RAW == '"') stop = '"'; | 
|  | 2666 | else if (RAW == '\'') stop = '\''; | 
|  | 2667 | else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2668 | xmlFatalErr(ctxt, XML_ERR_ENTITY_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2669 | return(NULL); | 
|  | 2670 | } | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2671 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2672 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2673 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2674 | return(NULL); | 
|  | 2675 | } | 
|  | 2676 |  | 
|  | 2677 | /* | 
|  | 2678 | * The content of the entity definition is copied in a buffer. | 
|  | 2679 | */ | 
|  | 2680 |  | 
|  | 2681 | ctxt->instate = XML_PARSER_ENTITY_VALUE; | 
|  | 2682 | input = ctxt->input; | 
|  | 2683 | GROW; | 
|  | 2684 | NEXT; | 
|  | 2685 | c = CUR_CHAR(l); | 
|  | 2686 | /* | 
|  | 2687 | * NOTE: 4.4.5 Included in Literal | 
|  | 2688 | * When a parameter entity reference appears in a literal entity | 
|  | 2689 | * value, ... a single or double quote character in the replacement | 
|  | 2690 | * text is always treated as a normal data character and will not | 
|  | 2691 | * terminate the literal. | 
|  | 2692 | * In practice it means we stop the loop only when back at parsing | 
|  | 2693 | * the initial entity and the quote is found | 
|  | 2694 | */ | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 2695 | while ((IS_CHAR(c)) && ((c != stop) || /* checked */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2696 | (ctxt->input != input))) { | 
|  | 2697 | if (len + 5 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2698 | xmlChar *tmp; | 
|  | 2699 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2700 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2701 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 2702 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2703 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2704 | xmlFree(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2705 | return(NULL); | 
|  | 2706 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 2707 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2708 | } | 
|  | 2709 | COPY_BUF(l,buf,len,c); | 
|  | 2710 | NEXTL(l); | 
|  | 2711 | /* | 
|  | 2712 | * Pop-up of finished entities. | 
|  | 2713 | */ | 
|  | 2714 | while ((RAW == 0) && (ctxt->inputNr > 1)) /* non input consuming */ | 
|  | 2715 | xmlPopInput(ctxt); | 
|  | 2716 |  | 
|  | 2717 | GROW; | 
|  | 2718 | c = CUR_CHAR(l); | 
|  | 2719 | if (c == 0) { | 
|  | 2720 | GROW; | 
|  | 2721 | c = CUR_CHAR(l); | 
|  | 2722 | } | 
|  | 2723 | } | 
|  | 2724 | buf[len] = 0; | 
|  | 2725 |  | 
|  | 2726 | /* | 
|  | 2727 | * Raise problem w.r.t. '&' and '%' being used in non-entities | 
|  | 2728 | * reference constructs. Note Charref will be handled in | 
|  | 2729 | * xmlStringDecodeEntities() | 
|  | 2730 | */ | 
|  | 2731 | cur = buf; | 
|  | 2732 | while (*cur != 0) { /* non input consuming */ | 
|  | 2733 | if ((*cur == '%') || ((*cur == '&') && (cur[1] != '#'))) { | 
|  | 2734 | xmlChar *name; | 
|  | 2735 | xmlChar tmp = *cur; | 
|  | 2736 |  | 
|  | 2737 | cur++; | 
|  | 2738 | name = xmlParseStringName(ctxt, &cur); | 
|  | 2739 | if ((name == NULL) || (*cur != ';')) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 2740 | xmlFatalErrMsgInt(ctxt, XML_ERR_ENTITY_CHAR_ERROR, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2741 | "EntityValue: '%c' forbidden except for entities references\n", | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 2742 | tmp); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2743 | } | 
| Daniel Veillard | 5151c06 | 2001-10-23 13:10:19 +0000 | [diff] [blame] | 2744 | if ((tmp == '%') && (ctxt->inSubset == 1) && | 
|  | 2745 | (ctxt->inputNr == 1)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2746 | xmlFatalErr(ctxt, XML_ERR_ENTITY_PE_INTERNAL, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2747 | } | 
|  | 2748 | if (name != NULL) | 
|  | 2749 | xmlFree(name); | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 2750 | if (*cur == 0) | 
|  | 2751 | break; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2752 | } | 
|  | 2753 | cur++; | 
|  | 2754 | } | 
|  | 2755 |  | 
|  | 2756 | /* | 
|  | 2757 | * Then PEReference entities are substituted. | 
|  | 2758 | */ | 
|  | 2759 | if (c != stop) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2760 | xmlFatalErr(ctxt, XML_ERR_ENTITY_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2761 | xmlFree(buf); | 
|  | 2762 | } else { | 
|  | 2763 | NEXT; | 
|  | 2764 | /* | 
|  | 2765 | * NOTE: 4.4.7 Bypassed | 
|  | 2766 | * When a general entity reference appears in the EntityValue in | 
|  | 2767 | * an entity declaration, it is bypassed and left as is. | 
|  | 2768 | * so XML_SUBSTITUTE_REF is not set here. | 
|  | 2769 | */ | 
|  | 2770 | ret = xmlStringDecodeEntities(ctxt, buf, XML_SUBSTITUTE_PEREF, | 
|  | 2771 | 0, 0, 0); | 
|  | 2772 | if (orig != NULL) | 
|  | 2773 | *orig = buf; | 
|  | 2774 | else | 
|  | 2775 | xmlFree(buf); | 
|  | 2776 | } | 
|  | 2777 |  | 
|  | 2778 | return(ret); | 
|  | 2779 | } | 
|  | 2780 |  | 
|  | 2781 | /** | 
| Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 2782 | * xmlParseAttValueComplex: | 
|  | 2783 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 2784 | * @len:   the resulting attribute len | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2785 | * @normalize:  wether to apply the inner normalization | 
| Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 2786 | * | 
|  | 2787 | * parse a value for an attribute, this is the fallback function | 
|  | 2788 | * of xmlParseAttValue() when the attribute parsing requires handling | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2789 | * of non-ASCII characters, or normalization compaction. | 
| Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 2790 | * | 
|  | 2791 | * Returns the AttValue parsed or NULL. The value has to be freed by the caller. | 
|  | 2792 | */ | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 2793 | static xmlChar * | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2794 | xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { | 
| Daniel Veillard | e72c756 | 2002-05-31 09:47:30 +0000 | [diff] [blame] | 2795 | xmlChar limit = 0; | 
|  | 2796 | xmlChar *buf = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2797 | int len = 0; | 
|  | 2798 | int buf_size = 0; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2799 | int c, l, in_space = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2800 | xmlChar *current = NULL; | 
|  | 2801 | xmlEntityPtr ent; | 
|  | 2802 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2803 | if (NXT(0) == '"') { | 
|  | 2804 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; | 
|  | 2805 | limit = '"'; | 
|  | 2806 | NEXT; | 
|  | 2807 | } else if (NXT(0) == '\'') { | 
|  | 2808 | limit = '\''; | 
|  | 2809 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; | 
|  | 2810 | NEXT; | 
|  | 2811 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2812 | xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2813 | return(NULL); | 
|  | 2814 | } | 
|  | 2815 |  | 
|  | 2816 | /* | 
|  | 2817 | * allocate a translation buffer. | 
|  | 2818 | */ | 
|  | 2819 | buf_size = XML_PARSER_BUFFER_SIZE; | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2820 | buf = (xmlChar *) xmlMallocAtomic(buf_size * sizeof(xmlChar)); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2821 | if (buf == NULL) goto mem_error; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2822 |  | 
|  | 2823 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2824 | * OK loop until we reach one of the ending char or a size limit. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2825 | */ | 
|  | 2826 | c = CUR_CHAR(l); | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2827 | while ((NXT(0) != limit) && /* checked */ | 
|  | 2828 | (c != '<')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2829 | if (c == 0) break; | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2830 | if (c == '&') { | 
| Daniel Veillard | 62998c0 | 2003-09-15 12:56:36 +0000 | [diff] [blame] | 2831 | in_space = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2832 | if (NXT(1) == '#') { | 
|  | 2833 | int val = xmlParseCharRef(ctxt); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2834 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2835 | if (val == '&') { | 
| Daniel Veillard | 319a742 | 2001-09-11 09:27:09 +0000 | [diff] [blame] | 2836 | if (ctxt->replaceEntities) { | 
|  | 2837 | if (len > buf_size - 10) { | 
|  | 2838 | growBuffer(buf); | 
|  | 2839 | } | 
|  | 2840 | buf[len++] = '&'; | 
|  | 2841 | } else { | 
|  | 2842 | /* | 
|  | 2843 | * The reparsing will be done in xmlStringGetNodeList() | 
|  | 2844 | * called by the attribute() function in SAX.c | 
|  | 2845 | */ | 
| Daniel Veillard | 319a742 | 2001-09-11 09:27:09 +0000 | [diff] [blame] | 2846 | if (len > buf_size - 10) { | 
|  | 2847 | growBuffer(buf); | 
|  | 2848 | } | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2849 | buf[len++] = '&'; | 
|  | 2850 | buf[len++] = '#'; | 
|  | 2851 | buf[len++] = '3'; | 
|  | 2852 | buf[len++] = '8'; | 
|  | 2853 | buf[len++] = ';'; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2854 | } | 
|  | 2855 | } else { | 
| Daniel Veillard | 0b6b55b | 2001-03-20 11:27:34 +0000 | [diff] [blame] | 2856 | if (len > buf_size - 10) { | 
|  | 2857 | growBuffer(buf); | 
|  | 2858 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2859 | len += xmlCopyChar(0, &buf[len], val); | 
|  | 2860 | } | 
|  | 2861 | } else { | 
|  | 2862 | ent = xmlParseEntityRef(ctxt); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2863 | if ((ent != NULL) && | 
|  | 2864 | (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { | 
|  | 2865 | if (len > buf_size - 10) { | 
|  | 2866 | growBuffer(buf); | 
|  | 2867 | } | 
|  | 2868 | if ((ctxt->replaceEntities == 0) && | 
|  | 2869 | (ent->content[0] == '&')) { | 
|  | 2870 | buf[len++] = '&'; | 
|  | 2871 | buf[len++] = '#'; | 
|  | 2872 | buf[len++] = '3'; | 
|  | 2873 | buf[len++] = '8'; | 
|  | 2874 | buf[len++] = ';'; | 
|  | 2875 | } else { | 
|  | 2876 | buf[len++] = ent->content[0]; | 
|  | 2877 | } | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2878 | } else if ((ent != NULL) && | 
|  | 2879 | (ctxt->replaceEntities != 0)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2880 | xmlChar *rep; | 
|  | 2881 |  | 
|  | 2882 | if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) { | 
|  | 2883 | rep = xmlStringDecodeEntities(ctxt, ent->content, | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2884 | XML_SUBSTITUTE_REF, | 
|  | 2885 | 0, 0, 0); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2886 | if (rep != NULL) { | 
|  | 2887 | current = rep; | 
|  | 2888 | while (*current != 0) { /* non input consuming */ | 
|  | 2889 | buf[len++] = *current++; | 
|  | 2890 | if (len > buf_size - 10) { | 
|  | 2891 | growBuffer(buf); | 
|  | 2892 | } | 
|  | 2893 | } | 
|  | 2894 | xmlFree(rep); | 
|  | 2895 | } | 
|  | 2896 | } else { | 
| Daniel Veillard | 0b6b55b | 2001-03-20 11:27:34 +0000 | [diff] [blame] | 2897 | if (len > buf_size - 10) { | 
|  | 2898 | growBuffer(buf); | 
|  | 2899 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2900 | if (ent->content != NULL) | 
|  | 2901 | buf[len++] = ent->content[0]; | 
|  | 2902 | } | 
|  | 2903 | } else if (ent != NULL) { | 
|  | 2904 | int i = xmlStrlen(ent->name); | 
|  | 2905 | const xmlChar *cur = ent->name; | 
|  | 2906 |  | 
|  | 2907 | /* | 
|  | 2908 | * This may look absurd but is needed to detect | 
|  | 2909 | * entities problems | 
|  | 2910 | */ | 
|  | 2911 | if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) && | 
|  | 2912 | (ent->content != NULL)) { | 
|  | 2913 | xmlChar *rep; | 
|  | 2914 | rep = xmlStringDecodeEntities(ctxt, ent->content, | 
|  | 2915 | XML_SUBSTITUTE_REF, 0, 0, 0); | 
|  | 2916 | if (rep != NULL) | 
|  | 2917 | xmlFree(rep); | 
|  | 2918 | } | 
|  | 2919 |  | 
|  | 2920 | /* | 
|  | 2921 | * Just output the reference | 
|  | 2922 | */ | 
|  | 2923 | buf[len++] = '&'; | 
|  | 2924 | if (len > buf_size - i - 10) { | 
|  | 2925 | growBuffer(buf); | 
|  | 2926 | } | 
|  | 2927 | for (;i > 0;i--) | 
|  | 2928 | buf[len++] = *cur++; | 
|  | 2929 | buf[len++] = ';'; | 
|  | 2930 | } | 
|  | 2931 | } | 
|  | 2932 | } else { | 
|  | 2933 | if ((c == 0x20) || (c == 0xD) || (c == 0xA) || (c == 0x9)) { | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2934 | if ((len != 0) || (!normalize)) { | 
|  | 2935 | if ((!normalize) || (!in_space)) { | 
|  | 2936 | COPY_BUF(l,buf,len,0x20); | 
|  | 2937 | if (len > buf_size - 10) { | 
|  | 2938 | growBuffer(buf); | 
|  | 2939 | } | 
|  | 2940 | } | 
|  | 2941 | in_space = 1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2942 | } | 
|  | 2943 | } else { | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2944 | in_space = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2945 | COPY_BUF(l,buf,len,c); | 
|  | 2946 | if (len > buf_size - 10) { | 
|  | 2947 | growBuffer(buf); | 
|  | 2948 | } | 
|  | 2949 | } | 
|  | 2950 | NEXTL(l); | 
|  | 2951 | } | 
|  | 2952 | GROW; | 
|  | 2953 | c = CUR_CHAR(l); | 
|  | 2954 | } | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2955 | if ((in_space) && (normalize)) { | 
|  | 2956 | while (buf[len - 1] == 0x20) len--; | 
|  | 2957 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2958 | buf[len] = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2959 | if (RAW == '<') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2960 | xmlFatalErr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2961 | } else if (RAW != limit) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 2962 | xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, | 
|  | 2963 | "AttValue: ' expected\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2964 | } else | 
|  | 2965 | NEXT; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 2966 | if (attlen != NULL) *attlen = len; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2967 | return(buf); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2968 |  | 
|  | 2969 | mem_error: | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 2970 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 2971 | return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 2972 | } | 
|  | 2973 |  | 
|  | 2974 | /** | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 2975 | * xmlParseAttValue: | 
|  | 2976 | * @ctxt:  an XML parser context | 
|  | 2977 | * | 
|  | 2978 | * parse a value for an attribute | 
|  | 2979 | * Note: the parser won't do substitution of entities here, this | 
|  | 2980 | * will be handled later in xmlStringGetNodeList | 
|  | 2981 | * | 
|  | 2982 | * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | | 
|  | 2983 | *                   "'" ([^<&'] | Reference)* "'" | 
|  | 2984 | * | 
|  | 2985 | * 3.3.3 Attribute-Value Normalization: | 
|  | 2986 | * Before the value of an attribute is passed to the application or | 
|  | 2987 | * checked for validity, the XML processor must normalize it as follows: | 
|  | 2988 | * - a character reference is processed by appending the referenced | 
|  | 2989 | *   character to the attribute value | 
|  | 2990 | * - an entity reference is processed by recursively processing the | 
|  | 2991 | *   replacement text of the entity | 
|  | 2992 | * - a whitespace character (#x20, #xD, #xA, #x9) is processed by | 
|  | 2993 | *   appending #x20 to the normalized value, except that only a single | 
|  | 2994 | *   #x20 is appended for a "#xD#xA" sequence that is part of an external | 
|  | 2995 | *   parsed entity or the literal entity value of an internal parsed entity | 
|  | 2996 | * - other characters are processed by appending them to the normalized value | 
|  | 2997 | * If the declared value is not CDATA, then the XML processor must further | 
|  | 2998 | * process the normalized attribute value by discarding any leading and | 
|  | 2999 | * trailing space (#x20) characters, and by replacing sequences of space | 
|  | 3000 | * (#x20) characters by a single space (#x20) character. | 
|  | 3001 | * All attributes for which no declaration has been read should be treated | 
|  | 3002 | * by a non-validating parser as if declared CDATA. | 
|  | 3003 | * | 
|  | 3004 | * Returns the AttValue parsed or NULL. The value has to be freed by the caller. | 
|  | 3005 | */ | 
|  | 3006 |  | 
|  | 3007 |  | 
|  | 3008 | xmlChar * | 
|  | 3009 | xmlParseAttValue(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 3010 | if ((ctxt == NULL) || (ctxt->input == NULL)) return(NULL); | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 3011 | return(xmlParseAttValueInternal(ctxt, NULL, NULL, 0)); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 3012 | } | 
|  | 3013 |  | 
|  | 3014 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3015 | * xmlParseSystemLiteral: | 
|  | 3016 | * @ctxt:  an XML parser context | 
|  | 3017 | * | 
|  | 3018 | * parse an XML Literal | 
|  | 3019 | * | 
|  | 3020 | * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") | 
|  | 3021 | * | 
|  | 3022 | * Returns the SystemLiteral parsed or NULL | 
|  | 3023 | */ | 
|  | 3024 |  | 
|  | 3025 | xmlChar * | 
|  | 3026 | xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { | 
|  | 3027 | xmlChar *buf = NULL; | 
|  | 3028 | int len = 0; | 
|  | 3029 | int size = XML_PARSER_BUFFER_SIZE; | 
|  | 3030 | int cur, l; | 
|  | 3031 | xmlChar stop; | 
|  | 3032 | int state = ctxt->instate; | 
|  | 3033 | int count = 0; | 
|  | 3034 |  | 
|  | 3035 | SHRINK; | 
|  | 3036 | if (RAW == '"') { | 
|  | 3037 | NEXT; | 
|  | 3038 | stop = '"'; | 
|  | 3039 | } else if (RAW == '\'') { | 
|  | 3040 | NEXT; | 
|  | 3041 | stop = '\''; | 
|  | 3042 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3043 | xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3044 | return(NULL); | 
|  | 3045 | } | 
|  | 3046 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 3047 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3048 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3049 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3050 | return(NULL); | 
|  | 3051 | } | 
|  | 3052 | ctxt->instate = XML_PARSER_SYSTEM_LITERAL; | 
|  | 3053 | cur = CUR_CHAR(l); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 3054 | while ((IS_CHAR(cur)) && (cur != stop)) { /* checked */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3055 | if (len + 5 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3056 | xmlChar *tmp; | 
|  | 3057 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3058 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3059 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 3060 | if (tmp == NULL) { | 
|  | 3061 | xmlFree(buf); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3062 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3063 | ctxt->instate = (xmlParserInputState) state; | 
|  | 3064 | return(NULL); | 
|  | 3065 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3066 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3067 | } | 
|  | 3068 | count++; | 
|  | 3069 | if (count > 50) { | 
|  | 3070 | GROW; | 
|  | 3071 | count = 0; | 
|  | 3072 | } | 
|  | 3073 | COPY_BUF(l,buf,len,cur); | 
|  | 3074 | NEXTL(l); | 
|  | 3075 | cur = CUR_CHAR(l); | 
|  | 3076 | if (cur == 0) { | 
|  | 3077 | GROW; | 
|  | 3078 | SHRINK; | 
|  | 3079 | cur = CUR_CHAR(l); | 
|  | 3080 | } | 
|  | 3081 | } | 
|  | 3082 | buf[len] = 0; | 
|  | 3083 | ctxt->instate = (xmlParserInputState) state; | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 3084 | if (!IS_CHAR(cur)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3085 | xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3086 | } else { | 
|  | 3087 | NEXT; | 
|  | 3088 | } | 
|  | 3089 | return(buf); | 
|  | 3090 | } | 
|  | 3091 |  | 
|  | 3092 | /** | 
|  | 3093 | * xmlParsePubidLiteral: | 
|  | 3094 | * @ctxt:  an XML parser context | 
|  | 3095 | * | 
|  | 3096 | * parse an XML public literal | 
|  | 3097 | * | 
|  | 3098 | * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" | 
|  | 3099 | * | 
|  | 3100 | * Returns the PubidLiteral parsed or NULL. | 
|  | 3101 | */ | 
|  | 3102 |  | 
|  | 3103 | xmlChar * | 
|  | 3104 | xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { | 
|  | 3105 | xmlChar *buf = NULL; | 
|  | 3106 | int len = 0; | 
|  | 3107 | int size = XML_PARSER_BUFFER_SIZE; | 
|  | 3108 | xmlChar cur; | 
|  | 3109 | xmlChar stop; | 
|  | 3110 | int count = 0; | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 3111 | xmlParserInputState oldstate = ctxt->instate; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3112 |  | 
|  | 3113 | SHRINK; | 
|  | 3114 | if (RAW == '"') { | 
|  | 3115 | NEXT; | 
|  | 3116 | stop = '"'; | 
|  | 3117 | } else if (RAW == '\'') { | 
|  | 3118 | NEXT; | 
|  | 3119 | stop = '\''; | 
|  | 3120 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3121 | xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3122 | return(NULL); | 
|  | 3123 | } | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 3124 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3125 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3126 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3127 | return(NULL); | 
|  | 3128 | } | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 3129 | ctxt->instate = XML_PARSER_PUBLIC_LITERAL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3130 | cur = CUR; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3131 | while ((IS_PUBIDCHAR_CH(cur)) && (cur != stop)) { /* checked */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3132 | if (len + 1 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3133 | xmlChar *tmp; | 
|  | 3134 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3135 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3136 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 3137 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3138 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3139 | xmlFree(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3140 | return(NULL); | 
|  | 3141 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3142 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3143 | } | 
|  | 3144 | buf[len++] = cur; | 
|  | 3145 | count++; | 
|  | 3146 | if (count > 50) { | 
|  | 3147 | GROW; | 
|  | 3148 | count = 0; | 
|  | 3149 | } | 
|  | 3150 | NEXT; | 
|  | 3151 | cur = CUR; | 
|  | 3152 | if (cur == 0) { | 
|  | 3153 | GROW; | 
|  | 3154 | SHRINK; | 
|  | 3155 | cur = CUR; | 
|  | 3156 | } | 
|  | 3157 | } | 
|  | 3158 | buf[len] = 0; | 
|  | 3159 | if (cur != stop) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3160 | xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3161 | } else { | 
|  | 3162 | NEXT; | 
|  | 3163 | } | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 3164 | ctxt->instate = oldstate; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3165 | return(buf); | 
|  | 3166 | } | 
|  | 3167 |  | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3168 | void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata); | 
| Daniel Veillard | 0a119eb | 2005-07-20 13:46:00 +0000 | [diff] [blame] | 3169 |  | 
|  | 3170 | /* | 
|  | 3171 | * used for the test in the inner loop of the char data testing | 
|  | 3172 | */ | 
|  | 3173 | static const unsigned char test_char_data[256] = { | 
|  | 3174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3175 | 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9, CR/LF separated */ | 
|  | 3176 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3177 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3178 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x00, 0x27, /* & */ | 
|  | 3179 | 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, | 
|  | 3180 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | 
|  | 3181 | 0x38, 0x39, 0x3A, 0x3B, 0x00, 0x3D, 0x3E, 0x3F, /* < */ | 
|  | 3182 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | 
|  | 3183 | 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, | 
|  | 3184 | 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, | 
|  | 3185 | 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x00, 0x5E, 0x5F, /* ] */ | 
|  | 3186 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, | 
|  | 3187 | 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, | 
|  | 3188 | 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, | 
|  | 3189 | 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, | 
|  | 3190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* non-ascii */ | 
|  | 3191 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3192 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3193 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3194 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3195 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3196 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3197 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3198 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3199 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3200 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3201 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3202 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3203 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3204 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 3205 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 
|  | 3206 | }; | 
|  | 3207 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3208 | /** | 
|  | 3209 | * xmlParseCharData: | 
|  | 3210 | * @ctxt:  an XML parser context | 
|  | 3211 | * @cdata:  int indicating whether we are within a CDATA section | 
|  | 3212 | * | 
|  | 3213 | * parse a CharData section. | 
|  | 3214 | * if we are within a CDATA section ']]>' marks an end of section. | 
|  | 3215 | * | 
|  | 3216 | * The right angle bracket (>) may be represented using the string ">", | 
|  | 3217 | * and must, for compatibility, be escaped using ">" or a character | 
|  | 3218 | * reference when it appears in the string "]]>" in content, when that | 
|  | 3219 | * string is not marking the end of a CDATA section. | 
|  | 3220 | * | 
|  | 3221 | * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) | 
|  | 3222 | */ | 
|  | 3223 |  | 
|  | 3224 | void | 
|  | 3225 | xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3226 | const xmlChar *in; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3227 | int nbchar = 0; | 
| Daniel Veillard | 5058211 | 2001-03-26 22:52:16 +0000 | [diff] [blame] | 3228 | int line = ctxt->input->line; | 
|  | 3229 | int col = ctxt->input->col; | 
| Daniel Veillard | 0714c5b | 2005-01-23 00:01:01 +0000 | [diff] [blame] | 3230 | int ccol; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3231 |  | 
|  | 3232 | SHRINK; | 
|  | 3233 | GROW; | 
|  | 3234 | /* | 
|  | 3235 | * Accelerated common case where input don't need to be | 
|  | 3236 | * modified before passing it to the handler. | 
|  | 3237 | */ | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3238 | if (!cdata) { | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3239 | in = ctxt->input->cur; | 
|  | 3240 | do { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3241 | get_more_space: | 
|  | 3242 | while (*in == 0x20) in++; | 
|  | 3243 | if (*in == 0xA) { | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 3244 | ctxt->input->line++; ctxt->input->col = 1; | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3245 | in++; | 
|  | 3246 | while (*in == 0xA) { | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 3247 | ctxt->input->line++; ctxt->input->col = 1; | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3248 | in++; | 
|  | 3249 | } | 
|  | 3250 | goto get_more_space; | 
|  | 3251 | } | 
|  | 3252 | if (*in == '<') { | 
|  | 3253 | nbchar = in - ctxt->input->cur; | 
|  | 3254 | if (nbchar > 0) { | 
|  | 3255 | const xmlChar *tmp = ctxt->input->cur; | 
|  | 3256 | ctxt->input->cur = in; | 
|  | 3257 |  | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 3258 | if ((ctxt->sax != NULL) && | 
|  | 3259 | (ctxt->sax->ignorableWhitespace != | 
|  | 3260 | ctxt->sax->characters)) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3261 | if (areBlanks(ctxt, tmp, nbchar, 1)) { | 
| Daniel Veillard | 32acf0c | 2005-03-31 14:12:37 +0000 | [diff] [blame] | 3262 | if (ctxt->sax->ignorableWhitespace != NULL) | 
|  | 3263 | ctxt->sax->ignorableWhitespace(ctxt->userData, | 
|  | 3264 | tmp, nbchar); | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3265 | } else if (ctxt->sax->characters != NULL) | 
|  | 3266 | ctxt->sax->characters(ctxt->userData, | 
|  | 3267 | tmp, nbchar); | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 3268 | } else if ((ctxt->sax != NULL) && | 
|  | 3269 | (ctxt->sax->characters != NULL)) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3270 | ctxt->sax->characters(ctxt->userData, | 
|  | 3271 | tmp, nbchar); | 
|  | 3272 | } | 
|  | 3273 | } | 
|  | 3274 | return; | 
|  | 3275 | } | 
| Daniel Veillard | 0714c5b | 2005-01-23 00:01:01 +0000 | [diff] [blame] | 3276 |  | 
| Daniel Veillard | 3ed155f | 2001-04-29 19:56:59 +0000 | [diff] [blame] | 3277 | get_more: | 
| Daniel Veillard | 0714c5b | 2005-01-23 00:01:01 +0000 | [diff] [blame] | 3278 | ccol = ctxt->input->col; | 
| Daniel Veillard | 0a119eb | 2005-07-20 13:46:00 +0000 | [diff] [blame] | 3279 | while (test_char_data[*in]) { | 
|  | 3280 | in++; | 
|  | 3281 | ccol++; | 
|  | 3282 | } | 
| Daniel Veillard | 0714c5b | 2005-01-23 00:01:01 +0000 | [diff] [blame] | 3283 | ctxt->input->col = ccol; | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3284 | if (*in == 0xA) { | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 3285 | ctxt->input->line++; ctxt->input->col = 1; | 
| Daniel Veillard | 3ed155f | 2001-04-29 19:56:59 +0000 | [diff] [blame] | 3286 | in++; | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3287 | while (*in == 0xA) { | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 3288 | ctxt->input->line++; ctxt->input->col = 1; | 
| Daniel Veillard | 3ed155f | 2001-04-29 19:56:59 +0000 | [diff] [blame] | 3289 | in++; | 
|  | 3290 | } | 
|  | 3291 | goto get_more; | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3292 | } | 
|  | 3293 | if (*in == ']') { | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 3294 | if ((in[1] == ']') && (in[2] == '>')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3295 | xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL); | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 3296 | ctxt->input->cur = in; | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 3297 | return; | 
|  | 3298 | } | 
|  | 3299 | in++; | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 3300 | ctxt->input->col++; | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 3301 | goto get_more; | 
|  | 3302 | } | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3303 | nbchar = in - ctxt->input->cur; | 
| Daniel Veillard | 80f3257 | 2001-03-07 19:45:40 +0000 | [diff] [blame] | 3304 | if (nbchar > 0) { | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 3305 | if ((ctxt->sax != NULL) && | 
|  | 3306 | (ctxt->sax->ignorableWhitespace != | 
| Daniel Veillard | 40412cd | 2003-09-03 13:28:32 +0000 | [diff] [blame] | 3307 | ctxt->sax->characters) && | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3308 | (IS_BLANK_CH(*ctxt->input->cur))) { | 
| Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3309 | const xmlChar *tmp = ctxt->input->cur; | 
|  | 3310 | ctxt->input->cur = in; | 
| Daniel Veillard | 40412cd | 2003-09-03 13:28:32 +0000 | [diff] [blame] | 3311 |  | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3312 | if (areBlanks(ctxt, tmp, nbchar, 0)) { | 
| Daniel Veillard | 32acf0c | 2005-03-31 14:12:37 +0000 | [diff] [blame] | 3313 | if (ctxt->sax->ignorableWhitespace != NULL) | 
|  | 3314 | ctxt->sax->ignorableWhitespace(ctxt->userData, | 
|  | 3315 | tmp, nbchar); | 
| Daniel Veillard | 40412cd | 2003-09-03 13:28:32 +0000 | [diff] [blame] | 3316 | } else if (ctxt->sax->characters != NULL) | 
|  | 3317 | ctxt->sax->characters(ctxt->userData, | 
|  | 3318 | tmp, nbchar); | 
| Daniel Veillard | 3ed27bd | 2001-06-17 17:58:17 +0000 | [diff] [blame] | 3319 | line = ctxt->input->line; | 
|  | 3320 | col = ctxt->input->col; | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 3321 | } else if (ctxt->sax != NULL) { | 
| Daniel Veillard | 80f3257 | 2001-03-07 19:45:40 +0000 | [diff] [blame] | 3322 | if (ctxt->sax->characters != NULL) | 
|  | 3323 | ctxt->sax->characters(ctxt->userData, | 
|  | 3324 | ctxt->input->cur, nbchar); | 
| Daniel Veillard | 3ed27bd | 2001-06-17 17:58:17 +0000 | [diff] [blame] | 3325 | line = ctxt->input->line; | 
|  | 3326 | col = ctxt->input->col; | 
| Daniel Veillard | 80f3257 | 2001-03-07 19:45:40 +0000 | [diff] [blame] | 3327 | } | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3328 | } | 
|  | 3329 | ctxt->input->cur = in; | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3330 | if (*in == 0xD) { | 
|  | 3331 | in++; | 
|  | 3332 | if (*in == 0xA) { | 
|  | 3333 | ctxt->input->cur = in; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3334 | in++; | 
| Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 3335 | ctxt->input->line++; ctxt->input->col = 1; | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3336 | continue; /* while */ | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3337 | } | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 3338 | in--; | 
|  | 3339 | } | 
|  | 3340 | if (*in == '<') { | 
|  | 3341 | return; | 
|  | 3342 | } | 
|  | 3343 | if (*in == '&') { | 
|  | 3344 | return; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3345 | } | 
|  | 3346 | SHRINK; | 
|  | 3347 | GROW; | 
|  | 3348 | in = ctxt->input->cur; | 
| William M. Brack | c07329e | 2003-09-08 01:57:30 +0000 | [diff] [blame] | 3349 | } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09)); | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3350 | nbchar = 0; | 
|  | 3351 | } | 
| Daniel Veillard | 5058211 | 2001-03-26 22:52:16 +0000 | [diff] [blame] | 3352 | ctxt->input->line = line; | 
|  | 3353 | ctxt->input->col = col; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3354 | xmlParseCharDataComplex(ctxt, cdata); | 
|  | 3355 | } | 
|  | 3356 |  | 
| Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 3357 | /** | 
|  | 3358 | * xmlParseCharDataComplex: | 
|  | 3359 | * @ctxt:  an XML parser context | 
|  | 3360 | * @cdata:  int indicating whether we are within a CDATA section | 
|  | 3361 | * | 
|  | 3362 | * parse a CharData section.this is the fallback function | 
|  | 3363 | * of xmlParseCharData() when the parsing requires handling | 
|  | 3364 | * of non-ASCII characters. | 
|  | 3365 | */ | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3366 | void | 
|  | 3367 | xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3368 | xmlChar buf[XML_PARSER_BIG_BUFFER_SIZE + 5]; | 
|  | 3369 | int nbchar = 0; | 
|  | 3370 | int cur, l; | 
|  | 3371 | int count = 0; | 
|  | 3372 |  | 
|  | 3373 | SHRINK; | 
|  | 3374 | GROW; | 
|  | 3375 | cur = CUR_CHAR(l); | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3376 | while ((cur != '<') && /* checked */ | 
|  | 3377 | (cur != '&') && | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 3378 | (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3379 | if ((cur == ']') && (NXT(1) == ']') && | 
|  | 3380 | (NXT(2) == '>')) { | 
|  | 3381 | if (cdata) break; | 
|  | 3382 | else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3383 | xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3384 | } | 
|  | 3385 | } | 
|  | 3386 | COPY_BUF(l,buf,nbchar,cur); | 
|  | 3387 | if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) { | 
| Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 3388 | buf[nbchar] = 0; | 
|  | 3389 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3390 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3391 | * OK the segment is to be consumed as chars. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3392 | */ | 
|  | 3393 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3394 | if (areBlanks(ctxt, buf, nbchar, 0)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3395 | if (ctxt->sax->ignorableWhitespace != NULL) | 
|  | 3396 | ctxt->sax->ignorableWhitespace(ctxt->userData, | 
|  | 3397 | buf, nbchar); | 
|  | 3398 | } else { | 
|  | 3399 | if (ctxt->sax->characters != NULL) | 
|  | 3400 | ctxt->sax->characters(ctxt->userData, buf, nbchar); | 
|  | 3401 | } | 
|  | 3402 | } | 
|  | 3403 | nbchar = 0; | 
|  | 3404 | } | 
|  | 3405 | count++; | 
|  | 3406 | if (count > 50) { | 
|  | 3407 | GROW; | 
|  | 3408 | count = 0; | 
|  | 3409 | } | 
|  | 3410 | NEXTL(l); | 
|  | 3411 | cur = CUR_CHAR(l); | 
|  | 3412 | } | 
|  | 3413 | if (nbchar != 0) { | 
| Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 3414 | buf[nbchar] = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3415 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3416 | * OK the segment is to be consumed as chars. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3417 | */ | 
|  | 3418 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 3419 | if (areBlanks(ctxt, buf, nbchar, 0)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3420 | if (ctxt->sax->ignorableWhitespace != NULL) | 
|  | 3421 | ctxt->sax->ignorableWhitespace(ctxt->userData, buf, nbchar); | 
|  | 3422 | } else { | 
|  | 3423 | if (ctxt->sax->characters != NULL) | 
|  | 3424 | ctxt->sax->characters(ctxt->userData, buf, nbchar); | 
|  | 3425 | } | 
|  | 3426 | } | 
|  | 3427 | } | 
|  | 3428 | } | 
|  | 3429 |  | 
|  | 3430 | /** | 
|  | 3431 | * xmlParseExternalID: | 
|  | 3432 | * @ctxt:  an XML parser context | 
|  | 3433 | * @publicID:  a xmlChar** receiving PubidLiteral | 
|  | 3434 | * @strict: indicate whether we should restrict parsing to only | 
|  | 3435 | *          production [75], see NOTE below | 
|  | 3436 | * | 
|  | 3437 | * Parse an External ID or a Public ID | 
|  | 3438 | * | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3439 | * NOTE: Productions [75] and [83] interact badly since [75] can generate | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3440 | *       'PUBLIC' S PubidLiteral S SystemLiteral | 
|  | 3441 | * | 
|  | 3442 | * [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 
|  | 3443 | *                   | 'PUBLIC' S PubidLiteral S SystemLiteral | 
|  | 3444 | * | 
|  | 3445 | * [83] PublicID ::= 'PUBLIC' S PubidLiteral | 
|  | 3446 | * | 
|  | 3447 | * Returns the function returns SystemLiteral and in the second | 
|  | 3448 | *                case publicID receives PubidLiteral, is strict is off | 
|  | 3449 | *                it is possible to return NULL and have publicID set. | 
|  | 3450 | */ | 
|  | 3451 |  | 
|  | 3452 | xmlChar * | 
|  | 3453 | xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict) { | 
|  | 3454 | xmlChar *URI = NULL; | 
|  | 3455 |  | 
|  | 3456 | SHRINK; | 
| Daniel Veillard | 146c912 | 2001-03-22 15:22:27 +0000 | [diff] [blame] | 3457 |  | 
|  | 3458 | *publicID = NULL; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 3459 | if (CMP6(CUR_PTR, 'S', 'Y', 'S', 'T', 'E', 'M')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3460 | SKIP(6); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3461 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3462 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 3463 | "Space required after 'SYSTEM'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3464 | } | 
|  | 3465 | SKIP_BLANKS; | 
|  | 3466 | URI = xmlParseSystemLiteral(ctxt); | 
|  | 3467 | if (URI == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3468 | xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3469 | } | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 3470 | } else if (CMP6(CUR_PTR, 'P', 'U', 'B', 'L', 'I', 'C')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3471 | SKIP(6); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3472 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3473 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3474 | "Space required after 'PUBLIC'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3475 | } | 
|  | 3476 | SKIP_BLANKS; | 
|  | 3477 | *publicID = xmlParsePubidLiteral(ctxt); | 
|  | 3478 | if (*publicID == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3479 | xmlFatalErr(ctxt, XML_ERR_PUBID_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3480 | } | 
|  | 3481 | if (strict) { | 
|  | 3482 | /* | 
|  | 3483 | * We don't handle [83] so "S SystemLiteral" is required. | 
|  | 3484 | */ | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3485 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3486 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3487 | "Space required after the Public Identifier\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3488 | } | 
|  | 3489 | } else { | 
|  | 3490 | /* | 
|  | 3491 | * We handle [83] so we return immediately, if | 
|  | 3492 | * "S SystemLiteral" is not detected. From a purely parsing | 
|  | 3493 | * point of view that's a nice mess. | 
|  | 3494 | */ | 
|  | 3495 | const xmlChar *ptr; | 
|  | 3496 | GROW; | 
|  | 3497 |  | 
|  | 3498 | ptr = CUR_PTR; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3499 | if (!IS_BLANK_CH(*ptr)) return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3500 |  | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3501 | while (IS_BLANK_CH(*ptr)) ptr++; /* TODO: dangerous, fix ! */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3502 | if ((*ptr != '\'') && (*ptr != '"')) return(NULL); | 
|  | 3503 | } | 
|  | 3504 | SKIP_BLANKS; | 
|  | 3505 | URI = xmlParseSystemLiteral(ctxt); | 
|  | 3506 | if (URI == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3507 | xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3508 | } | 
|  | 3509 | } | 
|  | 3510 | return(URI); | 
|  | 3511 | } | 
|  | 3512 |  | 
|  | 3513 | /** | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3514 | * xmlParseCommentComplex: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3515 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3516 | * @buf:  the already parsed part of the buffer | 
|  | 3517 | * @len:  number of bytes filles in the buffer | 
|  | 3518 | * @size:  allocated size of the buffer | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3519 | * | 
|  | 3520 | * Skip an XML (SGML) comment <!-- .... --> | 
|  | 3521 | *  The spec says that "For compatibility, the string "--" (double-hyphen) | 
|  | 3522 | *  must not occur within comments. " | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3523 | * This is the slow routine in case the accelerator for ascii didn't work | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3524 | * | 
|  | 3525 | * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' | 
|  | 3526 | */ | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3527 | static void | 
|  | 3528 | xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3529 | int q, ql; | 
|  | 3530 | int r, rl; | 
|  | 3531 | int cur, l; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3532 | xmlParserInputPtr input = ctxt->input; | 
|  | 3533 | int count = 0; | 
|  | 3534 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3535 | if (buf == NULL) { | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3536 | len = 0; | 
|  | 3537 | size = XML_PARSER_BUFFER_SIZE; | 
|  | 3538 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
|  | 3539 | if (buf == NULL) { | 
|  | 3540 | xmlErrMemory(ctxt, NULL); | 
|  | 3541 | return; | 
|  | 3542 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3543 | } | 
|  | 3544 | q = CUR_CHAR(ql); | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3545 | if (q == 0) | 
|  | 3546 | goto not_terminated; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3547 | NEXTL(ql); | 
|  | 3548 | r = CUR_CHAR(rl); | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3549 | if (r == 0) | 
|  | 3550 | goto not_terminated; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3551 | NEXTL(rl); | 
|  | 3552 | cur = CUR_CHAR(l); | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3553 | if (cur == 0) | 
|  | 3554 | goto not_terminated; | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 3555 | while (IS_CHAR(cur) && /* checked */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3556 | ((cur != '>') || | 
|  | 3557 | (r != '-') || (q != '-'))) { | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 3558 | if ((r == '-') && (q == '-')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3559 | xmlFatalErr(ctxt, XML_ERR_HYPHEN_IN_COMMENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3560 | } | 
|  | 3561 | if (len + 5 >= size) { | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 3562 | xmlChar *new_buf; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3563 | size *= 2; | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 3564 | new_buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 3565 | if (new_buf == NULL) { | 
|  | 3566 | xmlFree (buf); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3567 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3568 | return; | 
|  | 3569 | } | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 3570 | buf = new_buf; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3571 | } | 
|  | 3572 | COPY_BUF(ql,buf,len,q); | 
|  | 3573 | q = r; | 
|  | 3574 | ql = rl; | 
|  | 3575 | r = cur; | 
|  | 3576 | rl = l; | 
|  | 3577 |  | 
|  | 3578 | count++; | 
|  | 3579 | if (count > 50) { | 
|  | 3580 | GROW; | 
|  | 3581 | count = 0; | 
|  | 3582 | } | 
|  | 3583 | NEXTL(l); | 
|  | 3584 | cur = CUR_CHAR(l); | 
|  | 3585 | if (cur == 0) { | 
|  | 3586 | SHRINK; | 
|  | 3587 | GROW; | 
|  | 3588 | cur = CUR_CHAR(l); | 
|  | 3589 | } | 
|  | 3590 | } | 
|  | 3591 | buf[len] = 0; | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 3592 | if (!IS_CHAR(cur)) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 3593 | xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3594 | "Comment not terminated \n<!--%.50s\n", buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3595 | xmlFree(buf); | 
|  | 3596 | } else { | 
|  | 3597 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3598 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 3599 | "Comment doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3600 | } | 
|  | 3601 | NEXT; | 
|  | 3602 | if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) && | 
|  | 3603 | (!ctxt->disableSAX)) | 
|  | 3604 | ctxt->sax->comment(ctxt->userData, buf); | 
|  | 3605 | xmlFree(buf); | 
|  | 3606 | } | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3607 | return; | 
|  | 3608 | not_terminated: | 
|  | 3609 | xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, | 
|  | 3610 | "Comment not terminated\n", NULL); | 
|  | 3611 | xmlFree(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3612 | } | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3613 | /** | 
|  | 3614 | * xmlParseComment: | 
|  | 3615 | * @ctxt:  an XML parser context | 
|  | 3616 | * | 
|  | 3617 | * Skip an XML (SGML) comment <!-- .... --> | 
|  | 3618 | *  The spec says that "For compatibility, the string "--" (double-hyphen) | 
|  | 3619 | *  must not occur within comments. " | 
|  | 3620 | * | 
|  | 3621 | * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' | 
|  | 3622 | */ | 
|  | 3623 | void | 
|  | 3624 | xmlParseComment(xmlParserCtxtPtr ctxt) { | 
|  | 3625 | xmlChar *buf = NULL; | 
|  | 3626 | int size = XML_PARSER_BUFFER_SIZE; | 
| Daniel Veillard | 316a5c3 | 2005-01-23 22:56:39 +0000 | [diff] [blame] | 3627 | int len = 0; | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 3628 | xmlParserInputState state; | 
|  | 3629 | const xmlChar *in; | 
|  | 3630 | int nbchar = 0, ccol; | 
|  | 3631 |  | 
|  | 3632 | /* | 
|  | 3633 | * Check that there is a comment right here. | 
|  | 3634 | */ | 
|  | 3635 | if ((RAW != '<') || (NXT(1) != '!') || | 
|  | 3636 | (NXT(2) != '-') || (NXT(3) != '-')) return; | 
|  | 3637 |  | 
|  | 3638 | state = ctxt->instate; | 
|  | 3639 | ctxt->instate = XML_PARSER_COMMENT; | 
|  | 3640 | SKIP(4); | 
|  | 3641 | SHRINK; | 
|  | 3642 | GROW; | 
|  | 3643 |  | 
|  | 3644 | /* | 
|  | 3645 | * Accelerated common case where input don't need to be | 
|  | 3646 | * modified before passing it to the handler. | 
|  | 3647 | */ | 
|  | 3648 | in = ctxt->input->cur; | 
|  | 3649 | do { | 
|  | 3650 | if (*in == 0xA) { | 
|  | 3651 | ctxt->input->line++; ctxt->input->col = 1; | 
|  | 3652 | in++; | 
|  | 3653 | while (*in == 0xA) { | 
|  | 3654 | ctxt->input->line++; ctxt->input->col = 1; | 
|  | 3655 | in++; | 
|  | 3656 | } | 
|  | 3657 | } | 
|  | 3658 | get_more: | 
|  | 3659 | ccol = ctxt->input->col; | 
|  | 3660 | while (((*in > '-') && (*in <= 0x7F)) || | 
|  | 3661 | ((*in >= 0x20) && (*in < '-')) || | 
|  | 3662 | (*in == 0x09)) { | 
|  | 3663 | in++; | 
|  | 3664 | ccol++; | 
|  | 3665 | } | 
|  | 3666 | ctxt->input->col = ccol; | 
|  | 3667 | if (*in == 0xA) { | 
|  | 3668 | ctxt->input->line++; ctxt->input->col = 1; | 
|  | 3669 | in++; | 
|  | 3670 | while (*in == 0xA) { | 
|  | 3671 | ctxt->input->line++; ctxt->input->col = 1; | 
|  | 3672 | in++; | 
|  | 3673 | } | 
|  | 3674 | goto get_more; | 
|  | 3675 | } | 
|  | 3676 | nbchar = in - ctxt->input->cur; | 
|  | 3677 | /* | 
|  | 3678 | * save current set of data | 
|  | 3679 | */ | 
|  | 3680 | if (nbchar > 0) { | 
|  | 3681 | if ((ctxt->sax != NULL) && | 
|  | 3682 | (ctxt->sax->comment != NULL)) { | 
|  | 3683 | if (buf == NULL) { | 
|  | 3684 | if ((*in == '-') && (in[1] == '-')) | 
|  | 3685 | size = nbchar + 1; | 
|  | 3686 | else | 
|  | 3687 | size = XML_PARSER_BUFFER_SIZE + nbchar; | 
|  | 3688 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
|  | 3689 | if (buf == NULL) { | 
|  | 3690 | xmlErrMemory(ctxt, NULL); | 
|  | 3691 | ctxt->instate = state; | 
|  | 3692 | return; | 
|  | 3693 | } | 
|  | 3694 | len = 0; | 
|  | 3695 | } else if (len + nbchar + 1 >= size) { | 
|  | 3696 | xmlChar *new_buf; | 
|  | 3697 | size  += len + nbchar + XML_PARSER_BUFFER_SIZE; | 
|  | 3698 | new_buf = (xmlChar *) xmlRealloc(buf, | 
|  | 3699 | size * sizeof(xmlChar)); | 
|  | 3700 | if (new_buf == NULL) { | 
|  | 3701 | xmlFree (buf); | 
|  | 3702 | xmlErrMemory(ctxt, NULL); | 
|  | 3703 | ctxt->instate = state; | 
|  | 3704 | return; | 
|  | 3705 | } | 
|  | 3706 | buf = new_buf; | 
|  | 3707 | } | 
|  | 3708 | memcpy(&buf[len], ctxt->input->cur, nbchar); | 
|  | 3709 | len += nbchar; | 
|  | 3710 | buf[len] = 0; | 
|  | 3711 | } | 
|  | 3712 | } | 
|  | 3713 | ctxt->input->cur = in; | 
|  | 3714 | if (*in == 0xA) | 
|  | 3715 |  | 
|  | 3716 | if (*in == 0xD) { | 
|  | 3717 | in++; | 
|  | 3718 | if (*in == 0xA) { | 
|  | 3719 | ctxt->input->cur = in; | 
|  | 3720 | in++; | 
|  | 3721 | ctxt->input->line++; ctxt->input->col = 1; | 
|  | 3722 | continue; /* while */ | 
|  | 3723 | } | 
|  | 3724 | in--; | 
|  | 3725 | } | 
|  | 3726 | SHRINK; | 
|  | 3727 | GROW; | 
|  | 3728 | in = ctxt->input->cur; | 
|  | 3729 | if (*in == '-') { | 
|  | 3730 | if (in[1] == '-') { | 
|  | 3731 | if (in[2] == '>') { | 
|  | 3732 | SKIP(3); | 
|  | 3733 | if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) && | 
|  | 3734 | (!ctxt->disableSAX)) { | 
|  | 3735 | if (buf != NULL) | 
|  | 3736 | ctxt->sax->comment(ctxt->userData, buf); | 
|  | 3737 | else | 
|  | 3738 | ctxt->sax->comment(ctxt->userData, BAD_CAST ""); | 
|  | 3739 | } | 
|  | 3740 | if (buf != NULL) | 
|  | 3741 | xmlFree(buf); | 
|  | 3742 | ctxt->instate = state; | 
|  | 3743 | return; | 
|  | 3744 | } | 
|  | 3745 | if (buf != NULL) | 
|  | 3746 | xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, | 
|  | 3747 | "Comment not terminated \n<!--%.50s\n", | 
|  | 3748 | buf); | 
|  | 3749 | else | 
|  | 3750 | xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, | 
|  | 3751 | "Comment not terminated \n", NULL); | 
|  | 3752 | in++; | 
|  | 3753 | ctxt->input->col++; | 
|  | 3754 | } | 
|  | 3755 | in++; | 
|  | 3756 | ctxt->input->col++; | 
|  | 3757 | goto get_more; | 
|  | 3758 | } | 
|  | 3759 | } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09)); | 
|  | 3760 | xmlParseCommentComplex(ctxt, buf, len, size); | 
|  | 3761 | ctxt->instate = state; | 
|  | 3762 | return; | 
|  | 3763 | } | 
|  | 3764 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3765 |  | 
|  | 3766 | /** | 
|  | 3767 | * xmlParsePITarget: | 
|  | 3768 | * @ctxt:  an XML parser context | 
|  | 3769 | * | 
|  | 3770 | * parse the name of a PI | 
|  | 3771 | * | 
|  | 3772 | * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) | 
|  | 3773 | * | 
|  | 3774 | * Returns the PITarget name or NULL | 
|  | 3775 | */ | 
|  | 3776 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 3777 | const xmlChar * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3778 | xmlParsePITarget(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 3779 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3780 |  | 
|  | 3781 | name = xmlParseName(ctxt); | 
|  | 3782 | if ((name != NULL) && | 
|  | 3783 | ((name[0] == 'x') || (name[0] == 'X')) && | 
|  | 3784 | ((name[1] == 'm') || (name[1] == 'M')) && | 
|  | 3785 | ((name[2] == 'l') || (name[2] == 'L'))) { | 
|  | 3786 | int i; | 
|  | 3787 | if ((name[0] == 'x') && (name[1] == 'm') && | 
|  | 3788 | (name[2] == 'l') && (name[3] == 0)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3789 | xmlFatalErrMsg(ctxt, XML_ERR_RESERVED_XML_NAME, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3790 | "XML declaration allowed only at the start of the document\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3791 | return(name); | 
|  | 3792 | } else if (name[3] == 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3793 | xmlFatalErr(ctxt, XML_ERR_RESERVED_XML_NAME, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3794 | return(name); | 
|  | 3795 | } | 
|  | 3796 | for (i = 0;;i++) { | 
|  | 3797 | if (xmlW3CPIs[i] == NULL) break; | 
|  | 3798 | if (xmlStrEqual(name, (const xmlChar *)xmlW3CPIs[i])) | 
|  | 3799 | return(name); | 
|  | 3800 | } | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 3801 | xmlWarningMsg(ctxt, XML_ERR_RESERVED_XML_NAME, | 
|  | 3802 | "xmlParsePITarget: invalid name prefix 'xml'\n", | 
|  | 3803 | NULL, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3804 | } | 
|  | 3805 | return(name); | 
|  | 3806 | } | 
|  | 3807 |  | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3808 | #ifdef LIBXML_CATALOG_ENABLED | 
|  | 3809 | /** | 
|  | 3810 | * xmlParseCatalogPI: | 
|  | 3811 | * @ctxt:  an XML parser context | 
|  | 3812 | * @catalog:  the PI value string | 
|  | 3813 | * | 
|  | 3814 | * parse an XML Catalog Processing Instruction. | 
|  | 3815 | * | 
|  | 3816 | * <?oasis-xml-catalog catalog="http://example.com/catalog.xml"?> | 
|  | 3817 | * | 
|  | 3818 | * Occurs only if allowed by the user and if happening in the Misc | 
|  | 3819 | * part of the document before any doctype informations | 
|  | 3820 | * This will add the given catalog to the parsing context in order | 
|  | 3821 | * to be used if there is a resolution need further down in the document | 
|  | 3822 | */ | 
|  | 3823 |  | 
|  | 3824 | static void | 
|  | 3825 | xmlParseCatalogPI(xmlParserCtxtPtr ctxt, const xmlChar *catalog) { | 
|  | 3826 | xmlChar *URL = NULL; | 
|  | 3827 | const xmlChar *tmp, *base; | 
|  | 3828 | xmlChar marker; | 
|  | 3829 |  | 
|  | 3830 | tmp = catalog; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3831 | while (IS_BLANK_CH(*tmp)) tmp++; | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3832 | if (xmlStrncmp(tmp, BAD_CAST"catalog", 7)) | 
|  | 3833 | goto error; | 
|  | 3834 | tmp += 7; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3835 | while (IS_BLANK_CH(*tmp)) tmp++; | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3836 | if (*tmp != '=') { | 
|  | 3837 | return; | 
|  | 3838 | } | 
|  | 3839 | tmp++; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3840 | while (IS_BLANK_CH(*tmp)) tmp++; | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3841 | marker = *tmp; | 
|  | 3842 | if ((marker != '\'') && (marker != '"')) | 
|  | 3843 | goto error; | 
|  | 3844 | tmp++; | 
|  | 3845 | base = tmp; | 
|  | 3846 | while ((*tmp != 0) && (*tmp != marker)) tmp++; | 
|  | 3847 | if (*tmp == 0) | 
|  | 3848 | goto error; | 
|  | 3849 | URL = xmlStrndup(base, tmp - base); | 
|  | 3850 | tmp++; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3851 | while (IS_BLANK_CH(*tmp)) tmp++; | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3852 | if (*tmp != 0) | 
|  | 3853 | goto error; | 
|  | 3854 |  | 
|  | 3855 | if (URL != NULL) { | 
|  | 3856 | ctxt->catalogs = xmlCatalogAddLocal(ctxt->catalogs, URL); | 
|  | 3857 | xmlFree(URL); | 
|  | 3858 | } | 
|  | 3859 | return; | 
|  | 3860 |  | 
|  | 3861 | error: | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 3862 | xmlWarningMsg(ctxt, XML_WAR_CATALOG_PI, | 
|  | 3863 | "Catalog PI syntax error: %s\n", | 
|  | 3864 | catalog, NULL); | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3865 | if (URL != NULL) | 
|  | 3866 | xmlFree(URL); | 
|  | 3867 | } | 
|  | 3868 | #endif | 
|  | 3869 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3870 | /** | 
|  | 3871 | * xmlParsePI: | 
|  | 3872 | * @ctxt:  an XML parser context | 
|  | 3873 | * | 
|  | 3874 | * parse an XML Processing Instruction. | 
|  | 3875 | * | 
|  | 3876 | * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' | 
|  | 3877 | * | 
|  | 3878 | * The processing is transfered to SAX once parsed. | 
|  | 3879 | */ | 
|  | 3880 |  | 
|  | 3881 | void | 
|  | 3882 | xmlParsePI(xmlParserCtxtPtr ctxt) { | 
|  | 3883 | xmlChar *buf = NULL; | 
|  | 3884 | int len = 0; | 
|  | 3885 | int size = XML_PARSER_BUFFER_SIZE; | 
|  | 3886 | int cur, l; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 3887 | const xmlChar *target; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3888 | xmlParserInputState state; | 
|  | 3889 | int count = 0; | 
|  | 3890 |  | 
|  | 3891 | if ((RAW == '<') && (NXT(1) == '?')) { | 
|  | 3892 | xmlParserInputPtr input = ctxt->input; | 
|  | 3893 | state = ctxt->instate; | 
|  | 3894 | ctxt->instate = XML_PARSER_PI; | 
|  | 3895 | /* | 
|  | 3896 | * this is a Processing Instruction. | 
|  | 3897 | */ | 
|  | 3898 | SKIP(2); | 
|  | 3899 | SHRINK; | 
|  | 3900 |  | 
|  | 3901 | /* | 
|  | 3902 | * Parse the target name and check for special support like | 
|  | 3903 | * namespace. | 
|  | 3904 | */ | 
|  | 3905 | target = xmlParsePITarget(ctxt); | 
|  | 3906 | if (target != NULL) { | 
|  | 3907 | if ((RAW == '?') && (NXT(1) == '>')) { | 
|  | 3908 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3909 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 3910 | "PI declaration doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3911 | } | 
|  | 3912 | SKIP(2); | 
|  | 3913 |  | 
|  | 3914 | /* | 
|  | 3915 | * SAX: PI detected. | 
|  | 3916 | */ | 
|  | 3917 | if ((ctxt->sax) && (!ctxt->disableSAX) && | 
|  | 3918 | (ctxt->sax->processingInstruction != NULL)) | 
|  | 3919 | ctxt->sax->processingInstruction(ctxt->userData, | 
|  | 3920 | target, NULL); | 
|  | 3921 | ctxt->instate = state; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3922 | return; | 
|  | 3923 | } | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 3924 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3925 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3926 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3927 | ctxt->instate = state; | 
|  | 3928 | return; | 
|  | 3929 | } | 
|  | 3930 | cur = CUR; | 
|  | 3931 | if (!IS_BLANK(cur)) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 3932 | xmlFatalErrMsgStr(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 3933 | "ParsePI: PI %s space expected\n", target); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3934 | } | 
|  | 3935 | SKIP_BLANKS; | 
|  | 3936 | cur = CUR_CHAR(l); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 3937 | while (IS_CHAR(cur) && /* checked */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3938 | ((cur != '?') || (NXT(1) != '>'))) { | 
|  | 3939 | if (len + 5 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3940 | xmlChar *tmp; | 
|  | 3941 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3942 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3943 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 3944 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3945 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3946 | xmlFree(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3947 | ctxt->instate = state; | 
|  | 3948 | return; | 
|  | 3949 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 3950 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3951 | } | 
|  | 3952 | count++; | 
|  | 3953 | if (count > 50) { | 
|  | 3954 | GROW; | 
|  | 3955 | count = 0; | 
|  | 3956 | } | 
|  | 3957 | COPY_BUF(l,buf,len,cur); | 
|  | 3958 | NEXTL(l); | 
|  | 3959 | cur = CUR_CHAR(l); | 
|  | 3960 | if (cur == 0) { | 
|  | 3961 | SHRINK; | 
|  | 3962 | GROW; | 
|  | 3963 | cur = CUR_CHAR(l); | 
|  | 3964 | } | 
|  | 3965 | } | 
|  | 3966 | buf[len] = 0; | 
|  | 3967 | if (cur != '?') { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 3968 | xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED, | 
|  | 3969 | "ParsePI: PI %s never end ...\n", target); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3970 | } else { | 
|  | 3971 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 3972 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 3973 | "PI declaration doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3974 | } | 
|  | 3975 | SKIP(2); | 
|  | 3976 |  | 
| Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3977 | #ifdef LIBXML_CATALOG_ENABLED | 
|  | 3978 | if (((state == XML_PARSER_MISC) || | 
|  | 3979 | (state == XML_PARSER_START)) && | 
|  | 3980 | (xmlStrEqual(target, XML_CATALOG_PI))) { | 
|  | 3981 | xmlCatalogAllow allow = xmlCatalogGetDefaults(); | 
|  | 3982 | if ((allow == XML_CATA_ALLOW_DOCUMENT) || | 
|  | 3983 | (allow == XML_CATA_ALLOW_ALL)) | 
|  | 3984 | xmlParseCatalogPI(ctxt, buf); | 
|  | 3985 | } | 
|  | 3986 | #endif | 
|  | 3987 |  | 
|  | 3988 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3989 | /* | 
|  | 3990 | * SAX: PI detected. | 
|  | 3991 | */ | 
|  | 3992 | if ((ctxt->sax) && (!ctxt->disableSAX) && | 
|  | 3993 | (ctxt->sax->processingInstruction != NULL)) | 
|  | 3994 | ctxt->sax->processingInstruction(ctxt->userData, | 
|  | 3995 | target, buf); | 
|  | 3996 | } | 
|  | 3997 | xmlFree(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3998 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 3999 | xmlFatalErr(ctxt, XML_ERR_PI_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4000 | } | 
|  | 4001 | ctxt->instate = state; | 
|  | 4002 | } | 
|  | 4003 | } | 
|  | 4004 |  | 
|  | 4005 | /** | 
|  | 4006 | * xmlParseNotationDecl: | 
|  | 4007 | * @ctxt:  an XML parser context | 
|  | 4008 | * | 
|  | 4009 | * parse a notation declaration | 
|  | 4010 | * | 
|  | 4011 | * [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID |  PublicID) S? '>' | 
|  | 4012 | * | 
|  | 4013 | * Hence there is actually 3 choices: | 
|  | 4014 | *     'PUBLIC' S PubidLiteral | 
|  | 4015 | *     'PUBLIC' S PubidLiteral S SystemLiteral | 
|  | 4016 | * and 'SYSTEM' S SystemLiteral | 
|  | 4017 | * | 
|  | 4018 | * See the NOTE on xmlParseExternalID(). | 
|  | 4019 | */ | 
|  | 4020 |  | 
|  | 4021 | void | 
|  | 4022 | xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4023 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4024 | xmlChar *Pubid; | 
|  | 4025 | xmlChar *Systemid; | 
|  | 4026 |  | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4027 | if (CMP10(CUR_PTR, '<', '!', 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4028 | xmlParserInputPtr input = ctxt->input; | 
|  | 4029 | SHRINK; | 
|  | 4030 | SKIP(10); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4031 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4032 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4033 | "Space required after '<!NOTATION'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4034 | return; | 
|  | 4035 | } | 
|  | 4036 | SKIP_BLANKS; | 
|  | 4037 |  | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4038 | name = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4039 | if (name == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4040 | xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4041 | return; | 
|  | 4042 | } | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4043 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4044 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4045 | "Space required after the NOTATION name'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4046 | return; | 
|  | 4047 | } | 
|  | 4048 | SKIP_BLANKS; | 
|  | 4049 |  | 
|  | 4050 | /* | 
|  | 4051 | * Parse the IDs. | 
|  | 4052 | */ | 
|  | 4053 | Systemid = xmlParseExternalID(ctxt, &Pubid, 0); | 
|  | 4054 | SKIP_BLANKS; | 
|  | 4055 |  | 
|  | 4056 | if (RAW == '>') { | 
|  | 4057 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4058 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4059 | "Notation declaration doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4060 | } | 
|  | 4061 | NEXT; | 
|  | 4062 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && | 
|  | 4063 | (ctxt->sax->notationDecl != NULL)) | 
|  | 4064 | ctxt->sax->notationDecl(ctxt->userData, name, Pubid, Systemid); | 
|  | 4065 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4066 | xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4067 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4068 | if (Systemid != NULL) xmlFree(Systemid); | 
|  | 4069 | if (Pubid != NULL) xmlFree(Pubid); | 
|  | 4070 | } | 
|  | 4071 | } | 
|  | 4072 |  | 
|  | 4073 | /** | 
|  | 4074 | * xmlParseEntityDecl: | 
|  | 4075 | * @ctxt:  an XML parser context | 
|  | 4076 | * | 
|  | 4077 | * parse <!ENTITY declarations | 
|  | 4078 | * | 
|  | 4079 | * [70] EntityDecl ::= GEDecl | PEDecl | 
|  | 4080 | * | 
|  | 4081 | * [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>' | 
|  | 4082 | * | 
|  | 4083 | * [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>' | 
|  | 4084 | * | 
|  | 4085 | * [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?) | 
|  | 4086 | * | 
|  | 4087 | * [74] PEDef ::= EntityValue | ExternalID | 
|  | 4088 | * | 
|  | 4089 | * [76] NDataDecl ::= S 'NDATA' S Name | 
|  | 4090 | * | 
|  | 4091 | * [ VC: Notation Declared ] | 
|  | 4092 | * The Name must match the declared name of a notation. | 
|  | 4093 | */ | 
|  | 4094 |  | 
|  | 4095 | void | 
|  | 4096 | xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4097 | const xmlChar *name = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4098 | xmlChar *value = NULL; | 
|  | 4099 | xmlChar *URI = NULL, *literal = NULL; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4100 | const xmlChar *ndata = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4101 | int isParameter = 0; | 
|  | 4102 | xmlChar *orig = NULL; | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 4103 | int skipped; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4104 |  | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 4105 | /* GROW; done in the caller */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4106 | if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T', 'I', 'T', 'Y')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4107 | xmlParserInputPtr input = ctxt->input; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4108 | SHRINK; | 
|  | 4109 | SKIP(8); | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 4110 | skipped = SKIP_BLANKS; | 
|  | 4111 | if (skipped == 0) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4112 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4113 | "Space required after '<!ENTITY'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4114 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4115 |  | 
|  | 4116 | if (RAW == '%') { | 
|  | 4117 | NEXT; | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 4118 | skipped = SKIP_BLANKS; | 
|  | 4119 | if (skipped == 0) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4120 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4121 | "Space required after '%'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4122 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4123 | isParameter = 1; | 
|  | 4124 | } | 
|  | 4125 |  | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4126 | name = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4127 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4128 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 4129 | "xmlParseEntityDecl: no name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4130 | return; | 
|  | 4131 | } | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 4132 | skipped = SKIP_BLANKS; | 
|  | 4133 | if (skipped == 0) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4134 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4135 | "Space required after the entity name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4136 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4137 |  | 
| Daniel Veillard | f5582f1 | 2002-06-11 10:08:16 +0000 | [diff] [blame] | 4138 | ctxt->instate = XML_PARSER_ENTITY_DECL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4139 | /* | 
|  | 4140 | * handle the various case of definitions... | 
|  | 4141 | */ | 
|  | 4142 | if (isParameter) { | 
|  | 4143 | if ((RAW == '"') || (RAW == '\'')) { | 
|  | 4144 | value = xmlParseEntityValue(ctxt, &orig); | 
|  | 4145 | if (value) { | 
|  | 4146 | if ((ctxt->sax != NULL) && | 
|  | 4147 | (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL)) | 
|  | 4148 | ctxt->sax->entityDecl(ctxt->userData, name, | 
|  | 4149 | XML_INTERNAL_PARAMETER_ENTITY, | 
|  | 4150 | NULL, NULL, value); | 
|  | 4151 | } | 
|  | 4152 | } else { | 
|  | 4153 | URI = xmlParseExternalID(ctxt, &literal, 1); | 
|  | 4154 | if ((URI == NULL) && (literal == NULL)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4155 | xmlFatalErr(ctxt, XML_ERR_VALUE_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4156 | } | 
|  | 4157 | if (URI) { | 
|  | 4158 | xmlURIPtr uri; | 
|  | 4159 |  | 
|  | 4160 | uri = xmlParseURI((const char *) URI); | 
|  | 4161 | if (uri == NULL) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 4162 | xmlErrMsgStr(ctxt, XML_ERR_INVALID_URI, | 
|  | 4163 | "Invalid URI: %s\n", URI); | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 4164 | /* | 
|  | 4165 | * This really ought to be a well formedness error | 
|  | 4166 | * but the XML Core WG decided otherwise c.f. issue | 
|  | 4167 | * E26 of the XML erratas. | 
|  | 4168 | */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4169 | } else { | 
|  | 4170 | if (uri->fragment != NULL) { | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 4171 | /* | 
|  | 4172 | * Okay this is foolish to block those but not | 
|  | 4173 | * invalid URIs. | 
|  | 4174 | */ | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4175 | xmlFatalErr(ctxt, XML_ERR_URI_FRAGMENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4176 | } else { | 
|  | 4177 | if ((ctxt->sax != NULL) && | 
|  | 4178 | (!ctxt->disableSAX) && | 
|  | 4179 | (ctxt->sax->entityDecl != NULL)) | 
|  | 4180 | ctxt->sax->entityDecl(ctxt->userData, name, | 
|  | 4181 | XML_EXTERNAL_PARAMETER_ENTITY, | 
|  | 4182 | literal, URI, NULL); | 
|  | 4183 | } | 
|  | 4184 | xmlFreeURI(uri); | 
|  | 4185 | } | 
|  | 4186 | } | 
|  | 4187 | } | 
|  | 4188 | } else { | 
|  | 4189 | if ((RAW == '"') || (RAW == '\'')) { | 
|  | 4190 | value = xmlParseEntityValue(ctxt, &orig); | 
|  | 4191 | if ((ctxt->sax != NULL) && | 
|  | 4192 | (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL)) | 
|  | 4193 | ctxt->sax->entityDecl(ctxt->userData, name, | 
|  | 4194 | XML_INTERNAL_GENERAL_ENTITY, | 
|  | 4195 | NULL, NULL, value); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 4196 | /* | 
|  | 4197 | * For expat compatibility in SAX mode. | 
|  | 4198 | */ | 
|  | 4199 | if ((ctxt->myDoc == NULL) || | 
|  | 4200 | (xmlStrEqual(ctxt->myDoc->version, SAX_COMPAT_MODE))) { | 
|  | 4201 | if (ctxt->myDoc == NULL) { | 
|  | 4202 | ctxt->myDoc = xmlNewDoc(SAX_COMPAT_MODE); | 
|  | 4203 | } | 
|  | 4204 | if (ctxt->myDoc->intSubset == NULL) | 
|  | 4205 | ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc, | 
|  | 4206 | BAD_CAST "fake", NULL, NULL); | 
|  | 4207 |  | 
| Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 4208 | xmlSAX2EntityDecl(ctxt, name, XML_INTERNAL_GENERAL_ENTITY, | 
|  | 4209 | NULL, NULL, value); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 4210 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4211 | } else { | 
|  | 4212 | URI = xmlParseExternalID(ctxt, &literal, 1); | 
|  | 4213 | if ((URI == NULL) && (literal == NULL)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4214 | xmlFatalErr(ctxt, XML_ERR_VALUE_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4215 | } | 
|  | 4216 | if (URI) { | 
|  | 4217 | xmlURIPtr uri; | 
|  | 4218 |  | 
|  | 4219 | uri = xmlParseURI((const char *)URI); | 
|  | 4220 | if (uri == NULL) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 4221 | xmlErrMsgStr(ctxt, XML_ERR_INVALID_URI, | 
|  | 4222 | "Invalid URI: %s\n", URI); | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 4223 | /* | 
|  | 4224 | * This really ought to be a well formedness error | 
|  | 4225 | * but the XML Core WG decided otherwise c.f. issue | 
|  | 4226 | * E26 of the XML erratas. | 
|  | 4227 | */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4228 | } else { | 
|  | 4229 | if (uri->fragment != NULL) { | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 4230 | /* | 
|  | 4231 | * Okay this is foolish to block those but not | 
|  | 4232 | * invalid URIs. | 
|  | 4233 | */ | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4234 | xmlFatalErr(ctxt, XML_ERR_URI_FRAGMENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4235 | } | 
|  | 4236 | xmlFreeURI(uri); | 
|  | 4237 | } | 
|  | 4238 | } | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4239 | if ((RAW != '>') && (!IS_BLANK_CH(CUR))) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4240 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4241 | "Space required before 'NDATA'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4242 | } | 
|  | 4243 | SKIP_BLANKS; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4244 | if (CMP5(CUR_PTR, 'N', 'D', 'A', 'T', 'A')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4245 | SKIP(5); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4246 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4247 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4248 | "Space required after 'NDATA'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4249 | } | 
|  | 4250 | SKIP_BLANKS; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4251 | ndata = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4252 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && | 
|  | 4253 | (ctxt->sax->unparsedEntityDecl != NULL)) | 
|  | 4254 | ctxt->sax->unparsedEntityDecl(ctxt->userData, name, | 
|  | 4255 | literal, URI, ndata); | 
|  | 4256 | } else { | 
|  | 4257 | if ((ctxt->sax != NULL) && | 
|  | 4258 | (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL)) | 
|  | 4259 | ctxt->sax->entityDecl(ctxt->userData, name, | 
|  | 4260 | XML_EXTERNAL_GENERAL_PARSED_ENTITY, | 
|  | 4261 | literal, URI, NULL); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 4262 | /* | 
|  | 4263 | * For expat compatibility in SAX mode. | 
|  | 4264 | * assuming the entity repalcement was asked for | 
|  | 4265 | */ | 
|  | 4266 | if ((ctxt->replaceEntities != 0) && | 
|  | 4267 | ((ctxt->myDoc == NULL) || | 
|  | 4268 | (xmlStrEqual(ctxt->myDoc->version, SAX_COMPAT_MODE)))) { | 
|  | 4269 | if (ctxt->myDoc == NULL) { | 
|  | 4270 | ctxt->myDoc = xmlNewDoc(SAX_COMPAT_MODE); | 
|  | 4271 | } | 
|  | 4272 |  | 
|  | 4273 | if (ctxt->myDoc->intSubset == NULL) | 
|  | 4274 | ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc, | 
|  | 4275 | BAD_CAST "fake", NULL, NULL); | 
| Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 4276 | xmlSAX2EntityDecl(ctxt, name, | 
|  | 4277 | XML_EXTERNAL_GENERAL_PARSED_ENTITY, | 
|  | 4278 | literal, URI, NULL); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 4279 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4280 | } | 
|  | 4281 | } | 
|  | 4282 | } | 
|  | 4283 | SKIP_BLANKS; | 
|  | 4284 | if (RAW != '>') { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 4285 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4286 | "xmlParseEntityDecl: entity %s not terminated\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4287 | } else { | 
|  | 4288 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4289 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 4290 | "Entity declaration doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4291 | } | 
|  | 4292 | NEXT; | 
|  | 4293 | } | 
|  | 4294 | if (orig != NULL) { | 
|  | 4295 | /* | 
|  | 4296 | * Ugly mechanism to save the raw entity value. | 
|  | 4297 | */ | 
|  | 4298 | xmlEntityPtr cur = NULL; | 
|  | 4299 |  | 
|  | 4300 | if (isParameter) { | 
|  | 4301 | if ((ctxt->sax != NULL) && | 
|  | 4302 | (ctxt->sax->getParameterEntity != NULL)) | 
|  | 4303 | cur = ctxt->sax->getParameterEntity(ctxt->userData, name); | 
|  | 4304 | } else { | 
|  | 4305 | if ((ctxt->sax != NULL) && | 
|  | 4306 | (ctxt->sax->getEntity != NULL)) | 
|  | 4307 | cur = ctxt->sax->getEntity(ctxt->userData, name); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 4308 | if ((cur == NULL) && (ctxt->userData==ctxt)) { | 
| Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 4309 | cur = xmlSAX2GetEntity(ctxt, name); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 4310 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4311 | } | 
|  | 4312 | if (cur != NULL) { | 
|  | 4313 | if (cur->orig != NULL) | 
|  | 4314 | xmlFree(orig); | 
|  | 4315 | else | 
|  | 4316 | cur->orig = orig; | 
|  | 4317 | } else | 
|  | 4318 | xmlFree(orig); | 
|  | 4319 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4320 | if (value != NULL) xmlFree(value); | 
|  | 4321 | if (URI != NULL) xmlFree(URI); | 
|  | 4322 | if (literal != NULL) xmlFree(literal); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4323 | } | 
|  | 4324 | } | 
|  | 4325 |  | 
|  | 4326 | /** | 
|  | 4327 | * xmlParseDefaultDecl: | 
|  | 4328 | * @ctxt:  an XML parser context | 
|  | 4329 | * @value:  Receive a possible fixed default value for the attribute | 
|  | 4330 | * | 
|  | 4331 | * Parse an attribute default declaration | 
|  | 4332 | * | 
|  | 4333 | * [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) | 
|  | 4334 | * | 
|  | 4335 | * [ VC: Required Attribute ] | 
|  | 4336 | * if the default declaration is the keyword #REQUIRED, then the | 
|  | 4337 | * attribute must be specified for all elements of the type in the | 
|  | 4338 | * attribute-list declaration. | 
|  | 4339 | * | 
|  | 4340 | * [ VC: Attribute Default Legal ] | 
|  | 4341 | * The declared default value must meet the lexical constraints of | 
|  | 4342 | * the declared attribute type c.f. xmlValidateAttributeDecl() | 
|  | 4343 | * | 
|  | 4344 | * [ VC: Fixed Attribute Default ] | 
|  | 4345 | * if an attribute has a default value declared with the #FIXED | 
|  | 4346 | * keyword, instances of that attribute must match the default value. | 
|  | 4347 | * | 
|  | 4348 | * [ WFC: No < in Attribute Values ] | 
|  | 4349 | * handled in xmlParseAttValue() | 
|  | 4350 | * | 
|  | 4351 | * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED | 
|  | 4352 | *          or XML_ATTRIBUTE_FIXED. | 
|  | 4353 | */ | 
|  | 4354 |  | 
|  | 4355 | int | 
|  | 4356 | xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) { | 
|  | 4357 | int val; | 
|  | 4358 | xmlChar *ret; | 
|  | 4359 |  | 
|  | 4360 | *value = NULL; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4361 | if (CMP9(CUR_PTR, '#', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4362 | SKIP(9); | 
|  | 4363 | return(XML_ATTRIBUTE_REQUIRED); | 
|  | 4364 | } | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4365 | if (CMP8(CUR_PTR, '#', 'I', 'M', 'P', 'L', 'I', 'E', 'D')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4366 | SKIP(8); | 
|  | 4367 | return(XML_ATTRIBUTE_IMPLIED); | 
|  | 4368 | } | 
|  | 4369 | val = XML_ATTRIBUTE_NONE; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4370 | if (CMP6(CUR_PTR, '#', 'F', 'I', 'X', 'E', 'D')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4371 | SKIP(6); | 
|  | 4372 | val = XML_ATTRIBUTE_FIXED; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4373 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4374 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4375 | "Space required after '#FIXED'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4376 | } | 
|  | 4377 | SKIP_BLANKS; | 
|  | 4378 | } | 
|  | 4379 | ret = xmlParseAttValue(ctxt); | 
|  | 4380 | ctxt->instate = XML_PARSER_DTD; | 
|  | 4381 | if (ret == NULL) { | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 4382 | xmlFatalErrMsg(ctxt, (xmlParserErrors)ctxt->errNo, | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4383 | "Attribute default value declaration error\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4384 | } else | 
|  | 4385 | *value = ret; | 
|  | 4386 | return(val); | 
|  | 4387 | } | 
|  | 4388 |  | 
|  | 4389 | /** | 
|  | 4390 | * xmlParseNotationType: | 
|  | 4391 | * @ctxt:  an XML parser context | 
|  | 4392 | * | 
|  | 4393 | * parse an Notation attribute type. | 
|  | 4394 | * | 
|  | 4395 | * Note: the leading 'NOTATION' S part has already being parsed... | 
|  | 4396 | * | 
|  | 4397 | * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' | 
|  | 4398 | * | 
|  | 4399 | * [ VC: Notation Attributes ] | 
|  | 4400 | * Values of this type must match one of the notation names included | 
|  | 4401 | * in the declaration; all notation names in the declaration must be declared. | 
|  | 4402 | * | 
|  | 4403 | * Returns: the notation attribute tree built while parsing | 
|  | 4404 | */ | 
|  | 4405 |  | 
|  | 4406 | xmlEnumerationPtr | 
|  | 4407 | xmlParseNotationType(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4408 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4409 | xmlEnumerationPtr ret = NULL, last = NULL, cur; | 
|  | 4410 |  | 
|  | 4411 | if (RAW != '(') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4412 | xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4413 | return(NULL); | 
|  | 4414 | } | 
|  | 4415 | SHRINK; | 
|  | 4416 | do { | 
|  | 4417 | NEXT; | 
|  | 4418 | SKIP_BLANKS; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4419 | name = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4420 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4421 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 4422 | "Name expected in NOTATION declaration\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4423 | return(ret); | 
|  | 4424 | } | 
|  | 4425 | cur = xmlCreateEnumeration(name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4426 | if (cur == NULL) return(ret); | 
|  | 4427 | if (last == NULL) ret = last = cur; | 
|  | 4428 | else { | 
|  | 4429 | last->next = cur; | 
|  | 4430 | last = cur; | 
|  | 4431 | } | 
|  | 4432 | SKIP_BLANKS; | 
|  | 4433 | } while (RAW == '|'); | 
|  | 4434 | if (RAW != ')') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4435 | xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4436 | if ((last != NULL) && (last != ret)) | 
|  | 4437 | xmlFreeEnumeration(last); | 
|  | 4438 | return(ret); | 
|  | 4439 | } | 
|  | 4440 | NEXT; | 
|  | 4441 | return(ret); | 
|  | 4442 | } | 
|  | 4443 |  | 
|  | 4444 | /** | 
|  | 4445 | * xmlParseEnumerationType: | 
|  | 4446 | * @ctxt:  an XML parser context | 
|  | 4447 | * | 
|  | 4448 | * parse an Enumeration attribute type. | 
|  | 4449 | * | 
|  | 4450 | * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' | 
|  | 4451 | * | 
|  | 4452 | * [ VC: Enumeration ] | 
|  | 4453 | * Values of this type must match one of the Nmtoken tokens in | 
|  | 4454 | * the declaration | 
|  | 4455 | * | 
|  | 4456 | * Returns: the enumeration attribute tree built while parsing | 
|  | 4457 | */ | 
|  | 4458 |  | 
|  | 4459 | xmlEnumerationPtr | 
|  | 4460 | xmlParseEnumerationType(xmlParserCtxtPtr ctxt) { | 
|  | 4461 | xmlChar *name; | 
|  | 4462 | xmlEnumerationPtr ret = NULL, last = NULL, cur; | 
|  | 4463 |  | 
|  | 4464 | if (RAW != '(') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4465 | xmlFatalErr(ctxt, XML_ERR_ATTLIST_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4466 | return(NULL); | 
|  | 4467 | } | 
|  | 4468 | SHRINK; | 
|  | 4469 | do { | 
|  | 4470 | NEXT; | 
|  | 4471 | SKIP_BLANKS; | 
|  | 4472 | name = xmlParseNmtoken(ctxt); | 
|  | 4473 | if (name == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4474 | xmlFatalErr(ctxt, XML_ERR_NMTOKEN_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4475 | return(ret); | 
|  | 4476 | } | 
|  | 4477 | cur = xmlCreateEnumeration(name); | 
|  | 4478 | xmlFree(name); | 
|  | 4479 | if (cur == NULL) return(ret); | 
|  | 4480 | if (last == NULL) ret = last = cur; | 
|  | 4481 | else { | 
|  | 4482 | last->next = cur; | 
|  | 4483 | last = cur; | 
|  | 4484 | } | 
|  | 4485 | SKIP_BLANKS; | 
|  | 4486 | } while (RAW == '|'); | 
|  | 4487 | if (RAW != ')') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4488 | xmlFatalErr(ctxt, XML_ERR_ATTLIST_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4489 | return(ret); | 
|  | 4490 | } | 
|  | 4491 | NEXT; | 
|  | 4492 | return(ret); | 
|  | 4493 | } | 
|  | 4494 |  | 
|  | 4495 | /** | 
|  | 4496 | * xmlParseEnumeratedType: | 
|  | 4497 | * @ctxt:  an XML parser context | 
|  | 4498 | * @tree:  the enumeration tree built while parsing | 
|  | 4499 | * | 
|  | 4500 | * parse an Enumerated attribute type. | 
|  | 4501 | * | 
|  | 4502 | * [57] EnumeratedType ::= NotationType | Enumeration | 
|  | 4503 | * | 
|  | 4504 | * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' | 
|  | 4505 | * | 
|  | 4506 | * | 
|  | 4507 | * Returns: XML_ATTRIBUTE_ENUMERATION or XML_ATTRIBUTE_NOTATION | 
|  | 4508 | */ | 
|  | 4509 |  | 
|  | 4510 | int | 
|  | 4511 | xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4512 | if (CMP8(CUR_PTR, 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4513 | SKIP(8); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4514 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4515 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4516 | "Space required after 'NOTATION'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4517 | return(0); | 
|  | 4518 | } | 
|  | 4519 | SKIP_BLANKS; | 
|  | 4520 | *tree = xmlParseNotationType(ctxt); | 
|  | 4521 | if (*tree == NULL) return(0); | 
|  | 4522 | return(XML_ATTRIBUTE_NOTATION); | 
|  | 4523 | } | 
|  | 4524 | *tree = xmlParseEnumerationType(ctxt); | 
|  | 4525 | if (*tree == NULL) return(0); | 
|  | 4526 | return(XML_ATTRIBUTE_ENUMERATION); | 
|  | 4527 | } | 
|  | 4528 |  | 
|  | 4529 | /** | 
|  | 4530 | * xmlParseAttributeType: | 
|  | 4531 | * @ctxt:  an XML parser context | 
|  | 4532 | * @tree:  the enumeration tree built while parsing | 
|  | 4533 | * | 
|  | 4534 | * parse the Attribute list def for an element | 
|  | 4535 | * | 
|  | 4536 | * [54] AttType ::= StringType | TokenizedType | EnumeratedType | 
|  | 4537 | * | 
|  | 4538 | * [55] StringType ::= 'CDATA' | 
|  | 4539 | * | 
|  | 4540 | * [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | | 
|  | 4541 | *                        'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' | 
|  | 4542 | * | 
|  | 4543 | * Validity constraints for attribute values syntax are checked in | 
|  | 4544 | * xmlValidateAttributeValue() | 
|  | 4545 | * | 
|  | 4546 | * [ VC: ID ] | 
|  | 4547 | * Values of type ID must match the Name production. A name must not | 
|  | 4548 | * appear more than once in an XML document as a value of this type; | 
|  | 4549 | * i.e., ID values must uniquely identify the elements which bear them. | 
|  | 4550 | * | 
|  | 4551 | * [ VC: One ID per Element Type ] | 
|  | 4552 | * No element type may have more than one ID attribute specified. | 
|  | 4553 | * | 
|  | 4554 | * [ VC: ID Attribute Default ] | 
|  | 4555 | * An ID attribute must have a declared default of #IMPLIED or #REQUIRED. | 
|  | 4556 | * | 
|  | 4557 | * [ VC: IDREF ] | 
|  | 4558 | * Values of type IDREF must match the Name production, and values | 
|  | 4559 | * of type IDREFS must match Names; each IDREF Name must match the value | 
|  | 4560 | * of an ID attribute on some element in the XML document; i.e. IDREF | 
|  | 4561 | * values must match the value of some ID attribute. | 
|  | 4562 | * | 
|  | 4563 | * [ VC: Entity Name ] | 
|  | 4564 | * Values of type ENTITY must match the Name production, values | 
|  | 4565 | * of type ENTITIES must match Names; each Entity Name must match the | 
|  | 4566 | * name of an unparsed entity declared in the DTD. | 
|  | 4567 | * | 
|  | 4568 | * [ VC: Name Token ] | 
|  | 4569 | * Values of type NMTOKEN must match the Nmtoken production; values | 
|  | 4570 | * of type NMTOKENS must match Nmtokens. | 
|  | 4571 | * | 
|  | 4572 | * Returns the attribute type | 
|  | 4573 | */ | 
|  | 4574 | int | 
|  | 4575 | xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { | 
|  | 4576 | SHRINK; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4577 | if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4578 | SKIP(5); | 
|  | 4579 | return(XML_ATTRIBUTE_CDATA); | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4580 | } else if (CMP6(CUR_PTR, 'I', 'D', 'R', 'E', 'F', 'S')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4581 | SKIP(6); | 
|  | 4582 | return(XML_ATTRIBUTE_IDREFS); | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4583 | } else if (CMP5(CUR_PTR, 'I', 'D', 'R', 'E', 'F')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4584 | SKIP(5); | 
|  | 4585 | return(XML_ATTRIBUTE_IDREF); | 
|  | 4586 | } else if ((RAW == 'I') && (NXT(1) == 'D')) { | 
|  | 4587 | SKIP(2); | 
|  | 4588 | return(XML_ATTRIBUTE_ID); | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4589 | } else if (CMP6(CUR_PTR, 'E', 'N', 'T', 'I', 'T', 'Y')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4590 | SKIP(6); | 
|  | 4591 | return(XML_ATTRIBUTE_ENTITY); | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4592 | } else if (CMP8(CUR_PTR, 'E', 'N', 'T', 'I', 'T', 'I', 'E', 'S')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4593 | SKIP(8); | 
|  | 4594 | return(XML_ATTRIBUTE_ENTITIES); | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4595 | } else if (CMP8(CUR_PTR, 'N', 'M', 'T', 'O', 'K', 'E', 'N', 'S')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4596 | SKIP(8); | 
|  | 4597 | return(XML_ATTRIBUTE_NMTOKENS); | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4598 | } else if (CMP7(CUR_PTR, 'N', 'M', 'T', 'O', 'K', 'E', 'N')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4599 | SKIP(7); | 
|  | 4600 | return(XML_ATTRIBUTE_NMTOKEN); | 
|  | 4601 | } | 
|  | 4602 | return(xmlParseEnumeratedType(ctxt, tree)); | 
|  | 4603 | } | 
|  | 4604 |  | 
|  | 4605 | /** | 
|  | 4606 | * xmlParseAttributeListDecl: | 
|  | 4607 | * @ctxt:  an XML parser context | 
|  | 4608 | * | 
|  | 4609 | * : parse the Attribute list def for an element | 
|  | 4610 | * | 
|  | 4611 | * [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>' | 
|  | 4612 | * | 
|  | 4613 | * [53] AttDef ::= S Name S AttType S DefaultDecl | 
|  | 4614 | * | 
|  | 4615 | */ | 
|  | 4616 | void | 
|  | 4617 | xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4618 | const xmlChar *elemName; | 
|  | 4619 | const xmlChar *attrName; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4620 | xmlEnumerationPtr tree; | 
|  | 4621 |  | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4622 | if (CMP9(CUR_PTR, '<', '!', 'A', 'T', 'T', 'L', 'I', 'S', 'T')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4623 | xmlParserInputPtr input = ctxt->input; | 
|  | 4624 |  | 
|  | 4625 | SKIP(9); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4626 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4627 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4628 | "Space required after '<!ATTLIST'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4629 | } | 
|  | 4630 | SKIP_BLANKS; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4631 | elemName = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4632 | if (elemName == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4633 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 4634 | "ATTLIST: no name for Element\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4635 | return; | 
|  | 4636 | } | 
|  | 4637 | SKIP_BLANKS; | 
|  | 4638 | GROW; | 
|  | 4639 | while (RAW != '>') { | 
|  | 4640 | const xmlChar *check = CUR_PTR; | 
|  | 4641 | int type; | 
|  | 4642 | int def; | 
|  | 4643 | xmlChar *defaultValue = NULL; | 
|  | 4644 |  | 
|  | 4645 | GROW; | 
|  | 4646 | tree = NULL; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4647 | attrName = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4648 | if (attrName == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4649 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 4650 | "ATTLIST: no name for Attribute\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4651 | break; | 
|  | 4652 | } | 
|  | 4653 | GROW; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4654 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4655 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4656 | "Space required after the attribute name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4657 | if (defaultValue != NULL) | 
|  | 4658 | xmlFree(defaultValue); | 
|  | 4659 | break; | 
|  | 4660 | } | 
|  | 4661 | SKIP_BLANKS; | 
|  | 4662 |  | 
|  | 4663 | type = xmlParseAttributeType(ctxt, &tree); | 
|  | 4664 | if (type <= 0) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4665 | if (defaultValue != NULL) | 
|  | 4666 | xmlFree(defaultValue); | 
|  | 4667 | break; | 
|  | 4668 | } | 
|  | 4669 |  | 
|  | 4670 | GROW; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4671 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4672 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 4673 | "Space required after the attribute type\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4674 | if (defaultValue != NULL) | 
|  | 4675 | xmlFree(defaultValue); | 
|  | 4676 | if (tree != NULL) | 
|  | 4677 | xmlFreeEnumeration(tree); | 
|  | 4678 | break; | 
|  | 4679 | } | 
|  | 4680 | SKIP_BLANKS; | 
|  | 4681 |  | 
|  | 4682 | def = xmlParseDefaultDecl(ctxt, &defaultValue); | 
|  | 4683 | if (def <= 0) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4684 | if (defaultValue != NULL) | 
|  | 4685 | xmlFree(defaultValue); | 
|  | 4686 | if (tree != NULL) | 
|  | 4687 | xmlFreeEnumeration(tree); | 
|  | 4688 | break; | 
|  | 4689 | } | 
|  | 4690 |  | 
|  | 4691 | GROW; | 
|  | 4692 | if (RAW != '>') { | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4693 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4694 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4695 | "Space required after the attribute default value\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4696 | if (defaultValue != NULL) | 
|  | 4697 | xmlFree(defaultValue); | 
|  | 4698 | if (tree != NULL) | 
|  | 4699 | xmlFreeEnumeration(tree); | 
|  | 4700 | break; | 
|  | 4701 | } | 
|  | 4702 | SKIP_BLANKS; | 
|  | 4703 | } | 
|  | 4704 | if (check == CUR_PTR) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4705 | xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 4706 | "in xmlParseAttributeListDecl\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4707 | if (defaultValue != NULL) | 
|  | 4708 | xmlFree(defaultValue); | 
|  | 4709 | if (tree != NULL) | 
|  | 4710 | xmlFreeEnumeration(tree); | 
|  | 4711 | break; | 
|  | 4712 | } | 
|  | 4713 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && | 
|  | 4714 | (ctxt->sax->attributeDecl != NULL)) | 
|  | 4715 | ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName, | 
|  | 4716 | type, def, defaultValue, tree); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 4717 | else if (tree != NULL) | 
|  | 4718 | xmlFreeEnumeration(tree); | 
|  | 4719 |  | 
|  | 4720 | if ((ctxt->sax2) && (defaultValue != NULL) && | 
|  | 4721 | (def != XML_ATTRIBUTE_IMPLIED) && | 
|  | 4722 | (def != XML_ATTRIBUTE_REQUIRED)) { | 
|  | 4723 | xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue); | 
|  | 4724 | } | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 4725 | if ((ctxt->sax2) && (type != XML_ATTRIBUTE_CDATA)) { | 
|  | 4726 | xmlAddSpecialAttr(ctxt, elemName, attrName, type); | 
|  | 4727 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4728 | if (defaultValue != NULL) | 
|  | 4729 | xmlFree(defaultValue); | 
|  | 4730 | GROW; | 
|  | 4731 | } | 
|  | 4732 | if (RAW == '>') { | 
|  | 4733 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4734 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 4735 | "Attribute list declaration doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4736 | } | 
|  | 4737 | NEXT; | 
|  | 4738 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4739 | } | 
|  | 4740 | } | 
|  | 4741 |  | 
|  | 4742 | /** | 
|  | 4743 | * xmlParseElementMixedContentDecl: | 
|  | 4744 | * @ctxt:  an XML parser context | 
| Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 4745 | * @inputchk:  the input used for the current entity, needed for boundary checks | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4746 | * | 
|  | 4747 | * parse the declaration for a Mixed Element content | 
|  | 4748 | * The leading '(' and spaces have been skipped in xmlParseElementContentDecl | 
|  | 4749 | * | 
|  | 4750 | * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | | 
|  | 4751 | *                '(' S? '#PCDATA' S? ')' | 
|  | 4752 | * | 
|  | 4753 | * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49]) | 
|  | 4754 | * | 
|  | 4755 | * [ VC: No Duplicate Types ] | 
|  | 4756 | * The same name must not appear more than once in a single | 
|  | 4757 | * mixed-content declaration. | 
|  | 4758 | * | 
|  | 4759 | * returns: the list of the xmlElementContentPtr describing the element choices | 
|  | 4760 | */ | 
|  | 4761 | xmlElementContentPtr | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4762 | xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4763 | xmlElementContentPtr ret = NULL, cur = NULL, n; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4764 | const xmlChar *elem = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4765 |  | 
|  | 4766 | GROW; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 4767 | if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4768 | SKIP(7); | 
|  | 4769 | SKIP_BLANKS; | 
|  | 4770 | SHRINK; | 
|  | 4771 | if (RAW == ')') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4772 | if ((ctxt->validate) && (ctxt->input->id != inputchk)) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 4773 | xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 4774 | "Element content declaration doesn't start and stop in the same entity\n", | 
|  | 4775 | NULL); | 
| Daniel Veillard | 8dc16a6 | 2002-02-19 21:08:48 +0000 | [diff] [blame] | 4776 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4777 | NEXT; | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4778 | ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4779 | if (RAW == '*') { | 
|  | 4780 | ret->ocur = XML_ELEMENT_CONTENT_MULT; | 
|  | 4781 | NEXT; | 
|  | 4782 | } | 
|  | 4783 | return(ret); | 
|  | 4784 | } | 
|  | 4785 | if ((RAW == '(') || (RAW == '|')) { | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4786 | ret = cur = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4787 | if (ret == NULL) return(NULL); | 
|  | 4788 | } | 
|  | 4789 | while (RAW == '|') { | 
|  | 4790 | NEXT; | 
|  | 4791 | if (elem == NULL) { | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4792 | ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_OR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4793 | if (ret == NULL) return(NULL); | 
|  | 4794 | ret->c1 = cur; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4795 | if (cur != NULL) | 
|  | 4796 | cur->parent = ret; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4797 | cur = ret; | 
|  | 4798 | } else { | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4799 | n = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_OR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4800 | if (n == NULL) return(NULL); | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4801 | n->c1 = xmlNewDocElementContent(ctxt->myDoc, elem, XML_ELEMENT_CONTENT_ELEMENT); | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4802 | if (n->c1 != NULL) | 
|  | 4803 | n->c1->parent = n; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4804 | cur->c2 = n; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4805 | if (n != NULL) | 
|  | 4806 | n->parent = cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4807 | cur = n; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4808 | } | 
|  | 4809 | SKIP_BLANKS; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4810 | elem = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4811 | if (elem == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4812 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4813 | "xmlParseElementMixedContentDecl : Name expected\n"); | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4814 | xmlFreeDocElementContent(ctxt->myDoc, cur); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4815 | return(NULL); | 
|  | 4816 | } | 
|  | 4817 | SKIP_BLANKS; | 
|  | 4818 | GROW; | 
|  | 4819 | } | 
|  | 4820 | if ((RAW == ')') && (NXT(1) == '*')) { | 
|  | 4821 | if (elem != NULL) { | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4822 | cur->c2 = xmlNewDocElementContent(ctxt->myDoc, elem, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4823 | XML_ELEMENT_CONTENT_ELEMENT); | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4824 | if (cur->c2 != NULL) | 
|  | 4825 | cur->c2->parent = cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4826 | } | 
|  | 4827 | ret->ocur = XML_ELEMENT_CONTENT_MULT; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4828 | if ((ctxt->validate) && (ctxt->input->id != inputchk)) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 4829 | xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 4830 | "Element content declaration doesn't start and stop in the same entity\n", | 
|  | 4831 | NULL); | 
| Daniel Veillard | 8dc16a6 | 2002-02-19 21:08:48 +0000 | [diff] [blame] | 4832 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4833 | SKIP(2); | 
|  | 4834 | } else { | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4835 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4836 | xmlFatalErr(ctxt, XML_ERR_MIXED_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4837 | return(NULL); | 
|  | 4838 | } | 
|  | 4839 |  | 
|  | 4840 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4841 | xmlFatalErr(ctxt, XML_ERR_PCDATA_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4842 | } | 
|  | 4843 | return(ret); | 
|  | 4844 | } | 
|  | 4845 |  | 
|  | 4846 | /** | 
|  | 4847 | * xmlParseElementChildrenContentDecl: | 
|  | 4848 | * @ctxt:  an XML parser context | 
| Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 4849 | * @inputchk:  the input used for the current entity, needed for boundary checks | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4850 | * | 
|  | 4851 | * parse the declaration for a Mixed Element content | 
|  | 4852 | * The leading '(' and spaces have been skipped in xmlParseElementContentDecl | 
|  | 4853 | * | 
|  | 4854 | * | 
|  | 4855 | * [47] children ::= (choice | seq) ('?' | '*' | '+')? | 
|  | 4856 | * | 
|  | 4857 | * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? | 
|  | 4858 | * | 
|  | 4859 | * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')' | 
|  | 4860 | * | 
|  | 4861 | * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' | 
|  | 4862 | * | 
|  | 4863 | * [ VC: Proper Group/PE Nesting ] applies to [49] and [50] | 
|  | 4864 | * TODO Parameter-entity replacement text must be properly nested | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 4865 | *	with parenthesized groups. That is to say, if either of the | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4866 | *	opening or closing parentheses in a choice, seq, or Mixed | 
|  | 4867 | *	construct is contained in the replacement text for a parameter | 
|  | 4868 | *	entity, both must be contained in the same replacement text. For | 
|  | 4869 | *	interoperability, if a parameter-entity reference appears in a | 
|  | 4870 | *	choice, seq, or Mixed construct, its replacement text should not | 
|  | 4871 | *	be empty, and neither the first nor last non-blank character of | 
|  | 4872 | *	the replacement text should be a connector (| or ,). | 
|  | 4873 | * | 
| Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 4874 | * Returns the tree of xmlElementContentPtr describing the element | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4875 | *          hierarchy. | 
|  | 4876 | */ | 
|  | 4877 | xmlElementContentPtr | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4878 | xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4879 | xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL; | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 4880 | const xmlChar *elem; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4881 | xmlChar type = 0; | 
|  | 4882 |  | 
|  | 4883 | SKIP_BLANKS; | 
|  | 4884 | GROW; | 
|  | 4885 | if (RAW == '(') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4886 | int inputid = ctxt->input->id; | 
| Daniel Veillard | 8dc16a6 | 2002-02-19 21:08:48 +0000 | [diff] [blame] | 4887 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4888 | /* Recurse on first child */ | 
|  | 4889 | NEXT; | 
|  | 4890 | SKIP_BLANKS; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4891 | cur = ret = xmlParseElementChildrenContentDecl(ctxt, inputid); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4892 | SKIP_BLANKS; | 
|  | 4893 | GROW; | 
|  | 4894 | } else { | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 4895 | elem = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4896 | if (elem == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4897 | xmlFatalErr(ctxt, XML_ERR_ELEMCONTENT_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4898 | return(NULL); | 
|  | 4899 | } | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4900 | cur = ret = xmlNewDocElementContent(ctxt->myDoc, elem, XML_ELEMENT_CONTENT_ELEMENT); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 4901 | if (cur == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 4902 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 4903 | return(NULL); | 
|  | 4904 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4905 | GROW; | 
|  | 4906 | if (RAW == '?') { | 
|  | 4907 | cur->ocur = XML_ELEMENT_CONTENT_OPT; | 
|  | 4908 | NEXT; | 
|  | 4909 | } else if (RAW == '*') { | 
|  | 4910 | cur->ocur = XML_ELEMENT_CONTENT_MULT; | 
|  | 4911 | NEXT; | 
|  | 4912 | } else if (RAW == '+') { | 
|  | 4913 | cur->ocur = XML_ELEMENT_CONTENT_PLUS; | 
|  | 4914 | NEXT; | 
|  | 4915 | } else { | 
|  | 4916 | cur->ocur = XML_ELEMENT_CONTENT_ONCE; | 
|  | 4917 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4918 | GROW; | 
|  | 4919 | } | 
|  | 4920 | SKIP_BLANKS; | 
|  | 4921 | SHRINK; | 
|  | 4922 | while (RAW != ')') { | 
|  | 4923 | /* | 
|  | 4924 | * Each loop we parse one separator and one element. | 
|  | 4925 | */ | 
|  | 4926 | if (RAW == ',') { | 
|  | 4927 | if (type == 0) type = CUR; | 
|  | 4928 |  | 
|  | 4929 | /* | 
|  | 4930 | * Detect "Name | Name , Name" error | 
|  | 4931 | */ | 
|  | 4932 | else if (type != CUR) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4933 | xmlFatalErrMsgInt(ctxt, XML_ERR_SEPARATOR_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4934 | "xmlParseElementChildrenContentDecl : '%c' expected\n", | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4935 | type); | 
| Daniel Veillard | d54fa3e | 2002-02-20 16:48:52 +0000 | [diff] [blame] | 4936 | if ((last != NULL) && (last != ret)) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4937 | xmlFreeDocElementContent(ctxt->myDoc, last); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4938 | if (ret != NULL) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4939 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4940 | return(NULL); | 
|  | 4941 | } | 
|  | 4942 | NEXT; | 
|  | 4943 |  | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4944 | op = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_SEQ); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4945 | if (op == NULL) { | 
| Daniel Veillard | d54fa3e | 2002-02-20 16:48:52 +0000 | [diff] [blame] | 4946 | if ((last != NULL) && (last != ret)) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4947 | xmlFreeDocElementContent(ctxt->myDoc, last); | 
|  | 4948 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4949 | return(NULL); | 
|  | 4950 | } | 
|  | 4951 | if (last == NULL) { | 
|  | 4952 | op->c1 = ret; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4953 | if (ret != NULL) | 
|  | 4954 | ret->parent = op; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4955 | ret = cur = op; | 
|  | 4956 | } else { | 
|  | 4957 | cur->c2 = op; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4958 | if (op != NULL) | 
|  | 4959 | op->parent = cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4960 | op->c1 = last; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4961 | if (last != NULL) | 
|  | 4962 | last->parent = op; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4963 | cur =op; | 
|  | 4964 | last = NULL; | 
|  | 4965 | } | 
|  | 4966 | } else if (RAW == '|') { | 
|  | 4967 | if (type == 0) type = CUR; | 
|  | 4968 |  | 
|  | 4969 | /* | 
|  | 4970 | * Detect "Name , Name | Name" error | 
|  | 4971 | */ | 
|  | 4972 | else if (type != CUR) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4973 | xmlFatalErrMsgInt(ctxt, XML_ERR_SEPARATOR_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4974 | "xmlParseElementChildrenContentDecl : '%c' expected\n", | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 4975 | type); | 
| Daniel Veillard | d54fa3e | 2002-02-20 16:48:52 +0000 | [diff] [blame] | 4976 | if ((last != NULL) && (last != ret)) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4977 | xmlFreeDocElementContent(ctxt->myDoc, last); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4978 | if (ret != NULL) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4979 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4980 | return(NULL); | 
|  | 4981 | } | 
|  | 4982 | NEXT; | 
|  | 4983 |  | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4984 | op = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_OR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4985 | if (op == NULL) { | 
| Daniel Veillard | d54fa3e | 2002-02-20 16:48:52 +0000 | [diff] [blame] | 4986 | if ((last != NULL) && (last != ret)) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4987 | xmlFreeDocElementContent(ctxt->myDoc, last); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4988 | if (ret != NULL) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 4989 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4990 | return(NULL); | 
|  | 4991 | } | 
|  | 4992 | if (last == NULL) { | 
|  | 4993 | op->c1 = ret; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4994 | if (ret != NULL) | 
|  | 4995 | ret->parent = op; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 4996 | ret = cur = op; | 
|  | 4997 | } else { | 
|  | 4998 | cur->c2 = op; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 4999 | if (op != NULL) | 
|  | 5000 | op->parent = cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5001 | op->c1 = last; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 5002 | if (last != NULL) | 
|  | 5003 | last->parent = op; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5004 | cur =op; | 
|  | 5005 | last = NULL; | 
|  | 5006 | } | 
|  | 5007 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5008 | xmlFatalErr(ctxt, XML_ERR_ELEMCONTENT_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5009 | if (ret != NULL) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 5010 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5011 | return(NULL); | 
|  | 5012 | } | 
|  | 5013 | GROW; | 
|  | 5014 | SKIP_BLANKS; | 
|  | 5015 | GROW; | 
|  | 5016 | if (RAW == '(') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5017 | int inputid = ctxt->input->id; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5018 | /* Recurse on second child */ | 
|  | 5019 | NEXT; | 
|  | 5020 | SKIP_BLANKS; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5021 | last = xmlParseElementChildrenContentDecl(ctxt, inputid); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5022 | SKIP_BLANKS; | 
|  | 5023 | } else { | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 5024 | elem = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5025 | if (elem == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5026 | xmlFatalErr(ctxt, XML_ERR_ELEMCONTENT_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5027 | if (ret != NULL) | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 5028 | xmlFreeDocElementContent(ctxt->myDoc, ret); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5029 | return(NULL); | 
|  | 5030 | } | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 5031 | last = xmlNewDocElementContent(ctxt->myDoc, elem, XML_ELEMENT_CONTENT_ELEMENT); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5032 | if (RAW == '?') { | 
|  | 5033 | last->ocur = XML_ELEMENT_CONTENT_OPT; | 
|  | 5034 | NEXT; | 
|  | 5035 | } else if (RAW == '*') { | 
|  | 5036 | last->ocur = XML_ELEMENT_CONTENT_MULT; | 
|  | 5037 | NEXT; | 
|  | 5038 | } else if (RAW == '+') { | 
|  | 5039 | last->ocur = XML_ELEMENT_CONTENT_PLUS; | 
|  | 5040 | NEXT; | 
|  | 5041 | } else { | 
|  | 5042 | last->ocur = XML_ELEMENT_CONTENT_ONCE; | 
|  | 5043 | } | 
|  | 5044 | } | 
|  | 5045 | SKIP_BLANKS; | 
|  | 5046 | GROW; | 
|  | 5047 | } | 
|  | 5048 | if ((cur != NULL) && (last != NULL)) { | 
|  | 5049 | cur->c2 = last; | 
| Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 5050 | if (last != NULL) | 
|  | 5051 | last->parent = cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5052 | } | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5053 | if ((ctxt->validate) && (ctxt->input->id != inputchk)) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 5054 | xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 5055 | "Element content declaration doesn't start and stop in the same entity\n", | 
|  | 5056 | NULL); | 
| Daniel Veillard | 8dc16a6 | 2002-02-19 21:08:48 +0000 | [diff] [blame] | 5057 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5058 | NEXT; | 
|  | 5059 | if (RAW == '?') { | 
| William M. Brack | f8f2e8f | 2004-05-14 04:37:41 +0000 | [diff] [blame] | 5060 | if (ret != NULL) { | 
|  | 5061 | if ((ret->ocur == XML_ELEMENT_CONTENT_PLUS) || | 
|  | 5062 | (ret->ocur == XML_ELEMENT_CONTENT_MULT)) | 
|  | 5063 | ret->ocur = XML_ELEMENT_CONTENT_MULT; | 
|  | 5064 | else | 
|  | 5065 | ret->ocur = XML_ELEMENT_CONTENT_OPT; | 
|  | 5066 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5067 | NEXT; | 
|  | 5068 | } else if (RAW == '*') { | 
| Daniel Veillard | ce2c2f0 | 2001-10-18 14:57:24 +0000 | [diff] [blame] | 5069 | if (ret != NULL) { | 
| Daniel Veillard | e470df7 | 2001-04-18 21:41:07 +0000 | [diff] [blame] | 5070 | ret->ocur = XML_ELEMENT_CONTENT_MULT; | 
| Daniel Veillard | ce2c2f0 | 2001-10-18 14:57:24 +0000 | [diff] [blame] | 5071 | cur = ret; | 
|  | 5072 | /* | 
|  | 5073 | * Some normalization: | 
|  | 5074 | * (a | b* | c?)* == (a | b | c)* | 
|  | 5075 | */ | 
|  | 5076 | while (cur->type == XML_ELEMENT_CONTENT_OR) { | 
|  | 5077 | if ((cur->c1 != NULL) && | 
|  | 5078 | ((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) || | 
|  | 5079 | (cur->c1->ocur == XML_ELEMENT_CONTENT_MULT))) | 
|  | 5080 | cur->c1->ocur = XML_ELEMENT_CONTENT_ONCE; | 
|  | 5081 | if ((cur->c2 != NULL) && | 
|  | 5082 | ((cur->c2->ocur == XML_ELEMENT_CONTENT_OPT) || | 
|  | 5083 | (cur->c2->ocur == XML_ELEMENT_CONTENT_MULT))) | 
|  | 5084 | cur->c2->ocur = XML_ELEMENT_CONTENT_ONCE; | 
|  | 5085 | cur = cur->c2; | 
|  | 5086 | } | 
|  | 5087 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5088 | NEXT; | 
|  | 5089 | } else if (RAW == '+') { | 
| Daniel Veillard | ce2c2f0 | 2001-10-18 14:57:24 +0000 | [diff] [blame] | 5090 | if (ret != NULL) { | 
|  | 5091 | int found = 0; | 
|  | 5092 |  | 
| William M. Brack | f8f2e8f | 2004-05-14 04:37:41 +0000 | [diff] [blame] | 5093 | if ((ret->ocur == XML_ELEMENT_CONTENT_OPT) || | 
|  | 5094 | (ret->ocur == XML_ELEMENT_CONTENT_MULT)) | 
|  | 5095 | ret->ocur = XML_ELEMENT_CONTENT_MULT; | 
| William M. Brack | eb8509c | 2004-05-14 03:48:02 +0000 | [diff] [blame] | 5096 | else | 
|  | 5097 | ret->ocur = XML_ELEMENT_CONTENT_PLUS; | 
| Daniel Veillard | ce2c2f0 | 2001-10-18 14:57:24 +0000 | [diff] [blame] | 5098 | /* | 
|  | 5099 | * Some normalization: | 
|  | 5100 | * (a | b*)+ == (a | b)* | 
|  | 5101 | * (a | b?)+ == (a | b)* | 
|  | 5102 | */ | 
|  | 5103 | while (cur->type == XML_ELEMENT_CONTENT_OR) { | 
|  | 5104 | if ((cur->c1 != NULL) && | 
|  | 5105 | ((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) || | 
|  | 5106 | (cur->c1->ocur == XML_ELEMENT_CONTENT_MULT))) { | 
|  | 5107 | cur->c1->ocur = XML_ELEMENT_CONTENT_ONCE; | 
|  | 5108 | found = 1; | 
|  | 5109 | } | 
|  | 5110 | if ((cur->c2 != NULL) && | 
|  | 5111 | ((cur->c2->ocur == XML_ELEMENT_CONTENT_OPT) || | 
|  | 5112 | (cur->c2->ocur == XML_ELEMENT_CONTENT_MULT))) { | 
|  | 5113 | cur->c2->ocur = XML_ELEMENT_CONTENT_ONCE; | 
|  | 5114 | found = 1; | 
|  | 5115 | } | 
|  | 5116 | cur = cur->c2; | 
|  | 5117 | } | 
|  | 5118 | if (found) | 
|  | 5119 | ret->ocur = XML_ELEMENT_CONTENT_MULT; | 
|  | 5120 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5121 | NEXT; | 
|  | 5122 | } | 
|  | 5123 | return(ret); | 
|  | 5124 | } | 
|  | 5125 |  | 
|  | 5126 | /** | 
|  | 5127 | * xmlParseElementContentDecl: | 
|  | 5128 | * @ctxt:  an XML parser context | 
|  | 5129 | * @name:  the name of the element being defined. | 
|  | 5130 | * @result:  the Element Content pointer will be stored here if any | 
|  | 5131 | * | 
|  | 5132 | * parse the declaration for an Element content either Mixed or Children, | 
|  | 5133 | * the cases EMPTY and ANY are handled directly in xmlParseElementDecl | 
|  | 5134 | * | 
|  | 5135 | * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children | 
|  | 5136 | * | 
|  | 5137 | * returns: the type of element content XML_ELEMENT_TYPE_xxx | 
|  | 5138 | */ | 
|  | 5139 |  | 
|  | 5140 | int | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 5141 | xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5142 | xmlElementContentPtr *result) { | 
|  | 5143 |  | 
|  | 5144 | xmlElementContentPtr tree = NULL; | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5145 | int inputid = ctxt->input->id; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5146 | int res; | 
|  | 5147 |  | 
|  | 5148 | *result = NULL; | 
|  | 5149 |  | 
|  | 5150 | if (RAW != '(') { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 5151 | xmlFatalErrMsgStr(ctxt, XML_ERR_ELEMCONTENT_NOT_STARTED, | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 5152 | "xmlParseElementContentDecl : %s '(' expected\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5153 | return(-1); | 
|  | 5154 | } | 
|  | 5155 | NEXT; | 
|  | 5156 | GROW; | 
|  | 5157 | SKIP_BLANKS; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5158 | if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5159 | tree = xmlParseElementMixedContentDecl(ctxt, inputid); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5160 | res = XML_ELEMENT_TYPE_MIXED; | 
|  | 5161 | } else { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5162 | tree = xmlParseElementChildrenContentDecl(ctxt, inputid); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5163 | res = XML_ELEMENT_TYPE_ELEMENT; | 
|  | 5164 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5165 | SKIP_BLANKS; | 
|  | 5166 | *result = tree; | 
|  | 5167 | return(res); | 
|  | 5168 | } | 
|  | 5169 |  | 
|  | 5170 | /** | 
|  | 5171 | * xmlParseElementDecl: | 
|  | 5172 | * @ctxt:  an XML parser context | 
|  | 5173 | * | 
|  | 5174 | * parse an Element declaration. | 
|  | 5175 | * | 
|  | 5176 | * [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>' | 
|  | 5177 | * | 
|  | 5178 | * [ VC: Unique Element Type Declaration ] | 
|  | 5179 | * No element type may be declared more than once | 
|  | 5180 | * | 
|  | 5181 | * Returns the type of the element, or -1 in case of error | 
|  | 5182 | */ | 
|  | 5183 | int | 
|  | 5184 | xmlParseElementDecl(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 5185 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5186 | int ret = -1; | 
|  | 5187 | xmlElementContentPtr content  = NULL; | 
|  | 5188 |  | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 5189 | /* GROW; done in the caller */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5190 | if (CMP9(CUR_PTR, '<', '!', 'E', 'L', 'E', 'M', 'E', 'N', 'T')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5191 | xmlParserInputPtr input = ctxt->input; | 
|  | 5192 |  | 
|  | 5193 | SKIP(9); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5194 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5195 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 5196 | "Space required after 'ELEMENT'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5197 | } | 
|  | 5198 | SKIP_BLANKS; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 5199 | name = xmlParseName(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5200 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5201 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 5202 | "xmlParseElementDecl: no name for Element\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5203 | return(-1); | 
|  | 5204 | } | 
|  | 5205 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 5206 | xmlPopInput(ctxt); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5207 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5208 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 5209 | "Space required after the element name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5210 | } | 
|  | 5211 | SKIP_BLANKS; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5212 | if (CMP5(CUR_PTR, 'E', 'M', 'P', 'T', 'Y')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5213 | SKIP(5); | 
|  | 5214 | /* | 
|  | 5215 | * Element must always be empty. | 
|  | 5216 | */ | 
|  | 5217 | ret = XML_ELEMENT_TYPE_EMPTY; | 
|  | 5218 | } else if ((RAW == 'A') && (NXT(1) == 'N') && | 
|  | 5219 | (NXT(2) == 'Y')) { | 
|  | 5220 | SKIP(3); | 
|  | 5221 | /* | 
|  | 5222 | * Element is a generic container. | 
|  | 5223 | */ | 
|  | 5224 | ret = XML_ELEMENT_TYPE_ANY; | 
|  | 5225 | } else if (RAW == '(') { | 
|  | 5226 | ret = xmlParseElementContentDecl(ctxt, name, &content); | 
|  | 5227 | } else { | 
|  | 5228 | /* | 
|  | 5229 | * [ WFC: PEs in Internal Subset ] error handling. | 
|  | 5230 | */ | 
|  | 5231 | if ((RAW == '%') && (ctxt->external == 0) && | 
|  | 5232 | (ctxt->inputNr == 1)) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 5233 | xmlFatalErrMsg(ctxt, XML_ERR_PEREF_IN_INT_SUBSET, | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5234 | "PEReference: forbidden within markup decl in internal subset\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5235 | } else { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 5236 | xmlFatalErrMsg(ctxt, XML_ERR_ELEMCONTENT_NOT_STARTED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5237 | "xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected\n"); | 
|  | 5238 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5239 | return(-1); | 
|  | 5240 | } | 
|  | 5241 |  | 
|  | 5242 | SKIP_BLANKS; | 
|  | 5243 | /* | 
|  | 5244 | * Pop-up of finished entities. | 
|  | 5245 | */ | 
|  | 5246 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 5247 | xmlPopInput(ctxt); | 
|  | 5248 | SKIP_BLANKS; | 
|  | 5249 |  | 
|  | 5250 | if (RAW != '>') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5251 | xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 5252 | if (content != NULL) { | 
|  | 5253 | xmlFreeDocElementContent(ctxt->myDoc, content); | 
|  | 5254 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5255 | } else { | 
|  | 5256 | if (input != ctxt->input) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5257 | xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, | 
|  | 5258 | "Element declaration doesn't start and stop in the same entity\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5259 | } | 
|  | 5260 |  | 
|  | 5261 | NEXT; | 
|  | 5262 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 5263 | (ctxt->sax->elementDecl != NULL)) { | 
|  | 5264 | if (content != NULL) | 
|  | 5265 | content->parent = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5266 | ctxt->sax->elementDecl(ctxt->userData, name, ret, | 
|  | 5267 | content); | 
| Daniel Veillard | cee2b3a | 2005-01-25 00:22:52 +0000 | [diff] [blame] | 5268 | if ((content != NULL) && (content->parent == NULL)) { | 
|  | 5269 | /* | 
|  | 5270 | * this is a trick: if xmlAddElementDecl is called, | 
|  | 5271 | * instead of copying the full tree it is plugged directly | 
|  | 5272 | * if called from the parser. Avoid duplicating the | 
|  | 5273 | * interfaces or change the API/ABI | 
|  | 5274 | */ | 
|  | 5275 | xmlFreeDocElementContent(ctxt->myDoc, content); | 
|  | 5276 | } | 
|  | 5277 | } else if (content != NULL) { | 
|  | 5278 | xmlFreeDocElementContent(ctxt->myDoc, content); | 
|  | 5279 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5280 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5281 | } | 
|  | 5282 | return(ret); | 
|  | 5283 | } | 
|  | 5284 |  | 
|  | 5285 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5286 | * xmlParseConditionalSections | 
|  | 5287 | * @ctxt:  an XML parser context | 
|  | 5288 | * | 
|  | 5289 | * [61] conditionalSect ::= includeSect | ignoreSect | 
|  | 5290 | * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' | 
|  | 5291 | * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' | 
|  | 5292 | * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* | 
|  | 5293 | * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*) | 
|  | 5294 | */ | 
|  | 5295 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 5296 | static void | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5297 | xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { | 
|  | 5298 | SKIP(3); | 
|  | 5299 | SKIP_BLANKS; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5300 | if (CMP7(CUR_PTR, 'I', 'N', 'C', 'L', 'U', 'D', 'E')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5301 | SKIP(7); | 
|  | 5302 | SKIP_BLANKS; | 
|  | 5303 | if (RAW != '[') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5304 | xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5305 | } else { | 
|  | 5306 | NEXT; | 
|  | 5307 | } | 
|  | 5308 | if (xmlParserDebugEntities) { | 
|  | 5309 | if ((ctxt->input != NULL) && (ctxt->input->filename)) | 
|  | 5310 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5311 | "%s(%d): ", ctxt->input->filename, | 
|  | 5312 | ctxt->input->line); | 
|  | 5313 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5314 | "Entering INCLUDE Conditional Section\n"); | 
|  | 5315 | } | 
|  | 5316 |  | 
|  | 5317 | while ((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') || | 
|  | 5318 | (NXT(2) != '>'))) { | 
|  | 5319 | const xmlChar *check = CUR_PTR; | 
| Daniel Veillard | 3e59fc5 | 2003-04-18 12:34:58 +0000 | [diff] [blame] | 5320 | unsigned int cons = ctxt->input->consumed; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5321 |  | 
|  | 5322 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { | 
|  | 5323 | xmlParseConditionalSections(ctxt); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5324 | } else if (IS_BLANK_CH(CUR)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5325 | NEXT; | 
|  | 5326 | } else if (RAW == '%') { | 
|  | 5327 | xmlParsePEReference(ctxt); | 
|  | 5328 | } else | 
|  | 5329 | xmlParseMarkupDecl(ctxt); | 
|  | 5330 |  | 
|  | 5331 | /* | 
|  | 5332 | * Pop-up of finished entities. | 
|  | 5333 | */ | 
|  | 5334 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 5335 | xmlPopInput(ctxt); | 
|  | 5336 |  | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 5337 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5338 | xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5339 | break; | 
|  | 5340 | } | 
|  | 5341 | } | 
|  | 5342 | if (xmlParserDebugEntities) { | 
|  | 5343 | if ((ctxt->input != NULL) && (ctxt->input->filename)) | 
|  | 5344 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5345 | "%s(%d): ", ctxt->input->filename, | 
|  | 5346 | ctxt->input->line); | 
|  | 5347 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5348 | "Leaving INCLUDE Conditional Section\n"); | 
|  | 5349 | } | 
|  | 5350 |  | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5351 | } else if (CMP6(CUR_PTR, 'I', 'G', 'N', 'O', 'R', 'E')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5352 | int state; | 
| William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 5353 | xmlParserInputState instate; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5354 | int depth = 0; | 
|  | 5355 |  | 
|  | 5356 | SKIP(6); | 
|  | 5357 | SKIP_BLANKS; | 
|  | 5358 | if (RAW != '[') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5359 | xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5360 | } else { | 
|  | 5361 | NEXT; | 
|  | 5362 | } | 
|  | 5363 | if (xmlParserDebugEntities) { | 
|  | 5364 | if ((ctxt->input != NULL) && (ctxt->input->filename)) | 
|  | 5365 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5366 | "%s(%d): ", ctxt->input->filename, | 
|  | 5367 | ctxt->input->line); | 
|  | 5368 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5369 | "Entering IGNORE Conditional Section\n"); | 
|  | 5370 | } | 
|  | 5371 |  | 
|  | 5372 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 5373 | * Parse up to the end of the conditional section | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5374 | * But disable SAX event generating DTD building in the meantime | 
|  | 5375 | */ | 
|  | 5376 | state = ctxt->disableSAX; | 
|  | 5377 | instate = ctxt->instate; | 
| Daniel Veillard | dad3f68 | 2002-11-17 16:47:27 +0000 | [diff] [blame] | 5378 | if (ctxt->recovery == 0) ctxt->disableSAX = 1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5379 | ctxt->instate = XML_PARSER_IGNORE; | 
|  | 5380 |  | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 5381 | while ((depth >= 0) && (RAW != 0)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5382 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { | 
|  | 5383 | depth++; | 
|  | 5384 | SKIP(3); | 
|  | 5385 | continue; | 
|  | 5386 | } | 
|  | 5387 | if ((RAW == ']') && (NXT(1) == ']') && (NXT(2) == '>')) { | 
|  | 5388 | if (--depth >= 0) SKIP(3); | 
|  | 5389 | continue; | 
|  | 5390 | } | 
|  | 5391 | NEXT; | 
|  | 5392 | continue; | 
|  | 5393 | } | 
|  | 5394 |  | 
|  | 5395 | ctxt->disableSAX = state; | 
|  | 5396 | ctxt->instate = instate; | 
|  | 5397 |  | 
|  | 5398 | if (xmlParserDebugEntities) { | 
|  | 5399 | if ((ctxt->input != NULL) && (ctxt->input->filename)) | 
|  | 5400 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5401 | "%s(%d): ", ctxt->input->filename, | 
|  | 5402 | ctxt->input->line); | 
|  | 5403 | xmlGenericError(xmlGenericErrorContext, | 
|  | 5404 | "Leaving IGNORE Conditional Section\n"); | 
|  | 5405 | } | 
|  | 5406 |  | 
|  | 5407 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5408 | xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5409 | } | 
|  | 5410 |  | 
|  | 5411 | if (RAW == 0) | 
|  | 5412 | SHRINK; | 
|  | 5413 |  | 
|  | 5414 | if (RAW == 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5415 | xmlFatalErr(ctxt, XML_ERR_CONDSEC_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5416 | } else { | 
|  | 5417 | SKIP(3); | 
|  | 5418 | } | 
|  | 5419 | } | 
|  | 5420 |  | 
|  | 5421 | /** | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5422 | * xmlParseMarkupDecl: | 
|  | 5423 | * @ctxt:  an XML parser context | 
|  | 5424 | * | 
|  | 5425 | * parse Markup declarations | 
|  | 5426 | * | 
|  | 5427 | * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | | 
|  | 5428 | *                     NotationDecl | PI | Comment | 
|  | 5429 | * | 
|  | 5430 | * [ VC: Proper Declaration/PE Nesting ] | 
|  | 5431 | * Parameter-entity replacement text must be properly nested with | 
|  | 5432 | * markup declarations. That is to say, if either the first character | 
|  | 5433 | * or the last character of a markup declaration (markupdecl above) is | 
|  | 5434 | * contained in the replacement text for a parameter-entity reference, | 
|  | 5435 | * both must be contained in the same replacement text. | 
|  | 5436 | * | 
|  | 5437 | * [ WFC: PEs in Internal Subset ] | 
|  | 5438 | * In the internal DTD subset, parameter-entity references can occur | 
|  | 5439 | * only where markup declarations can occur, not within markup declarations. | 
|  | 5440 | * (This does not apply to references that occur in external parameter | 
|  | 5441 | * entities or to the external subset.) | 
|  | 5442 | */ | 
|  | 5443 | void | 
|  | 5444 | xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { | 
|  | 5445 | GROW; | 
| Daniel Veillard | 4c778d8 | 2005-01-23 17:37:44 +0000 | [diff] [blame] | 5446 | if (CUR == '<') { | 
|  | 5447 | if (NXT(1) == '!') { | 
|  | 5448 | switch (NXT(2)) { | 
|  | 5449 | case 'E': | 
|  | 5450 | if (NXT(3) == 'L') | 
|  | 5451 | xmlParseElementDecl(ctxt); | 
|  | 5452 | else if (NXT(3) == 'N') | 
|  | 5453 | xmlParseEntityDecl(ctxt); | 
|  | 5454 | break; | 
|  | 5455 | case 'A': | 
|  | 5456 | xmlParseAttributeListDecl(ctxt); | 
|  | 5457 | break; | 
|  | 5458 | case 'N': | 
|  | 5459 | xmlParseNotationDecl(ctxt); | 
|  | 5460 | break; | 
|  | 5461 | case '-': | 
|  | 5462 | xmlParseComment(ctxt); | 
|  | 5463 | break; | 
|  | 5464 | default: | 
|  | 5465 | /* there is an error but it will be detected later */ | 
|  | 5466 | break; | 
|  | 5467 | } | 
|  | 5468 | } else if (NXT(1) == '?') { | 
|  | 5469 | xmlParsePI(ctxt); | 
|  | 5470 | } | 
|  | 5471 | } | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5472 | /* | 
|  | 5473 | * This is only for internal subset. On external entities, | 
|  | 5474 | * the replacement is done before parsing stage | 
|  | 5475 | */ | 
|  | 5476 | if ((ctxt->external == 0) && (ctxt->inputNr == 1)) | 
|  | 5477 | xmlParsePEReference(ctxt); | 
|  | 5478 |  | 
|  | 5479 | /* | 
|  | 5480 | * Conditional sections are allowed from entities included | 
|  | 5481 | * by PE References in the internal subset. | 
|  | 5482 | */ | 
|  | 5483 | if ((ctxt->external == 0) && (ctxt->inputNr > 1)) { | 
|  | 5484 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { | 
|  | 5485 | xmlParseConditionalSections(ctxt); | 
|  | 5486 | } | 
|  | 5487 | } | 
|  | 5488 |  | 
|  | 5489 | ctxt->instate = XML_PARSER_DTD; | 
|  | 5490 | } | 
|  | 5491 |  | 
|  | 5492 | /** | 
|  | 5493 | * xmlParseTextDecl: | 
|  | 5494 | * @ctxt:  an XML parser context | 
|  | 5495 | * | 
|  | 5496 | * parse an XML declaration header for external entities | 
|  | 5497 | * | 
|  | 5498 | * [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>' | 
|  | 5499 | * | 
|  | 5500 | * Question: Seems that EncodingDecl is mandatory ? Is that a typo ? | 
|  | 5501 | */ | 
|  | 5502 |  | 
|  | 5503 | void | 
|  | 5504 | xmlParseTextDecl(xmlParserCtxtPtr ctxt) { | 
|  | 5505 | xmlChar *version; | 
| Daniel Veillard | f5cb3cd | 2003-10-28 13:58:13 +0000 | [diff] [blame] | 5506 | const xmlChar *encoding; | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5507 |  | 
|  | 5508 | /* | 
|  | 5509 | * We know that '<?xml' is here. | 
|  | 5510 | */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5511 | if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5512 | SKIP(5); | 
|  | 5513 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5514 | xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_STARTED, NULL); | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5515 | return; | 
|  | 5516 | } | 
|  | 5517 |  | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5518 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5519 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 5520 | "Space needed after '<?xml'\n"); | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5521 | } | 
|  | 5522 | SKIP_BLANKS; | 
|  | 5523 |  | 
|  | 5524 | /* | 
|  | 5525 | * We may have the VersionInfo here. | 
|  | 5526 | */ | 
|  | 5527 | version = xmlParseVersionInfo(ctxt); | 
|  | 5528 | if (version == NULL) | 
|  | 5529 | version = xmlCharStrdup(XML_DEFAULT_VERSION); | 
| Daniel Veillard | 401c211 | 2002-01-07 16:54:10 +0000 | [diff] [blame] | 5530 | else { | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5531 | if (!IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5532 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 5533 | "Space needed here\n"); | 
| Daniel Veillard | 401c211 | 2002-01-07 16:54:10 +0000 | [diff] [blame] | 5534 | } | 
|  | 5535 | } | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5536 | ctxt->input->version = version; | 
|  | 5537 |  | 
|  | 5538 | /* | 
|  | 5539 | * We must have the encoding declaration | 
|  | 5540 | */ | 
| Daniel Veillard | f5cb3cd | 2003-10-28 13:58:13 +0000 | [diff] [blame] | 5541 | encoding = xmlParseEncodingDecl(ctxt); | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5542 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 5543 | /* | 
|  | 5544 | * The XML REC instructs us to stop parsing right here | 
|  | 5545 | */ | 
|  | 5546 | return; | 
|  | 5547 | } | 
| Daniel Veillard | f5cb3cd | 2003-10-28 13:58:13 +0000 | [diff] [blame] | 5548 | if ((encoding == NULL) && (ctxt->errNo == XML_ERR_OK)) { | 
|  | 5549 | xmlFatalErrMsg(ctxt, XML_ERR_MISSING_ENCODING, | 
|  | 5550 | "Missing encoding in text declaration\n"); | 
|  | 5551 | } | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5552 |  | 
|  | 5553 | SKIP_BLANKS; | 
|  | 5554 | if ((RAW == '?') && (NXT(1) == '>')) { | 
|  | 5555 | SKIP(2); | 
|  | 5556 | } else if (RAW == '>') { | 
|  | 5557 | /* Deprecated old WD ... */ | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5558 | xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5559 | NEXT; | 
|  | 5560 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5561 | xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); | 
| Daniel Veillard | 5e3eecb | 2001-07-31 15:10:53 +0000 | [diff] [blame] | 5562 | MOVETO_ENDTAG(CUR_PTR); | 
|  | 5563 | NEXT; | 
|  | 5564 | } | 
|  | 5565 | } | 
|  | 5566 |  | 
|  | 5567 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5568 | * xmlParseExternalSubset: | 
|  | 5569 | * @ctxt:  an XML parser context | 
|  | 5570 | * @ExternalID: the external identifier | 
|  | 5571 | * @SystemID: the system identifier (or URL) | 
|  | 5572 | * | 
|  | 5573 | * parse Markup declarations from an external subset | 
|  | 5574 | * | 
|  | 5575 | * [30] extSubset ::= textDecl? extSubsetDecl | 
|  | 5576 | * | 
|  | 5577 | * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) * | 
|  | 5578 | */ | 
|  | 5579 | void | 
|  | 5580 | xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, | 
|  | 5581 | const xmlChar *SystemID) { | 
| Daniel Veillard | 309f81d | 2003-09-23 09:02:53 +0000 | [diff] [blame] | 5582 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5583 | GROW; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5584 | if (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5585 | xmlParseTextDecl(ctxt); | 
|  | 5586 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 5587 | /* | 
|  | 5588 | * The XML REC instructs us to stop parsing right here | 
|  | 5589 | */ | 
|  | 5590 | ctxt->instate = XML_PARSER_EOF; | 
|  | 5591 | return; | 
|  | 5592 | } | 
|  | 5593 | } | 
|  | 5594 | if (ctxt->myDoc == NULL) { | 
|  | 5595 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 5596 | } | 
|  | 5597 | if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL)) | 
|  | 5598 | xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID); | 
|  | 5599 |  | 
|  | 5600 | ctxt->instate = XML_PARSER_DTD; | 
|  | 5601 | ctxt->external = 1; | 
|  | 5602 | while (((RAW == '<') && (NXT(1) == '?')) || | 
|  | 5603 | ((RAW == '<') && (NXT(1) == '!')) || | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5604 | (RAW == '%') || IS_BLANK_CH(CUR)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5605 | const xmlChar *check = CUR_PTR; | 
| Daniel Veillard | 3e59fc5 | 2003-04-18 12:34:58 +0000 | [diff] [blame] | 5606 | unsigned int cons = ctxt->input->consumed; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5607 |  | 
|  | 5608 | GROW; | 
|  | 5609 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { | 
|  | 5610 | xmlParseConditionalSections(ctxt); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 5611 | } else if (IS_BLANK_CH(CUR)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5612 | NEXT; | 
|  | 5613 | } else if (RAW == '%') { | 
|  | 5614 | xmlParsePEReference(ctxt); | 
|  | 5615 | } else | 
|  | 5616 | xmlParseMarkupDecl(ctxt); | 
|  | 5617 |  | 
|  | 5618 | /* | 
|  | 5619 | * Pop-up of finished entities. | 
|  | 5620 | */ | 
|  | 5621 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 5622 | xmlPopInput(ctxt); | 
|  | 5623 |  | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 5624 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5625 | xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5626 | break; | 
|  | 5627 | } | 
|  | 5628 | } | 
|  | 5629 |  | 
|  | 5630 | if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5631 | xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5632 | } | 
|  | 5633 |  | 
|  | 5634 | } | 
|  | 5635 |  | 
|  | 5636 | /** | 
|  | 5637 | * xmlParseReference: | 
|  | 5638 | * @ctxt:  an XML parser context | 
|  | 5639 | * | 
|  | 5640 | * parse and handle entity references in content, depending on the SAX | 
|  | 5641 | * interface, this may end-up in a call to character() if this is a | 
|  | 5642 | * CharRef, a predefined entity, if there is no reference() callback. | 
|  | 5643 | * or if the parser was asked to switch to that mode. | 
|  | 5644 | * | 
|  | 5645 | * [67] Reference ::= EntityRef | CharRef | 
|  | 5646 | */ | 
|  | 5647 | void | 
|  | 5648 | xmlParseReference(xmlParserCtxtPtr ctxt) { | 
|  | 5649 | xmlEntityPtr ent; | 
|  | 5650 | xmlChar *val; | 
|  | 5651 | if (RAW != '&') return; | 
|  | 5652 |  | 
|  | 5653 | if (NXT(1) == '#') { | 
|  | 5654 | int i = 0; | 
|  | 5655 | xmlChar out[10]; | 
|  | 5656 | int hex = NXT(2); | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 5657 | int value = xmlParseCharRef(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5658 |  | 
|  | 5659 | if (ctxt->charset != XML_CHAR_ENCODING_UTF8) { | 
|  | 5660 | /* | 
|  | 5661 | * So we are using non-UTF-8 buffers | 
|  | 5662 | * Check that the char fit on 8bits, if not | 
|  | 5663 | * generate a CharRef. | 
|  | 5664 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 5665 | if (value <= 0xFF) { | 
|  | 5666 | out[0] = value; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5667 | out[1] = 0; | 
|  | 5668 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && | 
|  | 5669 | (!ctxt->disableSAX)) | 
|  | 5670 | ctxt->sax->characters(ctxt->userData, out, 1); | 
|  | 5671 | } else { | 
|  | 5672 | if ((hex == 'x') || (hex == 'X')) | 
| Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 5673 | snprintf((char *)out, sizeof(out), "#x%X", value); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5674 | else | 
| Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 5675 | snprintf((char *)out, sizeof(out), "#%d", value); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5676 | if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) && | 
|  | 5677 | (!ctxt->disableSAX)) | 
|  | 5678 | ctxt->sax->reference(ctxt->userData, out); | 
|  | 5679 | } | 
|  | 5680 | } else { | 
|  | 5681 | /* | 
|  | 5682 | * Just encode the value in UTF-8 | 
|  | 5683 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 5684 | COPY_BUF(0 ,out, i, value); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5685 | out[i] = 0; | 
|  | 5686 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && | 
|  | 5687 | (!ctxt->disableSAX)) | 
|  | 5688 | ctxt->sax->characters(ctxt->userData, out, i); | 
|  | 5689 | } | 
|  | 5690 | } else { | 
|  | 5691 | ent = xmlParseEntityRef(ctxt); | 
|  | 5692 | if (ent == NULL) return; | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 5693 | if (!ctxt->wellFormed) | 
|  | 5694 | return; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5695 | if ((ent->name != NULL) && | 
|  | 5696 | (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY)) { | 
|  | 5697 | xmlNodePtr list = NULL; | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 5698 | xmlParserErrors ret = XML_ERR_OK; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5699 |  | 
|  | 5700 |  | 
|  | 5701 | /* | 
|  | 5702 | * The first reference to the entity trigger a parsing phase | 
|  | 5703 | * where the ent->children is filled with the result from | 
|  | 5704 | * the parsing. | 
|  | 5705 | */ | 
|  | 5706 | if (ent->children == NULL) { | 
|  | 5707 | xmlChar *value; | 
|  | 5708 | value = ent->content; | 
|  | 5709 |  | 
|  | 5710 | /* | 
|  | 5711 | * Check that this entity is well formed | 
|  | 5712 | */ | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 5713 | if ((value != NULL) && (value[0] != 0) && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5714 | (value[1] == 0) && (value[0] == '<') && | 
|  | 5715 | (xmlStrEqual(ent->name, BAD_CAST "lt"))) { | 
|  | 5716 | /* | 
|  | 5717 | * DONE: get definite answer on this !!! | 
|  | 5718 | * Lots of entity decls are used to declare a single | 
|  | 5719 | * char | 
|  | 5720 | *    <!ENTITY lt     "<"> | 
|  | 5721 | * Which seems to be valid since | 
|  | 5722 | * 2.4: The ampersand character (&) and the left angle | 
|  | 5723 | * bracket (<) may appear in their literal form only | 
|  | 5724 | * when used ... They are also legal within the literal | 
|  | 5725 | * entity value of an internal entity declaration;i | 
|  | 5726 | * see "4.3.2 Well-Formed Parsed Entities". | 
|  | 5727 | * IMHO 2.4 and 4.3.2 are directly in contradiction. | 
|  | 5728 | * Looking at the OASIS test suite and James Clark | 
|  | 5729 | * tests, this is broken. However the XML REC uses | 
|  | 5730 | * it. Is the XML REC not well-formed ???? | 
|  | 5731 | * This is a hack to avoid this problem | 
|  | 5732 | * | 
|  | 5733 | * ANSWER: since lt gt amp .. are already defined, | 
|  | 5734 | *   this is a redefinition and hence the fact that the | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 5735 | *   content is not well balanced is not a Wf error, this | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5736 | *   is lousy but acceptable. | 
|  | 5737 | */ | 
|  | 5738 | list = xmlNewDocText(ctxt->myDoc, value); | 
|  | 5739 | if (list != NULL) { | 
|  | 5740 | if ((ent->etype == XML_INTERNAL_GENERAL_ENTITY) && | 
|  | 5741 | (ent->children == NULL)) { | 
|  | 5742 | ent->children = list; | 
|  | 5743 | ent->last = list; | 
| Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 5744 | ent->owner = 1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5745 | list->parent = (xmlNodePtr) ent; | 
|  | 5746 | } else { | 
|  | 5747 | xmlFreeNodeList(list); | 
|  | 5748 | } | 
|  | 5749 | } else if (list != NULL) { | 
|  | 5750 | xmlFreeNodeList(list); | 
|  | 5751 | } | 
|  | 5752 | } else { | 
|  | 5753 | /* | 
|  | 5754 | * 4.3.2: An internal general parsed entity is well-formed | 
|  | 5755 | * if its replacement text matches the production labeled | 
|  | 5756 | * content. | 
|  | 5757 | */ | 
| Daniel Veillard | b5a60ec | 2002-03-18 11:45:56 +0000 | [diff] [blame] | 5758 |  | 
|  | 5759 | void *user_data; | 
|  | 5760 | /* | 
|  | 5761 | * This is a bit hackish but this seems the best | 
|  | 5762 | * way to make sure both SAX and DOM entity support | 
|  | 5763 | * behaves okay. | 
|  | 5764 | */ | 
|  | 5765 | if (ctxt->userData == ctxt) | 
|  | 5766 | user_data = NULL; | 
|  | 5767 | else | 
|  | 5768 | user_data = ctxt->userData; | 
|  | 5769 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5770 | if (ent->etype == XML_INTERNAL_GENERAL_ENTITY) { | 
|  | 5771 | ctxt->depth++; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 5772 | ret = xmlParseBalancedChunkMemoryInternal(ctxt, | 
|  | 5773 | value, user_data, &list); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5774 | ctxt->depth--; | 
|  | 5775 | } else if (ent->etype == | 
|  | 5776 | XML_EXTERNAL_GENERAL_PARSED_ENTITY) { | 
|  | 5777 | ctxt->depth++; | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 5778 | ret = xmlParseExternalEntityPrivate(ctxt->myDoc, ctxt, | 
| Daniel Veillard | b5a60ec | 2002-03-18 11:45:56 +0000 | [diff] [blame] | 5779 | ctxt->sax, user_data, ctxt->depth, | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 5780 | ent->URI, ent->ExternalID, &list); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5781 | ctxt->depth--; | 
|  | 5782 | } else { | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 5783 | ret = XML_ERR_ENTITY_PE_INTERNAL; | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 5784 | xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 5785 | "invalid entity type found\n", NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5786 | } | 
|  | 5787 | if (ret == XML_ERR_ENTITY_LOOP) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5788 | xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL); | 
| Daniel Veillard | bb7ddb3 | 2002-02-17 21:26:33 +0000 | [diff] [blame] | 5789 | return; | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 5790 | } else if ((ret == XML_ERR_OK) && (list != NULL)) { | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 5791 | if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) || | 
|  | 5792 | (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))&& | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5793 | (ent->children == NULL)) { | 
|  | 5794 | ent->children = list; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5795 | if (ctxt->replaceEntities) { | 
|  | 5796 | /* | 
|  | 5797 | * Prune it directly in the generated document | 
|  | 5798 | * except for single text nodes. | 
|  | 5799 | */ | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5800 | if (((list->type == XML_TEXT_NODE) && | 
|  | 5801 | (list->next == NULL)) || | 
|  | 5802 | (ctxt->parseMode == XML_PARSE_READER)) { | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5803 | list->parent = (xmlNodePtr) ent; | 
|  | 5804 | list = NULL; | 
| Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 5805 | ent->owner = 1; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5806 | } else { | 
| Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 5807 | ent->owner = 0; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5808 | while (list != NULL) { | 
|  | 5809 | list->parent = (xmlNodePtr) ctxt->node; | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 5810 | list->doc = ctxt->myDoc; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5811 | if (list->next == NULL) | 
|  | 5812 | ent->last = list; | 
|  | 5813 | list = list->next; | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 5814 | } | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5815 | list = ent->children; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 5816 | #ifdef LIBXML_LEGACY_ENABLED | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 5817 | if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) | 
|  | 5818 | xmlAddEntityReference(ent, list, NULL); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 5819 | #endif /* LIBXML_LEGACY_ENABLED */ | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5820 | } | 
|  | 5821 | } else { | 
| Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 5822 | ent->owner = 1; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5823 | while (list != NULL) { | 
|  | 5824 | list->parent = (xmlNodePtr) ent; | 
|  | 5825 | if (list->next == NULL) | 
|  | 5826 | ent->last = list; | 
|  | 5827 | list = list->next; | 
|  | 5828 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5829 | } | 
|  | 5830 | } else { | 
|  | 5831 | xmlFreeNodeList(list); | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5832 | list = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5833 | } | 
| William M. Brack | b670e2e | 2003-09-27 01:05:55 +0000 | [diff] [blame] | 5834 | } else if ((ret != XML_ERR_OK) && | 
|  | 5835 | (ret != XML_WAR_UNDECLARED_ENTITY)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 5836 | xmlFatalErr(ctxt, ret, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5837 | } else if (list != NULL) { | 
|  | 5838 | xmlFreeNodeList(list); | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5839 | list = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5840 | } | 
|  | 5841 | } | 
|  | 5842 | } | 
|  | 5843 | if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) && | 
|  | 5844 | (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) { | 
|  | 5845 | /* | 
|  | 5846 | * Create a node. | 
|  | 5847 | */ | 
|  | 5848 | ctxt->sax->reference(ctxt->userData, ent->name); | 
|  | 5849 | return; | 
|  | 5850 | } else if (ctxt->replaceEntities) { | 
| William M. Brack | 1227fb3 | 2004-10-25 23:17:53 +0000 | [diff] [blame] | 5851 | /* | 
|  | 5852 | * There is a problem on the handling of _private for entities | 
|  | 5853 | * (bug 155816): Should we copy the content of the field from | 
|  | 5854 | * the entity (possibly overwriting some value set by the user | 
|  | 5855 | * when a copy is created), should we leave it alone, or should | 
|  | 5856 | * we try to take care of different situations?  The problem | 
|  | 5857 | * is exacerbated by the usage of this field by the xmlReader. | 
|  | 5858 | * To fix this bug, we look at _private on the created node | 
|  | 5859 | * and, if it's NULL, we copy in whatever was in the entity. | 
|  | 5860 | * If it's not NULL we leave it alone.  This is somewhat of a | 
|  | 5861 | * hack - maybe we should have further tests to determine | 
|  | 5862 | * what to do. | 
|  | 5863 | */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5864 | if ((ctxt->node != NULL) && (ent->children != NULL)) { | 
|  | 5865 | /* | 
|  | 5866 | * Seems we are generating the DOM content, do | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5867 | * a simple tree copy for all references except the first | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5868 | * In the first occurrence list contains the replacement. | 
|  | 5869 | * progressive == 2 means we are operating on the Reader | 
|  | 5870 | * and since nodes are discarded we must copy all the time. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5871 | */ | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5872 | if (((list == NULL) && (ent->owner == 0)) || | 
|  | 5873 | (ctxt->parseMode == XML_PARSE_READER)) { | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5874 | xmlNodePtr nw = NULL, cur, firstChild = NULL; | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5875 |  | 
|  | 5876 | /* | 
|  | 5877 | * when operating on a reader, the entities definitions | 
|  | 5878 | * are always owning the entities subtree. | 
|  | 5879 | if (ctxt->parseMode == XML_PARSE_READER) | 
|  | 5880 | ent->owner = 1; | 
|  | 5881 | */ | 
|  | 5882 |  | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5883 | cur = ent->children; | 
|  | 5884 | while (cur != NULL) { | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 5885 | nw = xmlDocCopyNode(cur, ctxt->myDoc, 1); | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5886 | if (nw != NULL) { | 
| William M. Brack | 1227fb3 | 2004-10-25 23:17:53 +0000 | [diff] [blame] | 5887 | if (nw->_private == NULL) | 
|  | 5888 | nw->_private = cur->_private; | 
| Daniel Veillard | 8f87244 | 2003-01-09 23:19:02 +0000 | [diff] [blame] | 5889 | if (firstChild == NULL){ | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5890 | firstChild = nw; | 
| Daniel Veillard | 8f87244 | 2003-01-09 23:19:02 +0000 | [diff] [blame] | 5891 | } | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5892 | nw = xmlAddChild(ctxt->node, nw); | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 5893 | } | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5894 | if (cur == ent->last) { | 
|  | 5895 | /* | 
|  | 5896 | * needed to detect some strange empty | 
|  | 5897 | * node cases in the reader tests | 
|  | 5898 | */ | 
|  | 5899 | if ((ctxt->parseMode == XML_PARSE_READER) && | 
|  | 5900 | (nw->type == XML_ELEMENT_NODE) && | 
|  | 5901 | (nw->children == NULL)) | 
|  | 5902 | nw->extra = 1; | 
|  | 5903 |  | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5904 | break; | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 5905 | } | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5906 | cur = cur->next; | 
|  | 5907 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 5908 | #ifdef LIBXML_LEGACY_ENABLED | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 5909 | if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5910 | xmlAddEntityReference(ent, firstChild, nw); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 5911 | #endif /* LIBXML_LEGACY_ENABLED */ | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5912 | } else if (list == NULL) { | 
|  | 5913 | xmlNodePtr nw = NULL, cur, next, last, | 
|  | 5914 | firstChild = NULL; | 
|  | 5915 | /* | 
|  | 5916 | * Copy the entity child list and make it the new | 
|  | 5917 | * entity child list. The goal is to make sure any | 
|  | 5918 | * ID or REF referenced will be the one from the | 
|  | 5919 | * document content and not the entity copy. | 
|  | 5920 | */ | 
|  | 5921 | cur = ent->children; | 
|  | 5922 | ent->children = NULL; | 
|  | 5923 | last = ent->last; | 
|  | 5924 | ent->last = NULL; | 
|  | 5925 | while (cur != NULL) { | 
|  | 5926 | next = cur->next; | 
|  | 5927 | cur->next = NULL; | 
|  | 5928 | cur->parent = NULL; | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 5929 | nw = xmlDocCopyNode(cur, ctxt->myDoc, 1); | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5930 | if (nw != NULL) { | 
| William M. Brack | 1227fb3 | 2004-10-25 23:17:53 +0000 | [diff] [blame] | 5931 | if (nw->_private == NULL) | 
|  | 5932 | nw->_private = cur->_private; | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5933 | if (firstChild == NULL){ | 
|  | 5934 | firstChild = cur; | 
|  | 5935 | } | 
|  | 5936 | xmlAddChild((xmlNodePtr) ent, nw); | 
|  | 5937 | xmlAddChild(ctxt->node, cur); | 
|  | 5938 | } | 
|  | 5939 | if (cur == last) | 
|  | 5940 | break; | 
|  | 5941 | cur = next; | 
|  | 5942 | } | 
|  | 5943 | ent->owner = 1; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 5944 | #ifdef LIBXML_LEGACY_ENABLED | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 5945 | if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) | 
|  | 5946 | xmlAddEntityReference(ent, firstChild, nw); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 5947 | #endif /* LIBXML_LEGACY_ENABLED */ | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5948 | } else { | 
| Daniel Veillard | 370ba3d | 2004-10-25 16:23:56 +0000 | [diff] [blame] | 5949 | const xmlChar *nbktext; | 
|  | 5950 |  | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5951 | /* | 
|  | 5952 | * the name change is to avoid coalescing of the | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 5953 | * node with a possible previous text one which | 
|  | 5954 | * would make ent->children a dangling pointer | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5955 | */ | 
| Daniel Veillard | 370ba3d | 2004-10-25 16:23:56 +0000 | [diff] [blame] | 5956 | nbktext = xmlDictLookup(ctxt->dict, BAD_CAST "nbktext", | 
|  | 5957 | -1); | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5958 | if (ent->children->type == XML_TEXT_NODE) | 
| Daniel Veillard | 370ba3d | 2004-10-25 16:23:56 +0000 | [diff] [blame] | 5959 | ent->children->name = nbktext; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5960 | if ((ent->last != ent->children) && | 
|  | 5961 | (ent->last->type == XML_TEXT_NODE)) | 
| Daniel Veillard | 370ba3d | 2004-10-25 16:23:56 +0000 | [diff] [blame] | 5962 | ent->last->name = nbktext; | 
| Daniel Veillard | 62f313b | 2001-07-04 19:49:14 +0000 | [diff] [blame] | 5963 | xmlAddChildList(ctxt->node, ent->children); | 
|  | 5964 | } | 
|  | 5965 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5966 | /* | 
|  | 5967 | * This is to avoid a nasty side effect, see | 
|  | 5968 | * characters() in SAX.c | 
|  | 5969 | */ | 
|  | 5970 | ctxt->nodemem = 0; | 
|  | 5971 | ctxt->nodelen = 0; | 
|  | 5972 | return; | 
|  | 5973 | } else { | 
|  | 5974 | /* | 
|  | 5975 | * Probably running in SAX mode | 
|  | 5976 | */ | 
|  | 5977 | xmlParserInputPtr input; | 
|  | 5978 |  | 
|  | 5979 | input = xmlNewEntityInputStream(ctxt, ent); | 
|  | 5980 | xmlPushInput(ctxt, input); | 
|  | 5981 | if ((ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) && | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 5982 | (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && | 
|  | 5983 | (IS_BLANK_CH(NXT(5)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5984 | xmlParseTextDecl(ctxt); | 
|  | 5985 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 5986 | /* | 
|  | 5987 | * The XML REC instructs us to stop parsing right here | 
|  | 5988 | */ | 
|  | 5989 | ctxt->instate = XML_PARSER_EOF; | 
|  | 5990 | return; | 
|  | 5991 | } | 
|  | 5992 | if (input->standalone == 1) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 5993 | xmlFatalErr(ctxt, XML_ERR_EXT_ENTITY_STANDALONE, | 
|  | 5994 | NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5995 | } | 
|  | 5996 | } | 
|  | 5997 | return; | 
|  | 5998 | } | 
|  | 5999 | } | 
|  | 6000 | } else { | 
|  | 6001 | val = ent->content; | 
|  | 6002 | if (val == NULL) return; | 
|  | 6003 | /* | 
|  | 6004 | * inline the entity. | 
|  | 6005 | */ | 
|  | 6006 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && | 
|  | 6007 | (!ctxt->disableSAX)) | 
|  | 6008 | ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val)); | 
|  | 6009 | } | 
|  | 6010 | } | 
|  | 6011 | } | 
|  | 6012 |  | 
|  | 6013 | /** | 
|  | 6014 | * xmlParseEntityRef: | 
|  | 6015 | * @ctxt:  an XML parser context | 
|  | 6016 | * | 
|  | 6017 | * parse ENTITY references declarations | 
|  | 6018 | * | 
|  | 6019 | * [68] EntityRef ::= '&' Name ';' | 
|  | 6020 | * | 
|  | 6021 | * [ WFC: Entity Declared ] | 
|  | 6022 | * In a document without any DTD, a document with only an internal DTD | 
|  | 6023 | * subset which contains no parameter entity references, or a document | 
|  | 6024 | * with "standalone='yes'", the Name given in the entity reference | 
|  | 6025 | * must match that in an entity declaration, except that well-formed | 
|  | 6026 | * documents need not declare any of the following entities: amp, lt, | 
|  | 6027 | * gt, apos, quot.  The declaration of a parameter entity must precede | 
|  | 6028 | * any reference to it.  Similarly, the declaration of a general entity | 
|  | 6029 | * must precede any reference to it which appears in a default value in an | 
|  | 6030 | * attribute-list declaration. Note that if entities are declared in the | 
|  | 6031 | * external subset or in external parameter entities, a non-validating | 
|  | 6032 | * processor is not obligated to read and process their declarations; | 
|  | 6033 | * for such documents, the rule that an entity must be declared is a | 
|  | 6034 | * well-formedness constraint only if standalone='yes'. | 
|  | 6035 | * | 
|  | 6036 | * [ WFC: Parsed Entity ] | 
|  | 6037 | * An entity reference must not contain the name of an unparsed entity | 
|  | 6038 | * | 
|  | 6039 | * Returns the xmlEntityPtr if found, or NULL otherwise. | 
|  | 6040 | */ | 
|  | 6041 | xmlEntityPtr | 
|  | 6042 | xmlParseEntityRef(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6043 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6044 | xmlEntityPtr ent = NULL; | 
|  | 6045 |  | 
|  | 6046 | GROW; | 
|  | 6047 |  | 
|  | 6048 | if (RAW == '&') { | 
|  | 6049 | NEXT; | 
|  | 6050 | name = xmlParseName(ctxt); | 
|  | 6051 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6052 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 6053 | "xmlParseEntityRef: no name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6054 | } else { | 
|  | 6055 | if (RAW == ';') { | 
|  | 6056 | NEXT; | 
|  | 6057 | /* | 
|  | 6058 | * Ask first SAX for entity resolution, otherwise try the | 
|  | 6059 | * predefined set. | 
|  | 6060 | */ | 
|  | 6061 | if (ctxt->sax != NULL) { | 
|  | 6062 | if (ctxt->sax->getEntity != NULL) | 
|  | 6063 | ent = ctxt->sax->getEntity(ctxt->userData, name); | 
| Daniel Veillard | 39eb88b | 2003-03-11 11:21:28 +0000 | [diff] [blame] | 6064 | if ((ctxt->wellFormed == 1 ) && (ent == NULL)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6065 | ent = xmlGetPredefinedEntity(name); | 
| Daniel Veillard | 39eb88b | 2003-03-11 11:21:28 +0000 | [diff] [blame] | 6066 | if ((ctxt->wellFormed == 1 ) && (ent == NULL) && | 
|  | 6067 | (ctxt->userData==ctxt)) { | 
| Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 6068 | ent = xmlSAX2GetEntity(ctxt, name); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 6069 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6070 | } | 
|  | 6071 | /* | 
|  | 6072 | * [ WFC: Entity Declared ] | 
|  | 6073 | * In a document without any DTD, a document with only an | 
|  | 6074 | * internal DTD subset which contains no parameter entity | 
|  | 6075 | * references, or a document with "standalone='yes'", the | 
|  | 6076 | * Name given in the entity reference must match that in an | 
|  | 6077 | * entity declaration, except that well-formed documents | 
|  | 6078 | * need not declare any of the following entities: amp, lt, | 
|  | 6079 | * gt, apos, quot. | 
|  | 6080 | * The declaration of a parameter entity must precede any | 
|  | 6081 | * reference to it. | 
|  | 6082 | * Similarly, the declaration of a general entity must | 
|  | 6083 | * precede any reference to it which appears in a default | 
|  | 6084 | * value in an attribute-list declaration. Note that if | 
|  | 6085 | * entities are declared in the external subset or in | 
|  | 6086 | * external parameter entities, a non-validating processor | 
|  | 6087 | * is not obligated to read and process their declarations; | 
|  | 6088 | * for such documents, the rule that an entity must be | 
|  | 6089 | * declared is a well-formedness constraint only if | 
|  | 6090 | * standalone='yes'. | 
|  | 6091 | */ | 
|  | 6092 | if (ent == NULL) { | 
|  | 6093 | if ((ctxt->standalone == 1) || | 
|  | 6094 | ((ctxt->hasExternalSubset == 0) && | 
|  | 6095 | (ctxt->hasPErefs == 0))) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6096 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6097 | "Entity '%s' not defined\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6098 | } else { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6099 | xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6100 | "Entity '%s' not defined\n", name); | 
|  | 6101 | } | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6102 | ctxt->valid = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6103 | } | 
|  | 6104 |  | 
|  | 6105 | /* | 
|  | 6106 | * [ WFC: Parsed Entity ] | 
|  | 6107 | * An entity reference must not contain the name of an | 
|  | 6108 | * unparsed entity | 
|  | 6109 | */ | 
|  | 6110 | else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6111 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6112 | "Entity reference to unparsed entity %s\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6113 | } | 
|  | 6114 |  | 
|  | 6115 | /* | 
|  | 6116 | * [ WFC: No External Entity References ] | 
|  | 6117 | * Attribute values cannot contain direct or indirect | 
|  | 6118 | * entity references to external entities. | 
|  | 6119 | */ | 
|  | 6120 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && | 
|  | 6121 | (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6122 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL, | 
|  | 6123 | "Attribute references external entity '%s'\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6124 | } | 
|  | 6125 | /* | 
|  | 6126 | * [ WFC: No < in Attribute Values ] | 
|  | 6127 | * The replacement text of any entity referred to directly or | 
|  | 6128 | * indirectly in an attribute value (other than "<") must | 
|  | 6129 | * not contain a <. | 
|  | 6130 | */ | 
|  | 6131 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && | 
|  | 6132 | (ent != NULL) && | 
|  | 6133 | (!xmlStrEqual(ent->name, BAD_CAST "lt")) && | 
|  | 6134 | (ent->content != NULL) && | 
|  | 6135 | (xmlStrchr(ent->content, '<'))) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6136 | xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6137 | "'<' in entity '%s' is not allowed in attributes values\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6138 | } | 
|  | 6139 |  | 
|  | 6140 | /* | 
|  | 6141 | * Internal check, no parameter entities here ... | 
|  | 6142 | */ | 
|  | 6143 | else { | 
|  | 6144 | switch (ent->etype) { | 
|  | 6145 | case XML_INTERNAL_PARAMETER_ENTITY: | 
|  | 6146 | case XML_EXTERNAL_PARAMETER_ENTITY: | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6147 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER, | 
|  | 6148 | "Attempt to reference the parameter entity '%s'\n", | 
|  | 6149 | name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6150 | break; | 
|  | 6151 | default: | 
|  | 6152 | break; | 
|  | 6153 | } | 
|  | 6154 | } | 
|  | 6155 |  | 
|  | 6156 | /* | 
|  | 6157 | * [ WFC: No Recursion ] | 
|  | 6158 | * A parsed entity must not contain a recursive reference | 
|  | 6159 | * to itself, either directly or indirectly. | 
|  | 6160 | * Done somewhere else | 
|  | 6161 | */ | 
|  | 6162 |  | 
|  | 6163 | } else { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6164 | xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6165 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6166 | } | 
|  | 6167 | } | 
|  | 6168 | return(ent); | 
|  | 6169 | } | 
|  | 6170 |  | 
|  | 6171 | /** | 
|  | 6172 | * xmlParseStringEntityRef: | 
|  | 6173 | * @ctxt:  an XML parser context | 
|  | 6174 | * @str:  a pointer to an index in the string | 
|  | 6175 | * | 
|  | 6176 | * parse ENTITY references declarations, but this version parses it from | 
|  | 6177 | * a string value. | 
|  | 6178 | * | 
|  | 6179 | * [68] EntityRef ::= '&' Name ';' | 
|  | 6180 | * | 
|  | 6181 | * [ WFC: Entity Declared ] | 
|  | 6182 | * In a document without any DTD, a document with only an internal DTD | 
|  | 6183 | * subset which contains no parameter entity references, or a document | 
|  | 6184 | * with "standalone='yes'", the Name given in the entity reference | 
|  | 6185 | * must match that in an entity declaration, except that well-formed | 
|  | 6186 | * documents need not declare any of the following entities: amp, lt, | 
|  | 6187 | * gt, apos, quot.  The declaration of a parameter entity must precede | 
|  | 6188 | * any reference to it.  Similarly, the declaration of a general entity | 
|  | 6189 | * must precede any reference to it which appears in a default value in an | 
|  | 6190 | * attribute-list declaration. Note that if entities are declared in the | 
|  | 6191 | * external subset or in external parameter entities, a non-validating | 
|  | 6192 | * processor is not obligated to read and process their declarations; | 
|  | 6193 | * for such documents, the rule that an entity must be declared is a | 
|  | 6194 | * well-formedness constraint only if standalone='yes'. | 
|  | 6195 | * | 
|  | 6196 | * [ WFC: Parsed Entity ] | 
|  | 6197 | * An entity reference must not contain the name of an unparsed entity | 
|  | 6198 | * | 
|  | 6199 | * Returns the xmlEntityPtr if found, or NULL otherwise. The str pointer | 
|  | 6200 | * is updated to the current location in the string. | 
|  | 6201 | */ | 
|  | 6202 | xmlEntityPtr | 
|  | 6203 | xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) { | 
|  | 6204 | xmlChar *name; | 
|  | 6205 | const xmlChar *ptr; | 
|  | 6206 | xmlChar cur; | 
|  | 6207 | xmlEntityPtr ent = NULL; | 
|  | 6208 |  | 
|  | 6209 | if ((str == NULL) || (*str == NULL)) | 
|  | 6210 | return(NULL); | 
|  | 6211 | ptr = *str; | 
|  | 6212 | cur = *ptr; | 
|  | 6213 | if (cur == '&') { | 
|  | 6214 | ptr++; | 
|  | 6215 | cur = *ptr; | 
|  | 6216 | name = xmlParseStringName(ctxt, &ptr); | 
|  | 6217 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6218 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 6219 | "xmlParseStringEntityRef: no name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6220 | } else { | 
|  | 6221 | if (*ptr == ';') { | 
|  | 6222 | ptr++; | 
|  | 6223 | /* | 
|  | 6224 | * Ask first SAX for entity resolution, otherwise try the | 
|  | 6225 | * predefined set. | 
|  | 6226 | */ | 
|  | 6227 | if (ctxt->sax != NULL) { | 
|  | 6228 | if (ctxt->sax->getEntity != NULL) | 
|  | 6229 | ent = ctxt->sax->getEntity(ctxt->userData, name); | 
|  | 6230 | if (ent == NULL) | 
|  | 6231 | ent = xmlGetPredefinedEntity(name); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 6232 | if ((ent == NULL) && (ctxt->userData==ctxt)) { | 
| Daniel Veillard | 1af9a41 | 2003-08-20 22:54:39 +0000 | [diff] [blame] | 6233 | ent = xmlSAX2GetEntity(ctxt, name); | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 6234 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6235 | } | 
|  | 6236 | /* | 
|  | 6237 | * [ WFC: Entity Declared ] | 
|  | 6238 | * In a document without any DTD, a document with only an | 
|  | 6239 | * internal DTD subset which contains no parameter entity | 
|  | 6240 | * references, or a document with "standalone='yes'", the | 
|  | 6241 | * Name given in the entity reference must match that in an | 
|  | 6242 | * entity declaration, except that well-formed documents | 
|  | 6243 | * need not declare any of the following entities: amp, lt, | 
|  | 6244 | * gt, apos, quot. | 
|  | 6245 | * The declaration of a parameter entity must precede any | 
|  | 6246 | * reference to it. | 
|  | 6247 | * Similarly, the declaration of a general entity must | 
|  | 6248 | * precede any reference to it which appears in a default | 
|  | 6249 | * value in an attribute-list declaration. Note that if | 
|  | 6250 | * entities are declared in the external subset or in | 
|  | 6251 | * external parameter entities, a non-validating processor | 
|  | 6252 | * is not obligated to read and process their declarations; | 
|  | 6253 | * for such documents, the rule that an entity must be | 
|  | 6254 | * declared is a well-formedness constraint only if | 
|  | 6255 | * standalone='yes'. | 
|  | 6256 | */ | 
|  | 6257 | if (ent == NULL) { | 
|  | 6258 | if ((ctxt->standalone == 1) || | 
|  | 6259 | ((ctxt->hasExternalSubset == 0) && | 
|  | 6260 | (ctxt->hasPErefs == 0))) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6261 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6262 | "Entity '%s' not defined\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6263 | } else { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6264 | xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 6265 | "Entity '%s' not defined\n", | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6266 | name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6267 | } | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 6268 | /* TODO ? check regressions ctxt->valid = 0; */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6269 | } | 
|  | 6270 |  | 
|  | 6271 | /* | 
|  | 6272 | * [ WFC: Parsed Entity ] | 
|  | 6273 | * An entity reference must not contain the name of an | 
|  | 6274 | * unparsed entity | 
|  | 6275 | */ | 
|  | 6276 | else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6277 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6278 | "Entity reference to unparsed entity %s\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6279 | } | 
|  | 6280 |  | 
|  | 6281 | /* | 
|  | 6282 | * [ WFC: No External Entity References ] | 
|  | 6283 | * Attribute values cannot contain direct or indirect | 
|  | 6284 | * entity references to external entities. | 
|  | 6285 | */ | 
|  | 6286 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && | 
|  | 6287 | (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6288 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6289 | "Attribute references external entity '%s'\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6290 | } | 
|  | 6291 | /* | 
|  | 6292 | * [ WFC: No < in Attribute Values ] | 
|  | 6293 | * The replacement text of any entity referred to directly or | 
|  | 6294 | * indirectly in an attribute value (other than "<") must | 
|  | 6295 | * not contain a <. | 
|  | 6296 | */ | 
|  | 6297 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && | 
|  | 6298 | (ent != NULL) && | 
|  | 6299 | (!xmlStrEqual(ent->name, BAD_CAST "lt")) && | 
|  | 6300 | (ent->content != NULL) && | 
|  | 6301 | (xmlStrchr(ent->content, '<'))) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6302 | xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, | 
|  | 6303 | "'<' in entity '%s' is not allowed in attributes values\n", | 
|  | 6304 | name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6305 | } | 
|  | 6306 |  | 
|  | 6307 | /* | 
|  | 6308 | * Internal check, no parameter entities here ... | 
|  | 6309 | */ | 
|  | 6310 | else { | 
|  | 6311 | switch (ent->etype) { | 
|  | 6312 | case XML_INTERNAL_PARAMETER_ENTITY: | 
|  | 6313 | case XML_EXTERNAL_PARAMETER_ENTITY: | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6314 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER, | 
|  | 6315 | "Attempt to reference the parameter entity '%s'\n", | 
|  | 6316 | name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6317 | break; | 
|  | 6318 | default: | 
|  | 6319 | break; | 
|  | 6320 | } | 
|  | 6321 | } | 
|  | 6322 |  | 
|  | 6323 | /* | 
|  | 6324 | * [ WFC: No Recursion ] | 
|  | 6325 | * A parsed entity must not contain a recursive reference | 
|  | 6326 | * to itself, either directly or indirectly. | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 6327 | * Done somewhere else | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6328 | */ | 
|  | 6329 |  | 
|  | 6330 | } else { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6331 | xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6332 | } | 
|  | 6333 | xmlFree(name); | 
|  | 6334 | } | 
|  | 6335 | } | 
|  | 6336 | *str = ptr; | 
|  | 6337 | return(ent); | 
|  | 6338 | } | 
|  | 6339 |  | 
|  | 6340 | /** | 
|  | 6341 | * xmlParsePEReference: | 
|  | 6342 | * @ctxt:  an XML parser context | 
|  | 6343 | * | 
|  | 6344 | * parse PEReference declarations | 
|  | 6345 | * The entity content is handled directly by pushing it's content as | 
|  | 6346 | * a new input stream. | 
|  | 6347 | * | 
|  | 6348 | * [69] PEReference ::= '%' Name ';' | 
|  | 6349 | * | 
|  | 6350 | * [ WFC: No Recursion ] | 
|  | 6351 | * A parsed entity must not contain a recursive | 
|  | 6352 | * reference to itself, either directly or indirectly. | 
|  | 6353 | * | 
|  | 6354 | * [ WFC: Entity Declared ] | 
|  | 6355 | * In a document without any DTD, a document with only an internal DTD | 
|  | 6356 | * subset which contains no parameter entity references, or a document | 
|  | 6357 | * with "standalone='yes'", ...  ... The declaration of a parameter | 
|  | 6358 | * entity must precede any reference to it... | 
|  | 6359 | * | 
|  | 6360 | * [ VC: Entity Declared ] | 
|  | 6361 | * In a document with an external subset or external parameter entities | 
|  | 6362 | * with "standalone='no'", ...  ... The declaration of a parameter entity | 
|  | 6363 | * must precede any reference to it... | 
|  | 6364 | * | 
|  | 6365 | * [ WFC: In DTD ] | 
|  | 6366 | * Parameter-entity references may only appear in the DTD. | 
|  | 6367 | * NOTE: misleading but this is handled. | 
|  | 6368 | */ | 
|  | 6369 | void | 
| Daniel Veillard | 8f597c3 | 2003-10-06 08:19:27 +0000 | [diff] [blame] | 6370 | xmlParsePEReference(xmlParserCtxtPtr ctxt) | 
|  | 6371 | { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6372 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6373 | xmlEntityPtr entity = NULL; | 
|  | 6374 | xmlParserInputPtr input; | 
|  | 6375 |  | 
|  | 6376 | if (RAW == '%') { | 
|  | 6377 | NEXT; | 
| Daniel Veillard | 76d66f4 | 2001-05-16 21:05:17 +0000 | [diff] [blame] | 6378 | name = xmlParseName(ctxt); | 
| Daniel Veillard | 8f597c3 | 2003-10-06 08:19:27 +0000 | [diff] [blame] | 6379 | if (name == NULL) { | 
|  | 6380 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 6381 | "xmlParsePEReference: no name\n"); | 
|  | 6382 | } else { | 
|  | 6383 | if (RAW == ';') { | 
|  | 6384 | NEXT; | 
|  | 6385 | if ((ctxt->sax != NULL) && | 
|  | 6386 | (ctxt->sax->getParameterEntity != NULL)) | 
|  | 6387 | entity = ctxt->sax->getParameterEntity(ctxt->userData, | 
|  | 6388 | name); | 
|  | 6389 | if (entity == NULL) { | 
|  | 6390 | /* | 
|  | 6391 | * [ WFC: Entity Declared ] | 
|  | 6392 | * In a document without any DTD, a document with only an | 
|  | 6393 | * internal DTD subset which contains no parameter entity | 
|  | 6394 | * references, or a document with "standalone='yes'", ... | 
|  | 6395 | * ... The declaration of a parameter entity must precede | 
|  | 6396 | * any reference to it... | 
|  | 6397 | */ | 
|  | 6398 | if ((ctxt->standalone == 1) || | 
|  | 6399 | ((ctxt->hasExternalSubset == 0) && | 
|  | 6400 | (ctxt->hasPErefs == 0))) { | 
|  | 6401 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, | 
|  | 6402 | "PEReference: %%%s; not found\n", | 
|  | 6403 | name); | 
|  | 6404 | } else { | 
|  | 6405 | /* | 
|  | 6406 | * [ VC: Entity Declared ] | 
|  | 6407 | * In a document with an external subset or external | 
|  | 6408 | * parameter entities with "standalone='no'", ... | 
|  | 6409 | * ... The declaration of a parameter entity must | 
|  | 6410 | * precede any reference to it... | 
|  | 6411 | */ | 
|  | 6412 | xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
|  | 6413 | "PEReference: %%%s; not found\n", | 
|  | 6414 | name, NULL); | 
|  | 6415 | ctxt->valid = 0; | 
|  | 6416 | } | 
|  | 6417 | } else { | 
|  | 6418 | /* | 
|  | 6419 | * Internal checking in case the entity quest barfed | 
|  | 6420 | */ | 
|  | 6421 | if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && | 
|  | 6422 | (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { | 
|  | 6423 | xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
|  | 6424 | "Internal: %%%s; is not a parameter entity\n", | 
|  | 6425 | name, NULL); | 
|  | 6426 | } else if (ctxt->input->free != deallocblankswrapper) { | 
|  | 6427 | input = | 
|  | 6428 | xmlNewBlanksWrapperInputStream(ctxt, entity); | 
|  | 6429 | xmlPushInput(ctxt, input); | 
|  | 6430 | } else { | 
|  | 6431 | /* | 
|  | 6432 | * TODO !!! | 
|  | 6433 | * handle the extra spaces added before and after | 
|  | 6434 | * c.f. http://www.w3.org/TR/REC-xml#as-PE | 
|  | 6435 | */ | 
|  | 6436 | input = xmlNewEntityInputStream(ctxt, entity); | 
|  | 6437 | xmlPushInput(ctxt, input); | 
|  | 6438 | if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 6439 | (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 6440 | (IS_BLANK_CH(NXT(5)))) { | 
| Daniel Veillard | 8f597c3 | 2003-10-06 08:19:27 +0000 | [diff] [blame] | 6441 | xmlParseTextDecl(ctxt); | 
|  | 6442 | if (ctxt->errNo == | 
|  | 6443 | XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 6444 | /* | 
|  | 6445 | * The XML REC instructs us to stop parsing | 
|  | 6446 | * right here | 
|  | 6447 | */ | 
|  | 6448 | ctxt->instate = XML_PARSER_EOF; | 
|  | 6449 | return; | 
|  | 6450 | } | 
|  | 6451 | } | 
|  | 6452 | } | 
|  | 6453 | } | 
|  | 6454 | ctxt->hasPErefs = 1; | 
|  | 6455 | } else { | 
|  | 6456 | xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); | 
|  | 6457 | } | 
|  | 6458 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6459 | } | 
|  | 6460 | } | 
|  | 6461 |  | 
|  | 6462 | /** | 
|  | 6463 | * xmlParseStringPEReference: | 
|  | 6464 | * @ctxt:  an XML parser context | 
|  | 6465 | * @str:  a pointer to an index in the string | 
|  | 6466 | * | 
|  | 6467 | * parse PEReference declarations | 
|  | 6468 | * | 
|  | 6469 | * [69] PEReference ::= '%' Name ';' | 
|  | 6470 | * | 
|  | 6471 | * [ WFC: No Recursion ] | 
|  | 6472 | * A parsed entity must not contain a recursive | 
|  | 6473 | * reference to itself, either directly or indirectly. | 
|  | 6474 | * | 
|  | 6475 | * [ WFC: Entity Declared ] | 
|  | 6476 | * In a document without any DTD, a document with only an internal DTD | 
|  | 6477 | * subset which contains no parameter entity references, or a document | 
|  | 6478 | * with "standalone='yes'", ...  ... The declaration of a parameter | 
|  | 6479 | * entity must precede any reference to it... | 
|  | 6480 | * | 
|  | 6481 | * [ VC: Entity Declared ] | 
|  | 6482 | * In a document with an external subset or external parameter entities | 
|  | 6483 | * with "standalone='no'", ...  ... The declaration of a parameter entity | 
|  | 6484 | * must precede any reference to it... | 
|  | 6485 | * | 
|  | 6486 | * [ WFC: In DTD ] | 
|  | 6487 | * Parameter-entity references may only appear in the DTD. | 
|  | 6488 | * NOTE: misleading but this is handled. | 
|  | 6489 | * | 
|  | 6490 | * Returns the string of the entity content. | 
|  | 6491 | *         str is updated to the current value of the index | 
|  | 6492 | */ | 
|  | 6493 | xmlEntityPtr | 
|  | 6494 | xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str) { | 
|  | 6495 | const xmlChar *ptr; | 
|  | 6496 | xmlChar cur; | 
|  | 6497 | xmlChar *name; | 
|  | 6498 | xmlEntityPtr entity = NULL; | 
|  | 6499 |  | 
|  | 6500 | if ((str == NULL) || (*str == NULL)) return(NULL); | 
|  | 6501 | ptr = *str; | 
|  | 6502 | cur = *ptr; | 
|  | 6503 | if (cur == '%') { | 
|  | 6504 | ptr++; | 
|  | 6505 | cur = *ptr; | 
|  | 6506 | name = xmlParseStringName(ctxt, &ptr); | 
|  | 6507 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6508 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 6509 | "xmlParseStringPEReference: no name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6510 | } else { | 
|  | 6511 | cur = *ptr; | 
|  | 6512 | if (cur == ';') { | 
|  | 6513 | ptr++; | 
|  | 6514 | cur = *ptr; | 
|  | 6515 | if ((ctxt->sax != NULL) && | 
|  | 6516 | (ctxt->sax->getParameterEntity != NULL)) | 
|  | 6517 | entity = ctxt->sax->getParameterEntity(ctxt->userData, | 
|  | 6518 | name); | 
|  | 6519 | if (entity == NULL) { | 
|  | 6520 | /* | 
|  | 6521 | * [ WFC: Entity Declared ] | 
|  | 6522 | * In a document without any DTD, a document with only an | 
|  | 6523 | * internal DTD subset which contains no parameter entity | 
|  | 6524 | * references, or a document with "standalone='yes'", ... | 
|  | 6525 | * ... The declaration of a parameter entity must precede | 
|  | 6526 | * any reference to it... | 
|  | 6527 | */ | 
|  | 6528 | if ((ctxt->standalone == 1) || | 
|  | 6529 | ((ctxt->hasExternalSubset == 0) && | 
|  | 6530 | (ctxt->hasPErefs == 0))) { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6531 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6532 | "PEReference: %%%s; not found\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6533 | } else { | 
|  | 6534 | /* | 
|  | 6535 | * [ VC: Entity Declared ] | 
|  | 6536 | * In a document with an external subset or external | 
|  | 6537 | * parameter entities with "standalone='no'", ... | 
|  | 6538 | * ... The declaration of a parameter entity must | 
|  | 6539 | * precede any reference to it... | 
|  | 6540 | */ | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 6541 | xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
|  | 6542 | "PEReference: %%%s; not found\n", | 
|  | 6543 | name, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6544 | ctxt->valid = 0; | 
|  | 6545 | } | 
|  | 6546 | } else { | 
|  | 6547 | /* | 
|  | 6548 | * Internal checking in case the entity quest barfed | 
|  | 6549 | */ | 
|  | 6550 | if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && | 
|  | 6551 | (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 6552 | xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, | 
|  | 6553 | "%%%s; is not a parameter entity\n", | 
|  | 6554 | name, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6555 | } | 
|  | 6556 | } | 
|  | 6557 | ctxt->hasPErefs = 1; | 
|  | 6558 | } else { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6559 | xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6560 | } | 
|  | 6561 | xmlFree(name); | 
|  | 6562 | } | 
|  | 6563 | } | 
|  | 6564 | *str = ptr; | 
|  | 6565 | return(entity); | 
|  | 6566 | } | 
|  | 6567 |  | 
|  | 6568 | /** | 
|  | 6569 | * xmlParseDocTypeDecl: | 
|  | 6570 | * @ctxt:  an XML parser context | 
|  | 6571 | * | 
|  | 6572 | * parse a DOCTYPE declaration | 
|  | 6573 | * | 
|  | 6574 | * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? | 
|  | 6575 | *                      ('[' (markupdecl | PEReference | S)* ']' S?)? '>' | 
|  | 6576 | * | 
|  | 6577 | * [ VC: Root Element Type ] | 
|  | 6578 | * The Name in the document type declaration must match the element | 
|  | 6579 | * type of the root element. | 
|  | 6580 | */ | 
|  | 6581 |  | 
|  | 6582 | void | 
|  | 6583 | xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6584 | const xmlChar *name = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6585 | xmlChar *ExternalID = NULL; | 
|  | 6586 | xmlChar *URI = NULL; | 
|  | 6587 |  | 
|  | 6588 | /* | 
|  | 6589 | * We know that '<!DOCTYPE' has been detected. | 
|  | 6590 | */ | 
|  | 6591 | SKIP(9); | 
|  | 6592 |  | 
|  | 6593 | SKIP_BLANKS; | 
|  | 6594 |  | 
|  | 6595 | /* | 
|  | 6596 | * Parse the DOCTYPE name. | 
|  | 6597 | */ | 
|  | 6598 | name = xmlParseName(ctxt); | 
|  | 6599 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6600 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 6601 | "xmlParseDocTypeDecl : no DOCTYPE name !\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6602 | } | 
|  | 6603 | ctxt->intSubName = name; | 
|  | 6604 |  | 
|  | 6605 | SKIP_BLANKS; | 
|  | 6606 |  | 
|  | 6607 | /* | 
|  | 6608 | * Check for SystemID and ExternalID | 
|  | 6609 | */ | 
|  | 6610 | URI = xmlParseExternalID(ctxt, &ExternalID, 1); | 
|  | 6611 |  | 
|  | 6612 | if ((URI != NULL) || (ExternalID != NULL)) { | 
|  | 6613 | ctxt->hasExternalSubset = 1; | 
|  | 6614 | } | 
|  | 6615 | ctxt->extSubURI = URI; | 
|  | 6616 | ctxt->extSubSystem = ExternalID; | 
|  | 6617 |  | 
|  | 6618 | SKIP_BLANKS; | 
|  | 6619 |  | 
|  | 6620 | /* | 
|  | 6621 | * Create and update the internal subset. | 
|  | 6622 | */ | 
|  | 6623 | if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) && | 
|  | 6624 | (!ctxt->disableSAX)) | 
|  | 6625 | ctxt->sax->internalSubset(ctxt->userData, name, ExternalID, URI); | 
|  | 6626 |  | 
|  | 6627 | /* | 
|  | 6628 | * Is there any internal subset declarations ? | 
|  | 6629 | * they are handled separately in xmlParseInternalSubset() | 
|  | 6630 | */ | 
|  | 6631 | if (RAW == '[') | 
|  | 6632 | return; | 
|  | 6633 |  | 
|  | 6634 | /* | 
|  | 6635 | * We should be at the end of the DOCTYPE declaration. | 
|  | 6636 | */ | 
|  | 6637 | if (RAW != '>') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6638 | xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6639 | } | 
|  | 6640 | NEXT; | 
|  | 6641 | } | 
|  | 6642 |  | 
|  | 6643 | /** | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 6644 | * xmlParseInternalSubset: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6645 | * @ctxt:  an XML parser context | 
|  | 6646 | * | 
|  | 6647 | * parse the internal subset declaration | 
|  | 6648 | * | 
|  | 6649 | * [28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>' | 
|  | 6650 | */ | 
|  | 6651 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 6652 | static void | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6653 | xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { | 
|  | 6654 | /* | 
|  | 6655 | * Is there any DTD definition ? | 
|  | 6656 | */ | 
|  | 6657 | if (RAW == '[') { | 
|  | 6658 | ctxt->instate = XML_PARSER_DTD; | 
|  | 6659 | NEXT; | 
|  | 6660 | /* | 
|  | 6661 | * Parse the succession of Markup declarations and | 
|  | 6662 | * PEReferences. | 
|  | 6663 | * Subsequence (markupdecl | PEReference | S)* | 
|  | 6664 | */ | 
|  | 6665 | while (RAW != ']') { | 
|  | 6666 | const xmlChar *check = CUR_PTR; | 
| Daniel Veillard | 3e59fc5 | 2003-04-18 12:34:58 +0000 | [diff] [blame] | 6667 | unsigned int cons = ctxt->input->consumed; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6668 |  | 
|  | 6669 | SKIP_BLANKS; | 
|  | 6670 | xmlParseMarkupDecl(ctxt); | 
|  | 6671 | xmlParsePEReference(ctxt); | 
|  | 6672 |  | 
|  | 6673 | /* | 
|  | 6674 | * Pop-up of finished entities. | 
|  | 6675 | */ | 
|  | 6676 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 6677 | xmlPopInput(ctxt); | 
|  | 6678 |  | 
|  | 6679 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6680 | xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6681 | "xmlParseInternalSubset: error detected in Markup declaration\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6682 | break; | 
|  | 6683 | } | 
|  | 6684 | } | 
|  | 6685 | if (RAW == ']') { | 
|  | 6686 | NEXT; | 
|  | 6687 | SKIP_BLANKS; | 
|  | 6688 | } | 
|  | 6689 | } | 
|  | 6690 |  | 
|  | 6691 | /* | 
|  | 6692 | * We should be at the end of the DOCTYPE declaration. | 
|  | 6693 | */ | 
|  | 6694 | if (RAW != '>') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6695 | xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6696 | } | 
|  | 6697 | NEXT; | 
|  | 6698 | } | 
|  | 6699 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 6700 | #ifdef LIBXML_SAX1_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6701 | /** | 
|  | 6702 | * xmlParseAttribute: | 
|  | 6703 | * @ctxt:  an XML parser context | 
|  | 6704 | * @value:  a xmlChar ** used to store the value of the attribute | 
|  | 6705 | * | 
|  | 6706 | * parse an attribute | 
|  | 6707 | * | 
|  | 6708 | * [41] Attribute ::= Name Eq AttValue | 
|  | 6709 | * | 
|  | 6710 | * [ WFC: No External Entity References ] | 
|  | 6711 | * Attribute values cannot contain direct or indirect entity references | 
|  | 6712 | * to external entities. | 
|  | 6713 | * | 
|  | 6714 | * [ WFC: No < in Attribute Values ] | 
|  | 6715 | * The replacement text of any entity referred to directly or indirectly in | 
|  | 6716 | * an attribute value (other than "<") must not contain a <. | 
|  | 6717 | * | 
|  | 6718 | * [ VC: Attribute Value Type ] | 
|  | 6719 | * The attribute must have been declared; the value must be of the type | 
|  | 6720 | * declared for it. | 
|  | 6721 | * | 
|  | 6722 | * [25] Eq ::= S? '=' S? | 
|  | 6723 | * | 
|  | 6724 | * With namespace: | 
|  | 6725 | * | 
|  | 6726 | * [NS 11] Attribute ::= QName Eq AttValue | 
|  | 6727 | * | 
|  | 6728 | * Also the case QName == xmlns:??? is handled independently as a namespace | 
|  | 6729 | * definition. | 
|  | 6730 | * | 
|  | 6731 | * Returns the attribute name, and the value in *value. | 
|  | 6732 | */ | 
|  | 6733 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6734 | const xmlChar * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6735 | xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6736 | const xmlChar *name; | 
|  | 6737 | xmlChar *val; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6738 |  | 
|  | 6739 | *value = NULL; | 
| Daniel Veillard | 878eab0 | 2002-02-19 13:46:09 +0000 | [diff] [blame] | 6740 | GROW; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6741 | name = xmlParseName(ctxt); | 
|  | 6742 | if (name == NULL) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6743 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6744 | "error parsing attribute name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6745 | return(NULL); | 
|  | 6746 | } | 
|  | 6747 |  | 
|  | 6748 | /* | 
|  | 6749 | * read the value | 
|  | 6750 | */ | 
|  | 6751 | SKIP_BLANKS; | 
|  | 6752 | if (RAW == '=') { | 
|  | 6753 | NEXT; | 
|  | 6754 | SKIP_BLANKS; | 
|  | 6755 | val = xmlParseAttValue(ctxt); | 
|  | 6756 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 6757 | } else { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 6758 | xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6759 | "Specification mandate value for attribute %s\n", name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6760 | return(NULL); | 
|  | 6761 | } | 
|  | 6762 |  | 
|  | 6763 | /* | 
|  | 6764 | * Check that xml:lang conforms to the specification | 
|  | 6765 | * No more registered as an error, just generate a warning now | 
|  | 6766 | * since this was deprecated in XML second edition | 
|  | 6767 | */ | 
|  | 6768 | if ((ctxt->pedantic) && (xmlStrEqual(name, BAD_CAST "xml:lang"))) { | 
|  | 6769 | if (!xmlCheckLanguageID(val)) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 6770 | xmlWarningMsg(ctxt, XML_WAR_LANG_VALUE, | 
|  | 6771 | "Malformed value for xml:lang : %s\n", | 
|  | 6772 | val, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6773 | } | 
|  | 6774 | } | 
|  | 6775 |  | 
|  | 6776 | /* | 
|  | 6777 | * Check that xml:space conforms to the specification | 
|  | 6778 | */ | 
|  | 6779 | if (xmlStrEqual(name, BAD_CAST "xml:space")) { | 
|  | 6780 | if (xmlStrEqual(val, BAD_CAST "default")) | 
|  | 6781 | *(ctxt->space) = 0; | 
|  | 6782 | else if (xmlStrEqual(val, BAD_CAST "preserve")) | 
|  | 6783 | *(ctxt->space) = 1; | 
|  | 6784 | else { | 
| Daniel Veillard | d892557 | 2005-06-08 22:34:55 +0000 | [diff] [blame] | 6785 | xmlWarningMsg(ctxt, XML_WAR_SPACE_VALUE, | 
| Daniel Veillard | 642104e | 2003-03-26 16:32:05 +0000 | [diff] [blame] | 6786 | "Invalid value \"%s\" for xml:space : \"default\" or \"preserve\" expected\n", | 
| Daniel Veillard | d892557 | 2005-06-08 22:34:55 +0000 | [diff] [blame] | 6787 | val, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6788 | } | 
|  | 6789 | } | 
|  | 6790 |  | 
|  | 6791 | *value = val; | 
|  | 6792 | return(name); | 
|  | 6793 | } | 
|  | 6794 |  | 
|  | 6795 | /** | 
|  | 6796 | * xmlParseStartTag: | 
|  | 6797 | * @ctxt:  an XML parser context | 
|  | 6798 | * | 
|  | 6799 | * parse a start of tag either for rule element or | 
|  | 6800 | * EmptyElement. In both case we don't parse the tag closing chars. | 
|  | 6801 | * | 
|  | 6802 | * [40] STag ::= '<' Name (S Attribute)* S? '>' | 
|  | 6803 | * | 
|  | 6804 | * [ WFC: Unique Att Spec ] | 
|  | 6805 | * No attribute name may appear more than once in the same start-tag or | 
|  | 6806 | * empty-element tag. | 
|  | 6807 | * | 
|  | 6808 | * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' | 
|  | 6809 | * | 
|  | 6810 | * [ WFC: Unique Att Spec ] | 
|  | 6811 | * No attribute name may appear more than once in the same start-tag or | 
|  | 6812 | * empty-element tag. | 
|  | 6813 | * | 
|  | 6814 | * With namespace: | 
|  | 6815 | * | 
|  | 6816 | * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' | 
|  | 6817 | * | 
|  | 6818 | * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' | 
|  | 6819 | * | 
|  | 6820 | * Returns the element name parsed | 
|  | 6821 | */ | 
|  | 6822 |  | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6823 | const xmlChar * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6824 | xmlParseStartTag(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6825 | const xmlChar *name; | 
|  | 6826 | const xmlChar *attname; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6827 | xmlChar *attvalue; | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6828 | const xmlChar **atts = ctxt->atts; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6829 | int nbatts = 0; | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6830 | int maxatts = ctxt->maxatts; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6831 | int i; | 
|  | 6832 |  | 
|  | 6833 | if (RAW != '<') return(NULL); | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 6834 | NEXT1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6835 |  | 
|  | 6836 | name = xmlParseName(ctxt); | 
|  | 6837 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6838 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6839 | "xmlParseStartTag: invalid element name\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6840 | return(NULL); | 
|  | 6841 | } | 
|  | 6842 |  | 
|  | 6843 | /* | 
|  | 6844 | * Now parse the attributes, it ends up with the ending | 
|  | 6845 | * | 
|  | 6846 | * (S Attribute)* S? | 
|  | 6847 | */ | 
|  | 6848 | SKIP_BLANKS; | 
|  | 6849 | GROW; | 
|  | 6850 |  | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 6851 | while ((RAW != '>') && | 
|  | 6852 | ((RAW != '/') || (NXT(1) != '>')) && | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 6853 | (IS_BYTE_CHAR(RAW))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6854 | const xmlChar *q = CUR_PTR; | 
| Daniel Veillard | 3e59fc5 | 2003-04-18 12:34:58 +0000 | [diff] [blame] | 6855 | unsigned int cons = ctxt->input->consumed; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6856 |  | 
|  | 6857 | attname = xmlParseAttribute(ctxt, &attvalue); | 
|  | 6858 | if ((attname != NULL) && (attvalue != NULL)) { | 
|  | 6859 | /* | 
|  | 6860 | * [ WFC: Unique Att Spec ] | 
|  | 6861 | * No attribute name may appear more than once in the same | 
|  | 6862 | * start-tag or empty-element tag. | 
|  | 6863 | */ | 
|  | 6864 | for (i = 0; i < nbatts;i += 2) { | 
|  | 6865 | if (xmlStrEqual(atts[i], attname)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 6866 | xmlErrAttributeDup(ctxt, NULL, attname); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6867 | xmlFree(attvalue); | 
|  | 6868 | goto failed; | 
|  | 6869 | } | 
|  | 6870 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6871 | /* | 
|  | 6872 | * Add the pair to atts | 
|  | 6873 | */ | 
|  | 6874 | if (atts == NULL) { | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6875 | maxatts = 22; /* allow for 10 attrs by default */ | 
|  | 6876 | atts = (const xmlChar **) | 
|  | 6877 | xmlMalloc(maxatts * sizeof(xmlChar *)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6878 | if (atts == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 6879 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6880 | if (attvalue != NULL) | 
|  | 6881 | xmlFree(attvalue); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6882 | goto failed; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6883 | } | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6884 | ctxt->atts = atts; | 
|  | 6885 | ctxt->maxatts = maxatts; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6886 | } else if (nbatts + 4 > maxatts) { | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6887 | const xmlChar **n; | 
|  | 6888 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6889 | maxatts *= 2; | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6890 | n = (const xmlChar **) xmlRealloc((void *) atts, | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6891 | maxatts * sizeof(const xmlChar *)); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6892 | if (n == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 6893 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6894 | if (attvalue != NULL) | 
|  | 6895 | xmlFree(attvalue); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6896 | goto failed; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6897 | } | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6898 | atts = n; | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6899 | ctxt->atts = atts; | 
|  | 6900 | ctxt->maxatts = maxatts; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6901 | } | 
|  | 6902 | atts[nbatts++] = attname; | 
|  | 6903 | atts[nbatts++] = attvalue; | 
|  | 6904 | atts[nbatts] = NULL; | 
|  | 6905 | atts[nbatts + 1] = NULL; | 
|  | 6906 | } else { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6907 | if (attvalue != NULL) | 
|  | 6908 | xmlFree(attvalue); | 
|  | 6909 | } | 
|  | 6910 |  | 
|  | 6911 | failed: | 
|  | 6912 |  | 
| Daniel Veillard | 3772de3 | 2002-12-17 10:31:45 +0000 | [diff] [blame] | 6913 | GROW | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6914 | if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) | 
|  | 6915 | break; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 6916 | if (!IS_BLANK_CH(RAW)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6917 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 6918 | "attributes construct error\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6919 | } | 
|  | 6920 | SKIP_BLANKS; | 
| Daniel Veillard | 02111c1 | 2003-02-24 19:14:52 +0000 | [diff] [blame] | 6921 | if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && | 
|  | 6922 | (attname == NULL) && (attvalue == NULL)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6923 | xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 6924 | "xmlParseStartTag: problem parsing attributes\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6925 | break; | 
|  | 6926 | } | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6927 | SHRINK; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6928 | GROW; | 
|  | 6929 | } | 
|  | 6930 |  | 
|  | 6931 | /* | 
|  | 6932 | * SAX: Start of Element ! | 
|  | 6933 | */ | 
|  | 6934 | if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL) && | 
| Daniel Veillard | 6155d8a | 2003-08-19 15:01:28 +0000 | [diff] [blame] | 6935 | (!ctxt->disableSAX)) { | 
|  | 6936 | if (nbatts > 0) | 
|  | 6937 | ctxt->sax->startElement(ctxt->userData, name, atts); | 
|  | 6938 | else | 
|  | 6939 | ctxt->sax->startElement(ctxt->userData, name, NULL); | 
|  | 6940 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6941 |  | 
|  | 6942 | if (atts != NULL) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6943 | /* Free only the content strings */ | 
|  | 6944 | for (i = 1;i < nbatts;i+=2) | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 6945 | if (atts[i] != NULL) | 
|  | 6946 | xmlFree((xmlChar *) atts[i]); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6947 | } | 
|  | 6948 | return(name); | 
|  | 6949 | } | 
|  | 6950 |  | 
|  | 6951 | /** | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 6952 | * xmlParseEndTag1: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6953 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 6954 | * @line:  line of the start tag | 
|  | 6955 | * @nsNr:  number of namespaces on the start tag | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6956 | * | 
|  | 6957 | * parse an end of tag | 
|  | 6958 | * | 
|  | 6959 | * [42] ETag ::= '</' Name S? '>' | 
|  | 6960 | * | 
|  | 6961 | * With namespace | 
|  | 6962 | * | 
|  | 6963 | * [NS 9] ETag ::= '</' QName S? '>' | 
|  | 6964 | */ | 
|  | 6965 |  | 
| Daniel Veillard | 6c5b2d3 | 2003-03-27 14:55:52 +0000 | [diff] [blame] | 6966 | static void | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 6967 | xmlParseEndTag1(xmlParserCtxtPtr ctxt, int line) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 6968 | const xmlChar *name; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6969 |  | 
|  | 6970 | GROW; | 
|  | 6971 | if ((RAW != '<') || (NXT(1) != '/')) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6972 | xmlFatalErrMsg(ctxt, XML_ERR_LTSLASH_REQUIRED, | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 6973 | "xmlParseEndTag: '</' not found\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6974 | return; | 
|  | 6975 | } | 
|  | 6976 | SKIP(2); | 
|  | 6977 |  | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 6978 | name = xmlParseNameAndCompare(ctxt,ctxt->name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6979 |  | 
|  | 6980 | /* | 
|  | 6981 | * We should definitely be at the ending "S? '>'" part | 
|  | 6982 | */ | 
|  | 6983 | GROW; | 
|  | 6984 | SKIP_BLANKS; | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 6985 | if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 6986 | xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6987 | } else | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 6988 | NEXT1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 6989 |  | 
|  | 6990 | /* | 
|  | 6991 | * [ WFC: Element Type Match ] | 
|  | 6992 | * The Name in an element's end-tag must match the element type in the | 
|  | 6993 | * start-tag. | 
|  | 6994 | * | 
|  | 6995 | */ | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 6996 | if (name != (xmlChar*)1) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 6997 | if (name == NULL) name = BAD_CAST "unparseable"; | 
|  | 6998 | xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH, | 
| Daniel Veillard | 6c5b2d3 | 2003-03-27 14:55:52 +0000 | [diff] [blame] | 6999 | "Opening and ending tag mismatch: %s line %d and %s\n", | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 7000 | ctxt->name, line, name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7001 | } | 
|  | 7002 |  | 
|  | 7003 | /* | 
|  | 7004 | * SAX: End of Tag | 
|  | 7005 | */ | 
|  | 7006 | if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL) && | 
|  | 7007 | (!ctxt->disableSAX)) | 
| Daniel Veillard | 46de64e | 2002-05-29 08:21:33 +0000 | [diff] [blame] | 7008 | ctxt->sax->endElement(ctxt->userData, ctxt->name); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7009 |  | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7010 | namePop(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7011 | spacePop(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7012 | return; | 
|  | 7013 | } | 
|  | 7014 |  | 
|  | 7015 | /** | 
| Daniel Veillard | 6c5b2d3 | 2003-03-27 14:55:52 +0000 | [diff] [blame] | 7016 | * xmlParseEndTag: | 
|  | 7017 | * @ctxt:  an XML parser context | 
|  | 7018 | * | 
|  | 7019 | * parse an end of tag | 
|  | 7020 | * | 
|  | 7021 | * [42] ETag ::= '</' Name S? '>' | 
|  | 7022 | * | 
|  | 7023 | * With namespace | 
|  | 7024 | * | 
|  | 7025 | * [NS 9] ETag ::= '</' QName S? '>' | 
|  | 7026 | */ | 
|  | 7027 |  | 
|  | 7028 | void | 
|  | 7029 | xmlParseEndTag(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7030 | xmlParseEndTag1(ctxt, 0); | 
|  | 7031 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 7032 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7033 |  | 
|  | 7034 | /************************************************************************ | 
|  | 7035 | *									* | 
|  | 7036 | *		      SAX 2 specific operations				* | 
|  | 7037 | *									* | 
|  | 7038 | ************************************************************************/ | 
|  | 7039 |  | 
|  | 7040 | static const xmlChar * | 
|  | 7041 | xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) { | 
|  | 7042 | int len = 0, l; | 
|  | 7043 | int c; | 
|  | 7044 | int count = 0; | 
|  | 7045 |  | 
|  | 7046 | /* | 
|  | 7047 | * Handler for more complex cases | 
|  | 7048 | */ | 
|  | 7049 | GROW; | 
|  | 7050 | c = CUR_CHAR(l); | 
|  | 7051 | if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */ | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7052 | (!IS_LETTER(c) && (c != '_'))) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7053 | return(NULL); | 
|  | 7054 | } | 
|  | 7055 |  | 
|  | 7056 | while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */ | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 7057 | ((IS_LETTER(c)) || (IS_DIGIT(c)) || | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7058 | (c == '.') || (c == '-') || (c == '_') || | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 7059 | (IS_COMBINING(c)) || | 
|  | 7060 | (IS_EXTENDER(c)))) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7061 | if (count++ > 100) { | 
|  | 7062 | count = 0; | 
|  | 7063 | GROW; | 
|  | 7064 | } | 
|  | 7065 | len += l; | 
|  | 7066 | NEXTL(l); | 
|  | 7067 | c = CUR_CHAR(l); | 
|  | 7068 | } | 
|  | 7069 | return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len)); | 
|  | 7070 | } | 
|  | 7071 |  | 
|  | 7072 | /* | 
|  | 7073 | * xmlGetNamespace: | 
|  | 7074 | * @ctxt:  an XML parser context | 
|  | 7075 | * @prefix:  the prefix to lookup | 
|  | 7076 | * | 
|  | 7077 | * Lookup the namespace name for the @prefix (which ca be NULL) | 
|  | 7078 | * The prefix must come from the @ctxt->dict dictionnary | 
|  | 7079 | * | 
|  | 7080 | * Returns the namespace name or NULL if not bound | 
|  | 7081 | */ | 
|  | 7082 | static const xmlChar * | 
|  | 7083 | xmlGetNamespace(xmlParserCtxtPtr ctxt, const xmlChar *prefix) { | 
|  | 7084 | int i; | 
|  | 7085 |  | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7086 | if (prefix == ctxt->str_xml) return(ctxt->str_xml_ns); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7087 | for (i = ctxt->nsNr - 2;i >= 0;i-=2) | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7088 | if (ctxt->nsTab[i] == prefix) { | 
|  | 7089 | if ((prefix == NULL) && (*ctxt->nsTab[i + 1] == 0)) | 
|  | 7090 | return(NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7091 | return(ctxt->nsTab[i + 1]); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7092 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7093 | return(NULL); | 
|  | 7094 | } | 
|  | 7095 |  | 
|  | 7096 | /** | 
|  | 7097 | * xmlParseNCName: | 
|  | 7098 | * @ctxt:  an XML parser context | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 7099 | * @len:  lenght of the string parsed | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7100 | * | 
|  | 7101 | * parse an XML name. | 
|  | 7102 | * | 
|  | 7103 | * [4NS] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | | 
|  | 7104 | *                      CombiningChar | Extender | 
|  | 7105 | * | 
|  | 7106 | * [5NS] NCName ::= (Letter | '_') (NCNameChar)* | 
|  | 7107 | * | 
|  | 7108 | * Returns the Name parsed or NULL | 
|  | 7109 | */ | 
|  | 7110 |  | 
|  | 7111 | static const xmlChar * | 
|  | 7112 | xmlParseNCName(xmlParserCtxtPtr ctxt) { | 
|  | 7113 | const xmlChar *in; | 
|  | 7114 | const xmlChar *ret; | 
|  | 7115 | int count = 0; | 
|  | 7116 |  | 
|  | 7117 | /* | 
|  | 7118 | * Accelerator for simple ASCII names | 
|  | 7119 | */ | 
|  | 7120 | in = ctxt->input->cur; | 
|  | 7121 | if (((*in >= 0x61) && (*in <= 0x7A)) || | 
|  | 7122 | ((*in >= 0x41) && (*in <= 0x5A)) || | 
|  | 7123 | (*in == '_')) { | 
|  | 7124 | in++; | 
|  | 7125 | while (((*in >= 0x61) && (*in <= 0x7A)) || | 
|  | 7126 | ((*in >= 0x41) && (*in <= 0x5A)) || | 
|  | 7127 | ((*in >= 0x30) && (*in <= 0x39)) || | 
|  | 7128 | (*in == '_') || (*in == '-') || | 
|  | 7129 | (*in == '.')) | 
|  | 7130 | in++; | 
|  | 7131 | if ((*in > 0) && (*in < 0x80)) { | 
|  | 7132 | count = in - ctxt->input->cur; | 
|  | 7133 | ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count); | 
|  | 7134 | ctxt->input->cur = in; | 
|  | 7135 | ctxt->nbChars += count; | 
|  | 7136 | ctxt->input->col += count; | 
|  | 7137 | if (ret == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 7138 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7139 | } | 
|  | 7140 | return(ret); | 
|  | 7141 | } | 
|  | 7142 | } | 
|  | 7143 | return(xmlParseNCNameComplex(ctxt)); | 
|  | 7144 | } | 
|  | 7145 |  | 
|  | 7146 | /** | 
|  | 7147 | * xmlParseQName: | 
|  | 7148 | * @ctxt:  an XML parser context | 
|  | 7149 | * @prefix:  pointer to store the prefix part | 
|  | 7150 | * | 
|  | 7151 | * parse an XML Namespace QName | 
|  | 7152 | * | 
|  | 7153 | * [6]  QName  ::= (Prefix ':')? LocalPart | 
|  | 7154 | * [7]  Prefix  ::= NCName | 
|  | 7155 | * [8]  LocalPart  ::= NCName | 
|  | 7156 | * | 
|  | 7157 | * Returns the Name parsed or NULL | 
|  | 7158 | */ | 
|  | 7159 |  | 
|  | 7160 | static const xmlChar * | 
|  | 7161 | xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) { | 
|  | 7162 | const xmlChar *l, *p; | 
|  | 7163 |  | 
|  | 7164 | GROW; | 
|  | 7165 |  | 
|  | 7166 | l = xmlParseNCName(ctxt); | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7167 | if (l == NULL) { | 
|  | 7168 | if (CUR == ':') { | 
|  | 7169 | l = xmlParseName(ctxt); | 
|  | 7170 | if (l != NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7171 | xmlNsErr(ctxt, XML_NS_ERR_QNAME, | 
|  | 7172 | "Failed to parse QName '%s'\n", l, NULL, NULL); | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7173 | *prefix = NULL; | 
|  | 7174 | return(l); | 
|  | 7175 | } | 
|  | 7176 | } | 
|  | 7177 | return(NULL); | 
|  | 7178 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7179 | if (CUR == ':') { | 
|  | 7180 | NEXT; | 
|  | 7181 | p = l; | 
|  | 7182 | l = xmlParseNCName(ctxt); | 
|  | 7183 | if (l == NULL) { | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7184 | xmlChar *tmp; | 
|  | 7185 |  | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7186 | xmlNsErr(ctxt, XML_NS_ERR_QNAME, | 
|  | 7187 | "Failed to parse QName '%s:'\n", p, NULL, NULL); | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7188 | tmp = xmlBuildQName(BAD_CAST "", p, NULL, 0); | 
|  | 7189 | p = xmlDictLookup(ctxt->dict, tmp, -1); | 
|  | 7190 | if (tmp != NULL) xmlFree(tmp); | 
|  | 7191 | *prefix = NULL; | 
|  | 7192 | return(p); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7193 | } | 
|  | 7194 | if (CUR == ':') { | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7195 | xmlChar *tmp; | 
|  | 7196 |  | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7197 | xmlNsErr(ctxt, XML_NS_ERR_QNAME, | 
|  | 7198 | "Failed to parse QName '%s:%s:'\n", p, l, NULL); | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7199 | NEXT; | 
|  | 7200 | tmp = (xmlChar *) xmlParseName(ctxt); | 
|  | 7201 | if (tmp != NULL) { | 
|  | 7202 | tmp = xmlBuildQName(tmp, l, NULL, 0); | 
|  | 7203 | l = xmlDictLookup(ctxt->dict, tmp, -1); | 
|  | 7204 | if (tmp != NULL) xmlFree(tmp); | 
|  | 7205 | *prefix = p; | 
|  | 7206 | return(l); | 
|  | 7207 | } | 
|  | 7208 | tmp = xmlBuildQName(BAD_CAST "", l, NULL, 0); | 
|  | 7209 | l = xmlDictLookup(ctxt->dict, tmp, -1); | 
|  | 7210 | if (tmp != NULL) xmlFree(tmp); | 
|  | 7211 | *prefix = p; | 
|  | 7212 | return(l); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7213 | } | 
|  | 7214 | *prefix = p; | 
|  | 7215 | } else | 
|  | 7216 | *prefix = NULL; | 
|  | 7217 | return(l); | 
|  | 7218 | } | 
|  | 7219 |  | 
|  | 7220 | /** | 
|  | 7221 | * xmlParseQNameAndCompare: | 
|  | 7222 | * @ctxt:  an XML parser context | 
|  | 7223 | * @name:  the localname | 
|  | 7224 | * @prefix:  the prefix, if any. | 
|  | 7225 | * | 
|  | 7226 | * parse an XML name and compares for match | 
|  | 7227 | * (specialized for endtag parsing) | 
|  | 7228 | * | 
|  | 7229 | * Returns NULL for an illegal name, (xmlChar*) 1 for success | 
|  | 7230 | * and the name for mismatch | 
|  | 7231 | */ | 
|  | 7232 |  | 
|  | 7233 | static const xmlChar * | 
|  | 7234 | xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name, | 
|  | 7235 | xmlChar const *prefix) { | 
|  | 7236 | const xmlChar *cmp = name; | 
|  | 7237 | const xmlChar *in; | 
|  | 7238 | const xmlChar *ret; | 
|  | 7239 | const xmlChar *prefix2; | 
|  | 7240 |  | 
|  | 7241 | if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name)); | 
|  | 7242 |  | 
|  | 7243 | GROW; | 
|  | 7244 | in = ctxt->input->cur; | 
|  | 7245 |  | 
|  | 7246 | cmp = prefix; | 
|  | 7247 | while (*in != 0 && *in == *cmp) { | 
|  | 7248 | ++in; | 
|  | 7249 | ++cmp; | 
|  | 7250 | } | 
|  | 7251 | if ((*cmp == 0) && (*in == ':')) { | 
|  | 7252 | in++; | 
|  | 7253 | cmp = name; | 
|  | 7254 | while (*in != 0 && *in == *cmp) { | 
|  | 7255 | ++in; | 
|  | 7256 | ++cmp; | 
|  | 7257 | } | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 7258 | if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7259 | /* success */ | 
|  | 7260 | ctxt->input->cur = in; | 
|  | 7261 | return((const xmlChar*) 1); | 
|  | 7262 | } | 
|  | 7263 | } | 
|  | 7264 | /* | 
|  | 7265 | * all strings coms from the dictionary, equality can be done directly | 
|  | 7266 | */ | 
|  | 7267 | ret = xmlParseQName (ctxt, &prefix2); | 
|  | 7268 | if ((ret == name) && (prefix == prefix2)) | 
|  | 7269 | return((const xmlChar*) 1); | 
|  | 7270 | return ret; | 
|  | 7271 | } | 
|  | 7272 |  | 
|  | 7273 | /** | 
|  | 7274 | * xmlParseAttValueInternal: | 
|  | 7275 | * @ctxt:  an XML parser context | 
|  | 7276 | * @len:  attribute len result | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7277 | * @alloc:  whether the attribute was reallocated as a new string | 
|  | 7278 | * @normalize:  if 1 then further non-CDATA normalization must be done | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7279 | * | 
|  | 7280 | * parse a value for an attribute. | 
|  | 7281 | * NOTE: if no normalization is needed, the routine will return pointers | 
|  | 7282 | *       directly from the data buffer. | 
|  | 7283 | * | 
|  | 7284 | * 3.3.3 Attribute-Value Normalization: | 
|  | 7285 | * Before the value of an attribute is passed to the application or | 
|  | 7286 | * checked for validity, the XML processor must normalize it as follows: | 
|  | 7287 | * - a character reference is processed by appending the referenced | 
|  | 7288 | *   character to the attribute value | 
|  | 7289 | * - an entity reference is processed by recursively processing the | 
|  | 7290 | *   replacement text of the entity | 
|  | 7291 | * - a whitespace character (#x20, #xD, #xA, #x9) is processed by | 
|  | 7292 | *   appending #x20 to the normalized value, except that only a single | 
|  | 7293 | *   #x20 is appended for a "#xD#xA" sequence that is part of an external | 
|  | 7294 | *   parsed entity or the literal entity value of an internal parsed entity | 
|  | 7295 | * - other characters are processed by appending them to the normalized value | 
|  | 7296 | * If the declared value is not CDATA, then the XML processor must further | 
|  | 7297 | * process the normalized attribute value by discarding any leading and | 
|  | 7298 | * trailing space (#x20) characters, and by replacing sequences of space | 
|  | 7299 | * (#x20) characters by a single space (#x20) character. | 
|  | 7300 | * All attributes for which no declaration has been read should be treated | 
|  | 7301 | * by a non-validating parser as if declared CDATA. | 
|  | 7302 | * | 
|  | 7303 | * Returns the AttValue parsed or NULL. The value has to be freed by the | 
|  | 7304 | *     caller if it was copied, this can be detected by val[*len] == 0. | 
|  | 7305 | */ | 
|  | 7306 |  | 
|  | 7307 | static xmlChar * | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7308 | xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, | 
|  | 7309 | int normalize) | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7310 | { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7311 | xmlChar limit = 0; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7312 | const xmlChar *in = NULL, *start, *end, *last; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7313 | xmlChar *ret = NULL; | 
|  | 7314 |  | 
|  | 7315 | GROW; | 
|  | 7316 | in = (xmlChar *) CUR_PTR; | 
|  | 7317 | if (*in != '"' && *in != '\'') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7318 | xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7319 | return (NULL); | 
|  | 7320 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7321 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7322 |  | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7323 | /* | 
|  | 7324 | * try to handle in this routine the most common case where no | 
|  | 7325 | * allocation of a new string is required and where content is | 
|  | 7326 | * pure ASCII. | 
|  | 7327 | */ | 
|  | 7328 | limit = *in++; | 
|  | 7329 | end = ctxt->input->end; | 
|  | 7330 | start = in; | 
|  | 7331 | if (in >= end) { | 
|  | 7332 | const xmlChar *oldbase = ctxt->input->base; | 
|  | 7333 | GROW; | 
|  | 7334 | if (oldbase != ctxt->input->base) { | 
|  | 7335 | long delta = ctxt->input->base - oldbase; | 
|  | 7336 | start = start + delta; | 
|  | 7337 | in = in + delta; | 
|  | 7338 | } | 
|  | 7339 | end = ctxt->input->end; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7340 | } | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7341 | if (normalize) { | 
|  | 7342 | /* | 
|  | 7343 | * Skip any leading spaces | 
|  | 7344 | */ | 
|  | 7345 | while ((in < end) && (*in != limit) && | 
|  | 7346 | ((*in == 0x20) || (*in == 0x9) || | 
|  | 7347 | (*in == 0xA) || (*in == 0xD))) { | 
|  | 7348 | in++; | 
|  | 7349 | start = in; | 
|  | 7350 | if (in >= end) { | 
|  | 7351 | const xmlChar *oldbase = ctxt->input->base; | 
|  | 7352 | GROW; | 
|  | 7353 | if (oldbase != ctxt->input->base) { | 
|  | 7354 | long delta = ctxt->input->base - oldbase; | 
|  | 7355 | start = start + delta; | 
|  | 7356 | in = in + delta; | 
|  | 7357 | } | 
|  | 7358 | end = ctxt->input->end; | 
|  | 7359 | } | 
|  | 7360 | } | 
|  | 7361 | while ((in < end) && (*in != limit) && (*in >= 0x20) && | 
|  | 7362 | (*in <= 0x7f) && (*in != '&') && (*in != '<')) { | 
|  | 7363 | if ((*in++ == 0x20) && (*in == 0x20)) break; | 
|  | 7364 | if (in >= end) { | 
|  | 7365 | const xmlChar *oldbase = ctxt->input->base; | 
|  | 7366 | GROW; | 
|  | 7367 | if (oldbase != ctxt->input->base) { | 
|  | 7368 | long delta = ctxt->input->base - oldbase; | 
|  | 7369 | start = start + delta; | 
|  | 7370 | in = in + delta; | 
|  | 7371 | } | 
|  | 7372 | end = ctxt->input->end; | 
|  | 7373 | } | 
|  | 7374 | } | 
|  | 7375 | last = in; | 
|  | 7376 | /* | 
|  | 7377 | * skip the trailing blanks | 
|  | 7378 | */ | 
| Daniel Veillard | c6e20e4 | 2003-09-11 16:30:26 +0000 | [diff] [blame] | 7379 | while ((last[-1] == 0x20) && (last > start)) last--; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7380 | while ((in < end) && (*in != limit) && | 
|  | 7381 | ((*in == 0x20) || (*in == 0x9) || | 
|  | 7382 | (*in == 0xA) || (*in == 0xD))) { | 
|  | 7383 | in++; | 
|  | 7384 | if (in >= end) { | 
|  | 7385 | const xmlChar *oldbase = ctxt->input->base; | 
|  | 7386 | GROW; | 
|  | 7387 | if (oldbase != ctxt->input->base) { | 
|  | 7388 | long delta = ctxt->input->base - oldbase; | 
|  | 7389 | start = start + delta; | 
|  | 7390 | in = in + delta; | 
|  | 7391 | last = last + delta; | 
|  | 7392 | } | 
|  | 7393 | end = ctxt->input->end; | 
|  | 7394 | } | 
|  | 7395 | } | 
|  | 7396 | if (*in != limit) goto need_complex; | 
|  | 7397 | } else { | 
|  | 7398 | while ((in < end) && (*in != limit) && (*in >= 0x20) && | 
|  | 7399 | (*in <= 0x7f) && (*in != '&') && (*in != '<')) { | 
|  | 7400 | in++; | 
|  | 7401 | if (in >= end) { | 
|  | 7402 | const xmlChar *oldbase = ctxt->input->base; | 
|  | 7403 | GROW; | 
|  | 7404 | if (oldbase != ctxt->input->base) { | 
|  | 7405 | long delta = ctxt->input->base - oldbase; | 
|  | 7406 | start = start + delta; | 
|  | 7407 | in = in + delta; | 
|  | 7408 | } | 
|  | 7409 | end = ctxt->input->end; | 
|  | 7410 | } | 
|  | 7411 | } | 
|  | 7412 | last = in; | 
|  | 7413 | if (*in != limit) goto need_complex; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7414 | } | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7415 | in++; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7416 | if (len != NULL) { | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7417 | *len = last - start; | 
|  | 7418 | ret = (xmlChar *) start; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7419 | } else { | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7420 | if (alloc) *alloc = 1; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7421 | ret = xmlStrndup(start, last - start); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7422 | } | 
|  | 7423 | CUR_PTR = in; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7424 | if (alloc) *alloc = 0; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7425 | return ret; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7426 | need_complex: | 
|  | 7427 | if (alloc) *alloc = 1; | 
|  | 7428 | return xmlParseAttValueComplex(ctxt, len, normalize); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7429 | } | 
|  | 7430 |  | 
|  | 7431 | /** | 
|  | 7432 | * xmlParseAttribute2: | 
|  | 7433 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7434 | * @pref:  the element prefix | 
|  | 7435 | * @elem:  the element name | 
|  | 7436 | * @prefix:  a xmlChar ** used to store the value of the attribute prefix | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7437 | * @value:  a xmlChar ** used to store the value of the attribute | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7438 | * @len:  an int * to save the length of the attribute | 
|  | 7439 | * @alloc:  an int * to indicate if the attribute was allocated | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7440 | * | 
|  | 7441 | * parse an attribute in the new SAX2 framework. | 
|  | 7442 | * | 
|  | 7443 | * Returns the attribute name, and the value in *value, . | 
|  | 7444 | */ | 
|  | 7445 |  | 
|  | 7446 | static const xmlChar * | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7447 | xmlParseAttribute2(xmlParserCtxtPtr ctxt, | 
|  | 7448 | const xmlChar *pref, const xmlChar *elem, | 
|  | 7449 | const xmlChar **prefix, xmlChar **value, | 
|  | 7450 | int *len, int *alloc) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7451 | const xmlChar *name; | 
| Daniel Veillard | d892557 | 2005-06-08 22:34:55 +0000 | [diff] [blame] | 7452 | xmlChar *val, *internal_val = NULL; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7453 | int normalize = 0; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7454 |  | 
|  | 7455 | *value = NULL; | 
|  | 7456 | GROW; | 
|  | 7457 | name = xmlParseQName(ctxt, prefix); | 
|  | 7458 | if (name == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7459 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 7460 | "error parsing attribute name\n"); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7461 | return(NULL); | 
|  | 7462 | } | 
|  | 7463 |  | 
|  | 7464 | /* | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7465 | * get the type if needed | 
|  | 7466 | */ | 
|  | 7467 | if (ctxt->attsSpecial != NULL) { | 
|  | 7468 | int type; | 
|  | 7469 |  | 
|  | 7470 | type = (int) (long) xmlHashQLookup2(ctxt->attsSpecial, | 
|  | 7471 | pref, elem, *prefix, name); | 
|  | 7472 | if (type != 0) normalize = 1; | 
|  | 7473 | } | 
|  | 7474 |  | 
|  | 7475 | /* | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7476 | * read the value | 
|  | 7477 | */ | 
|  | 7478 | SKIP_BLANKS; | 
|  | 7479 | if (RAW == '=') { | 
|  | 7480 | NEXT; | 
|  | 7481 | SKIP_BLANKS; | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7482 | val = xmlParseAttValueInternal(ctxt, len, alloc, normalize); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7483 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 7484 | } else { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 7485 | xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE, | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7486 | "Specification mandate value for attribute %s\n", name); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7487 | return(NULL); | 
|  | 7488 | } | 
|  | 7489 |  | 
| Daniel Veillard | d892557 | 2005-06-08 22:34:55 +0000 | [diff] [blame] | 7490 | if (*prefix == ctxt->str_xml) { | 
|  | 7491 | /* | 
|  | 7492 | * Check that xml:lang conforms to the specification | 
|  | 7493 | * No more registered as an error, just generate a warning now | 
|  | 7494 | * since this was deprecated in XML second edition | 
|  | 7495 | */ | 
|  | 7496 | if ((ctxt->pedantic) && (xmlStrEqual(name, BAD_CAST "lang"))) { | 
|  | 7497 | internal_val = xmlStrndup(val, *len); | 
|  | 7498 | if (!xmlCheckLanguageID(internal_val)) { | 
|  | 7499 | xmlWarningMsg(ctxt, XML_WAR_LANG_VALUE, | 
|  | 7500 | "Malformed value for xml:lang : %s\n", | 
|  | 7501 | internal_val, NULL); | 
|  | 7502 | } | 
|  | 7503 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7504 |  | 
| Daniel Veillard | d892557 | 2005-06-08 22:34:55 +0000 | [diff] [blame] | 7505 | /* | 
|  | 7506 | * Check that xml:space conforms to the specification | 
|  | 7507 | */ | 
|  | 7508 | if (xmlStrEqual(name, BAD_CAST "space")) { | 
|  | 7509 | internal_val = xmlStrndup(val, *len); | 
|  | 7510 | if (xmlStrEqual(internal_val, BAD_CAST "default")) | 
|  | 7511 | *(ctxt->space) = 0; | 
|  | 7512 | else if (xmlStrEqual(internal_val, BAD_CAST "preserve")) | 
|  | 7513 | *(ctxt->space) = 1; | 
|  | 7514 | else { | 
|  | 7515 | xmlWarningMsg(ctxt, XML_WAR_SPACE_VALUE, | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7516 | "Invalid value \"%s\" for xml:space : \"default\" or \"preserve\" expected\n", | 
| Daniel Veillard | d892557 | 2005-06-08 22:34:55 +0000 | [diff] [blame] | 7517 | internal_val, NULL); | 
|  | 7518 | } | 
|  | 7519 | } | 
|  | 7520 | if (internal_val) { | 
|  | 7521 | xmlFree(internal_val); | 
|  | 7522 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7523 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7524 |  | 
|  | 7525 | *value = val; | 
|  | 7526 | return(name); | 
|  | 7527 | } | 
|  | 7528 |  | 
|  | 7529 | /** | 
|  | 7530 | * xmlParseStartTag2: | 
|  | 7531 | * @ctxt:  an XML parser context | 
|  | 7532 | * | 
|  | 7533 | * parse a start of tag either for rule element or | 
|  | 7534 | * EmptyElement. In both case we don't parse the tag closing chars. | 
|  | 7535 | * This routine is called when running SAX2 parsing | 
|  | 7536 | * | 
|  | 7537 | * [40] STag ::= '<' Name (S Attribute)* S? '>' | 
|  | 7538 | * | 
|  | 7539 | * [ WFC: Unique Att Spec ] | 
|  | 7540 | * No attribute name may appear more than once in the same start-tag or | 
|  | 7541 | * empty-element tag. | 
|  | 7542 | * | 
|  | 7543 | * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' | 
|  | 7544 | * | 
|  | 7545 | * [ WFC: Unique Att Spec ] | 
|  | 7546 | * No attribute name may appear more than once in the same start-tag or | 
|  | 7547 | * empty-element tag. | 
|  | 7548 | * | 
|  | 7549 | * With namespace: | 
|  | 7550 | * | 
|  | 7551 | * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' | 
|  | 7552 | * | 
|  | 7553 | * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' | 
|  | 7554 | * | 
|  | 7555 | * Returns the element name parsed | 
|  | 7556 | */ | 
|  | 7557 |  | 
|  | 7558 | static const xmlChar * | 
|  | 7559 | xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 7560 | const xmlChar **URI, int *tlen) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7561 | const xmlChar *localname; | 
|  | 7562 | const xmlChar *prefix; | 
|  | 7563 | const xmlChar *attname; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7564 | const xmlChar *aprefix; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7565 | const xmlChar *nsname; | 
|  | 7566 | xmlChar *attvalue; | 
|  | 7567 | const xmlChar **atts = ctxt->atts; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7568 | int maxatts = ctxt->maxatts; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7569 | int nratts, nbatts, nbdef; | 
|  | 7570 | int i, j, nbNs, attval; | 
|  | 7571 | const xmlChar *base; | 
|  | 7572 | unsigned long cur; | 
| Daniel Veillard | 365cf67 | 2005-06-09 08:18:24 +0000 | [diff] [blame] | 7573 | int nsNr = ctxt->nsNr; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7574 |  | 
|  | 7575 | if (RAW != '<') return(NULL); | 
|  | 7576 | NEXT1; | 
|  | 7577 |  | 
|  | 7578 | /* | 
|  | 7579 | * NOTE: it is crucial with the SAX2 API to never call SHRINK beyond that | 
|  | 7580 | *       point since the attribute values may be stored as pointers to | 
|  | 7581 | *       the buffer and calling SHRINK would destroy them ! | 
|  | 7582 | *       The Shrinking is only possible once the full set of attribute | 
|  | 7583 | *       callbacks have been done. | 
|  | 7584 | */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7585 | reparse: | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7586 | SHRINK; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7587 | base = ctxt->input->base; | 
|  | 7588 | cur = ctxt->input->cur - ctxt->input->base; | 
|  | 7589 | nbatts = 0; | 
|  | 7590 | nratts = 0; | 
|  | 7591 | nbdef = 0; | 
|  | 7592 | nbNs = 0; | 
|  | 7593 | attval = 0; | 
| Daniel Veillard | 365cf67 | 2005-06-09 08:18:24 +0000 | [diff] [blame] | 7594 | /* Forget any namespaces added during an earlier parse of this element. */ | 
|  | 7595 | ctxt->nsNr = nsNr; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7596 |  | 
|  | 7597 | localname = xmlParseQName(ctxt, &prefix); | 
|  | 7598 | if (localname == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7599 | xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, | 
|  | 7600 | "StartTag: invalid element name\n"); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7601 | return(NULL); | 
|  | 7602 | } | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 7603 | *tlen = ctxt->input->cur - ctxt->input->base - cur; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7604 |  | 
|  | 7605 | /* | 
|  | 7606 | * Now parse the attributes, it ends up with the ending | 
|  | 7607 | * | 
|  | 7608 | * (S Attribute)* S? | 
|  | 7609 | */ | 
|  | 7610 | SKIP_BLANKS; | 
|  | 7611 | GROW; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7612 | if (ctxt->input->base != base) goto base_changed; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7613 |  | 
|  | 7614 | while ((RAW != '>') && | 
|  | 7615 | ((RAW != '/') || (NXT(1) != '>')) && | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 7616 | (IS_BYTE_CHAR(RAW))) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7617 | const xmlChar *q = CUR_PTR; | 
|  | 7618 | unsigned int cons = ctxt->input->consumed; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7619 | int len = -1, alloc = 0; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7620 |  | 
| Daniel Veillard | 8e36e6a | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7621 | attname = xmlParseAttribute2(ctxt, prefix, localname, | 
|  | 7622 | &aprefix, &attvalue, &len, &alloc); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7623 | if ((attname != NULL) && (attvalue != NULL)) { | 
|  | 7624 | if (len < 0) len = xmlStrlen(attvalue); | 
|  | 7625 | if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) { | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7626 | const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); | 
|  | 7627 | xmlURIPtr uri; | 
|  | 7628 |  | 
|  | 7629 | if (*URL != 0) { | 
|  | 7630 | uri = xmlParseURI((const char *) URL); | 
|  | 7631 | if (uri == NULL) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 7632 | xmlWarningMsg(ctxt, XML_WAR_NS_URI, | 
|  | 7633 | "xmlns: %s not a valid URI\n", | 
|  | 7634 | URL, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7635 | } else { | 
|  | 7636 | if (uri->scheme == NULL) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 7637 | xmlWarningMsg(ctxt, XML_WAR_NS_URI_RELATIVE, | 
|  | 7638 | "xmlns: URI %s is not absolute\n", | 
|  | 7639 | URL, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7640 | } | 
|  | 7641 | xmlFreeURI(uri); | 
|  | 7642 | } | 
|  | 7643 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7644 | /* | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 7645 | * check that it's not a defined namespace | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7646 | */ | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 7647 | for (j = 1;j <= nbNs;j++) | 
|  | 7648 | if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL) | 
|  | 7649 | break; | 
|  | 7650 | if (j <= nbNs) | 
|  | 7651 | xmlErrAttributeDup(ctxt, NULL, attname); | 
|  | 7652 | else | 
|  | 7653 | if (nsPush(ctxt, NULL, URL) > 0) nbNs++; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7654 | if (alloc != 0) xmlFree(attvalue); | 
|  | 7655 | SKIP_BLANKS; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7656 | continue; | 
|  | 7657 | } | 
|  | 7658 | if (aprefix == ctxt->str_xmlns) { | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7659 | const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); | 
|  | 7660 | xmlURIPtr uri; | 
|  | 7661 |  | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7662 | if (attname == ctxt->str_xml) { | 
|  | 7663 | if (URL != ctxt->str_xml_ns) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7664 | xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE, | 
|  | 7665 | "xml namespace prefix mapped to wrong URI\n", | 
|  | 7666 | NULL, NULL, NULL); | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7667 | } | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7668 | /* | 
|  | 7669 | * Do not keep a namespace definition node | 
|  | 7670 | */ | 
|  | 7671 | if (alloc != 0) xmlFree(attvalue); | 
|  | 7672 | SKIP_BLANKS; | 
|  | 7673 | continue; | 
|  | 7674 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7675 | uri = xmlParseURI((const char *) URL); | 
|  | 7676 | if (uri == NULL) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 7677 | xmlWarningMsg(ctxt, XML_WAR_NS_URI, | 
|  | 7678 | "xmlns:%s: '%s' is not a valid URI\n", | 
|  | 7679 | attname, URL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7680 | } else { | 
| Daniel Veillard | 3b7840c | 2003-09-11 23:42:01 +0000 | [diff] [blame] | 7681 | if ((ctxt->pedantic) && (uri->scheme == NULL)) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 7682 | xmlWarningMsg(ctxt, XML_WAR_NS_URI_RELATIVE, | 
|  | 7683 | "xmlns:%s: URI %s is not absolute\n", | 
|  | 7684 | attname, URL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7685 | } | 
|  | 7686 | xmlFreeURI(uri); | 
|  | 7687 | } | 
|  | 7688 |  | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7689 | /* | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 7690 | * check that it's not a defined namespace | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7691 | */ | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 7692 | for (j = 1;j <= nbNs;j++) | 
|  | 7693 | if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname) | 
|  | 7694 | break; | 
|  | 7695 | if (j <= nbNs) | 
|  | 7696 | xmlErrAttributeDup(ctxt, aprefix, attname); | 
|  | 7697 | else | 
|  | 7698 | if (nsPush(ctxt, attname, URL) > 0) nbNs++; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7699 | if (alloc != 0) xmlFree(attvalue); | 
|  | 7700 | SKIP_BLANKS; | 
| Daniel Veillard | d3999c7 | 2004-03-10 16:27:03 +0000 | [diff] [blame] | 7701 | if (ctxt->input->base != base) goto base_changed; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7702 | continue; | 
|  | 7703 | } | 
|  | 7704 |  | 
|  | 7705 | /* | 
|  | 7706 | * Add the pair to atts | 
|  | 7707 | */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7708 | if ((atts == NULL) || (nbatts + 5 > maxatts)) { | 
|  | 7709 | if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7710 | if (attvalue[len] == 0) | 
|  | 7711 | xmlFree(attvalue); | 
|  | 7712 | goto failed; | 
|  | 7713 | } | 
|  | 7714 | maxatts = ctxt->maxatts; | 
|  | 7715 | atts = ctxt->atts; | 
|  | 7716 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7717 | ctxt->attallocs[nratts++] = alloc; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7718 | atts[nbatts++] = attname; | 
|  | 7719 | atts[nbatts++] = aprefix; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7720 | atts[nbatts++] = NULL; /* the URI will be fetched later */ | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7721 | atts[nbatts++] = attvalue; | 
|  | 7722 | attvalue += len; | 
|  | 7723 | atts[nbatts++] = attvalue; | 
|  | 7724 | /* | 
|  | 7725 | * tag if some deallocation is needed | 
|  | 7726 | */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7727 | if (alloc != 0) attval = 1; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7728 | } else { | 
|  | 7729 | if ((attvalue != NULL) && (attvalue[len] == 0)) | 
|  | 7730 | xmlFree(attvalue); | 
|  | 7731 | } | 
|  | 7732 |  | 
|  | 7733 | failed: | 
|  | 7734 |  | 
|  | 7735 | GROW | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7736 | if (ctxt->input->base != base) goto base_changed; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7737 | if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) | 
|  | 7738 | break; | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 7739 | if (!IS_BLANK_CH(RAW)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7740 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 7741 | "attributes construct error\n"); | 
| William M. Brack | 13dfa87 | 2004-09-18 04:52:08 +0000 | [diff] [blame] | 7742 | break; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7743 | } | 
|  | 7744 | SKIP_BLANKS; | 
|  | 7745 | if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && | 
|  | 7746 | (attname == NULL) && (attvalue == NULL)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7747 | xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7748 | "xmlParseStartTag: problem parsing attributes\n"); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7749 | break; | 
|  | 7750 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7751 | GROW; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7752 | if (ctxt->input->base != base) goto base_changed; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7753 | } | 
|  | 7754 |  | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7755 | /* | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7756 | * The attributes defaulting | 
|  | 7757 | */ | 
|  | 7758 | if (ctxt->attsDefault != NULL) { | 
|  | 7759 | xmlDefAttrsPtr defaults; | 
|  | 7760 |  | 
|  | 7761 | defaults = xmlHashLookup2(ctxt->attsDefault, localname, prefix); | 
|  | 7762 | if (defaults != NULL) { | 
|  | 7763 | for (i = 0;i < defaults->nbAttrs;i++) { | 
|  | 7764 | attname = defaults->values[4 * i]; | 
|  | 7765 | aprefix = defaults->values[4 * i + 1]; | 
|  | 7766 |  | 
|  | 7767 | /* | 
|  | 7768 | * special work for namespaces defaulted defs | 
|  | 7769 | */ | 
|  | 7770 | if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) { | 
|  | 7771 | /* | 
|  | 7772 | * check that it's not a defined namespace | 
|  | 7773 | */ | 
|  | 7774 | for (j = 1;j <= nbNs;j++) | 
|  | 7775 | if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL) | 
|  | 7776 | break; | 
|  | 7777 | if (j <= nbNs) continue; | 
|  | 7778 |  | 
|  | 7779 | nsname = xmlGetNamespace(ctxt, NULL); | 
|  | 7780 | if (nsname != defaults->values[4 * i + 2]) { | 
|  | 7781 | if (nsPush(ctxt, NULL, | 
|  | 7782 | defaults->values[4 * i + 2]) > 0) | 
|  | 7783 | nbNs++; | 
|  | 7784 | } | 
|  | 7785 | } else if (aprefix == ctxt->str_xmlns) { | 
|  | 7786 | /* | 
|  | 7787 | * check that it's not a defined namespace | 
|  | 7788 | */ | 
|  | 7789 | for (j = 1;j <= nbNs;j++) | 
|  | 7790 | if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname) | 
|  | 7791 | break; | 
|  | 7792 | if (j <= nbNs) continue; | 
|  | 7793 |  | 
|  | 7794 | nsname = xmlGetNamespace(ctxt, attname); | 
|  | 7795 | if (nsname != defaults->values[2]) { | 
|  | 7796 | if (nsPush(ctxt, attname, | 
|  | 7797 | defaults->values[4 * i + 2]) > 0) | 
|  | 7798 | nbNs++; | 
|  | 7799 | } | 
|  | 7800 | } else { | 
|  | 7801 | /* | 
|  | 7802 | * check that it's not a defined attribute | 
|  | 7803 | */ | 
|  | 7804 | for (j = 0;j < nbatts;j+=5) { | 
|  | 7805 | if ((attname == atts[j]) && (aprefix == atts[j+1])) | 
|  | 7806 | break; | 
|  | 7807 | } | 
|  | 7808 | if (j < nbatts) continue; | 
|  | 7809 |  | 
|  | 7810 | if ((atts == NULL) || (nbatts + 5 > maxatts)) { | 
|  | 7811 | if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) { | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 7812 | return(NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7813 | } | 
|  | 7814 | maxatts = ctxt->maxatts; | 
|  | 7815 | atts = ctxt->atts; | 
|  | 7816 | } | 
|  | 7817 | atts[nbatts++] = attname; | 
|  | 7818 | atts[nbatts++] = aprefix; | 
|  | 7819 | if (aprefix == NULL) | 
|  | 7820 | atts[nbatts++] = NULL; | 
|  | 7821 | else | 
|  | 7822 | atts[nbatts++] = xmlGetNamespace(ctxt, aprefix); | 
|  | 7823 | atts[nbatts++] = defaults->values[4 * i + 2]; | 
|  | 7824 | atts[nbatts++] = defaults->values[4 * i + 3]; | 
|  | 7825 | nbdef++; | 
|  | 7826 | } | 
|  | 7827 | } | 
|  | 7828 | } | 
|  | 7829 | } | 
|  | 7830 |  | 
| Daniel Veillard | e70c877 | 2003-11-25 07:21:18 +0000 | [diff] [blame] | 7831 | /* | 
|  | 7832 | * The attributes checkings | 
|  | 7833 | */ | 
|  | 7834 | for (i = 0; i < nbatts;i += 5) { | 
| Kasimier T. Buchcik | 455472f | 2005-04-29 10:04:43 +0000 | [diff] [blame] | 7835 | /* | 
|  | 7836 | * The default namespace does not apply to attribute names. | 
|  | 7837 | */ | 
|  | 7838 | if (atts[i + 1] != NULL) { | 
|  | 7839 | nsname = xmlGetNamespace(ctxt, atts[i + 1]); | 
|  | 7840 | if (nsname == NULL) { | 
|  | 7841 | xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, | 
|  | 7842 | "Namespace prefix %s for %s on %s is not defined\n", | 
|  | 7843 | atts[i + 1], atts[i], localname); | 
|  | 7844 | } | 
|  | 7845 | atts[i + 2] = nsname; | 
|  | 7846 | } else | 
|  | 7847 | nsname = NULL; | 
| Daniel Veillard | e70c877 | 2003-11-25 07:21:18 +0000 | [diff] [blame] | 7848 | /* | 
|  | 7849 | * [ WFC: Unique Att Spec ] | 
|  | 7850 | * No attribute name may appear more than once in the same | 
|  | 7851 | * start-tag or empty-element tag. | 
|  | 7852 | * As extended by the Namespace in XML REC. | 
|  | 7853 | */ | 
|  | 7854 | for (j = 0; j < i;j += 5) { | 
|  | 7855 | if (atts[i] == atts[j]) { | 
|  | 7856 | if (atts[i+1] == atts[j+1]) { | 
|  | 7857 | xmlErrAttributeDup(ctxt, atts[i+1], atts[i]); | 
|  | 7858 | break; | 
|  | 7859 | } | 
|  | 7860 | if ((nsname != NULL) && (atts[j + 2] == nsname)) { | 
|  | 7861 | xmlNsErr(ctxt, XML_NS_ERR_ATTRIBUTE_REDEFINED, | 
|  | 7862 | "Namespaced Attribute %s in '%s' redefined\n", | 
|  | 7863 | atts[i], nsname, NULL); | 
|  | 7864 | break; | 
|  | 7865 | } | 
|  | 7866 | } | 
|  | 7867 | } | 
|  | 7868 | } | 
|  | 7869 |  | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7870 | nsname = xmlGetNamespace(ctxt, prefix); | 
|  | 7871 | if ((prefix != NULL) && (nsname == NULL)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7872 | xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, | 
|  | 7873 | "Namespace prefix %s on %s is not defined\n", | 
|  | 7874 | prefix, localname, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7875 | } | 
|  | 7876 | *pref = prefix; | 
|  | 7877 | *URI = nsname; | 
|  | 7878 |  | 
|  | 7879 | /* | 
|  | 7880 | * SAX: Start of Element ! | 
|  | 7881 | */ | 
|  | 7882 | if ((ctxt->sax != NULL) && (ctxt->sax->startElementNs != NULL) && | 
|  | 7883 | (!ctxt->disableSAX)) { | 
|  | 7884 | if (nbNs > 0) | 
|  | 7885 | ctxt->sax->startElementNs(ctxt->userData, localname, prefix, | 
|  | 7886 | nsname, nbNs, &ctxt->nsTab[ctxt->nsNr - 2 * nbNs], | 
|  | 7887 | nbatts / 5, nbdef, atts); | 
|  | 7888 | else | 
|  | 7889 | ctxt->sax->startElementNs(ctxt->userData, localname, prefix, | 
|  | 7890 | nsname, 0, NULL, nbatts / 5, nbdef, atts); | 
|  | 7891 | } | 
|  | 7892 |  | 
|  | 7893 | /* | 
|  | 7894 | * Free up attribute allocated strings if needed | 
|  | 7895 | */ | 
|  | 7896 | if (attval != 0) { | 
|  | 7897 | for (i = 3,j = 0; j < nratts;i += 5,j++) | 
|  | 7898 | if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL)) | 
|  | 7899 | xmlFree((xmlChar *) atts[i]); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7900 | } | 
|  | 7901 |  | 
|  | 7902 | return(localname); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 7903 |  | 
|  | 7904 | base_changed: | 
|  | 7905 | /* | 
|  | 7906 | * the attribute strings are valid iif the base didn't changed | 
|  | 7907 | */ | 
|  | 7908 | if (attval != 0) { | 
|  | 7909 | for (i = 3,j = 0; j < nratts;i += 5,j++) | 
|  | 7910 | if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL)) | 
|  | 7911 | xmlFree((xmlChar *) atts[i]); | 
|  | 7912 | } | 
|  | 7913 | ctxt->input->cur = ctxt->input->base + cur; | 
|  | 7914 | if (ctxt->wellFormed == 1) { | 
|  | 7915 | goto reparse; | 
|  | 7916 | } | 
|  | 7917 | return(NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7918 | } | 
|  | 7919 |  | 
|  | 7920 | /** | 
|  | 7921 | * xmlParseEndTag2: | 
|  | 7922 | * @ctxt:  an XML parser context | 
|  | 7923 | * @line:  line of the start tag | 
|  | 7924 | * @nsNr:  number of namespaces on the start tag | 
|  | 7925 | * | 
|  | 7926 | * parse an end of tag | 
|  | 7927 | * | 
|  | 7928 | * [42] ETag ::= '</' Name S? '>' | 
|  | 7929 | * | 
|  | 7930 | * With namespace | 
|  | 7931 | * | 
|  | 7932 | * [NS 9] ETag ::= '</' QName S? '>' | 
|  | 7933 | */ | 
|  | 7934 |  | 
|  | 7935 | static void | 
|  | 7936 | xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar *prefix, | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 7937 | const xmlChar *URI, int line, int nsNr, int tlen) { | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7938 | const xmlChar *name; | 
|  | 7939 |  | 
|  | 7940 | GROW; | 
|  | 7941 | if ((RAW != '<') || (NXT(1) != '/')) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 7942 | xmlFatalErr(ctxt, XML_ERR_LTSLASH_REQUIRED, NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7943 | return; | 
|  | 7944 | } | 
|  | 7945 | SKIP(2); | 
|  | 7946 |  | 
| William M. Brack | 13dfa87 | 2004-09-18 04:52:08 +0000 | [diff] [blame] | 7947 | if ((tlen > 0) && (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 7948 | if (ctxt->input->cur[tlen] == '>') { | 
|  | 7949 | ctxt->input->cur += tlen + 1; | 
|  | 7950 | goto done; | 
|  | 7951 | } | 
|  | 7952 | ctxt->input->cur += tlen; | 
|  | 7953 | name = (xmlChar*)1; | 
|  | 7954 | } else { | 
|  | 7955 | if (prefix == NULL) | 
|  | 7956 | name = xmlParseNameAndCompare(ctxt, ctxt->name); | 
|  | 7957 | else | 
|  | 7958 | name = xmlParseQNameAndCompare(ctxt, ctxt->name, prefix); | 
|  | 7959 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7960 |  | 
|  | 7961 | /* | 
|  | 7962 | * We should definitely be at the ending "S? '>'" part | 
|  | 7963 | */ | 
|  | 7964 | GROW; | 
|  | 7965 | SKIP_BLANKS; | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 7966 | if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 7967 | xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7968 | } else | 
|  | 7969 | NEXT1; | 
|  | 7970 |  | 
|  | 7971 | /* | 
|  | 7972 | * [ WFC: Element Type Match ] | 
|  | 7973 | * The Name in an element's end-tag must match the element type in the | 
|  | 7974 | * start-tag. | 
|  | 7975 | * | 
|  | 7976 | */ | 
|  | 7977 | if (name != (xmlChar*)1) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 7978 | if (name == NULL) name = BAD_CAST "unparseable"; | 
|  | 7979 | xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH, | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7980 | "Opening and ending tag mismatch: %s line %d and %s\n", | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 7981 | ctxt->name, line, name); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7982 | } | 
|  | 7983 |  | 
|  | 7984 | /* | 
|  | 7985 | * SAX: End of Tag | 
|  | 7986 | */ | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 7987 | done: | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7988 | if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) && | 
|  | 7989 | (!ctxt->disableSAX)) | 
|  | 7990 | ctxt->sax->endElementNs(ctxt->userData, ctxt->name, prefix, URI); | 
|  | 7991 |  | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 7992 | spacePop(ctxt); | 
|  | 7993 | if (nsNr != 0) | 
|  | 7994 | nsPop(ctxt, nsNr); | 
|  | 7995 | return; | 
| Daniel Veillard | 6c5b2d3 | 2003-03-27 14:55:52 +0000 | [diff] [blame] | 7996 | } | 
|  | 7997 |  | 
|  | 7998 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7999 | * xmlParseCDSect: | 
|  | 8000 | * @ctxt:  an XML parser context | 
|  | 8001 | * | 
|  | 8002 | * Parse escaped pure raw content. | 
|  | 8003 | * | 
|  | 8004 | * [18] CDSect ::= CDStart CData CDEnd | 
|  | 8005 | * | 
|  | 8006 | * [19] CDStart ::= '<![CDATA[' | 
|  | 8007 | * | 
|  | 8008 | * [20] Data ::= (Char* - (Char* ']]>' Char*)) | 
|  | 8009 | * | 
|  | 8010 | * [21] CDEnd ::= ']]>' | 
|  | 8011 | */ | 
|  | 8012 | void | 
|  | 8013 | xmlParseCDSect(xmlParserCtxtPtr ctxt) { | 
|  | 8014 | xmlChar *buf = NULL; | 
|  | 8015 | int len = 0; | 
|  | 8016 | int size = XML_PARSER_BUFFER_SIZE; | 
|  | 8017 | int r, rl; | 
|  | 8018 | int	s, sl; | 
|  | 8019 | int cur, l; | 
|  | 8020 | int count = 0; | 
|  | 8021 |  | 
| Daniel Veillard | 8f597c3 | 2003-10-06 08:19:27 +0000 | [diff] [blame] | 8022 | /* Check 2.6.0 was NXT(0) not RAW */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8023 | if (CMP9(CUR_PTR, '<', '!', '[', 'C', 'D', 'A', 'T', 'A', '[')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8024 | SKIP(9); | 
|  | 8025 | } else | 
|  | 8026 | return; | 
|  | 8027 |  | 
|  | 8028 | ctxt->instate = XML_PARSER_CDATA_SECTION; | 
|  | 8029 | r = CUR_CHAR(rl); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 8030 | if (!IS_CHAR(r)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8031 | xmlFatalErr(ctxt, XML_ERR_CDATA_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8032 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 8033 | return; | 
|  | 8034 | } | 
|  | 8035 | NEXTL(rl); | 
|  | 8036 | s = CUR_CHAR(sl); | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 8037 | if (!IS_CHAR(s)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8038 | xmlFatalErr(ctxt, XML_ERR_CDATA_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8039 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 8040 | return; | 
|  | 8041 | } | 
|  | 8042 | NEXTL(sl); | 
|  | 8043 | cur = CUR_CHAR(l); | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 8044 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8045 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8046 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8047 | return; | 
|  | 8048 | } | 
| William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 8049 | while (IS_CHAR(cur) && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8050 | ((r != ']') || (s != ']') || (cur != '>'))) { | 
|  | 8051 | if (len + 5 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8052 | xmlChar *tmp; | 
|  | 8053 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8054 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8055 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 8056 | if (tmp == NULL) { | 
|  | 8057 | xmlFree(buf); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8058 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8059 | return; | 
|  | 8060 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8061 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8062 | } | 
|  | 8063 | COPY_BUF(rl,buf,len,r); | 
|  | 8064 | r = s; | 
|  | 8065 | rl = sl; | 
|  | 8066 | s = cur; | 
|  | 8067 | sl = l; | 
|  | 8068 | count++; | 
|  | 8069 | if (count > 50) { | 
|  | 8070 | GROW; | 
|  | 8071 | count = 0; | 
|  | 8072 | } | 
|  | 8073 | NEXTL(l); | 
|  | 8074 | cur = CUR_CHAR(l); | 
|  | 8075 | } | 
|  | 8076 | buf[len] = 0; | 
|  | 8077 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 8078 | if (cur != '>') { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 8079 | xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED, | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8080 | "CData section not finished\n%.50s\n", buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8081 | xmlFree(buf); | 
|  | 8082 | return; | 
|  | 8083 | } | 
|  | 8084 | NEXTL(l); | 
|  | 8085 |  | 
|  | 8086 | /* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 8087 | * OK the buffer is to be consumed as cdata. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8088 | */ | 
|  | 8089 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { | 
|  | 8090 | if (ctxt->sax->cdataBlock != NULL) | 
|  | 8091 | ctxt->sax->cdataBlock(ctxt->userData, buf, len); | 
| Daniel Veillard | 7583a59 | 2001-07-08 13:15:55 +0000 | [diff] [blame] | 8092 | else if (ctxt->sax->characters != NULL) | 
|  | 8093 | ctxt->sax->characters(ctxt->userData, buf, len); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8094 | } | 
|  | 8095 | xmlFree(buf); | 
|  | 8096 | } | 
|  | 8097 |  | 
|  | 8098 | /** | 
|  | 8099 | * xmlParseContent: | 
|  | 8100 | * @ctxt:  an XML parser context | 
|  | 8101 | * | 
|  | 8102 | * Parse a content: | 
|  | 8103 | * | 
|  | 8104 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* | 
|  | 8105 | */ | 
|  | 8106 |  | 
|  | 8107 | void | 
|  | 8108 | xmlParseContent(xmlParserCtxtPtr ctxt) { | 
|  | 8109 | GROW; | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 8110 | while ((RAW != 0) && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8111 | ((RAW != '<') || (NXT(1) != '/'))) { | 
|  | 8112 | const xmlChar *test = CUR_PTR; | 
| Daniel Veillard | 3e59fc5 | 2003-04-18 12:34:58 +0000 | [diff] [blame] | 8113 | unsigned int cons = ctxt->input->consumed; | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 8114 | const xmlChar *cur = ctxt->input->cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8115 |  | 
|  | 8116 | /* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8117 | * First case : a Processing Instruction. | 
|  | 8118 | */ | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 8119 | if ((*cur == '<') && (cur[1] == '?')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8120 | xmlParsePI(ctxt); | 
|  | 8121 | } | 
|  | 8122 |  | 
|  | 8123 | /* | 
|  | 8124 | * Second case : a CDSection | 
|  | 8125 | */ | 
| Daniel Veillard | 8f597c3 | 2003-10-06 08:19:27 +0000 | [diff] [blame] | 8126 | /* 2.6.0 test was *cur not RAW */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8127 | else if (CMP9(CUR_PTR, '<', '!', '[', 'C', 'D', 'A', 'T', 'A', '[')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8128 | xmlParseCDSect(ctxt); | 
|  | 8129 | } | 
|  | 8130 |  | 
|  | 8131 | /* | 
|  | 8132 | * Third case :  a comment | 
|  | 8133 | */ | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 8134 | else if ((*cur == '<') && (NXT(1) == '!') && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8135 | (NXT(2) == '-') && (NXT(3) == '-')) { | 
|  | 8136 | xmlParseComment(ctxt); | 
|  | 8137 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 8138 | } | 
|  | 8139 |  | 
|  | 8140 | /* | 
|  | 8141 | * Fourth case :  a sub-element. | 
|  | 8142 | */ | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 8143 | else if (*cur == '<') { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8144 | xmlParseElement(ctxt); | 
|  | 8145 | } | 
|  | 8146 |  | 
|  | 8147 | /* | 
|  | 8148 | * Fifth case : a reference. If if has not been resolved, | 
|  | 8149 | *    parsing returns it's Name, create the node | 
|  | 8150 | */ | 
|  | 8151 |  | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 8152 | else if (*cur == '&') { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8153 | xmlParseReference(ctxt); | 
|  | 8154 | } | 
|  | 8155 |  | 
|  | 8156 | /* | 
|  | 8157 | * Last case, text. Note that References are handled directly. | 
|  | 8158 | */ | 
|  | 8159 | else { | 
|  | 8160 | xmlParseCharData(ctxt, 0); | 
|  | 8161 | } | 
|  | 8162 |  | 
|  | 8163 | GROW; | 
|  | 8164 | /* | 
|  | 8165 | * Pop-up of finished entities. | 
|  | 8166 | */ | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 8167 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8168 | xmlPopInput(ctxt); | 
|  | 8169 | SHRINK; | 
|  | 8170 |  | 
| Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 8171 | if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8172 | xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 8173 | "detected an error in element content\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8174 | ctxt->instate = XML_PARSER_EOF; | 
|  | 8175 | break; | 
|  | 8176 | } | 
|  | 8177 | } | 
|  | 8178 | } | 
|  | 8179 |  | 
|  | 8180 | /** | 
|  | 8181 | * xmlParseElement: | 
|  | 8182 | * @ctxt:  an XML parser context | 
|  | 8183 | * | 
|  | 8184 | * parse an XML element, this is highly recursive | 
|  | 8185 | * | 
|  | 8186 | * [39] element ::= EmptyElemTag | STag content ETag | 
|  | 8187 | * | 
|  | 8188 | * [ WFC: Element Type Match ] | 
|  | 8189 | * The Name in an element's end-tag must match the element type in the | 
|  | 8190 | * start-tag. | 
|  | 8191 | * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8192 | */ | 
|  | 8193 |  | 
|  | 8194 | void | 
|  | 8195 | xmlParseElement(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 2fdbd32 | 2003-08-18 12:15:38 +0000 | [diff] [blame] | 8196 | const xmlChar *name; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8197 | const xmlChar *prefix; | 
|  | 8198 | const xmlChar *URI; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8199 | xmlParserNodeInfo node_info; | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 8200 | int line, tlen; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8201 | xmlNodePtr ret; | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8202 | int nsNr = ctxt->nsNr; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8203 |  | 
|  | 8204 | /* Capture start position */ | 
|  | 8205 | if (ctxt->record_info) { | 
|  | 8206 | node_info.begin_pos = ctxt->input->consumed + | 
|  | 8207 | (CUR_PTR - ctxt->input->base); | 
|  | 8208 | node_info.begin_line = ctxt->input->line; | 
|  | 8209 | } | 
|  | 8210 |  | 
|  | 8211 | if (ctxt->spaceNr == 0) | 
|  | 8212 | spacePush(ctxt, -1); | 
|  | 8213 | else | 
|  | 8214 | spacePush(ctxt, *ctxt->space); | 
|  | 8215 |  | 
| Daniel Veillard | 6c5b2d3 | 2003-03-27 14:55:52 +0000 | [diff] [blame] | 8216 | line = ctxt->input->line; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8217 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8218 | if (ctxt->sax2) | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8219 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 8220 | name = xmlParseStartTag2(ctxt, &prefix, &URI, &tlen); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8221 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8222 | else | 
|  | 8223 | name = xmlParseStartTag(ctxt); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8224 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8225 | if (name == NULL) { | 
|  | 8226 | spacePop(ctxt); | 
|  | 8227 | return; | 
|  | 8228 | } | 
|  | 8229 | namePush(ctxt, name); | 
|  | 8230 | ret = ctxt->node; | 
|  | 8231 |  | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 8232 | #ifdef LIBXML_VALID_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8233 | /* | 
|  | 8234 | * [ VC: Root Element Type ] | 
|  | 8235 | * The Name in the document type declaration must match the element | 
|  | 8236 | * type of the root element. | 
|  | 8237 | */ | 
|  | 8238 | if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && | 
|  | 8239 | ctxt->node && (ctxt->node == ctxt->myDoc->children)) | 
|  | 8240 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 8241 | #endif /* LIBXML_VALID_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8242 |  | 
|  | 8243 | /* | 
|  | 8244 | * Check for an Empty Element. | 
|  | 8245 | */ | 
|  | 8246 | if ((RAW == '/') && (NXT(1) == '>')) { | 
|  | 8247 | SKIP(2); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8248 | if (ctxt->sax2) { | 
|  | 8249 | if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) && | 
|  | 8250 | (!ctxt->disableSAX)) | 
|  | 8251 | ctxt->sax->endElementNs(ctxt->userData, name, prefix, URI); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8252 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8253 | } else { | 
|  | 8254 | if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL) && | 
|  | 8255 | (!ctxt->disableSAX)) | 
|  | 8256 | ctxt->sax->endElement(ctxt->userData, name); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8257 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8258 | } | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8259 | namePop(ctxt); | 
|  | 8260 | spacePop(ctxt); | 
|  | 8261 | if (nsNr != ctxt->nsNr) | 
|  | 8262 | nsPop(ctxt, ctxt->nsNr - nsNr); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8263 | if ( ret != NULL && ctxt->record_info ) { | 
|  | 8264 | node_info.end_pos = ctxt->input->consumed + | 
|  | 8265 | (CUR_PTR - ctxt->input->base); | 
|  | 8266 | node_info.end_line = ctxt->input->line; | 
|  | 8267 | node_info.node = ret; | 
|  | 8268 | xmlParserAddNodeInfo(ctxt, &node_info); | 
|  | 8269 | } | 
|  | 8270 | return; | 
|  | 8271 | } | 
|  | 8272 | if (RAW == '>') { | 
| Daniel Veillard | 21a0f91 | 2001-02-25 19:54:14 +0000 | [diff] [blame] | 8273 | NEXT1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8274 | } else { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 8275 | xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_GT_REQUIRED, | 
|  | 8276 | "Couldn't find end of Start Tag %s line %d\n", | 
|  | 8277 | name, line, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8278 |  | 
|  | 8279 | /* | 
|  | 8280 | * end of parsing of this node. | 
|  | 8281 | */ | 
|  | 8282 | nodePop(ctxt); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8283 | namePop(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8284 | spacePop(ctxt); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8285 | if (nsNr != ctxt->nsNr) | 
|  | 8286 | nsPop(ctxt, ctxt->nsNr - nsNr); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8287 |  | 
|  | 8288 | /* | 
|  | 8289 | * Capture end position and add node | 
|  | 8290 | */ | 
|  | 8291 | if ( ret != NULL && ctxt->record_info ) { | 
|  | 8292 | node_info.end_pos = ctxt->input->consumed + | 
|  | 8293 | (CUR_PTR - ctxt->input->base); | 
|  | 8294 | node_info.end_line = ctxt->input->line; | 
|  | 8295 | node_info.node = ret; | 
|  | 8296 | xmlParserAddNodeInfo(ctxt, &node_info); | 
|  | 8297 | } | 
|  | 8298 | return; | 
|  | 8299 | } | 
|  | 8300 |  | 
|  | 8301 | /* | 
|  | 8302 | * Parse the content of the element: | 
|  | 8303 | */ | 
|  | 8304 | xmlParseContent(ctxt); | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 8305 | if (!IS_BYTE_CHAR(RAW)) { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 8306 | xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED, | 
| Daniel Veillard | 2b0f879 | 2003-10-10 19:36:36 +0000 | [diff] [blame] | 8307 | "Premature end of data in tag %s line %d\n", | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 8308 | name, line, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8309 |  | 
|  | 8310 | /* | 
|  | 8311 | * end of parsing of this node. | 
|  | 8312 | */ | 
|  | 8313 | nodePop(ctxt); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8314 | namePop(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8315 | spacePop(ctxt); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8316 | if (nsNr != ctxt->nsNr) | 
|  | 8317 | nsPop(ctxt, ctxt->nsNr - nsNr); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8318 | return; | 
|  | 8319 | } | 
|  | 8320 |  | 
|  | 8321 | /* | 
|  | 8322 | * parse the end of tag: '</' should be here. | 
|  | 8323 | */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 8324 | if (ctxt->sax2) { | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 8325 | xmlParseEndTag2(ctxt, prefix, URI, line, ctxt->nsNr - nsNr, tlen); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 8326 | namePop(ctxt); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8327 | } | 
|  | 8328 | #ifdef LIBXML_SAX1_ENABLED | 
|  | 8329 | else | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8330 | xmlParseEndTag1(ctxt, line); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 8331 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8332 |  | 
|  | 8333 | /* | 
|  | 8334 | * Capture end position and add node | 
|  | 8335 | */ | 
|  | 8336 | if ( ret != NULL && ctxt->record_info ) { | 
|  | 8337 | node_info.end_pos = ctxt->input->consumed + | 
|  | 8338 | (CUR_PTR - ctxt->input->base); | 
|  | 8339 | node_info.end_line = ctxt->input->line; | 
|  | 8340 | node_info.node = ret; | 
|  | 8341 | xmlParserAddNodeInfo(ctxt, &node_info); | 
|  | 8342 | } | 
|  | 8343 | } | 
|  | 8344 |  | 
|  | 8345 | /** | 
|  | 8346 | * xmlParseVersionNum: | 
|  | 8347 | * @ctxt:  an XML parser context | 
|  | 8348 | * | 
|  | 8349 | * parse the XML version value. | 
|  | 8350 | * | 
|  | 8351 | * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ | 
|  | 8352 | * | 
|  | 8353 | * Returns the string giving the XML version number, or NULL | 
|  | 8354 | */ | 
|  | 8355 | xmlChar * | 
|  | 8356 | xmlParseVersionNum(xmlParserCtxtPtr ctxt) { | 
|  | 8357 | xmlChar *buf = NULL; | 
|  | 8358 | int len = 0; | 
|  | 8359 | int size = 10; | 
|  | 8360 | xmlChar cur; | 
|  | 8361 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 8362 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8363 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8364 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8365 | return(NULL); | 
|  | 8366 | } | 
|  | 8367 | cur = CUR; | 
|  | 8368 | while (((cur >= 'a') && (cur <= 'z')) || | 
|  | 8369 | ((cur >= 'A') && (cur <= 'Z')) || | 
|  | 8370 | ((cur >= '0') && (cur <= '9')) || | 
|  | 8371 | (cur == '_') || (cur == '.') || | 
|  | 8372 | (cur == ':') || (cur == '-')) { | 
|  | 8373 | if (len + 1 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8374 | xmlChar *tmp; | 
|  | 8375 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8376 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8377 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 8378 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8379 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8380 | return(NULL); | 
|  | 8381 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8382 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8383 | } | 
|  | 8384 | buf[len++] = cur; | 
|  | 8385 | NEXT; | 
|  | 8386 | cur=CUR; | 
|  | 8387 | } | 
|  | 8388 | buf[len] = 0; | 
|  | 8389 | return(buf); | 
|  | 8390 | } | 
|  | 8391 |  | 
|  | 8392 | /** | 
|  | 8393 | * xmlParseVersionInfo: | 
|  | 8394 | * @ctxt:  an XML parser context | 
|  | 8395 | * | 
|  | 8396 | * parse the XML version. | 
|  | 8397 | * | 
|  | 8398 | * [24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ") | 
|  | 8399 | * | 
|  | 8400 | * [25] Eq ::= S? '=' S? | 
|  | 8401 | * | 
|  | 8402 | * Returns the version string, e.g. "1.0" | 
|  | 8403 | */ | 
|  | 8404 |  | 
|  | 8405 | xmlChar * | 
|  | 8406 | xmlParseVersionInfo(xmlParserCtxtPtr ctxt) { | 
|  | 8407 | xmlChar *version = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8408 |  | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8409 | if (CMP7(CUR_PTR, 'v', 'e', 'r', 's', 'i', 'o', 'n')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8410 | SKIP(7); | 
|  | 8411 | SKIP_BLANKS; | 
|  | 8412 | if (RAW != '=') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8413 | xmlFatalErr(ctxt, XML_ERR_EQUAL_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8414 | return(NULL); | 
|  | 8415 | } | 
|  | 8416 | NEXT; | 
|  | 8417 | SKIP_BLANKS; | 
|  | 8418 | if (RAW == '"') { | 
|  | 8419 | NEXT; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8420 | version = xmlParseVersionNum(ctxt); | 
|  | 8421 | if (RAW != '"') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8422 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8423 | } else | 
|  | 8424 | NEXT; | 
|  | 8425 | } else if (RAW == '\''){ | 
|  | 8426 | NEXT; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8427 | version = xmlParseVersionNum(ctxt); | 
|  | 8428 | if (RAW != '\'') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8429 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8430 | } else | 
|  | 8431 | NEXT; | 
|  | 8432 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8433 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8434 | } | 
|  | 8435 | } | 
|  | 8436 | return(version); | 
|  | 8437 | } | 
|  | 8438 |  | 
|  | 8439 | /** | 
|  | 8440 | * xmlParseEncName: | 
|  | 8441 | * @ctxt:  an XML parser context | 
|  | 8442 | * | 
|  | 8443 | * parse the XML encoding name | 
|  | 8444 | * | 
|  | 8445 | * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* | 
|  | 8446 | * | 
|  | 8447 | * Returns the encoding name value or NULL | 
|  | 8448 | */ | 
|  | 8449 | xmlChar * | 
|  | 8450 | xmlParseEncName(xmlParserCtxtPtr ctxt) { | 
|  | 8451 | xmlChar *buf = NULL; | 
|  | 8452 | int len = 0; | 
|  | 8453 | int size = 10; | 
|  | 8454 | xmlChar cur; | 
|  | 8455 |  | 
|  | 8456 | cur = CUR; | 
|  | 8457 | if (((cur >= 'a') && (cur <= 'z')) || | 
|  | 8458 | ((cur >= 'A') && (cur <= 'Z'))) { | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 8459 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8460 | if (buf == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8461 | xmlErrMemory(ctxt, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8462 | return(NULL); | 
|  | 8463 | } | 
|  | 8464 |  | 
|  | 8465 | buf[len++] = cur; | 
|  | 8466 | NEXT; | 
|  | 8467 | cur = CUR; | 
|  | 8468 | while (((cur >= 'a') && (cur <= 'z')) || | 
|  | 8469 | ((cur >= 'A') && (cur <= 'Z')) || | 
|  | 8470 | ((cur >= '0') && (cur <= '9')) || | 
|  | 8471 | (cur == '.') || (cur == '_') || | 
|  | 8472 | (cur == '-')) { | 
|  | 8473 | if (len + 1 >= size) { | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8474 | xmlChar *tmp; | 
|  | 8475 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8476 | size *= 2; | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8477 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); | 
|  | 8478 | if (tmp == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8479 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8480 | xmlFree(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8481 | return(NULL); | 
|  | 8482 | } | 
| Daniel Veillard | 2248ff1 | 2004-09-22 23:05:14 +0000 | [diff] [blame] | 8483 | buf = tmp; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8484 | } | 
|  | 8485 | buf[len++] = cur; | 
|  | 8486 | NEXT; | 
|  | 8487 | cur = CUR; | 
|  | 8488 | if (cur == 0) { | 
|  | 8489 | SHRINK; | 
|  | 8490 | GROW; | 
|  | 8491 | cur = CUR; | 
|  | 8492 | } | 
|  | 8493 | } | 
|  | 8494 | buf[len] = 0; | 
|  | 8495 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8496 | xmlFatalErr(ctxt, XML_ERR_ENCODING_NAME, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8497 | } | 
|  | 8498 | return(buf); | 
|  | 8499 | } | 
|  | 8500 |  | 
|  | 8501 | /** | 
|  | 8502 | * xmlParseEncodingDecl: | 
|  | 8503 | * @ctxt:  an XML parser context | 
|  | 8504 | * | 
|  | 8505 | * parse the XML encoding declaration | 
|  | 8506 | * | 
|  | 8507 | * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' |  "'" EncName "'") | 
|  | 8508 | * | 
|  | 8509 | * this setups the conversion filters. | 
|  | 8510 | * | 
|  | 8511 | * Returns the encoding value or NULL | 
|  | 8512 | */ | 
|  | 8513 |  | 
| Daniel Veillard | ab1ae3a | 2003-08-14 12:19:54 +0000 | [diff] [blame] | 8514 | const xmlChar * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8515 | xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { | 
|  | 8516 | xmlChar *encoding = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8517 |  | 
|  | 8518 | SKIP_BLANKS; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8519 | if (CMP8(CUR_PTR, 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8520 | SKIP(8); | 
|  | 8521 | SKIP_BLANKS; | 
|  | 8522 | if (RAW != '=') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8523 | xmlFatalErr(ctxt, XML_ERR_EQUAL_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8524 | return(NULL); | 
|  | 8525 | } | 
|  | 8526 | NEXT; | 
|  | 8527 | SKIP_BLANKS; | 
|  | 8528 | if (RAW == '"') { | 
|  | 8529 | NEXT; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8530 | encoding = xmlParseEncName(ctxt); | 
|  | 8531 | if (RAW != '"') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8532 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8533 | } else | 
|  | 8534 | NEXT; | 
|  | 8535 | } else if (RAW == '\''){ | 
|  | 8536 | NEXT; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8537 | encoding = xmlParseEncName(ctxt); | 
|  | 8538 | if (RAW != '\'') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8539 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8540 | } else | 
|  | 8541 | NEXT; | 
| Daniel Veillard | 82ac6b0 | 2002-02-17 23:18:55 +0000 | [diff] [blame] | 8542 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8543 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8544 | } | 
| Daniel Veillard | 6b621b8 | 2003-08-11 15:03:34 +0000 | [diff] [blame] | 8545 | /* | 
|  | 8546 | * UTF-16 encoding stwich has already taken place at this stage, | 
|  | 8547 | * more over the little-endian/big-endian selection is already done | 
|  | 8548 | */ | 
|  | 8549 | if ((encoding != NULL) && | 
|  | 8550 | ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-16")) || | 
|  | 8551 | (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) { | 
| Daniel Veillard | ab1ae3a | 2003-08-14 12:19:54 +0000 | [diff] [blame] | 8552 | if (ctxt->encoding != NULL) | 
|  | 8553 | xmlFree((xmlChar *) ctxt->encoding); | 
|  | 8554 | ctxt->encoding = encoding; | 
| Daniel Veillard | b19ba83 | 2003-08-14 00:33:46 +0000 | [diff] [blame] | 8555 | } | 
|  | 8556 | /* | 
|  | 8557 | * UTF-8 encoding is handled natively | 
|  | 8558 | */ | 
| Daniel Veillard | ab1ae3a | 2003-08-14 12:19:54 +0000 | [diff] [blame] | 8559 | else if ((encoding != NULL) && | 
| Daniel Veillard | b19ba83 | 2003-08-14 00:33:46 +0000 | [diff] [blame] | 8560 | ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-8")) || | 
|  | 8561 | (!xmlStrcasecmp(encoding, BAD_CAST "UTF8")))) { | 
| Daniel Veillard | ab1ae3a | 2003-08-14 12:19:54 +0000 | [diff] [blame] | 8562 | if (ctxt->encoding != NULL) | 
|  | 8563 | xmlFree((xmlChar *) ctxt->encoding); | 
|  | 8564 | ctxt->encoding = encoding; | 
| Daniel Veillard | 6b621b8 | 2003-08-11 15:03:34 +0000 | [diff] [blame] | 8565 | } | 
| Daniel Veillard | ab1ae3a | 2003-08-14 12:19:54 +0000 | [diff] [blame] | 8566 | else if (encoding != NULL) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8567 | xmlCharEncodingHandlerPtr handler; | 
|  | 8568 |  | 
|  | 8569 | if (ctxt->input->encoding != NULL) | 
|  | 8570 | xmlFree((xmlChar *) ctxt->input->encoding); | 
|  | 8571 | ctxt->input->encoding = encoding; | 
|  | 8572 |  | 
| Daniel Veillard | a6874ca | 2003-07-29 16:47:24 +0000 | [diff] [blame] | 8573 | handler = xmlFindCharEncodingHandler((const char *) encoding); | 
|  | 8574 | if (handler != NULL) { | 
|  | 8575 | xmlSwitchToEncoding(ctxt, handler); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8576 | } else { | 
| Daniel Veillard | f403d29 | 2003-10-05 13:51:35 +0000 | [diff] [blame] | 8577 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING, | 
| Daniel Veillard | a6874ca | 2003-07-29 16:47:24 +0000 | [diff] [blame] | 8578 | "Unsupported encoding %s\n", encoding); | 
|  | 8579 | return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8580 | } | 
|  | 8581 | } | 
|  | 8582 | } | 
|  | 8583 | return(encoding); | 
|  | 8584 | } | 
|  | 8585 |  | 
|  | 8586 | /** | 
|  | 8587 | * xmlParseSDDecl: | 
|  | 8588 | * @ctxt:  an XML parser context | 
|  | 8589 | * | 
|  | 8590 | * parse the XML standalone declaration | 
|  | 8591 | * | 
|  | 8592 | * [32] SDDecl ::= S 'standalone' Eq | 
|  | 8593 | *                 (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) | 
|  | 8594 | * | 
|  | 8595 | * [ VC: Standalone Document Declaration ] | 
|  | 8596 | * TODO The standalone document declaration must have the value "no" | 
|  | 8597 | * if any external markup declarations contain declarations of: | 
|  | 8598 | *  - attributes with default values, if elements to which these | 
|  | 8599 | *    attributes apply appear in the document without specifications | 
|  | 8600 | *    of values for these attributes, or | 
|  | 8601 | *  - entities (other than amp, lt, gt, apos, quot), if references | 
|  | 8602 | *    to those entities appear in the document, or | 
|  | 8603 | *  - attributes with values subject to normalization, where the | 
|  | 8604 | *    attribute appears in the document with a value which will change | 
|  | 8605 | *    as a result of normalization, or | 
|  | 8606 | *  - element types with element content, if white space occurs directly | 
|  | 8607 | *    within any instance of those types. | 
|  | 8608 | * | 
|  | 8609 | * Returns 1 if standalone, 0 otherwise | 
|  | 8610 | */ | 
|  | 8611 |  | 
|  | 8612 | int | 
|  | 8613 | xmlParseSDDecl(xmlParserCtxtPtr ctxt) { | 
|  | 8614 | int standalone = -1; | 
|  | 8615 |  | 
|  | 8616 | SKIP_BLANKS; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8617 | if (CMP10(CUR_PTR, 's', 't', 'a', 'n', 'd', 'a', 'l', 'o', 'n', 'e')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8618 | SKIP(10); | 
|  | 8619 | SKIP_BLANKS; | 
|  | 8620 | if (RAW != '=') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8621 | xmlFatalErr(ctxt, XML_ERR_EQUAL_REQUIRED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8622 | return(standalone); | 
|  | 8623 | } | 
|  | 8624 | NEXT; | 
|  | 8625 | SKIP_BLANKS; | 
|  | 8626 | if (RAW == '\''){ | 
|  | 8627 | NEXT; | 
|  | 8628 | if ((RAW == 'n') && (NXT(1) == 'o')) { | 
|  | 8629 | standalone = 0; | 
|  | 8630 | SKIP(2); | 
|  | 8631 | } else if ((RAW == 'y') && (NXT(1) == 'e') && | 
|  | 8632 | (NXT(2) == 's')) { | 
|  | 8633 | standalone = 1; | 
|  | 8634 | SKIP(3); | 
|  | 8635 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8636 | xmlFatalErr(ctxt, XML_ERR_STANDALONE_VALUE, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8637 | } | 
|  | 8638 | if (RAW != '\'') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8639 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8640 | } else | 
|  | 8641 | NEXT; | 
|  | 8642 | } else if (RAW == '"'){ | 
|  | 8643 | NEXT; | 
|  | 8644 | if ((RAW == 'n') && (NXT(1) == 'o')) { | 
|  | 8645 | standalone = 0; | 
|  | 8646 | SKIP(2); | 
|  | 8647 | } else if ((RAW == 'y') && (NXT(1) == 'e') && | 
|  | 8648 | (NXT(2) == 's')) { | 
|  | 8649 | standalone = 1; | 
|  | 8650 | SKIP(3); | 
|  | 8651 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8652 | xmlFatalErr(ctxt, XML_ERR_STANDALONE_VALUE, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8653 | } | 
|  | 8654 | if (RAW != '"') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8655 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8656 | } else | 
|  | 8657 | NEXT; | 
|  | 8658 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8659 | xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8660 | } | 
|  | 8661 | } | 
|  | 8662 | return(standalone); | 
|  | 8663 | } | 
|  | 8664 |  | 
|  | 8665 | /** | 
|  | 8666 | * xmlParseXMLDecl: | 
|  | 8667 | * @ctxt:  an XML parser context | 
|  | 8668 | * | 
|  | 8669 | * parse an XML declaration header | 
|  | 8670 | * | 
|  | 8671 | * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' | 
|  | 8672 | */ | 
|  | 8673 |  | 
|  | 8674 | void | 
|  | 8675 | xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { | 
|  | 8676 | xmlChar *version; | 
|  | 8677 |  | 
|  | 8678 | /* | 
|  | 8679 | * We know that '<?xml' is here. | 
|  | 8680 | */ | 
|  | 8681 | SKIP(5); | 
|  | 8682 |  | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 8683 | if (!IS_BLANK_CH(RAW)) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 8684 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, | 
|  | 8685 | "Blank needed after '<?xml'\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8686 | } | 
|  | 8687 | SKIP_BLANKS; | 
|  | 8688 |  | 
|  | 8689 | /* | 
| Daniel Veillard | 1984094 | 2001-11-29 16:11:38 +0000 | [diff] [blame] | 8690 | * We must have the VersionInfo here. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8691 | */ | 
|  | 8692 | version = xmlParseVersionInfo(ctxt); | 
| Daniel Veillard | 1984094 | 2001-11-29 16:11:38 +0000 | [diff] [blame] | 8693 | if (version == NULL) { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 8694 | xmlFatalErr(ctxt, XML_ERR_VERSION_MISSING, NULL); | 
| Daniel Veillard | 1984094 | 2001-11-29 16:11:38 +0000 | [diff] [blame] | 8695 | } else { | 
|  | 8696 | if (!xmlStrEqual(version, (const xmlChar *) XML_DEFAULT_VERSION)) { | 
|  | 8697 | /* | 
|  | 8698 | * TODO: Blueberry should be detected here | 
|  | 8699 | */ | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 8700 | xmlWarningMsg(ctxt, XML_WAR_UNKNOWN_VERSION, | 
|  | 8701 | "Unsupported version '%s'\n", | 
|  | 8702 | version, NULL); | 
| Daniel Veillard | 1984094 | 2001-11-29 16:11:38 +0000 | [diff] [blame] | 8703 | } | 
|  | 8704 | if (ctxt->version != NULL) | 
| Daniel Veillard | d3b0882 | 2001-12-05 12:03:33 +0000 | [diff] [blame] | 8705 | xmlFree((void *) ctxt->version); | 
| Daniel Veillard | 1984094 | 2001-11-29 16:11:38 +0000 | [diff] [blame] | 8706 | ctxt->version = version; | 
| Daniel Veillard | a050d23 | 2001-09-05 15:51:05 +0000 | [diff] [blame] | 8707 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8708 |  | 
|  | 8709 | /* | 
|  | 8710 | * We may have the encoding declaration | 
|  | 8711 | */ | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 8712 | if (!IS_BLANK_CH(RAW)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8713 | if ((RAW == '?') && (NXT(1) == '>')) { | 
|  | 8714 | SKIP(2); | 
|  | 8715 | return; | 
|  | 8716 | } | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 8717 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8718 | } | 
|  | 8719 | xmlParseEncodingDecl(ctxt); | 
|  | 8720 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 8721 | /* | 
|  | 8722 | * The XML REC instructs us to stop parsing right here | 
|  | 8723 | */ | 
|  | 8724 | return; | 
|  | 8725 | } | 
|  | 8726 |  | 
|  | 8727 | /* | 
|  | 8728 | * We may have the standalone status. | 
|  | 8729 | */ | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 8730 | if ((ctxt->input->encoding != NULL) && (!IS_BLANK_CH(RAW))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8731 | if ((RAW == '?') && (NXT(1) == '>')) { | 
|  | 8732 | SKIP(2); | 
|  | 8733 | return; | 
|  | 8734 | } | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 8735 | xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8736 | } | 
|  | 8737 | SKIP_BLANKS; | 
|  | 8738 | ctxt->input->standalone = xmlParseSDDecl(ctxt); | 
|  | 8739 |  | 
|  | 8740 | SKIP_BLANKS; | 
|  | 8741 | if ((RAW == '?') && (NXT(1) == '>')) { | 
|  | 8742 | SKIP(2); | 
|  | 8743 | } else if (RAW == '>') { | 
|  | 8744 | /* Deprecated old WD ... */ | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8745 | xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8746 | NEXT; | 
|  | 8747 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8748 | xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8749 | MOVETO_ENDTAG(CUR_PTR); | 
|  | 8750 | NEXT; | 
|  | 8751 | } | 
|  | 8752 | } | 
|  | 8753 |  | 
|  | 8754 | /** | 
|  | 8755 | * xmlParseMisc: | 
|  | 8756 | * @ctxt:  an XML parser context | 
|  | 8757 | * | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 8758 | * parse an XML Misc* optional field. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8759 | * | 
|  | 8760 | * [27] Misc ::= Comment | PI |  S | 
|  | 8761 | */ | 
|  | 8762 |  | 
|  | 8763 | void | 
|  | 8764 | xmlParseMisc(xmlParserCtxtPtr ctxt) { | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 8765 | while (((RAW == '<') && (NXT(1) == '?')) || | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8766 | (CMP4(CUR_PTR, '<', '!', '-', '-')) || | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 8767 | IS_BLANK_CH(CUR)) { | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 8768 | if ((RAW == '<') && (NXT(1) == '?')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8769 | xmlParsePI(ctxt); | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 8770 | } else if (IS_BLANK_CH(CUR)) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8771 | NEXT; | 
|  | 8772 | } else | 
|  | 8773 | xmlParseComment(ctxt); | 
|  | 8774 | } | 
|  | 8775 | } | 
|  | 8776 |  | 
|  | 8777 | /** | 
|  | 8778 | * xmlParseDocument: | 
|  | 8779 | * @ctxt:  an XML parser context | 
|  | 8780 | * | 
|  | 8781 | * parse an XML document (and build a tree if using the standard SAX | 
|  | 8782 | * interface). | 
|  | 8783 | * | 
|  | 8784 | * [1] document ::= prolog element Misc* | 
|  | 8785 | * | 
|  | 8786 | * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? | 
|  | 8787 | * | 
|  | 8788 | * Returns 0, -1 in case of error. the parser context is augmented | 
|  | 8789 | *                as a result of the parsing. | 
|  | 8790 | */ | 
|  | 8791 |  | 
|  | 8792 | int | 
|  | 8793 | xmlParseDocument(xmlParserCtxtPtr ctxt) { | 
|  | 8794 | xmlChar start[4]; | 
|  | 8795 | xmlCharEncoding enc; | 
|  | 8796 |  | 
|  | 8797 | xmlInitParser(); | 
|  | 8798 |  | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 8799 | if ((ctxt == NULL) || (ctxt->input == NULL)) | 
|  | 8800 | return(-1); | 
|  | 8801 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8802 | GROW; | 
|  | 8803 |  | 
|  | 8804 | /* | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8805 | * SAX: detecting the level. | 
|  | 8806 | */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 8807 | xmlDetectSAX2(ctxt); | 
| Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 8808 |  | 
|  | 8809 | /* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8810 | * SAX: beginning of the document processing. | 
|  | 8811 | */ | 
|  | 8812 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) | 
|  | 8813 | ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); | 
|  | 8814 |  | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 8815 | if ((ctxt->encoding == (const xmlChar *)XML_CHAR_ENCODING_NONE) && | 
|  | 8816 | ((ctxt->input->end - ctxt->input->cur) >= 4)) { | 
| Daniel Veillard | 4aafa79 | 2001-07-28 17:21:12 +0000 | [diff] [blame] | 8817 | /* | 
|  | 8818 | * Get the 4 first bytes and decode the charset | 
|  | 8819 | * if enc != XML_CHAR_ENCODING_NONE | 
|  | 8820 | * plug some encoding conversion routines. | 
|  | 8821 | */ | 
|  | 8822 | start[0] = RAW; | 
|  | 8823 | start[1] = NXT(1); | 
|  | 8824 | start[2] = NXT(2); | 
|  | 8825 | start[3] = NXT(3); | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 8826 | enc = xmlDetectCharEncoding(&start[0], 4); | 
| Daniel Veillard | 4aafa79 | 2001-07-28 17:21:12 +0000 | [diff] [blame] | 8827 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 8828 | xmlSwitchEncoding(ctxt, enc); | 
|  | 8829 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8830 | } | 
|  | 8831 |  | 
|  | 8832 |  | 
|  | 8833 | if (CUR == 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8834 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8835 | } | 
|  | 8836 |  | 
|  | 8837 | /* | 
|  | 8838 | * Check for the XMLDecl in the Prolog. | 
|  | 8839 | */ | 
|  | 8840 | GROW; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8841 | if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8842 |  | 
|  | 8843 | /* | 
|  | 8844 | * Note that we will switch encoding on the fly. | 
|  | 8845 | */ | 
|  | 8846 | xmlParseXMLDecl(ctxt); | 
|  | 8847 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 8848 | /* | 
|  | 8849 | * The XML REC instructs us to stop parsing right here | 
|  | 8850 | */ | 
|  | 8851 | return(-1); | 
|  | 8852 | } | 
|  | 8853 | ctxt->standalone = ctxt->input->standalone; | 
|  | 8854 | SKIP_BLANKS; | 
|  | 8855 | } else { | 
|  | 8856 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); | 
|  | 8857 | } | 
|  | 8858 | if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) | 
|  | 8859 | ctxt->sax->startDocument(ctxt->userData); | 
|  | 8860 |  | 
|  | 8861 | /* | 
|  | 8862 | * The Misc part of the Prolog | 
|  | 8863 | */ | 
|  | 8864 | GROW; | 
|  | 8865 | xmlParseMisc(ctxt); | 
|  | 8866 |  | 
|  | 8867 | /* | 
|  | 8868 | * Then possibly doc type declaration(s) and more Misc | 
|  | 8869 | * (doctypedecl Misc*)? | 
|  | 8870 | */ | 
|  | 8871 | GROW; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 8872 | if (CMP9(CUR_PTR, '<', '!', 'D', 'O', 'C', 'T', 'Y', 'P', 'E')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8873 |  | 
|  | 8874 | ctxt->inSubset = 1; | 
|  | 8875 | xmlParseDocTypeDecl(ctxt); | 
|  | 8876 | if (RAW == '[') { | 
|  | 8877 | ctxt->instate = XML_PARSER_DTD; | 
|  | 8878 | xmlParseInternalSubset(ctxt); | 
|  | 8879 | } | 
|  | 8880 |  | 
|  | 8881 | /* | 
|  | 8882 | * Create and update the external subset. | 
|  | 8883 | */ | 
|  | 8884 | ctxt->inSubset = 2; | 
|  | 8885 | if ((ctxt->sax != NULL) && (ctxt->sax->externalSubset != NULL) && | 
|  | 8886 | (!ctxt->disableSAX)) | 
|  | 8887 | ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName, | 
|  | 8888 | ctxt->extSubSystem, ctxt->extSubURI); | 
|  | 8889 | ctxt->inSubset = 0; | 
|  | 8890 |  | 
|  | 8891 |  | 
|  | 8892 | ctxt->instate = XML_PARSER_PROLOG; | 
|  | 8893 | xmlParseMisc(ctxt); | 
|  | 8894 | } | 
|  | 8895 |  | 
|  | 8896 | /* | 
|  | 8897 | * Time to start parsing the tree itself | 
|  | 8898 | */ | 
|  | 8899 | GROW; | 
|  | 8900 | if (RAW != '<') { | 
| Daniel Veillard | bdbe0d4 | 2003-09-14 19:56:14 +0000 | [diff] [blame] | 8901 | xmlFatalErrMsg(ctxt, XML_ERR_DOCUMENT_EMPTY, | 
|  | 8902 | "Start tag expected, '<' not found\n"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8903 | } else { | 
|  | 8904 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 8905 | xmlParseElement(ctxt); | 
|  | 8906 | ctxt->instate = XML_PARSER_EPILOG; | 
|  | 8907 |  | 
|  | 8908 |  | 
|  | 8909 | /* | 
|  | 8910 | * The Misc part at the end | 
|  | 8911 | */ | 
|  | 8912 | xmlParseMisc(ctxt); | 
|  | 8913 |  | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 8914 | if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8915 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8916 | } | 
|  | 8917 | ctxt->instate = XML_PARSER_EOF; | 
|  | 8918 | } | 
|  | 8919 |  | 
|  | 8920 | /* | 
|  | 8921 | * SAX: end of the document processing. | 
|  | 8922 | */ | 
| Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 8923 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8924 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 8925 |  | 
| Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 8926 | /* | 
|  | 8927 | * Remove locally kept entity definitions if the tree was not built | 
|  | 8928 | */ | 
|  | 8929 | if ((ctxt->myDoc != NULL) && | 
|  | 8930 | (xmlStrEqual(ctxt->myDoc->version, SAX_COMPAT_MODE))) { | 
|  | 8931 | xmlFreeDoc(ctxt->myDoc); | 
|  | 8932 | ctxt->myDoc = NULL; | 
|  | 8933 | } | 
|  | 8934 |  | 
| Daniel Veillard | c761299 | 2002-02-17 22:47:37 +0000 | [diff] [blame] | 8935 | if (! ctxt->wellFormed) { | 
|  | 8936 | ctxt->valid = 0; | 
|  | 8937 | return(-1); | 
|  | 8938 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8939 | return(0); | 
|  | 8940 | } | 
|  | 8941 |  | 
|  | 8942 | /** | 
|  | 8943 | * xmlParseExtParsedEnt: | 
|  | 8944 | * @ctxt:  an XML parser context | 
|  | 8945 | * | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 8946 | * parse a general parsed entity | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8947 | * An external general parsed entity is well-formed if it matches the | 
|  | 8948 | * production labeled extParsedEnt. | 
|  | 8949 | * | 
|  | 8950 | * [78] extParsedEnt ::= TextDecl? content | 
|  | 8951 | * | 
|  | 8952 | * Returns 0, -1 in case of error. the parser context is augmented | 
|  | 8953 | *                as a result of the parsing. | 
|  | 8954 | */ | 
|  | 8955 |  | 
|  | 8956 | int | 
|  | 8957 | xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { | 
|  | 8958 | xmlChar start[4]; | 
|  | 8959 | xmlCharEncoding enc; | 
|  | 8960 |  | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 8961 | if ((ctxt == NULL) || (ctxt->input == NULL)) | 
|  | 8962 | return(-1); | 
|  | 8963 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8964 | xmlDefaultSAXHandlerInit(); | 
|  | 8965 |  | 
| Daniel Veillard | 309f81d | 2003-09-23 09:02:53 +0000 | [diff] [blame] | 8966 | xmlDetectSAX2(ctxt); | 
|  | 8967 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8968 | GROW; | 
|  | 8969 |  | 
|  | 8970 | /* | 
|  | 8971 | * SAX: beginning of the document processing. | 
|  | 8972 | */ | 
|  | 8973 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) | 
|  | 8974 | ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); | 
|  | 8975 |  | 
|  | 8976 | /* | 
|  | 8977 | * Get the 4 first bytes and decode the charset | 
|  | 8978 | * if enc != XML_CHAR_ENCODING_NONE | 
|  | 8979 | * plug some encoding conversion routines. | 
|  | 8980 | */ | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 8981 | if ((ctxt->input->end - ctxt->input->cur) >= 4) { | 
|  | 8982 | start[0] = RAW; | 
|  | 8983 | start[1] = NXT(1); | 
|  | 8984 | start[2] = NXT(2); | 
|  | 8985 | start[3] = NXT(3); | 
|  | 8986 | enc = xmlDetectCharEncoding(start, 4); | 
|  | 8987 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 8988 | xmlSwitchEncoding(ctxt, enc); | 
|  | 8989 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8990 | } | 
|  | 8991 |  | 
|  | 8992 |  | 
|  | 8993 | if (CUR == 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 8994 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 8995 | } | 
|  | 8996 |  | 
|  | 8997 | /* | 
|  | 8998 | * Check for the XMLDecl in the Prolog. | 
|  | 8999 | */ | 
|  | 9000 | GROW; | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 9001 | if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9002 |  | 
|  | 9003 | /* | 
|  | 9004 | * Note that we will switch encoding on the fly. | 
|  | 9005 | */ | 
|  | 9006 | xmlParseXMLDecl(ctxt); | 
|  | 9007 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 9008 | /* | 
|  | 9009 | * The XML REC instructs us to stop parsing right here | 
|  | 9010 | */ | 
|  | 9011 | return(-1); | 
|  | 9012 | } | 
|  | 9013 | SKIP_BLANKS; | 
|  | 9014 | } else { | 
|  | 9015 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); | 
|  | 9016 | } | 
|  | 9017 | if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) | 
|  | 9018 | ctxt->sax->startDocument(ctxt->userData); | 
|  | 9019 |  | 
|  | 9020 | /* | 
|  | 9021 | * Doing validity checking on chunk doesn't make sense | 
|  | 9022 | */ | 
|  | 9023 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 9024 | ctxt->validate = 0; | 
|  | 9025 | ctxt->loadsubset = 0; | 
|  | 9026 | ctxt->depth = 0; | 
|  | 9027 |  | 
|  | 9028 | xmlParseContent(ctxt); | 
|  | 9029 |  | 
|  | 9030 | if ((RAW == '<') && (NXT(1) == '/')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 9031 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9032 | } else if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 9033 | xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9034 | } | 
|  | 9035 |  | 
|  | 9036 | /* | 
|  | 9037 | * SAX: end of the document processing. | 
|  | 9038 | */ | 
| Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 9039 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9040 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 9041 |  | 
|  | 9042 | if (! ctxt->wellFormed) return(-1); | 
|  | 9043 | return(0); | 
|  | 9044 | } | 
|  | 9045 |  | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 9046 | #ifdef LIBXML_PUSH_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9047 | /************************************************************************ | 
|  | 9048 | *									* | 
|  | 9049 | * 		Progressive parsing interfaces				* | 
|  | 9050 | *									* | 
|  | 9051 | ************************************************************************/ | 
|  | 9052 |  | 
|  | 9053 | /** | 
|  | 9054 | * xmlParseLookupSequence: | 
|  | 9055 | * @ctxt:  an XML parser context | 
|  | 9056 | * @first:  the first char to lookup | 
|  | 9057 | * @next:  the next char to lookup or zero | 
|  | 9058 | * @third:  the next char to lookup or zero | 
|  | 9059 | * | 
|  | 9060 | * Try to find if a sequence (first, next, third) or  just (first next) or | 
|  | 9061 | * (first) is available in the input stream. | 
|  | 9062 | * This function has a side effect of (possibly) incrementing ctxt->checkIndex | 
|  | 9063 | * to avoid rescanning sequences of bytes, it DOES change the state of the | 
|  | 9064 | * parser, do not use liberally. | 
|  | 9065 | * | 
|  | 9066 | * Returns the index to the current parsing point if the full sequence | 
|  | 9067 | *      is available, -1 otherwise. | 
|  | 9068 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 9069 | static int | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9070 | xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar first, | 
|  | 9071 | xmlChar next, xmlChar third) { | 
|  | 9072 | int base, len; | 
|  | 9073 | xmlParserInputPtr in; | 
|  | 9074 | const xmlChar *buf; | 
|  | 9075 |  | 
|  | 9076 | in = ctxt->input; | 
|  | 9077 | if (in == NULL) return(-1); | 
|  | 9078 | base = in->cur - in->base; | 
|  | 9079 | if (base < 0) return(-1); | 
|  | 9080 | if (ctxt->checkIndex > base) | 
|  | 9081 | base = ctxt->checkIndex; | 
|  | 9082 | if (in->buf == NULL) { | 
|  | 9083 | buf = in->base; | 
|  | 9084 | len = in->length; | 
|  | 9085 | } else { | 
|  | 9086 | buf = in->buf->buffer->content; | 
|  | 9087 | len = in->buf->buffer->use; | 
|  | 9088 | } | 
|  | 9089 | /* take into account the sequence length */ | 
|  | 9090 | if (third) len -= 2; | 
|  | 9091 | else if (next) len --; | 
|  | 9092 | for (;base < len;base++) { | 
|  | 9093 | if (buf[base] == first) { | 
|  | 9094 | if (third != 0) { | 
|  | 9095 | if ((buf[base + 1] != next) || | 
|  | 9096 | (buf[base + 2] != third)) continue; | 
|  | 9097 | } else if (next != 0) { | 
|  | 9098 | if (buf[base + 1] != next) continue; | 
|  | 9099 | } | 
|  | 9100 | ctxt->checkIndex = 0; | 
|  | 9101 | #ifdef DEBUG_PUSH | 
|  | 9102 | if (next == 0) | 
|  | 9103 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9104 | "PP: lookup '%c' found at %d\n", | 
|  | 9105 | first, base); | 
|  | 9106 | else if (third == 0) | 
|  | 9107 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9108 | "PP: lookup '%c%c' found at %d\n", | 
|  | 9109 | first, next, base); | 
|  | 9110 | else | 
|  | 9111 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9112 | "PP: lookup '%c%c%c' found at %d\n", | 
|  | 9113 | first, next, third, base); | 
|  | 9114 | #endif | 
|  | 9115 | return(base - (in->cur - in->base)); | 
|  | 9116 | } | 
|  | 9117 | } | 
|  | 9118 | ctxt->checkIndex = base; | 
|  | 9119 | #ifdef DEBUG_PUSH | 
|  | 9120 | if (next == 0) | 
|  | 9121 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9122 | "PP: lookup '%c' failed\n", first); | 
|  | 9123 | else if (third == 0) | 
|  | 9124 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9125 | "PP: lookup '%c%c' failed\n", first, next); | 
|  | 9126 | else | 
|  | 9127 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9128 | "PP: lookup '%c%c%c' failed\n", first, next, third); | 
|  | 9129 | #endif | 
|  | 9130 | return(-1); | 
|  | 9131 | } | 
|  | 9132 |  | 
|  | 9133 | /** | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9134 | * xmlParseGetLasts: | 
|  | 9135 | * @ctxt:  an XML parser context | 
|  | 9136 | * @lastlt:  pointer to store the last '<' from the input | 
|  | 9137 | * @lastgt:  pointer to store the last '>' from the input | 
|  | 9138 | * | 
|  | 9139 | * Lookup the last < and > in the current chunk | 
|  | 9140 | */ | 
|  | 9141 | static void | 
|  | 9142 | xmlParseGetLasts(xmlParserCtxtPtr ctxt, const xmlChar **lastlt, | 
|  | 9143 | const xmlChar **lastgt) { | 
|  | 9144 | const xmlChar *tmp; | 
|  | 9145 |  | 
|  | 9146 | if ((ctxt == NULL) || (lastlt == NULL) || (lastgt == NULL)) { | 
|  | 9147 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9148 | "Internal error: xmlParseGetLasts\n"); | 
|  | 9149 | return; | 
|  | 9150 | } | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 9151 | if ((ctxt->progressive != 0) && (ctxt->inputNr == 1)) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9152 | tmp = ctxt->input->end; | 
|  | 9153 | tmp--; | 
| Daniel Veillard | eb70f93 | 2004-07-05 16:46:09 +0000 | [diff] [blame] | 9154 | while ((tmp >= ctxt->input->base) && (*tmp != '<')) tmp--; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9155 | if (tmp < ctxt->input->base) { | 
|  | 9156 | *lastlt = NULL; | 
|  | 9157 | *lastgt = NULL; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9158 | } else { | 
| Daniel Veillard | eb70f93 | 2004-07-05 16:46:09 +0000 | [diff] [blame] | 9159 | *lastlt = tmp; | 
|  | 9160 | tmp++; | 
|  | 9161 | while ((tmp < ctxt->input->end) && (*tmp != '>')) { | 
|  | 9162 | if (*tmp == '\'') { | 
|  | 9163 | tmp++; | 
|  | 9164 | while ((tmp < ctxt->input->end) && (*tmp != '\'')) tmp++; | 
|  | 9165 | if (tmp < ctxt->input->end) tmp++; | 
|  | 9166 | } else if (*tmp == '"') { | 
|  | 9167 | tmp++; | 
|  | 9168 | while ((tmp < ctxt->input->end) && (*tmp != '"')) tmp++; | 
|  | 9169 | if (tmp < ctxt->input->end) tmp++; | 
|  | 9170 | } else | 
|  | 9171 | tmp++; | 
|  | 9172 | } | 
|  | 9173 | if (tmp < ctxt->input->end) | 
|  | 9174 | *lastgt = tmp; | 
|  | 9175 | else { | 
|  | 9176 | tmp = *lastlt; | 
|  | 9177 | tmp--; | 
|  | 9178 | while ((tmp >= ctxt->input->base) && (*tmp != '>')) tmp--; | 
|  | 9179 | if (tmp >= ctxt->input->base) | 
|  | 9180 | *lastgt = tmp; | 
|  | 9181 | else | 
|  | 9182 | *lastgt = NULL; | 
|  | 9183 | } | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9184 | } | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9185 | } else { | 
|  | 9186 | *lastlt = NULL; | 
|  | 9187 | *lastgt = NULL; | 
|  | 9188 | } | 
|  | 9189 | } | 
|  | 9190 | /** | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 9191 | * xmlCheckCdataPush: | 
|  | 9192 | * @cur: pointer to the bock of characters | 
|  | 9193 | * @len: length of the block in bytes | 
|  | 9194 | * | 
|  | 9195 | * Check that the block of characters is okay as SCdata content [20] | 
|  | 9196 | * | 
|  | 9197 | * Returns the number of bytes to pass if okay, a negative index where an | 
|  | 9198 | *         UTF-8 error occured otherwise | 
|  | 9199 | */ | 
|  | 9200 | static int | 
|  | 9201 | xmlCheckCdataPush(const xmlChar *utf, int len) { | 
|  | 9202 | int ix; | 
|  | 9203 | unsigned char c; | 
|  | 9204 | int codepoint; | 
|  | 9205 |  | 
|  | 9206 | if ((utf == NULL) || (len <= 0)) | 
|  | 9207 | return(0); | 
|  | 9208 |  | 
|  | 9209 | for (ix = 0; ix < len;) {      /* string is 0-terminated */ | 
|  | 9210 | c = utf[ix]; | 
|  | 9211 | if ((c & 0x80) == 0x00) {	/* 1-byte code, starts with 10 */ | 
|  | 9212 | if (c >= 0x20) | 
|  | 9213 | ix++; | 
|  | 9214 | else if ((c == 0xA) || (c == 0xD) || (c == 0x9)) | 
|  | 9215 | ix++; | 
|  | 9216 | else | 
|  | 9217 | return(-ix); | 
|  | 9218 | } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */ | 
|  | 9219 | if (ix + 2 > len) return(ix); | 
|  | 9220 | if ((utf[ix+1] & 0xc0 ) != 0x80) | 
|  | 9221 | return(-ix); | 
|  | 9222 | codepoint = (utf[0] & 0x1f) << 6; | 
|  | 9223 | codepoint |= utf[1] & 0x3f; | 
|  | 9224 | if (!xmlIsCharQ(codepoint)) | 
|  | 9225 | return(-ix); | 
|  | 9226 | ix += 2; | 
|  | 9227 | } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */ | 
|  | 9228 | if (ix + 3 > len) return(ix); | 
|  | 9229 | if (((utf[ix+1] & 0xc0) != 0x80) || | 
|  | 9230 | ((utf[ix+2] & 0xc0) != 0x80)) | 
|  | 9231 | return(-ix); | 
|  | 9232 | codepoint = (utf[0] & 0xf) << 12; | 
|  | 9233 | codepoint |= (utf[1] & 0x3f) << 6; | 
|  | 9234 | codepoint |= utf[2] & 0x3f; | 
|  | 9235 | if (!xmlIsCharQ(codepoint)) | 
|  | 9236 | return(-ix); | 
|  | 9237 | ix += 3; | 
|  | 9238 | } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */ | 
|  | 9239 | if (ix + 4 > len) return(ix); | 
|  | 9240 | if (((utf[ix+1] & 0xc0) != 0x80) || | 
|  | 9241 | ((utf[ix+2] & 0xc0) != 0x80) || | 
|  | 9242 | ((utf[ix+3] & 0xc0) != 0x80)) | 
|  | 9243 | return(-ix); | 
|  | 9244 | codepoint = (utf[0] & 0x7) << 18; | 
|  | 9245 | codepoint |= (utf[1] & 0x3f) << 12; | 
|  | 9246 | codepoint |= (utf[2] & 0x3f) << 6; | 
|  | 9247 | codepoint |= utf[3] & 0x3f; | 
|  | 9248 | if (!xmlIsCharQ(codepoint)) | 
|  | 9249 | return(-ix); | 
|  | 9250 | ix += 4; | 
|  | 9251 | } else				/* unknown encoding */ | 
|  | 9252 | return(-ix); | 
|  | 9253 | } | 
|  | 9254 | return(ix); | 
|  | 9255 | } | 
|  | 9256 |  | 
|  | 9257 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9258 | * xmlParseTryOrFinish: | 
|  | 9259 | * @ctxt:  an XML parser context | 
|  | 9260 | * @terminate:  last chunk indicator | 
|  | 9261 | * | 
|  | 9262 | * Try to progress on parsing | 
|  | 9263 | * | 
|  | 9264 | * Returns zero if no parsing was possible | 
|  | 9265 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 9266 | static int | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9267 | xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { | 
|  | 9268 | int ret = 0; | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 9269 | int avail, tlen; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9270 | xmlChar cur, next; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9271 | const xmlChar *lastlt, *lastgt; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9272 |  | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 9273 | if (ctxt->input == NULL) | 
|  | 9274 | return(0); | 
|  | 9275 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9276 | #ifdef DEBUG_PUSH | 
|  | 9277 | switch (ctxt->instate) { | 
|  | 9278 | case XML_PARSER_EOF: | 
|  | 9279 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9280 | "PP: try EOF\n"); break; | 
|  | 9281 | case XML_PARSER_START: | 
|  | 9282 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9283 | "PP: try START\n"); break; | 
|  | 9284 | case XML_PARSER_MISC: | 
|  | 9285 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9286 | "PP: try MISC\n");break; | 
|  | 9287 | case XML_PARSER_COMMENT: | 
|  | 9288 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9289 | "PP: try COMMENT\n");break; | 
|  | 9290 | case XML_PARSER_PROLOG: | 
|  | 9291 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9292 | "PP: try PROLOG\n");break; | 
|  | 9293 | case XML_PARSER_START_TAG: | 
|  | 9294 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9295 | "PP: try START_TAG\n");break; | 
|  | 9296 | case XML_PARSER_CONTENT: | 
|  | 9297 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9298 | "PP: try CONTENT\n");break; | 
|  | 9299 | case XML_PARSER_CDATA_SECTION: | 
|  | 9300 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9301 | "PP: try CDATA_SECTION\n");break; | 
|  | 9302 | case XML_PARSER_END_TAG: | 
|  | 9303 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9304 | "PP: try END_TAG\n");break; | 
|  | 9305 | case XML_PARSER_ENTITY_DECL: | 
|  | 9306 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9307 | "PP: try ENTITY_DECL\n");break; | 
|  | 9308 | case XML_PARSER_ENTITY_VALUE: | 
|  | 9309 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9310 | "PP: try ENTITY_VALUE\n");break; | 
|  | 9311 | case XML_PARSER_ATTRIBUTE_VALUE: | 
|  | 9312 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9313 | "PP: try ATTRIBUTE_VALUE\n");break; | 
|  | 9314 | case XML_PARSER_DTD: | 
|  | 9315 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9316 | "PP: try DTD\n");break; | 
|  | 9317 | case XML_PARSER_EPILOG: | 
|  | 9318 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9319 | "PP: try EPILOG\n");break; | 
|  | 9320 | case XML_PARSER_PI: | 
|  | 9321 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9322 | "PP: try PI\n");break; | 
|  | 9323 | case XML_PARSER_IGNORE: | 
|  | 9324 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9325 | "PP: try IGNORE\n");break; | 
|  | 9326 | } | 
|  | 9327 | #endif | 
|  | 9328 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 9329 | if ((ctxt->input != NULL) && | 
|  | 9330 | (ctxt->input->cur - ctxt->input->base > 4096)) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9331 | xmlSHRINK(ctxt); | 
|  | 9332 | ctxt->checkIndex = 0; | 
|  | 9333 | } | 
|  | 9334 | xmlParseGetLasts(ctxt, &lastlt, &lastgt); | 
| Aleksey Sanin | e48a318 | 2002-05-09 18:20:01 +0000 | [diff] [blame] | 9335 |  | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9336 | while (1) { | 
| Daniel Veillard | 1441251 | 2005-01-21 23:53:26 +0000 | [diff] [blame] | 9337 | if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 9338 | return(0); | 
|  | 9339 |  | 
|  | 9340 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9341 | /* | 
|  | 9342 | * Pop-up of finished entities. | 
|  | 9343 | */ | 
|  | 9344 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 9345 | xmlPopInput(ctxt); | 
|  | 9346 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 9347 | if (ctxt->input == NULL) break; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9348 | if (ctxt->input->buf == NULL) | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9349 | avail = ctxt->input->length - | 
|  | 9350 | (ctxt->input->cur - ctxt->input->base); | 
| Daniel Veillard | 158a4d2 | 2002-02-20 22:17:58 +0000 | [diff] [blame] | 9351 | else { | 
|  | 9352 | /* | 
|  | 9353 | * If we are operating on converted input, try to flush | 
|  | 9354 | * remainng chars to avoid them stalling in the non-converted | 
|  | 9355 | * buffer. | 
|  | 9356 | */ | 
|  | 9357 | if ((ctxt->input->buf->raw != NULL) && | 
|  | 9358 | (ctxt->input->buf->raw->use > 0)) { | 
|  | 9359 | int base = ctxt->input->base - | 
|  | 9360 | ctxt->input->buf->buffer->content; | 
|  | 9361 | int current = ctxt->input->cur - ctxt->input->base; | 
|  | 9362 |  | 
|  | 9363 | xmlParserInputBufferPush(ctxt->input->buf, 0, ""); | 
|  | 9364 | ctxt->input->base = ctxt->input->buf->buffer->content + base; | 
|  | 9365 | ctxt->input->cur = ctxt->input->base + current; | 
|  | 9366 | ctxt->input->end = | 
|  | 9367 | &ctxt->input->buf->buffer->content[ | 
|  | 9368 | ctxt->input->buf->buffer->use]; | 
|  | 9369 | } | 
|  | 9370 | avail = ctxt->input->buf->buffer->use - | 
|  | 9371 | (ctxt->input->cur - ctxt->input->base); | 
|  | 9372 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9373 | if (avail < 1) | 
|  | 9374 | goto done; | 
|  | 9375 | switch (ctxt->instate) { | 
|  | 9376 | case XML_PARSER_EOF: | 
|  | 9377 | /* | 
|  | 9378 | * Document parsing is done ! | 
|  | 9379 | */ | 
|  | 9380 | goto done; | 
|  | 9381 | case XML_PARSER_START: | 
| Daniel Veillard | 0e4cd17 | 2001-06-28 12:13:56 +0000 | [diff] [blame] | 9382 | if (ctxt->charset == XML_CHAR_ENCODING_NONE) { | 
|  | 9383 | xmlChar start[4]; | 
|  | 9384 | xmlCharEncoding enc; | 
|  | 9385 |  | 
|  | 9386 | /* | 
|  | 9387 | * Very first chars read from the document flow. | 
|  | 9388 | */ | 
|  | 9389 | if (avail < 4) | 
|  | 9390 | goto done; | 
|  | 9391 |  | 
|  | 9392 | /* | 
|  | 9393 | * Get the 4 first bytes and decode the charset | 
|  | 9394 | * if enc != XML_CHAR_ENCODING_NONE | 
| William M. Brack | 3a1cd21 | 2005-02-11 14:35:54 +0000 | [diff] [blame] | 9395 | * plug some encoding conversion routines, | 
|  | 9396 | * else xmlSwitchEncoding will set to (default) | 
|  | 9397 | * UTF8. | 
| Daniel Veillard | 0e4cd17 | 2001-06-28 12:13:56 +0000 | [diff] [blame] | 9398 | */ | 
|  | 9399 | start[0] = RAW; | 
|  | 9400 | start[1] = NXT(1); | 
|  | 9401 | start[2] = NXT(2); | 
|  | 9402 | start[3] = NXT(3); | 
|  | 9403 | enc = xmlDetectCharEncoding(start, 4); | 
| William M. Brack | 3a1cd21 | 2005-02-11 14:35:54 +0000 | [diff] [blame] | 9404 | xmlSwitchEncoding(ctxt, enc); | 
| Daniel Veillard | 0e4cd17 | 2001-06-28 12:13:56 +0000 | [diff] [blame] | 9405 | break; | 
|  | 9406 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9407 |  | 
| Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 9408 | if (avail < 2) | 
|  | 9409 | goto done; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9410 | cur = ctxt->input->cur[0]; | 
|  | 9411 | next = ctxt->input->cur[1]; | 
|  | 9412 | if (cur == 0) { | 
|  | 9413 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) | 
|  | 9414 | ctxt->sax->setDocumentLocator(ctxt->userData, | 
|  | 9415 | &xmlDefaultSAXLocator); | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 9416 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9417 | ctxt->instate = XML_PARSER_EOF; | 
|  | 9418 | #ifdef DEBUG_PUSH | 
|  | 9419 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9420 | "PP: entering EOF\n"); | 
|  | 9421 | #endif | 
|  | 9422 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
|  | 9423 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 9424 | goto done; | 
|  | 9425 | } | 
|  | 9426 | if ((cur == '<') && (next == '?')) { | 
|  | 9427 | /* PI or XML decl */ | 
|  | 9428 | if (avail < 5) return(ret); | 
|  | 9429 | if ((!terminate) && | 
|  | 9430 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) | 
|  | 9431 | return(ret); | 
|  | 9432 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) | 
|  | 9433 | ctxt->sax->setDocumentLocator(ctxt->userData, | 
|  | 9434 | &xmlDefaultSAXLocator); | 
|  | 9435 | if ((ctxt->input->cur[2] == 'x') && | 
|  | 9436 | (ctxt->input->cur[3] == 'm') && | 
|  | 9437 | (ctxt->input->cur[4] == 'l') && | 
| William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 9438 | (IS_BLANK_CH(ctxt->input->cur[5]))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9439 | ret += 5; | 
|  | 9440 | #ifdef DEBUG_PUSH | 
|  | 9441 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9442 | "PP: Parsing XML Decl\n"); | 
|  | 9443 | #endif | 
|  | 9444 | xmlParseXMLDecl(ctxt); | 
|  | 9445 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { | 
|  | 9446 | /* | 
|  | 9447 | * The XML REC instructs us to stop parsing right | 
|  | 9448 | * here | 
|  | 9449 | */ | 
|  | 9450 | ctxt->instate = XML_PARSER_EOF; | 
|  | 9451 | return(0); | 
|  | 9452 | } | 
|  | 9453 | ctxt->standalone = ctxt->input->standalone; | 
|  | 9454 | if ((ctxt->encoding == NULL) && | 
|  | 9455 | (ctxt->input->encoding != NULL)) | 
|  | 9456 | ctxt->encoding = xmlStrdup(ctxt->input->encoding); | 
|  | 9457 | if ((ctxt->sax) && (ctxt->sax->startDocument) && | 
|  | 9458 | (!ctxt->disableSAX)) | 
|  | 9459 | ctxt->sax->startDocument(ctxt->userData); | 
|  | 9460 | ctxt->instate = XML_PARSER_MISC; | 
|  | 9461 | #ifdef DEBUG_PUSH | 
|  | 9462 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9463 | "PP: entering MISC\n"); | 
|  | 9464 | #endif | 
|  | 9465 | } else { | 
|  | 9466 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); | 
|  | 9467 | if ((ctxt->sax) && (ctxt->sax->startDocument) && | 
|  | 9468 | (!ctxt->disableSAX)) | 
|  | 9469 | ctxt->sax->startDocument(ctxt->userData); | 
|  | 9470 | ctxt->instate = XML_PARSER_MISC; | 
|  | 9471 | #ifdef DEBUG_PUSH | 
|  | 9472 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9473 | "PP: entering MISC\n"); | 
|  | 9474 | #endif | 
|  | 9475 | } | 
|  | 9476 | } else { | 
|  | 9477 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) | 
|  | 9478 | ctxt->sax->setDocumentLocator(ctxt->userData, | 
|  | 9479 | &xmlDefaultSAXLocator); | 
|  | 9480 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 9481 | if (ctxt->version == NULL) { | 
|  | 9482 | xmlErrMemory(ctxt, NULL); | 
|  | 9483 | break; | 
|  | 9484 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9485 | if ((ctxt->sax) && (ctxt->sax->startDocument) && | 
|  | 9486 | (!ctxt->disableSAX)) | 
|  | 9487 | ctxt->sax->startDocument(ctxt->userData); | 
|  | 9488 | ctxt->instate = XML_PARSER_MISC; | 
|  | 9489 | #ifdef DEBUG_PUSH | 
|  | 9490 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9491 | "PP: entering MISC\n"); | 
|  | 9492 | #endif | 
|  | 9493 | } | 
|  | 9494 | break; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9495 | case XML_PARSER_START_TAG: { | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9496 | const xmlChar *name; | 
|  | 9497 | const xmlChar *prefix; | 
|  | 9498 | const xmlChar *URI; | 
|  | 9499 | int nsNr = ctxt->nsNr; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9500 |  | 
|  | 9501 | if ((avail < 2) && (ctxt->inputNr == 1)) | 
|  | 9502 | goto done; | 
|  | 9503 | cur = ctxt->input->cur[0]; | 
|  | 9504 | if (cur != '<') { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 9505 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9506 | ctxt->instate = XML_PARSER_EOF; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9507 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
|  | 9508 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 9509 | goto done; | 
|  | 9510 | } | 
|  | 9511 | if (!terminate) { | 
|  | 9512 | if (ctxt->progressive) { | 
| Daniel Veillard | b374400 | 2004-02-18 14:28:22 +0000 | [diff] [blame] | 9513 | /* > can be found unescaped in attribute values */ | 
| Daniel Veillard | eb70f93 | 2004-07-05 16:46:09 +0000 | [diff] [blame] | 9514 | if ((lastgt == NULL) || (ctxt->input->cur >= lastgt)) | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9515 | goto done; | 
|  | 9516 | } else if (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0) { | 
|  | 9517 | goto done; | 
|  | 9518 | } | 
|  | 9519 | } | 
|  | 9520 | if (ctxt->spaceNr == 0) | 
|  | 9521 | spacePush(ctxt, -1); | 
|  | 9522 | else | 
|  | 9523 | spacePush(ctxt, *ctxt->space); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9524 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9525 | if (ctxt->sax2) | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9526 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 9527 | name = xmlParseStartTag2(ctxt, &prefix, &URI, &tlen); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9528 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9529 | else | 
|  | 9530 | name = xmlParseStartTag(ctxt); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9531 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9532 | if (name == NULL) { | 
|  | 9533 | spacePop(ctxt); | 
|  | 9534 | ctxt->instate = XML_PARSER_EOF; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9535 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
|  | 9536 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 9537 | goto done; | 
|  | 9538 | } | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 9539 | #ifdef LIBXML_VALID_ENABLED | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9540 | /* | 
|  | 9541 | * [ VC: Root Element Type ] | 
|  | 9542 | * The Name in the document type declaration must match | 
|  | 9543 | * the element type of the root element. | 
|  | 9544 | */ | 
|  | 9545 | if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && | 
|  | 9546 | ctxt->node && (ctxt->node == ctxt->myDoc->children)) | 
|  | 9547 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 9548 | #endif /* LIBXML_VALID_ENABLED */ | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9549 |  | 
|  | 9550 | /* | 
|  | 9551 | * Check for an Empty Element. | 
|  | 9552 | */ | 
|  | 9553 | if ((RAW == '/') && (NXT(1) == '>')) { | 
|  | 9554 | SKIP(2); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9555 |  | 
|  | 9556 | if (ctxt->sax2) { | 
|  | 9557 | if ((ctxt->sax != NULL) && | 
|  | 9558 | (ctxt->sax->endElementNs != NULL) && | 
|  | 9559 | (!ctxt->disableSAX)) | 
|  | 9560 | ctxt->sax->endElementNs(ctxt->userData, name, | 
|  | 9561 | prefix, URI); | 
| Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 9562 | if (ctxt->nsNr - nsNr > 0) | 
|  | 9563 | nsPop(ctxt, ctxt->nsNr - nsNr); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9564 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9565 | } else { | 
|  | 9566 | if ((ctxt->sax != NULL) && | 
|  | 9567 | (ctxt->sax->endElement != NULL) && | 
|  | 9568 | (!ctxt->disableSAX)) | 
|  | 9569 | ctxt->sax->endElement(ctxt->userData, name); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9570 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9571 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9572 | spacePop(ctxt); | 
|  | 9573 | if (ctxt->nameNr == 0) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9574 | ctxt->instate = XML_PARSER_EPILOG; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9575 | } else { | 
|  | 9576 | ctxt->instate = XML_PARSER_CONTENT; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9577 | } | 
|  | 9578 | break; | 
|  | 9579 | } | 
|  | 9580 | if (RAW == '>') { | 
|  | 9581 | NEXT; | 
|  | 9582 | } else { | 
| Daniel Veillard | bc92eca | 2003-09-15 09:48:06 +0000 | [diff] [blame] | 9583 | xmlFatalErrMsgStr(ctxt, XML_ERR_GT_REQUIRED, | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9584 | "Couldn't find end of Start Tag %s\n", | 
|  | 9585 | name); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9586 | nodePop(ctxt); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9587 | spacePop(ctxt); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9588 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9589 | if (ctxt->sax2) | 
|  | 9590 | nameNsPush(ctxt, name, prefix, URI, ctxt->nsNr - nsNr); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9591 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9592 | else | 
|  | 9593 | namePush(ctxt, name); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9594 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9595 |  | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9596 | ctxt->instate = XML_PARSER_CONTENT; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9597 | break; | 
|  | 9598 | } | 
|  | 9599 | case XML_PARSER_CONTENT: { | 
|  | 9600 | const xmlChar *test; | 
|  | 9601 | unsigned int cons; | 
|  | 9602 | if ((avail < 2) && (ctxt->inputNr == 1)) | 
|  | 9603 | goto done; | 
|  | 9604 | cur = ctxt->input->cur[0]; | 
|  | 9605 | next = ctxt->input->cur[1]; | 
|  | 9606 |  | 
|  | 9607 | test = CUR_PTR; | 
|  | 9608 | cons = ctxt->input->consumed; | 
|  | 9609 | if ((cur == '<') && (next == '/')) { | 
|  | 9610 | ctxt->instate = XML_PARSER_END_TAG; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9611 | break; | 
|  | 9612 | } else if ((cur == '<') && (next == '?')) { | 
|  | 9613 | if ((!terminate) && | 
|  | 9614 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) | 
|  | 9615 | goto done; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9616 | xmlParsePI(ctxt); | 
|  | 9617 | } else if ((cur == '<') && (next != '!')) { | 
|  | 9618 | ctxt->instate = XML_PARSER_START_TAG; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9619 | break; | 
|  | 9620 | } else if ((cur == '<') && (next == '!') && | 
|  | 9621 | (ctxt->input->cur[2] == '-') && | 
|  | 9622 | (ctxt->input->cur[3] == '-')) { | 
|  | 9623 | if ((!terminate) && | 
|  | 9624 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) | 
|  | 9625 | goto done; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9626 | xmlParseComment(ctxt); | 
|  | 9627 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 9628 | } else if ((cur == '<') && (ctxt->input->cur[1] == '!') && | 
|  | 9629 | (ctxt->input->cur[2] == '[') && | 
|  | 9630 | (ctxt->input->cur[3] == 'C') && | 
|  | 9631 | (ctxt->input->cur[4] == 'D') && | 
|  | 9632 | (ctxt->input->cur[5] == 'A') && | 
|  | 9633 | (ctxt->input->cur[6] == 'T') && | 
|  | 9634 | (ctxt->input->cur[7] == 'A') && | 
|  | 9635 | (ctxt->input->cur[8] == '[')) { | 
|  | 9636 | SKIP(9); | 
|  | 9637 | ctxt->instate = XML_PARSER_CDATA_SECTION; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9638 | break; | 
|  | 9639 | } else if ((cur == '<') && (next == '!') && | 
|  | 9640 | (avail < 9)) { | 
|  | 9641 | goto done; | 
|  | 9642 | } else if (cur == '&') { | 
|  | 9643 | if ((!terminate) && | 
|  | 9644 | (xmlParseLookupSequence(ctxt, ';', 0, 0) < 0)) | 
|  | 9645 | goto done; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9646 | xmlParseReference(ctxt); | 
|  | 9647 | } else { | 
|  | 9648 | /* TODO Avoid the extra copy, handle directly !!! */ | 
|  | 9649 | /* | 
|  | 9650 | * Goal of the following test is: | 
|  | 9651 | *  - minimize calls to the SAX 'character' callback | 
|  | 9652 | *    when they are mergeable | 
|  | 9653 | *  - handle an problem for isBlank when we only parse | 
|  | 9654 | *    a sequence of blank chars and the next one is | 
|  | 9655 | *    not available to check against '<' presence. | 
|  | 9656 | *  - tries to homogenize the differences in SAX | 
|  | 9657 | *    callbacks between the push and pull versions | 
|  | 9658 | *    of the parser. | 
|  | 9659 | */ | 
|  | 9660 | if ((ctxt->inputNr == 1) && | 
|  | 9661 | (avail < XML_PARSER_BIG_BUFFER_SIZE)) { | 
|  | 9662 | if (!terminate) { | 
|  | 9663 | if (ctxt->progressive) { | 
|  | 9664 | if ((lastlt == NULL) || | 
|  | 9665 | (ctxt->input->cur > lastlt)) | 
|  | 9666 | goto done; | 
|  | 9667 | } else if (xmlParseLookupSequence(ctxt, | 
|  | 9668 | '<', 0, 0) < 0) { | 
|  | 9669 | goto done; | 
|  | 9670 | } | 
|  | 9671 | } | 
|  | 9672 | } | 
|  | 9673 | ctxt->checkIndex = 0; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9674 | xmlParseCharData(ctxt, 0); | 
|  | 9675 | } | 
|  | 9676 | /* | 
|  | 9677 | * Pop-up of finished entities. | 
|  | 9678 | */ | 
|  | 9679 | while ((RAW == 0) && (ctxt->inputNr > 1)) | 
|  | 9680 | xmlPopInput(ctxt); | 
|  | 9681 | if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 9682 | xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, | 
|  | 9683 | "detected an error in element content\n"); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9684 | ctxt->instate = XML_PARSER_EOF; | 
|  | 9685 | break; | 
|  | 9686 | } | 
|  | 9687 | break; | 
|  | 9688 | } | 
|  | 9689 | case XML_PARSER_END_TAG: | 
|  | 9690 | if (avail < 2) | 
|  | 9691 | goto done; | 
|  | 9692 | if (!terminate) { | 
|  | 9693 | if (ctxt->progressive) { | 
| Daniel Veillard | eb70f93 | 2004-07-05 16:46:09 +0000 | [diff] [blame] | 9694 | /* > can be found unescaped in attribute values */ | 
|  | 9695 | if ((lastgt == NULL) || (ctxt->input->cur >= lastgt)) | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9696 | goto done; | 
|  | 9697 | } else if (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0) { | 
|  | 9698 | goto done; | 
|  | 9699 | } | 
|  | 9700 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9701 | if (ctxt->sax2) { | 
|  | 9702 | xmlParseEndTag2(ctxt, | 
|  | 9703 | (void *) ctxt->pushTab[ctxt->nameNr * 3 - 3], | 
|  | 9704 | (void *) ctxt->pushTab[ctxt->nameNr * 3 - 2], 0, | 
| Daniel Veillard | c82c57e | 2004-01-12 16:24:34 +0000 | [diff] [blame] | 9705 | (int) (long) ctxt->pushTab[ctxt->nameNr * 3 - 1], 0); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9706 | nameNsPop(ctxt); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9707 | } | 
|  | 9708 | #ifdef LIBXML_SAX1_ENABLED | 
|  | 9709 | else | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9710 | xmlParseEndTag1(ctxt, 0); | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 9711 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 9712 | if (ctxt->nameNr == 0) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9713 | ctxt->instate = XML_PARSER_EPILOG; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9714 | } else { | 
|  | 9715 | ctxt->instate = XML_PARSER_CONTENT; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9716 | } | 
|  | 9717 | break; | 
|  | 9718 | case XML_PARSER_CDATA_SECTION: { | 
|  | 9719 | /* | 
|  | 9720 | * The Push mode need to have the SAX callback for | 
|  | 9721 | * cdataBlock merge back contiguous callbacks. | 
|  | 9722 | */ | 
|  | 9723 | int base; | 
|  | 9724 |  | 
|  | 9725 | base = xmlParseLookupSequence(ctxt, ']', ']', '>'); | 
|  | 9726 | if (base < 0) { | 
|  | 9727 | if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) { | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 9728 | int tmp; | 
|  | 9729 |  | 
|  | 9730 | tmp = xmlCheckCdataPush(ctxt->input->cur, | 
|  | 9731 | XML_PARSER_BIG_BUFFER_SIZE); | 
|  | 9732 | if (tmp < 0) { | 
|  | 9733 | tmp = -tmp; | 
|  | 9734 | ctxt->input->cur += tmp; | 
|  | 9735 | goto encoding_error; | 
|  | 9736 | } | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9737 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { | 
|  | 9738 | if (ctxt->sax->cdataBlock != NULL) | 
| Daniel Veillard | d9d32ae | 2003-07-05 20:32:43 +0000 | [diff] [blame] | 9739 | ctxt->sax->cdataBlock(ctxt->userData, | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 9740 | ctxt->input->cur, tmp); | 
| Daniel Veillard | d9d32ae | 2003-07-05 20:32:43 +0000 | [diff] [blame] | 9741 | else if (ctxt->sax->characters != NULL) | 
|  | 9742 | ctxt->sax->characters(ctxt->userData, | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 9743 | ctxt->input->cur, tmp); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9744 | } | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 9745 | SKIPL(tmp); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9746 | ctxt->checkIndex = 0; | 
|  | 9747 | } | 
|  | 9748 | goto done; | 
|  | 9749 | } else { | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 9750 | int tmp; | 
|  | 9751 |  | 
|  | 9752 | tmp = xmlCheckCdataPush(ctxt->input->cur, base); | 
|  | 9753 | if ((tmp < 0) || (tmp != base)) { | 
|  | 9754 | tmp = -tmp; | 
|  | 9755 | ctxt->input->cur += tmp; | 
|  | 9756 | goto encoding_error; | 
|  | 9757 | } | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9758 | if ((ctxt->sax != NULL) && (base > 0) && | 
|  | 9759 | (!ctxt->disableSAX)) { | 
|  | 9760 | if (ctxt->sax->cdataBlock != NULL) | 
|  | 9761 | ctxt->sax->cdataBlock(ctxt->userData, | 
|  | 9762 | ctxt->input->cur, base); | 
| Daniel Veillard | d9d32ae | 2003-07-05 20:32:43 +0000 | [diff] [blame] | 9763 | else if (ctxt->sax->characters != NULL) | 
|  | 9764 | ctxt->sax->characters(ctxt->userData, | 
|  | 9765 | ctxt->input->cur, base); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9766 | } | 
| Daniel Veillard | 0b787f3 | 2004-03-26 17:29:53 +0000 | [diff] [blame] | 9767 | SKIPL(base + 3); | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9768 | ctxt->checkIndex = 0; | 
|  | 9769 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 9770 | #ifdef DEBUG_PUSH | 
|  | 9771 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9772 | "PP: entering CONTENT\n"); | 
|  | 9773 | #endif | 
|  | 9774 | } | 
|  | 9775 | break; | 
|  | 9776 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9777 | case XML_PARSER_MISC: | 
|  | 9778 | SKIP_BLANKS; | 
|  | 9779 | if (ctxt->input->buf == NULL) | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9780 | avail = ctxt->input->length - | 
|  | 9781 | (ctxt->input->cur - ctxt->input->base); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9782 | else | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9783 | avail = ctxt->input->buf->buffer->use - | 
|  | 9784 | (ctxt->input->cur - ctxt->input->base); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9785 | if (avail < 2) | 
|  | 9786 | goto done; | 
|  | 9787 | cur = ctxt->input->cur[0]; | 
|  | 9788 | next = ctxt->input->cur[1]; | 
|  | 9789 | if ((cur == '<') && (next == '?')) { | 
|  | 9790 | if ((!terminate) && | 
|  | 9791 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) | 
|  | 9792 | goto done; | 
|  | 9793 | #ifdef DEBUG_PUSH | 
|  | 9794 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9795 | "PP: Parsing PI\n"); | 
|  | 9796 | #endif | 
|  | 9797 | xmlParsePI(ctxt); | 
|  | 9798 | } else if ((cur == '<') && (next == '!') && | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9799 | (ctxt->input->cur[2] == '-') && | 
|  | 9800 | (ctxt->input->cur[3] == '-')) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9801 | if ((!terminate) && | 
|  | 9802 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) | 
|  | 9803 | goto done; | 
|  | 9804 | #ifdef DEBUG_PUSH | 
|  | 9805 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9806 | "PP: Parsing Comment\n"); | 
|  | 9807 | #endif | 
|  | 9808 | xmlParseComment(ctxt); | 
|  | 9809 | ctxt->instate = XML_PARSER_MISC; | 
|  | 9810 | } else if ((cur == '<') && (next == '!') && | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9811 | (ctxt->input->cur[2] == 'D') && | 
|  | 9812 | (ctxt->input->cur[3] == 'O') && | 
|  | 9813 | (ctxt->input->cur[4] == 'C') && | 
|  | 9814 | (ctxt->input->cur[5] == 'T') && | 
|  | 9815 | (ctxt->input->cur[6] == 'Y') && | 
|  | 9816 | (ctxt->input->cur[7] == 'P') && | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9817 | (ctxt->input->cur[8] == 'E')) { | 
|  | 9818 | if ((!terminate) && | 
|  | 9819 | (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) | 
|  | 9820 | goto done; | 
|  | 9821 | #ifdef DEBUG_PUSH | 
|  | 9822 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9823 | "PP: Parsing internal subset\n"); | 
|  | 9824 | #endif | 
|  | 9825 | ctxt->inSubset = 1; | 
|  | 9826 | xmlParseDocTypeDecl(ctxt); | 
|  | 9827 | if (RAW == '[') { | 
|  | 9828 | ctxt->instate = XML_PARSER_DTD; | 
|  | 9829 | #ifdef DEBUG_PUSH | 
|  | 9830 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9831 | "PP: entering DTD\n"); | 
|  | 9832 | #endif | 
|  | 9833 | } else { | 
|  | 9834 | /* | 
|  | 9835 | * Create and update the external subset. | 
|  | 9836 | */ | 
|  | 9837 | ctxt->inSubset = 2; | 
|  | 9838 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && | 
|  | 9839 | (ctxt->sax->externalSubset != NULL)) | 
|  | 9840 | ctxt->sax->externalSubset(ctxt->userData, | 
|  | 9841 | ctxt->intSubName, ctxt->extSubSystem, | 
|  | 9842 | ctxt->extSubURI); | 
|  | 9843 | ctxt->inSubset = 0; | 
|  | 9844 | ctxt->instate = XML_PARSER_PROLOG; | 
|  | 9845 | #ifdef DEBUG_PUSH | 
|  | 9846 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9847 | "PP: entering PROLOG\n"); | 
|  | 9848 | #endif | 
|  | 9849 | } | 
|  | 9850 | } else if ((cur == '<') && (next == '!') && | 
|  | 9851 | (avail < 9)) { | 
|  | 9852 | goto done; | 
|  | 9853 | } else { | 
|  | 9854 | ctxt->instate = XML_PARSER_START_TAG; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9855 | ctxt->progressive = 1; | 
|  | 9856 | xmlParseGetLasts(ctxt, &lastlt, &lastgt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9857 | #ifdef DEBUG_PUSH | 
|  | 9858 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9859 | "PP: entering START_TAG\n"); | 
|  | 9860 | #endif | 
|  | 9861 | } | 
|  | 9862 | break; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9863 | case XML_PARSER_PROLOG: | 
|  | 9864 | SKIP_BLANKS; | 
|  | 9865 | if (ctxt->input->buf == NULL) | 
|  | 9866 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); | 
|  | 9867 | else | 
|  | 9868 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); | 
|  | 9869 | if (avail < 2) | 
|  | 9870 | goto done; | 
|  | 9871 | cur = ctxt->input->cur[0]; | 
|  | 9872 | next = ctxt->input->cur[1]; | 
|  | 9873 | if ((cur == '<') && (next == '?')) { | 
|  | 9874 | if ((!terminate) && | 
|  | 9875 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) | 
|  | 9876 | goto done; | 
|  | 9877 | #ifdef DEBUG_PUSH | 
|  | 9878 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9879 | "PP: Parsing PI\n"); | 
|  | 9880 | #endif | 
|  | 9881 | xmlParsePI(ctxt); | 
|  | 9882 | } else if ((cur == '<') && (next == '!') && | 
|  | 9883 | (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { | 
|  | 9884 | if ((!terminate) && | 
|  | 9885 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) | 
|  | 9886 | goto done; | 
|  | 9887 | #ifdef DEBUG_PUSH | 
|  | 9888 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9889 | "PP: Parsing Comment\n"); | 
|  | 9890 | #endif | 
|  | 9891 | xmlParseComment(ctxt); | 
|  | 9892 | ctxt->instate = XML_PARSER_PROLOG; | 
|  | 9893 | } else if ((cur == '<') && (next == '!') && | 
|  | 9894 | (avail < 4)) { | 
|  | 9895 | goto done; | 
|  | 9896 | } else { | 
|  | 9897 | ctxt->instate = XML_PARSER_START_TAG; | 
| Daniel Veillard | 0df3bc3 | 2004-06-08 12:03:41 +0000 | [diff] [blame] | 9898 | if (ctxt->progressive == 0) | 
|  | 9899 | ctxt->progressive = 1; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 9900 | xmlParseGetLasts(ctxt, &lastlt, &lastgt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9901 | #ifdef DEBUG_PUSH | 
|  | 9902 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9903 | "PP: entering START_TAG\n"); | 
|  | 9904 | #endif | 
|  | 9905 | } | 
|  | 9906 | break; | 
|  | 9907 | case XML_PARSER_EPILOG: | 
|  | 9908 | SKIP_BLANKS; | 
|  | 9909 | if (ctxt->input->buf == NULL) | 
|  | 9910 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); | 
|  | 9911 | else | 
|  | 9912 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); | 
|  | 9913 | if (avail < 2) | 
|  | 9914 | goto done; | 
|  | 9915 | cur = ctxt->input->cur[0]; | 
|  | 9916 | next = ctxt->input->cur[1]; | 
|  | 9917 | if ((cur == '<') && (next == '?')) { | 
|  | 9918 | if ((!terminate) && | 
|  | 9919 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) | 
|  | 9920 | goto done; | 
|  | 9921 | #ifdef DEBUG_PUSH | 
|  | 9922 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9923 | "PP: Parsing PI\n"); | 
|  | 9924 | #endif | 
|  | 9925 | xmlParsePI(ctxt); | 
|  | 9926 | ctxt->instate = XML_PARSER_EPILOG; | 
|  | 9927 | } else if ((cur == '<') && (next == '!') && | 
|  | 9928 | (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { | 
|  | 9929 | if ((!terminate) && | 
|  | 9930 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) | 
|  | 9931 | goto done; | 
|  | 9932 | #ifdef DEBUG_PUSH | 
|  | 9933 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9934 | "PP: Parsing Comment\n"); | 
|  | 9935 | #endif | 
|  | 9936 | xmlParseComment(ctxt); | 
|  | 9937 | ctxt->instate = XML_PARSER_EPILOG; | 
|  | 9938 | } else if ((cur == '<') && (next == '!') && | 
|  | 9939 | (avail < 4)) { | 
|  | 9940 | goto done; | 
|  | 9941 | } else { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 9942 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9943 | ctxt->instate = XML_PARSER_EOF; | 
|  | 9944 | #ifdef DEBUG_PUSH | 
|  | 9945 | xmlGenericError(xmlGenericErrorContext, | 
|  | 9946 | "PP: entering EOF\n"); | 
|  | 9947 | #endif | 
| Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 9948 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9949 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 9950 | goto done; | 
|  | 9951 | } | 
|  | 9952 | break; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9953 | case XML_PARSER_DTD: { | 
|  | 9954 | /* | 
|  | 9955 | * Sorry but progressive parsing of the internal subset | 
|  | 9956 | * is not expected to be supported. We first check that | 
|  | 9957 | * the full content of the internal subset is available and | 
|  | 9958 | * the parsing is launched only at that point. | 
|  | 9959 | * Internal subset ends up with "']' S? '>'" in an unescaped | 
|  | 9960 | * section and not in a ']]>' sequence which are conditional | 
|  | 9961 | * sections (whoever argued to keep that crap in XML deserve | 
|  | 9962 | * a place in hell !). | 
|  | 9963 | */ | 
|  | 9964 | int base, i; | 
|  | 9965 | xmlChar *buf; | 
|  | 9966 | xmlChar quote = 0; | 
|  | 9967 |  | 
|  | 9968 | base = ctxt->input->cur - ctxt->input->base; | 
|  | 9969 | if (base < 0) return(0); | 
|  | 9970 | if (ctxt->checkIndex > base) | 
|  | 9971 | base = ctxt->checkIndex; | 
|  | 9972 | buf = ctxt->input->buf->buffer->content; | 
|  | 9973 | for (;(unsigned int) base < ctxt->input->buf->buffer->use; | 
|  | 9974 | base++) { | 
|  | 9975 | if (quote != 0) { | 
|  | 9976 | if (buf[base] == quote) | 
|  | 9977 | quote = 0; | 
|  | 9978 | continue; | 
|  | 9979 | } | 
| Daniel Veillard | 036143b | 2004-02-12 11:57:52 +0000 | [diff] [blame] | 9980 | if ((quote == 0) && (buf[base] == '<')) { | 
|  | 9981 | int found  = 0; | 
|  | 9982 | /* special handling of comments */ | 
|  | 9983 | if (((unsigned int) base + 4 < | 
|  | 9984 | ctxt->input->buf->buffer->use) && | 
|  | 9985 | (buf[base + 1] == '!') && | 
|  | 9986 | (buf[base + 2] == '-') && | 
|  | 9987 | (buf[base + 3] == '-')) { | 
|  | 9988 | for (;(unsigned int) base + 3 < | 
|  | 9989 | ctxt->input->buf->buffer->use; base++) { | 
|  | 9990 | if ((buf[base] == '-') && | 
|  | 9991 | (buf[base + 1] == '-') && | 
|  | 9992 | (buf[base + 2] == '>')) { | 
|  | 9993 | found = 1; | 
|  | 9994 | base += 2; | 
|  | 9995 | break; | 
|  | 9996 | } | 
|  | 9997 | } | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 9998 | if (!found) { | 
|  | 9999 | #if 0 | 
|  | 10000 | fprintf(stderr, "unfinished comment\n"); | 
|  | 10001 | #endif | 
|  | 10002 | break; /* for */ | 
|  | 10003 | } | 
| Daniel Veillard | 036143b | 2004-02-12 11:57:52 +0000 | [diff] [blame] | 10004 | continue; | 
|  | 10005 | } | 
|  | 10006 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10007 | if (buf[base] == '"') { | 
|  | 10008 | quote = '"'; | 
|  | 10009 | continue; | 
|  | 10010 | } | 
|  | 10011 | if (buf[base] == '\'') { | 
|  | 10012 | quote = '\''; | 
|  | 10013 | continue; | 
|  | 10014 | } | 
|  | 10015 | if (buf[base] == ']') { | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10016 | #if 0 | 
|  | 10017 | fprintf(stderr, "%c%c%c%c: ", buf[base], | 
|  | 10018 | buf[base + 1], buf[base + 2], buf[base + 3]); | 
|  | 10019 | #endif | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10020 | if ((unsigned int) base +1 >= | 
|  | 10021 | ctxt->input->buf->buffer->use) | 
|  | 10022 | break; | 
|  | 10023 | if (buf[base + 1] == ']') { | 
|  | 10024 | /* conditional crap, skip both ']' ! */ | 
|  | 10025 | base++; | 
|  | 10026 | continue; | 
|  | 10027 | } | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10028 | for (i = 1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10029 | (unsigned int) base + i < ctxt->input->buf->buffer->use; | 
|  | 10030 | i++) { | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10031 | if (buf[base + i] == '>') { | 
|  | 10032 | #if 0 | 
|  | 10033 | fprintf(stderr, "found\n"); | 
|  | 10034 | #endif | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10035 | goto found_end_int_subset; | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10036 | } | 
|  | 10037 | if (!IS_BLANK_CH(buf[base + i])) { | 
|  | 10038 | #if 0 | 
|  | 10039 | fprintf(stderr, "not found\n"); | 
|  | 10040 | #endif | 
|  | 10041 | goto not_end_of_int_subset; | 
|  | 10042 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10043 | } | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10044 | #if 0 | 
|  | 10045 | fprintf(stderr, "end of stream\n"); | 
|  | 10046 | #endif | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10047 | break; | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10048 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10049 | } | 
| Daniel Veillard | 8f8a9dd | 2005-01-25 21:41:42 +0000 | [diff] [blame] | 10050 | not_end_of_int_subset: | 
|  | 10051 | continue; /* for */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10052 | } | 
|  | 10053 | /* | 
|  | 10054 | * We didn't found the end of the Internal subset | 
|  | 10055 | */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10056 | #ifdef DEBUG_PUSH | 
|  | 10057 | if (next == 0) | 
|  | 10058 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10059 | "PP: lookup of int subset end filed\n"); | 
|  | 10060 | #endif | 
|  | 10061 | goto done; | 
|  | 10062 |  | 
|  | 10063 | found_end_int_subset: | 
|  | 10064 | xmlParseInternalSubset(ctxt); | 
|  | 10065 | ctxt->inSubset = 2; | 
|  | 10066 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && | 
|  | 10067 | (ctxt->sax->externalSubset != NULL)) | 
|  | 10068 | ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName, | 
|  | 10069 | ctxt->extSubSystem, ctxt->extSubURI); | 
|  | 10070 | ctxt->inSubset = 0; | 
|  | 10071 | ctxt->instate = XML_PARSER_PROLOG; | 
|  | 10072 | ctxt->checkIndex = 0; | 
|  | 10073 | #ifdef DEBUG_PUSH | 
|  | 10074 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10075 | "PP: entering PROLOG\n"); | 
|  | 10076 | #endif | 
|  | 10077 | break; | 
|  | 10078 | } | 
|  | 10079 | case XML_PARSER_COMMENT: | 
|  | 10080 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10081 | "PP: internal error, state == COMMENT\n"); | 
|  | 10082 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 10083 | #ifdef DEBUG_PUSH | 
|  | 10084 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10085 | "PP: entering CONTENT\n"); | 
|  | 10086 | #endif | 
|  | 10087 | break; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 10088 | case XML_PARSER_IGNORE: | 
|  | 10089 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10090 | "PP: internal error, state == IGNORE"); | 
|  | 10091 | ctxt->instate = XML_PARSER_DTD; | 
|  | 10092 | #ifdef DEBUG_PUSH | 
|  | 10093 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10094 | "PP: entering DTD\n"); | 
|  | 10095 | #endif | 
|  | 10096 | break; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10097 | case XML_PARSER_PI: | 
|  | 10098 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10099 | "PP: internal error, state == PI\n"); | 
|  | 10100 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 10101 | #ifdef DEBUG_PUSH | 
|  | 10102 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10103 | "PP: entering CONTENT\n"); | 
|  | 10104 | #endif | 
|  | 10105 | break; | 
|  | 10106 | case XML_PARSER_ENTITY_DECL: | 
|  | 10107 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10108 | "PP: internal error, state == ENTITY_DECL\n"); | 
|  | 10109 | ctxt->instate = XML_PARSER_DTD; | 
|  | 10110 | #ifdef DEBUG_PUSH | 
|  | 10111 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10112 | "PP: entering DTD\n"); | 
|  | 10113 | #endif | 
|  | 10114 | break; | 
|  | 10115 | case XML_PARSER_ENTITY_VALUE: | 
|  | 10116 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10117 | "PP: internal error, state == ENTITY_VALUE\n"); | 
|  | 10118 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 10119 | #ifdef DEBUG_PUSH | 
|  | 10120 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10121 | "PP: entering DTD\n"); | 
|  | 10122 | #endif | 
|  | 10123 | break; | 
|  | 10124 | case XML_PARSER_ATTRIBUTE_VALUE: | 
|  | 10125 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10126 | "PP: internal error, state == ATTRIBUTE_VALUE\n"); | 
|  | 10127 | ctxt->instate = XML_PARSER_START_TAG; | 
|  | 10128 | #ifdef DEBUG_PUSH | 
|  | 10129 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10130 | "PP: entering START_TAG\n"); | 
|  | 10131 | #endif | 
|  | 10132 | break; | 
|  | 10133 | case XML_PARSER_SYSTEM_LITERAL: | 
|  | 10134 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10135 | "PP: internal error, state == SYSTEM_LITERAL\n"); | 
|  | 10136 | ctxt->instate = XML_PARSER_START_TAG; | 
|  | 10137 | #ifdef DEBUG_PUSH | 
|  | 10138 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10139 | "PP: entering START_TAG\n"); | 
|  | 10140 | #endif | 
|  | 10141 | break; | 
| Daniel Veillard | 4a7ae50 | 2002-02-18 19:18:17 +0000 | [diff] [blame] | 10142 | case XML_PARSER_PUBLIC_LITERAL: | 
|  | 10143 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10144 | "PP: internal error, state == PUBLIC_LITERAL\n"); | 
|  | 10145 | ctxt->instate = XML_PARSER_START_TAG; | 
|  | 10146 | #ifdef DEBUG_PUSH | 
|  | 10147 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10148 | "PP: entering START_TAG\n"); | 
|  | 10149 | #endif | 
|  | 10150 | break; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10151 | } | 
|  | 10152 | } | 
|  | 10153 | done: | 
|  | 10154 | #ifdef DEBUG_PUSH | 
|  | 10155 | xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret); | 
|  | 10156 | #endif | 
|  | 10157 | return(ret); | 
| Daniel Veillard | 3fa5e7e | 2005-07-04 11:12:25 +0000 | [diff] [blame] | 10158 | encoding_error: | 
|  | 10159 | { | 
|  | 10160 | char buffer[150]; | 
|  | 10161 |  | 
|  | 10162 | snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", | 
|  | 10163 | ctxt->input->cur[0], ctxt->input->cur[1], | 
|  | 10164 | ctxt->input->cur[2], ctxt->input->cur[3]); | 
|  | 10165 | __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR, | 
|  | 10166 | "Input is not proper UTF-8, indicate encoding !\n%s", | 
|  | 10167 | BAD_CAST buffer, NULL); | 
|  | 10168 | } | 
|  | 10169 | return(0); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10170 | } | 
|  | 10171 |  | 
|  | 10172 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10173 | * xmlParseChunk: | 
|  | 10174 | * @ctxt:  an XML parser context | 
|  | 10175 | * @chunk:  an char array | 
|  | 10176 | * @size:  the size in byte of the chunk | 
|  | 10177 | * @terminate:  last chunk indicator | 
|  | 10178 | * | 
|  | 10179 | * Parse a Chunk of memory | 
|  | 10180 | * | 
|  | 10181 | * Returns zero if no error, the xmlParserErrors otherwise. | 
|  | 10182 | */ | 
|  | 10183 | int | 
|  | 10184 | xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, | 
|  | 10185 | int terminate) { | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 10186 | if (ctxt == NULL) | 
|  | 10187 | return(XML_ERR_INTERNAL_ERROR); | 
| Daniel Veillard | 1441251 | 2005-01-21 23:53:26 +0000 | [diff] [blame] | 10188 | if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 10189 | return(ctxt->errNo); | 
| Daniel Veillard | 309f81d | 2003-09-23 09:02:53 +0000 | [diff] [blame] | 10190 | if (ctxt->instate == XML_PARSER_START) | 
|  | 10191 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10192 | if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && | 
|  | 10193 | (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF))  { | 
|  | 10194 | int base = ctxt->input->base - ctxt->input->buf->buffer->content; | 
|  | 10195 | int cur = ctxt->input->cur - ctxt->input->base; | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 10196 | int res; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10197 |  | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 10198 | res =xmlParserInputBufferPush(ctxt->input->buf, size, chunk); | 
|  | 10199 | if (res < 0) { | 
|  | 10200 | ctxt->errNo = XML_PARSER_EOF; | 
|  | 10201 | ctxt->disableSAX = 1; | 
|  | 10202 | return (XML_PARSER_EOF); | 
|  | 10203 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10204 | ctxt->input->base = ctxt->input->buf->buffer->content + base; | 
|  | 10205 | ctxt->input->cur = ctxt->input->base + cur; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 10206 | ctxt->input->end = | 
|  | 10207 | &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use]; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10208 | #ifdef DEBUG_PUSH | 
|  | 10209 | xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); | 
|  | 10210 | #endif | 
|  | 10211 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10212 | } else if (ctxt->instate != XML_PARSER_EOF) { | 
|  | 10213 | if ((ctxt->input != NULL) && ctxt->input->buf != NULL) { | 
|  | 10214 | xmlParserInputBufferPtr in = ctxt->input->buf; | 
|  | 10215 | if ((in->encoder != NULL) && (in->buffer != NULL) && | 
|  | 10216 | (in->raw != NULL)) { | 
|  | 10217 | int nbchars; | 
|  | 10218 |  | 
|  | 10219 | nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); | 
|  | 10220 | if (nbchars < 0) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 10221 | /* TODO 2.6.0 */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10222 | xmlGenericError(xmlGenericErrorContext, | 
|  | 10223 | "xmlParseChunk: encoder error\n"); | 
|  | 10224 | return(XML_ERR_INVALID_ENCODING); | 
|  | 10225 | } | 
|  | 10226 | } | 
|  | 10227 | } | 
|  | 10228 | } | 
|  | 10229 | xmlParseTryOrFinish(ctxt, terminate); | 
| Daniel Veillard | 1441251 | 2005-01-21 23:53:26 +0000 | [diff] [blame] | 10230 | if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 10231 | return(ctxt->errNo); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10232 | if (terminate) { | 
|  | 10233 | /* | 
|  | 10234 | * Check for termination | 
|  | 10235 | */ | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 10236 | int avail = 0; | 
|  | 10237 |  | 
|  | 10238 | if (ctxt->input != NULL) { | 
| Daniel Veillard | 819d5cb | 2002-10-14 11:15:18 +0000 | [diff] [blame] | 10239 | if (ctxt->input->buf == NULL) | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 10240 | avail = ctxt->input->length - | 
|  | 10241 | (ctxt->input->cur - ctxt->input->base); | 
|  | 10242 | else | 
|  | 10243 | avail = ctxt->input->buf->buffer->use - | 
|  | 10244 | (ctxt->input->cur - ctxt->input->base); | 
|  | 10245 | } | 
| Daniel Veillard | 819d5cb | 2002-10-14 11:15:18 +0000 | [diff] [blame] | 10246 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10247 | if ((ctxt->instate != XML_PARSER_EOF) && | 
|  | 10248 | (ctxt->instate != XML_PARSER_EPILOG)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10249 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10250 | } | 
| Daniel Veillard | 819d5cb | 2002-10-14 11:15:18 +0000 | [diff] [blame] | 10251 | if ((ctxt->instate == XML_PARSER_EPILOG) && (avail > 0)) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10252 | xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); | 
| Daniel Veillard | 819d5cb | 2002-10-14 11:15:18 +0000 | [diff] [blame] | 10253 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10254 | if (ctxt->instate != XML_PARSER_EOF) { | 
| Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 10255 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10256 | ctxt->sax->endDocument(ctxt->userData); | 
|  | 10257 | } | 
|  | 10258 | ctxt->instate = XML_PARSER_EOF; | 
|  | 10259 | } | 
|  | 10260 | return((xmlParserErrors) ctxt->errNo); | 
|  | 10261 | } | 
|  | 10262 |  | 
|  | 10263 | /************************************************************************ | 
|  | 10264 | *									* | 
|  | 10265 | * 		I/O front end functions to the parser			* | 
|  | 10266 | *									* | 
|  | 10267 | ************************************************************************/ | 
|  | 10268 |  | 
|  | 10269 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10270 | * xmlCreatePushParserCtxt: | 
|  | 10271 | * @sax:  a SAX handler | 
|  | 10272 | * @user_data:  The user data returned on SAX callbacks | 
|  | 10273 | * @chunk:  a pointer to an array of chars | 
|  | 10274 | * @size:  number of chars in the array | 
|  | 10275 | * @filename:  an optional file name or URI | 
|  | 10276 | * | 
| Daniel Veillard | 176d99f | 2002-07-06 19:22:28 +0000 | [diff] [blame] | 10277 | * Create a parser context for using the XML parser in push mode. | 
|  | 10278 | * If @buffer and @size are non-NULL, the data is used to detect | 
|  | 10279 | * the encoding.  The remaining characters will be parsed so they | 
|  | 10280 | * don't need to be fed in again through xmlParseChunk. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10281 | * To allow content encoding detection, @size should be >= 4 | 
|  | 10282 | * The value of @filename is used for fetching external entities | 
|  | 10283 | * and error/warning reports. | 
|  | 10284 | * | 
|  | 10285 | * Returns the new parser context or NULL | 
|  | 10286 | */ | 
| Daniel Veillard | 176d99f | 2002-07-06 19:22:28 +0000 | [diff] [blame] | 10287 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10288 | xmlParserCtxtPtr | 
|  | 10289 | xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, | 
|  | 10290 | const char *chunk, int size, const char *filename) { | 
|  | 10291 | xmlParserCtxtPtr ctxt; | 
|  | 10292 | xmlParserInputPtr inputStream; | 
|  | 10293 | xmlParserInputBufferPtr buf; | 
|  | 10294 | xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; | 
|  | 10295 |  | 
|  | 10296 | /* | 
|  | 10297 | * plug some encoding conversion routines | 
|  | 10298 | */ | 
|  | 10299 | if ((chunk != NULL) && (size >= 4)) | 
|  | 10300 | enc = xmlDetectCharEncoding((const xmlChar *) chunk, size); | 
|  | 10301 |  | 
|  | 10302 | buf = xmlAllocParserInputBuffer(enc); | 
|  | 10303 | if (buf == NULL) return(NULL); | 
|  | 10304 |  | 
|  | 10305 | ctxt = xmlNewParserCtxt(); | 
|  | 10306 | if (ctxt == NULL) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 10307 | xmlErrMemory(NULL, "creating parser: out of memory\n"); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 10308 | xmlFreeParserInputBuffer(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10309 | return(NULL); | 
|  | 10310 | } | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 10311 | ctxt->dictNames = 1; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 10312 | ctxt->pushTab = (void **) xmlMalloc(ctxt->nameMax * 3 * sizeof(xmlChar *)); | 
|  | 10313 | if (ctxt->pushTab == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10314 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 10315 | xmlFreeParserInputBuffer(buf); | 
|  | 10316 | xmlFreeParserCtxt(ctxt); | 
|  | 10317 | return(NULL); | 
|  | 10318 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10319 | if (sax != NULL) { | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 10320 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 10321 | if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 10322 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10323 | xmlFree(ctxt->sax); | 
|  | 10324 | ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); | 
|  | 10325 | if (ctxt->sax == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10326 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 10327 | xmlFreeParserInputBuffer(buf); | 
|  | 10328 | xmlFreeParserCtxt(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10329 | return(NULL); | 
|  | 10330 | } | 
| Daniel Veillard | 5ea30d7 | 2004-11-08 11:54:28 +0000 | [diff] [blame] | 10331 | memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); | 
|  | 10332 | if (sax->initialized == XML_SAX2_MAGIC) | 
|  | 10333 | memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); | 
|  | 10334 | else | 
|  | 10335 | memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10336 | if (user_data != NULL) | 
|  | 10337 | ctxt->userData = user_data; | 
|  | 10338 | } | 
|  | 10339 | if (filename == NULL) { | 
|  | 10340 | ctxt->directory = NULL; | 
|  | 10341 | } else { | 
|  | 10342 | ctxt->directory = xmlParserGetDirectory(filename); | 
|  | 10343 | } | 
|  | 10344 |  | 
|  | 10345 | inputStream = xmlNewInputStream(ctxt); | 
|  | 10346 | if (inputStream == NULL) { | 
|  | 10347 | xmlFreeParserCtxt(ctxt); | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 10348 | xmlFreeParserInputBuffer(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10349 | return(NULL); | 
|  | 10350 | } | 
|  | 10351 |  | 
|  | 10352 | if (filename == NULL) | 
|  | 10353 | inputStream->filename = NULL; | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 10354 | else { | 
| Daniel Veillard | f4862f0 | 2002-09-10 11:13:43 +0000 | [diff] [blame] | 10355 | inputStream->filename = (char *) | 
| Igor Zlatkovic | 5f9fada | 2003-02-19 14:51:00 +0000 | [diff] [blame] | 10356 | xmlCanonicPath((const xmlChar *) filename); | 
| William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 10357 | if (inputStream->filename == NULL) { | 
|  | 10358 | xmlFreeParserCtxt(ctxt); | 
|  | 10359 | xmlFreeParserInputBuffer(buf); | 
|  | 10360 | return(NULL); | 
|  | 10361 | } | 
|  | 10362 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10363 | inputStream->buf = buf; | 
|  | 10364 | inputStream->base = inputStream->buf->buffer->content; | 
|  | 10365 | inputStream->cur = inputStream->buf->buffer->content; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 10366 | inputStream->end = | 
|  | 10367 | &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10368 |  | 
|  | 10369 | inputPush(ctxt, inputStream); | 
|  | 10370 |  | 
| William M. Brack | 3a1cd21 | 2005-02-11 14:35:54 +0000 | [diff] [blame] | 10371 | /* | 
|  | 10372 | * If the caller didn't provide an initial 'chunk' for determining | 
|  | 10373 | * the encoding, we set the context to XML_CHAR_ENCODING_NONE so | 
|  | 10374 | * that it can be automatically determined later | 
|  | 10375 | */ | 
|  | 10376 | if ((size == 0) || (chunk == NULL)) { | 
|  | 10377 | ctxt->charset = XML_CHAR_ENCODING_NONE; | 
|  | 10378 | } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) { | 
| Daniel Veillard | aa39a0f | 2002-01-06 12:47:22 +0000 | [diff] [blame] | 10379 | int base = ctxt->input->base - ctxt->input->buf->buffer->content; | 
|  | 10380 | int cur = ctxt->input->cur - ctxt->input->base; | 
|  | 10381 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10382 | xmlParserInputBufferPush(ctxt->input->buf, size, chunk); | 
| Daniel Veillard | aa39a0f | 2002-01-06 12:47:22 +0000 | [diff] [blame] | 10383 |  | 
|  | 10384 | ctxt->input->base = ctxt->input->buf->buffer->content + base; | 
|  | 10385 | ctxt->input->cur = ctxt->input->base + cur; | 
|  | 10386 | ctxt->input->end = | 
|  | 10387 | &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use]; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10388 | #ifdef DEBUG_PUSH | 
|  | 10389 | xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); | 
|  | 10390 | #endif | 
|  | 10391 | } | 
|  | 10392 |  | 
| Daniel Veillard | 0e4cd17 | 2001-06-28 12:13:56 +0000 | [diff] [blame] | 10393 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 10394 | xmlSwitchEncoding(ctxt, enc); | 
|  | 10395 | } | 
|  | 10396 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10397 | return(ctxt); | 
|  | 10398 | } | 
| Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 10399 | #endif /* LIBXML_PUSH_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10400 |  | 
|  | 10401 | /** | 
| Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 10402 | * xmlStopParser: | 
|  | 10403 | * @ctxt:  an XML parser context | 
|  | 10404 | * | 
|  | 10405 | * Blocks further parser processing | 
|  | 10406 | */ | 
|  | 10407 | void | 
|  | 10408 | xmlStopParser(xmlParserCtxtPtr ctxt) { | 
|  | 10409 | if (ctxt == NULL) | 
|  | 10410 | return; | 
|  | 10411 | ctxt->instate = XML_PARSER_EOF; | 
|  | 10412 | ctxt->disableSAX = 1; | 
|  | 10413 | if (ctxt->input != NULL) { | 
|  | 10414 | ctxt->input->cur = BAD_CAST""; | 
|  | 10415 | ctxt->input->base = ctxt->input->cur; | 
|  | 10416 | } | 
|  | 10417 | } | 
|  | 10418 |  | 
|  | 10419 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10420 | * xmlCreateIOParserCtxt: | 
|  | 10421 | * @sax:  a SAX handler | 
|  | 10422 | * @user_data:  The user data returned on SAX callbacks | 
|  | 10423 | * @ioread:  an I/O read function | 
|  | 10424 | * @ioclose:  an I/O close function | 
|  | 10425 | * @ioctx:  an I/O handler | 
|  | 10426 | * @enc:  the charset encoding if known | 
|  | 10427 | * | 
|  | 10428 | * Create a parser context for using the XML parser with an existing | 
|  | 10429 | * I/O stream | 
|  | 10430 | * | 
|  | 10431 | * Returns the new parser context or NULL | 
|  | 10432 | */ | 
|  | 10433 | xmlParserCtxtPtr | 
|  | 10434 | xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, | 
|  | 10435 | xmlInputReadCallback   ioread, xmlInputCloseCallback  ioclose, | 
|  | 10436 | void *ioctx, xmlCharEncoding enc) { | 
|  | 10437 | xmlParserCtxtPtr ctxt; | 
|  | 10438 | xmlParserInputPtr inputStream; | 
|  | 10439 | xmlParserInputBufferPtr buf; | 
| Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 10440 |  | 
|  | 10441 | if (ioread == NULL) return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10442 |  | 
|  | 10443 | buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc); | 
|  | 10444 | if (buf == NULL) return(NULL); | 
|  | 10445 |  | 
|  | 10446 | ctxt = xmlNewParserCtxt(); | 
|  | 10447 | if (ctxt == NULL) { | 
| Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 10448 | xmlFreeParserInputBuffer(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10449 | return(NULL); | 
|  | 10450 | } | 
|  | 10451 | if (sax != NULL) { | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 10452 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 10453 | if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 10454 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10455 | xmlFree(ctxt->sax); | 
|  | 10456 | ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); | 
|  | 10457 | if (ctxt->sax == NULL) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10458 | xmlErrMemory(ctxt, NULL); | 
| Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 10459 | xmlFreeParserCtxt(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10460 | return(NULL); | 
|  | 10461 | } | 
| Daniel Veillard | 5ea30d7 | 2004-11-08 11:54:28 +0000 | [diff] [blame] | 10462 | memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); | 
|  | 10463 | if (sax->initialized == XML_SAX2_MAGIC) | 
|  | 10464 | memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); | 
|  | 10465 | else | 
|  | 10466 | memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10467 | if (user_data != NULL) | 
|  | 10468 | ctxt->userData = user_data; | 
|  | 10469 | } | 
|  | 10470 |  | 
|  | 10471 | inputStream = xmlNewIOInputStream(ctxt, buf, enc); | 
|  | 10472 | if (inputStream == NULL) { | 
|  | 10473 | xmlFreeParserCtxt(ctxt); | 
|  | 10474 | return(NULL); | 
|  | 10475 | } | 
|  | 10476 | inputPush(ctxt, inputStream); | 
|  | 10477 |  | 
|  | 10478 | return(ctxt); | 
|  | 10479 | } | 
|  | 10480 |  | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 10481 | #ifdef LIBXML_VALID_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10482 | /************************************************************************ | 
|  | 10483 | *									* | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 10484 | * 		Front ends when parsing a DTD				* | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10485 | *									* | 
|  | 10486 | ************************************************************************/ | 
|  | 10487 |  | 
|  | 10488 | /** | 
|  | 10489 | * xmlIOParseDTD: | 
|  | 10490 | * @sax:  the SAX handler block or NULL | 
|  | 10491 | * @input:  an Input Buffer | 
|  | 10492 | * @enc:  the charset encoding if known | 
|  | 10493 | * | 
|  | 10494 | * Load and parse a DTD | 
|  | 10495 | * | 
|  | 10496 | * Returns the resulting xmlDtdPtr or NULL in case of error. | 
|  | 10497 | * @input will be freed at parsing end. | 
|  | 10498 | */ | 
|  | 10499 |  | 
|  | 10500 | xmlDtdPtr | 
|  | 10501 | xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, | 
|  | 10502 | xmlCharEncoding enc) { | 
|  | 10503 | xmlDtdPtr ret = NULL; | 
|  | 10504 | xmlParserCtxtPtr ctxt; | 
|  | 10505 | xmlParserInputPtr pinput = NULL; | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10506 | xmlChar start[4]; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10507 |  | 
|  | 10508 | if (input == NULL) | 
|  | 10509 | return(NULL); | 
|  | 10510 |  | 
|  | 10511 | ctxt = xmlNewParserCtxt(); | 
|  | 10512 | if (ctxt == NULL) { | 
|  | 10513 | return(NULL); | 
|  | 10514 | } | 
|  | 10515 |  | 
|  | 10516 | /* | 
|  | 10517 | * Set-up the SAX context | 
|  | 10518 | */ | 
|  | 10519 | if (sax != NULL) { | 
|  | 10520 | if (ctxt->sax != NULL) | 
|  | 10521 | xmlFree(ctxt->sax); | 
|  | 10522 | ctxt->sax = sax; | 
| Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 10523 | ctxt->userData = ctxt; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10524 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 10525 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10526 |  | 
|  | 10527 | /* | 
|  | 10528 | * generate a parser input from the I/O handler | 
|  | 10529 | */ | 
|  | 10530 |  | 
| Daniel Veillard | 43caefb | 2003-12-07 19:32:22 +0000 | [diff] [blame] | 10531 | pinput = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10532 | if (pinput == NULL) { | 
|  | 10533 | if (sax != NULL) ctxt->sax = NULL; | 
|  | 10534 | xmlFreeParserCtxt(ctxt); | 
|  | 10535 | return(NULL); | 
|  | 10536 | } | 
|  | 10537 |  | 
|  | 10538 | /* | 
|  | 10539 | * plug some encoding conversion routines here. | 
|  | 10540 | */ | 
|  | 10541 | xmlPushInput(ctxt, pinput); | 
| Daniel Veillard | 43caefb | 2003-12-07 19:32:22 +0000 | [diff] [blame] | 10542 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 10543 | xmlSwitchEncoding(ctxt, enc); | 
|  | 10544 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10545 |  | 
|  | 10546 | pinput->filename = NULL; | 
|  | 10547 | pinput->line = 1; | 
|  | 10548 | pinput->col = 1; | 
|  | 10549 | pinput->base = ctxt->input->cur; | 
|  | 10550 | pinput->cur = ctxt->input->cur; | 
|  | 10551 | pinput->free = NULL; | 
|  | 10552 |  | 
|  | 10553 | /* | 
|  | 10554 | * let's parse that entity knowing it's an external subset. | 
|  | 10555 | */ | 
|  | 10556 | ctxt->inSubset = 2; | 
|  | 10557 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 10558 | ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", | 
|  | 10559 | BAD_CAST "none", BAD_CAST "none"); | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10560 |  | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 10561 | if ((enc == XML_CHAR_ENCODING_NONE) && | 
|  | 10562 | ((ctxt->input->end - ctxt->input->cur) >= 4)) { | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10563 | /* | 
|  | 10564 | * Get the 4 first bytes and decode the charset | 
|  | 10565 | * if enc != XML_CHAR_ENCODING_NONE | 
|  | 10566 | * plug some encoding conversion routines. | 
|  | 10567 | */ | 
|  | 10568 | start[0] = RAW; | 
|  | 10569 | start[1] = NXT(1); | 
|  | 10570 | start[2] = NXT(2); | 
|  | 10571 | start[3] = NXT(3); | 
|  | 10572 | enc = xmlDetectCharEncoding(start, 4); | 
|  | 10573 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 10574 | xmlSwitchEncoding(ctxt, enc); | 
|  | 10575 | } | 
|  | 10576 | } | 
|  | 10577 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10578 | xmlParseExternalSubset(ctxt, BAD_CAST "none", BAD_CAST "none"); | 
|  | 10579 |  | 
|  | 10580 | if (ctxt->myDoc != NULL) { | 
|  | 10581 | if (ctxt->wellFormed) { | 
|  | 10582 | ret = ctxt->myDoc->extSubset; | 
|  | 10583 | ctxt->myDoc->extSubset = NULL; | 
| Daniel Veillard | 329456a | 2003-04-26 21:21:00 +0000 | [diff] [blame] | 10584 | if (ret != NULL) { | 
|  | 10585 | xmlNodePtr tmp; | 
|  | 10586 |  | 
|  | 10587 | ret->doc = NULL; | 
|  | 10588 | tmp = ret->children; | 
|  | 10589 | while (tmp != NULL) { | 
|  | 10590 | tmp->doc = NULL; | 
|  | 10591 | tmp = tmp->next; | 
|  | 10592 | } | 
|  | 10593 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10594 | } else { | 
|  | 10595 | ret = NULL; | 
|  | 10596 | } | 
|  | 10597 | xmlFreeDoc(ctxt->myDoc); | 
|  | 10598 | ctxt->myDoc = NULL; | 
|  | 10599 | } | 
|  | 10600 | if (sax != NULL) ctxt->sax = NULL; | 
|  | 10601 | xmlFreeParserCtxt(ctxt); | 
|  | 10602 |  | 
|  | 10603 | return(ret); | 
|  | 10604 | } | 
|  | 10605 |  | 
|  | 10606 | /** | 
|  | 10607 | * xmlSAXParseDTD: | 
|  | 10608 | * @sax:  the SAX handler block | 
|  | 10609 | * @ExternalID:  a NAME* containing the External ID of the DTD | 
|  | 10610 | * @SystemID:  a NAME* containing the URL to the DTD | 
|  | 10611 | * | 
|  | 10612 | * Load and parse an external subset. | 
|  | 10613 | * | 
|  | 10614 | * Returns the resulting xmlDtdPtr or NULL in case of error. | 
|  | 10615 | */ | 
|  | 10616 |  | 
|  | 10617 | xmlDtdPtr | 
|  | 10618 | xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, | 
|  | 10619 | const xmlChar *SystemID) { | 
|  | 10620 | xmlDtdPtr ret = NULL; | 
|  | 10621 | xmlParserCtxtPtr ctxt; | 
|  | 10622 | xmlParserInputPtr input = NULL; | 
|  | 10623 | xmlCharEncoding enc; | 
| Igor Zlatkovic | 07d5976 | 2004-08-24 19:12:51 +0000 | [diff] [blame] | 10624 | xmlChar* systemIdCanonic; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10625 |  | 
|  | 10626 | if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); | 
|  | 10627 |  | 
|  | 10628 | ctxt = xmlNewParserCtxt(); | 
|  | 10629 | if (ctxt == NULL) { | 
|  | 10630 | return(NULL); | 
|  | 10631 | } | 
|  | 10632 |  | 
|  | 10633 | /* | 
|  | 10634 | * Set-up the SAX context | 
|  | 10635 | */ | 
|  | 10636 | if (sax != NULL) { | 
|  | 10637 | if (ctxt->sax != NULL) | 
|  | 10638 | xmlFree(ctxt->sax); | 
|  | 10639 | ctxt->sax = sax; | 
| Daniel Veillard | bf1e3d8 | 2003-08-14 23:57:26 +0000 | [diff] [blame] | 10640 | ctxt->userData = ctxt; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10641 | } | 
| Igor Zlatkovic | 07d5976 | 2004-08-24 19:12:51 +0000 | [diff] [blame] | 10642 |  | 
|  | 10643 | /* | 
|  | 10644 | * Canonicalise the system ID | 
|  | 10645 | */ | 
|  | 10646 | systemIdCanonic = xmlCanonicPath(SystemID); | 
| Daniel Veillard | c93a19f | 2004-10-04 11:53:20 +0000 | [diff] [blame] | 10647 | if ((SystemID != NULL) && (systemIdCanonic == NULL)) { | 
| Igor Zlatkovic | 07d5976 | 2004-08-24 19:12:51 +0000 | [diff] [blame] | 10648 | xmlFreeParserCtxt(ctxt); | 
|  | 10649 | return(NULL); | 
|  | 10650 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10651 |  | 
|  | 10652 | /* | 
|  | 10653 | * Ask the Entity resolver to load the damn thing | 
|  | 10654 | */ | 
|  | 10655 |  | 
|  | 10656 | if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) | 
| Igor Zlatkovic | 07d5976 | 2004-08-24 19:12:51 +0000 | [diff] [blame] | 10657 | input = ctxt->sax->resolveEntity(ctxt, ExternalID, systemIdCanonic); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10658 | if (input == NULL) { | 
|  | 10659 | if (sax != NULL) ctxt->sax = NULL; | 
|  | 10660 | xmlFreeParserCtxt(ctxt); | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 10661 | if (systemIdCanonic != NULL) | 
|  | 10662 | xmlFree(systemIdCanonic); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10663 | return(NULL); | 
|  | 10664 | } | 
|  | 10665 |  | 
|  | 10666 | /* | 
|  | 10667 | * plug some encoding conversion routines here. | 
|  | 10668 | */ | 
|  | 10669 | xmlPushInput(ctxt, input); | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 10670 | if ((ctxt->input->end - ctxt->input->cur) >= 4) { | 
|  | 10671 | enc = xmlDetectCharEncoding(ctxt->input->cur, 4); | 
|  | 10672 | xmlSwitchEncoding(ctxt, enc); | 
|  | 10673 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10674 |  | 
|  | 10675 | if (input->filename == NULL) | 
| Igor Zlatkovic | 07d5976 | 2004-08-24 19:12:51 +0000 | [diff] [blame] | 10676 | input->filename = (char *) systemIdCanonic; | 
|  | 10677 | else | 
|  | 10678 | xmlFree(systemIdCanonic); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10679 | input->line = 1; | 
|  | 10680 | input->col = 1; | 
|  | 10681 | input->base = ctxt->input->cur; | 
|  | 10682 | input->cur = ctxt->input->cur; | 
|  | 10683 | input->free = NULL; | 
|  | 10684 |  | 
|  | 10685 | /* | 
|  | 10686 | * let's parse that entity knowing it's an external subset. | 
|  | 10687 | */ | 
|  | 10688 | ctxt->inSubset = 2; | 
|  | 10689 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 10690 | ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", | 
|  | 10691 | ExternalID, SystemID); | 
|  | 10692 | xmlParseExternalSubset(ctxt, ExternalID, SystemID); | 
|  | 10693 |  | 
|  | 10694 | if (ctxt->myDoc != NULL) { | 
|  | 10695 | if (ctxt->wellFormed) { | 
|  | 10696 | ret = ctxt->myDoc->extSubset; | 
|  | 10697 | ctxt->myDoc->extSubset = NULL; | 
| Daniel Veillard | c557346 | 2003-04-25 16:43:49 +0000 | [diff] [blame] | 10698 | if (ret != NULL) { | 
|  | 10699 | xmlNodePtr tmp; | 
|  | 10700 |  | 
|  | 10701 | ret->doc = NULL; | 
|  | 10702 | tmp = ret->children; | 
|  | 10703 | while (tmp != NULL) { | 
|  | 10704 | tmp->doc = NULL; | 
|  | 10705 | tmp = tmp->next; | 
|  | 10706 | } | 
|  | 10707 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10708 | } else { | 
|  | 10709 | ret = NULL; | 
|  | 10710 | } | 
|  | 10711 | xmlFreeDoc(ctxt->myDoc); | 
|  | 10712 | ctxt->myDoc = NULL; | 
|  | 10713 | } | 
|  | 10714 | if (sax != NULL) ctxt->sax = NULL; | 
|  | 10715 | xmlFreeParserCtxt(ctxt); | 
|  | 10716 |  | 
|  | 10717 | return(ret); | 
|  | 10718 | } | 
|  | 10719 |  | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 10720 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10721 | /** | 
|  | 10722 | * xmlParseDTD: | 
|  | 10723 | * @ExternalID:  a NAME* containing the External ID of the DTD | 
|  | 10724 | * @SystemID:  a NAME* containing the URL to the DTD | 
|  | 10725 | * | 
|  | 10726 | * Load and parse an external subset. | 
|  | 10727 | * | 
|  | 10728 | * Returns the resulting xmlDtdPtr or NULL in case of error. | 
|  | 10729 | */ | 
|  | 10730 |  | 
|  | 10731 | xmlDtdPtr | 
|  | 10732 | xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) { | 
|  | 10733 | return(xmlSAXParseDTD(NULL, ExternalID, SystemID)); | 
|  | 10734 | } | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 10735 | #endif /* LIBXML_VALID_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10736 |  | 
|  | 10737 | /************************************************************************ | 
|  | 10738 | *									* | 
|  | 10739 | * 		Front ends when parsing an Entity			* | 
|  | 10740 | *									* | 
|  | 10741 | ************************************************************************/ | 
|  | 10742 |  | 
|  | 10743 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10744 | * xmlParseCtxtExternalEntity: | 
|  | 10745 | * @ctx:  the existing parsing context | 
|  | 10746 | * @URL:  the URL for the entity to load | 
|  | 10747 | * @ID:  the System ID for the entity to load | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 10748 | * @lst:  the return value for the set of parsed nodes | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10749 | * | 
|  | 10750 | * Parse an external general entity within an existing parsing context | 
|  | 10751 | * An external general parsed entity is well-formed if it matches the | 
|  | 10752 | * production labeled extParsedEnt. | 
|  | 10753 | * | 
|  | 10754 | * [78] extParsedEnt ::= TextDecl? content | 
|  | 10755 | * | 
|  | 10756 | * Returns 0 if the entity is well formed, -1 in case of args problem and | 
|  | 10757 | *    the parser error code otherwise | 
|  | 10758 | */ | 
|  | 10759 |  | 
|  | 10760 | int | 
|  | 10761 | xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL, | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 10762 | const xmlChar *ID, xmlNodePtr *lst) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10763 | xmlParserCtxtPtr ctxt; | 
|  | 10764 | xmlDocPtr newDoc; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 10765 | xmlNodePtr newRoot; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10766 | xmlSAXHandlerPtr oldsax = NULL; | 
|  | 10767 | int ret = 0; | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10768 | xmlChar start[4]; | 
|  | 10769 | xmlCharEncoding enc; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10770 |  | 
| Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 10771 | if (ctx == NULL) return(-1); | 
|  | 10772 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10773 | if (ctx->depth > 40) { | 
|  | 10774 | return(XML_ERR_ENTITY_LOOP); | 
|  | 10775 | } | 
|  | 10776 |  | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 10777 | if (lst != NULL) | 
|  | 10778 | *lst = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10779 | if ((URL == NULL) && (ID == NULL)) | 
|  | 10780 | return(-1); | 
|  | 10781 | if (ctx->myDoc == NULL) /* @@ relax but check for dereferences */ | 
|  | 10782 | return(-1); | 
|  | 10783 |  | 
|  | 10784 |  | 
|  | 10785 | ctxt = xmlCreateEntityParserCtxt(URL, ID, NULL); | 
|  | 10786 | if (ctxt == NULL) return(-1); | 
|  | 10787 | ctxt->userData = ctxt; | 
| Daniel Veillard | e2830f1 | 2003-01-08 17:47:49 +0000 | [diff] [blame] | 10788 | ctxt->_private = ctx->_private; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10789 | oldsax = ctxt->sax; | 
|  | 10790 | ctxt->sax = ctx->sax; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 10791 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10792 | newDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 10793 | if (newDoc == NULL) { | 
|  | 10794 | xmlFreeParserCtxt(ctxt); | 
|  | 10795 | return(-1); | 
|  | 10796 | } | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 10797 | if (ctx->myDoc->dict) { | 
|  | 10798 | newDoc->dict = ctx->myDoc->dict; | 
|  | 10799 | xmlDictReference(newDoc->dict); | 
|  | 10800 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10801 | if (ctx->myDoc != NULL) { | 
|  | 10802 | newDoc->intSubset = ctx->myDoc->intSubset; | 
|  | 10803 | newDoc->extSubset = ctx->myDoc->extSubset; | 
|  | 10804 | } | 
|  | 10805 | if (ctx->myDoc->URL != NULL) { | 
|  | 10806 | newDoc->URL = xmlStrdup(ctx->myDoc->URL); | 
|  | 10807 | } | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 10808 | newRoot = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); | 
|  | 10809 | if (newRoot == NULL) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10810 | ctxt->sax = oldsax; | 
|  | 10811 | xmlFreeParserCtxt(ctxt); | 
|  | 10812 | newDoc->intSubset = NULL; | 
|  | 10813 | newDoc->extSubset = NULL; | 
|  | 10814 | xmlFreeDoc(newDoc); | 
|  | 10815 | return(-1); | 
|  | 10816 | } | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 10817 | xmlAddChild((xmlNodePtr) newDoc, newRoot); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10818 | nodePush(ctxt, newDoc->children); | 
|  | 10819 | if (ctx->myDoc == NULL) { | 
|  | 10820 | ctxt->myDoc = newDoc; | 
|  | 10821 | } else { | 
|  | 10822 | ctxt->myDoc = ctx->myDoc; | 
|  | 10823 | newDoc->children->doc = ctx->myDoc; | 
|  | 10824 | } | 
|  | 10825 |  | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10826 | /* | 
|  | 10827 | * Get the 4 first bytes and decode the charset | 
|  | 10828 | * if enc != XML_CHAR_ENCODING_NONE | 
|  | 10829 | * plug some encoding conversion routines. | 
|  | 10830 | */ | 
|  | 10831 | GROW | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 10832 | if ((ctxt->input->end - ctxt->input->cur) >= 4) { | 
|  | 10833 | start[0] = RAW; | 
|  | 10834 | start[1] = NXT(1); | 
|  | 10835 | start[2] = NXT(2); | 
|  | 10836 | start[3] = NXT(3); | 
|  | 10837 | enc = xmlDetectCharEncoding(start, 4); | 
|  | 10838 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 10839 | xmlSwitchEncoding(ctxt, enc); | 
|  | 10840 | } | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10841 | } | 
|  | 10842 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10843 | /* | 
|  | 10844 | * Parse a possible text declaration first | 
|  | 10845 | */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 10846 | if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10847 | xmlParseTextDecl(ctxt); | 
|  | 10848 | } | 
|  | 10849 |  | 
|  | 10850 | /* | 
|  | 10851 | * Doing validity checking on chunk doesn't make sense | 
|  | 10852 | */ | 
|  | 10853 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 10854 | ctxt->validate = ctx->validate; | 
| Daniel Veillard | 5f8d1a3 | 2003-03-23 21:02:00 +0000 | [diff] [blame] | 10855 | ctxt->valid = ctx->valid; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10856 | ctxt->loadsubset = ctx->loadsubset; | 
|  | 10857 | ctxt->depth = ctx->depth + 1; | 
|  | 10858 | ctxt->replaceEntities = ctx->replaceEntities; | 
|  | 10859 | if (ctxt->validate) { | 
|  | 10860 | ctxt->vctxt.error = ctx->vctxt.error; | 
|  | 10861 | ctxt->vctxt.warning = ctx->vctxt.warning; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10862 | } else { | 
|  | 10863 | ctxt->vctxt.error = NULL; | 
|  | 10864 | ctxt->vctxt.warning = NULL; | 
|  | 10865 | } | 
| Daniel Veillard | a9142e7 | 2001-06-19 11:07:54 +0000 | [diff] [blame] | 10866 | ctxt->vctxt.nodeTab = NULL; | 
|  | 10867 | ctxt->vctxt.nodeNr = 0; | 
|  | 10868 | ctxt->vctxt.nodeMax = 0; | 
|  | 10869 | ctxt->vctxt.node = NULL; | 
| Daniel Veillard | e4e3f5d | 2003-10-28 23:06:32 +0000 | [diff] [blame] | 10870 | if (ctxt->dict != NULL) xmlDictFree(ctxt->dict); | 
|  | 10871 | ctxt->dict = ctx->dict; | 
| Daniel Veillard | fd343dc | 2003-10-31 10:55:22 +0000 | [diff] [blame] | 10872 | ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3); | 
|  | 10873 | ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5); | 
|  | 10874 | ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36); | 
| Daniel Veillard | e4e3f5d | 2003-10-28 23:06:32 +0000 | [diff] [blame] | 10875 | ctxt->dictNames = ctx->dictNames; | 
|  | 10876 | ctxt->attsDefault = ctx->attsDefault; | 
|  | 10877 | ctxt->attsSpecial = ctx->attsSpecial; | 
| William M. Brack | 503b610 | 2004-08-19 02:17:27 +0000 | [diff] [blame] | 10878 | ctxt->linenumbers = ctx->linenumbers; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10879 |  | 
|  | 10880 | xmlParseContent(ctxt); | 
|  | 10881 |  | 
| Daniel Veillard | 5f8d1a3 | 2003-03-23 21:02:00 +0000 | [diff] [blame] | 10882 | ctx->validate = ctxt->validate; | 
|  | 10883 | ctx->valid = ctxt->valid; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10884 | if ((RAW == '<') && (NXT(1) == '/')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10885 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10886 | } else if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10887 | xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10888 | } | 
|  | 10889 | if (ctxt->node != newDoc->children) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 10890 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10891 | } | 
|  | 10892 |  | 
|  | 10893 | if (!ctxt->wellFormed) { | 
|  | 10894 | if (ctxt->errNo == 0) | 
|  | 10895 | ret = 1; | 
|  | 10896 | else | 
|  | 10897 | ret = ctxt->errNo; | 
|  | 10898 | } else { | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 10899 | if (lst != NULL) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10900 | xmlNodePtr cur; | 
|  | 10901 |  | 
|  | 10902 | /* | 
|  | 10903 | * Return the newly created nodeset after unlinking it from | 
|  | 10904 | * they pseudo parent. | 
|  | 10905 | */ | 
|  | 10906 | cur = newDoc->children->children; | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 10907 | *lst = cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10908 | while (cur != NULL) { | 
|  | 10909 | cur->parent = NULL; | 
|  | 10910 | cur = cur->next; | 
|  | 10911 | } | 
|  | 10912 | newDoc->children->children = NULL; | 
|  | 10913 | } | 
|  | 10914 | ret = 0; | 
|  | 10915 | } | 
|  | 10916 | ctxt->sax = oldsax; | 
| Daniel Veillard | e4e3f5d | 2003-10-28 23:06:32 +0000 | [diff] [blame] | 10917 | ctxt->dict = NULL; | 
|  | 10918 | ctxt->attsDefault = NULL; | 
|  | 10919 | ctxt->attsSpecial = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10920 | xmlFreeParserCtxt(ctxt); | 
|  | 10921 | newDoc->intSubset = NULL; | 
|  | 10922 | newDoc->extSubset = NULL; | 
|  | 10923 | xmlFreeDoc(newDoc); | 
|  | 10924 |  | 
|  | 10925 | return(ret); | 
|  | 10926 | } | 
|  | 10927 |  | 
|  | 10928 | /** | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 10929 | * xmlParseExternalEntityPrivate: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10930 | * @doc:  the document the chunk pertains to | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 10931 | * @oldctxt:  the previous parser context if available | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10932 | * @sax:  the SAX handler bloc (possibly NULL) | 
|  | 10933 | * @user_data:  The user data returned on SAX callbacks (possibly NULL) | 
|  | 10934 | * @depth:  Used for loop detection, use 0 | 
|  | 10935 | * @URL:  the URL for the entity to load | 
|  | 10936 | * @ID:  the System ID for the entity to load | 
|  | 10937 | * @list:  the return value for the set of parsed nodes | 
|  | 10938 | * | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 10939 | * Private version of xmlParseExternalEntity() | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10940 | * | 
|  | 10941 | * Returns 0 if the entity is well formed, -1 in case of args problem and | 
|  | 10942 | *    the parser error code otherwise | 
|  | 10943 | */ | 
|  | 10944 |  | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 10945 | static xmlParserErrors | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 10946 | xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, | 
|  | 10947 | xmlSAXHandlerPtr sax, | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 10948 | void *user_data, int depth, const xmlChar *URL, | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 10949 | const xmlChar *ID, xmlNodePtr *list) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10950 | xmlParserCtxtPtr ctxt; | 
|  | 10951 | xmlDocPtr newDoc; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 10952 | xmlNodePtr newRoot; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10953 | xmlSAXHandlerPtr oldsax = NULL; | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 10954 | xmlParserErrors ret = XML_ERR_OK; | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 10955 | xmlChar start[4]; | 
|  | 10956 | xmlCharEncoding enc; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10957 |  | 
|  | 10958 | if (depth > 40) { | 
|  | 10959 | return(XML_ERR_ENTITY_LOOP); | 
|  | 10960 | } | 
|  | 10961 |  | 
|  | 10962 |  | 
|  | 10963 |  | 
|  | 10964 | if (list != NULL) | 
|  | 10965 | *list = NULL; | 
|  | 10966 | if ((URL == NULL) && (ID == NULL)) | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 10967 | return(XML_ERR_INTERNAL_ERROR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10968 | if (doc == NULL) /* @@ relax but check for dereferences */ | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 10969 | return(XML_ERR_INTERNAL_ERROR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10970 |  | 
|  | 10971 |  | 
|  | 10972 | ctxt = xmlCreateEntityParserCtxt(URL, ID, NULL); | 
| William M. Brack | b670e2e | 2003-09-27 01:05:55 +0000 | [diff] [blame] | 10973 | if (ctxt == NULL) return(XML_WAR_UNDECLARED_ENTITY); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10974 | ctxt->userData = ctxt; | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 10975 | if (oldctxt != NULL) { | 
|  | 10976 | ctxt->_private = oldctxt->_private; | 
|  | 10977 | ctxt->loadsubset = oldctxt->loadsubset; | 
|  | 10978 | ctxt->validate = oldctxt->validate; | 
|  | 10979 | ctxt->external = oldctxt->external; | 
| Daniel Veillard | 44e1dd0 | 2003-02-21 23:23:28 +0000 | [diff] [blame] | 10980 | ctxt->record_info = oldctxt->record_info; | 
|  | 10981 | ctxt->node_seq.maximum = oldctxt->node_seq.maximum; | 
|  | 10982 | ctxt->node_seq.length = oldctxt->node_seq.length; | 
|  | 10983 | ctxt->node_seq.buffer = oldctxt->node_seq.buffer; | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 10984 | } else { | 
|  | 10985 | /* | 
|  | 10986 | * Doing validity checking on chunk without context | 
|  | 10987 | * doesn't make sense | 
|  | 10988 | */ | 
|  | 10989 | ctxt->_private = NULL; | 
|  | 10990 | ctxt->validate = 0; | 
|  | 10991 | ctxt->external = 2; | 
|  | 10992 | ctxt->loadsubset = 0; | 
|  | 10993 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 10994 | if (sax != NULL) { | 
|  | 10995 | oldsax = ctxt->sax; | 
|  | 10996 | ctxt->sax = sax; | 
|  | 10997 | if (user_data != NULL) | 
|  | 10998 | ctxt->userData = user_data; | 
|  | 10999 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 11000 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11001 | newDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 11002 | if (newDoc == NULL) { | 
| Daniel Veillard | 44e1dd0 | 2003-02-21 23:23:28 +0000 | [diff] [blame] | 11003 | ctxt->node_seq.maximum = 0; | 
|  | 11004 | ctxt->node_seq.length = 0; | 
|  | 11005 | ctxt->node_seq.buffer = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11006 | xmlFreeParserCtxt(ctxt); | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11007 | return(XML_ERR_INTERNAL_ERROR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11008 | } | 
|  | 11009 | if (doc != NULL) { | 
|  | 11010 | newDoc->intSubset = doc->intSubset; | 
|  | 11011 | newDoc->extSubset = doc->extSubset; | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11012 | newDoc->dict = doc->dict; | 
|  | 11013 | } else if (oldctxt != NULL) { | 
|  | 11014 | newDoc->dict = oldctxt->dict; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11015 | } | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11016 | xmlDictReference(newDoc->dict); | 
|  | 11017 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11018 | if (doc->URL != NULL) { | 
|  | 11019 | newDoc->URL = xmlStrdup(doc->URL); | 
|  | 11020 | } | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11021 | newRoot = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); | 
|  | 11022 | if (newRoot == NULL) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11023 | if (sax != NULL) | 
|  | 11024 | ctxt->sax = oldsax; | 
| Daniel Veillard | 44e1dd0 | 2003-02-21 23:23:28 +0000 | [diff] [blame] | 11025 | ctxt->node_seq.maximum = 0; | 
|  | 11026 | ctxt->node_seq.length = 0; | 
|  | 11027 | ctxt->node_seq.buffer = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11028 | xmlFreeParserCtxt(ctxt); | 
|  | 11029 | newDoc->intSubset = NULL; | 
|  | 11030 | newDoc->extSubset = NULL; | 
|  | 11031 | xmlFreeDoc(newDoc); | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11032 | return(XML_ERR_INTERNAL_ERROR); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11033 | } | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11034 | xmlAddChild((xmlNodePtr) newDoc, newRoot); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11035 | nodePush(ctxt, newDoc->children); | 
|  | 11036 | if (doc == NULL) { | 
|  | 11037 | ctxt->myDoc = newDoc; | 
|  | 11038 | } else { | 
|  | 11039 | ctxt->myDoc = doc; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11040 | newRoot->doc = doc; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11041 | } | 
|  | 11042 |  | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 11043 | /* | 
|  | 11044 | * Get the 4 first bytes and decode the charset | 
|  | 11045 | * if enc != XML_CHAR_ENCODING_NONE | 
|  | 11046 | * plug some encoding conversion routines. | 
|  | 11047 | */ | 
|  | 11048 | GROW; | 
| Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 11049 | if ((ctxt->input->end - ctxt->input->cur) >= 4) { | 
|  | 11050 | start[0] = RAW; | 
|  | 11051 | start[1] = NXT(1); | 
|  | 11052 | start[2] = NXT(2); | 
|  | 11053 | start[3] = NXT(3); | 
|  | 11054 | enc = xmlDetectCharEncoding(start, 4); | 
|  | 11055 | if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 11056 | xmlSwitchEncoding(ctxt, enc); | 
|  | 11057 | } | 
| Daniel Veillard | 87a764e | 2001-06-20 17:41:10 +0000 | [diff] [blame] | 11058 | } | 
|  | 11059 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11060 | /* | 
|  | 11061 | * Parse a possible text declaration first | 
|  | 11062 | */ | 
| Daniel Veillard | a07050d | 2003-10-19 14:46:32 +0000 | [diff] [blame] | 11063 | if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11064 | xmlParseTextDecl(ctxt); | 
|  | 11065 | } | 
|  | 11066 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11067 | ctxt->instate = XML_PARSER_CONTENT; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11068 | ctxt->depth = depth; | 
|  | 11069 |  | 
|  | 11070 | xmlParseContent(ctxt); | 
|  | 11071 |  | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 11072 | if ((RAW == '<') && (NXT(1) == '/')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11073 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 11074 | } else if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11075 | xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11076 | } | 
|  | 11077 | if (ctxt->node != newDoc->children) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11078 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11079 | } | 
|  | 11080 |  | 
|  | 11081 | if (!ctxt->wellFormed) { | 
|  | 11082 | if (ctxt->errNo == 0) | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11083 | ret = XML_ERR_INTERNAL_ERROR; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11084 | else | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11085 | ret = (xmlParserErrors)ctxt->errNo; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11086 | } else { | 
|  | 11087 | if (list != NULL) { | 
|  | 11088 | xmlNodePtr cur; | 
|  | 11089 |  | 
|  | 11090 | /* | 
|  | 11091 | * Return the newly created nodeset after unlinking it from | 
|  | 11092 | * they pseudo parent. | 
|  | 11093 | */ | 
|  | 11094 | cur = newDoc->children->children; | 
|  | 11095 | *list = cur; | 
|  | 11096 | while (cur != NULL) { | 
|  | 11097 | cur->parent = NULL; | 
|  | 11098 | cur = cur->next; | 
|  | 11099 | } | 
|  | 11100 | newDoc->children->children = NULL; | 
|  | 11101 | } | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11102 | ret = XML_ERR_OK; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11103 | } | 
|  | 11104 | if (sax != NULL) | 
|  | 11105 | ctxt->sax = oldsax; | 
| Daniel Veillard | 0046c0f | 2003-02-23 13:52:30 +0000 | [diff] [blame] | 11106 | oldctxt->node_seq.maximum = ctxt->node_seq.maximum; | 
|  | 11107 | oldctxt->node_seq.length = ctxt->node_seq.length; | 
|  | 11108 | oldctxt->node_seq.buffer = ctxt->node_seq.buffer; | 
| Daniel Veillard | 44e1dd0 | 2003-02-21 23:23:28 +0000 | [diff] [blame] | 11109 | ctxt->node_seq.maximum = 0; | 
|  | 11110 | ctxt->node_seq.length = 0; | 
|  | 11111 | ctxt->node_seq.buffer = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11112 | xmlFreeParserCtxt(ctxt); | 
|  | 11113 | newDoc->intSubset = NULL; | 
|  | 11114 | newDoc->extSubset = NULL; | 
|  | 11115 | xmlFreeDoc(newDoc); | 
|  | 11116 |  | 
|  | 11117 | return(ret); | 
|  | 11118 | } | 
|  | 11119 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 11120 | #ifdef LIBXML_SAX1_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11121 | /** | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 11122 | * xmlParseExternalEntity: | 
|  | 11123 | * @doc:  the document the chunk pertains to | 
|  | 11124 | * @sax:  the SAX handler bloc (possibly NULL) | 
|  | 11125 | * @user_data:  The user data returned on SAX callbacks (possibly NULL) | 
|  | 11126 | * @depth:  Used for loop detection, use 0 | 
|  | 11127 | * @URL:  the URL for the entity to load | 
|  | 11128 | * @ID:  the System ID for the entity to load | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 11129 | * @lst:  the return value for the set of parsed nodes | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 11130 | * | 
|  | 11131 | * Parse an external general entity | 
|  | 11132 | * An external general parsed entity is well-formed if it matches the | 
|  | 11133 | * production labeled extParsedEnt. | 
|  | 11134 | * | 
|  | 11135 | * [78] extParsedEnt ::= TextDecl? content | 
|  | 11136 | * | 
|  | 11137 | * Returns 0 if the entity is well formed, -1 in case of args problem and | 
|  | 11138 | *    the parser error code otherwise | 
|  | 11139 | */ | 
|  | 11140 |  | 
|  | 11141 | int | 
|  | 11142 | xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data, | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 11143 | int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *lst) { | 
| Daniel Veillard | a97a19b | 2001-05-20 13:19:52 +0000 | [diff] [blame] | 11144 | return(xmlParseExternalEntityPrivate(doc, NULL, sax, user_data, depth, URL, | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 11145 | ID, lst)); | 
| Daniel Veillard | 257d910 | 2001-05-08 10:41:44 +0000 | [diff] [blame] | 11146 | } | 
|  | 11147 |  | 
|  | 11148 | /** | 
| Daniel Veillard | e020c3a | 2001-03-21 18:06:15 +0000 | [diff] [blame] | 11149 | * xmlParseBalancedChunkMemory: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11150 | * @doc:  the document the chunk pertains to | 
|  | 11151 | * @sax:  the SAX handler bloc (possibly NULL) | 
|  | 11152 | * @user_data:  The user data returned on SAX callbacks (possibly NULL) | 
|  | 11153 | * @depth:  Used for loop detection, use 0 | 
|  | 11154 | * @string:  the input string in UTF8 or ISO-Latin (zero terminated) | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 11155 | * @lst:  the return value for the set of parsed nodes | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11156 | * | 
|  | 11157 | * Parse a well-balanced chunk of an XML document | 
|  | 11158 | * called by the parser | 
|  | 11159 | * The allowed sequence for the Well Balanced Chunk is the one defined by | 
|  | 11160 | * the content production in the XML grammar: | 
|  | 11161 | * | 
|  | 11162 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* | 
|  | 11163 | * | 
|  | 11164 | * Returns 0 if the chunk is well balanced, -1 in case of args problem and | 
|  | 11165 | *    the parser error code otherwise | 
|  | 11166 | */ | 
|  | 11167 |  | 
|  | 11168 | int | 
|  | 11169 | xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax, | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 11170 | void *user_data, int depth, const xmlChar *string, xmlNodePtr *lst) { | 
| Daniel Veillard | 58e44c9 | 2002-08-02 22:19:49 +0000 | [diff] [blame] | 11171 | return xmlParseBalancedChunkMemoryRecover( doc, sax, user_data, | 
|  | 11172 | depth, string, lst, 0 ); | 
|  | 11173 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 11174 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | 58e44c9 | 2002-08-02 22:19:49 +0000 | [diff] [blame] | 11175 |  | 
|  | 11176 | /** | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11177 | * xmlParseBalancedChunkMemoryInternal: | 
|  | 11178 | * @oldctxt:  the existing parsing context | 
|  | 11179 | * @string:  the input string in UTF8 or ISO-Latin (zero terminated) | 
|  | 11180 | * @user_data:  the user data field for the parser context | 
|  | 11181 | * @lst:  the return value for the set of parsed nodes | 
|  | 11182 | * | 
|  | 11183 | * | 
|  | 11184 | * Parse a well-balanced chunk of an XML document | 
|  | 11185 | * called by the parser | 
|  | 11186 | * The allowed sequence for the Well Balanced Chunk is the one defined by | 
|  | 11187 | * the content production in the XML grammar: | 
|  | 11188 | * | 
|  | 11189 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* | 
|  | 11190 | * | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11191 | * Returns XML_ERR_OK if the chunk is well balanced, and the parser | 
|  | 11192 | * error code otherwise | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11193 | * | 
|  | 11194 | * In case recover is set to 1, the nodelist will not be empty even if | 
|  | 11195 | * the parsed chunk is not well balanced. | 
|  | 11196 | */ | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11197 | static xmlParserErrors | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11198 | xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, | 
|  | 11199 | const xmlChar *string, void *user_data, xmlNodePtr *lst) { | 
|  | 11200 | xmlParserCtxtPtr ctxt; | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11201 | xmlDocPtr newDoc = NULL; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11202 | xmlNodePtr newRoot; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11203 | xmlSAXHandlerPtr oldsax = NULL; | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11204 | xmlNodePtr content = NULL; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11205 | xmlNodePtr last = NULL; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11206 | int size; | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11207 | xmlParserErrors ret = XML_ERR_OK; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11208 |  | 
|  | 11209 | if (oldctxt->depth > 40) { | 
|  | 11210 | return(XML_ERR_ENTITY_LOOP); | 
|  | 11211 | } | 
|  | 11212 |  | 
|  | 11213 |  | 
|  | 11214 | if (lst != NULL) | 
|  | 11215 | *lst = NULL; | 
|  | 11216 | if (string == NULL) | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11217 | return(XML_ERR_INTERNAL_ERROR); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11218 |  | 
|  | 11219 | size = xmlStrlen(string); | 
|  | 11220 |  | 
|  | 11221 | ctxt = xmlCreateMemoryParserCtxt((char *) string, size); | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11222 | if (ctxt == NULL) return(XML_WAR_UNDECLARED_ENTITY); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11223 | if (user_data != NULL) | 
|  | 11224 | ctxt->userData = user_data; | 
|  | 11225 | else | 
|  | 11226 | ctxt->userData = ctxt; | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 11227 | if (ctxt->dict != NULL) xmlDictFree(ctxt->dict); | 
|  | 11228 | ctxt->dict = oldctxt->dict; | 
| Daniel Veillard | fd343dc | 2003-10-31 10:55:22 +0000 | [diff] [blame] | 11229 | ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3); | 
|  | 11230 | ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5); | 
|  | 11231 | ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11232 |  | 
|  | 11233 | oldsax = ctxt->sax; | 
|  | 11234 | ctxt->sax = oldctxt->sax; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 11235 | xmlDetectSAX2(ctxt); | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 11236 | ctxt->replaceEntities = oldctxt->replaceEntities; | 
|  | 11237 | ctxt->options = oldctxt->options; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 11238 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 11239 | ctxt->_private = oldctxt->_private; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11240 | if (oldctxt->myDoc == NULL) { | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11241 | newDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 11242 | if (newDoc == NULL) { | 
|  | 11243 | ctxt->sax = oldsax; | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 11244 | ctxt->dict = NULL; | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11245 | xmlFreeParserCtxt(ctxt); | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11246 | return(XML_ERR_INTERNAL_ERROR); | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11247 | } | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11248 | newDoc->dict = ctxt->dict; | 
|  | 11249 | xmlDictReference(newDoc->dict); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11250 | ctxt->myDoc = newDoc; | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11251 | } else { | 
|  | 11252 | ctxt->myDoc = oldctxt->myDoc; | 
|  | 11253 | content = ctxt->myDoc->children; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11254 | last = ctxt->myDoc->last; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11255 | } | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11256 | newRoot = xmlNewDocNode(ctxt->myDoc, NULL, BAD_CAST "pseudoroot", NULL); | 
|  | 11257 | if (newRoot == NULL) { | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11258 | ctxt->sax = oldsax; | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 11259 | ctxt->dict = NULL; | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11260 | xmlFreeParserCtxt(ctxt); | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11261 | if (newDoc != NULL) { | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11262 | xmlFreeDoc(newDoc); | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11263 | } | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11264 | return(XML_ERR_INTERNAL_ERROR); | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11265 | } | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11266 | ctxt->myDoc->children = NULL; | 
|  | 11267 | ctxt->myDoc->last = NULL; | 
|  | 11268 | xmlAddChild((xmlNodePtr) ctxt->myDoc, newRoot); | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11269 | nodePush(ctxt, ctxt->myDoc->children); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11270 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 11271 | ctxt->depth = oldctxt->depth + 1; | 
|  | 11272 |  | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11273 | ctxt->validate = 0; | 
|  | 11274 | ctxt->loadsubset = oldctxt->loadsubset; | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 11275 | if ((oldctxt->validate) || (oldctxt->replaceEntities != 0)) { | 
|  | 11276 | /* | 
|  | 11277 | * ID/IDREF registration will be done in xmlValidateElement below | 
|  | 11278 | */ | 
|  | 11279 | ctxt->loadsubset |= XML_SKIP_IDS; | 
|  | 11280 | } | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 11281 | ctxt->dictNames = oldctxt->dictNames; | 
| Daniel Veillard | 95d2d5b | 2003-10-27 14:54:49 +0000 | [diff] [blame] | 11282 | ctxt->attsDefault = oldctxt->attsDefault; | 
|  | 11283 | ctxt->attsSpecial = oldctxt->attsSpecial; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11284 |  | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11285 | xmlParseContent(ctxt); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11286 | if ((RAW == '<') && (NXT(1) == '/')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11287 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11288 | } else if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11289 | xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11290 | } | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11291 | if (ctxt->node != ctxt->myDoc->children) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11292 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11293 | } | 
|  | 11294 |  | 
|  | 11295 | if (!ctxt->wellFormed) { | 
|  | 11296 | if (ctxt->errNo == 0) | 
| Daniel Veillard | 7d51575 | 2003-09-26 19:12:37 +0000 | [diff] [blame] | 11297 | ret = XML_ERR_INTERNAL_ERROR; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11298 | else | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11299 | ret = (xmlParserErrors)ctxt->errNo; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11300 | } else { | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11301 | ret = XML_ERR_OK; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11302 | } | 
|  | 11303 |  | 
| William M. Brack | 7b9154b | 2003-09-27 19:23:50 +0000 | [diff] [blame] | 11304 | if ((lst != NULL) && (ret == XML_ERR_OK)) { | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11305 | xmlNodePtr cur; | 
|  | 11306 |  | 
|  | 11307 | /* | 
|  | 11308 | * Return the newly created nodeset after unlinking it from | 
|  | 11309 | * they pseudo parent. | 
|  | 11310 | */ | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11311 | cur = ctxt->myDoc->children->children; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11312 | *lst = cur; | 
|  | 11313 | while (cur != NULL) { | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 11314 | #ifdef LIBXML_VALID_ENABLED | 
| Daniel Veillard | 8d58904 | 2003-02-04 15:07:21 +0000 | [diff] [blame] | 11315 | if (oldctxt->validate && oldctxt->wellFormed && | 
|  | 11316 | oldctxt->myDoc && oldctxt->myDoc->intSubset) { | 
|  | 11317 | oldctxt->valid &= xmlValidateElement(&oldctxt->vctxt, | 
|  | 11318 | oldctxt->myDoc, cur); | 
|  | 11319 | } | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 11320 | #endif /* LIBXML_VALID_ENABLED */ | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11321 | cur->parent = NULL; | 
|  | 11322 | cur = cur->next; | 
|  | 11323 | } | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11324 | ctxt->myDoc->children->children = NULL; | 
|  | 11325 | } | 
|  | 11326 | if (ctxt->myDoc != NULL) { | 
|  | 11327 | xmlFreeNode(ctxt->myDoc->children); | 
|  | 11328 | ctxt->myDoc->children = content; | 
| Daniel Veillard | 8de5c0b | 2004-10-07 13:14:19 +0000 | [diff] [blame] | 11329 | ctxt->myDoc->last = last; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11330 | } | 
|  | 11331 |  | 
|  | 11332 | ctxt->sax = oldsax; | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 11333 | ctxt->dict = NULL; | 
| Daniel Veillard | 95d2d5b | 2003-10-27 14:54:49 +0000 | [diff] [blame] | 11334 | ctxt->attsDefault = NULL; | 
|  | 11335 | ctxt->attsSpecial = NULL; | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11336 | xmlFreeParserCtxt(ctxt); | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11337 | if (newDoc != NULL) { | 
| Daniel Veillard | 68e9e74 | 2002-11-16 15:35:11 +0000 | [diff] [blame] | 11338 | xmlFreeDoc(newDoc); | 
| Daniel Veillard | 03a53c3 | 2004-10-26 16:06:51 +0000 | [diff] [blame] | 11339 | } | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11340 |  | 
|  | 11341 | return(ret); | 
|  | 11342 | } | 
|  | 11343 |  | 
| Daniel Veillard | 29b1748 | 2004-08-16 00:39:03 +0000 | [diff] [blame] | 11344 | /** | 
|  | 11345 | * xmlParseInNodeContext: | 
|  | 11346 | * @node:  the context node | 
|  | 11347 | * @data:  the input string | 
|  | 11348 | * @datalen:  the input string length in bytes | 
|  | 11349 | * @options:  a combination of xmlParserOption | 
|  | 11350 | * @lst:  the return value for the set of parsed nodes | 
|  | 11351 | * | 
|  | 11352 | * Parse a well-balanced chunk of an XML document | 
|  | 11353 | * within the context (DTD, namespaces, etc ...) of the given node. | 
|  | 11354 | * | 
|  | 11355 | * The allowed sequence for the data is a Well Balanced Chunk defined by | 
|  | 11356 | * the content production in the XML grammar: | 
|  | 11357 | * | 
|  | 11358 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* | 
|  | 11359 | * | 
|  | 11360 | * Returns XML_ERR_OK if the chunk is well balanced, and the parser | 
|  | 11361 | * error code otherwise | 
|  | 11362 | */ | 
|  | 11363 | xmlParserErrors | 
|  | 11364 | xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen, | 
|  | 11365 | int options, xmlNodePtr *lst) { | 
|  | 11366 | #ifdef SAX2 | 
|  | 11367 | xmlParserCtxtPtr ctxt; | 
|  | 11368 | xmlDocPtr doc = NULL; | 
|  | 11369 | xmlNodePtr fake, cur; | 
|  | 11370 | int nsnr = 0; | 
|  | 11371 |  | 
|  | 11372 | xmlParserErrors ret = XML_ERR_OK; | 
|  | 11373 |  | 
|  | 11374 | /* | 
|  | 11375 | * check all input parameters, grab the document | 
|  | 11376 | */ | 
|  | 11377 | if ((lst == NULL) || (node == NULL) || (data == NULL) || (datalen < 0)) | 
|  | 11378 | return(XML_ERR_INTERNAL_ERROR); | 
|  | 11379 | switch (node->type) { | 
|  | 11380 | case XML_ELEMENT_NODE: | 
|  | 11381 | case XML_ATTRIBUTE_NODE: | 
|  | 11382 | case XML_TEXT_NODE: | 
|  | 11383 | case XML_CDATA_SECTION_NODE: | 
|  | 11384 | case XML_ENTITY_REF_NODE: | 
|  | 11385 | case XML_PI_NODE: | 
|  | 11386 | case XML_COMMENT_NODE: | 
|  | 11387 | case XML_DOCUMENT_NODE: | 
|  | 11388 | case XML_HTML_DOCUMENT_NODE: | 
|  | 11389 | break; | 
|  | 11390 | default: | 
|  | 11391 | return(XML_ERR_INTERNAL_ERROR); | 
|  | 11392 |  | 
|  | 11393 | } | 
|  | 11394 | while ((node != NULL) && (node->type != XML_ELEMENT_NODE) && | 
|  | 11395 | (node->type != XML_DOCUMENT_NODE) && | 
|  | 11396 | (node->type != XML_HTML_DOCUMENT_NODE)) | 
|  | 11397 | node = node->parent; | 
|  | 11398 | if (node == NULL) | 
|  | 11399 | return(XML_ERR_INTERNAL_ERROR); | 
|  | 11400 | if (node->type == XML_ELEMENT_NODE) | 
|  | 11401 | doc = node->doc; | 
|  | 11402 | else | 
|  | 11403 | doc = (xmlDocPtr) node; | 
|  | 11404 | if (doc == NULL) | 
|  | 11405 | return(XML_ERR_INTERNAL_ERROR); | 
|  | 11406 |  | 
|  | 11407 | /* | 
|  | 11408 | * allocate a context and set-up everything not related to the | 
|  | 11409 | * node position in the tree | 
|  | 11410 | */ | 
|  | 11411 | if (doc->type == XML_DOCUMENT_NODE) | 
|  | 11412 | ctxt = xmlCreateMemoryParserCtxt((char *) data, datalen); | 
|  | 11413 | #ifdef LIBXML_HTML_ENABLED | 
|  | 11414 | else if (doc->type == XML_HTML_DOCUMENT_NODE) | 
|  | 11415 | ctxt = htmlCreateMemoryParserCtxt((char *) data, datalen); | 
|  | 11416 | #endif | 
|  | 11417 | else | 
|  | 11418 | return(XML_ERR_INTERNAL_ERROR); | 
|  | 11419 |  | 
|  | 11420 | if (ctxt == NULL) | 
|  | 11421 | return(XML_ERR_NO_MEMORY); | 
|  | 11422 | fake = xmlNewComment(NULL); | 
|  | 11423 | if (fake == NULL) { | 
|  | 11424 | xmlFreeParserCtxt(ctxt); | 
|  | 11425 | return(XML_ERR_NO_MEMORY); | 
|  | 11426 | } | 
|  | 11427 | xmlAddChild(node, fake); | 
| William M. Brack | c3f8134 | 2004-10-03 01:22:44 +0000 | [diff] [blame] | 11428 |  | 
|  | 11429 | /* | 
|  | 11430 | * Use input doc's dict if present, else assure XML_PARSE_NODICT is set. | 
|  | 11431 | * We need a dictionary for xmlDetectSAX2, so if there's no doc dict | 
|  | 11432 | * we must wait until the last moment to free the original one. | 
|  | 11433 | */ | 
| Daniel Veillard | 29b1748 | 2004-08-16 00:39:03 +0000 | [diff] [blame] | 11434 | if (doc->dict != NULL) { | 
| William M. Brack | c3f8134 | 2004-10-03 01:22:44 +0000 | [diff] [blame] | 11435 | if (ctxt->dict != NULL) | 
| Daniel Veillard | 29b1748 | 2004-08-16 00:39:03 +0000 | [diff] [blame] | 11436 | xmlDictFree(ctxt->dict); | 
|  | 11437 | ctxt->dict = doc->dict; | 
| William M. Brack | c3f8134 | 2004-10-03 01:22:44 +0000 | [diff] [blame] | 11438 | } else | 
|  | 11439 | options |= XML_PARSE_NODICT; | 
|  | 11440 |  | 
|  | 11441 | xmlCtxtUseOptions(ctxt, options); | 
| Daniel Veillard | 29b1748 | 2004-08-16 00:39:03 +0000 | [diff] [blame] | 11442 | xmlDetectSAX2(ctxt); | 
|  | 11443 | ctxt->myDoc = doc; | 
|  | 11444 |  | 
|  | 11445 | if (node->type == XML_ELEMENT_NODE) { | 
|  | 11446 | nodePush(ctxt, node); | 
|  | 11447 | /* | 
|  | 11448 | * initialize the SAX2 namespaces stack | 
|  | 11449 | */ | 
|  | 11450 | cur = node; | 
|  | 11451 | while ((cur != NULL) && (cur->type == XML_ELEMENT_NODE)) { | 
|  | 11452 | xmlNsPtr ns = cur->nsDef; | 
|  | 11453 | const xmlChar *iprefix, *ihref; | 
|  | 11454 |  | 
|  | 11455 | while (ns != NULL) { | 
|  | 11456 | if (ctxt->dict) { | 
|  | 11457 | iprefix = xmlDictLookup(ctxt->dict, ns->prefix, -1); | 
|  | 11458 | ihref = xmlDictLookup(ctxt->dict, ns->href, -1); | 
|  | 11459 | } else { | 
|  | 11460 | iprefix = ns->prefix; | 
|  | 11461 | ihref = ns->href; | 
|  | 11462 | } | 
|  | 11463 |  | 
|  | 11464 | if (xmlGetNamespace(ctxt, iprefix) == NULL) { | 
|  | 11465 | nsPush(ctxt, iprefix, ihref); | 
|  | 11466 | nsnr++; | 
|  | 11467 | } | 
|  | 11468 | ns = ns->next; | 
|  | 11469 | } | 
|  | 11470 | cur = cur->parent; | 
|  | 11471 | } | 
|  | 11472 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 11473 | } | 
|  | 11474 |  | 
|  | 11475 | if ((ctxt->validate) || (ctxt->replaceEntities != 0)) { | 
|  | 11476 | /* | 
|  | 11477 | * ID/IDREF registration will be done in xmlValidateElement below | 
|  | 11478 | */ | 
|  | 11479 | ctxt->loadsubset |= XML_SKIP_IDS; | 
|  | 11480 | } | 
|  | 11481 |  | 
|  | 11482 | xmlParseContent(ctxt); | 
|  | 11483 | nsPop(ctxt, nsnr); | 
|  | 11484 | if ((RAW == '<') && (NXT(1) == '/')) { | 
|  | 11485 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
|  | 11486 | } else if (RAW != 0) { | 
|  | 11487 | xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); | 
|  | 11488 | } | 
|  | 11489 | if ((ctxt->node != NULL) && (ctxt->node != node)) { | 
|  | 11490 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
|  | 11491 | ctxt->wellFormed = 0; | 
|  | 11492 | } | 
|  | 11493 |  | 
|  | 11494 | if (!ctxt->wellFormed) { | 
|  | 11495 | if (ctxt->errNo == 0) | 
|  | 11496 | ret = XML_ERR_INTERNAL_ERROR; | 
|  | 11497 | else | 
|  | 11498 | ret = (xmlParserErrors)ctxt->errNo; | 
|  | 11499 | } else { | 
|  | 11500 | ret = XML_ERR_OK; | 
|  | 11501 | } | 
|  | 11502 |  | 
|  | 11503 | /* | 
|  | 11504 | * Return the newly created nodeset after unlinking it from | 
|  | 11505 | * the pseudo sibling. | 
|  | 11506 | */ | 
|  | 11507 |  | 
|  | 11508 | cur = fake->next; | 
|  | 11509 | fake->next = NULL; | 
|  | 11510 | node->last = fake; | 
|  | 11511 |  | 
|  | 11512 | if (cur != NULL) { | 
|  | 11513 | cur->prev = NULL; | 
|  | 11514 | } | 
|  | 11515 |  | 
|  | 11516 | *lst = cur; | 
|  | 11517 |  | 
|  | 11518 | while (cur != NULL) { | 
|  | 11519 | cur->parent = NULL; | 
|  | 11520 | cur = cur->next; | 
|  | 11521 | } | 
|  | 11522 |  | 
|  | 11523 | xmlUnlinkNode(fake); | 
|  | 11524 | xmlFreeNode(fake); | 
|  | 11525 |  | 
|  | 11526 |  | 
|  | 11527 | if (ret != XML_ERR_OK) { | 
|  | 11528 | xmlFreeNodeList(*lst); | 
|  | 11529 | *lst = NULL; | 
|  | 11530 | } | 
| William M. Brack | c3f8134 | 2004-10-03 01:22:44 +0000 | [diff] [blame] | 11531 |  | 
| William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 11532 | if (doc->dict != NULL) | 
|  | 11533 | ctxt->dict = NULL; | 
| Daniel Veillard | 29b1748 | 2004-08-16 00:39:03 +0000 | [diff] [blame] | 11534 | xmlFreeParserCtxt(ctxt); | 
|  | 11535 |  | 
|  | 11536 | return(ret); | 
|  | 11537 | #else /* !SAX2 */ | 
|  | 11538 | return(XML_ERR_INTERNAL_ERROR); | 
|  | 11539 | #endif | 
|  | 11540 | } | 
|  | 11541 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 11542 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 328f48c | 2002-11-15 15:24:34 +0000 | [diff] [blame] | 11543 | /** | 
| Daniel Veillard | 58e44c9 | 2002-08-02 22:19:49 +0000 | [diff] [blame] | 11544 | * xmlParseBalancedChunkMemoryRecover: | 
|  | 11545 | * @doc:  the document the chunk pertains to | 
|  | 11546 | * @sax:  the SAX handler bloc (possibly NULL) | 
|  | 11547 | * @user_data:  The user data returned on SAX callbacks (possibly NULL) | 
|  | 11548 | * @depth:  Used for loop detection, use 0 | 
|  | 11549 | * @string:  the input string in UTF8 or ISO-Latin (zero terminated) | 
|  | 11550 | * @lst:  the return value for the set of parsed nodes | 
|  | 11551 | * @recover: return nodes even if the data is broken (use 0) | 
|  | 11552 | * | 
|  | 11553 | * | 
|  | 11554 | * Parse a well-balanced chunk of an XML document | 
|  | 11555 | * called by the parser | 
|  | 11556 | * The allowed sequence for the Well Balanced Chunk is the one defined by | 
|  | 11557 | * the content production in the XML grammar: | 
|  | 11558 | * | 
|  | 11559 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* | 
|  | 11560 | * | 
|  | 11561 | * Returns 0 if the chunk is well balanced, -1 in case of args problem and | 
|  | 11562 | *    the parser error code otherwise | 
|  | 11563 | * | 
|  | 11564 | * In case recover is set to 1, the nodelist will not be empty even if | 
|  | 11565 | * the parsed chunk is not well balanced. | 
|  | 11566 | */ | 
|  | 11567 | int | 
|  | 11568 | xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax, | 
|  | 11569 | void *user_data, int depth, const xmlChar *string, xmlNodePtr *lst, | 
|  | 11570 | int recover) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11571 | xmlParserCtxtPtr ctxt; | 
|  | 11572 | xmlDocPtr newDoc; | 
|  | 11573 | xmlSAXHandlerPtr oldsax = NULL; | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11574 | xmlNodePtr content, newRoot; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11575 | int size; | 
|  | 11576 | int ret = 0; | 
|  | 11577 |  | 
|  | 11578 | if (depth > 40) { | 
|  | 11579 | return(XML_ERR_ENTITY_LOOP); | 
|  | 11580 | } | 
|  | 11581 |  | 
|  | 11582 |  | 
| Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 11583 | if (lst != NULL) | 
|  | 11584 | *lst = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11585 | if (string == NULL) | 
|  | 11586 | return(-1); | 
|  | 11587 |  | 
|  | 11588 | size = xmlStrlen(string); | 
|  | 11589 |  | 
|  | 11590 | ctxt = xmlCreateMemoryParserCtxt((char *) string, size); | 
|  | 11591 | if (ctxt == NULL) return(-1); | 
|  | 11592 | ctxt->userData = ctxt; | 
|  | 11593 | if (sax != NULL) { | 
|  | 11594 | oldsax = ctxt->sax; | 
|  | 11595 | ctxt->sax = sax; | 
|  | 11596 | if (user_data != NULL) | 
|  | 11597 | ctxt->userData = user_data; | 
|  | 11598 | } | 
|  | 11599 | newDoc = xmlNewDoc(BAD_CAST "1.0"); | 
|  | 11600 | if (newDoc == NULL) { | 
|  | 11601 | xmlFreeParserCtxt(ctxt); | 
|  | 11602 | return(-1); | 
|  | 11603 | } | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11604 | if ((doc != NULL) && (doc->dict != NULL)) { | 
|  | 11605 | xmlDictFree(ctxt->dict); | 
|  | 11606 | ctxt->dict = doc->dict; | 
|  | 11607 | xmlDictReference(ctxt->dict); | 
|  | 11608 | ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3); | 
|  | 11609 | ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5); | 
|  | 11610 | ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36); | 
|  | 11611 | ctxt->dictNames = 1; | 
|  | 11612 | } else { | 
|  | 11613 | xmlCtxtUseOptions(ctxt, XML_PARSE_NODICT); | 
|  | 11614 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11615 | if (doc != NULL) { | 
|  | 11616 | newDoc->intSubset = doc->intSubset; | 
|  | 11617 | newDoc->extSubset = doc->extSubset; | 
|  | 11618 | } | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11619 | newRoot = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); | 
|  | 11620 | if (newRoot == NULL) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11621 | if (sax != NULL) | 
|  | 11622 | ctxt->sax = oldsax; | 
|  | 11623 | xmlFreeParserCtxt(ctxt); | 
|  | 11624 | newDoc->intSubset = NULL; | 
|  | 11625 | newDoc->extSubset = NULL; | 
|  | 11626 | xmlFreeDoc(newDoc); | 
|  | 11627 | return(-1); | 
|  | 11628 | } | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11629 | xmlAddChild((xmlNodePtr) newDoc, newRoot); | 
|  | 11630 | nodePush(ctxt, newRoot); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11631 | if (doc == NULL) { | 
|  | 11632 | ctxt->myDoc = newDoc; | 
|  | 11633 | } else { | 
| Daniel Veillard | 42766c0 | 2002-08-22 20:52:17 +0000 | [diff] [blame] | 11634 | ctxt->myDoc = newDoc; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11635 | newDoc->children->doc = doc; | 
|  | 11636 | } | 
|  | 11637 | ctxt->instate = XML_PARSER_CONTENT; | 
|  | 11638 | ctxt->depth = depth; | 
|  | 11639 |  | 
|  | 11640 | /* | 
|  | 11641 | * Doing validity checking on chunk doesn't make sense | 
|  | 11642 | */ | 
|  | 11643 | ctxt->validate = 0; | 
|  | 11644 | ctxt->loadsubset = 0; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 11645 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11646 |  | 
| Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 11647 | if ( doc != NULL ){ | 
|  | 11648 | content = doc->children; | 
|  | 11649 | doc->children = NULL; | 
|  | 11650 | xmlParseContent(ctxt); | 
|  | 11651 | doc->children = content; | 
|  | 11652 | } | 
|  | 11653 | else { | 
|  | 11654 | xmlParseContent(ctxt); | 
|  | 11655 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11656 | if ((RAW == '<') && (NXT(1) == '/')) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11657 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11658 | } else if (RAW != 0) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11659 | xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11660 | } | 
|  | 11661 | if (ctxt->node != newDoc->children) { | 
| Daniel Veillard | 1afc9f3 | 2003-09-13 12:44:05 +0000 | [diff] [blame] | 11662 | xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11663 | } | 
|  | 11664 |  | 
|  | 11665 | if (!ctxt->wellFormed) { | 
|  | 11666 | if (ctxt->errNo == 0) | 
|  | 11667 | ret = 1; | 
|  | 11668 | else | 
|  | 11669 | ret = ctxt->errNo; | 
|  | 11670 | } else { | 
| Daniel Veillard | 58e44c9 | 2002-08-02 22:19:49 +0000 | [diff] [blame] | 11671 | ret = 0; | 
|  | 11672 | } | 
|  | 11673 |  | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11674 | if ((lst != NULL) && ((ret == 0) || (recover == 1))) { | 
|  | 11675 | xmlNodePtr cur; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11676 |  | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11677 | /* | 
|  | 11678 | * Return the newly created nodeset after unlinking it from | 
|  | 11679 | * they pseudo parent. | 
|  | 11680 | */ | 
|  | 11681 | cur = newDoc->children->children; | 
|  | 11682 | *lst = cur; | 
|  | 11683 | while (cur != NULL) { | 
|  | 11684 | xmlSetTreeDoc(cur, doc); | 
|  | 11685 | cur->parent = NULL; | 
|  | 11686 | cur = cur->next; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11687 | } | 
| Daniel Veillard | acbe6cf | 2004-10-31 21:04:50 +0000 | [diff] [blame] | 11688 | newDoc->children->children = NULL; | 
|  | 11689 | } | 
| Daniel Veillard | 58e44c9 | 2002-08-02 22:19:49 +0000 | [diff] [blame] | 11690 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11691 | if (sax != NULL) | 
|  | 11692 | ctxt->sax = oldsax; | 
|  | 11693 | xmlFreeParserCtxt(ctxt); | 
|  | 11694 | newDoc->intSubset = NULL; | 
|  | 11695 | newDoc->extSubset = NULL; | 
|  | 11696 | xmlFreeDoc(newDoc); | 
|  | 11697 |  | 
|  | 11698 | return(ret); | 
|  | 11699 | } | 
|  | 11700 |  | 
|  | 11701 | /** | 
|  | 11702 | * xmlSAXParseEntity: | 
|  | 11703 | * @sax:  the SAX handler block | 
|  | 11704 | * @filename:  the filename | 
|  | 11705 | * | 
|  | 11706 | * parse an XML external entity out of context and build a tree. | 
|  | 11707 | * It use the given SAX function block to handle the parsing callback. | 
|  | 11708 | * If sax is NULL, fallback to the default DOM tree building routines. | 
|  | 11709 | * | 
|  | 11710 | * [78] extParsedEnt ::= TextDecl? content | 
|  | 11711 | * | 
|  | 11712 | * This correspond to a "Well Balanced" chunk | 
|  | 11713 | * | 
|  | 11714 | * Returns the resulting document tree | 
|  | 11715 | */ | 
|  | 11716 |  | 
|  | 11717 | xmlDocPtr | 
|  | 11718 | xmlSAXParseEntity(xmlSAXHandlerPtr sax, const char *filename) { | 
|  | 11719 | xmlDocPtr ret; | 
|  | 11720 | xmlParserCtxtPtr ctxt; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11721 |  | 
|  | 11722 | ctxt = xmlCreateFileParserCtxt(filename); | 
|  | 11723 | if (ctxt == NULL) { | 
|  | 11724 | return(NULL); | 
|  | 11725 | } | 
|  | 11726 | if (sax != NULL) { | 
|  | 11727 | if (ctxt->sax != NULL) | 
|  | 11728 | xmlFree(ctxt->sax); | 
|  | 11729 | ctxt->sax = sax; | 
|  | 11730 | ctxt->userData = NULL; | 
|  | 11731 | } | 
|  | 11732 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11733 | xmlParseExtParsedEnt(ctxt); | 
|  | 11734 |  | 
|  | 11735 | if (ctxt->wellFormed) | 
|  | 11736 | ret = ctxt->myDoc; | 
|  | 11737 | else { | 
|  | 11738 | ret = NULL; | 
|  | 11739 | xmlFreeDoc(ctxt->myDoc); | 
|  | 11740 | ctxt->myDoc = NULL; | 
|  | 11741 | } | 
|  | 11742 | if (sax != NULL) | 
|  | 11743 | ctxt->sax = NULL; | 
|  | 11744 | xmlFreeParserCtxt(ctxt); | 
|  | 11745 |  | 
|  | 11746 | return(ret); | 
|  | 11747 | } | 
|  | 11748 |  | 
|  | 11749 | /** | 
|  | 11750 | * xmlParseEntity: | 
|  | 11751 | * @filename:  the filename | 
|  | 11752 | * | 
|  | 11753 | * parse an XML external entity out of context and build a tree. | 
|  | 11754 | * | 
|  | 11755 | * [78] extParsedEnt ::= TextDecl? content | 
|  | 11756 | * | 
|  | 11757 | * This correspond to a "Well Balanced" chunk | 
|  | 11758 | * | 
|  | 11759 | * Returns the resulting document tree | 
|  | 11760 | */ | 
|  | 11761 |  | 
|  | 11762 | xmlDocPtr | 
|  | 11763 | xmlParseEntity(const char *filename) { | 
|  | 11764 | return(xmlSAXParseEntity(NULL, filename)); | 
|  | 11765 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 11766 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11767 |  | 
|  | 11768 | /** | 
|  | 11769 | * xmlCreateEntityParserCtxt: | 
|  | 11770 | * @URL:  the entity URL | 
|  | 11771 | * @ID:  the entity PUBLIC ID | 
| Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 11772 | * @base:  a possible base for the target URI | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11773 | * | 
|  | 11774 | * Create a parser context for an external entity | 
|  | 11775 | * Automatic support for ZLIB/Compress compressed document is provided | 
|  | 11776 | * by default if found at compile-time. | 
|  | 11777 | * | 
|  | 11778 | * Returns the new parser context or NULL | 
|  | 11779 | */ | 
|  | 11780 | xmlParserCtxtPtr | 
|  | 11781 | xmlCreateEntityParserCtxt(const xmlChar *URL, const xmlChar *ID, | 
|  | 11782 | const xmlChar *base) { | 
|  | 11783 | xmlParserCtxtPtr ctxt; | 
|  | 11784 | xmlParserInputPtr inputStream; | 
|  | 11785 | char *directory = NULL; | 
|  | 11786 | xmlChar *uri; | 
|  | 11787 |  | 
|  | 11788 | ctxt = xmlNewParserCtxt(); | 
|  | 11789 | if (ctxt == NULL) { | 
|  | 11790 | return(NULL); | 
|  | 11791 | } | 
|  | 11792 |  | 
|  | 11793 | uri = xmlBuildURI(URL, base); | 
|  | 11794 |  | 
|  | 11795 | if (uri == NULL) { | 
|  | 11796 | inputStream = xmlLoadExternalEntity((char *)URL, (char *)ID, ctxt); | 
|  | 11797 | if (inputStream == NULL) { | 
|  | 11798 | xmlFreeParserCtxt(ctxt); | 
|  | 11799 | return(NULL); | 
|  | 11800 | } | 
|  | 11801 |  | 
|  | 11802 | inputPush(ctxt, inputStream); | 
|  | 11803 |  | 
|  | 11804 | if ((ctxt->directory == NULL) && (directory == NULL)) | 
|  | 11805 | directory = xmlParserGetDirectory((char *)URL); | 
|  | 11806 | if ((ctxt->directory == NULL) && (directory != NULL)) | 
|  | 11807 | ctxt->directory = directory; | 
|  | 11808 | } else { | 
|  | 11809 | inputStream = xmlLoadExternalEntity((char *)uri, (char *)ID, ctxt); | 
|  | 11810 | if (inputStream == NULL) { | 
|  | 11811 | xmlFree(uri); | 
|  | 11812 | xmlFreeParserCtxt(ctxt); | 
|  | 11813 | return(NULL); | 
|  | 11814 | } | 
|  | 11815 |  | 
|  | 11816 | inputPush(ctxt, inputStream); | 
|  | 11817 |  | 
|  | 11818 | if ((ctxt->directory == NULL) && (directory == NULL)) | 
|  | 11819 | directory = xmlParserGetDirectory((char *)uri); | 
|  | 11820 | if ((ctxt->directory == NULL) && (directory != NULL)) | 
|  | 11821 | ctxt->directory = directory; | 
|  | 11822 | xmlFree(uri); | 
|  | 11823 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11824 | return(ctxt); | 
|  | 11825 | } | 
|  | 11826 |  | 
|  | 11827 | /************************************************************************ | 
|  | 11828 | *									* | 
|  | 11829 | * 		Front ends when parsing from a file			* | 
|  | 11830 | *									* | 
|  | 11831 | ************************************************************************/ | 
|  | 11832 |  | 
|  | 11833 | /** | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 11834 | * xmlCreateURLParserCtxt: | 
|  | 11835 | * @filename:  the filename or URL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 11836 | * @options:  a combination of xmlParserOption | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11837 | * | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 11838 | * Create a parser context for a file or URL content. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11839 | * Automatic support for ZLIB/Compress compressed document is provided | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 11840 | * by default if found at compile-time and for file accesses | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11841 | * | 
|  | 11842 | * Returns the new parser context or NULL | 
|  | 11843 | */ | 
|  | 11844 | xmlParserCtxtPtr | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 11845 | xmlCreateURLParserCtxt(const char *filename, int options) | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11846 | { | 
|  | 11847 | xmlParserCtxtPtr ctxt; | 
|  | 11848 | xmlParserInputPtr inputStream; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11849 | char *directory = NULL; | 
|  | 11850 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11851 | ctxt = xmlNewParserCtxt(); | 
|  | 11852 | if (ctxt == NULL) { | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 11853 | xmlErrMemory(NULL, "cannot allocate parser context"); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11854 | return(NULL); | 
|  | 11855 | } | 
|  | 11856 |  | 
| Daniel Veillard | df292f7 | 2005-01-16 19:00:15 +0000 | [diff] [blame] | 11857 | if (options) | 
|  | 11858 | xmlCtxtUseOptions(ctxt, options); | 
|  | 11859 | ctxt->linenumbers = 1; | 
| Igor Zlatkovic | ce07616 | 2003-02-23 13:39:39 +0000 | [diff] [blame] | 11860 |  | 
| Daniel Veillard | 4e9b1bc | 2003-06-09 10:30:33 +0000 | [diff] [blame] | 11861 | inputStream = xmlLoadExternalEntity(filename, NULL, ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11862 | if (inputStream == NULL) { | 
|  | 11863 | xmlFreeParserCtxt(ctxt); | 
|  | 11864 | return(NULL); | 
|  | 11865 | } | 
|  | 11866 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11867 | inputPush(ctxt, inputStream); | 
|  | 11868 | if ((ctxt->directory == NULL) && (directory == NULL)) | 
| Igor Zlatkovic | 5f9fada | 2003-02-19 14:51:00 +0000 | [diff] [blame] | 11869 | directory = xmlParserGetDirectory(filename); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11870 | if ((ctxt->directory == NULL) && (directory != NULL)) | 
|  | 11871 | ctxt->directory = directory; | 
|  | 11872 |  | 
|  | 11873 | return(ctxt); | 
|  | 11874 | } | 
|  | 11875 |  | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 11876 | /** | 
|  | 11877 | * xmlCreateFileParserCtxt: | 
|  | 11878 | * @filename:  the filename | 
|  | 11879 | * | 
|  | 11880 | * Create a parser context for a file content. | 
|  | 11881 | * Automatic support for ZLIB/Compress compressed document is provided | 
|  | 11882 | * by default if found at compile-time. | 
|  | 11883 | * | 
|  | 11884 | * Returns the new parser context or NULL | 
|  | 11885 | */ | 
|  | 11886 | xmlParserCtxtPtr | 
|  | 11887 | xmlCreateFileParserCtxt(const char *filename) | 
|  | 11888 | { | 
|  | 11889 | return(xmlCreateURLParserCtxt(filename, 0)); | 
|  | 11890 | } | 
|  | 11891 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 11892 | #ifdef LIBXML_SAX1_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11893 | /** | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11894 | * xmlSAXParseFileWithData: | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11895 | * @sax:  the SAX handler block | 
|  | 11896 | * @filename:  the filename | 
|  | 11897 | * @recovery:  work in recovery mode, i.e. tries to read no Well Formed | 
|  | 11898 | *             documents | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11899 | * @data:  the userdata | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11900 | * | 
|  | 11901 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress | 
|  | 11902 | * compressed document is provided by default if found at compile-time. | 
|  | 11903 | * It use the given SAX function block to handle the parsing callback. | 
|  | 11904 | * If sax is NULL, fallback to the default DOM tree building routines. | 
|  | 11905 | * | 
| Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 11906 | * User data (void *) is stored within the parser context in the | 
|  | 11907 | * context's _private member, so it is available nearly everywhere in libxml | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11908 | * | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11909 | * Returns the resulting document tree | 
|  | 11910 | */ | 
|  | 11911 |  | 
|  | 11912 | xmlDocPtr | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11913 | xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename, | 
|  | 11914 | int recovery, void *data) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11915 | xmlDocPtr ret; | 
|  | 11916 | xmlParserCtxtPtr ctxt; | 
|  | 11917 | char *directory = NULL; | 
|  | 11918 |  | 
| Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 11919 | xmlInitParser(); | 
|  | 11920 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11921 | ctxt = xmlCreateFileParserCtxt(filename); | 
|  | 11922 | if (ctxt == NULL) { | 
|  | 11923 | return(NULL); | 
|  | 11924 | } | 
|  | 11925 | if (sax != NULL) { | 
|  | 11926 | if (ctxt->sax != NULL) | 
|  | 11927 | xmlFree(ctxt->sax); | 
|  | 11928 | ctxt->sax = sax; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11929 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 11930 | xmlDetectSAX2(ctxt); | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11931 | if (data!=NULL) { | 
| Daniel Veillard | c790bf4 | 2003-10-11 10:50:10 +0000 | [diff] [blame] | 11932 | ctxt->_private = data; | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11933 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11934 |  | 
|  | 11935 | if ((ctxt->directory == NULL) && (directory == NULL)) | 
|  | 11936 | directory = xmlParserGetDirectory(filename); | 
|  | 11937 | if ((ctxt->directory == NULL) && (directory != NULL)) | 
|  | 11938 | ctxt->directory = (char *) xmlStrdup((xmlChar *) directory); | 
|  | 11939 |  | 
| Daniel Veillard | dad3f68 | 2002-11-17 16:47:27 +0000 | [diff] [blame] | 11940 | ctxt->recovery = recovery; | 
|  | 11941 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11942 | xmlParseDocument(ctxt); | 
|  | 11943 |  | 
| William M. Brack | c07329e | 2003-09-08 01:57:30 +0000 | [diff] [blame] | 11944 | if ((ctxt->wellFormed) || recovery) { | 
|  | 11945 | ret = ctxt->myDoc; | 
| Daniel Veillard | b65e12e | 2003-10-08 21:33:28 +0000 | [diff] [blame] | 11946 | if (ret != NULL) { | 
|  | 11947 | if (ctxt->input->buf->compressed > 0) | 
|  | 11948 | ret->compression = 9; | 
|  | 11949 | else | 
|  | 11950 | ret->compression = ctxt->input->buf->compressed; | 
|  | 11951 | } | 
| William M. Brack | c07329e | 2003-09-08 01:57:30 +0000 | [diff] [blame] | 11952 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11953 | else { | 
|  | 11954 | ret = NULL; | 
|  | 11955 | xmlFreeDoc(ctxt->myDoc); | 
|  | 11956 | ctxt->myDoc = NULL; | 
|  | 11957 | } | 
|  | 11958 | if (sax != NULL) | 
|  | 11959 | ctxt->sax = NULL; | 
|  | 11960 | xmlFreeParserCtxt(ctxt); | 
|  | 11961 |  | 
|  | 11962 | return(ret); | 
|  | 11963 | } | 
|  | 11964 |  | 
|  | 11965 | /** | 
| Daniel Veillard | a293c32 | 2001-10-02 13:54:14 +0000 | [diff] [blame] | 11966 | * xmlSAXParseFile: | 
|  | 11967 | * @sax:  the SAX handler block | 
|  | 11968 | * @filename:  the filename | 
|  | 11969 | * @recovery:  work in recovery mode, i.e. tries to read no Well Formed | 
|  | 11970 | *             documents | 
|  | 11971 | * | 
|  | 11972 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress | 
|  | 11973 | * compressed document is provided by default if found at compile-time. | 
|  | 11974 | * It use the given SAX function block to handle the parsing callback. | 
|  | 11975 | * If sax is NULL, fallback to the default DOM tree building routines. | 
|  | 11976 | * | 
|  | 11977 | * Returns the resulting document tree | 
|  | 11978 | */ | 
|  | 11979 |  | 
|  | 11980 | xmlDocPtr | 
|  | 11981 | xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename, | 
|  | 11982 | int recovery) { | 
|  | 11983 | return(xmlSAXParseFileWithData(sax,filename,recovery,NULL)); | 
|  | 11984 | } | 
|  | 11985 |  | 
|  | 11986 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11987 | * xmlRecoverDoc: | 
|  | 11988 | * @cur:  a pointer to an array of xmlChar | 
|  | 11989 | * | 
|  | 11990 | * parse an XML in-memory document and build a tree. | 
|  | 11991 | * In the case the document is not Well Formed, a tree is built anyway | 
|  | 11992 | * | 
|  | 11993 | * Returns the resulting document tree | 
|  | 11994 | */ | 
|  | 11995 |  | 
|  | 11996 | xmlDocPtr | 
|  | 11997 | xmlRecoverDoc(xmlChar *cur) { | 
|  | 11998 | return(xmlSAXParseDoc(NULL, cur, 1)); | 
|  | 11999 | } | 
|  | 12000 |  | 
|  | 12001 | /** | 
|  | 12002 | * xmlParseFile: | 
|  | 12003 | * @filename:  the filename | 
|  | 12004 | * | 
|  | 12005 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress | 
|  | 12006 | * compressed document is provided by default if found at compile-time. | 
|  | 12007 | * | 
| Daniel Veillard | 5d96fff | 2001-08-31 14:55:30 +0000 | [diff] [blame] | 12008 | * Returns the resulting document tree if the file was wellformed, | 
|  | 12009 | * NULL otherwise. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12010 | */ | 
|  | 12011 |  | 
|  | 12012 | xmlDocPtr | 
|  | 12013 | xmlParseFile(const char *filename) { | 
|  | 12014 | return(xmlSAXParseFile(NULL, filename, 0)); | 
|  | 12015 | } | 
|  | 12016 |  | 
|  | 12017 | /** | 
|  | 12018 | * xmlRecoverFile: | 
|  | 12019 | * @filename:  the filename | 
|  | 12020 | * | 
|  | 12021 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress | 
|  | 12022 | * compressed document is provided by default if found at compile-time. | 
|  | 12023 | * In the case the document is not Well Formed, a tree is built anyway | 
|  | 12024 | * | 
|  | 12025 | * Returns the resulting document tree | 
|  | 12026 | */ | 
|  | 12027 |  | 
|  | 12028 | xmlDocPtr | 
|  | 12029 | xmlRecoverFile(const char *filename) { | 
|  | 12030 | return(xmlSAXParseFile(NULL, filename, 1)); | 
|  | 12031 | } | 
|  | 12032 |  | 
|  | 12033 |  | 
|  | 12034 | /** | 
|  | 12035 | * xmlSetupParserForBuffer: | 
|  | 12036 | * @ctxt:  an XML parser context | 
|  | 12037 | * @buffer:  a xmlChar * buffer | 
|  | 12038 | * @filename:  a file name | 
|  | 12039 | * | 
|  | 12040 | * Setup the parser context to parse a new buffer; Clears any prior | 
|  | 12041 | * contents from the parser context. The buffer parameter must not be | 
|  | 12042 | * NULL, but the filename parameter can be | 
|  | 12043 | */ | 
|  | 12044 | void | 
|  | 12045 | xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, | 
|  | 12046 | const char* filename) | 
|  | 12047 | { | 
|  | 12048 | xmlParserInputPtr input; | 
|  | 12049 |  | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 12050 | if ((ctxt == NULL) || (buffer == NULL)) | 
|  | 12051 | return; | 
|  | 12052 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12053 | input = xmlNewInputStream(ctxt); | 
|  | 12054 | if (input == NULL) { | 
| Daniel Veillard | 24eb978 | 2003-10-04 21:08:09 +0000 | [diff] [blame] | 12055 | xmlErrMemory(NULL, "parsing new buffer: out of memory\n"); | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 12056 | xmlClearParserCtxt(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12057 | return; | 
|  | 12058 | } | 
|  | 12059 |  | 
|  | 12060 | xmlClearParserCtxt(ctxt); | 
|  | 12061 | if (filename != NULL) | 
| Daniel Veillard | c3ca5ba | 2003-05-09 22:26:28 +0000 | [diff] [blame] | 12062 | input->filename = (char *) xmlCanonicPath((const xmlChar *)filename); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12063 | input->base = buffer; | 
|  | 12064 | input->cur = buffer; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 12065 | input->end = &buffer[xmlStrlen(buffer)]; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12066 | inputPush(ctxt, input); | 
|  | 12067 | } | 
|  | 12068 |  | 
|  | 12069 | /** | 
|  | 12070 | * xmlSAXUserParseFile: | 
|  | 12071 | * @sax:  a SAX handler | 
|  | 12072 | * @user_data:  The user data returned on SAX callbacks | 
|  | 12073 | * @filename:  a file name | 
|  | 12074 | * | 
|  | 12075 | * parse an XML file and call the given SAX handler routines. | 
|  | 12076 | * Automatic support for ZLIB/Compress compressed document is provided | 
|  | 12077 | * | 
|  | 12078 | * Returns 0 in case of success or a error number otherwise | 
|  | 12079 | */ | 
|  | 12080 | int | 
|  | 12081 | xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, | 
|  | 12082 | const char *filename) { | 
|  | 12083 | int ret = 0; | 
|  | 12084 | xmlParserCtxtPtr ctxt; | 
|  | 12085 |  | 
|  | 12086 | ctxt = xmlCreateFileParserCtxt(filename); | 
|  | 12087 | if (ctxt == NULL) return -1; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12088 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 092643b | 2003-09-25 14:29:29 +0000 | [diff] [blame] | 12089 | if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12090 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12091 | xmlFree(ctxt->sax); | 
|  | 12092 | ctxt->sax = sax; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 12093 | xmlDetectSAX2(ctxt); | 
|  | 12094 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12095 | if (user_data != NULL) | 
|  | 12096 | ctxt->userData = user_data; | 
|  | 12097 |  | 
|  | 12098 | xmlParseDocument(ctxt); | 
|  | 12099 |  | 
|  | 12100 | if (ctxt->wellFormed) | 
|  | 12101 | ret = 0; | 
|  | 12102 | else { | 
|  | 12103 | if (ctxt->errNo != 0) | 
|  | 12104 | ret = ctxt->errNo; | 
|  | 12105 | else | 
|  | 12106 | ret = -1; | 
|  | 12107 | } | 
|  | 12108 | if (sax != NULL) | 
|  | 12109 | ctxt->sax = NULL; | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 12110 | if (ctxt->myDoc != NULL) { | 
|  | 12111 | xmlFreeDoc(ctxt->myDoc); | 
|  | 12112 | ctxt->myDoc = NULL; | 
|  | 12113 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12114 | xmlFreeParserCtxt(ctxt); | 
|  | 12115 |  | 
|  | 12116 | return ret; | 
|  | 12117 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12118 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12119 |  | 
|  | 12120 | /************************************************************************ | 
|  | 12121 | *									* | 
|  | 12122 | * 		Front ends when parsing from memory			* | 
|  | 12123 | *									* | 
|  | 12124 | ************************************************************************/ | 
|  | 12125 |  | 
|  | 12126 | /** | 
|  | 12127 | * xmlCreateMemoryParserCtxt: | 
|  | 12128 | * @buffer:  a pointer to a char array | 
|  | 12129 | * @size:  the size of the array | 
|  | 12130 | * | 
|  | 12131 | * Create a parser context for an XML in-memory document. | 
|  | 12132 | * | 
|  | 12133 | * Returns the new parser context or NULL | 
|  | 12134 | */ | 
|  | 12135 | xmlParserCtxtPtr | 
| Daniel Veillard | fd7ddca | 2001-05-16 10:57:35 +0000 | [diff] [blame] | 12136 | xmlCreateMemoryParserCtxt(const char *buffer, int size) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12137 | xmlParserCtxtPtr ctxt; | 
|  | 12138 | xmlParserInputPtr input; | 
|  | 12139 | xmlParserInputBufferPtr buf; | 
|  | 12140 |  | 
|  | 12141 | if (buffer == NULL) | 
|  | 12142 | return(NULL); | 
|  | 12143 | if (size <= 0) | 
|  | 12144 | return(NULL); | 
|  | 12145 |  | 
|  | 12146 | ctxt = xmlNewParserCtxt(); | 
|  | 12147 | if (ctxt == NULL) | 
|  | 12148 | return(NULL); | 
|  | 12149 |  | 
| Daniel Veillard | 5335055 | 2003-09-18 13:35:51 +0000 | [diff] [blame] | 12150 | /* TODO: xmlParserInputBufferCreateStatic, requires some serious changes */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12151 | buf = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE); | 
| Daniel Veillard | a7e05b4 | 2002-11-19 08:11:14 +0000 | [diff] [blame] | 12152 | if (buf == NULL) { | 
|  | 12153 | xmlFreeParserCtxt(ctxt); | 
|  | 12154 | return(NULL); | 
|  | 12155 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12156 |  | 
|  | 12157 | input = xmlNewInputStream(ctxt); | 
|  | 12158 | if (input == NULL) { | 
| Daniel Veillard | a7e05b4 | 2002-11-19 08:11:14 +0000 | [diff] [blame] | 12159 | xmlFreeParserInputBuffer(buf); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12160 | xmlFreeParserCtxt(ctxt); | 
|  | 12161 | return(NULL); | 
|  | 12162 | } | 
|  | 12163 |  | 
|  | 12164 | input->filename = NULL; | 
|  | 12165 | input->buf = buf; | 
|  | 12166 | input->base = input->buf->buffer->content; | 
|  | 12167 | input->cur = input->buf->buffer->content; | 
| Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 12168 | input->end = &input->buf->buffer->content[input->buf->buffer->use]; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12169 |  | 
|  | 12170 | inputPush(ctxt, input); | 
|  | 12171 | return(ctxt); | 
|  | 12172 | } | 
|  | 12173 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12174 | #ifdef LIBXML_SAX1_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12175 | /** | 
| Daniel Veillard | 8606bbb | 2002-11-12 12:36:52 +0000 | [diff] [blame] | 12176 | * xmlSAXParseMemoryWithData: | 
|  | 12177 | * @sax:  the SAX handler block | 
|  | 12178 | * @buffer:  an pointer to a char array | 
|  | 12179 | * @size:  the size of the array | 
|  | 12180 | * @recovery:  work in recovery mode, i.e. tries to read no Well Formed | 
|  | 12181 | *             documents | 
|  | 12182 | * @data:  the userdata | 
|  | 12183 | * | 
|  | 12184 | * parse an XML in-memory block and use the given SAX function block | 
|  | 12185 | * to handle the parsing callback. If sax is NULL, fallback to the default | 
|  | 12186 | * DOM tree building routines. | 
|  | 12187 | * | 
|  | 12188 | * User data (void *) is stored within the parser context in the | 
|  | 12189 | * context's _private member, so it is available nearly everywhere in libxml | 
|  | 12190 | * | 
|  | 12191 | * Returns the resulting document tree | 
|  | 12192 | */ | 
|  | 12193 |  | 
|  | 12194 | xmlDocPtr | 
|  | 12195 | xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer, | 
|  | 12196 | int size, int recovery, void *data) { | 
|  | 12197 | xmlDocPtr ret; | 
|  | 12198 | xmlParserCtxtPtr ctxt; | 
|  | 12199 |  | 
|  | 12200 | ctxt = xmlCreateMemoryParserCtxt(buffer, size); | 
|  | 12201 | if (ctxt == NULL) return(NULL); | 
|  | 12202 | if (sax != NULL) { | 
|  | 12203 | if (ctxt->sax != NULL) | 
|  | 12204 | xmlFree(ctxt->sax); | 
|  | 12205 | ctxt->sax = sax; | 
|  | 12206 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 12207 | xmlDetectSAX2(ctxt); | 
| Daniel Veillard | 8606bbb | 2002-11-12 12:36:52 +0000 | [diff] [blame] | 12208 | if (data!=NULL) { | 
|  | 12209 | ctxt->_private=data; | 
|  | 12210 | } | 
|  | 12211 |  | 
| Daniel Veillard | adba5f1 | 2003-04-04 16:09:01 +0000 | [diff] [blame] | 12212 | ctxt->recovery = recovery; | 
|  | 12213 |  | 
| Daniel Veillard | 8606bbb | 2002-11-12 12:36:52 +0000 | [diff] [blame] | 12214 | xmlParseDocument(ctxt); | 
|  | 12215 |  | 
|  | 12216 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; | 
|  | 12217 | else { | 
|  | 12218 | ret = NULL; | 
|  | 12219 | xmlFreeDoc(ctxt->myDoc); | 
|  | 12220 | ctxt->myDoc = NULL; | 
|  | 12221 | } | 
|  | 12222 | if (sax != NULL) | 
|  | 12223 | ctxt->sax = NULL; | 
|  | 12224 | xmlFreeParserCtxt(ctxt); | 
|  | 12225 |  | 
|  | 12226 | return(ret); | 
|  | 12227 | } | 
|  | 12228 |  | 
|  | 12229 | /** | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12230 | * xmlSAXParseMemory: | 
|  | 12231 | * @sax:  the SAX handler block | 
|  | 12232 | * @buffer:  an pointer to a char array | 
|  | 12233 | * @size:  the size of the array | 
|  | 12234 | * @recovery:  work in recovery mode, i.e. tries to read not Well Formed | 
|  | 12235 | *             documents | 
|  | 12236 | * | 
|  | 12237 | * parse an XML in-memory block and use the given SAX function block | 
|  | 12238 | * to handle the parsing callback. If sax is NULL, fallback to the default | 
|  | 12239 | * DOM tree building routines. | 
|  | 12240 | * | 
|  | 12241 | * Returns the resulting document tree | 
|  | 12242 | */ | 
|  | 12243 | xmlDocPtr | 
| Daniel Veillard | 50822cb | 2001-07-26 20:05:51 +0000 | [diff] [blame] | 12244 | xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, | 
|  | 12245 | int size, int recovery) { | 
| Daniel Veillard | 8606bbb | 2002-11-12 12:36:52 +0000 | [diff] [blame] | 12246 | return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12247 | } | 
|  | 12248 |  | 
|  | 12249 | /** | 
|  | 12250 | * xmlParseMemory: | 
|  | 12251 | * @buffer:  an pointer to a char array | 
|  | 12252 | * @size:  the size of the array | 
|  | 12253 | * | 
|  | 12254 | * parse an XML in-memory block and build a tree. | 
|  | 12255 | * | 
|  | 12256 | * Returns the resulting document tree | 
|  | 12257 | */ | 
|  | 12258 |  | 
| Daniel Veillard | 50822cb | 2001-07-26 20:05:51 +0000 | [diff] [blame] | 12259 | xmlDocPtr xmlParseMemory(const char *buffer, int size) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12260 | return(xmlSAXParseMemory(NULL, buffer, size, 0)); | 
|  | 12261 | } | 
|  | 12262 |  | 
|  | 12263 | /** | 
|  | 12264 | * xmlRecoverMemory: | 
|  | 12265 | * @buffer:  an pointer to a char array | 
|  | 12266 | * @size:  the size of the array | 
|  | 12267 | * | 
|  | 12268 | * parse an XML in-memory block and build a tree. | 
|  | 12269 | * In the case the document is not Well Formed, a tree is built anyway | 
|  | 12270 | * | 
|  | 12271 | * Returns the resulting document tree | 
|  | 12272 | */ | 
|  | 12273 |  | 
| Daniel Veillard | 50822cb | 2001-07-26 20:05:51 +0000 | [diff] [blame] | 12274 | xmlDocPtr xmlRecoverMemory(const char *buffer, int size) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12275 | return(xmlSAXParseMemory(NULL, buffer, size, 1)); | 
|  | 12276 | } | 
|  | 12277 |  | 
|  | 12278 | /** | 
|  | 12279 | * xmlSAXUserParseMemory: | 
|  | 12280 | * @sax:  a SAX handler | 
|  | 12281 | * @user_data:  The user data returned on SAX callbacks | 
|  | 12282 | * @buffer:  an in-memory XML document input | 
|  | 12283 | * @size:  the length of the XML document in bytes | 
|  | 12284 | * | 
|  | 12285 | * A better SAX parsing routine. | 
|  | 12286 | * parse an XML in-memory buffer and call the given SAX handler routines. | 
|  | 12287 | * | 
|  | 12288 | * Returns 0 in case of success or a error number otherwise | 
|  | 12289 | */ | 
|  | 12290 | int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data, | 
| Daniel Veillard | fd7ddca | 2001-05-16 10:57:35 +0000 | [diff] [blame] | 12291 | const char *buffer, int size) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12292 | int ret = 0; | 
|  | 12293 | xmlParserCtxtPtr ctxt; | 
|  | 12294 | xmlSAXHandlerPtr oldsax = NULL; | 
|  | 12295 |  | 
| Daniel Veillard | 9e92351 | 2002-08-14 08:48:52 +0000 | [diff] [blame] | 12296 | if (sax == NULL) return -1; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12297 | ctxt = xmlCreateMemoryParserCtxt(buffer, size); | 
|  | 12298 | if (ctxt == NULL) return -1; | 
| Daniel Veillard | 9e92351 | 2002-08-14 08:48:52 +0000 | [diff] [blame] | 12299 | oldsax = ctxt->sax; | 
|  | 12300 | ctxt->sax = sax; | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 12301 | xmlDetectSAX2(ctxt); | 
| Daniel Veillard | 30211a0 | 2001-04-26 09:33:18 +0000 | [diff] [blame] | 12302 | if (user_data != NULL) | 
|  | 12303 | ctxt->userData = user_data; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12304 |  | 
|  | 12305 | xmlParseDocument(ctxt); | 
|  | 12306 |  | 
|  | 12307 | if (ctxt->wellFormed) | 
|  | 12308 | ret = 0; | 
|  | 12309 | else { | 
|  | 12310 | if (ctxt->errNo != 0) | 
|  | 12311 | ret = ctxt->errNo; | 
|  | 12312 | else | 
|  | 12313 | ret = -1; | 
|  | 12314 | } | 
| Daniel Veillard | 9e92351 | 2002-08-14 08:48:52 +0000 | [diff] [blame] | 12315 | ctxt->sax = oldsax; | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 12316 | if (ctxt->myDoc != NULL) { | 
|  | 12317 | xmlFreeDoc(ctxt->myDoc); | 
|  | 12318 | ctxt->myDoc = NULL; | 
|  | 12319 | } | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12320 | xmlFreeParserCtxt(ctxt); | 
|  | 12321 |  | 
|  | 12322 | return ret; | 
|  | 12323 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12324 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12325 |  | 
|  | 12326 | /** | 
|  | 12327 | * xmlCreateDocParserCtxt: | 
|  | 12328 | * @cur:  a pointer to an array of xmlChar | 
|  | 12329 | * | 
|  | 12330 | * Creates a parser context for an XML in-memory document. | 
|  | 12331 | * | 
|  | 12332 | * Returns the new parser context or NULL | 
|  | 12333 | */ | 
|  | 12334 | xmlParserCtxtPtr | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12335 | xmlCreateDocParserCtxt(const xmlChar *cur) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12336 | int len; | 
|  | 12337 |  | 
|  | 12338 | if (cur == NULL) | 
|  | 12339 | return(NULL); | 
|  | 12340 | len = xmlStrlen(cur); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12341 | return(xmlCreateMemoryParserCtxt((const char *)cur, len)); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12342 | } | 
|  | 12343 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12344 | #ifdef LIBXML_SAX1_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12345 | /** | 
|  | 12346 | * xmlSAXParseDoc: | 
|  | 12347 | * @sax:  the SAX handler block | 
|  | 12348 | * @cur:  a pointer to an array of xmlChar | 
|  | 12349 | * @recovery:  work in recovery mode, i.e. tries to read no Well Formed | 
|  | 12350 | *             documents | 
|  | 12351 | * | 
|  | 12352 | * parse an XML in-memory document and build a tree. | 
|  | 12353 | * It use the given SAX function block to handle the parsing callback. | 
|  | 12354 | * If sax is NULL, fallback to the default DOM tree building routines. | 
|  | 12355 | * | 
|  | 12356 | * Returns the resulting document tree | 
|  | 12357 | */ | 
|  | 12358 |  | 
|  | 12359 | xmlDocPtr | 
| Daniel Veillard | 7331e5c | 2005-03-31 14:59:00 +0000 | [diff] [blame] | 12360 | xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cur, int recovery) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12361 | xmlDocPtr ret; | 
|  | 12362 | xmlParserCtxtPtr ctxt; | 
| Daniel Veillard | 3893606 | 2004-11-04 17:45:11 +0000 | [diff] [blame] | 12363 | xmlSAXHandlerPtr oldsax = NULL; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12364 |  | 
| Daniel Veillard | 3893606 | 2004-11-04 17:45:11 +0000 | [diff] [blame] | 12365 | if (cur == NULL) return(NULL); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12366 |  | 
|  | 12367 |  | 
|  | 12368 | ctxt = xmlCreateDocParserCtxt(cur); | 
|  | 12369 | if (ctxt == NULL) return(NULL); | 
|  | 12370 | if (sax != NULL) { | 
| Daniel Veillard | 3893606 | 2004-11-04 17:45:11 +0000 | [diff] [blame] | 12371 | oldsax = ctxt->sax; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12372 | ctxt->sax = sax; | 
|  | 12373 | ctxt->userData = NULL; | 
|  | 12374 | } | 
| Daniel Veillard | e57ec79 | 2003-09-10 10:50:59 +0000 | [diff] [blame] | 12375 | xmlDetectSAX2(ctxt); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12376 |  | 
|  | 12377 | xmlParseDocument(ctxt); | 
|  | 12378 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; | 
|  | 12379 | else { | 
|  | 12380 | ret = NULL; | 
|  | 12381 | xmlFreeDoc(ctxt->myDoc); | 
|  | 12382 | ctxt->myDoc = NULL; | 
|  | 12383 | } | 
| Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 12384 | if (sax != NULL) | 
| Daniel Veillard | 3893606 | 2004-11-04 17:45:11 +0000 | [diff] [blame] | 12385 | ctxt->sax = oldsax; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12386 | xmlFreeParserCtxt(ctxt); | 
|  | 12387 |  | 
|  | 12388 | return(ret); | 
|  | 12389 | } | 
|  | 12390 |  | 
|  | 12391 | /** | 
|  | 12392 | * xmlParseDoc: | 
|  | 12393 | * @cur:  a pointer to an array of xmlChar | 
|  | 12394 | * | 
|  | 12395 | * parse an XML in-memory document and build a tree. | 
|  | 12396 | * | 
|  | 12397 | * Returns the resulting document tree | 
|  | 12398 | */ | 
|  | 12399 |  | 
|  | 12400 | xmlDocPtr | 
| Daniel Veillard | 7331e5c | 2005-03-31 14:59:00 +0000 | [diff] [blame] | 12401 | xmlParseDoc(const xmlChar *cur) { | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12402 | return(xmlSAXParseDoc(NULL, cur, 0)); | 
|  | 12403 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12404 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12405 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12406 | #ifdef LIBXML_LEGACY_ENABLED | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 12407 | /************************************************************************ | 
|  | 12408 | *									* | 
|  | 12409 | * 	Specific function to keep track of entities references		* | 
|  | 12410 | * 	and used by the XSLT debugger					* | 
|  | 12411 | *									* | 
|  | 12412 | ************************************************************************/ | 
|  | 12413 |  | 
|  | 12414 | static xmlEntityReferenceFunc xmlEntityRefFunc = NULL; | 
|  | 12415 |  | 
|  | 12416 | /** | 
|  | 12417 | * xmlAddEntityReference: | 
|  | 12418 | * @ent : A valid entity | 
|  | 12419 | * @firstNode : A valid first node for children of entity | 
|  | 12420 | * @lastNode : A valid last node of children entity | 
|  | 12421 | * | 
|  | 12422 | * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY | 
|  | 12423 | */ | 
|  | 12424 | static void | 
|  | 12425 | xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode, | 
|  | 12426 | xmlNodePtr lastNode) | 
|  | 12427 | { | 
|  | 12428 | if (xmlEntityRefFunc != NULL) { | 
|  | 12429 | (*xmlEntityRefFunc) (ent, firstNode, lastNode); | 
|  | 12430 | } | 
|  | 12431 | } | 
|  | 12432 |  | 
|  | 12433 |  | 
|  | 12434 | /** | 
|  | 12435 | * xmlSetEntityReferenceFunc: | 
| Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 12436 | * @func: A valid function | 
| Daniel Veillard | 8107a22 | 2002-01-13 14:10:10 +0000 | [diff] [blame] | 12437 | * | 
|  | 12438 | * Set the function to call call back when a xml reference has been made | 
|  | 12439 | */ | 
|  | 12440 | void | 
|  | 12441 | xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func) | 
|  | 12442 | { | 
|  | 12443 | xmlEntityRefFunc = func; | 
|  | 12444 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12445 | #endif /* LIBXML_LEGACY_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12446 |  | 
|  | 12447 | /************************************************************************ | 
|  | 12448 | *									* | 
|  | 12449 | * 				Miscellaneous				* | 
|  | 12450 | *									* | 
|  | 12451 | ************************************************************************/ | 
|  | 12452 |  | 
|  | 12453 | #ifdef LIBXML_XPATH_ENABLED | 
|  | 12454 | #include <libxml/xpath.h> | 
|  | 12455 | #endif | 
|  | 12456 |  | 
| Daniel Veillard | ffa3c74 | 2005-07-21 13:24:09 +0000 | [diff] [blame] | 12457 | extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12458 | static int xmlParserInitialized = 0; | 
|  | 12459 |  | 
|  | 12460 | /** | 
|  | 12461 | * xmlInitParser: | 
|  | 12462 | * | 
|  | 12463 | * Initialization function for the XML parser. | 
|  | 12464 | * This is not reentrant. Call once before processing in case of | 
|  | 12465 | * use in multithreaded programs. | 
|  | 12466 | */ | 
|  | 12467 |  | 
|  | 12468 | void | 
|  | 12469 | xmlInitParser(void) { | 
| Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 12470 | if (xmlParserInitialized != 0) | 
|  | 12471 | return; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12472 |  | 
| Daniel Veillard | db5850a | 2002-01-18 11:49:26 +0000 | [diff] [blame] | 12473 | if ((xmlGenericError == xmlGenericErrorDefaultFunc) || | 
|  | 12474 | (xmlGenericError == NULL)) | 
|  | 12475 | initGenericErrorDefaultFunc(NULL); | 
| Daniel Veillard | 781ac8b | 2003-05-15 22:11:36 +0000 | [diff] [blame] | 12476 | xmlInitGlobals(); | 
| Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 12477 | xmlInitThreads(); | 
| Daniel Veillard | 6f35029 | 2001-10-14 09:56:15 +0000 | [diff] [blame] | 12478 | xmlInitMemory(); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12479 | xmlInitCharEncodingHandlers(); | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12480 | xmlDefaultSAXHandlerInit(); | 
|  | 12481 | xmlRegisterDefaultInputCallbacks(); | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 12482 | #ifdef LIBXML_OUTPUT_ENABLED | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12483 | xmlRegisterDefaultOutputCallbacks(); | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 12484 | #endif /* LIBXML_OUTPUT_ENABLED */ | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12485 | #ifdef LIBXML_HTML_ENABLED | 
|  | 12486 | htmlInitAutoClose(); | 
|  | 12487 | htmlDefaultSAXHandlerInit(); | 
|  | 12488 | #endif | 
|  | 12489 | #ifdef LIBXML_XPATH_ENABLED | 
|  | 12490 | xmlXPathInit(); | 
|  | 12491 | #endif | 
|  | 12492 | xmlParserInitialized = 1; | 
|  | 12493 | } | 
|  | 12494 |  | 
|  | 12495 | /** | 
|  | 12496 | * xmlCleanupParser: | 
|  | 12497 | * | 
| Daniel Veillard | d8cf906 | 2003-11-11 21:12:36 +0000 | [diff] [blame] | 12498 | * Cleanup function for the XML library. It tries to reclaim all | 
|  | 12499 | * parsing related global memory allocated for the library processing. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12500 | * It doesn't deallocate any document related memory. Calling this | 
| Daniel Veillard | d8cf906 | 2003-11-11 21:12:36 +0000 | [diff] [blame] | 12501 | * function should not prevent reusing the library but one should | 
|  | 12502 | * call xmlCleanupParser() only when the process has | 
| Daniel Veillard | 7424eb6 | 2003-01-24 14:14:52 +0000 | [diff] [blame] | 12503 | * finished using the library or XML document built with it. | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12504 | */ | 
|  | 12505 |  | 
|  | 12506 | void | 
|  | 12507 | xmlCleanupParser(void) { | 
| Daniel Veillard | 7fb801f | 2003-08-17 21:07:26 +0000 | [diff] [blame] | 12508 | if (!xmlParserInitialized) | 
|  | 12509 | return; | 
|  | 12510 |  | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12511 | xmlCleanupCharEncodingHandlers(); | 
| Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 12512 | #ifdef LIBXML_CATALOG_ENABLED | 
|  | 12513 | xmlCatalogCleanup(); | 
|  | 12514 | #endif | 
| Daniel Veillard | 1441251 | 2005-01-21 23:53:26 +0000 | [diff] [blame] | 12515 | xmlDictCleanup(); | 
| Daniel Veillard | 04054be | 2003-10-15 10:48:54 +0000 | [diff] [blame] | 12516 | xmlCleanupInputCallbacks(); | 
|  | 12517 | #ifdef LIBXML_OUTPUT_ENABLED | 
|  | 12518 | xmlCleanupOutputCallbacks(); | 
|  | 12519 | #endif | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 12520 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 12521 | xmlSchemaCleanupTypes(); | 
| Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 12522 | xmlRelaxNGCleanupTypes(); | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 12523 | #endif | 
| Daniel Veillard | 781ac8b | 2003-05-15 22:11:36 +0000 | [diff] [blame] | 12524 | xmlCleanupGlobals(); | 
| Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 12525 | xmlResetLastError(); | 
| Daniel Veillard | 74c0e59 | 2003-11-25 07:01:38 +0000 | [diff] [blame] | 12526 | xmlCleanupThreads(); /* must be last if called not from the main thread */ | 
| William M. Brack | 72ee48d | 2003-12-30 08:30:19 +0000 | [diff] [blame] | 12527 | xmlCleanupMemory(); | 
| Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 12528 | xmlParserInitialized = 0; | 
| Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12529 | } | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12530 |  | 
|  | 12531 | /************************************************************************ | 
|  | 12532 | *									* | 
|  | 12533 | *	New set (2.6.0) of simpler and more flexible APIs		* | 
|  | 12534 | *									* | 
|  | 12535 | ************************************************************************/ | 
|  | 12536 |  | 
|  | 12537 | /** | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12538 | * DICT_FREE: | 
|  | 12539 | * @str:  a string | 
|  | 12540 | * | 
|  | 12541 | * Free a string if it is not owned by the "dict" dictionnary in the | 
|  | 12542 | * current scope | 
|  | 12543 | */ | 
|  | 12544 | #define DICT_FREE(str)						\ | 
|  | 12545 | if ((str) && ((!dict) || 				\ | 
|  | 12546 | (xmlDictOwns(dict, (const xmlChar *)(str)) == 0)))	\ | 
|  | 12547 | xmlFree((char *)(str)); | 
|  | 12548 |  | 
|  | 12549 | /** | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12550 | * xmlCtxtReset: | 
|  | 12551 | * @ctxt: an XML parser context | 
|  | 12552 | * | 
|  | 12553 | * Reset a parser context | 
|  | 12554 | */ | 
|  | 12555 | void | 
|  | 12556 | xmlCtxtReset(xmlParserCtxtPtr ctxt) | 
|  | 12557 | { | 
|  | 12558 | xmlParserInputPtr input; | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 12559 | xmlDictPtr dict; | 
|  | 12560 |  | 
|  | 12561 | if (ctxt == NULL) | 
|  | 12562 | return; | 
|  | 12563 |  | 
|  | 12564 | dict = ctxt->dict; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12565 |  | 
|  | 12566 | while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */ | 
|  | 12567 | xmlFreeInputStream(input); | 
|  | 12568 | } | 
|  | 12569 | ctxt->inputNr = 0; | 
|  | 12570 | ctxt->input = NULL; | 
|  | 12571 |  | 
|  | 12572 | ctxt->spaceNr = 0; | 
|  | 12573 | ctxt->spaceTab[0] = -1; | 
|  | 12574 | ctxt->space = &ctxt->spaceTab[0]; | 
|  | 12575 |  | 
|  | 12576 |  | 
|  | 12577 | ctxt->nodeNr = 0; | 
|  | 12578 | ctxt->node = NULL; | 
|  | 12579 |  | 
|  | 12580 | ctxt->nameNr = 0; | 
|  | 12581 | ctxt->name = NULL; | 
|  | 12582 |  | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12583 | DICT_FREE(ctxt->version); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12584 | ctxt->version = NULL; | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12585 | DICT_FREE(ctxt->encoding); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12586 | ctxt->encoding = NULL; | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12587 | DICT_FREE(ctxt->directory); | 
|  | 12588 | ctxt->directory = NULL; | 
|  | 12589 | DICT_FREE(ctxt->extSubURI); | 
|  | 12590 | ctxt->extSubURI = NULL; | 
|  | 12591 | DICT_FREE(ctxt->extSubSystem); | 
|  | 12592 | ctxt->extSubSystem = NULL; | 
|  | 12593 | if (ctxt->myDoc != NULL) | 
|  | 12594 | xmlFreeDoc(ctxt->myDoc); | 
|  | 12595 | ctxt->myDoc = NULL; | 
|  | 12596 |  | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12597 | ctxt->standalone = -1; | 
|  | 12598 | ctxt->hasExternalSubset = 0; | 
|  | 12599 | ctxt->hasPErefs = 0; | 
|  | 12600 | ctxt->html = 0; | 
|  | 12601 | ctxt->external = 0; | 
|  | 12602 | ctxt->instate = XML_PARSER_START; | 
|  | 12603 | ctxt->token = 0; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12604 |  | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12605 | ctxt->wellFormed = 1; | 
|  | 12606 | ctxt->nsWellFormed = 1; | 
| Daniel Veillard | ae28918 | 2004-01-21 16:00:43 +0000 | [diff] [blame] | 12607 | ctxt->disableSAX = 0; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12608 | ctxt->valid = 1; | 
| Daniel Veillard | 766c4f9 | 2004-03-26 10:48:29 +0000 | [diff] [blame] | 12609 | #if 0 | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12610 | ctxt->vctxt.userData = ctxt; | 
|  | 12611 | ctxt->vctxt.error = xmlParserValidityError; | 
|  | 12612 | ctxt->vctxt.warning = xmlParserValidityWarning; | 
| Daniel Veillard | 766c4f9 | 2004-03-26 10:48:29 +0000 | [diff] [blame] | 12613 | #endif | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12614 | ctxt->record_info = 0; | 
|  | 12615 | ctxt->nbChars = 0; | 
|  | 12616 | ctxt->checkIndex = 0; | 
|  | 12617 | ctxt->inSubset = 0; | 
|  | 12618 | ctxt->errNo = XML_ERR_OK; | 
|  | 12619 | ctxt->depth = 0; | 
|  | 12620 | ctxt->charset = XML_CHAR_ENCODING_UTF8; | 
|  | 12621 | ctxt->catalogs = NULL; | 
|  | 12622 | xmlInitNodeInfoSeq(&ctxt->node_seq); | 
|  | 12623 |  | 
|  | 12624 | if (ctxt->attsDefault != NULL) { | 
|  | 12625 | xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree); | 
|  | 12626 | ctxt->attsDefault = NULL; | 
|  | 12627 | } | 
|  | 12628 | if (ctxt->attsSpecial != NULL) { | 
|  | 12629 | xmlHashFree(ctxt->attsSpecial, NULL); | 
|  | 12630 | ctxt->attsSpecial = NULL; | 
|  | 12631 | } | 
|  | 12632 |  | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 12633 | #ifdef LIBXML_CATALOG_ENABLED | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12634 | if (ctxt->catalogs != NULL) | 
|  | 12635 | xmlCatalogFreeLocal(ctxt->catalogs); | 
| Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 12636 | #endif | 
| Daniel Veillard | cc199e0 | 2003-10-24 21:11:48 +0000 | [diff] [blame] | 12637 | if (ctxt->lastError.code != XML_ERR_OK) | 
|  | 12638 | xmlResetError(&ctxt->lastError); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12639 | } | 
|  | 12640 |  | 
|  | 12641 | /** | 
| Daniel Veillard | 9ba8e38 | 2003-10-28 21:31:45 +0000 | [diff] [blame] | 12642 | * xmlCtxtResetPush: | 
|  | 12643 | * @ctxt: an XML parser context | 
|  | 12644 | * @chunk:  a pointer to an array of chars | 
|  | 12645 | * @size:  number of chars in the array | 
|  | 12646 | * @filename:  an optional file name or URI | 
|  | 12647 | * @encoding:  the document encoding, or NULL | 
|  | 12648 | * | 
| Daniel Veillard | e4e3f5d | 2003-10-28 23:06:32 +0000 | [diff] [blame] | 12649 | * Reset a push parser context | 
|  | 12650 | * | 
|  | 12651 | * Returns 0 in case of success and 1 in case of error | 
| Daniel Veillard | 9ba8e38 | 2003-10-28 21:31:45 +0000 | [diff] [blame] | 12652 | */ | 
|  | 12653 | int | 
|  | 12654 | xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk, | 
|  | 12655 | int size, const char *filename, const char *encoding) | 
|  | 12656 | { | 
|  | 12657 | xmlParserInputPtr inputStream; | 
|  | 12658 | xmlParserInputBufferPtr buf; | 
|  | 12659 | xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; | 
|  | 12660 |  | 
| Daniel Veillard | e4e3f5d | 2003-10-28 23:06:32 +0000 | [diff] [blame] | 12661 | if (ctxt == NULL) | 
|  | 12662 | return(1); | 
|  | 12663 |  | 
| Daniel Veillard | 9ba8e38 | 2003-10-28 21:31:45 +0000 | [diff] [blame] | 12664 | if ((encoding == NULL) && (chunk != NULL) && (size >= 4)) | 
|  | 12665 | enc = xmlDetectCharEncoding((const xmlChar *) chunk, size); | 
|  | 12666 |  | 
|  | 12667 | buf = xmlAllocParserInputBuffer(enc); | 
|  | 12668 | if (buf == NULL) | 
|  | 12669 | return(1); | 
|  | 12670 |  | 
|  | 12671 | if (ctxt == NULL) { | 
|  | 12672 | xmlFreeParserInputBuffer(buf); | 
|  | 12673 | return(1); | 
|  | 12674 | } | 
|  | 12675 |  | 
|  | 12676 | xmlCtxtReset(ctxt); | 
|  | 12677 |  | 
|  | 12678 | if (ctxt->pushTab == NULL) { | 
|  | 12679 | ctxt->pushTab = (void **) xmlMalloc(ctxt->nameMax * 3 * | 
|  | 12680 | sizeof(xmlChar *)); | 
|  | 12681 | if (ctxt->pushTab == NULL) { | 
|  | 12682 | xmlErrMemory(ctxt, NULL); | 
|  | 12683 | xmlFreeParserInputBuffer(buf); | 
|  | 12684 | return(1); | 
|  | 12685 | } | 
|  | 12686 | } | 
|  | 12687 |  | 
|  | 12688 | if (filename == NULL) { | 
|  | 12689 | ctxt->directory = NULL; | 
|  | 12690 | } else { | 
|  | 12691 | ctxt->directory = xmlParserGetDirectory(filename); | 
|  | 12692 | } | 
|  | 12693 |  | 
|  | 12694 | inputStream = xmlNewInputStream(ctxt); | 
|  | 12695 | if (inputStream == NULL) { | 
|  | 12696 | xmlFreeParserInputBuffer(buf); | 
|  | 12697 | return(1); | 
|  | 12698 | } | 
|  | 12699 |  | 
|  | 12700 | if (filename == NULL) | 
|  | 12701 | inputStream->filename = NULL; | 
|  | 12702 | else | 
|  | 12703 | inputStream->filename = (char *) | 
|  | 12704 | xmlCanonicPath((const xmlChar *) filename); | 
|  | 12705 | inputStream->buf = buf; | 
|  | 12706 | inputStream->base = inputStream->buf->buffer->content; | 
|  | 12707 | inputStream->cur = inputStream->buf->buffer->content; | 
|  | 12708 | inputStream->end = | 
|  | 12709 | &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; | 
|  | 12710 |  | 
|  | 12711 | inputPush(ctxt, inputStream); | 
|  | 12712 |  | 
|  | 12713 | if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && | 
|  | 12714 | (ctxt->input->buf != NULL)) { | 
|  | 12715 | int base = ctxt->input->base - ctxt->input->buf->buffer->content; | 
|  | 12716 | int cur = ctxt->input->cur - ctxt->input->base; | 
|  | 12717 |  | 
|  | 12718 | xmlParserInputBufferPush(ctxt->input->buf, size, chunk); | 
|  | 12719 |  | 
|  | 12720 | ctxt->input->base = ctxt->input->buf->buffer->content + base; | 
|  | 12721 | ctxt->input->cur = ctxt->input->base + cur; | 
|  | 12722 | ctxt->input->end = | 
|  | 12723 | &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer-> | 
|  | 12724 | use]; | 
|  | 12725 | #ifdef DEBUG_PUSH | 
|  | 12726 | xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); | 
|  | 12727 | #endif | 
|  | 12728 | } | 
|  | 12729 |  | 
|  | 12730 | if (encoding != NULL) { | 
|  | 12731 | xmlCharEncodingHandlerPtr hdlr; | 
|  | 12732 |  | 
|  | 12733 | hdlr = xmlFindCharEncodingHandler(encoding); | 
|  | 12734 | if (hdlr != NULL) { | 
|  | 12735 | xmlSwitchToEncoding(ctxt, hdlr); | 
|  | 12736 | } else { | 
|  | 12737 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING, | 
|  | 12738 | "Unsupported encoding %s\n", BAD_CAST encoding); | 
|  | 12739 | } | 
|  | 12740 | } else if (enc != XML_CHAR_ENCODING_NONE) { | 
|  | 12741 | xmlSwitchEncoding(ctxt, enc); | 
|  | 12742 | } | 
|  | 12743 |  | 
|  | 12744 | return(0); | 
|  | 12745 | } | 
|  | 12746 |  | 
|  | 12747 | /** | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12748 | * xmlCtxtUseOptions: | 
|  | 12749 | * @ctxt: an XML parser context | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 12750 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12751 | * | 
|  | 12752 | * Applies the options to the parser context | 
|  | 12753 | * | 
|  | 12754 | * Returns 0 in case of success, the set of unknown or unimplemented options | 
|  | 12755 | *         in case of error. | 
|  | 12756 | */ | 
|  | 12757 | int | 
|  | 12758 | xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options) | 
|  | 12759 | { | 
| Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 12760 | if (ctxt == NULL) | 
|  | 12761 | return(-1); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12762 | if (options & XML_PARSE_RECOVER) { | 
|  | 12763 | ctxt->recovery = 1; | 
|  | 12764 | options -= XML_PARSE_RECOVER; | 
|  | 12765 | } else | 
|  | 12766 | ctxt->recovery = 0; | 
|  | 12767 | if (options & XML_PARSE_DTDLOAD) { | 
|  | 12768 | ctxt->loadsubset = XML_DETECT_IDS; | 
|  | 12769 | options -= XML_PARSE_DTDLOAD; | 
|  | 12770 | } else | 
|  | 12771 | ctxt->loadsubset = 0; | 
|  | 12772 | if (options & XML_PARSE_DTDATTR) { | 
|  | 12773 | ctxt->loadsubset |= XML_COMPLETE_ATTRS; | 
|  | 12774 | options -= XML_PARSE_DTDATTR; | 
|  | 12775 | } | 
|  | 12776 | if (options & XML_PARSE_NOENT) { | 
|  | 12777 | ctxt->replaceEntities = 1; | 
|  | 12778 | /* ctxt->loadsubset |= XML_DETECT_IDS; */ | 
|  | 12779 | options -= XML_PARSE_NOENT; | 
|  | 12780 | } else | 
|  | 12781 | ctxt->replaceEntities = 0; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12782 | if (options & XML_PARSE_PEDANTIC) { | 
|  | 12783 | ctxt->pedantic = 1; | 
|  | 12784 | options -= XML_PARSE_PEDANTIC; | 
|  | 12785 | } else | 
|  | 12786 | ctxt->pedantic = 0; | 
|  | 12787 | if (options & XML_PARSE_NOBLANKS) { | 
|  | 12788 | ctxt->keepBlanks = 0; | 
|  | 12789 | ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace; | 
|  | 12790 | options -= XML_PARSE_NOBLANKS; | 
|  | 12791 | } else | 
|  | 12792 | ctxt->keepBlanks = 1; | 
|  | 12793 | if (options & XML_PARSE_DTDVALID) { | 
|  | 12794 | ctxt->validate = 1; | 
|  | 12795 | if (options & XML_PARSE_NOWARNING) | 
|  | 12796 | ctxt->vctxt.warning = NULL; | 
|  | 12797 | if (options & XML_PARSE_NOERROR) | 
|  | 12798 | ctxt->vctxt.error = NULL; | 
|  | 12799 | options -= XML_PARSE_DTDVALID; | 
|  | 12800 | } else | 
|  | 12801 | ctxt->validate = 0; | 
| Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 12802 | if (options & XML_PARSE_NOWARNING) { | 
|  | 12803 | ctxt->sax->warning = NULL; | 
|  | 12804 | options -= XML_PARSE_NOWARNING; | 
|  | 12805 | } | 
|  | 12806 | if (options & XML_PARSE_NOERROR) { | 
|  | 12807 | ctxt->sax->error = NULL; | 
|  | 12808 | ctxt->sax->fatalError = NULL; | 
|  | 12809 | options -= XML_PARSE_NOERROR; | 
|  | 12810 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12811 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12812 | if (options & XML_PARSE_SAX1) { | 
|  | 12813 | ctxt->sax->startElement = xmlSAX2StartElement; | 
|  | 12814 | ctxt->sax->endElement = xmlSAX2EndElement; | 
|  | 12815 | ctxt->sax->startElementNs = NULL; | 
|  | 12816 | ctxt->sax->endElementNs = NULL; | 
|  | 12817 | ctxt->sax->initialized = 1; | 
|  | 12818 | options -= XML_PARSE_SAX1; | 
|  | 12819 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 12820 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12821 | if (options & XML_PARSE_NODICT) { | 
|  | 12822 | ctxt->dictNames = 0; | 
|  | 12823 | options -= XML_PARSE_NODICT; | 
|  | 12824 | } else { | 
|  | 12825 | ctxt->dictNames = 1; | 
|  | 12826 | } | 
| Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 12827 | if (options & XML_PARSE_NOCDATA) { | 
|  | 12828 | ctxt->sax->cdataBlock = NULL; | 
|  | 12829 | options -= XML_PARSE_NOCDATA; | 
|  | 12830 | } | 
|  | 12831 | if (options & XML_PARSE_NSCLEAN) { | 
|  | 12832 | ctxt->options |= XML_PARSE_NSCLEAN; | 
|  | 12833 | options -= XML_PARSE_NSCLEAN; | 
|  | 12834 | } | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 12835 | if (options & XML_PARSE_NONET) { | 
|  | 12836 | ctxt->options |= XML_PARSE_NONET; | 
|  | 12837 | options -= XML_PARSE_NONET; | 
|  | 12838 | } | 
| Daniel Veillard | 7ec2997 | 2003-10-31 14:36:36 +0000 | [diff] [blame] | 12839 | ctxt->linenumbers = 1; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12840 | return (options); | 
|  | 12841 | } | 
|  | 12842 |  | 
|  | 12843 | /** | 
|  | 12844 | * xmlDoRead: | 
|  | 12845 | * @ctxt:  an XML parser context | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12846 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12847 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 12848 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12849 | * @reuse:  keep the context for reuse | 
|  | 12850 | * | 
|  | 12851 | * Common front-end for the xmlRead functions | 
|  | 12852 | * | 
|  | 12853 | * Returns the resulting document tree or NULL | 
|  | 12854 | */ | 
|  | 12855 | static xmlDocPtr | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12856 | xmlDoRead(xmlParserCtxtPtr ctxt, const char *URL, const char *encoding, | 
|  | 12857 | int options, int reuse) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12858 | { | 
|  | 12859 | xmlDocPtr ret; | 
|  | 12860 |  | 
|  | 12861 | xmlCtxtUseOptions(ctxt, options); | 
|  | 12862 | if (encoding != NULL) { | 
|  | 12863 | xmlCharEncodingHandlerPtr hdlr; | 
|  | 12864 |  | 
|  | 12865 | hdlr = xmlFindCharEncodingHandler(encoding); | 
|  | 12866 | if (hdlr != NULL) | 
|  | 12867 | xmlSwitchToEncoding(ctxt, hdlr); | 
|  | 12868 | } | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12869 | if ((URL != NULL) && (ctxt->input != NULL) && | 
|  | 12870 | (ctxt->input->filename == NULL)) | 
|  | 12871 | ctxt->input->filename = (char *) xmlStrdup((const xmlChar *) URL); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12872 | xmlParseDocument(ctxt); | 
|  | 12873 | if ((ctxt->wellFormed) || ctxt->recovery) | 
|  | 12874 | ret = ctxt->myDoc; | 
|  | 12875 | else { | 
|  | 12876 | ret = NULL; | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12877 | if (ctxt->myDoc != NULL) { | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12878 | xmlFreeDoc(ctxt->myDoc); | 
|  | 12879 | } | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12880 | } | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12881 | ctxt->myDoc = NULL; | 
|  | 12882 | if (!reuse) { | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12883 | xmlFreeParserCtxt(ctxt); | 
| Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 12884 | } | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12885 |  | 
|  | 12886 | return (ret); | 
|  | 12887 | } | 
|  | 12888 |  | 
|  | 12889 | /** | 
|  | 12890 | * xmlReadDoc: | 
|  | 12891 | * @cur:  a pointer to a zero terminated string | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12892 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12893 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 12894 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12895 | * | 
|  | 12896 | * parse an XML in-memory document and build a tree. | 
|  | 12897 | * | 
|  | 12898 | * Returns the resulting document tree | 
|  | 12899 | */ | 
|  | 12900 | xmlDocPtr | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12901 | xmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12902 | { | 
|  | 12903 | xmlParserCtxtPtr ctxt; | 
|  | 12904 |  | 
|  | 12905 | if (cur == NULL) | 
|  | 12906 | return (NULL); | 
|  | 12907 |  | 
|  | 12908 | ctxt = xmlCreateDocParserCtxt(cur); | 
|  | 12909 | if (ctxt == NULL) | 
|  | 12910 | return (NULL); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12911 | return (xmlDoRead(ctxt, URL, encoding, options, 0)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12912 | } | 
|  | 12913 |  | 
|  | 12914 | /** | 
|  | 12915 | * xmlReadFile: | 
|  | 12916 | * @filename:  a file or URL | 
|  | 12917 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 12918 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12919 | * | 
|  | 12920 | * parse an XML file from the filesystem or the network. | 
|  | 12921 | * | 
|  | 12922 | * Returns the resulting document tree | 
|  | 12923 | */ | 
|  | 12924 | xmlDocPtr | 
|  | 12925 | xmlReadFile(const char *filename, const char *encoding, int options) | 
|  | 12926 | { | 
|  | 12927 | xmlParserCtxtPtr ctxt; | 
|  | 12928 |  | 
| Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 12929 | ctxt = xmlCreateURLParserCtxt(filename, options); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12930 | if (ctxt == NULL) | 
|  | 12931 | return (NULL); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12932 | return (xmlDoRead(ctxt, NULL, encoding, options, 0)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12933 | } | 
|  | 12934 |  | 
|  | 12935 | /** | 
|  | 12936 | * xmlReadMemory: | 
|  | 12937 | * @buffer:  a pointer to a char array | 
|  | 12938 | * @size:  the size of the array | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12939 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12940 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 12941 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12942 | * | 
|  | 12943 | * parse an XML in-memory document and build a tree. | 
|  | 12944 | * | 
|  | 12945 | * Returns the resulting document tree | 
|  | 12946 | */ | 
|  | 12947 | xmlDocPtr | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12948 | xmlReadMemory(const char *buffer, int size, const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12949 | { | 
|  | 12950 | xmlParserCtxtPtr ctxt; | 
|  | 12951 |  | 
|  | 12952 | ctxt = xmlCreateMemoryParserCtxt(buffer, size); | 
|  | 12953 | if (ctxt == NULL) | 
|  | 12954 | return (NULL); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12955 | return (xmlDoRead(ctxt, URL, encoding, options, 0)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12956 | } | 
|  | 12957 |  | 
|  | 12958 | /** | 
|  | 12959 | * xmlReadFd: | 
|  | 12960 | * @fd:  an open file descriptor | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12961 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12962 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 12963 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12964 | * | 
|  | 12965 | * parse an XML from a file descriptor and build a tree. | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 12966 | * NOTE that the file descriptor will not be closed when the | 
|  | 12967 | *      reader is closed or reset. | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12968 | * | 
|  | 12969 | * Returns the resulting document tree | 
|  | 12970 | */ | 
|  | 12971 | xmlDocPtr | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12972 | xmlReadFd(int fd, const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12973 | { | 
|  | 12974 | xmlParserCtxtPtr ctxt; | 
|  | 12975 | xmlParserInputBufferPtr input; | 
|  | 12976 | xmlParserInputPtr stream; | 
|  | 12977 |  | 
|  | 12978 | if (fd < 0) | 
|  | 12979 | return (NULL); | 
|  | 12980 |  | 
|  | 12981 | input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); | 
|  | 12982 | if (input == NULL) | 
|  | 12983 | return (NULL); | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 12984 | input->closecallback = NULL; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12985 | ctxt = xmlNewParserCtxt(); | 
|  | 12986 | if (ctxt == NULL) { | 
|  | 12987 | xmlFreeParserInputBuffer(input); | 
|  | 12988 | return (NULL); | 
|  | 12989 | } | 
|  | 12990 | stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); | 
|  | 12991 | if (stream == NULL) { | 
|  | 12992 | xmlFreeParserInputBuffer(input); | 
|  | 12993 | xmlFreeParserCtxt(ctxt); | 
|  | 12994 | return (NULL); | 
|  | 12995 | } | 
|  | 12996 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 12997 | return (xmlDoRead(ctxt, URL, encoding, options, 0)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 12998 | } | 
|  | 12999 |  | 
|  | 13000 | /** | 
|  | 13001 | * xmlReadIO: | 
|  | 13002 | * @ioread:  an I/O read function | 
|  | 13003 | * @ioclose:  an I/O close function | 
|  | 13004 | * @ioctx:  an I/O handler | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13005 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13006 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 13007 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13008 | * | 
|  | 13009 | * parse an XML document from I/O functions and source and build a tree. | 
|  | 13010 | * | 
|  | 13011 | * Returns the resulting document tree | 
|  | 13012 | */ | 
|  | 13013 | xmlDocPtr | 
|  | 13014 | xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13015 | void *ioctx, const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13016 | { | 
|  | 13017 | xmlParserCtxtPtr ctxt; | 
|  | 13018 | xmlParserInputBufferPtr input; | 
|  | 13019 | xmlParserInputPtr stream; | 
|  | 13020 |  | 
|  | 13021 | if (ioread == NULL) | 
|  | 13022 | return (NULL); | 
|  | 13023 |  | 
|  | 13024 | input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, | 
|  | 13025 | XML_CHAR_ENCODING_NONE); | 
|  | 13026 | if (input == NULL) | 
|  | 13027 | return (NULL); | 
|  | 13028 | ctxt = xmlNewParserCtxt(); | 
|  | 13029 | if (ctxt == NULL) { | 
|  | 13030 | xmlFreeParserInputBuffer(input); | 
|  | 13031 | return (NULL); | 
|  | 13032 | } | 
|  | 13033 | stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); | 
|  | 13034 | if (stream == NULL) { | 
|  | 13035 | xmlFreeParserInputBuffer(input); | 
|  | 13036 | xmlFreeParserCtxt(ctxt); | 
|  | 13037 | return (NULL); | 
|  | 13038 | } | 
|  | 13039 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13040 | return (xmlDoRead(ctxt, URL, encoding, options, 0)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13041 | } | 
|  | 13042 |  | 
|  | 13043 | /** | 
|  | 13044 | * xmlCtxtReadDoc: | 
|  | 13045 | * @ctxt:  an XML parser context | 
|  | 13046 | * @cur:  a pointer to a zero terminated string | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13047 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13048 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 13049 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13050 | * | 
|  | 13051 | * parse an XML in-memory document and build a tree. | 
|  | 13052 | * This reuses the existing @ctxt parser context | 
|  | 13053 | * | 
|  | 13054 | * Returns the resulting document tree | 
|  | 13055 | */ | 
|  | 13056 | xmlDocPtr | 
|  | 13057 | xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur, | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13058 | const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13059 | { | 
|  | 13060 | xmlParserInputPtr stream; | 
|  | 13061 |  | 
|  | 13062 | if (cur == NULL) | 
|  | 13063 | return (NULL); | 
|  | 13064 | if (ctxt == NULL) | 
|  | 13065 | return (NULL); | 
|  | 13066 |  | 
|  | 13067 | xmlCtxtReset(ctxt); | 
|  | 13068 |  | 
|  | 13069 | stream = xmlNewStringInputStream(ctxt, cur); | 
|  | 13070 | if (stream == NULL) { | 
|  | 13071 | return (NULL); | 
|  | 13072 | } | 
|  | 13073 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13074 | return (xmlDoRead(ctxt, URL, encoding, options, 1)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13075 | } | 
|  | 13076 |  | 
|  | 13077 | /** | 
|  | 13078 | * xmlCtxtReadFile: | 
|  | 13079 | * @ctxt:  an XML parser context | 
|  | 13080 | * @filename:  a file or URL | 
|  | 13081 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 13082 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13083 | * | 
|  | 13084 | * parse an XML file from the filesystem or the network. | 
|  | 13085 | * This reuses the existing @ctxt parser context | 
|  | 13086 | * | 
|  | 13087 | * Returns the resulting document tree | 
|  | 13088 | */ | 
|  | 13089 | xmlDocPtr | 
|  | 13090 | xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename, | 
|  | 13091 | const char *encoding, int options) | 
|  | 13092 | { | 
|  | 13093 | xmlParserInputPtr stream; | 
|  | 13094 |  | 
|  | 13095 | if (filename == NULL) | 
|  | 13096 | return (NULL); | 
|  | 13097 | if (ctxt == NULL) | 
|  | 13098 | return (NULL); | 
|  | 13099 |  | 
|  | 13100 | xmlCtxtReset(ctxt); | 
|  | 13101 |  | 
| Daniel Veillard | 29614c7 | 2004-11-26 10:47:26 +0000 | [diff] [blame] | 13102 | stream = xmlLoadExternalEntity(filename, NULL, ctxt); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13103 | if (stream == NULL) { | 
|  | 13104 | return (NULL); | 
|  | 13105 | } | 
|  | 13106 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13107 | return (xmlDoRead(ctxt, NULL, encoding, options, 1)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13108 | } | 
|  | 13109 |  | 
|  | 13110 | /** | 
|  | 13111 | * xmlCtxtReadMemory: | 
|  | 13112 | * @ctxt:  an XML parser context | 
|  | 13113 | * @buffer:  a pointer to a char array | 
|  | 13114 | * @size:  the size of the array | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13115 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13116 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 13117 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13118 | * | 
|  | 13119 | * parse an XML in-memory document and build a tree. | 
|  | 13120 | * This reuses the existing @ctxt parser context | 
|  | 13121 | * | 
|  | 13122 | * Returns the resulting document tree | 
|  | 13123 | */ | 
|  | 13124 | xmlDocPtr | 
|  | 13125 | xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size, | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13126 | const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13127 | { | 
|  | 13128 | xmlParserInputBufferPtr input; | 
|  | 13129 | xmlParserInputPtr stream; | 
|  | 13130 |  | 
|  | 13131 | if (ctxt == NULL) | 
|  | 13132 | return (NULL); | 
|  | 13133 | if (buffer == NULL) | 
|  | 13134 | return (NULL); | 
|  | 13135 |  | 
|  | 13136 | xmlCtxtReset(ctxt); | 
|  | 13137 |  | 
|  | 13138 | input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE); | 
|  | 13139 | if (input == NULL) { | 
|  | 13140 | return(NULL); | 
|  | 13141 | } | 
|  | 13142 |  | 
|  | 13143 | stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); | 
|  | 13144 | if (stream == NULL) { | 
|  | 13145 | xmlFreeParserInputBuffer(input); | 
|  | 13146 | return(NULL); | 
|  | 13147 | } | 
|  | 13148 |  | 
|  | 13149 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13150 | return (xmlDoRead(ctxt, URL, encoding, options, 1)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13151 | } | 
|  | 13152 |  | 
|  | 13153 | /** | 
|  | 13154 | * xmlCtxtReadFd: | 
|  | 13155 | * @ctxt:  an XML parser context | 
|  | 13156 | * @fd:  an open file descriptor | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13157 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13158 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 13159 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13160 | * | 
|  | 13161 | * parse an XML from a file descriptor and build a tree. | 
|  | 13162 | * This reuses the existing @ctxt parser context | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 13163 | * NOTE that the file descriptor will not be closed when the | 
|  | 13164 | *      reader is closed or reset. | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13165 | * | 
|  | 13166 | * Returns the resulting document tree | 
|  | 13167 | */ | 
|  | 13168 | xmlDocPtr | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13169 | xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd, | 
|  | 13170 | const char *URL, const char *encoding, int options) | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13171 | { | 
|  | 13172 | xmlParserInputBufferPtr input; | 
|  | 13173 | xmlParserInputPtr stream; | 
|  | 13174 |  | 
|  | 13175 | if (fd < 0) | 
|  | 13176 | return (NULL); | 
|  | 13177 | if (ctxt == NULL) | 
|  | 13178 | return (NULL); | 
|  | 13179 |  | 
|  | 13180 | xmlCtxtReset(ctxt); | 
|  | 13181 |  | 
|  | 13182 |  | 
|  | 13183 | input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); | 
|  | 13184 | if (input == NULL) | 
|  | 13185 | return (NULL); | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 13186 | input->closecallback = NULL; | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13187 | stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); | 
|  | 13188 | if (stream == NULL) { | 
|  | 13189 | xmlFreeParserInputBuffer(input); | 
|  | 13190 | return (NULL); | 
|  | 13191 | } | 
|  | 13192 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13193 | return (xmlDoRead(ctxt, URL, encoding, options, 1)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13194 | } | 
|  | 13195 |  | 
|  | 13196 | /** | 
|  | 13197 | * xmlCtxtReadIO: | 
|  | 13198 | * @ctxt:  an XML parser context | 
|  | 13199 | * @ioread:  an I/O read function | 
|  | 13200 | * @ioclose:  an I/O close function | 
|  | 13201 | * @ioctx:  an I/O handler | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13202 | * @URL:  the base URL to use for the document | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13203 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 13204 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13205 | * | 
|  | 13206 | * parse an XML document from I/O functions and source and build a tree. | 
|  | 13207 | * This reuses the existing @ctxt parser context | 
|  | 13208 | * | 
|  | 13209 | * Returns the resulting document tree | 
|  | 13210 | */ | 
|  | 13211 | xmlDocPtr | 
|  | 13212 | xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread, | 
|  | 13213 | xmlInputCloseCallback ioclose, void *ioctx, | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13214 | const char *URL, | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13215 | const char *encoding, int options) | 
|  | 13216 | { | 
|  | 13217 | xmlParserInputBufferPtr input; | 
|  | 13218 | xmlParserInputPtr stream; | 
|  | 13219 |  | 
|  | 13220 | if (ioread == NULL) | 
|  | 13221 | return (NULL); | 
|  | 13222 | if (ctxt == NULL) | 
|  | 13223 | return (NULL); | 
|  | 13224 |  | 
|  | 13225 | xmlCtxtReset(ctxt); | 
|  | 13226 |  | 
|  | 13227 | input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, | 
|  | 13228 | XML_CHAR_ENCODING_NONE); | 
|  | 13229 | if (input == NULL) | 
|  | 13230 | return (NULL); | 
|  | 13231 | stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); | 
|  | 13232 | if (stream == NULL) { | 
|  | 13233 | xmlFreeParserInputBuffer(input); | 
|  | 13234 | return (NULL); | 
|  | 13235 | } | 
|  | 13236 | inputPush(ctxt, stream); | 
| Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 13237 | return (xmlDoRead(ctxt, URL, encoding, options, 1)); | 
| Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 13238 | } | 
| Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 13239 |  | 
|  | 13240 | #define bottom_parser | 
|  | 13241 | #include "elfgcchack.h" |