Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 2 | * parser.c : an XML 1.0 parser, namespaces and validity support are mostly |
| 3 | * implemented on top of the SAX interfaces |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4 | * |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 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 | * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 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 |
| 15 | * high level APIs to call the parser and a few miscelaneous functions. |
| 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 |
| 25 | * from the SAx callbacks or as standalones functions using a preparsed |
| 26 | * document. |
| 27 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 28 | * See Copyright for the status of this software. |
| 29 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 30 | * Daniel.Veillard@w3.org |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #ifdef WIN32 |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 34 | #include "win32config.h" |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 35 | #define XML_DIR_SEP '\\' |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 36 | #else |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 37 | #include "config.h" |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 38 | #define XML_DIR_SEP '/' |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 39 | #endif |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 40 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 41 | #include <stdio.h> |
Daniel Veillard | b71379b | 2000-10-09 12:30:39 +0000 | [diff] [blame] | 42 | #include <stdlib.h> |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 43 | #include <string.h> |
Daniel Veillard | b71379b | 2000-10-09 12:30:39 +0000 | [diff] [blame] | 44 | #include <libxml/xmlmemory.h> |
| 45 | #include <libxml/tree.h> |
| 46 | #include <libxml/parser.h> |
| 47 | #include <libxml/parserInternals.h> |
| 48 | #include <libxml/valid.h> |
| 49 | #include <libxml/entities.h> |
| 50 | #include <libxml/xmlerror.h> |
| 51 | #include <libxml/encoding.h> |
| 52 | #include <libxml/xmlIO.h> |
| 53 | #include <libxml/uri.h> |
| 54 | |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 55 | #ifdef HAVE_CTYPE_H |
| 56 | #include <ctype.h> |
| 57 | #endif |
| 58 | #ifdef HAVE_STDLIB_H |
Seth Alves | e7f12e6 | 1998-10-01 20:51:15 +0000 | [diff] [blame] | 59 | #include <stdlib.h> |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 60 | #endif |
| 61 | #ifdef HAVE_SYS_STAT_H |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 62 | #include <sys/stat.h> |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 63 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 64 | #ifdef HAVE_FCNTL_H |
| 65 | #include <fcntl.h> |
| 66 | #endif |
| 67 | #ifdef HAVE_UNISTD_H |
| 68 | #include <unistd.h> |
| 69 | #endif |
| 70 | #ifdef HAVE_ZLIB_H |
| 71 | #include <zlib.h> |
| 72 | #endif |
| 73 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 74 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 75 | #define XML_PARSER_BIG_BUFFER_SIZE 1000 |
| 76 | #define XML_PARSER_BUFFER_SIZE 100 |
| 77 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 78 | /* |
| 79 | * Various global defaults for parsing |
| 80 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 81 | int xmlGetWarningsDefaultValue = 1; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 82 | int xmlParserDebugEntities = 0; |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 83 | int xmlSubstituteEntitiesDefaultValue = 0; |
| 84 | int xmlDoValidityCheckingDefaultValue = 0; |
| 85 | int xmlPedanticParserDefaultValue = 0; |
| 86 | int xmlKeepBlanksDefaultValue = 1; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 87 | |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 88 | /* |
| 89 | * List of XML prefixed PI allowed by W3C specs |
| 90 | */ |
| 91 | |
| 92 | const char *xmlW3CPIs[] = { |
| 93 | "xml-stylesheet", |
| 94 | NULL |
| 95 | }; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 96 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 97 | /* DEPR void xmlParserHandleReference(xmlParserCtxtPtr ctxt); */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 98 | void xmlParserHandlePEReference(xmlParserCtxtPtr ctxt); |
| 99 | xmlEntityPtr xmlParseStringPEReference(xmlParserCtxtPtr ctxt, |
| 100 | const xmlChar **str); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 101 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 102 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 103 | /************************************************************************ |
| 104 | * * |
| 105 | * Parser stacks related functions and macros * |
| 106 | * * |
| 107 | ************************************************************************/ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 108 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 109 | xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, |
| 110 | const xmlChar ** str); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 111 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 112 | /* |
| 113 | * Generic function for accessing stacks in the Parser Context |
| 114 | */ |
| 115 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 116 | #define PUSH_AND_POP(scope, type, name) \ |
| 117 | scope int name##Push(xmlParserCtxtPtr ctxt, type value) { \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 118 | if (ctxt->name##Nr >= ctxt->name##Max) { \ |
| 119 | ctxt->name##Max *= 2; \ |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 120 | ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 121 | ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \ |
| 122 | if (ctxt->name##Tab == NULL) { \ |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 123 | xmlGenericError(xmlGenericErrorContext, \ |
| 124 | "realloc failed !\n"); \ |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 125 | return(0); \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 126 | } \ |
| 127 | } \ |
| 128 | ctxt->name##Tab[ctxt->name##Nr] = value; \ |
| 129 | ctxt->name = value; \ |
| 130 | return(ctxt->name##Nr++); \ |
| 131 | } \ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 132 | scope type name##Pop(xmlParserCtxtPtr ctxt) { \ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 133 | type ret; \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 134 | if (ctxt->name##Nr <= 0) return(0); \ |
| 135 | ctxt->name##Nr--; \ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 136 | if (ctxt->name##Nr > 0) \ |
| 137 | ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \ |
| 138 | else \ |
| 139 | ctxt->name = NULL; \ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 140 | ret = ctxt->name##Tab[ctxt->name##Nr]; \ |
| 141 | ctxt->name##Tab[ctxt->name##Nr] = 0; \ |
| 142 | return(ret); \ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 143 | } \ |
| 144 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 145 | /* |
| 146 | * Those macros actually generate the functions |
| 147 | */ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 148 | PUSH_AND_POP(extern, xmlParserInputPtr, input) |
| 149 | PUSH_AND_POP(extern, xmlNodePtr, node) |
| 150 | PUSH_AND_POP(extern, xmlChar*, name) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 151 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 152 | int spacePush(xmlParserCtxtPtr ctxt, int val) { |
| 153 | if (ctxt->spaceNr >= ctxt->spaceMax) { |
| 154 | ctxt->spaceMax *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 155 | ctxt->spaceTab = (int *) xmlRealloc(ctxt->spaceTab, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 156 | ctxt->spaceMax * sizeof(ctxt->spaceTab[0])); |
| 157 | if (ctxt->spaceTab == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 158 | xmlGenericError(xmlGenericErrorContext, |
| 159 | "realloc failed !\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 160 | return(0); |
| 161 | } |
| 162 | } |
| 163 | ctxt->spaceTab[ctxt->spaceNr] = val; |
| 164 | ctxt->space = &ctxt->spaceTab[ctxt->spaceNr]; |
| 165 | return(ctxt->spaceNr++); |
| 166 | } |
| 167 | |
| 168 | int spacePop(xmlParserCtxtPtr ctxt) { |
| 169 | int ret; |
| 170 | if (ctxt->spaceNr <= 0) return(0); |
| 171 | ctxt->spaceNr--; |
| 172 | if (ctxt->spaceNr > 0) |
| 173 | ctxt->space = &ctxt->spaceTab[ctxt->spaceNr - 1]; |
| 174 | else |
| 175 | ctxt->space = NULL; |
| 176 | ret = ctxt->spaceTab[ctxt->spaceNr]; |
| 177 | ctxt->spaceTab[ctxt->spaceNr] = -1; |
| 178 | return(ret); |
| 179 | } |
| 180 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 181 | /* |
| 182 | * Macros for accessing the content. Those should be used only by the parser, |
| 183 | * and not exported. |
| 184 | * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 185 | * Dirty macros, i.e. one often need to make assumption on the context to |
| 186 | * use them |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 187 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 188 | * CUR_PTR return the current pointer to the xmlChar to be parsed. |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 189 | * To be used with extreme caution since operations consuming |
| 190 | * characters may move the input buffer to a different location ! |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 191 | * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 192 | * This should be used internally by the parser |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 193 | * only to compare to ASCII values otherwise it would break when |
| 194 | * running with UTF-8 encoding. |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 195 | * RAW same as CUR but in the input buffer, bypass any token |
| 196 | * extraction that may have been done |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 197 | * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 198 | * to compare on ASCII based substring. |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 199 | * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 200 | * strings within the parser. |
| 201 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 202 | * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 203 | * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 204 | * NEXT Skip to the next character, this does the proper decoding |
| 205 | * in UTF-8 mode. It also pop-up unfinished entities on the fly. |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 206 | * NEXTL(l) Skip l xmlChars in the input buffer |
| 207 | * CUR_CHAR(l) returns the current unicode character (int), set l |
| 208 | * to the number of xmlChars used for the encoding [0-5]. |
| 209 | * CUR_SCHAR same but operate on a string instead of the context |
| 210 | * COPY_BUF copy the current unicode char to the target buffer, increment |
| 211 | * the index |
| 212 | * GROW, SHRINK handling of input buffers |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 213 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 214 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 215 | #define RAW (ctxt->token ? -1 : (*ctxt->input->cur)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 216 | #define CUR (ctxt->token ? ctxt->token : (*ctxt->input->cur)) |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 217 | #define NXT(val) ctxt->input->cur[(val)] |
| 218 | #define CUR_PTR ctxt->input->cur |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 219 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 220 | #define SKIP(val) do { \ |
| 221 | ctxt->nbChars += (val),ctxt->input->cur += (val); \ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 222 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 223 | /* DEPR if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); */\ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 224 | if ((*ctxt->input->cur == 0) && \ |
| 225 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 226 | xmlPopInput(ctxt); \ |
| 227 | } while (0) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 228 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 229 | #define SHRINK do { \ |
| 230 | xmlParserInputShrink(ctxt->input); \ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 231 | if ((*ctxt->input->cur == 0) && \ |
| 232 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 233 | xmlPopInput(ctxt); \ |
| 234 | } while (0) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 235 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 236 | #define GROW do { \ |
| 237 | xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 238 | if ((*ctxt->input->cur == 0) && \ |
| 239 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 240 | xmlPopInput(ctxt); \ |
| 241 | } while (0) |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 242 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 243 | #define SKIP_BLANKS xmlSkipBlankChars(ctxt) |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 244 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 245 | #define NEXT xmlNextChar(ctxt) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 246 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 247 | #define NEXTL(l) do { \ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 248 | if (*(ctxt->input->cur) == '\n') { \ |
| 249 | ctxt->input->line++; ctxt->input->col = 1; \ |
| 250 | } else ctxt->input->col++; \ |
| 251 | ctxt->token = 0; ctxt->input->cur += l; \ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 252 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 253 | /* DEPR if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); */\ |
| 254 | } while (0) |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 255 | |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 256 | #define CUR_CHAR(l) xmlCurrentChar(ctxt, &l) |
| 257 | #define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 258 | |
| 259 | #define COPY_BUF(l,b,i,v) \ |
| 260 | if (l == 1) b[i++] = (xmlChar) v; \ |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 261 | else i += xmlCopyChar(l,&b[i],v) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 264 | * xmlSkipBlankChars: |
| 265 | * @ctxt: the XML parser context |
| 266 | * |
| 267 | * skip all blanks character found at that point in the input streams. |
| 268 | * It pops up finished entities in the process if allowable at that point. |
| 269 | * |
| 270 | * Returns the number of space chars skipped |
| 271 | */ |
| 272 | |
| 273 | int |
| 274 | xmlSkipBlankChars(xmlParserCtxtPtr ctxt) { |
| 275 | int cur, res = 0; |
| 276 | |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 277 | /* |
| 278 | * It's Okay to use CUR/NEXT here since all the blanks are on |
| 279 | * the ASCII range. |
| 280 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 281 | do { |
| 282 | cur = CUR; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 283 | while (IS_BLANK(cur)) { /* CHECKED tstblanks.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 284 | NEXT; |
| 285 | cur = CUR; |
| 286 | res++; |
| 287 | } |
| 288 | while ((cur == 0) && (ctxt->inputNr > 1) && |
| 289 | (ctxt->instate != XML_PARSER_COMMENT)) { |
| 290 | xmlPopInput(ctxt); |
| 291 | cur = CUR; |
| 292 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 293 | /* |
| 294 | * Need to handle support of entities branching here |
| 295 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 296 | if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 297 | /* DEPR if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); */ |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 298 | } while (IS_BLANK(cur)); /* CHECKED tstblanks.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 299 | return(res); |
| 300 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 301 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 302 | /************************************************************************ |
| 303 | * * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 304 | * Commodity functions to handle entities * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 305 | * * |
| 306 | ************************************************************************/ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 307 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 308 | /** |
| 309 | * xmlPopInput: |
| 310 | * @ctxt: an XML parser context |
| 311 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 312 | * xmlPopInput: the current input pointed by ctxt->input came to an end |
| 313 | * pop it and return the next char. |
| 314 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 315 | * Returns the current xmlChar in the parser context |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 316 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 317 | xmlChar |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 318 | xmlPopInput(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 319 | if (ctxt->inputNr == 1) return(0); /* End of main Input */ |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 320 | if (xmlParserDebugEntities) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 321 | xmlGenericError(xmlGenericErrorContext, |
| 322 | "Popping input %d\n", ctxt->inputNr); |
Daniel Veillard | bc50b59 | 1999-03-01 12:28:53 +0000 | [diff] [blame] | 323 | xmlFreeInputStream(inputPop(ctxt)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 324 | if ((*ctxt->input->cur == 0) && |
| 325 | (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) |
| 326 | return(xmlPopInput(ctxt)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 327 | return(CUR); |
| 328 | } |
| 329 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 330 | /** |
| 331 | * xmlPushInput: |
| 332 | * @ctxt: an XML parser context |
| 333 | * @input: an XML parser input fragment (entity, XML fragment ...). |
| 334 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 335 | * xmlPushInput: switch to a new input stream which is stacked on top |
| 336 | * of the previous one(s). |
| 337 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 338 | void |
| 339 | xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 340 | if (input == NULL) return; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 341 | |
| 342 | if (xmlParserDebugEntities) { |
| 343 | if ((ctxt->input != NULL) && (ctxt->input->filename)) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 344 | xmlGenericError(xmlGenericErrorContext, |
| 345 | "%s(%d): ", ctxt->input->filename, |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 346 | ctxt->input->line); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 347 | xmlGenericError(xmlGenericErrorContext, |
| 348 | "Pushing input %d : %.30s\n", ctxt->inputNr+1, input->cur); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 349 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 350 | inputPush(ctxt, input); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 351 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 354 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 355 | * xmlParseCharRef: |
| 356 | * @ctxt: an XML parser context |
| 357 | * |
| 358 | * parse Reference declarations |
| 359 | * |
| 360 | * [66] CharRef ::= '&#' [0-9]+ ';' | |
| 361 | * '&#x' [0-9a-fA-F]+ ';' |
| 362 | * |
| 363 | * [ WFC: Legal Character ] |
| 364 | * Characters referred to using character references must match the |
| 365 | * production for Char. |
| 366 | * |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 367 | * Returns the value parsed (as an int), 0 in case of error |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 368 | */ |
| 369 | int |
| 370 | xmlParseCharRef(xmlParserCtxtPtr ctxt) { |
| 371 | int val = 0; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 372 | int count = 0; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 373 | |
| 374 | if (ctxt->token != 0) { |
| 375 | val = ctxt->token; |
| 376 | ctxt->token = 0; |
| 377 | return(val); |
| 378 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 379 | /* |
| 380 | * Using RAW/CUR/NEXT is okay since we are working on ASCII range here |
| 381 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 382 | if ((RAW == '&') && (NXT(1) == '#') && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 383 | (NXT(2) == 'x')) { |
| 384 | SKIP(3); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 385 | GROW; |
| 386 | while (RAW != ';') { /* loop blocked by count */ |
| 387 | if ((RAW >= '0') && (RAW <= '9') && (count < 20)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 388 | val = val * 16 + (CUR - '0'); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 389 | else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 390 | val = val * 16 + (CUR - 'a') + 10; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 391 | else if ((RAW >= 'A') && (RAW <= 'F') && (count < 20)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 392 | val = val * 16 + (CUR - 'A') + 10; |
| 393 | else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 394 | ctxt->errNo = XML_ERR_INVALID_HEX_CHARREF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 395 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 396 | ctxt->sax->error(ctxt->userData, |
| 397 | "xmlParseCharRef: invalid hexadecimal value\n"); |
| 398 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 399 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 400 | val = 0; |
| 401 | break; |
| 402 | } |
| 403 | NEXT; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 404 | count++; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 405 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 406 | if (RAW == ';') { |
| 407 | /* on purpose to avoid reentrancy problems with NEXT and SKIP */ |
| 408 | ctxt->nbChars ++; |
| 409 | ctxt->input->cur++; |
| 410 | } |
| 411 | } else if ((RAW == '&') && (NXT(1) == '#')) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 412 | SKIP(2); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 413 | GROW; |
| 414 | while (RAW != ';') { /* loop blocked by count */ |
| 415 | if ((RAW >= '0') && (RAW <= '9') && (count < 20)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 416 | val = val * 10 + (CUR - '0'); |
| 417 | else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 418 | ctxt->errNo = XML_ERR_INVALID_DEC_CHARREF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 419 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 420 | ctxt->sax->error(ctxt->userData, |
| 421 | "xmlParseCharRef: invalid decimal value\n"); |
| 422 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 423 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 424 | val = 0; |
| 425 | break; |
| 426 | } |
| 427 | NEXT; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 428 | count++; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 429 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 430 | if (RAW == ';') { |
| 431 | /* on purpose to avoid reentrancy problems with NEXT and SKIP */ |
| 432 | ctxt->nbChars ++; |
| 433 | ctxt->input->cur++; |
| 434 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 435 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 436 | ctxt->errNo = XML_ERR_INVALID_CHARREF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 437 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 438 | ctxt->sax->error(ctxt->userData, |
| 439 | "xmlParseCharRef: invalid value\n"); |
| 440 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 441 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /* |
| 445 | * [ WFC: Legal Character ] |
| 446 | * Characters referred to using character references must match the |
| 447 | * production for Char. |
| 448 | */ |
| 449 | if (IS_CHAR(val)) { |
| 450 | return(val); |
| 451 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 452 | ctxt->errNo = XML_ERR_INVALID_CHAR; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 453 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 454 | ctxt->sax->error(ctxt->userData, "CharRef: invalid xmlChar value %d\n", |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 455 | val); |
| 456 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 457 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 458 | } |
| 459 | return(0); |
| 460 | } |
| 461 | |
| 462 | /** |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 463 | * xmlParseStringCharRef: |
| 464 | * @ctxt: an XML parser context |
| 465 | * @str: a pointer to an index in the string |
| 466 | * |
| 467 | * parse Reference declarations, variant parsing from a string rather |
| 468 | * than an an input flow. |
| 469 | * |
| 470 | * [66] CharRef ::= '&#' [0-9]+ ';' | |
| 471 | * '&#x' [0-9a-fA-F]+ ';' |
| 472 | * |
| 473 | * [ WFC: Legal Character ] |
| 474 | * Characters referred to using character references must match the |
| 475 | * production for Char. |
| 476 | * |
| 477 | * Returns the value parsed (as an int), 0 in case of error, str will be |
| 478 | * updated to the current value of the index |
| 479 | */ |
| 480 | int |
| 481 | xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str) { |
| 482 | const xmlChar *ptr; |
| 483 | xmlChar cur; |
| 484 | int val = 0; |
| 485 | |
| 486 | if ((str == NULL) || (*str == NULL)) return(0); |
| 487 | ptr = *str; |
| 488 | cur = *ptr; |
Daniel Veillard | 0caf07a | 1999-12-21 16:25:49 +0000 | [diff] [blame] | 489 | if ((cur == '&') && (ptr[1] == '#') && (ptr[2] == 'x')) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 490 | ptr += 3; |
| 491 | cur = *ptr; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 492 | while (cur != ';') { /* Non input consuming loop */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 493 | if ((cur >= '0') && (cur <= '9')) |
| 494 | val = val * 16 + (cur - '0'); |
| 495 | else if ((cur >= 'a') && (cur <= 'f')) |
| 496 | val = val * 16 + (cur - 'a') + 10; |
| 497 | else if ((cur >= 'A') && (cur <= 'F')) |
| 498 | val = val * 16 + (cur - 'A') + 10; |
| 499 | else { |
| 500 | ctxt->errNo = XML_ERR_INVALID_HEX_CHARREF; |
| 501 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 502 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 503 | "xmlParseStringCharRef: invalid hexadecimal value\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 504 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 505 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 506 | val = 0; |
| 507 | break; |
| 508 | } |
| 509 | ptr++; |
| 510 | cur = *ptr; |
| 511 | } |
| 512 | if (cur == ';') |
| 513 | ptr++; |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 514 | } else if ((cur == '&') && (ptr[1] == '#')){ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 515 | ptr += 2; |
| 516 | cur = *ptr; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 517 | while (cur != ';') { /* Non input consuming loops */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 518 | if ((cur >= '0') && (cur <= '9')) |
| 519 | val = val * 10 + (cur - '0'); |
| 520 | else { |
| 521 | ctxt->errNo = XML_ERR_INVALID_DEC_CHARREF; |
| 522 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 523 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 524 | "xmlParseStringCharRef: invalid decimal value\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 525 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 526 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 527 | val = 0; |
| 528 | break; |
| 529 | } |
| 530 | ptr++; |
| 531 | cur = *ptr; |
| 532 | } |
| 533 | if (cur == ';') |
| 534 | ptr++; |
| 535 | } else { |
| 536 | ctxt->errNo = XML_ERR_INVALID_CHARREF; |
| 537 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 538 | ctxt->sax->error(ctxt->userData, |
| 539 | "xmlParseCharRef: invalid value\n"); |
| 540 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 541 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 542 | return(0); |
| 543 | } |
| 544 | *str = ptr; |
| 545 | |
| 546 | /* |
| 547 | * [ WFC: Legal Character ] |
| 548 | * Characters referred to using character references must match the |
| 549 | * production for Char. |
| 550 | */ |
| 551 | if (IS_CHAR(val)) { |
| 552 | return(val); |
| 553 | } else { |
| 554 | ctxt->errNo = XML_ERR_INVALID_CHAR; |
| 555 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 556 | ctxt->sax->error(ctxt->userData, |
| 557 | "CharRef: invalid xmlChar value %d\n", val); |
| 558 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 559 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 560 | } |
| 561 | return(0); |
| 562 | } |
| 563 | |
| 564 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 565 | * xmlParserHandlePEReference: |
| 566 | * @ctxt: the parser context |
| 567 | * |
| 568 | * [69] PEReference ::= '%' Name ';' |
| 569 | * |
| 570 | * [ WFC: No Recursion ] |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 571 | * A parsed entity must not contain a recursive |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 572 | * reference to itself, either directly or indirectly. |
| 573 | * |
| 574 | * [ WFC: Entity Declared ] |
| 575 | * In a document without any DTD, a document with only an internal DTD |
| 576 | * subset which contains no parameter entity references, or a document |
| 577 | * with "standalone='yes'", ... ... The declaration of a parameter |
| 578 | * entity must precede any reference to it... |
| 579 | * |
| 580 | * [ VC: Entity Declared ] |
| 581 | * In a document with an external subset or external parameter entities |
| 582 | * with "standalone='no'", ... ... The declaration of a parameter entity |
| 583 | * must precede any reference to it... |
| 584 | * |
| 585 | * [ WFC: In DTD ] |
| 586 | * Parameter-entity references may only appear in the DTD. |
| 587 | * NOTE: misleading but this is handled. |
| 588 | * |
| 589 | * A PEReference may have been detected in the current input stream |
| 590 | * the handling is done accordingly to |
| 591 | * http://www.w3.org/TR/REC-xml#entproc |
| 592 | * i.e. |
| 593 | * - Included in literal in entity values |
| 594 | * - Included as Paraemeter Entity reference within DTDs |
| 595 | */ |
| 596 | void |
| 597 | xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 598 | xmlChar *name; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 599 | xmlEntityPtr entity = NULL; |
| 600 | xmlParserInputPtr input; |
| 601 | |
Daniel Veillard | 3500838 | 1999-10-25 13:15:52 +0000 | [diff] [blame] | 602 | if (ctxt->token != 0) { |
Daniel Veillard | 3500838 | 1999-10-25 13:15:52 +0000 | [diff] [blame] | 603 | return; |
| 604 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 605 | if (RAW != '%') return; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 606 | switch(ctxt->instate) { |
| 607 | case XML_PARSER_CDATA_SECTION: |
| 608 | return; |
| 609 | case XML_PARSER_COMMENT: |
| 610 | return; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 611 | case XML_PARSER_START_TAG: |
| 612 | return; |
| 613 | case XML_PARSER_END_TAG: |
| 614 | return; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 615 | case XML_PARSER_EOF: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 616 | ctxt->errNo = XML_ERR_PEREF_AT_EOF; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 617 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 618 | ctxt->sax->error(ctxt->userData, "PEReference at EOF\n"); |
| 619 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 620 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 621 | return; |
| 622 | case XML_PARSER_PROLOG: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 623 | case XML_PARSER_START: |
| 624 | case XML_PARSER_MISC: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 625 | ctxt->errNo = XML_ERR_PEREF_IN_PROLOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 626 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 627 | ctxt->sax->error(ctxt->userData, "PEReference in prolog!\n"); |
| 628 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 629 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 630 | return; |
| 631 | case XML_PARSER_ENTITY_DECL: |
| 632 | case XML_PARSER_CONTENT: |
| 633 | case XML_PARSER_ATTRIBUTE_VALUE: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 634 | case XML_PARSER_PI: |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 635 | case XML_PARSER_SYSTEM_LITERAL: |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 636 | /* we just ignore it there */ |
| 637 | return; |
| 638 | case XML_PARSER_EPILOG: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 639 | ctxt->errNo = XML_ERR_PEREF_IN_EPILOG; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 640 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 641 | ctxt->sax->error(ctxt->userData, "PEReference in epilog!\n"); |
| 642 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 643 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 644 | return; |
| 645 | case XML_PARSER_ENTITY_VALUE: |
| 646 | /* |
| 647 | * NOTE: in the case of entity values, we don't do the |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 648 | * substitution here since we need the literal |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 649 | * entity value to be able to save the internal |
| 650 | * subset of the document. |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 651 | * This will be handled by xmlStringDecodeEntities |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 652 | */ |
| 653 | return; |
| 654 | case XML_PARSER_DTD: |
| 655 | /* |
| 656 | * [WFC: Well-Formedness Constraint: PEs in Internal Subset] |
| 657 | * In the internal DTD subset, parameter-entity references |
| 658 | * can occur only where markup declarations can occur, not |
| 659 | * within markup declarations. |
| 660 | * In that case this is handled in xmlParseMarkupDecl |
| 661 | */ |
| 662 | if ((ctxt->external == 0) && (ctxt->inputNr == 1)) |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | NEXT; |
| 667 | name = xmlParseName(ctxt); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 668 | if (xmlParserDebugEntities) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 669 | xmlGenericError(xmlGenericErrorContext, |
| 670 | "PE Reference: %s\n", name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 671 | if (name == NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 672 | ctxt->errNo = XML_ERR_PEREF_NO_NAME; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 673 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 674 | ctxt->sax->error(ctxt->userData, "xmlHandlePEReference: no name\n"); |
| 675 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 676 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 677 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 678 | if (RAW == ';') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 679 | NEXT; |
| 680 | if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL)) |
| 681 | entity = ctxt->sax->getParameterEntity(ctxt->userData, name); |
| 682 | if (entity == NULL) { |
| 683 | |
| 684 | /* |
| 685 | * [ WFC: Entity Declared ] |
| 686 | * In a document without any DTD, a document with only an |
| 687 | * internal DTD subset which contains no parameter entity |
| 688 | * references, or a document with "standalone='yes'", ... |
| 689 | * ... The declaration of a parameter entity must precede |
| 690 | * any reference to it... |
| 691 | */ |
| 692 | if ((ctxt->standalone == 1) || |
| 693 | ((ctxt->hasExternalSubset == 0) && |
| 694 | (ctxt->hasPErefs == 0))) { |
| 695 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 696 | ctxt->sax->error(ctxt->userData, |
| 697 | "PEReference: %%%s; not found\n", name); |
| 698 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 699 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 700 | } else { |
| 701 | /* |
| 702 | * [ VC: Entity Declared ] |
| 703 | * In a document with an external subset or external |
| 704 | * parameter entities with "standalone='no'", ... |
| 705 | * ... The declaration of a parameter entity must precede |
| 706 | * any reference to it... |
| 707 | */ |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 708 | if ((!ctxt->disableSAX) && |
| 709 | (ctxt->validate) && (ctxt->vctxt.error != NULL)) { |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 710 | ctxt->vctxt.error(ctxt->vctxt.userData, |
| 711 | "PEReference: %%%s; not found\n", name); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 712 | } else if ((!ctxt->disableSAX) && |
| 713 | (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 714 | ctxt->sax->warning(ctxt->userData, |
| 715 | "PEReference: %%%s; not found\n", name); |
| 716 | ctxt->valid = 0; |
| 717 | } |
| 718 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 719 | if ((entity->etype == XML_INTERNAL_PARAMETER_ENTITY) || |
| 720 | (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY)) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 721 | /* |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 722 | * handle the extra spaces added before and after |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 723 | * c.f. http://www.w3.org/TR/REC-xml#as-PE |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 724 | * this is done independantly. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 725 | */ |
| 726 | input = xmlNewEntityInputStream(ctxt, entity); |
| 727 | xmlPushInput(ctxt, input); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 728 | if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && |
| 729 | (RAW == '<') && (NXT(1) == '?') && |
| 730 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 731 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 732 | xmlParseTextDecl(ctxt); |
| 733 | } |
| 734 | if (ctxt->token == 0) |
| 735 | ctxt->token = ' '; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 736 | } else { |
| 737 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 738 | ctxt->sax->error(ctxt->userData, |
| 739 | "xmlHandlePEReference: %s is not a parameter entity\n", |
| 740 | name); |
| 741 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 742 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 746 | ctxt->errNo = XML_ERR_PEREF_SEMICOL_MISSING; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 747 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 748 | ctxt->sax->error(ctxt->userData, |
| 749 | "xmlHandlePEReference: expecting ';'\n"); |
| 750 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 751 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 752 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 753 | xmlFree(name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 757 | /* |
| 758 | * Macro used to grow the current buffer. |
| 759 | */ |
| 760 | #define growBuffer(buffer) { \ |
| 761 | buffer##_size *= 2; \ |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 762 | buffer = (xmlChar *) \ |
| 763 | xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 764 | if (buffer == NULL) { \ |
| 765 | perror("realloc failed"); \ |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 766 | return(NULL); \ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 767 | } \ |
| 768 | } |
| 769 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 770 | /** |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 771 | * xmlStringDecodeEntities: |
| 772 | * @ctxt: the parser context |
| 773 | * @str: the input string |
| 774 | * @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF |
| 775 | * @end: an end marker xmlChar, 0 if none |
| 776 | * @end2: an end marker xmlChar, 0 if none |
| 777 | * @end3: an end marker xmlChar, 0 if none |
| 778 | * |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 779 | * Takes a entity string content and process to do the adequate subtitutions. |
| 780 | * |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 781 | * [67] Reference ::= EntityRef | CharRef |
| 782 | * |
| 783 | * [69] PEReference ::= '%' Name ';' |
| 784 | * |
| 785 | * Returns A newly allocated string with the substitution done. The caller |
| 786 | * must deallocate it ! |
| 787 | */ |
| 788 | xmlChar * |
| 789 | xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, |
| 790 | xmlChar end, xmlChar end2, xmlChar end3) { |
| 791 | xmlChar *buffer = NULL; |
| 792 | int buffer_size = 0; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 793 | |
| 794 | xmlChar *current = NULL; |
| 795 | xmlEntityPtr ent; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 796 | int c,l; |
| 797 | int nbchars = 0; |
| 798 | |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 799 | if (str == NULL) |
| 800 | return(NULL); |
| 801 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 802 | if (ctxt->depth > 40) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 803 | ctxt->errNo = XML_ERR_ENTITY_LOOP; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 804 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 805 | ctxt->sax->error(ctxt->userData, |
| 806 | "Detected entity reference loop\n"); |
| 807 | ctxt->wellFormed = 0; |
| 808 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 809 | return(NULL); |
| 810 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 811 | |
| 812 | /* |
| 813 | * allocate a translation buffer. |
| 814 | */ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 815 | buffer_size = XML_PARSER_BIG_BUFFER_SIZE; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 816 | buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); |
| 817 | if (buffer == NULL) { |
| 818 | perror("xmlDecodeEntities: malloc failed"); |
| 819 | return(NULL); |
| 820 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 821 | |
| 822 | /* |
| 823 | * Ok loop until we reach one of the ending char or a size limit. |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 824 | * we are operating on already parsed values. |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 825 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 826 | c = CUR_SCHAR(str, l); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 827 | while ((c != 0) && (c != end) && /* non input consuming loop */ |
| 828 | (c != end2) && (c != end3)) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 829 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 830 | if (c == 0) break; |
| 831 | if ((c == '&') && (str[1] == '#')) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 832 | int val = xmlParseStringCharRef(ctxt, &str); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 833 | if (val != 0) { |
| 834 | COPY_BUF(0,buffer,nbchars,val); |
| 835 | } |
| 836 | } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) { |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 837 | if (xmlParserDebugEntities) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 838 | xmlGenericError(xmlGenericErrorContext, |
| 839 | "String decoding Entity Reference: %.30s\n", |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 840 | str); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 841 | ent = xmlParseStringEntityRef(ctxt, &str); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 842 | if ((ent != NULL) && |
| 843 | (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
Daniel Veillard | 52402ce | 2000-08-22 23:36:12 +0000 | [diff] [blame] | 844 | if (ent->content != NULL) { |
| 845 | COPY_BUF(0,buffer,nbchars,ent->content[0]); |
| 846 | } else { |
| 847 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 848 | ctxt->sax->error(ctxt->userData, |
| 849 | "internal error entity has no content\n"); |
| 850 | } |
| 851 | } else if ((ent != NULL) && (ent->content != NULL)) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 852 | xmlChar *rep; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 853 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 854 | ctxt->depth++; |
| 855 | rep = xmlStringDecodeEntities(ctxt, ent->content, what, |
| 856 | 0, 0, 0); |
| 857 | ctxt->depth--; |
| 858 | if (rep != NULL) { |
| 859 | current = rep; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 860 | while (*current != 0) { /* non input consuming loop */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 861 | buffer[nbchars++] = *current++; |
| 862 | if (nbchars > |
| 863 | buffer_size - XML_PARSER_BUFFER_SIZE) { |
| 864 | growBuffer(buffer); |
| 865 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 866 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 867 | xmlFree(rep); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 868 | } |
| 869 | } else if (ent != NULL) { |
| 870 | int i = xmlStrlen(ent->name); |
| 871 | const xmlChar *cur = ent->name; |
| 872 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 873 | buffer[nbchars++] = '&'; |
| 874 | if (nbchars > buffer_size - i - XML_PARSER_BUFFER_SIZE) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 875 | growBuffer(buffer); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 876 | } |
| 877 | for (;i > 0;i--) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 878 | buffer[nbchars++] = *cur++; |
| 879 | buffer[nbchars++] = ';'; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 880 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 881 | } else if (c == '%' && (what & XML_SUBSTITUTE_PEREF)) { |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 882 | if (xmlParserDebugEntities) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 883 | xmlGenericError(xmlGenericErrorContext, |
| 884 | "String decoding PE Reference: %.30s\n", str); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 885 | ent = xmlParseStringPEReference(ctxt, &str); |
| 886 | if (ent != NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 887 | xmlChar *rep; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 888 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 889 | ctxt->depth++; |
| 890 | rep = xmlStringDecodeEntities(ctxt, ent->content, what, |
| 891 | 0, 0, 0); |
| 892 | ctxt->depth--; |
| 893 | if (rep != NULL) { |
| 894 | current = rep; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 895 | while (*current != 0) { /* non input consuming loop */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 896 | buffer[nbchars++] = *current++; |
| 897 | if (nbchars > |
| 898 | buffer_size - XML_PARSER_BUFFER_SIZE) { |
| 899 | growBuffer(buffer); |
| 900 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 901 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 902 | xmlFree(rep); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 906 | COPY_BUF(l,buffer,nbchars,c); |
| 907 | str += l; |
| 908 | if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 909 | growBuffer(buffer); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 910 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 911 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 912 | c = CUR_SCHAR(str, l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 913 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 914 | buffer[nbchars++] = 0; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 915 | return(buffer); |
| 916 | } |
| 917 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 918 | |
| 919 | /************************************************************************ |
| 920 | * * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 921 | * Commodity functions to handle xmlChars * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 922 | * * |
| 923 | ************************************************************************/ |
| 924 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 925 | /** |
| 926 | * xmlStrndup: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 927 | * @cur: the input xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 928 | * @len: the len of @cur |
| 929 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 930 | * a strndup for array of xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 931 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 932 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 933 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 934 | xmlChar * |
| 935 | xmlStrndup(const xmlChar *cur, int len) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 936 | xmlChar *ret; |
| 937 | |
| 938 | if ((cur == NULL) || (len < 0)) return(NULL); |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 939 | ret = (xmlChar *) xmlMalloc((len + 1) * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 940 | if (ret == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 941 | xmlGenericError(xmlGenericErrorContext, |
| 942 | "malloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 943 | (len + 1) * (long)sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 944 | return(NULL); |
| 945 | } |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 946 | memcpy(ret, cur, len * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 947 | ret[len] = 0; |
| 948 | return(ret); |
| 949 | } |
| 950 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 951 | /** |
| 952 | * xmlStrdup: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 953 | * @cur: the input xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 954 | * |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 955 | * a strdup for array of xmlChar's. Since they are supposed to be |
| 956 | * encoded in UTF-8 or an encoding with 8bit based chars, we assume |
| 957 | * a termination mark of '0'. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 958 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 959 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 960 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 961 | xmlChar * |
| 962 | xmlStrdup(const xmlChar *cur) { |
| 963 | const xmlChar *p = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 964 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 965 | if (cur == NULL) return(NULL); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 966 | while (*p != 0) p++; /* non input consuming */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 967 | return(xmlStrndup(cur, p - cur)); |
| 968 | } |
| 969 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 970 | /** |
| 971 | * xmlCharStrndup: |
| 972 | * @cur: the input char * |
| 973 | * @len: the len of @cur |
| 974 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 975 | * a strndup for char's to xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 976 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 977 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 978 | */ |
| 979 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 980 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 981 | xmlCharStrndup(const char *cur, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 982 | int i; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 983 | xmlChar *ret; |
| 984 | |
| 985 | if ((cur == NULL) || (len < 0)) return(NULL); |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 986 | ret = (xmlChar *) xmlMalloc((len + 1) * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 987 | if (ret == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 988 | xmlGenericError(xmlGenericErrorContext, "malloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 989 | (len + 1) * (long)sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 990 | return(NULL); |
| 991 | } |
| 992 | for (i = 0;i < len;i++) |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 993 | ret[i] = (xmlChar) cur[i]; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 994 | ret[len] = 0; |
| 995 | return(ret); |
| 996 | } |
| 997 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 998 | /** |
| 999 | * xmlCharStrdup: |
| 1000 | * @cur: the input char * |
| 1001 | * @len: the len of @cur |
| 1002 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1003 | * a strdup for char's to xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1004 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1005 | * Returns a new xmlChar * or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1006 | */ |
| 1007 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1008 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1009 | xmlCharStrdup(const char *cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1010 | const char *p = cur; |
| 1011 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1012 | if (cur == NULL) return(NULL); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1013 | while (*p != '\0') p++; /* non input consuming */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1014 | return(xmlCharStrndup(cur, p - cur)); |
| 1015 | } |
| 1016 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1017 | /** |
| 1018 | * xmlStrcmp: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1019 | * @str1: the first xmlChar * |
| 1020 | * @str2: the second xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1021 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1022 | * a strcmp for xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1023 | * |
| 1024 | * Returns the integer result of the comparison |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1025 | */ |
| 1026 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1027 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1028 | xmlStrcmp(const xmlChar *str1, const xmlChar *str2) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1029 | register int tmp; |
| 1030 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 1031 | if (str1 == str2) return(0); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1032 | if (str1 == NULL) return(-1); |
| 1033 | if (str2 == NULL) return(1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1034 | do { |
Daniel Veillard | b656ebe | 2000-09-22 13:51:48 +0000 | [diff] [blame] | 1035 | tmp = *str1++ - *str2; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1036 | if (tmp != 0) return(tmp); |
Daniel Veillard | b656ebe | 2000-09-22 13:51:48 +0000 | [diff] [blame] | 1037 | } while (*str2++ != 0); |
| 1038 | return 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1041 | /** |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 1042 | * xmlStrEqual: |
| 1043 | * @str1: the first xmlChar * |
| 1044 | * @str2: the second xmlChar * |
| 1045 | * |
| 1046 | * Check if both string are equal of have same content |
| 1047 | * Should be a bit more readable and faster than xmlStrEqual() |
| 1048 | * |
| 1049 | * Returns 1 if they are equal, 0 if they are different |
| 1050 | */ |
| 1051 | |
| 1052 | int |
| 1053 | xmlStrEqual(const xmlChar *str1, const xmlChar *str2) { |
| 1054 | if (str1 == str2) return(1); |
| 1055 | if (str1 == NULL) return(0); |
| 1056 | if (str2 == NULL) return(0); |
| 1057 | do { |
| 1058 | if (*str1++ != *str2) return(0); |
| 1059 | } while (*str2++); |
| 1060 | return(1); |
| 1061 | } |
| 1062 | |
| 1063 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1064 | * xmlStrncmp: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1065 | * @str1: the first xmlChar * |
| 1066 | * @str2: the second xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1067 | * @len: the max comparison length |
| 1068 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1069 | * a strncmp for xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1070 | * |
| 1071 | * Returns the integer result of the comparison |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1072 | */ |
| 1073 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1074 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1075 | xmlStrncmp(const xmlChar *str1, const xmlChar *str2, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1076 | register int tmp; |
| 1077 | |
| 1078 | if (len <= 0) return(0); |
Daniel Veillard | b656ebe | 2000-09-22 13:51:48 +0000 | [diff] [blame] | 1079 | if (str1 == str2) return(0); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1080 | if (str1 == NULL) return(-1); |
| 1081 | if (str2 == NULL) return(1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1082 | do { |
Daniel Veillard | b656ebe | 2000-09-22 13:51:48 +0000 | [diff] [blame] | 1083 | tmp = *str1++ - *str2; |
| 1084 | if (tmp != 0 || --len == 0) return(tmp); |
| 1085 | } while (*str2++ != 0); |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | static xmlChar casemap[256] = { |
| 1090 | 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, |
| 1091 | 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, |
| 1092 | 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, |
| 1093 | 0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, |
| 1094 | 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, |
| 1095 | 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, |
| 1096 | 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, |
| 1097 | 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, |
| 1098 | 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67, |
| 1099 | 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, |
| 1100 | 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, |
| 1101 | 0x78,0x79,0x7A,0x7B,0x5C,0x5D,0x5E,0x5F, |
| 1102 | 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67, |
| 1103 | 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, |
| 1104 | 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, |
| 1105 | 0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, |
| 1106 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, |
| 1107 | 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, |
| 1108 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, |
| 1109 | 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, |
| 1110 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7, |
| 1111 | 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, |
| 1112 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7, |
| 1113 | 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, |
| 1114 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7, |
| 1115 | 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, |
| 1116 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7, |
| 1117 | 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, |
| 1118 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7, |
| 1119 | 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, |
| 1120 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7, |
| 1121 | 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF |
| 1122 | }; |
| 1123 | |
| 1124 | /** |
| 1125 | * xmlStrcasecmp: |
| 1126 | * @str1: the first xmlChar * |
| 1127 | * @str2: the second xmlChar * |
| 1128 | * |
| 1129 | * a strcasecmp for xmlChar's |
| 1130 | * |
| 1131 | * Returns the integer result of the comparison |
| 1132 | */ |
| 1133 | |
| 1134 | int |
| 1135 | xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2) { |
| 1136 | register int tmp; |
| 1137 | |
| 1138 | if (str1 == str2) return(0); |
| 1139 | if (str1 == NULL) return(-1); |
| 1140 | if (str2 == NULL) return(1); |
| 1141 | do { |
| 1142 | tmp = casemap[*str1++] - casemap[*str2]; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1143 | if (tmp != 0) return(tmp); |
Daniel Veillard | b656ebe | 2000-09-22 13:51:48 +0000 | [diff] [blame] | 1144 | } while (*str2++ != 0); |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | /** |
| 1149 | * xmlStrncasecmp: |
| 1150 | * @str1: the first xmlChar * |
| 1151 | * @str2: the second xmlChar * |
| 1152 | * @len: the max comparison length |
| 1153 | * |
| 1154 | * a strncasecmp for xmlChar's |
| 1155 | * |
| 1156 | * Returns the integer result of the comparison |
| 1157 | */ |
| 1158 | |
| 1159 | int |
| 1160 | xmlStrncasecmp(const xmlChar *str1, const xmlChar *str2, int len) { |
| 1161 | register int tmp; |
| 1162 | |
| 1163 | if (len <= 0) return(0); |
| 1164 | if (str1 == str2) return(0); |
| 1165 | if (str1 == NULL) return(-1); |
| 1166 | if (str2 == NULL) return(1); |
| 1167 | do { |
| 1168 | tmp = casemap[*str1++] - casemap[*str2]; |
| 1169 | if (tmp != 0 || --len == 0) return(tmp); |
| 1170 | } while (*str2++ != 0); |
| 1171 | return 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1174 | /** |
| 1175 | * xmlStrchr: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1176 | * @str: the xmlChar * array |
| 1177 | * @val: the xmlChar to search |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1178 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1179 | * a strchr for xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1180 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1181 | * Returns the xmlChar * for the first occurence or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1182 | */ |
| 1183 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1184 | const xmlChar * |
| 1185 | xmlStrchr(const xmlChar *str, xmlChar val) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1186 | if (str == NULL) return(NULL); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1187 | while (*str != 0) { /* non input consuming */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1188 | if (*str == val) return((xmlChar *) str); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1189 | str++; |
| 1190 | } |
| 1191 | return(NULL); |
| 1192 | } |
| 1193 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1194 | /** |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1195 | * xmlStrstr: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1196 | * @str: the xmlChar * array (haystack) |
| 1197 | * @val: the xmlChar to search (needle) |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1198 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1199 | * a strstr for xmlChar's |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1200 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1201 | * Returns the xmlChar * for the first occurence or NULL. |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1202 | */ |
| 1203 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1204 | const xmlChar * |
| 1205 | xmlStrstr(const xmlChar *str, xmlChar *val) { |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1206 | int n; |
| 1207 | |
| 1208 | if (str == NULL) return(NULL); |
| 1209 | if (val == NULL) return(NULL); |
| 1210 | n = xmlStrlen(val); |
| 1211 | |
| 1212 | if (n == 0) return(str); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1213 | while (*str != 0) { /* non input consuming */ |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1214 | if (*str == *val) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1215 | if (!xmlStrncmp(str, val, n)) return((const xmlChar *) str); |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1216 | } |
| 1217 | str++; |
| 1218 | } |
| 1219 | return(NULL); |
| 1220 | } |
| 1221 | |
| 1222 | /** |
Daniel Veillard | b656ebe | 2000-09-22 13:51:48 +0000 | [diff] [blame] | 1223 | * xmlStrcasestr: |
| 1224 | * @str: the xmlChar * array (haystack) |
| 1225 | * @val: the xmlChar to search (needle) |
| 1226 | * |
| 1227 | * a case-ignoring strstr for xmlChar's |
| 1228 | * |
| 1229 | * Returns the xmlChar * for the first occurence or NULL. |
| 1230 | */ |
| 1231 | |
| 1232 | const xmlChar * |
| 1233 | xmlStrcasestr(const xmlChar *str, xmlChar *val) { |
| 1234 | int n; |
| 1235 | |
| 1236 | if (str == NULL) return(NULL); |
| 1237 | if (val == NULL) return(NULL); |
| 1238 | n = xmlStrlen(val); |
| 1239 | |
| 1240 | if (n == 0) return(str); |
| 1241 | while (*str != 0) { /* non input consuming */ |
| 1242 | if (casemap[*str] == casemap[*val]) |
| 1243 | if (!xmlStrncasecmp(str, val, n)) return(str); |
| 1244 | str++; |
| 1245 | } |
| 1246 | return(NULL); |
| 1247 | } |
| 1248 | |
| 1249 | /** |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1250 | * xmlStrsub: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1251 | * @str: the xmlChar * array (haystack) |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1252 | * @start: the index of the first char (zero based) |
| 1253 | * @len: the length of the substring |
| 1254 | * |
| 1255 | * Extract a substring of a given string |
| 1256 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1257 | * Returns the xmlChar * for the first occurence or NULL. |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1258 | */ |
| 1259 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1260 | xmlChar * |
| 1261 | xmlStrsub(const xmlChar *str, int start, int len) { |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 1262 | int i; |
| 1263 | |
| 1264 | if (str == NULL) return(NULL); |
| 1265 | if (start < 0) return(NULL); |
| 1266 | if (len < 0) return(NULL); |
| 1267 | |
| 1268 | for (i = 0;i < start;i++) { |
| 1269 | if (*str == 0) return(NULL); |
| 1270 | str++; |
| 1271 | } |
| 1272 | if (*str == 0) return(NULL); |
| 1273 | return(xmlStrndup(str, len)); |
| 1274 | } |
| 1275 | |
| 1276 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1277 | * xmlStrlen: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1278 | * @str: the xmlChar * array |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1279 | * |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 1280 | * length of a xmlChar's string |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1281 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1282 | * Returns the number of xmlChar contained in the ARRAY. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1283 | */ |
| 1284 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1285 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1286 | xmlStrlen(const xmlChar *str) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1287 | int len = 0; |
| 1288 | |
| 1289 | if (str == NULL) return(0); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1290 | while (*str != 0) { /* non input consuming */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1291 | str++; |
| 1292 | len++; |
| 1293 | } |
| 1294 | return(len); |
| 1295 | } |
| 1296 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1297 | /** |
| 1298 | * xmlStrncat: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1299 | * @cur: the original xmlChar * array |
| 1300 | * @add: the xmlChar * array added |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1301 | * @len: the length of @add |
| 1302 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1303 | * a strncat for array of xmlChar's |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1304 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1305 | * Returns a new xmlChar * containing the concatenated string. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1306 | */ |
| 1307 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1308 | xmlChar * |
| 1309 | xmlStrncat(xmlChar *cur, const xmlChar *add, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1310 | int size; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1311 | xmlChar *ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1312 | |
| 1313 | if ((add == NULL) || (len == 0)) |
| 1314 | return(cur); |
| 1315 | if (cur == NULL) |
| 1316 | return(xmlStrndup(add, len)); |
| 1317 | |
| 1318 | size = xmlStrlen(cur); |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 1319 | ret = (xmlChar *) xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1320 | if (ret == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1321 | xmlGenericError(xmlGenericErrorContext, |
| 1322 | "xmlStrncat: realloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1323 | (size + len + 1) * (long)sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1324 | return(cur); |
| 1325 | } |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1326 | memcpy(&ret[size], add, len * sizeof(xmlChar)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1327 | ret[size + len] = 0; |
| 1328 | return(ret); |
| 1329 | } |
| 1330 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1331 | /** |
| 1332 | * xmlStrcat: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1333 | * @cur: the original xmlChar * array |
| 1334 | * @add: the xmlChar * array added |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1335 | * |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1336 | * a strcat for array of xmlChar's. Since they are supposed to be |
| 1337 | * encoded in UTF-8 or an encoding with 8bit based chars, we assume |
| 1338 | * a termination mark of '0'. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1339 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1340 | * Returns a new xmlChar * containing the concatenated string. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1341 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1342 | xmlChar * |
| 1343 | xmlStrcat(xmlChar *cur, const xmlChar *add) { |
| 1344 | const xmlChar *p = add; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1345 | |
| 1346 | if (add == NULL) return(cur); |
| 1347 | if (cur == NULL) |
| 1348 | return(xmlStrdup(add)); |
| 1349 | |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1350 | while (*p != 0) p++; /* non input consuming */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1351 | return(xmlStrncat(cur, add, p - add)); |
| 1352 | } |
| 1353 | |
| 1354 | /************************************************************************ |
| 1355 | * * |
| 1356 | * Commodity functions, cleanup needed ? * |
| 1357 | * * |
| 1358 | ************************************************************************/ |
| 1359 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1360 | /** |
| 1361 | * areBlanks: |
| 1362 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1363 | * @str: a xmlChar * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1364 | * @len: the size of @str |
| 1365 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1366 | * Is this a sequence of blank chars that one can ignore ? |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1367 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1368 | * Returns 1 if ignorable 0 otherwise. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1369 | */ |
| 1370 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1371 | static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1372 | int i, ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1373 | xmlNodePtr lastChild; |
| 1374 | |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1375 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1376 | * Check for xml:space value. |
| 1377 | */ |
| 1378 | if (*(ctxt->space) == 1) |
| 1379 | return(0); |
| 1380 | |
| 1381 | /* |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1382 | * Check that the string is made of blanks |
| 1383 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1384 | for (i = 0;i < len;i++) |
| 1385 | if (!(IS_BLANK(str[i]))) return(0); |
| 1386 | |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1387 | /* |
| 1388 | * Look if the element is mixed content in the Dtd if available |
| 1389 | */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1390 | if (ctxt->myDoc != NULL) { |
| 1391 | ret = xmlIsMixedElement(ctxt->myDoc, ctxt->node->name); |
| 1392 | if (ret == 0) return(1); |
| 1393 | if (ret == 1) return(0); |
| 1394 | } |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1395 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1396 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1397 | * Otherwise, heuristic :-\ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1398 | */ |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1399 | if (ctxt->keepBlanks) |
| 1400 | return(0); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1401 | if (RAW != '<') return(0); |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1402 | if (ctxt->node == NULL) return(0); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1403 | if ((ctxt->node->children == NULL) && |
| 1404 | (RAW == '<') && (NXT(1) == '/')) return(0); |
Daniel Veillard | 83a30e7 | 2000-03-02 03:33:32 +0000 | [diff] [blame] | 1405 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1406 | lastChild = xmlGetLastChild(ctxt->node); |
| 1407 | if (lastChild == NULL) { |
Daniel Veillard | 90fb02c | 2000-03-02 03:46:43 +0000 | [diff] [blame] | 1408 | if (ctxt->node->content != NULL) return(0); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1409 | } else if (xmlNodeIsText(lastChild)) |
Daniel Veillard | 90fb02c | 2000-03-02 03:46:43 +0000 | [diff] [blame] | 1410 | return(0); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1411 | else if ((ctxt->node->children != NULL) && |
| 1412 | (xmlNodeIsText(ctxt->node->children))) |
Daniel Veillard | 90fb02c | 2000-03-02 03:46:43 +0000 | [diff] [blame] | 1413 | return(0); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1414 | return(1); |
| 1415 | } |
| 1416 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1417 | /* |
| 1418 | * Forward definition for recusive behaviour. |
| 1419 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1420 | void xmlParsePEReference(xmlParserCtxtPtr ctxt); |
| 1421 | void xmlParseReference(xmlParserCtxtPtr ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1422 | |
| 1423 | /************************************************************************ |
| 1424 | * * |
| 1425 | * Extra stuff for namespace support * |
| 1426 | * Relates to http://www.w3.org/TR/WD-xml-names * |
| 1427 | * * |
| 1428 | ************************************************************************/ |
| 1429 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1430 | /** |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1431 | * xmlSplitQName: |
| 1432 | * @ctxt: an XML parser context |
| 1433 | * @name: an XML parser context |
| 1434 | * @prefix: a xmlChar ** |
| 1435 | * |
| 1436 | * parse an UTF8 encoded XML qualified name string |
| 1437 | * |
| 1438 | * [NS 5] QName ::= (Prefix ':')? LocalPart |
| 1439 | * |
| 1440 | * [NS 6] Prefix ::= NCName |
| 1441 | * |
| 1442 | * [NS 7] LocalPart ::= NCName |
| 1443 | * |
| 1444 | * Returns the local part, and prefix is updated |
| 1445 | * to get the Prefix if any. |
| 1446 | */ |
| 1447 | |
| 1448 | xmlChar * |
| 1449 | xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { |
| 1450 | xmlChar buf[XML_MAX_NAMELEN + 5]; |
| 1451 | xmlChar *buffer = NULL; |
| 1452 | int len = 0; |
| 1453 | int max = XML_MAX_NAMELEN; |
| 1454 | xmlChar *ret = NULL; |
| 1455 | const xmlChar *cur = name; |
| 1456 | int c; |
| 1457 | |
| 1458 | *prefix = NULL; |
| 1459 | |
| 1460 | /* xml: prefix is not really a namespace */ |
| 1461 | if ((cur[0] == 'x') && (cur[1] == 'm') && |
| 1462 | (cur[2] == 'l') && (cur[3] == ':')) |
| 1463 | return(xmlStrdup(name)); |
| 1464 | |
| 1465 | /* nasty but valid */ |
| 1466 | if (cur[0] == ':') |
| 1467 | return(xmlStrdup(name)); |
| 1468 | |
| 1469 | c = *cur++; |
| 1470 | while ((c != 0) && (c != ':') && (len < max)) { /* tested bigname.xml */ |
| 1471 | buf[len++] = c; |
| 1472 | c = *cur++; |
| 1473 | } |
| 1474 | if (len >= max) { |
| 1475 | /* |
| 1476 | * Okay someone managed to make a huge name, so he's ready to pay |
| 1477 | * for the processing speed. |
| 1478 | */ |
| 1479 | max = len * 2; |
| 1480 | |
| 1481 | buffer = (xmlChar *) xmlMalloc(max * sizeof(xmlChar)); |
| 1482 | if (buffer == NULL) { |
| 1483 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1484 | ctxt->sax->error(ctxt->userData, |
| 1485 | "xmlSplitQName: out of memory\n"); |
| 1486 | return(NULL); |
| 1487 | } |
| 1488 | memcpy(buffer, buf, len); |
| 1489 | while ((c != 0) && (c != ':')) { /* tested bigname.xml */ |
| 1490 | if (len + 10 > max) { |
| 1491 | max *= 2; |
| 1492 | buffer = (xmlChar *) xmlRealloc(buffer, |
| 1493 | max * sizeof(xmlChar)); |
| 1494 | if (buffer == NULL) { |
| 1495 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1496 | ctxt->sax->error(ctxt->userData, |
| 1497 | "xmlSplitQName: out of memory\n"); |
| 1498 | return(NULL); |
| 1499 | } |
| 1500 | } |
| 1501 | buffer[len++] = c; |
| 1502 | c = *cur++; |
| 1503 | } |
| 1504 | buffer[len] = 0; |
| 1505 | } |
| 1506 | |
| 1507 | if (buffer == NULL) |
| 1508 | ret = xmlStrndup(buf, len); |
| 1509 | else { |
| 1510 | ret = buffer; |
| 1511 | buffer = NULL; |
| 1512 | max = XML_MAX_NAMELEN; |
| 1513 | } |
| 1514 | |
| 1515 | |
| 1516 | if (c == ':') { |
| 1517 | c = *cur++; |
| 1518 | if (c == 0) return(ret); |
| 1519 | *prefix = ret; |
| 1520 | len = 0; |
| 1521 | |
| 1522 | while ((c != 0) && (len < max)) { /* tested bigname2.xml */ |
| 1523 | buf[len++] = c; |
| 1524 | c = *cur++; |
| 1525 | } |
| 1526 | if (len >= max) { |
| 1527 | /* |
| 1528 | * Okay someone managed to make a huge name, so he's ready to pay |
| 1529 | * for the processing speed. |
| 1530 | */ |
| 1531 | max = len * 2; |
| 1532 | |
| 1533 | buffer = (xmlChar *) xmlMalloc(max * sizeof(xmlChar)); |
| 1534 | if (buffer == NULL) { |
| 1535 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1536 | ctxt->sax->error(ctxt->userData, |
| 1537 | "xmlSplitQName: out of memory\n"); |
| 1538 | return(NULL); |
| 1539 | } |
| 1540 | memcpy(buffer, buf, len); |
| 1541 | while (c != 0) { /* tested bigname2.xml */ |
| 1542 | if (len + 10 > max) { |
| 1543 | max *= 2; |
| 1544 | buffer = (xmlChar *) xmlRealloc(buffer, |
| 1545 | max * sizeof(xmlChar)); |
| 1546 | if (buffer == NULL) { |
| 1547 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1548 | ctxt->sax->error(ctxt->userData, |
| 1549 | "xmlSplitQName: out of memory\n"); |
| 1550 | return(NULL); |
| 1551 | } |
| 1552 | } |
| 1553 | buffer[len++] = c; |
| 1554 | c = *cur++; |
| 1555 | } |
| 1556 | buffer[len] = 0; |
| 1557 | } |
| 1558 | |
| 1559 | if (buffer == NULL) |
| 1560 | ret = xmlStrndup(buf, len); |
| 1561 | else { |
| 1562 | ret = buffer; |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | return(ret); |
| 1567 | } |
| 1568 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1569 | /************************************************************************ |
| 1570 | * * |
| 1571 | * The parser itself * |
| 1572 | * Relates to http://www.w3.org/TR/REC-xml * |
| 1573 | * * |
| 1574 | ************************************************************************/ |
| 1575 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1576 | /** |
| 1577 | * xmlParseName: |
| 1578 | * @ctxt: an XML parser context |
| 1579 | * |
| 1580 | * parse an XML name. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1581 | * |
| 1582 | * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | |
| 1583 | * CombiningChar | Extender |
| 1584 | * |
| 1585 | * [5] Name ::= (Letter | '_' | ':') (NameChar)* |
| 1586 | * |
| 1587 | * [6] Names ::= Name (S Name)* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1588 | * |
| 1589 | * Returns the Name parsed or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1590 | */ |
| 1591 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1592 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1593 | xmlParseName(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1594 | xmlChar buf[XML_MAX_NAMELEN + 5]; |
| 1595 | int len = 0, l; |
| 1596 | int c; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1597 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1598 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1599 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1600 | c = CUR_CHAR(l); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1601 | if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */ |
| 1602 | (!IS_LETTER(c) && (c != '_') && |
| 1603 | (c != ':'))) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1604 | return(NULL); |
| 1605 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1606 | |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1607 | while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */ |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1608 | ((IS_LETTER(c)) || (IS_DIGIT(c)) || |
| 1609 | (c == '.') || (c == '-') || |
| 1610 | (c == '_') || (c == ':') || |
| 1611 | (IS_COMBINING(c)) || |
| 1612 | (IS_EXTENDER(c)))) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1613 | if (count++ > 100) { |
| 1614 | count = 0; |
| 1615 | GROW; |
| 1616 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1617 | COPY_BUF(l,buf,len,c); |
| 1618 | NEXTL(l); |
| 1619 | c = CUR_CHAR(l); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1620 | if (len >= XML_MAX_NAMELEN) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1621 | /* |
| 1622 | * Okay someone managed to make a huge name, so he's ready to pay |
| 1623 | * for the processing speed. |
| 1624 | */ |
| 1625 | xmlChar *buffer; |
| 1626 | int max = len * 2; |
| 1627 | |
| 1628 | buffer = (xmlChar *) xmlMalloc(max * sizeof(xmlChar)); |
| 1629 | if (buffer == NULL) { |
| 1630 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1631 | ctxt->sax->error(ctxt->userData, |
| 1632 | "xmlParseName: out of memory\n"); |
| 1633 | return(NULL); |
| 1634 | } |
| 1635 | memcpy(buffer, buf, len); |
| 1636 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigname.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1637 | (c == '.') || (c == '-') || |
| 1638 | (c == '_') || (c == ':') || |
| 1639 | (IS_COMBINING(c)) || |
| 1640 | (IS_EXTENDER(c))) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1641 | if (count++ > 100) { |
| 1642 | count = 0; |
| 1643 | GROW; |
| 1644 | } |
| 1645 | if (len + 10 > max) { |
| 1646 | max *= 2; |
| 1647 | buffer = (xmlChar *) xmlRealloc(buffer, |
| 1648 | max * sizeof(xmlChar)); |
| 1649 | if (buffer == NULL) { |
| 1650 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1651 | ctxt->sax->error(ctxt->userData, |
| 1652 | "xmlParseName: out of memory\n"); |
| 1653 | return(NULL); |
| 1654 | } |
| 1655 | } |
| 1656 | COPY_BUF(l,buffer,len,c); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1657 | NEXTL(l); |
| 1658 | c = CUR_CHAR(l); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1659 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1660 | buffer[len] = 0; |
| 1661 | return(buffer); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | return(xmlStrndup(buf, len)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1667 | /** |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1668 | * xmlParseStringName: |
| 1669 | * @ctxt: an XML parser context |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 1670 | * @str: a pointer to the string pointer (IN/OUT) |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1671 | * |
| 1672 | * parse an XML name. |
| 1673 | * |
| 1674 | * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | |
| 1675 | * CombiningChar | Extender |
| 1676 | * |
| 1677 | * [5] Name ::= (Letter | '_' | ':') (NameChar)* |
| 1678 | * |
| 1679 | * [6] Names ::= Name (S Name)* |
| 1680 | * |
| 1681 | * Returns the Name parsed or NULL. The str pointer |
| 1682 | * is updated to the current location in the string. |
| 1683 | */ |
| 1684 | |
| 1685 | xmlChar * |
| 1686 | xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1687 | xmlChar buf[XML_MAX_NAMELEN + 5]; |
| 1688 | const xmlChar *cur = *str; |
| 1689 | int len = 0, l; |
| 1690 | int c; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1691 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1692 | c = CUR_SCHAR(cur, l); |
| 1693 | if (!IS_LETTER(c) && (c != '_') && |
| 1694 | (c != ':')) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1695 | return(NULL); |
| 1696 | } |
| 1697 | |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1698 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigentname.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1699 | (c == '.') || (c == '-') || |
| 1700 | (c == '_') || (c == ':') || |
| 1701 | (IS_COMBINING(c)) || |
| 1702 | (IS_EXTENDER(c))) { |
| 1703 | COPY_BUF(l,buf,len,c); |
| 1704 | cur += l; |
| 1705 | c = CUR_SCHAR(cur, l); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1706 | if (len >= XML_MAX_NAMELEN) { /* test bigentname.xml */ |
| 1707 | /* |
| 1708 | * Okay someone managed to make a huge name, so he's ready to pay |
| 1709 | * for the processing speed. |
| 1710 | */ |
| 1711 | xmlChar *buffer; |
| 1712 | int max = len * 2; |
| 1713 | |
| 1714 | buffer = (xmlChar *) xmlMalloc(max * sizeof(xmlChar)); |
| 1715 | if (buffer == NULL) { |
| 1716 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1717 | ctxt->sax->error(ctxt->userData, |
| 1718 | "xmlParseStringName: out of memory\n"); |
| 1719 | return(NULL); |
| 1720 | } |
| 1721 | memcpy(buffer, buf, len); |
| 1722 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigentname.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1723 | (c == '.') || (c == '-') || |
| 1724 | (c == '_') || (c == ':') || |
| 1725 | (IS_COMBINING(c)) || |
| 1726 | (IS_EXTENDER(c))) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1727 | if (len + 10 > max) { |
| 1728 | max *= 2; |
| 1729 | buffer = (xmlChar *) xmlRealloc(buffer, |
| 1730 | max * sizeof(xmlChar)); |
| 1731 | if (buffer == NULL) { |
| 1732 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1733 | ctxt->sax->error(ctxt->userData, |
| 1734 | "xmlParseStringName: out of memory\n"); |
| 1735 | return(NULL); |
| 1736 | } |
| 1737 | } |
| 1738 | COPY_BUF(l,buffer,len,c); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1739 | cur += l; |
| 1740 | c = CUR_SCHAR(cur, l); |
| 1741 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1742 | buffer[len] = 0; |
| 1743 | *str = cur; |
| 1744 | return(buffer); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1745 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1746 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1747 | *str = cur; |
| 1748 | return(xmlStrndup(buf, len)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1752 | * xmlParseNmtoken: |
| 1753 | * @ctxt: an XML parser context |
| 1754 | * |
| 1755 | * parse an XML Nmtoken. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1756 | * |
| 1757 | * [7] Nmtoken ::= (NameChar)+ |
| 1758 | * |
| 1759 | * [8] Nmtokens ::= Nmtoken (S Nmtoken)* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1760 | * |
| 1761 | * Returns the Nmtoken parsed or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1762 | */ |
| 1763 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1764 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 1765 | xmlParseNmtoken(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1766 | xmlChar buf[XML_MAX_NAMELEN + 5]; |
| 1767 | int len = 0, l; |
| 1768 | int c; |
| 1769 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1770 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1771 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1772 | c = CUR_CHAR(l); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1773 | |
| 1774 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigtoken.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1775 | (c == '.') || (c == '-') || |
| 1776 | (c == '_') || (c == ':') || |
| 1777 | (IS_COMBINING(c)) || |
| 1778 | (IS_EXTENDER(c))) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1779 | if (count++ > 100) { |
| 1780 | count = 0; |
| 1781 | GROW; |
| 1782 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1783 | COPY_BUF(l,buf,len,c); |
| 1784 | NEXTL(l); |
| 1785 | c = CUR_CHAR(l); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1786 | if (len >= XML_MAX_NAMELEN) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1787 | /* |
| 1788 | * Okay someone managed to make a huge token, so he's ready to pay |
| 1789 | * for the processing speed. |
| 1790 | */ |
| 1791 | xmlChar *buffer; |
| 1792 | int max = len * 2; |
| 1793 | |
| 1794 | buffer = (xmlChar *) xmlMalloc(max * sizeof(xmlChar)); |
| 1795 | if (buffer == NULL) { |
| 1796 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1797 | ctxt->sax->error(ctxt->userData, |
| 1798 | "xmlParseNmtoken: out of memory\n"); |
| 1799 | return(NULL); |
| 1800 | } |
| 1801 | memcpy(buffer, buf, len); |
| 1802 | while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigtoken.xml */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1803 | (c == '.') || (c == '-') || |
| 1804 | (c == '_') || (c == ':') || |
| 1805 | (IS_COMBINING(c)) || |
| 1806 | (IS_EXTENDER(c))) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1807 | if (count++ > 100) { |
| 1808 | count = 0; |
| 1809 | GROW; |
| 1810 | } |
| 1811 | if (len + 10 > max) { |
| 1812 | max *= 2; |
| 1813 | buffer = (xmlChar *) xmlRealloc(buffer, |
| 1814 | max * sizeof(xmlChar)); |
| 1815 | if (buffer == NULL) { |
| 1816 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1817 | ctxt->sax->error(ctxt->userData, |
| 1818 | "xmlParseName: out of memory\n"); |
| 1819 | return(NULL); |
| 1820 | } |
| 1821 | } |
| 1822 | COPY_BUF(l,buffer,len,c); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1823 | NEXTL(l); |
| 1824 | c = CUR_CHAR(l); |
| 1825 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1826 | buffer[len] = 0; |
| 1827 | return(buffer); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1828 | } |
| 1829 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1830 | if (len == 0) |
| 1831 | return(NULL); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 1832 | return(xmlStrndup(buf, len)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1835 | /** |
| 1836 | * xmlParseEntityValue: |
| 1837 | * @ctxt: an XML parser context |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1838 | * @orig: if non-NULL store a copy of the original entity value |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1839 | * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 1840 | * parse a value for ENTITY declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1841 | * |
| 1842 | * [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | |
| 1843 | * "'" ([^%&'] | PEReference | Reference)* "'" |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1844 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1845 | * Returns the EntityValue parsed with reference substitued or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1846 | */ |
| 1847 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1848 | xmlChar * |
| 1849 | xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1850 | xmlChar *buf = NULL; |
| 1851 | int len = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 1852 | int size = XML_PARSER_BUFFER_SIZE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1853 | int c, l; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1854 | xmlChar stop; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1855 | xmlChar *ret = NULL; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1856 | const xmlChar *cur = NULL; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1857 | xmlParserInputPtr input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1858 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1859 | if (RAW == '"') stop = '"'; |
| 1860 | else if (RAW == '\'') stop = '\''; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1861 | else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1862 | ctxt->errNo = XML_ERR_ENTITY_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 1863 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1864 | ctxt->sax->error(ctxt->userData, "EntityValue: \" or ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1865 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1866 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1867 | return(NULL); |
| 1868 | } |
| 1869 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 1870 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1871 | xmlGenericError(xmlGenericErrorContext, |
| 1872 | "malloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1873 | return(NULL); |
| 1874 | } |
| 1875 | |
| 1876 | /* |
| 1877 | * The content of the entity definition is copied in a buffer. |
| 1878 | */ |
| 1879 | |
| 1880 | ctxt->instate = XML_PARSER_ENTITY_VALUE; |
| 1881 | input = ctxt->input; |
| 1882 | GROW; |
| 1883 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1884 | c = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1885 | /* |
| 1886 | * NOTE: 4.4.5 Included in Literal |
| 1887 | * When a parameter entity reference appears in a literal entity |
| 1888 | * value, ... a single or double quote character in the replacement |
| 1889 | * text is always treated as a normal data character and will not |
| 1890 | * terminate the literal. |
| 1891 | * In practice it means we stop the loop only when back at parsing |
| 1892 | * the initial entity and the quote is found |
| 1893 | */ |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1894 | while ((IS_CHAR(c)) && ((c != stop) || /* checked */ |
| 1895 | (ctxt->input != input))) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1896 | if (len + 5 >= size) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1897 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 1898 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1899 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1900 | xmlGenericError(xmlGenericErrorContext, |
| 1901 | "realloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1902 | return(NULL); |
| 1903 | } |
| 1904 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1905 | COPY_BUF(l,buf,len,c); |
| 1906 | NEXTL(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1907 | /* |
| 1908 | * Pop-up of finished entities. |
| 1909 | */ |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 1910 | while ((RAW == 0) && (ctxt->inputNr > 1)) /* non input consuming */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1911 | xmlPopInput(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1912 | |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1913 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1914 | c = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1915 | if (c == 0) { |
| 1916 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1917 | c = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | buf[len] = 0; |
| 1921 | |
| 1922 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1923 | * Raise problem w.r.t. '&' and '%' being used in non-entities |
| 1924 | * reference constructs. Note Charref will be handled in |
| 1925 | * xmlStringDecodeEntities() |
| 1926 | */ |
| 1927 | cur = buf; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 1928 | while (*cur != 0) { /* non input consuming */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1929 | if ((*cur == '%') || ((*cur == '&') && (cur[1] != '#'))) { |
| 1930 | xmlChar *name; |
| 1931 | xmlChar tmp = *cur; |
| 1932 | |
| 1933 | cur++; |
| 1934 | name = xmlParseStringName(ctxt, &cur); |
| 1935 | if ((name == NULL) || (*cur != ';')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 1936 | ctxt->errNo = XML_ERR_ENTITY_CHAR_ERROR; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1937 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1938 | ctxt->sax->error(ctxt->userData, |
| 1939 | "EntityValue: '%c' forbidden except for entities references\n", |
| 1940 | tmp); |
| 1941 | ctxt->wellFormed = 0; |
| 1942 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1943 | } |
| 1944 | if ((ctxt->inSubset == 1) && (tmp == '%')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 1945 | ctxt->errNo = XML_ERR_ENTITY_PE_INTERNAL; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1946 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1947 | ctxt->sax->error(ctxt->userData, |
| 1948 | "EntityValue: PEReferences forbidden in internal subset\n", |
| 1949 | tmp); |
| 1950 | ctxt->wellFormed = 0; |
| 1951 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1952 | } |
| 1953 | if (name != NULL) |
| 1954 | xmlFree(name); |
| 1955 | } |
| 1956 | cur++; |
| 1957 | } |
| 1958 | |
| 1959 | /* |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1960 | * Then PEReference entities are substituted. |
| 1961 | */ |
| 1962 | if (c != stop) { |
| 1963 | ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED; |
| 1964 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 1965 | ctxt->sax->error(ctxt->userData, "EntityValue: \" expected\n"); |
| 1966 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1967 | ctxt->disableSAX = 1; |
| 1968 | xmlFree(buf); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1969 | } else { |
| 1970 | NEXT; |
| 1971 | /* |
| 1972 | * NOTE: 4.4.7 Bypassed |
| 1973 | * When a general entity reference appears in the EntityValue in |
| 1974 | * an entity declaration, it is bypassed and left as is. |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 1975 | * so XML_SUBSTITUTE_REF is not set here. |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 1976 | */ |
| 1977 | ret = xmlStringDecodeEntities(ctxt, buf, XML_SUBSTITUTE_PEREF, |
| 1978 | 0, 0, 0); |
| 1979 | if (orig != NULL) |
| 1980 | *orig = buf; |
| 1981 | else |
| 1982 | xmlFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | return(ret); |
| 1986 | } |
| 1987 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 1988 | /** |
| 1989 | * xmlParseAttValue: |
| 1990 | * @ctxt: an XML parser context |
| 1991 | * |
| 1992 | * parse a value for an attribute |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 1993 | * Note: the parser won't do substitution of entities here, this |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1994 | * will be handled later in xmlStringGetNodeList |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1995 | * |
| 1996 | * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | |
| 1997 | * "'" ([^<&'] | Reference)* "'" |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1998 | * |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 1999 | * 3.3.3 Attribute-Value Normalization: |
| 2000 | * Before the value of an attribute is passed to the application or |
| 2001 | * checked for validity, the XML processor must normalize it as follows: |
| 2002 | * - a character reference is processed by appending the referenced |
| 2003 | * character to the attribute value |
| 2004 | * - an entity reference is processed by recursively processing the |
| 2005 | * replacement text of the entity |
| 2006 | * - a whitespace character (#x20, #xD, #xA, #x9) is processed by |
| 2007 | * appending #x20 to the normalized value, except that only a single |
| 2008 | * #x20 is appended for a "#xD#xA" sequence that is part of an external |
| 2009 | * parsed entity or the literal entity value of an internal parsed entity |
| 2010 | * - other characters are processed by appending them to the normalized value |
Daniel Veillard | 0713665 | 1999-11-18 14:02:05 +0000 | [diff] [blame] | 2011 | * If the declared value is not CDATA, then the XML processor must further |
| 2012 | * process the normalized attribute value by discarding any leading and |
| 2013 | * trailing space (#x20) characters, and by replacing sequences of space |
| 2014 | * (#x20) characters by a single space (#x20) character. |
| 2015 | * All attributes for which no declaration has been read should be treated |
| 2016 | * by a non-validating parser as if declared CDATA. |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2017 | * |
| 2018 | * Returns the AttValue parsed or NULL. The value has to be freed by the caller. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2019 | */ |
| 2020 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2021 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2022 | xmlParseAttValue(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2023 | xmlChar limit = 0; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2024 | xmlChar *buf = NULL; |
| 2025 | int len = 0; |
| 2026 | int buf_size = 0; |
| 2027 | int c, l; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2028 | xmlChar *current = NULL; |
| 2029 | xmlEntityPtr ent; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2030 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2031 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2032 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2033 | if (NXT(0) == '"') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2034 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2035 | limit = '"'; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2036 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2037 | } else if (NXT(0) == '\'') { |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2038 | limit = '\''; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2039 | ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2040 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2041 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2042 | ctxt->errNo = XML_ERR_ATTRIBUTE_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2043 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2044 | ctxt->sax->error(ctxt->userData, "AttValue: \" or ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2045 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2046 | ctxt->disableSAX = 1; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2047 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2050 | /* |
| 2051 | * allocate a translation buffer. |
| 2052 | */ |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2053 | buf_size = XML_PARSER_BUFFER_SIZE; |
| 2054 | buf = (xmlChar *) xmlMalloc(buf_size * sizeof(xmlChar)); |
| 2055 | if (buf == NULL) { |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2056 | perror("xmlParseAttValue: malloc failed"); |
| 2057 | return(NULL); |
| 2058 | } |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2059 | |
| 2060 | /* |
| 2061 | * Ok loop until we reach one of the ending char or a size limit. |
| 2062 | */ |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2063 | c = CUR_CHAR(l); |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2064 | while (((NXT(0) != limit) && /* checked */ |
| 2065 | (c != '<')) || (ctxt->token != 0)) { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2066 | if (c == 0) break; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2067 | if (ctxt->token == '&') { |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 2068 | /* |
| 2069 | * The reparsing will be done in xmlStringGetNodeList() |
| 2070 | * called by the attribute() function in SAX.c |
| 2071 | */ |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2072 | static xmlChar buffer[6] = "&"; |
| 2073 | |
| 2074 | if (len > buf_size - 10) { |
| 2075 | growBuffer(buf); |
| 2076 | } |
| 2077 | current = &buffer[0]; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2078 | while (*current != 0) { /* non input consuming */ |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2079 | buf[len++] = *current++; |
| 2080 | } |
| 2081 | ctxt->token = 0; |
| 2082 | } else if ((c == '&') && (NXT(1) == '#')) { |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2083 | int val = xmlParseCharRef(ctxt); |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 2084 | if (val == '&') { |
| 2085 | /* |
| 2086 | * The reparsing will be done in xmlStringGetNodeList() |
| 2087 | * called by the attribute() function in SAX.c |
| 2088 | */ |
| 2089 | static xmlChar buffer[6] = "&"; |
| 2090 | |
| 2091 | if (len > buf_size - 10) { |
| 2092 | growBuffer(buf); |
| 2093 | } |
| 2094 | current = &buffer[0]; |
| 2095 | while (*current != 0) { /* non input consuming */ |
| 2096 | buf[len++] = *current++; |
| 2097 | } |
| 2098 | } else { |
Daniel Veillard | 1e85139 | 2000-10-15 10:02:56 +0000 | [diff] [blame] | 2099 | len += xmlCopyChar(0, &buf[len], val); |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 2100 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2101 | } else if (c == '&') { |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2102 | ent = xmlParseEntityRef(ctxt); |
| 2103 | if ((ent != NULL) && |
| 2104 | (ctxt->replaceEntities != 0)) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2105 | xmlChar *rep; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2106 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2107 | if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) { |
| 2108 | rep = xmlStringDecodeEntities(ctxt, ent->content, |
| 2109 | XML_SUBSTITUTE_REF, 0, 0, 0); |
| 2110 | if (rep != NULL) { |
| 2111 | current = rep; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2112 | while (*current != 0) { /* non input consuming */ |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2113 | buf[len++] = *current++; |
| 2114 | if (len > buf_size - 10) { |
| 2115 | growBuffer(buf); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | xmlFree(rep); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2119 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2120 | } else { |
| 2121 | if (ent->content != NULL) |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2122 | buf[len++] = ent->content[0]; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2123 | } |
| 2124 | } else if (ent != NULL) { |
| 2125 | int i = xmlStrlen(ent->name); |
| 2126 | const xmlChar *cur = ent->name; |
| 2127 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2128 | /* |
| 2129 | * This may look absurd but is needed to detect |
| 2130 | * entities problems |
| 2131 | */ |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 2132 | if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) && |
| 2133 | (ent->content != NULL)) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2134 | xmlChar *rep; |
| 2135 | rep = xmlStringDecodeEntities(ctxt, ent->content, |
| 2136 | XML_SUBSTITUTE_REF, 0, 0, 0); |
| 2137 | if (rep != NULL) |
| 2138 | xmlFree(rep); |
| 2139 | } |
| 2140 | |
| 2141 | /* |
| 2142 | * Just output the reference |
| 2143 | */ |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2144 | buf[len++] = '&'; |
| 2145 | if (len > buf_size - i - 10) { |
| 2146 | growBuffer(buf); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2147 | } |
| 2148 | for (;i > 0;i--) |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2149 | buf[len++] = *cur++; |
| 2150 | buf[len++] = ';'; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2151 | } |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2152 | } else { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2153 | if ((c == 0x20) || (c == 0xD) || (c == 0xA) || (c == 0x9)) { |
| 2154 | COPY_BUF(l,buf,len,0x20); |
| 2155 | if (len > buf_size - 10) { |
| 2156 | growBuffer(buf); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2157 | } |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2158 | } else { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2159 | COPY_BUF(l,buf,len,c); |
| 2160 | if (len > buf_size - 10) { |
| 2161 | growBuffer(buf); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2162 | } |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2163 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2164 | NEXTL(l); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2165 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2166 | GROW; |
| 2167 | c = CUR_CHAR(l); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2168 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2169 | buf[len++] = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2170 | if (RAW == '<') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2171 | ctxt->errNo = XML_ERR_LT_IN_ATTRIBUTE; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2172 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2173 | ctxt->sax->error(ctxt->userData, |
| 2174 | "Unescaped '<' not allowed in attributes values\n"); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2175 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2176 | ctxt->disableSAX = 1; |
| 2177 | } else if (RAW != limit) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2178 | ctxt->errNo = XML_ERR_ATTRIBUTE_NOT_FINISHED; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2179 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2180 | ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n"); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2181 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2182 | ctxt->disableSAX = 1; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 2183 | } else |
| 2184 | NEXT; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2185 | return(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2188 | /** |
| 2189 | * xmlParseSystemLiteral: |
| 2190 | * @ctxt: an XML parser context |
| 2191 | * |
| 2192 | * parse an XML Literal |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2193 | * |
| 2194 | * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2195 | * |
| 2196 | * Returns the SystemLiteral parsed or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2197 | */ |
| 2198 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2199 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2200 | xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2201 | xmlChar *buf = NULL; |
| 2202 | int len = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2203 | int size = XML_PARSER_BUFFER_SIZE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2204 | int cur, l; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2205 | xmlChar stop; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2206 | int state = ctxt->instate; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2207 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2208 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2209 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2210 | if (RAW == '"') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2211 | NEXT; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2212 | stop = '"'; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2213 | } else if (RAW == '\'') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2214 | NEXT; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2215 | stop = '\''; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2216 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2217 | ctxt->errNo = XML_ERR_LITERAL_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2218 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2219 | ctxt->sax->error(ctxt->userData, |
| 2220 | "SystemLiteral \" or ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2221 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2222 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2223 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2226 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 2227 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2228 | xmlGenericError(xmlGenericErrorContext, |
| 2229 | "malloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2230 | return(NULL); |
| 2231 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2232 | ctxt->instate = XML_PARSER_SYSTEM_LITERAL; |
| 2233 | cur = CUR_CHAR(l); |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2234 | while ((IS_CHAR(cur)) && (cur != stop)) { /* checked */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2235 | if (len + 5 >= size) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2236 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2237 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2238 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2239 | xmlGenericError(xmlGenericErrorContext, |
| 2240 | "realloc of %d byte failed\n", size); |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2241 | ctxt->instate = (xmlParserInputState) state; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2242 | return(NULL); |
| 2243 | } |
| 2244 | } |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2245 | count++; |
| 2246 | if (count > 50) { |
| 2247 | GROW; |
| 2248 | count = 0; |
| 2249 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2250 | COPY_BUF(l,buf,len,cur); |
| 2251 | NEXTL(l); |
| 2252 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2253 | if (cur == 0) { |
| 2254 | GROW; |
| 2255 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2256 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2257 | } |
| 2258 | } |
| 2259 | buf[len] = 0; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2260 | ctxt->instate = (xmlParserInputState) state; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2261 | if (!IS_CHAR(cur)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2262 | ctxt->errNo = XML_ERR_LITERAL_NOT_FINISHED; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2263 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2264 | ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2265 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2266 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2267 | } else { |
| 2268 | NEXT; |
| 2269 | } |
| 2270 | return(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2273 | /** |
| 2274 | * xmlParsePubidLiteral: |
| 2275 | * @ctxt: an XML parser context |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2276 | * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2277 | * parse an XML public literal |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2278 | * |
| 2279 | * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" |
| 2280 | * |
| 2281 | * Returns the PubidLiteral parsed or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2282 | */ |
| 2283 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2284 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2285 | xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2286 | xmlChar *buf = NULL; |
| 2287 | int len = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2288 | int size = XML_PARSER_BUFFER_SIZE; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2289 | xmlChar cur; |
| 2290 | xmlChar stop; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2291 | int count = 0; |
Daniel Veillard | 6077d03 | 1999-10-09 09:11:45 +0000 | [diff] [blame] | 2292 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2293 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2294 | if (RAW == '"') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2295 | NEXT; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2296 | stop = '"'; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2297 | } else if (RAW == '\'') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2298 | NEXT; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2299 | stop = '\''; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2300 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2301 | ctxt->errNo = XML_ERR_LITERAL_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2302 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2303 | ctxt->sax->error(ctxt->userData, |
| 2304 | "SystemLiteral \" or ' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2305 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2306 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2307 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2308 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2309 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 2310 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2311 | xmlGenericError(xmlGenericErrorContext, |
| 2312 | "malloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2313 | return(NULL); |
| 2314 | } |
| 2315 | cur = CUR; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2316 | while ((IS_PUBIDCHAR(cur)) && (cur != stop)) { /* checked */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2317 | if (len + 1 >= size) { |
| 2318 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2319 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2320 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2321 | xmlGenericError(xmlGenericErrorContext, |
| 2322 | "realloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2323 | return(NULL); |
| 2324 | } |
| 2325 | } |
| 2326 | buf[len++] = cur; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2327 | count++; |
| 2328 | if (count > 50) { |
| 2329 | GROW; |
| 2330 | count = 0; |
| 2331 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2332 | NEXT; |
| 2333 | cur = CUR; |
| 2334 | if (cur == 0) { |
| 2335 | GROW; |
| 2336 | SHRINK; |
| 2337 | cur = CUR; |
| 2338 | } |
| 2339 | } |
| 2340 | buf[len] = 0; |
| 2341 | if (cur != stop) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2342 | ctxt->errNo = XML_ERR_LITERAL_NOT_FINISHED; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2343 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2344 | ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2345 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2346 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2347 | } else { |
| 2348 | NEXT; |
| 2349 | } |
| 2350 | return(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2353 | /** |
| 2354 | * xmlParseCharData: |
| 2355 | * @ctxt: an XML parser context |
| 2356 | * @cdata: int indicating whether we are within a CDATA section |
| 2357 | * |
| 2358 | * parse a CharData section. |
| 2359 | * if we are within a CDATA section ']]>' marks an end of section. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2360 | * |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2361 | * The right angle bracket (>) may be represented using the string ">", |
| 2362 | * and must, for compatibility, be escaped using ">" or a character |
| 2363 | * reference when it appears in the string "]]>" in content, when that |
| 2364 | * string is not marking the end of a CDATA section. |
| 2365 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2366 | * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) |
| 2367 | */ |
| 2368 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2369 | void |
| 2370 | xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2371 | xmlChar buf[XML_PARSER_BIG_BUFFER_SIZE + 5]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2372 | int nbchar = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2373 | int cur, l; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2374 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2375 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2376 | SHRINK; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2377 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2378 | cur = CUR_CHAR(l); |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2379 | while (((cur != '<') || (ctxt->token == '<')) && /* checked */ |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 2380 | ((cur != '&') || (ctxt->token == '&')) && |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 2381 | (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2382 | if ((cur == ']') && (NXT(1) == ']') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2383 | (NXT(2) == '>')) { |
| 2384 | if (cdata) break; |
| 2385 | else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2386 | ctxt->errNo = XML_ERR_MISPLACED_CDATA_END; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2387 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2388 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2389 | "Sequence ']]>' not allowed in content\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2390 | /* Should this be relaxed ??? I see a "must here */ |
| 2391 | ctxt->wellFormed = 0; |
| 2392 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2393 | } |
| 2394 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2395 | COPY_BUF(l,buf,nbchar,cur); |
| 2396 | if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2397 | /* |
| 2398 | * Ok the segment is to be consumed as chars. |
| 2399 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2400 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2401 | if (areBlanks(ctxt, buf, nbchar)) { |
| 2402 | if (ctxt->sax->ignorableWhitespace != NULL) |
| 2403 | ctxt->sax->ignorableWhitespace(ctxt->userData, |
| 2404 | buf, nbchar); |
| 2405 | } else { |
| 2406 | if (ctxt->sax->characters != NULL) |
| 2407 | ctxt->sax->characters(ctxt->userData, buf, nbchar); |
| 2408 | } |
| 2409 | } |
| 2410 | nbchar = 0; |
| 2411 | } |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2412 | count++; |
| 2413 | if (count > 50) { |
| 2414 | GROW; |
| 2415 | count = 0; |
| 2416 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2417 | NEXTL(l); |
| 2418 | cur = CUR_CHAR(l); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2419 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2420 | if (nbchar != 0) { |
| 2421 | /* |
| 2422 | * Ok the segment is to be consumed as chars. |
| 2423 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2424 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2425 | if (areBlanks(ctxt, buf, nbchar)) { |
| 2426 | if (ctxt->sax->ignorableWhitespace != NULL) |
| 2427 | ctxt->sax->ignorableWhitespace(ctxt->userData, buf, nbchar); |
| 2428 | } else { |
| 2429 | if (ctxt->sax->characters != NULL) |
| 2430 | ctxt->sax->characters(ctxt->userData, buf, nbchar); |
| 2431 | } |
| 2432 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2436 | /** |
| 2437 | * xmlParseExternalID: |
| 2438 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2439 | * @publicID: a xmlChar** receiving PubidLiteral |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2440 | * @strict: indicate whether we should restrict parsing to only |
| 2441 | * production [75], see NOTE below |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2442 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2443 | * Parse an External ID or a Public ID |
| 2444 | * |
| 2445 | * NOTE: Productions [75] and [83] interract badly since [75] can generate |
| 2446 | * 'PUBLIC' S PubidLiteral S SystemLiteral |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2447 | * |
| 2448 | * [75] ExternalID ::= 'SYSTEM' S SystemLiteral |
| 2449 | * | 'PUBLIC' S PubidLiteral S SystemLiteral |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2450 | * |
| 2451 | * [83] PublicID ::= 'PUBLIC' S PubidLiteral |
| 2452 | * |
| 2453 | * Returns the function returns SystemLiteral and in the second |
| 2454 | * case publicID receives PubidLiteral, is strict is off |
| 2455 | * it is possible to return NULL and have publicID set. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2456 | */ |
| 2457 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2458 | xmlChar * |
| 2459 | xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict) { |
| 2460 | xmlChar *URI = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2461 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2462 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2463 | if ((RAW == 'S') && (NXT(1) == 'Y') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2464 | (NXT(2) == 'S') && (NXT(3) == 'T') && |
| 2465 | (NXT(4) == 'E') && (NXT(5) == 'M')) { |
| 2466 | SKIP(6); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2467 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2468 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2469 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2470 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2471 | "Space required after 'SYSTEM'\n"); |
| 2472 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2473 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2474 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2475 | SKIP_BLANKS; |
| 2476 | URI = xmlParseSystemLiteral(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2477 | if (URI == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2478 | ctxt->errNo = XML_ERR_URI_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2479 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2480 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2481 | "xmlParseExternalID: SYSTEM, no URI\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2482 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2483 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2484 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2485 | } else if ((RAW == 'P') && (NXT(1) == 'U') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2486 | (NXT(2) == 'B') && (NXT(3) == 'L') && |
| 2487 | (NXT(4) == 'I') && (NXT(5) == 'C')) { |
| 2488 | SKIP(6); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2489 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2490 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2491 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2492 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2493 | "Space required after 'PUBLIC'\n"); |
| 2494 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2495 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2496 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2497 | SKIP_BLANKS; |
| 2498 | *publicID = xmlParsePubidLiteral(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2499 | if (*publicID == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2500 | ctxt->errNo = XML_ERR_PUBID_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2501 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2502 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2503 | "xmlParseExternalID: PUBLIC, no Public Identifier\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2504 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2505 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2506 | } |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2507 | if (strict) { |
| 2508 | /* |
| 2509 | * We don't handle [83] so "S SystemLiteral" is required. |
| 2510 | */ |
| 2511 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2512 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2513 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2514 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2515 | "Space required after the Public Identifier\n"); |
| 2516 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2517 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2518 | } |
| 2519 | } else { |
| 2520 | /* |
| 2521 | * We handle [83] so we return immediately, if |
| 2522 | * "S SystemLiteral" is not detected. From a purely parsing |
| 2523 | * point of view that's a nice mess. |
| 2524 | */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2525 | const xmlChar *ptr; |
| 2526 | GROW; |
| 2527 | |
| 2528 | ptr = CUR_PTR; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2529 | if (!IS_BLANK(*ptr)) return(NULL); |
| 2530 | |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2531 | while (IS_BLANK(*ptr)) ptr++; /* TODO: dangerous, fix ! */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2532 | if ((*ptr != '\'') && (*ptr != '"')) return(NULL); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2533 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2534 | SKIP_BLANKS; |
| 2535 | URI = xmlParseSystemLiteral(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2536 | if (URI == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2537 | ctxt->errNo = XML_ERR_URI_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2538 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2539 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2540 | "xmlParseExternalID: PUBLIC, no URI\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2541 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2542 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2543 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2544 | } |
| 2545 | return(URI); |
| 2546 | } |
| 2547 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2548 | /** |
| 2549 | * xmlParseComment: |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2550 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2551 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2552 | * Skip an XML (SGML) comment <!-- .... --> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2553 | * The spec says that "For compatibility, the string "--" (double-hyphen) |
| 2554 | * must not occur within comments. " |
| 2555 | * |
| 2556 | * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' |
| 2557 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2558 | void |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2559 | xmlParseComment(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2560 | xmlChar *buf = NULL; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 2561 | int len; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2562 | int size = XML_PARSER_BUFFER_SIZE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2563 | int q, ql; |
| 2564 | int r, rl; |
| 2565 | int cur, l; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2566 | xmlParserInputState state; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2567 | xmlParserInputPtr input = ctxt->input; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2568 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2569 | |
| 2570 | /* |
| 2571 | * Check that there is a comment right here. |
| 2572 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2573 | if ((RAW != '<') || (NXT(1) != '!') || |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2574 | (NXT(2) != '-') || (NXT(3) != '-')) return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2575 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2576 | state = ctxt->instate; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2577 | ctxt->instate = XML_PARSER_COMMENT; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2578 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2579 | SKIP(4); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2580 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 2581 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2582 | xmlGenericError(xmlGenericErrorContext, |
| 2583 | "malloc of %d byte failed\n", size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2584 | ctxt->instate = state; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2585 | return; |
| 2586 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2587 | q = CUR_CHAR(ql); |
| 2588 | NEXTL(ql); |
| 2589 | r = CUR_CHAR(rl); |
| 2590 | NEXTL(rl); |
| 2591 | cur = CUR_CHAR(l); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 2592 | len = 0; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2593 | while (IS_CHAR(cur) && /* checked */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2594 | ((cur != '>') || |
| 2595 | (r != '-') || (q != '-'))) { |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 2596 | if ((r == '-') && (q == '-') && (len > 1)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2597 | ctxt->errNo = XML_ERR_HYPHEN_IN_COMMENT; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2598 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2599 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2600 | "Comment must not contain '--' (double-hyphen)`\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2601 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2602 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2603 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2604 | if (len + 5 >= size) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2605 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2606 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2607 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2608 | xmlGenericError(xmlGenericErrorContext, |
| 2609 | "realloc of %d byte failed\n", size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2610 | ctxt->instate = state; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2611 | return; |
| 2612 | } |
| 2613 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2614 | COPY_BUF(ql,buf,len,q); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2615 | q = r; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2616 | ql = rl; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2617 | r = cur; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2618 | rl = l; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2619 | |
| 2620 | count++; |
| 2621 | if (count > 50) { |
| 2622 | GROW; |
| 2623 | count = 0; |
| 2624 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2625 | NEXTL(l); |
| 2626 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2627 | if (cur == 0) { |
| 2628 | SHRINK; |
| 2629 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2630 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2631 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2632 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2633 | buf[len] = 0; |
| 2634 | if (!IS_CHAR(cur)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2635 | ctxt->errNo = XML_ERR_COMMENT_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2636 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2637 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2638 | "Comment not terminated \n<!--%.50s\n", buf); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2639 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2640 | ctxt->disableSAX = 1; |
| 2641 | xmlFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2642 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2643 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2644 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2645 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2646 | ctxt->sax->error(ctxt->userData, |
| 2647 | "Comment doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2648 | ctxt->wellFormed = 0; |
| 2649 | ctxt->disableSAX = 1; |
| 2650 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2651 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2652 | if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) && |
| 2653 | (!ctxt->disableSAX)) |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2654 | ctxt->sax->comment(ctxt->userData, buf); |
| 2655 | xmlFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2656 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2657 | ctxt->instate = state; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2660 | /** |
| 2661 | * xmlParsePITarget: |
| 2662 | * @ctxt: an XML parser context |
| 2663 | * |
| 2664 | * parse the name of a PI |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2665 | * |
| 2666 | * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2667 | * |
| 2668 | * Returns the PITarget name or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2669 | */ |
| 2670 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2671 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2672 | xmlParsePITarget(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2673 | xmlChar *name; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2674 | |
| 2675 | name = xmlParseName(ctxt); |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 2676 | if ((name != NULL) && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2677 | ((name[0] == 'x') || (name[0] == 'X')) && |
| 2678 | ((name[1] == 'm') || (name[1] == 'M')) && |
| 2679 | ((name[2] == 'l') || (name[2] == 'L'))) { |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 2680 | int i; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2681 | if ((name[0] == 'x') && (name[1] == 'm') && |
| 2682 | (name[2] == 'l') && (name[3] == 0)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2683 | ctxt->errNo = XML_ERR_RESERVED_XML_NAME; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2684 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2685 | ctxt->sax->error(ctxt->userData, |
| 2686 | "XML declaration allowed only at the start of the document\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2687 | ctxt->wellFormed = 0; |
| 2688 | ctxt->disableSAX = 1; |
| 2689 | return(name); |
| 2690 | } else if (name[3] == 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2691 | ctxt->errNo = XML_ERR_RESERVED_XML_NAME; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2692 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2693 | ctxt->sax->error(ctxt->userData, "Invalid PI name\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2694 | ctxt->wellFormed = 0; |
| 2695 | ctxt->disableSAX = 1; |
| 2696 | return(name); |
| 2697 | } |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 2698 | for (i = 0;;i++) { |
| 2699 | if (xmlW3CPIs[i] == NULL) break; |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 2700 | if (xmlStrEqual(name, (const xmlChar *)xmlW3CPIs[i])) |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 2701 | return(name); |
| 2702 | } |
| 2703 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2704 | ctxt->errNo = XML_ERR_RESERVED_XML_NAME; |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame] | 2705 | ctxt->sax->warning(ctxt->userData, |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2706 | "xmlParsePItarget: invalid name prefix 'xml'\n"); |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2707 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2708 | } |
| 2709 | return(name); |
| 2710 | } |
| 2711 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2712 | /** |
| 2713 | * xmlParsePI: |
| 2714 | * @ctxt: an XML parser context |
| 2715 | * |
| 2716 | * parse an XML Processing Instruction. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2717 | * |
| 2718 | * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2719 | * |
| 2720 | * The processing is transfered to SAX once parsed. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2721 | */ |
| 2722 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2723 | void |
| 2724 | xmlParsePI(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2725 | xmlChar *buf = NULL; |
| 2726 | int len = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2727 | int size = XML_PARSER_BUFFER_SIZE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2728 | int cur, l; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2729 | xmlChar *target; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2730 | xmlParserInputState state; |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2731 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2732 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2733 | if ((RAW == '<') && (NXT(1) == '?')) { |
| 2734 | xmlParserInputPtr input = ctxt->input; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2735 | state = ctxt->instate; |
| 2736 | ctxt->instate = XML_PARSER_PI; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2737 | /* |
| 2738 | * this is a Processing Instruction. |
| 2739 | */ |
| 2740 | SKIP(2); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2741 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2742 | |
| 2743 | /* |
| 2744 | * Parse the target name and check for special support like |
| 2745 | * namespace. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2746 | */ |
| 2747 | target = xmlParsePITarget(ctxt); |
| 2748 | if (target != NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2749 | if ((RAW == '?') && (NXT(1) == '>')) { |
| 2750 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2751 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2752 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2753 | ctxt->sax->error(ctxt->userData, |
| 2754 | "PI declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2755 | ctxt->wellFormed = 0; |
| 2756 | ctxt->disableSAX = 1; |
| 2757 | } |
| 2758 | SKIP(2); |
| 2759 | |
| 2760 | /* |
| 2761 | * SAX: PI detected. |
| 2762 | */ |
| 2763 | if ((ctxt->sax) && (!ctxt->disableSAX) && |
| 2764 | (ctxt->sax->processingInstruction != NULL)) |
| 2765 | ctxt->sax->processingInstruction(ctxt->userData, |
| 2766 | target, NULL); |
| 2767 | ctxt->instate = state; |
| 2768 | xmlFree(target); |
| 2769 | return; |
| 2770 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2771 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 2772 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2773 | xmlGenericError(xmlGenericErrorContext, |
| 2774 | "malloc of %d byte failed\n", size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2775 | ctxt->instate = state; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2776 | return; |
| 2777 | } |
| 2778 | cur = CUR; |
| 2779 | if (!IS_BLANK(cur)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2780 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2781 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2782 | ctxt->sax->error(ctxt->userData, |
| 2783 | "xmlParsePI: PI %s space expected\n", target); |
| 2784 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2785 | ctxt->disableSAX = 1; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2786 | } |
| 2787 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2788 | cur = CUR_CHAR(l); |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2789 | while (IS_CHAR(cur) && /* checked */ |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2790 | ((cur != '?') || (NXT(1) != '>'))) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2791 | if (len + 5 >= size) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2792 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 2793 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2794 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2795 | xmlGenericError(xmlGenericErrorContext, |
| 2796 | "realloc of %d byte failed\n", size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2797 | ctxt->instate = state; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2798 | return; |
| 2799 | } |
| 2800 | } |
Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 2801 | count++; |
| 2802 | if (count > 50) { |
| 2803 | GROW; |
| 2804 | count = 0; |
| 2805 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2806 | COPY_BUF(l,buf,len,cur); |
| 2807 | NEXTL(l); |
| 2808 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2809 | if (cur == 0) { |
| 2810 | SHRINK; |
| 2811 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2812 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2813 | } |
| 2814 | } |
| 2815 | buf[len] = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2816 | if (cur != '?') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2817 | ctxt->errNo = XML_ERR_PI_NOT_FINISHED; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2818 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2819 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2820 | "xmlParsePI: PI %s never end ...\n", target); |
| 2821 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2822 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2823 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2824 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2825 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2826 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2827 | ctxt->sax->error(ctxt->userData, |
| 2828 | "PI declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2829 | ctxt->wellFormed = 0; |
| 2830 | ctxt->disableSAX = 1; |
| 2831 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2832 | SKIP(2); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2833 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2834 | /* |
| 2835 | * SAX: PI detected. |
| 2836 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2837 | if ((ctxt->sax) && (!ctxt->disableSAX) && |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 2838 | (ctxt->sax->processingInstruction != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2839 | ctxt->sax->processingInstruction(ctxt->userData, |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2840 | target, buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2841 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 2842 | xmlFree(buf); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2843 | xmlFree(target); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2844 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2845 | ctxt->errNo = XML_ERR_PI_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2846 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2847 | ctxt->sax->error(ctxt->userData, |
| 2848 | "xmlParsePI : no target name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2849 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2850 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2851 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 2852 | ctxt->instate = state; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2853 | } |
| 2854 | } |
| 2855 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2856 | /** |
| 2857 | * xmlParseNotationDecl: |
| 2858 | * @ctxt: an XML parser context |
| 2859 | * |
| 2860 | * parse a notation declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2861 | * |
| 2862 | * [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>' |
| 2863 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2864 | * Hence there is actually 3 choices: |
| 2865 | * 'PUBLIC' S PubidLiteral |
| 2866 | * 'PUBLIC' S PubidLiteral S SystemLiteral |
| 2867 | * and 'SYSTEM' S SystemLiteral |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2868 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2869 | * See the NOTE on xmlParseExternalID(). |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2870 | */ |
| 2871 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2872 | void |
| 2873 | xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2874 | xmlChar *name; |
| 2875 | xmlChar *Pubid; |
| 2876 | xmlChar *Systemid; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2877 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2878 | if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2879 | (NXT(2) == 'N') && (NXT(3) == 'O') && |
| 2880 | (NXT(4) == 'T') && (NXT(5) == 'A') && |
| 2881 | (NXT(6) == 'T') && (NXT(7) == 'I') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2882 | (NXT(8) == 'O') && (NXT(9) == 'N')) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2883 | xmlParserInputPtr input = ctxt->input; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2884 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2885 | SKIP(10); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2886 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2887 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 2888 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2889 | ctxt->sax->error(ctxt->userData, |
| 2890 | "Space required after '<!NOTATION'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2891 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2892 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2893 | return; |
| 2894 | } |
| 2895 | SKIP_BLANKS; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2896 | |
| 2897 | name = xmlParseName(ctxt); |
| 2898 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2899 | ctxt->errNo = XML_ERR_NOTATION_NOT_STARTED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2900 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2901 | ctxt->sax->error(ctxt->userData, |
| 2902 | "NOTATION: Name expected here\n"); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2903 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2904 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2905 | return; |
| 2906 | } |
| 2907 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2908 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2909 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2910 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2911 | "Space required after the NOTATION name'\n"); |
| 2912 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2913 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2914 | return; |
| 2915 | } |
| 2916 | SKIP_BLANKS; |
| 2917 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2918 | /* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2919 | * Parse the IDs. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2920 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2921 | Systemid = xmlParseExternalID(ctxt, &Pubid, 0); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2922 | SKIP_BLANKS; |
| 2923 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2924 | if (RAW == '>') { |
| 2925 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2926 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2927 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 2928 | ctxt->sax->error(ctxt->userData, |
| 2929 | "Notation declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2930 | ctxt->wellFormed = 0; |
| 2931 | ctxt->disableSAX = 1; |
| 2932 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2933 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2934 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
| 2935 | (ctxt->sax->notationDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2936 | ctxt->sax->notationDecl(ctxt->userData, name, Pubid, Systemid); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2937 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2938 | ctxt->errNo = XML_ERR_NOTATION_NOT_FINISHED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2939 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 2940 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2941 | "'>' required to close NOTATION declaration\n"); |
| 2942 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2943 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2944 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2945 | xmlFree(name); |
| 2946 | if (Systemid != NULL) xmlFree(Systemid); |
| 2947 | if (Pubid != NULL) xmlFree(Pubid); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 2951 | /** |
| 2952 | * xmlParseEntityDecl: |
| 2953 | * @ctxt: an XML parser context |
| 2954 | * |
| 2955 | * parse <!ENTITY declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2956 | * |
| 2957 | * [70] EntityDecl ::= GEDecl | PEDecl |
| 2958 | * |
| 2959 | * [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>' |
| 2960 | * |
| 2961 | * [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>' |
| 2962 | * |
| 2963 | * [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?) |
| 2964 | * |
| 2965 | * [74] PEDef ::= EntityValue | ExternalID |
| 2966 | * |
| 2967 | * [76] NDataDecl ::= S 'NDATA' S Name |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2968 | * |
| 2969 | * [ VC: Notation Declared ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2970 | * The Name must match the declared name of a notation. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2971 | */ |
| 2972 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 2973 | void |
| 2974 | xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2975 | xmlChar *name = NULL; |
| 2976 | xmlChar *value = NULL; |
| 2977 | xmlChar *URI = NULL, *literal = NULL; |
| 2978 | xmlChar *ndata = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2979 | int isParameter = 0; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2980 | xmlChar *orig = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2981 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2982 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2983 | if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2984 | (NXT(2) == 'E') && (NXT(3) == 'N') && |
| 2985 | (NXT(4) == 'T') && (NXT(5) == 'I') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2986 | (NXT(6) == 'T') && (NXT(7) == 'Y')) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2987 | xmlParserInputPtr input = ctxt->input; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2988 | ctxt->instate = XML_PARSER_ENTITY_DECL; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2989 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2990 | SKIP(8); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2991 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 2992 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2993 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 2994 | ctxt->sax->error(ctxt->userData, |
| 2995 | "Space required after '<!ENTITY'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2996 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 2997 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2998 | } |
| 2999 | SKIP_BLANKS; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3000 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3001 | if (RAW == '%') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3002 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3003 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3004 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3005 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3006 | ctxt->sax->error(ctxt->userData, |
| 3007 | "Space required after '%'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3008 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3009 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3010 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3011 | SKIP_BLANKS; |
| 3012 | isParameter = 1; |
| 3013 | } |
| 3014 | |
| 3015 | name = xmlParseName(ctxt); |
| 3016 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3017 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3018 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3019 | ctxt->sax->error(ctxt->userData, "xmlParseEntityDecl: no name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3020 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3021 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3022 | return; |
| 3023 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3024 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3025 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3026 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3027 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3028 | "Space required after the entity name\n"); |
| 3029 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3030 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3031 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3032 | SKIP_BLANKS; |
| 3033 | |
| 3034 | /* |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3035 | * handle the various case of definitions... |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3036 | */ |
| 3037 | if (isParameter) { |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 3038 | if ((RAW == '"') || (RAW == '\'')) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3039 | value = xmlParseEntityValue(ctxt, &orig); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3040 | if (value) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3041 | if ((ctxt->sax != NULL) && |
| 3042 | (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3043 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3044 | XML_INTERNAL_PARAMETER_ENTITY, |
| 3045 | NULL, NULL, value); |
| 3046 | } |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 3047 | } else { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3048 | URI = xmlParseExternalID(ctxt, &literal, 1); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3049 | if ((URI == NULL) && (literal == NULL)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3050 | ctxt->errNo = XML_ERR_VALUE_REQUIRED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3051 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 3052 | ctxt->sax->error(ctxt->userData, |
| 3053 | "Entity value required\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3054 | ctxt->wellFormed = 0; |
| 3055 | ctxt->disableSAX = 1; |
| 3056 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3057 | if (URI) { |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3058 | xmlURIPtr uri; |
| 3059 | |
| 3060 | uri = xmlParseURI((const char *) URI); |
| 3061 | if (uri == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3062 | ctxt->errNo = XML_ERR_INVALID_URI; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3063 | if ((ctxt->sax != NULL) && |
| 3064 | (!ctxt->disableSAX) && |
| 3065 | (ctxt->sax->error != NULL)) |
| 3066 | ctxt->sax->error(ctxt->userData, |
| 3067 | "Invalid URI: %s\n", URI); |
| 3068 | ctxt->wellFormed = 0; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3069 | } else { |
| 3070 | if (uri->fragment != NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3071 | ctxt->errNo = XML_ERR_URI_FRAGMENT; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3072 | if ((ctxt->sax != NULL) && |
| 3073 | (!ctxt->disableSAX) && |
| 3074 | (ctxt->sax->error != NULL)) |
| 3075 | ctxt->sax->error(ctxt->userData, |
| 3076 | "Fragment not allowed: %s\n", URI); |
| 3077 | ctxt->wellFormed = 0; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3078 | } else { |
| 3079 | if ((ctxt->sax != NULL) && |
| 3080 | (!ctxt->disableSAX) && |
| 3081 | (ctxt->sax->entityDecl != NULL)) |
| 3082 | ctxt->sax->entityDecl(ctxt->userData, name, |
| 3083 | XML_EXTERNAL_PARAMETER_ENTITY, |
| 3084 | literal, URI, NULL); |
| 3085 | } |
| 3086 | xmlFreeURI(uri); |
| 3087 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3088 | } |
| 3089 | } |
| 3090 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3091 | if ((RAW == '"') || (RAW == '\'')) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3092 | value = xmlParseEntityValue(ctxt, &orig); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3093 | if ((ctxt->sax != NULL) && |
| 3094 | (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3095 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3096 | XML_INTERNAL_GENERAL_ENTITY, |
| 3097 | NULL, NULL, value); |
| 3098 | } else { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3099 | URI = xmlParseExternalID(ctxt, &literal, 1); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3100 | if ((URI == NULL) && (literal == NULL)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3101 | ctxt->errNo = XML_ERR_VALUE_REQUIRED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3102 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 3103 | ctxt->sax->error(ctxt->userData, |
| 3104 | "Entity value required\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3105 | ctxt->wellFormed = 0; |
| 3106 | ctxt->disableSAX = 1; |
| 3107 | } |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3108 | if (URI) { |
| 3109 | xmlURIPtr uri; |
| 3110 | |
| 3111 | uri = xmlParseURI((const char *)URI); |
| 3112 | if (uri == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3113 | ctxt->errNo = XML_ERR_INVALID_URI; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3114 | if ((ctxt->sax != NULL) && |
| 3115 | (!ctxt->disableSAX) && |
| 3116 | (ctxt->sax->error != NULL)) |
| 3117 | ctxt->sax->error(ctxt->userData, |
| 3118 | "Invalid URI: %s\n", URI); |
| 3119 | ctxt->wellFormed = 0; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3120 | } else { |
| 3121 | if (uri->fragment != NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3122 | ctxt->errNo = XML_ERR_URI_FRAGMENT; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3123 | if ((ctxt->sax != NULL) && |
| 3124 | (!ctxt->disableSAX) && |
| 3125 | (ctxt->sax->error != NULL)) |
| 3126 | ctxt->sax->error(ctxt->userData, |
| 3127 | "Fragment not allowed: %s\n", URI); |
| 3128 | ctxt->wellFormed = 0; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 3129 | } |
| 3130 | xmlFreeURI(uri); |
| 3131 | } |
| 3132 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3133 | if ((RAW != '>') && (!IS_BLANK(CUR))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3134 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3135 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3136 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3137 | "Space required before 'NDATA'\n"); |
| 3138 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3139 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3140 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3141 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3142 | if ((RAW == 'N') && (NXT(1) == 'D') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3143 | (NXT(2) == 'A') && (NXT(3) == 'T') && |
| 3144 | (NXT(4) == 'A')) { |
| 3145 | SKIP(5); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3146 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3147 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3148 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3149 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3150 | "Space required after 'NDATA'\n"); |
| 3151 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3152 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3153 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3154 | SKIP_BLANKS; |
| 3155 | ndata = xmlParseName(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3156 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3157 | (ctxt->sax->unparsedEntityDecl != NULL)) |
| 3158 | ctxt->sax->unparsedEntityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3159 | literal, URI, ndata); |
| 3160 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3161 | if ((ctxt->sax != NULL) && |
| 3162 | (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3163 | ctxt->sax->entityDecl(ctxt->userData, name, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3164 | XML_EXTERNAL_GENERAL_PARSED_ENTITY, |
| 3165 | literal, URI, NULL); |
| 3166 | } |
| 3167 | } |
| 3168 | } |
| 3169 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3170 | if (RAW != '>') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3171 | ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3172 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3173 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3174 | "xmlParseEntityDecl: entity %s not terminated\n", name); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3175 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3176 | ctxt->disableSAX = 1; |
| 3177 | } else { |
| 3178 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3179 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3180 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 3181 | ctxt->sax->error(ctxt->userData, |
| 3182 | "Entity declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3183 | ctxt->wellFormed = 0; |
| 3184 | ctxt->disableSAX = 1; |
| 3185 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3186 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3187 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3188 | if (orig != NULL) { |
| 3189 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3190 | * Ugly mechanism to save the raw entity value. |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3191 | */ |
| 3192 | xmlEntityPtr cur = NULL; |
| 3193 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3194 | if (isParameter) { |
| 3195 | if ((ctxt->sax != NULL) && |
| 3196 | (ctxt->sax->getParameterEntity != NULL)) |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 3197 | cur = ctxt->sax->getParameterEntity(ctxt->userData, name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3198 | } else { |
| 3199 | if ((ctxt->sax != NULL) && |
| 3200 | (ctxt->sax->getEntity != NULL)) |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 3201 | cur = ctxt->sax->getEntity(ctxt->userData, name); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3202 | } |
| 3203 | if (cur != NULL) { |
| 3204 | if (cur->orig != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3205 | xmlFree(orig); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3206 | else |
| 3207 | cur->orig = orig; |
| 3208 | } else |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3209 | xmlFree(orig); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3210 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3211 | if (name != NULL) xmlFree(name); |
| 3212 | if (value != NULL) xmlFree(value); |
| 3213 | if (URI != NULL) xmlFree(URI); |
| 3214 | if (literal != NULL) xmlFree(literal); |
| 3215 | if (ndata != NULL) xmlFree(ndata); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3219 | /** |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3220 | * xmlParseDefaultDecl: |
| 3221 | * @ctxt: an XML parser context |
| 3222 | * @value: Receive a possible fixed default value for the attribute |
| 3223 | * |
| 3224 | * Parse an attribute default declaration |
| 3225 | * |
| 3226 | * [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) |
| 3227 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3228 | * [ VC: Required Attribute ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3229 | * if the default declaration is the keyword #REQUIRED, then the |
| 3230 | * attribute must be specified for all elements of the type in the |
| 3231 | * attribute-list declaration. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3232 | * |
| 3233 | * [ VC: Attribute Default Legal ] |
| 3234 | * The declared default value must meet the lexical constraints of |
| 3235 | * the declared attribute type c.f. xmlValidateAttributeDecl() |
| 3236 | * |
| 3237 | * [ VC: Fixed Attribute Default ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3238 | * if an attribute has a default value declared with the #FIXED |
| 3239 | * keyword, instances of that attribute must match the default value. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3240 | * |
| 3241 | * [ WFC: No < in Attribute Values ] |
| 3242 | * handled in xmlParseAttValue() |
| 3243 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3244 | * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED |
| 3245 | * or XML_ATTRIBUTE_FIXED. |
| 3246 | */ |
| 3247 | |
| 3248 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3249 | xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3250 | int val; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3251 | xmlChar *ret; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3252 | |
| 3253 | *value = NULL; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3254 | if ((RAW == '#') && (NXT(1) == 'R') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3255 | (NXT(2) == 'E') && (NXT(3) == 'Q') && |
| 3256 | (NXT(4) == 'U') && (NXT(5) == 'I') && |
| 3257 | (NXT(6) == 'R') && (NXT(7) == 'E') && |
| 3258 | (NXT(8) == 'D')) { |
| 3259 | SKIP(9); |
| 3260 | return(XML_ATTRIBUTE_REQUIRED); |
| 3261 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3262 | if ((RAW == '#') && (NXT(1) == 'I') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3263 | (NXT(2) == 'M') && (NXT(3) == 'P') && |
| 3264 | (NXT(4) == 'L') && (NXT(5) == 'I') && |
| 3265 | (NXT(6) == 'E') && (NXT(7) == 'D')) { |
| 3266 | SKIP(8); |
| 3267 | return(XML_ATTRIBUTE_IMPLIED); |
| 3268 | } |
| 3269 | val = XML_ATTRIBUTE_NONE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3270 | if ((RAW == '#') && (NXT(1) == 'F') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3271 | (NXT(2) == 'I') && (NXT(3) == 'X') && |
| 3272 | (NXT(4) == 'E') && (NXT(5) == 'D')) { |
| 3273 | SKIP(6); |
| 3274 | val = XML_ATTRIBUTE_FIXED; |
| 3275 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3276 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3277 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3278 | ctxt->sax->error(ctxt->userData, |
| 3279 | "Space required after '#FIXED'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3280 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3281 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3282 | } |
| 3283 | SKIP_BLANKS; |
| 3284 | } |
| 3285 | ret = xmlParseAttValue(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3286 | ctxt->instate = XML_PARSER_DTD; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3287 | if (ret == NULL) { |
| 3288 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3289 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3290 | "Attribute default value declaration error\n"); |
| 3291 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3292 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3293 | } else |
| 3294 | *value = ret; |
| 3295 | return(val); |
| 3296 | } |
| 3297 | |
| 3298 | /** |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3299 | * xmlParseNotationType: |
| 3300 | * @ctxt: an XML parser context |
| 3301 | * |
| 3302 | * parse an Notation attribute type. |
| 3303 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3304 | * Note: the leading 'NOTATION' S part has already being parsed... |
| 3305 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3306 | * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' |
| 3307 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3308 | * [ VC: Notation Attributes ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3309 | * Values of this type must match one of the notation names included |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3310 | * in the declaration; all notation names in the declaration must be declared. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3311 | * |
| 3312 | * Returns: the notation attribute tree built while parsing |
| 3313 | */ |
| 3314 | |
| 3315 | xmlEnumerationPtr |
| 3316 | xmlParseNotationType(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3317 | xmlChar *name; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3318 | xmlEnumerationPtr ret = NULL, last = NULL, cur; |
| 3319 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3320 | if (RAW != '(') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3321 | ctxt->errNo = XML_ERR_NOTATION_NOT_STARTED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3322 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3323 | ctxt->sax->error(ctxt->userData, |
| 3324 | "'(' required to start 'NOTATION'\n"); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3325 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3326 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3327 | return(NULL); |
| 3328 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3329 | SHRINK; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3330 | do { |
| 3331 | NEXT; |
| 3332 | SKIP_BLANKS; |
| 3333 | name = xmlParseName(ctxt); |
| 3334 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3335 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3336 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3337 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3338 | "Name expected in NOTATION declaration\n"); |
| 3339 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3340 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3341 | return(ret); |
| 3342 | } |
| 3343 | cur = xmlCreateEnumeration(name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3344 | xmlFree(name); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3345 | if (cur == NULL) return(ret); |
| 3346 | if (last == NULL) ret = last = cur; |
| 3347 | else { |
| 3348 | last->next = cur; |
| 3349 | last = cur; |
| 3350 | } |
| 3351 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3352 | } while (RAW == '|'); |
| 3353 | if (RAW != ')') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3354 | ctxt->errNo = XML_ERR_NOTATION_NOT_FINISHED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3355 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3356 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3357 | "')' required to finish NOTATION declaration\n"); |
| 3358 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3359 | ctxt->disableSAX = 1; |
| 3360 | if ((last != NULL) && (last != ret)) |
| 3361 | xmlFreeEnumeration(last); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3362 | return(ret); |
| 3363 | } |
| 3364 | NEXT; |
| 3365 | return(ret); |
| 3366 | } |
| 3367 | |
| 3368 | /** |
| 3369 | * xmlParseEnumerationType: |
| 3370 | * @ctxt: an XML parser context |
| 3371 | * |
| 3372 | * parse an Enumeration attribute type. |
| 3373 | * |
| 3374 | * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' |
| 3375 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3376 | * [ VC: Enumeration ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3377 | * Values of this type must match one of the Nmtoken tokens in |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3378 | * the declaration |
| 3379 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3380 | * Returns: the enumeration attribute tree built while parsing |
| 3381 | */ |
| 3382 | |
| 3383 | xmlEnumerationPtr |
| 3384 | xmlParseEnumerationType(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3385 | xmlChar *name; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3386 | xmlEnumerationPtr ret = NULL, last = NULL, cur; |
| 3387 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3388 | if (RAW != '(') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3389 | ctxt->errNo = XML_ERR_ATTLIST_NOT_STARTED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3390 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3391 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3392 | "'(' required to start ATTLIST enumeration\n"); |
| 3393 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3394 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3395 | return(NULL); |
| 3396 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3397 | SHRINK; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3398 | do { |
| 3399 | NEXT; |
| 3400 | SKIP_BLANKS; |
| 3401 | name = xmlParseNmtoken(ctxt); |
| 3402 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3403 | ctxt->errNo = XML_ERR_NMTOKEN_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3404 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3405 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3406 | "NmToken expected in ATTLIST enumeration\n"); |
| 3407 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3408 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3409 | return(ret); |
| 3410 | } |
| 3411 | cur = xmlCreateEnumeration(name); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3412 | xmlFree(name); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3413 | if (cur == NULL) return(ret); |
| 3414 | if (last == NULL) ret = last = cur; |
| 3415 | else { |
| 3416 | last->next = cur; |
| 3417 | last = cur; |
| 3418 | } |
| 3419 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3420 | } while (RAW == '|'); |
| 3421 | if (RAW != ')') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3422 | ctxt->errNo = XML_ERR_ATTLIST_NOT_FINISHED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3423 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3424 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3425 | "')' required to finish ATTLIST enumeration\n"); |
| 3426 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3427 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3428 | return(ret); |
| 3429 | } |
| 3430 | NEXT; |
| 3431 | return(ret); |
| 3432 | } |
| 3433 | |
| 3434 | /** |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3435 | * xmlParseEnumeratedType: |
| 3436 | * @ctxt: an XML parser context |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3437 | * @tree: the enumeration tree built while parsing |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3438 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3439 | * parse an Enumerated attribute type. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3440 | * |
| 3441 | * [57] EnumeratedType ::= NotationType | Enumeration |
| 3442 | * |
| 3443 | * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' |
| 3444 | * |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3445 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3446 | * Returns: XML_ATTRIBUTE_ENUMERATION or XML_ATTRIBUTE_NOTATION |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3447 | */ |
| 3448 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3449 | int |
| 3450 | xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3451 | if ((RAW == 'N') && (NXT(1) == 'O') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3452 | (NXT(2) == 'T') && (NXT(3) == 'A') && |
| 3453 | (NXT(4) == 'T') && (NXT(5) == 'I') && |
| 3454 | (NXT(6) == 'O') && (NXT(7) == 'N')) { |
| 3455 | SKIP(8); |
| 3456 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3457 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3458 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3459 | ctxt->sax->error(ctxt->userData, |
| 3460 | "Space required after 'NOTATION'\n"); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3461 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3462 | ctxt->disableSAX = 1; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3463 | return(0); |
| 3464 | } |
| 3465 | SKIP_BLANKS; |
| 3466 | *tree = xmlParseNotationType(ctxt); |
| 3467 | if (*tree == NULL) return(0); |
| 3468 | return(XML_ATTRIBUTE_NOTATION); |
| 3469 | } |
| 3470 | *tree = xmlParseEnumerationType(ctxt); |
| 3471 | if (*tree == NULL) return(0); |
| 3472 | return(XML_ATTRIBUTE_ENUMERATION); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3475 | /** |
| 3476 | * xmlParseAttributeType: |
| 3477 | * @ctxt: an XML parser context |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3478 | * @tree: the enumeration tree built while parsing |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3479 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3480 | * parse the Attribute list def for an element |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3481 | * |
| 3482 | * [54] AttType ::= StringType | TokenizedType | EnumeratedType |
| 3483 | * |
| 3484 | * [55] StringType ::= 'CDATA' |
| 3485 | * |
| 3486 | * [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | |
| 3487 | * 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3488 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3489 | * Validity constraints for attribute values syntax are checked in |
| 3490 | * xmlValidateAttributeValue() |
| 3491 | * |
| 3492 | * [ VC: ID ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3493 | * Values of type ID must match the Name production. A name must not |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3494 | * appear more than once in an XML document as a value of this type; |
| 3495 | * i.e., ID values must uniquely identify the elements which bear them. |
| 3496 | * |
| 3497 | * [ VC: One ID per Element Type ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3498 | * No element type may have more than one ID attribute specified. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3499 | * |
| 3500 | * [ VC: ID Attribute Default ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3501 | * An ID attribute must have a declared default of #IMPLIED or #REQUIRED. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3502 | * |
| 3503 | * [ VC: IDREF ] |
| 3504 | * Values of type IDREF must match the Name production, and values |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 3505 | * of type IDREFS must match Names; each IDREF Name must match the value |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3506 | * of an ID attribute on some element in the XML document; i.e. IDREF |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3507 | * values must match the value of some ID attribute. |
| 3508 | * |
| 3509 | * [ VC: Entity Name ] |
| 3510 | * Values of type ENTITY must match the Name production, values |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 3511 | * of type ENTITIES must match Names; each Entity Name must match the |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3512 | * name of an unparsed entity declared in the DTD. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3513 | * |
| 3514 | * [ VC: Name Token ] |
| 3515 | * Values of type NMTOKEN must match the Nmtoken production; values |
| 3516 | * of type NMTOKENS must match Nmtokens. |
| 3517 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3518 | * Returns the attribute type |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3519 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3520 | int |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3521 | xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3522 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3523 | if ((RAW == 'C') && (NXT(1) == 'D') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3524 | (NXT(2) == 'A') && (NXT(3) == 'T') && |
| 3525 | (NXT(4) == 'A')) { |
| 3526 | SKIP(5); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3527 | return(XML_ATTRIBUTE_CDATA); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3528 | } else if ((RAW == 'I') && (NXT(1) == 'D') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3529 | (NXT(2) == 'R') && (NXT(3) == 'E') && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3530 | (NXT(4) == 'F') && (NXT(5) == 'S')) { |
| 3531 | SKIP(6); |
| 3532 | return(XML_ATTRIBUTE_IDREFS); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3533 | } else if ((RAW == 'I') && (NXT(1) == 'D') && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3534 | (NXT(2) == 'R') && (NXT(3) == 'E') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3535 | (NXT(4) == 'F')) { |
| 3536 | SKIP(5); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3537 | return(XML_ATTRIBUTE_IDREF); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3538 | } else if ((RAW == 'I') && (NXT(1) == 'D')) { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3539 | SKIP(2); |
| 3540 | return(XML_ATTRIBUTE_ID); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3541 | } else if ((RAW == 'E') && (NXT(1) == 'N') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3542 | (NXT(2) == 'T') && (NXT(3) == 'I') && |
| 3543 | (NXT(4) == 'T') && (NXT(5) == 'Y')) { |
| 3544 | SKIP(6); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3545 | return(XML_ATTRIBUTE_ENTITY); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3546 | } else if ((RAW == 'E') && (NXT(1) == 'N') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3547 | (NXT(2) == 'T') && (NXT(3) == 'I') && |
| 3548 | (NXT(4) == 'T') && (NXT(5) == 'I') && |
| 3549 | (NXT(6) == 'E') && (NXT(7) == 'S')) { |
| 3550 | SKIP(8); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3551 | return(XML_ATTRIBUTE_ENTITIES); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3552 | } else if ((RAW == 'N') && (NXT(1) == 'M') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3553 | (NXT(2) == 'T') && (NXT(3) == 'O') && |
| 3554 | (NXT(4) == 'K') && (NXT(5) == 'E') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3555 | (NXT(6) == 'N') && (NXT(7) == 'S')) { |
| 3556 | SKIP(8); |
| 3557 | return(XML_ATTRIBUTE_NMTOKENS); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3558 | } else if ((RAW == 'N') && (NXT(1) == 'M') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3559 | (NXT(2) == 'T') && (NXT(3) == 'O') && |
| 3560 | (NXT(4) == 'K') && (NXT(5) == 'E') && |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3561 | (NXT(6) == 'N')) { |
| 3562 | SKIP(7); |
| 3563 | return(XML_ATTRIBUTE_NMTOKEN); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3564 | } |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3565 | return(xmlParseEnumeratedType(ctxt, tree)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3568 | /** |
| 3569 | * xmlParseAttributeListDecl: |
| 3570 | * @ctxt: an XML parser context |
| 3571 | * |
| 3572 | * : parse the Attribute list def for an element |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3573 | * |
| 3574 | * [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>' |
| 3575 | * |
| 3576 | * [53] AttDef ::= S Name S AttType S DefaultDecl |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3577 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3578 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 3579 | void |
| 3580 | xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3581 | xmlChar *elemName; |
| 3582 | xmlChar *attrName; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3583 | xmlEnumerationPtr tree; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3584 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3585 | if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3586 | (NXT(2) == 'A') && (NXT(3) == 'T') && |
| 3587 | (NXT(4) == 'T') && (NXT(5) == 'L') && |
| 3588 | (NXT(6) == 'I') && (NXT(7) == 'S') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3589 | (NXT(8) == 'T')) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3590 | xmlParserInputPtr input = ctxt->input; |
| 3591 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3592 | SKIP(9); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3593 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3594 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3595 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3596 | ctxt->sax->error(ctxt->userData, |
| 3597 | "Space required after '<!ATTLIST'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3598 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3599 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3600 | } |
| 3601 | SKIP_BLANKS; |
| 3602 | elemName = xmlParseName(ctxt); |
| 3603 | if (elemName == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3604 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3605 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3606 | ctxt->sax->error(ctxt->userData, |
| 3607 | "ATTLIST: no name for Element\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3608 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3609 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3610 | return; |
| 3611 | } |
| 3612 | SKIP_BLANKS; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3613 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3614 | while (RAW != '>') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3615 | const xmlChar *check = CUR_PTR; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3616 | int type; |
| 3617 | int def; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3618 | xmlChar *defaultValue = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3619 | |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3620 | GROW; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3621 | tree = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3622 | attrName = xmlParseName(ctxt); |
| 3623 | if (attrName == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3624 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3625 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 3626 | ctxt->sax->error(ctxt->userData, |
| 3627 | "ATTLIST: no name for Attribute\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3628 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3629 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3630 | break; |
| 3631 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3632 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3633 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3634 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3635 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3636 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3637 | "Space required after the attribute name\n"); |
| 3638 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3639 | ctxt->disableSAX = 1; |
| 3640 | if (attrName != NULL) |
| 3641 | xmlFree(attrName); |
| 3642 | if (defaultValue != NULL) |
| 3643 | xmlFree(defaultValue); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3644 | break; |
| 3645 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3646 | SKIP_BLANKS; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3647 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3648 | type = xmlParseAttributeType(ctxt, &tree); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3649 | if (type <= 0) { |
| 3650 | if (attrName != NULL) |
| 3651 | xmlFree(attrName); |
| 3652 | if (defaultValue != NULL) |
| 3653 | xmlFree(defaultValue); |
| 3654 | break; |
| 3655 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3656 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3657 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3658 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3659 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3660 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3661 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3662 | "Space required after the attribute type\n"); |
| 3663 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3664 | ctxt->disableSAX = 1; |
| 3665 | if (attrName != NULL) |
| 3666 | xmlFree(attrName); |
| 3667 | if (defaultValue != NULL) |
| 3668 | xmlFree(defaultValue); |
| 3669 | if (tree != NULL) |
| 3670 | xmlFreeEnumeration(tree); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3671 | break; |
| 3672 | } |
| 3673 | SKIP_BLANKS; |
| 3674 | |
| 3675 | def = xmlParseDefaultDecl(ctxt, &defaultValue); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3676 | if (def <= 0) { |
| 3677 | if (attrName != NULL) |
| 3678 | xmlFree(attrName); |
| 3679 | if (defaultValue != NULL) |
| 3680 | xmlFree(defaultValue); |
| 3681 | if (tree != NULL) |
| 3682 | xmlFreeEnumeration(tree); |
| 3683 | break; |
| 3684 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3685 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3686 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3687 | if (RAW != '>') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3688 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3689 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3690 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3691 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3692 | "Space required after the attribute default value\n"); |
| 3693 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3694 | ctxt->disableSAX = 1; |
| 3695 | if (attrName != NULL) |
| 3696 | xmlFree(attrName); |
| 3697 | if (defaultValue != NULL) |
| 3698 | xmlFree(defaultValue); |
| 3699 | if (tree != NULL) |
| 3700 | xmlFreeEnumeration(tree); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3701 | break; |
| 3702 | } |
| 3703 | SKIP_BLANKS; |
| 3704 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3705 | if (check == CUR_PTR) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3706 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 3707 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3708 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3709 | "xmlParseAttributeListDecl: detected internal error\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3710 | if (attrName != NULL) |
| 3711 | xmlFree(attrName); |
| 3712 | if (defaultValue != NULL) |
| 3713 | xmlFree(defaultValue); |
| 3714 | if (tree != NULL) |
| 3715 | xmlFreeEnumeration(tree); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3716 | break; |
| 3717 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3718 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
| 3719 | (ctxt->sax->attributeDecl != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3720 | ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName, |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3721 | type, def, defaultValue, tree); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3722 | if (attrName != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3723 | xmlFree(attrName); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3724 | if (defaultValue != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3725 | xmlFree(defaultValue); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3726 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3727 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3728 | if (RAW == '>') { |
| 3729 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3730 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3731 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 3732 | ctxt->sax->error(ctxt->userData, |
| 3733 | "Attribute list declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3734 | ctxt->wellFormed = 0; |
| 3735 | ctxt->disableSAX = 1; |
| 3736 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3737 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3738 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3739 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3740 | xmlFree(elemName); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3741 | } |
| 3742 | } |
| 3743 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3744 | /** |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3745 | * xmlParseElementMixedContentDecl: |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3746 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 3747 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3748 | * parse the declaration for a Mixed Element content |
| 3749 | * The leading '(' and spaces have been skipped in xmlParseElementContentDecl |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3750 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3751 | * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | |
| 3752 | * '(' S? '#PCDATA' S? ')' |
| 3753 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3754 | * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49]) |
| 3755 | * |
| 3756 | * [ VC: No Duplicate Types ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3757 | * The same name must not appear more than once in a single |
| 3758 | * mixed-content declaration. |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3759 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3760 | * returns: the list of the xmlElementContentPtr describing the element choices |
| 3761 | */ |
| 3762 | xmlElementContentPtr |
| 3763 | xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3764 | xmlElementContentPtr ret = NULL, cur = NULL, n; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3765 | xmlChar *elem = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3766 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3767 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3768 | if ((RAW == '#') && (NXT(1) == 'P') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3769 | (NXT(2) == 'C') && (NXT(3) == 'D') && |
| 3770 | (NXT(4) == 'A') && (NXT(5) == 'T') && |
| 3771 | (NXT(6) == 'A')) { |
| 3772 | SKIP(7); |
| 3773 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3774 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3775 | if (RAW == ')') { |
| 3776 | ctxt->entity = ctxt->input; |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 3777 | NEXT; |
| 3778 | ret = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_PCDATA); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3779 | if (RAW == '*') { |
Daniel Veillard | f600e25 | 1999-12-18 15:32:46 +0000 | [diff] [blame] | 3780 | ret->ocur = XML_ELEMENT_CONTENT_MULT; |
| 3781 | NEXT; |
| 3782 | } |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 3783 | return(ret); |
| 3784 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3785 | if ((RAW == '(') || (RAW == '|')) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3786 | ret = cur = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_PCDATA); |
| 3787 | if (ret == NULL) return(NULL); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3788 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3789 | while (RAW == '|') { |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3790 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3791 | if (elem == NULL) { |
| 3792 | ret = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR); |
| 3793 | if (ret == NULL) return(NULL); |
| 3794 | ret->c1 = cur; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3795 | cur = ret; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3796 | } else { |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3797 | n = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR); |
| 3798 | if (n == NULL) return(NULL); |
| 3799 | n->c1 = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); |
| 3800 | cur->c2 = n; |
| 3801 | cur = n; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3802 | xmlFree(elem); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3803 | } |
| 3804 | SKIP_BLANKS; |
| 3805 | elem = xmlParseName(ctxt); |
| 3806 | if (elem == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3807 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3808 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3809 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3810 | "xmlParseElementMixedContentDecl : Name expected\n"); |
| 3811 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3812 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3813 | xmlFreeElementContent(cur); |
| 3814 | return(NULL); |
| 3815 | } |
| 3816 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3817 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3818 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3819 | if ((RAW == ')') && (NXT(1) == '*')) { |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3820 | if (elem != NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3821 | cur->c2 = xmlNewElementContent(elem, |
| 3822 | XML_ELEMENT_CONTENT_ELEMENT); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3823 | xmlFree(elem); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3824 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3825 | ret->ocur = XML_ELEMENT_CONTENT_MULT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3826 | ctxt->entity = ctxt->input; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3827 | SKIP(2); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3828 | } else { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3829 | if (elem != NULL) xmlFree(elem); |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3830 | xmlFreeElementContent(ret); |
| 3831 | ctxt->errNo = XML_ERR_MIXED_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3832 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3833 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 3834 | "xmlParseElementMixedContentDecl : '|' or ')*' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3835 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3836 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3837 | return(NULL); |
| 3838 | } |
| 3839 | |
| 3840 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3841 | ctxt->errNo = XML_ERR_PCDATA_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3842 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3843 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3844 | "xmlParseElementMixedContentDecl : '#PCDATA' expected\n"); |
| 3845 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3846 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3847 | } |
| 3848 | return(ret); |
| 3849 | } |
| 3850 | |
| 3851 | /** |
| 3852 | * xmlParseElementChildrenContentDecl: |
| 3853 | * @ctxt: an XML parser context |
| 3854 | * |
| 3855 | * parse the declaration for a Mixed Element content |
| 3856 | * The leading '(' and spaces have been skipped in xmlParseElementContentDecl |
| 3857 | * |
| 3858 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3859 | * [47] children ::= (choice | seq) ('?' | '*' | '+')? |
| 3860 | * |
| 3861 | * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? |
| 3862 | * |
| 3863 | * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')' |
| 3864 | * |
| 3865 | * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' |
| 3866 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3867 | * [ VC: Proper Group/PE Nesting ] applies to [49] and [50] |
| 3868 | * TODO Parameter-entity replacement text must be properly nested |
| 3869 | * with parenthetized groups. That is to say, if either of the |
| 3870 | * opening or closing parentheses in a choice, seq, or Mixed |
| 3871 | * construct is contained in the replacement text for a parameter |
| 3872 | * entity, both must be contained in the same replacement text. For |
| 3873 | * interoperability, if a parameter-entity reference appears in a |
| 3874 | * choice, seq, or Mixed construct, its replacement text should not |
| 3875 | * be empty, and neither the first nor last non-blank character of |
| 3876 | * the replacement text should be a connector (| or ,). |
| 3877 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3878 | * returns: the tree of xmlElementContentPtr describing the element |
| 3879 | * hierarchy. |
| 3880 | */ |
| 3881 | xmlElementContentPtr |
| 3882 | xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { |
| 3883 | xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3884 | xmlChar *elem; |
| 3885 | xmlChar type = 0; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3886 | |
| 3887 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3888 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3889 | if (RAW == '(') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3890 | /* Recurse on first child */ |
| 3891 | NEXT; |
| 3892 | SKIP_BLANKS; |
| 3893 | cur = ret = xmlParseElementChildrenContentDecl(ctxt); |
| 3894 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3895 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3896 | } else { |
| 3897 | elem = xmlParseName(ctxt); |
| 3898 | if (elem == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3899 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3900 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3901 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3902 | "xmlParseElementChildrenContentDecl : Name or '(' expected\n"); |
| 3903 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3904 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3905 | return(NULL); |
| 3906 | } |
| 3907 | cur = ret = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3908 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3909 | if (RAW == '?') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3910 | cur->ocur = XML_ELEMENT_CONTENT_OPT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3911 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3912 | } else if (RAW == '*') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3913 | cur->ocur = XML_ELEMENT_CONTENT_MULT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3914 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3915 | } else if (RAW == '+') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3916 | cur->ocur = XML_ELEMENT_CONTENT_PLUS; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3917 | NEXT; |
| 3918 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3919 | cur->ocur = XML_ELEMENT_CONTENT_ONCE; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3920 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3921 | xmlFree(elem); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3922 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3923 | } |
| 3924 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 3925 | SHRINK; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3926 | while (RAW != ')') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3927 | /* |
| 3928 | * Each loop we parse one separator and one element. |
| 3929 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3930 | if (RAW == ',') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3931 | if (type == 0) type = CUR; |
| 3932 | |
| 3933 | /* |
| 3934 | * Detect "Name | Name , Name" error |
| 3935 | */ |
| 3936 | else if (type != CUR) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3937 | ctxt->errNo = XML_ERR_SEPARATOR_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3938 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3939 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3940 | "xmlParseElementChildrenContentDecl : '%c' expected\n", |
| 3941 | type); |
| 3942 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3943 | ctxt->disableSAX = 1; |
| 3944 | if ((op != NULL) && (op != ret)) |
| 3945 | xmlFreeElementContent(op); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 3946 | if ((last != NULL) && (last != ret) && |
| 3947 | (last != ret->c1) && (last != ret->c2)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3948 | xmlFreeElementContent(last); |
| 3949 | if (ret != NULL) |
| 3950 | xmlFreeElementContent(ret); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3951 | return(NULL); |
| 3952 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3953 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3954 | |
| 3955 | op = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_SEQ); |
| 3956 | if (op == NULL) { |
| 3957 | xmlFreeElementContent(ret); |
| 3958 | return(NULL); |
| 3959 | } |
| 3960 | if (last == NULL) { |
| 3961 | op->c1 = ret; |
| 3962 | ret = cur = op; |
| 3963 | } else { |
| 3964 | cur->c2 = op; |
| 3965 | op->c1 = last; |
| 3966 | cur =op; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3967 | last = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3968 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3969 | } else if (RAW == '|') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3970 | if (type == 0) type = CUR; |
| 3971 | |
| 3972 | /* |
| 3973 | * Detect "Name , Name | Name" error |
| 3974 | */ |
| 3975 | else if (type != CUR) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 3976 | ctxt->errNo = XML_ERR_SEPARATOR_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3977 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 3978 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3979 | "xmlParseElementChildrenContentDecl : '%c' expected\n", |
| 3980 | type); |
| 3981 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3982 | ctxt->disableSAX = 1; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 3983 | if ((op != NULL) && (op != ret) && (op != last)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3984 | xmlFreeElementContent(op); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 3985 | if ((last != NULL) && (last != ret) && |
| 3986 | (last != ret->c1) && (last != ret->c2)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3987 | xmlFreeElementContent(last); |
| 3988 | if (ret != NULL) |
| 3989 | xmlFreeElementContent(ret); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3990 | return(NULL); |
| 3991 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 3992 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3993 | |
| 3994 | op = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR); |
| 3995 | if (op == NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 3996 | if ((op != NULL) && (op != ret)) |
| 3997 | xmlFreeElementContent(op); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 3998 | if ((last != NULL) && (last != ret) && |
| 3999 | (last != ret->c1) && (last != ret->c2)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4000 | xmlFreeElementContent(last); |
| 4001 | if (ret != NULL) |
| 4002 | xmlFreeElementContent(ret); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4003 | return(NULL); |
| 4004 | } |
| 4005 | if (last == NULL) { |
| 4006 | op->c1 = ret; |
| 4007 | ret = cur = op; |
| 4008 | } else { |
| 4009 | cur->c2 = op; |
| 4010 | op->c1 = last; |
| 4011 | cur =op; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 4012 | last = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4013 | } |
| 4014 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4015 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_FINISHED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4016 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4017 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4018 | "xmlParseElementChildrenContentDecl : ',' '|' or ')' expected\n"); |
| 4019 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4020 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4021 | if ((op != NULL) && (op != ret)) |
| 4022 | xmlFreeElementContent(op); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 4023 | if ((last != NULL) && (last != ret) && |
| 4024 | (last != ret->c1) && (last != ret->c2)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4025 | xmlFreeElementContent(last); |
| 4026 | if (ret != NULL) |
| 4027 | xmlFreeElementContent(ret); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4028 | return(NULL); |
| 4029 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4030 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4031 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4032 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4033 | if (RAW == '(') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4034 | /* Recurse on second child */ |
| 4035 | NEXT; |
| 4036 | SKIP_BLANKS; |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 4037 | last = xmlParseElementChildrenContentDecl(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4038 | SKIP_BLANKS; |
| 4039 | } else { |
| 4040 | elem = xmlParseName(ctxt); |
| 4041 | if (elem == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4042 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4043 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4044 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4045 | "xmlParseElementChildrenContentDecl : Name or '(' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4046 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4047 | ctxt->disableSAX = 1; |
| 4048 | if ((op != NULL) && (op != ret)) |
| 4049 | xmlFreeElementContent(op); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 4050 | if ((last != NULL) && (last != ret) && |
| 4051 | (last != ret->c1) && (last != ret->c2)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4052 | xmlFreeElementContent(last); |
| 4053 | if (ret != NULL) |
| 4054 | xmlFreeElementContent(ret); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4055 | return(NULL); |
| 4056 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 4057 | last = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4058 | xmlFree(elem); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4059 | if (RAW == '?') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4060 | last->ocur = XML_ELEMENT_CONTENT_OPT; |
| 4061 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4062 | } else if (RAW == '*') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4063 | last->ocur = XML_ELEMENT_CONTENT_MULT; |
| 4064 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4065 | } else if (RAW == '+') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4066 | last->ocur = XML_ELEMENT_CONTENT_PLUS; |
| 4067 | NEXT; |
| 4068 | } else { |
| 4069 | last->ocur = XML_ELEMENT_CONTENT_ONCE; |
| 4070 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4071 | } |
| 4072 | SKIP_BLANKS; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4073 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4074 | } |
Daniel Veillard | 1899e85 | 1999-02-01 12:18:54 +0000 | [diff] [blame] | 4075 | if ((cur != NULL) && (last != NULL)) { |
| 4076 | cur->c2 = last; |
| 4077 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4078 | ctxt->entity = ctxt->input; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4079 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4080 | if (RAW == '?') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4081 | ret->ocur = XML_ELEMENT_CONTENT_OPT; |
| 4082 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4083 | } else if (RAW == '*') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4084 | ret->ocur = XML_ELEMENT_CONTENT_MULT; |
| 4085 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4086 | } else if (RAW == '+') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4087 | ret->ocur = XML_ELEMENT_CONTENT_PLUS; |
| 4088 | NEXT; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4089 | } |
| 4090 | return(ret); |
| 4091 | } |
| 4092 | |
| 4093 | /** |
| 4094 | * xmlParseElementContentDecl: |
| 4095 | * @ctxt: an XML parser context |
| 4096 | * @name: the name of the element being defined. |
| 4097 | * @result: the Element Content pointer will be stored here if any |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4098 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4099 | * parse the declaration for an Element content either Mixed or Children, |
| 4100 | * the cases EMPTY and ANY are handled directly in xmlParseElementDecl |
| 4101 | * |
| 4102 | * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4103 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4104 | * returns: the type of element content XML_ELEMENT_TYPE_xxx |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4105 | */ |
| 4106 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4107 | int |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4108 | xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, xmlChar *name, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4109 | xmlElementContentPtr *result) { |
| 4110 | |
| 4111 | xmlElementContentPtr tree = NULL; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4112 | xmlParserInputPtr input = ctxt->input; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4113 | int res; |
| 4114 | |
| 4115 | *result = NULL; |
| 4116 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4117 | if (RAW != '(') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4118 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4119 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4120 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4121 | "xmlParseElementContentDecl : '(' expected\n"); |
| 4122 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4123 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4124 | return(-1); |
| 4125 | } |
| 4126 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4127 | GROW; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4128 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4129 | if ((RAW == '#') && (NXT(1) == 'P') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4130 | (NXT(2) == 'C') && (NXT(3) == 'D') && |
| 4131 | (NXT(4) == 'A') && (NXT(5) == 'T') && |
| 4132 | (NXT(6) == 'A')) { |
| 4133 | tree = xmlParseElementMixedContentDecl(ctxt); |
| 4134 | res = XML_ELEMENT_TYPE_MIXED; |
| 4135 | } else { |
| 4136 | tree = xmlParseElementChildrenContentDecl(ctxt); |
| 4137 | res = XML_ELEMENT_TYPE_ELEMENT; |
| 4138 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4139 | if ((ctxt->entity != NULL) && (input != ctxt->entity)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4140 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4141 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4142 | ctxt->sax->error(ctxt->userData, |
| 4143 | "Element content declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4144 | ctxt->wellFormed = 0; |
| 4145 | ctxt->disableSAX = 1; |
| 4146 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4147 | SKIP_BLANKS; |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 4148 | *result = tree; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4149 | return(res); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4150 | } |
| 4151 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4152 | /** |
| 4153 | * xmlParseElementDecl: |
| 4154 | * @ctxt: an XML parser context |
| 4155 | * |
| 4156 | * parse an Element declaration. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4157 | * |
| 4158 | * [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>' |
| 4159 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4160 | * [ VC: Unique Element Type Declaration ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4161 | * No element type may be declared more than once |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4162 | * |
| 4163 | * Returns the type of the element, or -1 in case of error |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4164 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4165 | int |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4166 | xmlParseElementDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4167 | xmlChar *name; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4168 | int ret = -1; |
| 4169 | xmlElementContentPtr content = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4170 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4171 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4172 | if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4173 | (NXT(2) == 'E') && (NXT(3) == 'L') && |
| 4174 | (NXT(4) == 'E') && (NXT(5) == 'M') && |
| 4175 | (NXT(6) == 'E') && (NXT(7) == 'N') && |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4176 | (NXT(8) == 'T')) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4177 | xmlParserInputPtr input = ctxt->input; |
| 4178 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4179 | SKIP(9); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4180 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4181 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4182 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4183 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4184 | "Space required after 'ELEMENT'\n"); |
| 4185 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4186 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4187 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4188 | SKIP_BLANKS; |
| 4189 | name = xmlParseName(ctxt); |
| 4190 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4191 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4192 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4193 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4194 | "xmlParseElementDecl: no name for Element\n"); |
| 4195 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4196 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4197 | return(-1); |
| 4198 | } |
| 4199 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4200 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4201 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4202 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4203 | "Space required after the element name\n"); |
| 4204 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4205 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4206 | } |
| 4207 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4208 | if ((RAW == 'E') && (NXT(1) == 'M') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4209 | (NXT(2) == 'P') && (NXT(3) == 'T') && |
| 4210 | (NXT(4) == 'Y')) { |
| 4211 | SKIP(5); |
| 4212 | /* |
| 4213 | * Element must always be empty. |
| 4214 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4215 | ret = XML_ELEMENT_TYPE_EMPTY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4216 | } else if ((RAW == 'A') && (NXT(1) == 'N') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4217 | (NXT(2) == 'Y')) { |
| 4218 | SKIP(3); |
| 4219 | /* |
| 4220 | * Element is a generic container. |
| 4221 | */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4222 | ret = XML_ELEMENT_TYPE_ANY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4223 | } else if (RAW == '(') { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4224 | ret = xmlParseElementContentDecl(ctxt, name, &content); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4225 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4226 | /* |
| 4227 | * [ WFC: PEs in Internal Subset ] error handling. |
| 4228 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4229 | if ((RAW == '%') && (ctxt->external == 0) && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4230 | (ctxt->inputNr == 1)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4231 | ctxt->errNo = XML_ERR_PEREF_IN_INT_SUBSET; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4232 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4233 | ctxt->sax->error(ctxt->userData, |
| 4234 | "PEReference: forbidden within markup decl in internal subset\n"); |
| 4235 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4236 | ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4237 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4238 | ctxt->sax->error(ctxt->userData, |
| 4239 | "xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected\n"); |
| 4240 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4241 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4242 | ctxt->disableSAX = 1; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4243 | if (name != NULL) xmlFree(name); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4244 | return(-1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4245 | } |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 4246 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4247 | SKIP_BLANKS; |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 4248 | /* |
| 4249 | * Pop-up of finished entities. |
| 4250 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4251 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 4252 | xmlPopInput(ctxt); |
| 4253 | SKIP_BLANKS; |
| 4254 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4255 | if (RAW != '>') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4256 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4257 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 4258 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4259 | "xmlParseElementDecl: expected '>' at the end\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4260 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4261 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4262 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4263 | if (input != ctxt->input) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4264 | ctxt->errNo = XML_ERR_ENTITY_BOUNDARY; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4265 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4266 | ctxt->sax->error(ctxt->userData, |
| 4267 | "Element declaration doesn't start and stop in the same entity\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4268 | ctxt->wellFormed = 0; |
| 4269 | ctxt->disableSAX = 1; |
| 4270 | } |
| 4271 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4272 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4273 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
| 4274 | (ctxt->sax->elementDecl != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4275 | ctxt->sax->elementDecl(ctxt->userData, name, ret, |
| 4276 | content); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4277 | } |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 4278 | if (content != NULL) { |
| 4279 | xmlFreeElementContent(content); |
| 4280 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4281 | if (name != NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 4282 | xmlFree(name); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4283 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4284 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4285 | return(ret); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4288 | /** |
| 4289 | * xmlParseMarkupDecl: |
| 4290 | * @ctxt: an XML parser context |
| 4291 | * |
| 4292 | * parse Markup declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4293 | * |
| 4294 | * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | |
| 4295 | * NotationDecl | PI | Comment |
| 4296 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4297 | * [ VC: Proper Declaration/PE Nesting ] |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 4298 | * Parameter-entity replacement text must be properly nested with |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4299 | * markup declarations. That is to say, if either the first character |
| 4300 | * or the last character of a markup declaration (markupdecl above) is |
| 4301 | * contained in the replacement text for a parameter-entity reference, |
| 4302 | * both must be contained in the same replacement text. |
| 4303 | * |
| 4304 | * [ WFC: PEs in Internal Subset ] |
| 4305 | * In the internal DTD subset, parameter-entity references can occur |
| 4306 | * only where markup declarations can occur, not within markup declarations. |
| 4307 | * (This does not apply to references that occur in external parameter |
| 4308 | * entities or to the external subset.) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4309 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4310 | void |
| 4311 | xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4312 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4313 | xmlParseElementDecl(ctxt); |
| 4314 | xmlParseAttributeListDecl(ctxt); |
| 4315 | xmlParseEntityDecl(ctxt); |
| 4316 | xmlParseNotationDecl(ctxt); |
| 4317 | xmlParsePI(ctxt); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4318 | xmlParseComment(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4319 | /* |
| 4320 | * This is only for internal subset. On external entities, |
| 4321 | * the replacement is done before parsing stage |
| 4322 | */ |
| 4323 | if ((ctxt->external == 0) && (ctxt->inputNr == 1)) |
| 4324 | xmlParsePEReference(ctxt); |
| 4325 | ctxt->instate = XML_PARSER_DTD; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4326 | } |
| 4327 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4328 | /** |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4329 | * xmlParseTextDecl: |
| 4330 | * @ctxt: an XML parser context |
| 4331 | * |
| 4332 | * parse an XML declaration header for external entities |
| 4333 | * |
| 4334 | * [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>' |
| 4335 | * |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4336 | * Question: Seems that EncodingDecl is mandatory ? Is that a typo ? |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4337 | */ |
| 4338 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4339 | void |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4340 | xmlParseTextDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4341 | xmlChar *version; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4342 | |
| 4343 | /* |
| 4344 | * We know that '<?xml' is here. |
| 4345 | */ |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 4346 | if ((RAW == '<') && (NXT(1) == '?') && |
| 4347 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 4348 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 4349 | SKIP(5); |
| 4350 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4351 | ctxt->errNo = XML_ERR_XMLDECL_NOT_STARTED; |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 4352 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4353 | ctxt->sax->error(ctxt->userData, |
| 4354 | "Text declaration '<?xml' required\n"); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 4355 | ctxt->wellFormed = 0; |
| 4356 | ctxt->disableSAX = 1; |
| 4357 | |
| 4358 | return; |
| 4359 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4360 | |
| 4361 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4362 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4363 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4364 | ctxt->sax->error(ctxt->userData, |
| 4365 | "Space needed after '<?xml'\n"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4366 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4367 | ctxt->disableSAX = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4368 | } |
| 4369 | SKIP_BLANKS; |
| 4370 | |
| 4371 | /* |
| 4372 | * We may have the VersionInfo here. |
| 4373 | */ |
| 4374 | version = xmlParseVersionInfo(ctxt); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4375 | if (version == NULL) |
| 4376 | version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4377 | ctxt->input->version = version; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4378 | |
| 4379 | /* |
| 4380 | * We must have the encoding declaration |
| 4381 | */ |
| 4382 | if (!IS_BLANK(CUR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4383 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4384 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4385 | ctxt->sax->error(ctxt->userData, "Space needed here\n"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4386 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4387 | ctxt->disableSAX = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4388 | } |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 4389 | xmlParseEncodingDecl(ctxt); |
| 4390 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 4391 | /* |
| 4392 | * The XML REC instructs us to stop parsing right here |
| 4393 | */ |
| 4394 | return; |
| 4395 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4396 | |
| 4397 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4398 | if ((RAW == '?') && (NXT(1) == '>')) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4399 | SKIP(2); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4400 | } else if (RAW == '>') { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4401 | /* Deprecated old WD ... */ |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4402 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4403 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4404 | ctxt->sax->error(ctxt->userData, |
| 4405 | "XML declaration must end-up with '?>'\n"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4406 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4407 | ctxt->disableSAX = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4408 | NEXT; |
| 4409 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4410 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4411 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 4412 | ctxt->sax->error(ctxt->userData, |
| 4413 | "parsing XML declaration: '?>' expected\n"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4414 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4415 | ctxt->disableSAX = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4416 | MOVETO_ENDTAG(CUR_PTR); |
| 4417 | NEXT; |
| 4418 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | /* |
| 4422 | * xmlParseConditionalSections |
| 4423 | * @ctxt: an XML parser context |
| 4424 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4425 | * [61] conditionalSect ::= includeSect | ignoreSect |
| 4426 | * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' |
| 4427 | * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' |
| 4428 | * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* |
| 4429 | * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*) |
| 4430 | */ |
| 4431 | |
| 4432 | void |
| 4433 | xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4434 | SKIP(3); |
| 4435 | SKIP_BLANKS; |
| 4436 | if ((RAW == 'I') && (NXT(1) == 'N') && (NXT(2) == 'C') && |
| 4437 | (NXT(3) == 'L') && (NXT(4) == 'U') && (NXT(5) == 'D') && |
| 4438 | (NXT(6) == 'E')) { |
| 4439 | SKIP(7); |
| 4440 | SKIP_BLANKS; |
| 4441 | if (RAW != '[') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4442 | ctxt->errNo = XML_ERR_CONDSEC_INVALID; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4443 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4444 | ctxt->sax->error(ctxt->userData, |
| 4445 | "XML conditional section '[' expected\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4446 | ctxt->wellFormed = 0; |
| 4447 | ctxt->disableSAX = 1; |
| 4448 | } else { |
| 4449 | NEXT; |
| 4450 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4451 | if (xmlParserDebugEntities) { |
| 4452 | if ((ctxt->input != NULL) && (ctxt->input->filename)) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4453 | xmlGenericError(xmlGenericErrorContext, |
| 4454 | "%s(%d): ", ctxt->input->filename, |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4455 | ctxt->input->line); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4456 | xmlGenericError(xmlGenericErrorContext, |
| 4457 | "Entering INCLUDE Conditional Section\n"); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4460 | while ((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') || |
| 4461 | (NXT(2) != '>'))) { |
| 4462 | const xmlChar *check = CUR_PTR; |
| 4463 | int cons = ctxt->input->consumed; |
| 4464 | int tok = ctxt->token; |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 4465 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4466 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { |
| 4467 | xmlParseConditionalSections(ctxt); |
| 4468 | } else if (IS_BLANK(CUR)) { |
| 4469 | NEXT; |
| 4470 | } else if (RAW == '%') { |
| 4471 | xmlParsePEReference(ctxt); |
| 4472 | } else |
| 4473 | xmlParseMarkupDecl(ctxt); |
| 4474 | |
| 4475 | /* |
| 4476 | * Pop-up of finished entities. |
| 4477 | */ |
| 4478 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
| 4479 | xmlPopInput(ctxt); |
| 4480 | |
| 4481 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed) && |
| 4482 | (tok == ctxt->token)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4483 | ctxt->errNo = XML_ERR_EXT_SUBSET_NOT_FINISHED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4484 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4485 | ctxt->sax->error(ctxt->userData, |
| 4486 | "Content error in the external subset\n"); |
| 4487 | ctxt->wellFormed = 0; |
| 4488 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4489 | break; |
| 4490 | } |
| 4491 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4492 | if (xmlParserDebugEntities) { |
| 4493 | if ((ctxt->input != NULL) && (ctxt->input->filename)) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4494 | xmlGenericError(xmlGenericErrorContext, |
| 4495 | "%s(%d): ", ctxt->input->filename, |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4496 | ctxt->input->line); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4497 | xmlGenericError(xmlGenericErrorContext, |
| 4498 | "Leaving INCLUDE Conditional Section\n"); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4499 | } |
| 4500 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4501 | } else if ((RAW == 'I') && (NXT(1) == 'G') && (NXT(2) == 'N') && |
| 4502 | (NXT(3) == 'O') && (NXT(4) == 'R') && (NXT(5) == 'E')) { |
| 4503 | int state; |
| 4504 | |
| 4505 | SKIP(6); |
| 4506 | SKIP_BLANKS; |
| 4507 | if (RAW != '[') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4508 | ctxt->errNo = XML_ERR_CONDSEC_INVALID; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4509 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4510 | ctxt->sax->error(ctxt->userData, |
| 4511 | "XML conditional section '[' expected\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4512 | ctxt->wellFormed = 0; |
| 4513 | ctxt->disableSAX = 1; |
| 4514 | } else { |
| 4515 | NEXT; |
| 4516 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4517 | if (xmlParserDebugEntities) { |
| 4518 | if ((ctxt->input != NULL) && (ctxt->input->filename)) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4519 | xmlGenericError(xmlGenericErrorContext, |
| 4520 | "%s(%d): ", ctxt->input->filename, |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4521 | ctxt->input->line); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4522 | xmlGenericError(xmlGenericErrorContext, |
| 4523 | "Entering IGNORE Conditional Section\n"); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4524 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4525 | |
| 4526 | /* |
| 4527 | * Parse up to the end of the conditionnal section |
| 4528 | * But disable SAX event generating DTD building in the meantime |
| 4529 | */ |
| 4530 | state = ctxt->disableSAX; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4531 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4532 | while ((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') || |
| 4533 | (NXT(2) != '>'))) { |
| 4534 | const xmlChar *check = CUR_PTR; |
| 4535 | int cons = ctxt->input->consumed; |
| 4536 | int tok = ctxt->token; |
| 4537 | |
| 4538 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { |
| 4539 | xmlParseConditionalSections(ctxt); |
| 4540 | } else if (IS_BLANK(CUR)) { |
| 4541 | NEXT; |
| 4542 | } else if (RAW == '%') { |
| 4543 | xmlParsePEReference(ctxt); |
| 4544 | } else |
| 4545 | xmlParseMarkupDecl(ctxt); |
| 4546 | |
| 4547 | /* |
| 4548 | * Pop-up of finished entities. |
| 4549 | */ |
| 4550 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
| 4551 | xmlPopInput(ctxt); |
| 4552 | |
| 4553 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed) && |
| 4554 | (tok == ctxt->token)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4555 | ctxt->errNo = XML_ERR_EXT_SUBSET_NOT_FINISHED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4556 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4557 | ctxt->sax->error(ctxt->userData, |
| 4558 | "Content error in the external subset\n"); |
| 4559 | ctxt->wellFormed = 0; |
| 4560 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | ctxt->disableSAX = state; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4565 | if (xmlParserDebugEntities) { |
| 4566 | if ((ctxt->input != NULL) && (ctxt->input->filename)) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4567 | xmlGenericError(xmlGenericErrorContext, |
| 4568 | "%s(%d): ", ctxt->input->filename, |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4569 | ctxt->input->line); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 4570 | xmlGenericError(xmlGenericErrorContext, |
| 4571 | "Leaving IGNORE Conditional Section\n"); |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4572 | } |
| 4573 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4574 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4575 | ctxt->errNo = XML_ERR_CONDSEC_INVALID; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4576 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4577 | ctxt->sax->error(ctxt->userData, |
| 4578 | "XML conditional section INCLUDE or IGNORE keyword expected\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4579 | ctxt->wellFormed = 0; |
| 4580 | ctxt->disableSAX = 1; |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4583 | if (RAW == 0) |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 4584 | SHRINK; |
| 4585 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4586 | if (RAW == 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4587 | ctxt->errNo = XML_ERR_CONDSEC_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4588 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4589 | ctxt->sax->error(ctxt->userData, |
| 4590 | "XML conditional section not closed\n"); |
| 4591 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4592 | ctxt->disableSAX = 1; |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 4593 | } else { |
| 4594 | SKIP(3); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | |
| 4598 | /** |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 4599 | * xmlParseExternalSubset: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4600 | * @ctxt: an XML parser context |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 4601 | * @ExternalID: the external identifier |
| 4602 | * @SystemID: the system identifier (or URL) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4603 | * |
| 4604 | * parse Markup declarations from an external subset |
| 4605 | * |
| 4606 | * [30] extSubset ::= textDecl? extSubsetDecl |
| 4607 | * |
| 4608 | * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4609 | */ |
| 4610 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4611 | xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, |
| 4612 | const xmlChar *SystemID) { |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 4613 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4614 | if ((RAW == '<') && (NXT(1) == '?') && |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4615 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 4616 | (NXT(4) == 'l')) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4617 | xmlParseTextDecl(ctxt); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 4618 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 4619 | /* |
| 4620 | * The XML REC instructs us to stop parsing right here |
| 4621 | */ |
| 4622 | ctxt->instate = XML_PARSER_EOF; |
| 4623 | return; |
| 4624 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4625 | } |
| 4626 | if (ctxt->myDoc == NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4627 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4628 | } |
| 4629 | if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL)) |
| 4630 | xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID); |
| 4631 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4632 | ctxt->instate = XML_PARSER_DTD; |
| 4633 | ctxt->external = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4634 | while (((RAW == '<') && (NXT(1) == '?')) || |
| 4635 | ((RAW == '<') && (NXT(1) == '!')) || |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4636 | IS_BLANK(CUR)) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4637 | const xmlChar *check = CUR_PTR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4638 | int cons = ctxt->input->consumed; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4639 | int tok = ctxt->token; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4640 | |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 4641 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4642 | if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4643 | xmlParseConditionalSections(ctxt); |
| 4644 | } else if (IS_BLANK(CUR)) { |
| 4645 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4646 | } else if (RAW == '%') { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4647 | xmlParsePEReference(ctxt); |
| 4648 | } else |
| 4649 | xmlParseMarkupDecl(ctxt); |
| 4650 | |
| 4651 | /* |
| 4652 | * Pop-up of finished entities. |
| 4653 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4654 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4655 | xmlPopInput(ctxt); |
| 4656 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4657 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed) && |
| 4658 | (tok == ctxt->token)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4659 | ctxt->errNo = XML_ERR_EXT_SUBSET_NOT_FINISHED; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4660 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4661 | ctxt->sax->error(ctxt->userData, |
| 4662 | "Content error in the external subset\n"); |
| 4663 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4664 | ctxt->disableSAX = 1; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4665 | break; |
| 4666 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4669 | if (RAW != 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4670 | ctxt->errNo = XML_ERR_EXT_SUBSET_NOT_FINISHED; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4671 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4672 | ctxt->sax->error(ctxt->userData, |
| 4673 | "Extra content at the end of the document\n"); |
| 4674 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4675 | ctxt->disableSAX = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | } |
| 4679 | |
| 4680 | /** |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4681 | * xmlParseReference: |
| 4682 | * @ctxt: an XML parser context |
| 4683 | * |
| 4684 | * parse and handle entity references in content, depending on the SAX |
| 4685 | * interface, this may end-up in a call to character() if this is a |
| 4686 | * CharRef, a predefined entity, if there is no reference() callback. |
| 4687 | * or if the parser was asked to switch to that mode. |
| 4688 | * |
| 4689 | * [67] Reference ::= EntityRef | CharRef |
| 4690 | */ |
| 4691 | void |
| 4692 | xmlParseReference(xmlParserCtxtPtr ctxt) { |
| 4693 | xmlEntityPtr ent; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4694 | xmlChar *val; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4695 | if (RAW != '&') return; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4696 | |
| 4697 | if (NXT(1) == '#') { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4698 | int i = 0; |
| 4699 | xmlChar out[10]; |
| 4700 | int hex = NXT(2); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4701 | int val = xmlParseCharRef(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4702 | |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 4703 | if (ctxt->charset != XML_CHAR_ENCODING_UTF8) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4704 | /* |
| 4705 | * So we are using non-UTF-8 buffers |
| 4706 | * Check that the char fit on 8bits, if not |
| 4707 | * generate a CharRef. |
| 4708 | */ |
| 4709 | if (val <= 0xFF) { |
| 4710 | out[0] = val; |
| 4711 | out[1] = 0; |
| 4712 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && |
| 4713 | (!ctxt->disableSAX)) |
| 4714 | ctxt->sax->characters(ctxt->userData, out, 1); |
| 4715 | } else { |
| 4716 | if ((hex == 'x') || (hex == 'X')) |
| 4717 | sprintf((char *)out, "#x%X", val); |
| 4718 | else |
| 4719 | sprintf((char *)out, "#%d", val); |
| 4720 | if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) && |
| 4721 | (!ctxt->disableSAX)) |
| 4722 | ctxt->sax->reference(ctxt->userData, out); |
| 4723 | } |
| 4724 | } else { |
| 4725 | /* |
| 4726 | * Just encode the value in UTF-8 |
| 4727 | */ |
| 4728 | COPY_BUF(0 ,out, i, val); |
| 4729 | out[i] = 0; |
| 4730 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && |
| 4731 | (!ctxt->disableSAX)) |
| 4732 | ctxt->sax->characters(ctxt->userData, out, i); |
| 4733 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4734 | } else { |
| 4735 | ent = xmlParseEntityRef(ctxt); |
| 4736 | if (ent == NULL) return; |
| 4737 | if ((ent->name != NULL) && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4738 | (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY)) { |
| 4739 | xmlNodePtr list = NULL; |
| 4740 | int ret; |
| 4741 | |
| 4742 | |
| 4743 | /* |
| 4744 | * The first reference to the entity trigger a parsing phase |
| 4745 | * where the ent->children is filled with the result from |
| 4746 | * the parsing. |
| 4747 | */ |
| 4748 | if (ent->children == NULL) { |
| 4749 | xmlChar *value; |
| 4750 | value = ent->content; |
| 4751 | |
| 4752 | /* |
| 4753 | * Check that this entity is well formed |
| 4754 | */ |
| 4755 | if ((value != NULL) && |
| 4756 | (value[1] == 0) && (value[0] == '<') && |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 4757 | (xmlStrEqual(ent->name, BAD_CAST "lt"))) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4758 | /* |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4759 | * DONE: get definite answer on this !!! |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4760 | * Lots of entity decls are used to declare a single |
| 4761 | * char |
| 4762 | * <!ENTITY lt "<"> |
| 4763 | * Which seems to be valid since |
| 4764 | * 2.4: The ampersand character (&) and the left angle |
| 4765 | * bracket (<) may appear in their literal form only |
| 4766 | * when used ... They are also legal within the literal |
| 4767 | * entity value of an internal entity declaration;i |
| 4768 | * see "4.3.2 Well-Formed Parsed Entities". |
| 4769 | * IMHO 2.4 and 4.3.2 are directly in contradiction. |
| 4770 | * Looking at the OASIS test suite and James Clark |
| 4771 | * tests, this is broken. However the XML REC uses |
| 4772 | * it. Is the XML REC not well-formed ???? |
| 4773 | * This is a hack to avoid this problem |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4774 | * |
| 4775 | * ANSWER: since lt gt amp .. are already defined, |
| 4776 | * this is a redefinition and hence the fact that the |
| 4777 | * contentis not well balanced is not a Wf error, this |
| 4778 | * is lousy but acceptable. |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4779 | */ |
| 4780 | list = xmlNewDocText(ctxt->myDoc, value); |
| 4781 | if (list != NULL) { |
| 4782 | if ((ent->etype == XML_INTERNAL_GENERAL_ENTITY) && |
| 4783 | (ent->children == NULL)) { |
| 4784 | ent->children = list; |
| 4785 | ent->last = list; |
| 4786 | list->parent = (xmlNodePtr) ent; |
| 4787 | } else { |
| 4788 | xmlFreeNodeList(list); |
| 4789 | } |
| 4790 | } else if (list != NULL) { |
| 4791 | xmlFreeNodeList(list); |
| 4792 | } |
| 4793 | } else { |
| 4794 | /* |
| 4795 | * 4.3.2: An internal general parsed entity is well-formed |
| 4796 | * if its replacement text matches the production labeled |
| 4797 | * content. |
| 4798 | */ |
| 4799 | if (ent->etype == XML_INTERNAL_GENERAL_ENTITY) { |
| 4800 | ctxt->depth++; |
| 4801 | ret = xmlParseBalancedChunkMemory(ctxt->myDoc, |
| 4802 | ctxt->sax, NULL, ctxt->depth, |
| 4803 | value, &list); |
| 4804 | ctxt->depth--; |
| 4805 | } else if (ent->etype == |
| 4806 | XML_EXTERNAL_GENERAL_PARSED_ENTITY) { |
| 4807 | ctxt->depth++; |
| 4808 | ret = xmlParseExternalEntity(ctxt->myDoc, |
| 4809 | ctxt->sax, NULL, ctxt->depth, |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 4810 | ent->URI, ent->ExternalID, &list); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4811 | ctxt->depth--; |
| 4812 | } else { |
| 4813 | ret = -1; |
| 4814 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4815 | ctxt->sax->error(ctxt->userData, |
| 4816 | "Internal: invalid entity type\n"); |
| 4817 | } |
| 4818 | if (ret == XML_ERR_ENTITY_LOOP) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4819 | ctxt->errNo = XML_ERR_ENTITY_LOOP; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4820 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4821 | ctxt->sax->error(ctxt->userData, |
| 4822 | "Detected entity reference loop\n"); |
| 4823 | ctxt->wellFormed = 0; |
| 4824 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4825 | } else if ((ret == 0) && (list != NULL)) { |
| 4826 | if ((ent->etype == XML_INTERNAL_GENERAL_ENTITY) && |
| 4827 | (ent->children == NULL)) { |
| 4828 | ent->children = list; |
| 4829 | while (list != NULL) { |
| 4830 | list->parent = (xmlNodePtr) ent; |
| 4831 | if (list->next == NULL) |
| 4832 | ent->last = list; |
| 4833 | list = list->next; |
| 4834 | } |
| 4835 | } else { |
| 4836 | xmlFreeNodeList(list); |
| 4837 | } |
| 4838 | } else if (ret > 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4839 | ctxt->errNo = ret; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4840 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4841 | ctxt->sax->error(ctxt->userData, |
| 4842 | "Entity value required\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4843 | ctxt->wellFormed = 0; |
| 4844 | ctxt->disableSAX = 1; |
| 4845 | } else if (list != NULL) { |
| 4846 | xmlFreeNodeList(list); |
| 4847 | } |
| 4848 | } |
| 4849 | } |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4850 | if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4851 | (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4852 | /* |
| 4853 | * Create a node. |
| 4854 | */ |
| 4855 | ctxt->sax->reference(ctxt->userData, ent->name); |
| 4856 | return; |
| 4857 | } else if (ctxt->replaceEntities) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4858 | if ((ctxt->node != NULL) && (ent->children != NULL)) { |
| 4859 | /* |
| 4860 | * Seems we are generating the DOM content, do |
| 4861 | * a simple tree copy |
| 4862 | */ |
| 4863 | xmlNodePtr new; |
| 4864 | new = xmlCopyNodeList(ent->children); |
| 4865 | |
| 4866 | xmlAddChildList(ctxt->node, new); |
| 4867 | /* |
| 4868 | * This is to avoid a nasty side effect, see |
| 4869 | * characters() in SAX.c |
| 4870 | */ |
| 4871 | ctxt->nodemem = 0; |
| 4872 | ctxt->nodelen = 0; |
| 4873 | return; |
| 4874 | } else { |
| 4875 | /* |
| 4876 | * Probably running in SAX mode |
| 4877 | */ |
| 4878 | xmlParserInputPtr input; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4879 | |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4880 | input = xmlNewEntityInputStream(ctxt, ent); |
| 4881 | xmlPushInput(ctxt, input); |
| 4882 | if ((ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) && |
| 4883 | (RAW == '<') && (NXT(1) == '?') && |
| 4884 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 4885 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 4886 | xmlParseTextDecl(ctxt); |
| 4887 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 4888 | /* |
| 4889 | * The XML REC instructs us to stop parsing right here |
| 4890 | */ |
| 4891 | ctxt->instate = XML_PARSER_EOF; |
| 4892 | return; |
| 4893 | } |
| 4894 | if (input->standalone == 1) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4895 | ctxt->errNo = XML_ERR_EXT_ENTITY_STANDALONE; |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4896 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 4897 | ctxt->sax->error(ctxt->userData, |
| 4898 | "external parsed entities cannot be standalone\n"); |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4899 | ctxt->wellFormed = 0; |
| 4900 | ctxt->disableSAX = 1; |
| 4901 | } |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 4902 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4903 | return; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4904 | } |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 4905 | } |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 4906 | } else { |
| 4907 | val = ent->content; |
| 4908 | if (val == NULL) return; |
| 4909 | /* |
| 4910 | * inline the entity. |
| 4911 | */ |
| 4912 | if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && |
| 4913 | (!ctxt->disableSAX)) |
| 4914 | ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val)); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4915 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4916 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4917 | } |
| 4918 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4919 | /** |
| 4920 | * xmlParseEntityRef: |
| 4921 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 4922 | * |
| 4923 | * parse ENTITY references declarations |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4924 | * |
| 4925 | * [68] EntityRef ::= '&' Name ';' |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 4926 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4927 | * [ WFC: Entity Declared ] |
| 4928 | * In a document without any DTD, a document with only an internal DTD |
| 4929 | * subset which contains no parameter entity references, or a document |
| 4930 | * with "standalone='yes'", the Name given in the entity reference |
| 4931 | * must match that in an entity declaration, except that well-formed |
| 4932 | * documents need not declare any of the following entities: amp, lt, |
| 4933 | * gt, apos, quot. The declaration of a parameter entity must precede |
| 4934 | * any reference to it. Similarly, the declaration of a general entity |
| 4935 | * must precede any reference to it which appears in a default value in an |
| 4936 | * attribute-list declaration. Note that if entities are declared in the |
| 4937 | * external subset or in external parameter entities, a non-validating |
| 4938 | * processor is not obligated to read and process their declarations; |
| 4939 | * for such documents, the rule that an entity must be declared is a |
| 4940 | * well-formedness constraint only if standalone='yes'. |
| 4941 | * |
| 4942 | * [ WFC: Parsed Entity ] |
| 4943 | * An entity reference must not contain the name of an unparsed entity |
| 4944 | * |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4945 | * Returns the xmlEntityPtr if found, or NULL otherwise. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4946 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4947 | xmlEntityPtr |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 4948 | xmlParseEntityRef(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 4949 | xmlChar *name; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 4950 | xmlEntityPtr ent = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4951 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 4952 | GROW; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4953 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4954 | if (RAW == '&') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4955 | NEXT; |
| 4956 | name = xmlParseName(ctxt); |
| 4957 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 4958 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 4959 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4960 | ctxt->sax->error(ctxt->userData, |
| 4961 | "xmlParseEntityRef: no name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4962 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4963 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4964 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 4965 | if (RAW == ';') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4966 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 4967 | /* |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4968 | * Ask first SAX for entity resolution, otherwise try the |
| 4969 | * predefined set. |
| 4970 | */ |
| 4971 | if (ctxt->sax != NULL) { |
| 4972 | if (ctxt->sax->getEntity != NULL) |
| 4973 | ent = ctxt->sax->getEntity(ctxt->userData, name); |
| 4974 | if (ent == NULL) |
| 4975 | ent = xmlGetPredefinedEntity(name); |
| 4976 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4977 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4978 | * [ WFC: Entity Declared ] |
| 4979 | * In a document without any DTD, a document with only an |
| 4980 | * internal DTD subset which contains no parameter entity |
| 4981 | * references, or a document with "standalone='yes'", the |
| 4982 | * Name given in the entity reference must match that in an |
| 4983 | * entity declaration, except that well-formed documents |
| 4984 | * need not declare any of the following entities: amp, lt, |
| 4985 | * gt, apos, quot. |
| 4986 | * The declaration of a parameter entity must precede any |
| 4987 | * reference to it. |
| 4988 | * Similarly, the declaration of a general entity must |
| 4989 | * precede any reference to it which appears in a default |
| 4990 | * value in an attribute-list declaration. Note that if |
| 4991 | * entities are declared in the external subset or in |
| 4992 | * external parameter entities, a non-validating processor |
| 4993 | * is not obligated to read and process their declarations; |
| 4994 | * for such documents, the rule that an entity must be |
| 4995 | * declared is a well-formedness constraint only if |
| 4996 | * standalone='yes'. |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4997 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 4998 | if (ent == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 4999 | if ((ctxt->standalone == 1) || |
| 5000 | ((ctxt->hasExternalSubset == 0) && |
| 5001 | (ctxt->hasPErefs == 0))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5002 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5003 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5004 | ctxt->sax->error(ctxt->userData, |
| 5005 | "Entity '%s' not defined\n", name); |
| 5006 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5007 | ctxt->disableSAX = 1; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5008 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5009 | ctxt->errNo = XML_WAR_UNDECLARED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5010 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 5011 | ctxt->sax->warning(ctxt->userData, |
| 5012 | "Entity '%s' not defined\n", name); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5013 | } |
| 5014 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5015 | |
| 5016 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5017 | * [ WFC: Parsed Entity ] |
| 5018 | * An entity reference must not contain the name of an |
| 5019 | * unparsed entity |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5020 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5021 | else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5022 | ctxt->errNo = XML_ERR_UNPARSED_ENTITY; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5023 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5024 | ctxt->sax->error(ctxt->userData, |
| 5025 | "Entity reference to unparsed entity %s\n", name); |
| 5026 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5027 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | /* |
| 5031 | * [ WFC: No External Entity References ] |
| 5032 | * Attribute values cannot contain direct or indirect |
| 5033 | * entity references to external entities. |
| 5034 | */ |
| 5035 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5036 | (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5037 | ctxt->errNo = XML_ERR_ENTITY_IS_EXTERNAL; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5038 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5039 | ctxt->sax->error(ctxt->userData, |
| 5040 | "Attribute references external entity '%s'\n", name); |
| 5041 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5042 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5043 | } |
| 5044 | /* |
| 5045 | * [ WFC: No < in Attribute Values ] |
| 5046 | * The replacement text of any entity referred to directly or |
| 5047 | * indirectly in an attribute value (other than "<") must |
| 5048 | * not contain a <. |
| 5049 | */ |
| 5050 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5051 | (ent != NULL) && |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 5052 | (!xmlStrEqual(ent->name, BAD_CAST "lt")) && |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5053 | (ent->content != NULL) && |
| 5054 | (xmlStrchr(ent->content, '<'))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5055 | ctxt->errNo = XML_ERR_LT_IN_ATTRIBUTE; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5056 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5057 | ctxt->sax->error(ctxt->userData, |
| 5058 | "'<' in entity '%s' is not allowed in attributes values\n", name); |
| 5059 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5060 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | /* |
| 5064 | * Internal check, no parameter entities here ... |
| 5065 | */ |
| 5066 | else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5067 | switch (ent->etype) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5068 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 5069 | case XML_EXTERNAL_PARAMETER_ENTITY: |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5070 | ctxt->errNo = XML_ERR_ENTITY_IS_PARAMETER; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5071 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5072 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5073 | "Attempt to reference the parameter entity '%s'\n", name); |
| 5074 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5075 | ctxt->disableSAX = 1; |
| 5076 | break; |
| 5077 | default: |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5078 | break; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5079 | } |
| 5080 | } |
| 5081 | |
| 5082 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5083 | * [ WFC: No Recursion ] |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5084 | * A parsed entity must not contain a recursive reference |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5085 | * to itself, either directly or indirectly. |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5086 | * Done somewhere else |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5087 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5088 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5089 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5090 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5091 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5092 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5093 | "xmlParseEntityRef: expecting ';'\n"); |
| 5094 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5095 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5096 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5097 | xmlFree(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5098 | } |
| 5099 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5100 | return(ent); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5101 | } |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5102 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5103 | /** |
| 5104 | * xmlParseStringEntityRef: |
| 5105 | * @ctxt: an XML parser context |
| 5106 | * @str: a pointer to an index in the string |
| 5107 | * |
| 5108 | * parse ENTITY references declarations, but this version parses it from |
| 5109 | * a string value. |
| 5110 | * |
| 5111 | * [68] EntityRef ::= '&' Name ';' |
| 5112 | * |
| 5113 | * [ WFC: Entity Declared ] |
| 5114 | * In a document without any DTD, a document with only an internal DTD |
| 5115 | * subset which contains no parameter entity references, or a document |
| 5116 | * with "standalone='yes'", the Name given in the entity reference |
| 5117 | * must match that in an entity declaration, except that well-formed |
| 5118 | * documents need not declare any of the following entities: amp, lt, |
| 5119 | * gt, apos, quot. The declaration of a parameter entity must precede |
| 5120 | * any reference to it. Similarly, the declaration of a general entity |
| 5121 | * must precede any reference to it which appears in a default value in an |
| 5122 | * attribute-list declaration. Note that if entities are declared in the |
| 5123 | * external subset or in external parameter entities, a non-validating |
| 5124 | * processor is not obligated to read and process their declarations; |
| 5125 | * for such documents, the rule that an entity must be declared is a |
| 5126 | * well-formedness constraint only if standalone='yes'. |
| 5127 | * |
| 5128 | * [ WFC: Parsed Entity ] |
| 5129 | * An entity reference must not contain the name of an unparsed entity |
| 5130 | * |
| 5131 | * Returns the xmlEntityPtr if found, or NULL otherwise. The str pointer |
| 5132 | * is updated to the current location in the string. |
| 5133 | */ |
| 5134 | xmlEntityPtr |
| 5135 | xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) { |
| 5136 | xmlChar *name; |
| 5137 | const xmlChar *ptr; |
| 5138 | xmlChar cur; |
| 5139 | xmlEntityPtr ent = NULL; |
| 5140 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5141 | if ((str == NULL) || (*str == NULL)) |
| 5142 | return(NULL); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5143 | ptr = *str; |
| 5144 | cur = *ptr; |
| 5145 | if (cur == '&') { |
| 5146 | ptr++; |
| 5147 | cur = *ptr; |
| 5148 | name = xmlParseStringName(ctxt, &ptr); |
| 5149 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5150 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5151 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5152 | ctxt->sax->error(ctxt->userData, |
| 5153 | "xmlParseEntityRef: no name\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5154 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5155 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5156 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5157 | if (*ptr == ';') { |
| 5158 | ptr++; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5159 | /* |
| 5160 | * Ask first SAX for entity resolution, otherwise try the |
| 5161 | * predefined set. |
| 5162 | */ |
| 5163 | if (ctxt->sax != NULL) { |
| 5164 | if (ctxt->sax->getEntity != NULL) |
| 5165 | ent = ctxt->sax->getEntity(ctxt->userData, name); |
| 5166 | if (ent == NULL) |
| 5167 | ent = xmlGetPredefinedEntity(name); |
| 5168 | } |
| 5169 | /* |
| 5170 | * [ WFC: Entity Declared ] |
| 5171 | * In a document without any DTD, a document with only an |
| 5172 | * internal DTD subset which contains no parameter entity |
| 5173 | * references, or a document with "standalone='yes'", the |
| 5174 | * Name given in the entity reference must match that in an |
| 5175 | * entity declaration, except that well-formed documents |
| 5176 | * need not declare any of the following entities: amp, lt, |
| 5177 | * gt, apos, quot. |
| 5178 | * The declaration of a parameter entity must precede any |
| 5179 | * reference to it. |
| 5180 | * Similarly, the declaration of a general entity must |
| 5181 | * precede any reference to it which appears in a default |
| 5182 | * value in an attribute-list declaration. Note that if |
| 5183 | * entities are declared in the external subset or in |
| 5184 | * external parameter entities, a non-validating processor |
| 5185 | * is not obligated to read and process their declarations; |
| 5186 | * for such documents, the rule that an entity must be |
| 5187 | * declared is a well-formedness constraint only if |
| 5188 | * standalone='yes'. |
| 5189 | */ |
| 5190 | if (ent == NULL) { |
| 5191 | if ((ctxt->standalone == 1) || |
| 5192 | ((ctxt->hasExternalSubset == 0) && |
| 5193 | (ctxt->hasPErefs == 0))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5194 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5195 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5196 | ctxt->sax->error(ctxt->userData, |
| 5197 | "Entity '%s' not defined\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5198 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5199 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5200 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5201 | ctxt->errNo = XML_WAR_UNDECLARED_ENTITY; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5202 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 5203 | ctxt->sax->warning(ctxt->userData, |
| 5204 | "Entity '%s' not defined\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5205 | } |
| 5206 | } |
| 5207 | |
| 5208 | /* |
| 5209 | * [ WFC: Parsed Entity ] |
| 5210 | * An entity reference must not contain the name of an |
| 5211 | * unparsed entity |
| 5212 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5213 | else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5214 | ctxt->errNo = XML_ERR_UNPARSED_ENTITY; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5215 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5216 | ctxt->sax->error(ctxt->userData, |
| 5217 | "Entity reference to unparsed entity %s\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5218 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5219 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | /* |
| 5223 | * [ WFC: No External Entity References ] |
| 5224 | * Attribute values cannot contain direct or indirect |
| 5225 | * entity references to external entities. |
| 5226 | */ |
| 5227 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5228 | (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5229 | ctxt->errNo = XML_ERR_ENTITY_IS_EXTERNAL; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5230 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5231 | ctxt->sax->error(ctxt->userData, |
| 5232 | "Attribute references external entity '%s'\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5233 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5234 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5235 | } |
| 5236 | /* |
| 5237 | * [ WFC: No < in Attribute Values ] |
| 5238 | * The replacement text of any entity referred to directly or |
| 5239 | * indirectly in an attribute value (other than "<") must |
| 5240 | * not contain a <. |
| 5241 | */ |
| 5242 | else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && |
| 5243 | (ent != NULL) && |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 5244 | (!xmlStrEqual(ent->name, BAD_CAST "lt")) && |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5245 | (ent->content != NULL) && |
| 5246 | (xmlStrchr(ent->content, '<'))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5247 | ctxt->errNo = XML_ERR_LT_IN_ATTRIBUTE; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5248 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5249 | ctxt->sax->error(ctxt->userData, |
| 5250 | "'<' in entity '%s' is not allowed in attributes values\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5251 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5252 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | /* |
| 5256 | * Internal check, no parameter entities here ... |
| 5257 | */ |
| 5258 | else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5259 | switch (ent->etype) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5260 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 5261 | case XML_EXTERNAL_PARAMETER_ENTITY: |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5262 | ctxt->errNo = XML_ERR_ENTITY_IS_PARAMETER; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5263 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5264 | ctxt->sax->error(ctxt->userData, |
| 5265 | "Attempt to reference the parameter entity '%s'\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5266 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5267 | ctxt->disableSAX = 1; |
| 5268 | break; |
| 5269 | default: |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5270 | break; |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | /* |
| 5275 | * [ WFC: No Recursion ] |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5276 | * A parsed entity must not contain a recursive reference |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5277 | * to itself, either directly or indirectly. |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5278 | * Done somewhwere else |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5279 | */ |
| 5280 | |
| 5281 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5282 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5283 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5284 | ctxt->sax->error(ctxt->userData, |
| 5285 | "xmlParseEntityRef: expecting ';'\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5286 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5287 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5288 | } |
| 5289 | xmlFree(name); |
| 5290 | } |
| 5291 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5292 | *str = ptr; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5293 | return(ent); |
| 5294 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5295 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5296 | /** |
| 5297 | * xmlParsePEReference: |
| 5298 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5299 | * |
| 5300 | * parse PEReference declarations |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5301 | * The entity content is handled directly by pushing it's content as |
| 5302 | * a new input stream. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5303 | * |
| 5304 | * [69] PEReference ::= '%' Name ';' |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5305 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5306 | * [ WFC: No Recursion ] |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5307 | * A parsed entity must not contain a recursive |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5308 | * reference to itself, either directly or indirectly. |
| 5309 | * |
| 5310 | * [ WFC: Entity Declared ] |
| 5311 | * In a document without any DTD, a document with only an internal DTD |
| 5312 | * subset which contains no parameter entity references, or a document |
| 5313 | * with "standalone='yes'", ... ... The declaration of a parameter |
| 5314 | * entity must precede any reference to it... |
| 5315 | * |
| 5316 | * [ VC: Entity Declared ] |
| 5317 | * In a document with an external subset or external parameter entities |
| 5318 | * with "standalone='no'", ... ... The declaration of a parameter entity |
| 5319 | * must precede any reference to it... |
| 5320 | * |
| 5321 | * [ WFC: In DTD ] |
| 5322 | * Parameter-entity references may only appear in the DTD. |
| 5323 | * NOTE: misleading but this is handled. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5324 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5325 | void |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5326 | xmlParsePEReference(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5327 | xmlChar *name; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5328 | xmlEntityPtr entity = NULL; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 5329 | xmlParserInputPtr input; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5330 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5331 | if (RAW == '%') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5332 | NEXT; |
| 5333 | name = xmlParseName(ctxt); |
| 5334 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5335 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5336 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5337 | ctxt->sax->error(ctxt->userData, |
| 5338 | "xmlParsePEReference: no name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5339 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5340 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5341 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5342 | if (RAW == ';') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5343 | NEXT; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5344 | if ((ctxt->sax != NULL) && |
| 5345 | (ctxt->sax->getParameterEntity != NULL)) |
| 5346 | entity = ctxt->sax->getParameterEntity(ctxt->userData, |
| 5347 | name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5348 | if (entity == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5349 | /* |
| 5350 | * [ WFC: Entity Declared ] |
| 5351 | * In a document without any DTD, a document with only an |
| 5352 | * internal DTD subset which contains no parameter entity |
| 5353 | * references, or a document with "standalone='yes'", ... |
| 5354 | * ... The declaration of a parameter entity must precede |
| 5355 | * any reference to it... |
| 5356 | */ |
| 5357 | if ((ctxt->standalone == 1) || |
| 5358 | ((ctxt->hasExternalSubset == 0) && |
| 5359 | (ctxt->hasPErefs == 0))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5360 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 5361 | if ((!ctxt->disableSAX) && |
| 5362 | (ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5363 | ctxt->sax->error(ctxt->userData, |
| 5364 | "PEReference: %%%s; not found\n", name); |
| 5365 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5366 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5367 | } else { |
| 5368 | /* |
| 5369 | * [ VC: Entity Declared ] |
| 5370 | * In a document with an external subset or external |
| 5371 | * parameter entities with "standalone='no'", ... |
| 5372 | * ... The declaration of a parameter entity must precede |
| 5373 | * any reference to it... |
| 5374 | */ |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 5375 | if ((!ctxt->disableSAX) && |
| 5376 | (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5377 | ctxt->sax->warning(ctxt->userData, |
| 5378 | "PEReference: %%%s; not found\n", name); |
| 5379 | ctxt->valid = 0; |
| 5380 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 5381 | } else { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5382 | /* |
| 5383 | * Internal checking in case the entity quest barfed |
| 5384 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5385 | if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && |
| 5386 | (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5387 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 5388 | ctxt->sax->warning(ctxt->userData, |
| 5389 | "Internal: %%%s; is not a parameter entity\n", name); |
| 5390 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5391 | /* |
| 5392 | * TODO !!! |
| 5393 | * handle the extra spaces added before and after |
| 5394 | * c.f. http://www.w3.org/TR/REC-xml#as-PE |
| 5395 | */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5396 | input = xmlNewEntityInputStream(ctxt, entity); |
| 5397 | xmlPushInput(ctxt, input); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5398 | if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && |
| 5399 | (RAW == '<') && (NXT(1) == '?') && |
| 5400 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 5401 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 5402 | xmlParseTextDecl(ctxt); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 5403 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 5404 | /* |
| 5405 | * The XML REC instructs us to stop parsing |
| 5406 | * right here |
| 5407 | */ |
| 5408 | ctxt->instate = XML_PARSER_EOF; |
| 5409 | xmlFree(name); |
| 5410 | return; |
| 5411 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5412 | } |
| 5413 | if (ctxt->token == 0) |
| 5414 | ctxt->token = ' '; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5415 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5416 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5417 | ctxt->hasPErefs = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5418 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5419 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5420 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5421 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5422 | "xmlParsePEReference: expecting ';'\n"); |
| 5423 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5424 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5425 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5426 | xmlFree(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5427 | } |
| 5428 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5431 | /** |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5432 | * xmlParseStringPEReference: |
| 5433 | * @ctxt: an XML parser context |
| 5434 | * @str: a pointer to an index in the string |
| 5435 | * |
| 5436 | * parse PEReference declarations |
| 5437 | * |
| 5438 | * [69] PEReference ::= '%' Name ';' |
| 5439 | * |
| 5440 | * [ WFC: No Recursion ] |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 5441 | * A parsed entity must not contain a recursive |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5442 | * reference to itself, either directly or indirectly. |
| 5443 | * |
| 5444 | * [ WFC: Entity Declared ] |
| 5445 | * In a document without any DTD, a document with only an internal DTD |
| 5446 | * subset which contains no parameter entity references, or a document |
| 5447 | * with "standalone='yes'", ... ... The declaration of a parameter |
| 5448 | * entity must precede any reference to it... |
| 5449 | * |
| 5450 | * [ VC: Entity Declared ] |
| 5451 | * In a document with an external subset or external parameter entities |
| 5452 | * with "standalone='no'", ... ... The declaration of a parameter entity |
| 5453 | * must precede any reference to it... |
| 5454 | * |
| 5455 | * [ WFC: In DTD ] |
| 5456 | * Parameter-entity references may only appear in the DTD. |
| 5457 | * NOTE: misleading but this is handled. |
| 5458 | * |
| 5459 | * Returns the string of the entity content. |
| 5460 | * str is updated to the current value of the index |
| 5461 | */ |
| 5462 | xmlEntityPtr |
| 5463 | xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str) { |
| 5464 | const xmlChar *ptr; |
| 5465 | xmlChar cur; |
| 5466 | xmlChar *name; |
| 5467 | xmlEntityPtr entity = NULL; |
| 5468 | |
| 5469 | if ((str == NULL) || (*str == NULL)) return(NULL); |
| 5470 | ptr = *str; |
| 5471 | cur = *ptr; |
| 5472 | if (cur == '%') { |
| 5473 | ptr++; |
| 5474 | cur = *ptr; |
| 5475 | name = xmlParseStringName(ctxt, &ptr); |
| 5476 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5477 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5478 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5479 | ctxt->sax->error(ctxt->userData, |
| 5480 | "xmlParseStringPEReference: no name\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5481 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5482 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5483 | } else { |
| 5484 | cur = *ptr; |
| 5485 | if (cur == ';') { |
| 5486 | ptr++; |
| 5487 | cur = *ptr; |
| 5488 | if ((ctxt->sax != NULL) && |
| 5489 | (ctxt->sax->getParameterEntity != NULL)) |
| 5490 | entity = ctxt->sax->getParameterEntity(ctxt->userData, |
| 5491 | name); |
| 5492 | if (entity == NULL) { |
| 5493 | /* |
| 5494 | * [ WFC: Entity Declared ] |
| 5495 | * In a document without any DTD, a document with only an |
| 5496 | * internal DTD subset which contains no parameter entity |
| 5497 | * references, or a document with "standalone='yes'", ... |
| 5498 | * ... The declaration of a parameter entity must precede |
| 5499 | * any reference to it... |
| 5500 | */ |
| 5501 | if ((ctxt->standalone == 1) || |
| 5502 | ((ctxt->hasExternalSubset == 0) && |
| 5503 | (ctxt->hasPErefs == 0))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5504 | ctxt->errNo = XML_ERR_UNDECLARED_ENTITY; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5505 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5506 | ctxt->sax->error(ctxt->userData, |
| 5507 | "PEReference: %%%s; not found\n", name); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5508 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5509 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5510 | } else { |
| 5511 | /* |
| 5512 | * [ VC: Entity Declared ] |
| 5513 | * In a document with an external subset or external |
| 5514 | * parameter entities with "standalone='no'", ... |
| 5515 | * ... The declaration of a parameter entity must |
| 5516 | * precede any reference to it... |
| 5517 | */ |
| 5518 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 5519 | ctxt->sax->warning(ctxt->userData, |
| 5520 | "PEReference: %%%s; not found\n", name); |
| 5521 | ctxt->valid = 0; |
| 5522 | } |
| 5523 | } else { |
| 5524 | /* |
| 5525 | * Internal checking in case the entity quest barfed |
| 5526 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5527 | if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && |
| 5528 | (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5529 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 5530 | ctxt->sax->warning(ctxt->userData, |
| 5531 | "Internal: %%%s; is not a parameter entity\n", name); |
| 5532 | } |
| 5533 | } |
| 5534 | ctxt->hasPErefs = 1; |
| 5535 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5536 | ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5537 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5538 | ctxt->sax->error(ctxt->userData, |
| 5539 | "xmlParseStringPEReference: expecting ';'\n"); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5540 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5541 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 5542 | } |
| 5543 | xmlFree(name); |
| 5544 | } |
| 5545 | } |
| 5546 | *str = ptr; |
| 5547 | return(entity); |
| 5548 | } |
| 5549 | |
| 5550 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5551 | * xmlParseDocTypeDecl: |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5552 | * @ctxt: an XML parser context |
| 5553 | * |
| 5554 | * parse a DOCTYPE declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5555 | * |
| 5556 | * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? |
| 5557 | * ('[' (markupdecl | PEReference | S)* ']' S?)? '>' |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5558 | * |
| 5559 | * [ VC: Root Element Type ] |
| 5560 | * The Name in the document type declaration must match the element |
| 5561 | * type of the root element. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5562 | */ |
| 5563 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5564 | void |
| 5565 | xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5566 | xmlChar *name = NULL; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5567 | xmlChar *ExternalID = NULL; |
| 5568 | xmlChar *URI = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5569 | |
| 5570 | /* |
| 5571 | * We know that '<!DOCTYPE' has been detected. |
| 5572 | */ |
| 5573 | SKIP(9); |
| 5574 | |
| 5575 | SKIP_BLANKS; |
| 5576 | |
| 5577 | /* |
| 5578 | * Parse the DOCTYPE name. |
| 5579 | */ |
| 5580 | name = xmlParseName(ctxt); |
| 5581 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5582 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5583 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 5584 | ctxt->sax->error(ctxt->userData, |
| 5585 | "xmlParseDocTypeDecl : no DOCTYPE name !\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5586 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5587 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5588 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5589 | ctxt->intSubName = name; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5590 | |
| 5591 | SKIP_BLANKS; |
| 5592 | |
| 5593 | /* |
| 5594 | * Check for SystemID and ExternalID |
| 5595 | */ |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5596 | URI = xmlParseExternalID(ctxt, &ExternalID, 1); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5597 | |
| 5598 | if ((URI != NULL) || (ExternalID != NULL)) { |
| 5599 | ctxt->hasExternalSubset = 1; |
| 5600 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5601 | ctxt->extSubURI = URI; |
| 5602 | ctxt->extSubSystem = ExternalID; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5603 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5604 | SKIP_BLANKS; |
| 5605 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5606 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5607 | * Create and update the internal subset. |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5608 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5609 | if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) && |
| 5610 | (!ctxt->disableSAX)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5611 | ctxt->sax->internalSubset(ctxt->userData, name, ExternalID, URI); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5612 | |
| 5613 | /* |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5614 | * Is there any internal subset declarations ? |
| 5615 | * they are handled separately in xmlParseInternalSubset() |
| 5616 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5617 | if (RAW == '[') |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5618 | return; |
| 5619 | |
| 5620 | /* |
| 5621 | * We should be at the end of the DOCTYPE declaration. |
| 5622 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5623 | if (RAW != '>') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5624 | ctxt->errNo = XML_ERR_DOCTYPE_NOT_FINISHED; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5625 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5626 | ctxt->sax->error(ctxt->userData, "DOCTYPE unproperly terminated\n"); |
| 5627 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5628 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5629 | } |
| 5630 | NEXT; |
| 5631 | } |
| 5632 | |
| 5633 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5634 | * xmlParseInternalsubset: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5635 | * @ctxt: an XML parser context |
| 5636 | * |
| 5637 | * parse the internal subset declaration |
| 5638 | * |
| 5639 | * [28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>' |
| 5640 | */ |
| 5641 | |
| 5642 | void |
| 5643 | xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { |
| 5644 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5645 | * Is there any DTD definition ? |
| 5646 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5647 | if (RAW == '[') { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5648 | ctxt->instate = XML_PARSER_DTD; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5649 | NEXT; |
| 5650 | /* |
| 5651 | * Parse the succession of Markup declarations and |
| 5652 | * PEReferences. |
| 5653 | * Subsequence (markupdecl | PEReference | S)* |
| 5654 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5655 | while (RAW != ']') { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5656 | const xmlChar *check = CUR_PTR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5657 | int cons = ctxt->input->consumed; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5658 | |
| 5659 | SKIP_BLANKS; |
| 5660 | xmlParseMarkupDecl(ctxt); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 5661 | xmlParsePEReference(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5662 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5663 | /* |
| 5664 | * Pop-up of finished entities. |
| 5665 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5666 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 5667 | xmlPopInput(ctxt); |
| 5668 | |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 5669 | if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5670 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5671 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5672 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5673 | "xmlParseInternalSubset: error detected in Markup declaration\n"); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5674 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5675 | ctxt->disableSAX = 1; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5676 | break; |
| 5677 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5678 | } |
Daniel Veillard | 3665069 | 2000-07-21 15:16:39 +0000 | [diff] [blame] | 5679 | if (RAW == ']') { |
| 5680 | NEXT; |
| 5681 | SKIP_BLANKS; |
| 5682 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | /* |
| 5686 | * We should be at the end of the DOCTYPE declaration. |
| 5687 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5688 | if (RAW != '>') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5689 | ctxt->errNo = XML_ERR_DOCTYPE_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5690 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5691 | ctxt->sax->error(ctxt->userData, "DOCTYPE unproperly terminated\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5692 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5693 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5694 | } |
| 5695 | NEXT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5698 | /** |
| 5699 | * xmlParseAttribute: |
| 5700 | * @ctxt: an XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5701 | * @value: a xmlChar ** used to store the value of the attribute |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5702 | * |
| 5703 | * parse an attribute |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5704 | * |
| 5705 | * [41] Attribute ::= Name Eq AttValue |
| 5706 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5707 | * [ WFC: No External Entity References ] |
| 5708 | * Attribute values cannot contain direct or indirect entity references |
| 5709 | * to external entities. |
| 5710 | * |
| 5711 | * [ WFC: No < in Attribute Values ] |
| 5712 | * The replacement text of any entity referred to directly or indirectly in |
| 5713 | * an attribute value (other than "<") must not contain a <. |
| 5714 | * |
| 5715 | * [ VC: Attribute Value Type ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5716 | * The attribute must have been declared; the value must be of the type |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5717 | * declared for it. |
| 5718 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5719 | * [25] Eq ::= S? '=' S? |
| 5720 | * |
| 5721 | * With namespace: |
| 5722 | * |
| 5723 | * [NS 11] Attribute ::= QName Eq AttValue |
| 5724 | * |
| 5725 | * Also the case QName == xmlns:??? is handled independently as a namespace |
| 5726 | * definition. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5727 | * |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5728 | * Returns the attribute name, and the value in *value. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5729 | */ |
| 5730 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5731 | xmlChar * |
| 5732 | xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) { |
| 5733 | xmlChar *name, *val; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5734 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5735 | *value = NULL; |
| 5736 | name = xmlParseName(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5737 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5738 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5739 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5740 | ctxt->sax->error(ctxt->userData, "error parsing attribute name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5741 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5742 | ctxt->disableSAX = 1; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 5743 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /* |
| 5747 | * read the value |
| 5748 | */ |
| 5749 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5750 | if (RAW == '=') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5751 | NEXT; |
| 5752 | SKIP_BLANKS; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5753 | val = xmlParseAttValue(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5754 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5755 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5756 | ctxt->errNo = XML_ERR_ATTRIBUTE_WITHOUT_VALUE; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5757 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5758 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5759 | "Specification mandate value for attribute %s\n", name); |
| 5760 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5761 | ctxt->disableSAX = 1; |
| 5762 | xmlFree(name); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 5763 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5766 | /* |
| 5767 | * Check that xml:lang conforms to the specification |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 5768 | * No more registered as an error, just generate a warning now |
| 5769 | * since this was deprecated in XML second edition |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5770 | */ |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 5771 | if ((ctxt->pedantic) && (xmlStrEqual(name, BAD_CAST "xml:lang"))) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5772 | if (!xmlCheckLanguageID(val)) { |
Daniel Veillard | e0854c3 | 2000-08-27 21:12:29 +0000 | [diff] [blame] | 5773 | if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) |
| 5774 | ctxt->sax->warning(ctxt->userData, |
| 5775 | "Malformed value for xml:lang : %s\n", val); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | /* |
| 5780 | * Check that xml:space conforms to the specification |
| 5781 | */ |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 5782 | if (xmlStrEqual(name, BAD_CAST "xml:space")) { |
| 5783 | if (xmlStrEqual(val, BAD_CAST "default")) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5784 | *(ctxt->space) = 0; |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 5785 | else if (xmlStrEqual(val, BAD_CAST "preserve")) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5786 | *(ctxt->space) = 1; |
| 5787 | else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5788 | ctxt->errNo = XML_ERR_ATTRIBUTE_WITHOUT_VALUE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5789 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5790 | ctxt->sax->error(ctxt->userData, |
| 5791 | "Invalid value for xml:space : \"%s\", \"default\" or \"preserve\" expected\n", |
| 5792 | val); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5793 | ctxt->wellFormed = 0; |
| 5794 | ctxt->disableSAX = 1; |
| 5795 | } |
| 5796 | } |
| 5797 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5798 | *value = val; |
| 5799 | return(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5802 | /** |
| 5803 | * xmlParseStartTag: |
| 5804 | * @ctxt: an XML parser context |
| 5805 | * |
| 5806 | * parse a start of tag either for rule element or |
| 5807 | * EmptyElement. In both case we don't parse the tag closing chars. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5808 | * |
| 5809 | * [40] STag ::= '<' Name (S Attribute)* S? '>' |
| 5810 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5811 | * [ WFC: Unique Att Spec ] |
| 5812 | * No attribute name may appear more than once in the same start-tag or |
| 5813 | * empty-element tag. |
| 5814 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5815 | * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' |
| 5816 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5817 | * [ WFC: Unique Att Spec ] |
| 5818 | * No attribute name may appear more than once in the same start-tag or |
| 5819 | * empty-element tag. |
| 5820 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5821 | * With namespace: |
| 5822 | * |
| 5823 | * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' |
| 5824 | * |
| 5825 | * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5826 | * |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 5827 | * Returns the element name parsed |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5828 | */ |
| 5829 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5830 | xmlChar * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 5831 | xmlParseStartTag(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5832 | xmlChar *name; |
| 5833 | xmlChar *attname; |
| 5834 | xmlChar *attvalue; |
| 5835 | const xmlChar **atts = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5836 | int nbatts = 0; |
| 5837 | int maxatts = 0; |
| 5838 | int i; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5839 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5840 | if (RAW != '<') return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5841 | NEXT; |
| 5842 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5843 | name = xmlParseName(ctxt); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5844 | if (name == NULL) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5845 | ctxt->errNo = XML_ERR_NAME_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5846 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5847 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5848 | "xmlParseStartTag: invalid element name\n"); |
| 5849 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5850 | ctxt->disableSAX = 1; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5851 | return(NULL); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5852 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5853 | |
| 5854 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5855 | * Now parse the attributes, it ends up with the ending |
| 5856 | * |
| 5857 | * (S Attribute)* S? |
| 5858 | */ |
| 5859 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5860 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5861 | |
| 5862 | while ((IS_CHAR(RAW)) && |
| 5863 | (RAW != '>') && |
| 5864 | ((RAW != '/') || (NXT(1) != '>'))) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5865 | const xmlChar *q = CUR_PTR; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5866 | int cons = ctxt->input->consumed; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5867 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5868 | attname = xmlParseAttribute(ctxt, &attvalue); |
| 5869 | if ((attname != NULL) && (attvalue != NULL)) { |
| 5870 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5871 | * [ WFC: Unique Att Spec ] |
| 5872 | * No attribute name may appear more than once in the same |
| 5873 | * start-tag or empty-element tag. |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5874 | */ |
| 5875 | for (i = 0; i < nbatts;i += 2) { |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 5876 | if (xmlStrEqual(atts[i], attname)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5877 | ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5878 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5879 | ctxt->sax->error(ctxt->userData, |
| 5880 | "Attribute %s redefined\n", |
| 5881 | attname); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5882 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5883 | ctxt->disableSAX = 1; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 5884 | xmlFree(attname); |
| 5885 | xmlFree(attvalue); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 5886 | goto failed; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5887 | } |
| 5888 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5889 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5890 | /* |
| 5891 | * Add the pair to atts |
| 5892 | */ |
| 5893 | if (atts == NULL) { |
| 5894 | maxatts = 10; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5895 | atts = (const xmlChar **) xmlMalloc(maxatts * sizeof(xmlChar *)); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5896 | if (atts == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 5897 | xmlGenericError(xmlGenericErrorContext, |
| 5898 | "malloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5899 | maxatts * (long)sizeof(xmlChar *)); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5900 | return(NULL); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5901 | } |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 5902 | } else if (nbatts + 4 > maxatts) { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5903 | maxatts *= 2; |
Daniel Veillard | 4b0755c | 2000-09-25 14:26:28 +0000 | [diff] [blame] | 5904 | atts = (const xmlChar **) xmlRealloc((void *) atts, |
| 5905 | maxatts * sizeof(xmlChar *)); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5906 | if (atts == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 5907 | xmlGenericError(xmlGenericErrorContext, |
| 5908 | "realloc of %ld byte failed\n", |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5909 | maxatts * (long)sizeof(xmlChar *)); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5910 | return(NULL); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5911 | } |
| 5912 | } |
| 5913 | atts[nbatts++] = attname; |
| 5914 | atts[nbatts++] = attvalue; |
| 5915 | atts[nbatts] = NULL; |
| 5916 | atts[nbatts + 1] = NULL; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5917 | } else { |
| 5918 | if (attname != NULL) |
| 5919 | xmlFree(attname); |
| 5920 | if (attvalue != NULL) |
| 5921 | xmlFree(attvalue); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 5924 | failed: |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5925 | |
| 5926 | if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) |
| 5927 | break; |
| 5928 | if (!IS_BLANK(RAW)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5929 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5930 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 5931 | ctxt->sax->error(ctxt->userData, |
| 5932 | "attributes construct error\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5933 | ctxt->wellFormed = 0; |
| 5934 | ctxt->disableSAX = 1; |
| 5935 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5936 | SKIP_BLANKS; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5937 | if ((cons == ctxt->input->consumed) && (q == CUR_PTR)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5938 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5939 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5940 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5941 | "xmlParseStartTag: problem parsing attributes\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5942 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5943 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5944 | break; |
| 5945 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5946 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5950 | * SAX: Start of Element ! |
| 5951 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5952 | if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL) && |
| 5953 | (!ctxt->disableSAX)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5954 | ctxt->sax->startElement(ctxt->userData, name, atts); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5955 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5956 | if (atts != NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5957 | for (i = 0;i < nbatts;i++) xmlFree((xmlChar *) atts[i]); |
Daniel Veillard | 4b0755c | 2000-09-25 14:26:28 +0000 | [diff] [blame] | 5958 | xmlFree((void *) atts); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5959 | } |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 5960 | return(name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5961 | } |
| 5962 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5963 | /** |
| 5964 | * xmlParseEndTag: |
| 5965 | * @ctxt: an XML parser context |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 5966 | * |
| 5967 | * parse an end of tag |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5968 | * |
| 5969 | * [42] ETag ::= '</' Name S? '>' |
| 5970 | * |
| 5971 | * With namespace |
| 5972 | * |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5973 | * [NS 9] ETag ::= '</' QName S? '>' |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5974 | */ |
| 5975 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 5976 | void |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5977 | xmlParseEndTag(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 5978 | xmlChar *name; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 5979 | xmlChar *oldname; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5980 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5981 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5982 | if ((RAW != '<') || (NXT(1) != '/')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 5983 | ctxt->errNo = XML_ERR_LTSLASH_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 5984 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 5985 | ctxt->sax->error(ctxt->userData, "xmlParseEndTag: '</' not found\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 5986 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5987 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5988 | return; |
| 5989 | } |
| 5990 | SKIP(2); |
| 5991 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 5992 | name = xmlParseName(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5993 | |
| 5994 | /* |
| 5995 | * We should definitely be at the ending "S? '>'" part |
| 5996 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 5997 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 5998 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 5999 | if ((!IS_CHAR(RAW)) || (RAW != '>')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6000 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6001 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6002 | ctxt->sax->error(ctxt->userData, "End tag : expected '>'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6003 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6004 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6005 | } else |
| 6006 | NEXT; |
| 6007 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6008 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6009 | * [ WFC: Element Type Match ] |
| 6010 | * The Name in an element's end-tag must match the element type in the |
| 6011 | * start-tag. |
| 6012 | * |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6013 | */ |
Daniel Veillard | da07c34 | 2000-01-25 18:31:22 +0000 | [diff] [blame] | 6014 | if ((name == NULL) || (ctxt->name == NULL) || |
Daniel Veillard | 8b5dd83 | 2000-10-01 20:28:44 +0000 | [diff] [blame] | 6015 | (!xmlStrEqual(name, ctxt->name))) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6016 | ctxt->errNo = XML_ERR_TAG_NAME_MISMATCH; |
Daniel Veillard | da07c34 | 2000-01-25 18:31:22 +0000 | [diff] [blame] | 6017 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) { |
| 6018 | if ((name != NULL) && (ctxt->name != NULL)) { |
| 6019 | ctxt->sax->error(ctxt->userData, |
| 6020 | "Opening and ending tag mismatch: %s and %s\n", |
| 6021 | ctxt->name, name); |
| 6022 | } else if (ctxt->name != NULL) { |
| 6023 | ctxt->sax->error(ctxt->userData, |
| 6024 | "Ending tag eror for: %s\n", ctxt->name); |
| 6025 | } else { |
| 6026 | ctxt->sax->error(ctxt->userData, |
| 6027 | "Ending tag error: internal error ???\n"); |
| 6028 | } |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6029 | |
Daniel Veillard | da07c34 | 2000-01-25 18:31:22 +0000 | [diff] [blame] | 6030 | } |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6031 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6032 | ctxt->disableSAX = 1; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | /* |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6036 | * SAX: End of Tag |
| 6037 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6038 | if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL) && |
| 6039 | (!ctxt->disableSAX)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6040 | ctxt->sax->endElement(ctxt->userData, name); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6041 | |
| 6042 | if (name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6043 | xmlFree(name); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6044 | oldname = namePop(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6045 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6046 | if (oldname != NULL) { |
| 6047 | #ifdef DEBUG_STACK |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6048 | xmlGenericError(xmlGenericErrorContext,"Close: popped %s\n", oldname); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6049 | #endif |
| 6050 | xmlFree(oldname); |
| 6051 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6052 | return; |
| 6053 | } |
| 6054 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6055 | /** |
| 6056 | * xmlParseCDSect: |
| 6057 | * @ctxt: an XML parser context |
| 6058 | * |
| 6059 | * Parse escaped pure raw content. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6060 | * |
| 6061 | * [18] CDSect ::= CDStart CData CDEnd |
| 6062 | * |
| 6063 | * [19] CDStart ::= '<![CDATA[' |
| 6064 | * |
| 6065 | * [20] Data ::= (Char* - (Char* ']]>' Char*)) |
| 6066 | * |
| 6067 | * [21] CDEnd ::= ']]>' |
| 6068 | */ |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6069 | void |
| 6070 | xmlParseCDSect(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6071 | xmlChar *buf = NULL; |
| 6072 | int len = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6073 | int size = XML_PARSER_BUFFER_SIZE; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6074 | int r, rl; |
| 6075 | int s, sl; |
| 6076 | int cur, l; |
Daniel Veillard | f09e7e3 | 2000-10-01 15:53:30 +0000 | [diff] [blame] | 6077 | int count = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6078 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6079 | if ((NXT(0) == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6080 | (NXT(2) == '[') && (NXT(3) == 'C') && |
| 6081 | (NXT(4) == 'D') && (NXT(5) == 'A') && |
| 6082 | (NXT(6) == 'T') && (NXT(7) == 'A') && |
| 6083 | (NXT(8) == '[')) { |
| 6084 | SKIP(9); |
| 6085 | } else |
| 6086 | return; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6087 | |
| 6088 | ctxt->instate = XML_PARSER_CDATA_SECTION; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6089 | r = CUR_CHAR(rl); |
| 6090 | if (!IS_CHAR(r)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6091 | ctxt->errNo = XML_ERR_CDATA_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6092 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6093 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6094 | "CData section not finished\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6095 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6096 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6097 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6098 | return; |
| 6099 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6100 | NEXTL(rl); |
| 6101 | s = CUR_CHAR(sl); |
| 6102 | if (!IS_CHAR(s)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6103 | ctxt->errNo = XML_ERR_CDATA_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6104 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6105 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6106 | "CData section not finished\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6107 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6108 | ctxt->disableSAX = 1; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6109 | ctxt->instate = XML_PARSER_CONTENT; |
| 6110 | return; |
| 6111 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6112 | NEXTL(sl); |
| 6113 | cur = CUR_CHAR(l); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6114 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 6115 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6116 | xmlGenericError(xmlGenericErrorContext, |
| 6117 | "malloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6118 | return; |
| 6119 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6120 | while (IS_CHAR(cur) && |
| 6121 | ((r != ']') || (s != ']') || (cur != '>'))) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6122 | if (len + 5 >= size) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6123 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 6124 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6125 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6126 | xmlGenericError(xmlGenericErrorContext, |
| 6127 | "realloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6128 | return; |
| 6129 | } |
| 6130 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6131 | COPY_BUF(rl,buf,len,r); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6132 | r = s; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6133 | rl = sl; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6134 | s = cur; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6135 | sl = l; |
Daniel Veillard | f09e7e3 | 2000-10-01 15:53:30 +0000 | [diff] [blame] | 6136 | count++; |
| 6137 | if (count > 50) { |
| 6138 | GROW; |
| 6139 | count = 0; |
| 6140 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6141 | NEXTL(l); |
| 6142 | cur = CUR_CHAR(l); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6143 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6144 | buf[len] = 0; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6145 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6146 | if (cur != '>') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6147 | ctxt->errNo = XML_ERR_CDATA_NOT_FINISHED; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6148 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6149 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6150 | "CData section not finished\n%.50s\n", buf); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6151 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6152 | ctxt->disableSAX = 1; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6153 | xmlFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6154 | return; |
| 6155 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6156 | NEXTL(l); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6157 | |
| 6158 | /* |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6159 | * Ok the buffer is to be consumed as cdata. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6160 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6161 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6162 | if (ctxt->sax->cdataBlock != NULL) |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6163 | ctxt->sax->cdataBlock(ctxt->userData, buf, len); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6164 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6165 | xmlFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6166 | } |
| 6167 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6168 | /** |
| 6169 | * xmlParseContent: |
| 6170 | * @ctxt: an XML parser context |
| 6171 | * |
| 6172 | * Parse a content: |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6173 | * |
| 6174 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* |
| 6175 | */ |
| 6176 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6177 | void |
| 6178 | xmlParseContent(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6179 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6180 | while (((RAW != 0) || (ctxt->token != 0)) && |
| 6181 | ((RAW != '<') || (NXT(1) != '/'))) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6182 | const xmlChar *test = CUR_PTR; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6183 | int cons = ctxt->input->consumed; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6184 | xmlChar tok = ctxt->token; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6185 | |
| 6186 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6187 | * Handle possible processed charrefs. |
| 6188 | */ |
| 6189 | if (ctxt->token != 0) { |
| 6190 | xmlParseCharData(ctxt, 0); |
| 6191 | } |
| 6192 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6193 | * First case : a Processing Instruction. |
| 6194 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6195 | else if ((RAW == '<') && (NXT(1) == '?')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6196 | xmlParsePI(ctxt); |
| 6197 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6198 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6199 | /* |
| 6200 | * Second case : a CDSection |
| 6201 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6202 | else if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6203 | (NXT(2) == '[') && (NXT(3) == 'C') && |
| 6204 | (NXT(4) == 'D') && (NXT(5) == 'A') && |
| 6205 | (NXT(6) == 'T') && (NXT(7) == 'A') && |
| 6206 | (NXT(8) == '[')) { |
| 6207 | xmlParseCDSect(ctxt); |
| 6208 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6209 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6210 | /* |
| 6211 | * Third case : a comment |
| 6212 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6213 | else if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6214 | (NXT(2) == '-') && (NXT(3) == '-')) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6215 | xmlParseComment(ctxt); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6216 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6217 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6218 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6219 | /* |
| 6220 | * Fourth case : a sub-element. |
| 6221 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6222 | else if (RAW == '<') { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6223 | xmlParseElement(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6224 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6225 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6226 | /* |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 6227 | * Fifth case : a reference. If if has not been resolved, |
| 6228 | * parsing returns it's Name, create the node |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6229 | */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6230 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6231 | else if (RAW == '&') { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6232 | xmlParseReference(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6233 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6234 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6235 | /* |
| 6236 | * Last case, text. Note that References are handled directly. |
| 6237 | */ |
| 6238 | else { |
| 6239 | xmlParseCharData(ctxt, 0); |
| 6240 | } |
| 6241 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6242 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6243 | /* |
| 6244 | * Pop-up of finished entities. |
| 6245 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6246 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
Daniel Veillard | bc50b59 | 1999-03-01 12:28:53 +0000 | [diff] [blame] | 6247 | xmlPopInput(ctxt); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6248 | SHRINK; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6249 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6250 | if ((cons == ctxt->input->consumed) && (test == CUR_PTR) && |
| 6251 | (tok == ctxt->token)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6252 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6253 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6254 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6255 | "detected an error in element content\n"); |
| 6256 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6257 | ctxt->disableSAX = 1; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 6258 | ctxt->instate = XML_PARSER_EOF; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6259 | break; |
| 6260 | } |
| 6261 | } |
| 6262 | } |
| 6263 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6264 | /** |
| 6265 | * xmlParseElement: |
| 6266 | * @ctxt: an XML parser context |
| 6267 | * |
| 6268 | * parse an XML element, this is highly recursive |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6269 | * |
| 6270 | * [39] element ::= EmptyElemTag | STag content ETag |
| 6271 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6272 | * [ WFC: Element Type Match ] |
| 6273 | * The Name in an element's end-tag must match the element type in the |
| 6274 | * start-tag. |
| 6275 | * |
| 6276 | * [ VC: Element Valid ] |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6277 | * An element is valid if there is a declaration matching elementdecl |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6278 | * where the Name matches the element type and one of the following holds: |
| 6279 | * - The declaration matches EMPTY and the element has no content. |
| 6280 | * - The declaration matches children and the sequence of child elements |
| 6281 | * belongs to the language generated by the regular expression in the |
| 6282 | * content model, with optional white space (characters matching the |
| 6283 | * nonterminal S) between each pair of child elements. |
| 6284 | * - The declaration matches Mixed and the content consists of character |
| 6285 | * data and child elements whose types match names in the content model. |
| 6286 | * - The declaration matches ANY, and the types of any child elements have |
| 6287 | * been declared. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6288 | */ |
| 6289 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6290 | void |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6291 | xmlParseElement(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6292 | const xmlChar *openTag = CUR_PTR; |
| 6293 | xmlChar *name; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6294 | xmlChar *oldname; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6295 | xmlParserNodeInfo node_info; |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 6296 | xmlNodePtr ret; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6297 | |
| 6298 | /* Capture start position */ |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 6299 | if (ctxt->record_info) { |
| 6300 | node_info.begin_pos = ctxt->input->consumed + |
| 6301 | (CUR_PTR - ctxt->input->base); |
| 6302 | node_info.begin_line = ctxt->input->line; |
| 6303 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6304 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6305 | if (ctxt->spaceNr == 0) |
| 6306 | spacePush(ctxt, -1); |
| 6307 | else |
| 6308 | spacePush(ctxt, *ctxt->space); |
| 6309 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6310 | name = xmlParseStartTag(ctxt); |
| 6311 | if (name == NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6312 | spacePop(ctxt); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6313 | return; |
| 6314 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6315 | namePush(ctxt, name); |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 6316 | ret = ctxt->node; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6317 | |
| 6318 | /* |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6319 | * [ VC: Root Element Type ] |
| 6320 | * The Name in the document type declaration must match the element |
| 6321 | * type of the root element. |
| 6322 | */ |
| 6323 | if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6324 | ctxt->node && (ctxt->node == ctxt->myDoc->children)) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6325 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); |
| 6326 | |
| 6327 | /* |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6328 | * Check for an Empty Element. |
| 6329 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6330 | if ((RAW == '/') && (NXT(1) == '>')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6331 | SKIP(2); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6332 | if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL) && |
| 6333 | (!ctxt->disableSAX)) |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 6334 | ctxt->sax->endElement(ctxt->userData, name); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6335 | oldname = namePop(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6336 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6337 | if (oldname != NULL) { |
| 6338 | #ifdef DEBUG_STACK |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6339 | xmlGenericError(xmlGenericErrorContext,"Close: popped %s\n", oldname); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6340 | #endif |
| 6341 | xmlFree(oldname); |
| 6342 | } |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 6343 | if ( ret != NULL && ctxt->record_info ) { |
| 6344 | node_info.end_pos = ctxt->input->consumed + |
| 6345 | (CUR_PTR - ctxt->input->base); |
| 6346 | node_info.end_line = ctxt->input->line; |
| 6347 | node_info.node = ret; |
| 6348 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 6349 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6350 | return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6351 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6352 | if (RAW == '>') { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6353 | NEXT; |
| 6354 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6355 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6356 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6357 | ctxt->sax->error(ctxt->userData, |
| 6358 | "Couldn't find end of Start Tag\n%.30s\n", |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 6359 | openTag); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6360 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6361 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6362 | |
| 6363 | /* |
| 6364 | * end of parsing of this node. |
| 6365 | */ |
| 6366 | nodePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6367 | oldname = namePop(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6368 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6369 | if (oldname != NULL) { |
| 6370 | #ifdef DEBUG_STACK |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6371 | xmlGenericError(xmlGenericErrorContext,"Close: popped %s\n", oldname); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6372 | #endif |
| 6373 | xmlFree(oldname); |
| 6374 | } |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 6375 | |
| 6376 | /* |
| 6377 | * Capture end position and add node |
| 6378 | */ |
| 6379 | if ( ret != NULL && ctxt->record_info ) { |
| 6380 | node_info.end_pos = ctxt->input->consumed + |
| 6381 | (CUR_PTR - ctxt->input->base); |
| 6382 | node_info.end_line = ctxt->input->line; |
| 6383 | node_info.node = ret; |
| 6384 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 6385 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6386 | return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | /* |
| 6390 | * Parse the content of the element: |
| 6391 | */ |
| 6392 | xmlParseContent(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6393 | if (!IS_CHAR(RAW)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6394 | ctxt->errNo = XML_ERR_TAG_NOT_FINISED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6395 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6396 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 6397 | "Premature end of data in tag %.30s\n", openTag); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6398 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6399 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6400 | |
| 6401 | /* |
| 6402 | * end of parsing of this node. |
| 6403 | */ |
| 6404 | nodePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6405 | oldname = namePop(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6406 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6407 | if (oldname != NULL) { |
| 6408 | #ifdef DEBUG_STACK |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6409 | xmlGenericError(xmlGenericErrorContext,"Close: popped %s\n", oldname); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6410 | #endif |
| 6411 | xmlFree(oldname); |
| 6412 | } |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6413 | return; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
| 6416 | /* |
| 6417 | * parse the end of tag: '</' should be here. |
| 6418 | */ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 6419 | xmlParseEndTag(ctxt); |
Daniel Veillard | c26087b | 1999-08-30 11:23:51 +0000 | [diff] [blame] | 6420 | |
| 6421 | /* |
| 6422 | * Capture end position and add node |
| 6423 | */ |
| 6424 | if ( ret != NULL && ctxt->record_info ) { |
| 6425 | node_info.end_pos = ctxt->input->consumed + |
| 6426 | (CUR_PTR - ctxt->input->base); |
| 6427 | node_info.end_line = ctxt->input->line; |
| 6428 | node_info.node = ret; |
| 6429 | xmlParserAddNodeInfo(ctxt, &node_info); |
| 6430 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6431 | } |
| 6432 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6433 | /** |
| 6434 | * xmlParseVersionNum: |
| 6435 | * @ctxt: an XML parser context |
| 6436 | * |
| 6437 | * parse the XML version value. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6438 | * |
| 6439 | * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6440 | * |
| 6441 | * Returns the string giving the XML version number, or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6442 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6443 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6444 | xmlParseVersionNum(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6445 | xmlChar *buf = NULL; |
| 6446 | int len = 0; |
| 6447 | int size = 10; |
| 6448 | xmlChar cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6449 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6450 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 6451 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6452 | xmlGenericError(xmlGenericErrorContext, |
| 6453 | "malloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6454 | return(NULL); |
| 6455 | } |
| 6456 | cur = CUR; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6457 | while (((cur >= 'a') && (cur <= 'z')) || |
| 6458 | ((cur >= 'A') && (cur <= 'Z')) || |
| 6459 | ((cur >= '0') && (cur <= '9')) || |
| 6460 | (cur == '_') || (cur == '.') || |
| 6461 | (cur == ':') || (cur == '-')) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6462 | if (len + 1 >= size) { |
| 6463 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 6464 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6465 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6466 | xmlGenericError(xmlGenericErrorContext, |
| 6467 | "realloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6468 | return(NULL); |
| 6469 | } |
| 6470 | } |
| 6471 | buf[len++] = cur; |
| 6472 | NEXT; |
| 6473 | cur=CUR; |
| 6474 | } |
| 6475 | buf[len] = 0; |
| 6476 | return(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6477 | } |
| 6478 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6479 | /** |
| 6480 | * xmlParseVersionInfo: |
| 6481 | * @ctxt: an XML parser context |
| 6482 | * |
| 6483 | * parse the XML version. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6484 | * |
| 6485 | * [24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ") |
| 6486 | * |
| 6487 | * [25] Eq ::= S? '=' S? |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6488 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6489 | * Returns the version string, e.g. "1.0" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6490 | */ |
| 6491 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6492 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6493 | xmlParseVersionInfo(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6494 | xmlChar *version = NULL; |
| 6495 | const xmlChar *q; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6496 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6497 | if ((RAW == 'v') && (NXT(1) == 'e') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6498 | (NXT(2) == 'r') && (NXT(3) == 's') && |
| 6499 | (NXT(4) == 'i') && (NXT(5) == 'o') && |
| 6500 | (NXT(6) == 'n')) { |
| 6501 | SKIP(7); |
| 6502 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6503 | if (RAW != '=') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6504 | ctxt->errNo = XML_ERR_EQUAL_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6505 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6506 | ctxt->sax->error(ctxt->userData, |
| 6507 | "xmlParseVersionInfo : expected '='\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6508 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6509 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6510 | return(NULL); |
| 6511 | } |
| 6512 | NEXT; |
| 6513 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6514 | if (RAW == '"') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6515 | NEXT; |
| 6516 | q = CUR_PTR; |
| 6517 | version = xmlParseVersionNum(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6518 | if (RAW != '"') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6519 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6520 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6521 | ctxt->sax->error(ctxt->userData, |
| 6522 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6523 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6524 | ctxt->disableSAX = 1; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6525 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6526 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6527 | } else if (RAW == '\''){ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6528 | NEXT; |
| 6529 | q = CUR_PTR; |
| 6530 | version = xmlParseVersionNum(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6531 | if (RAW != '\'') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6532 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6533 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6534 | ctxt->sax->error(ctxt->userData, |
| 6535 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6536 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6537 | ctxt->disableSAX = 1; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6538 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6539 | NEXT; |
| 6540 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6541 | ctxt->errNo = XML_ERR_STRING_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6542 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6543 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6544 | "xmlParseVersionInfo : expected ' or \"\n"); |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6545 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6546 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6547 | } |
| 6548 | } |
| 6549 | return(version); |
| 6550 | } |
| 6551 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6552 | /** |
| 6553 | * xmlParseEncName: |
| 6554 | * @ctxt: an XML parser context |
| 6555 | * |
| 6556 | * parse the XML encoding name |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6557 | * |
| 6558 | * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6559 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6560 | * Returns the encoding name value or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6561 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6562 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6563 | xmlParseEncName(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6564 | xmlChar *buf = NULL; |
| 6565 | int len = 0; |
| 6566 | int size = 10; |
| 6567 | xmlChar cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6568 | |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6569 | cur = CUR; |
| 6570 | if (((cur >= 'a') && (cur <= 'z')) || |
| 6571 | ((cur >= 'A') && (cur <= 'Z'))) { |
| 6572 | buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar)); |
| 6573 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6574 | xmlGenericError(xmlGenericErrorContext, |
| 6575 | "malloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6576 | return(NULL); |
| 6577 | } |
| 6578 | |
| 6579 | buf[len++] = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6580 | NEXT; |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6581 | cur = CUR; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6582 | while (((cur >= 'a') && (cur <= 'z')) || |
| 6583 | ((cur >= 'A') && (cur <= 'Z')) || |
| 6584 | ((cur >= '0') && (cur <= '9')) || |
| 6585 | (cur == '.') || (cur == '_') || |
| 6586 | (cur == '-')) { |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6587 | if (len + 1 >= size) { |
| 6588 | size *= 2; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 6589 | buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6590 | if (buf == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 6591 | xmlGenericError(xmlGenericErrorContext, |
| 6592 | "realloc of %d byte failed\n", size); |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6593 | return(NULL); |
| 6594 | } |
| 6595 | } |
| 6596 | buf[len++] = cur; |
| 6597 | NEXT; |
| 6598 | cur = CUR; |
| 6599 | if (cur == 0) { |
| 6600 | SHRINK; |
| 6601 | GROW; |
| 6602 | cur = CUR; |
| 6603 | } |
| 6604 | } |
| 6605 | buf[len] = 0; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6606 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6607 | ctxt->errNo = XML_ERR_ENCODING_NAME; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6608 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6609 | ctxt->sax->error(ctxt->userData, "Invalid XML encoding name\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6610 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6611 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6612 | } |
Daniel Veillard | 10a2c65 | 1999-12-12 13:03:50 +0000 | [diff] [blame] | 6613 | return(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6614 | } |
| 6615 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6616 | /** |
| 6617 | * xmlParseEncodingDecl: |
| 6618 | * @ctxt: an XML parser context |
| 6619 | * |
| 6620 | * parse the XML encoding declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6621 | * |
| 6622 | * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'") |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6623 | * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 6624 | * this setups the conversion filters. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6625 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6626 | * Returns the encoding value or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6627 | */ |
| 6628 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6629 | xmlChar * |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6630 | xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6631 | xmlChar *encoding = NULL; |
| 6632 | const xmlChar *q; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6633 | |
| 6634 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6635 | if ((RAW == 'e') && (NXT(1) == 'n') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6636 | (NXT(2) == 'c') && (NXT(3) == 'o') && |
| 6637 | (NXT(4) == 'd') && (NXT(5) == 'i') && |
| 6638 | (NXT(6) == 'n') && (NXT(7) == 'g')) { |
| 6639 | SKIP(8); |
| 6640 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6641 | if (RAW != '=') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6642 | ctxt->errNo = XML_ERR_EQUAL_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6643 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6644 | ctxt->sax->error(ctxt->userData, |
| 6645 | "xmlParseEncodingDecl : expected '='\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6646 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6647 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6648 | return(NULL); |
| 6649 | } |
| 6650 | NEXT; |
| 6651 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6652 | if (RAW == '"') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6653 | NEXT; |
| 6654 | q = CUR_PTR; |
| 6655 | encoding = xmlParseEncName(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6656 | if (RAW != '"') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6657 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6658 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6659 | ctxt->sax->error(ctxt->userData, |
| 6660 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6661 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6662 | ctxt->disableSAX = 1; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6663 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6664 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6665 | } else if (RAW == '\''){ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6666 | NEXT; |
| 6667 | q = CUR_PTR; |
| 6668 | encoding = xmlParseEncName(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6669 | if (RAW != '\'') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6670 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6671 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6672 | ctxt->sax->error(ctxt->userData, |
| 6673 | "String not closed\n%.50s\n", q); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6674 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6675 | ctxt->disableSAX = 1; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6676 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6677 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6678 | } else if (RAW == '"'){ |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6679 | ctxt->errNo = XML_ERR_STRING_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6680 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6681 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6682 | "xmlParseEncodingDecl : expected ' or \"\n"); |
| 6683 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6684 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6685 | } |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 6686 | if (encoding != NULL) { |
| 6687 | xmlCharEncoding enc; |
| 6688 | xmlCharEncodingHandlerPtr handler; |
| 6689 | |
| 6690 | if (ctxt->input->encoding != NULL) |
| 6691 | xmlFree((xmlChar *) ctxt->input->encoding); |
| 6692 | ctxt->input->encoding = encoding; |
| 6693 | |
| 6694 | enc = xmlParseCharEncoding((const char *) encoding); |
| 6695 | /* |
| 6696 | * registered set of known encodings |
| 6697 | */ |
| 6698 | if (enc != XML_CHAR_ENCODING_ERROR) { |
| 6699 | xmlSwitchEncoding(ctxt, enc); |
| 6700 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 6701 | xmlFree(encoding); |
| 6702 | return(NULL); |
| 6703 | } |
| 6704 | } else { |
| 6705 | /* |
| 6706 | * fallback for unknown encodings |
| 6707 | */ |
| 6708 | handler = xmlFindCharEncodingHandler((const char *) encoding); |
| 6709 | if (handler != NULL) { |
| 6710 | xmlSwitchToEncoding(ctxt, handler); |
| 6711 | } else { |
| 6712 | ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING; |
Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 6713 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 6714 | ctxt->sax->error(ctxt->userData, |
| 6715 | "Unsupported encoding %s\n", encoding); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 6716 | return(NULL); |
| 6717 | } |
| 6718 | } |
| 6719 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6720 | } |
| 6721 | return(encoding); |
| 6722 | } |
| 6723 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6724 | /** |
| 6725 | * xmlParseSDDecl: |
| 6726 | * @ctxt: an XML parser context |
| 6727 | * |
| 6728 | * parse the XML standalone declaration |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6729 | * |
| 6730 | * [32] SDDecl ::= S 'standalone' Eq |
| 6731 | * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6732 | * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 6733 | * [ VC: Standalone Document Declaration ] |
| 6734 | * TODO The standalone document declaration must have the value "no" |
| 6735 | * if any external markup declarations contain declarations of: |
| 6736 | * - attributes with default values, if elements to which these |
| 6737 | * attributes apply appear in the document without specifications |
| 6738 | * of values for these attributes, or |
| 6739 | * - entities (other than amp, lt, gt, apos, quot), if references |
| 6740 | * to those entities appear in the document, or |
| 6741 | * - attributes with values subject to normalization, where the |
| 6742 | * attribute appears in the document with a value which will change |
| 6743 | * as a result of normalization, or |
| 6744 | * - element types with element content, if white space occurs directly |
| 6745 | * within any instance of those types. |
| 6746 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6747 | * Returns 1 if standalone, 0 otherwise |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6748 | */ |
| 6749 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6750 | int |
| 6751 | xmlParseSDDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6752 | int standalone = -1; |
| 6753 | |
| 6754 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6755 | if ((RAW == 's') && (NXT(1) == 't') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6756 | (NXT(2) == 'a') && (NXT(3) == 'n') && |
| 6757 | (NXT(4) == 'd') && (NXT(5) == 'a') && |
| 6758 | (NXT(6) == 'l') && (NXT(7) == 'o') && |
| 6759 | (NXT(8) == 'n') && (NXT(9) == 'e')) { |
| 6760 | SKIP(10); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 6761 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6762 | if (RAW != '=') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6763 | ctxt->errNo = XML_ERR_EQUAL_REQUIRED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6764 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6765 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6766 | "XML standalone declaration : expected '='\n"); |
| 6767 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6768 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6769 | return(standalone); |
| 6770 | } |
| 6771 | NEXT; |
| 6772 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6773 | if (RAW == '\''){ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6774 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6775 | if ((RAW == 'n') && (NXT(1) == 'o')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6776 | standalone = 0; |
| 6777 | SKIP(2); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6778 | } else if ((RAW == 'y') && (NXT(1) == 'e') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6779 | (NXT(2) == 's')) { |
| 6780 | standalone = 1; |
| 6781 | SKIP(3); |
| 6782 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6783 | ctxt->errNo = XML_ERR_STANDALONE_VALUE; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6784 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6785 | ctxt->sax->error(ctxt->userData, |
| 6786 | "standalone accepts only 'yes' or 'no'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6787 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6788 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6789 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6790 | if (RAW != '\'') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6791 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6792 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6793 | ctxt->sax->error(ctxt->userData, "String not closed\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6794 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6795 | ctxt->disableSAX = 1; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6796 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6797 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6798 | } else if (RAW == '"'){ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6799 | NEXT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6800 | if ((RAW == 'n') && (NXT(1) == 'o')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6801 | standalone = 0; |
| 6802 | SKIP(2); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6803 | } else if ((RAW == 'y') && (NXT(1) == 'e') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6804 | (NXT(2) == 's')) { |
| 6805 | standalone = 1; |
| 6806 | SKIP(3); |
| 6807 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6808 | ctxt->errNo = XML_ERR_STANDALONE_VALUE; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6809 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6810 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6811 | "standalone accepts only 'yes' or 'no'\n"); |
| 6812 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6813 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6814 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6815 | if (RAW != '"') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6816 | ctxt->errNo = XML_ERR_STRING_NOT_CLOSED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6817 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6818 | ctxt->sax->error(ctxt->userData, "String not closed\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6819 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6820 | ctxt->disableSAX = 1; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6821 | } else |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6822 | NEXT; |
| 6823 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6824 | ctxt->errNo = XML_ERR_STRING_NOT_STARTED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6825 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6826 | ctxt->sax->error(ctxt->userData, |
| 6827 | "Standalone value not found\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6828 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6829 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6830 | } |
| 6831 | } |
| 6832 | return(standalone); |
| 6833 | } |
| 6834 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6835 | /** |
| 6836 | * xmlParseXMLDecl: |
| 6837 | * @ctxt: an XML parser context |
| 6838 | * |
| 6839 | * parse an XML declaration header |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6840 | * |
| 6841 | * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' |
| 6842 | */ |
| 6843 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6844 | void |
| 6845 | xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 6846 | xmlChar *version; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6847 | |
| 6848 | /* |
| 6849 | * We know that '<?xml' is here. |
| 6850 | */ |
| 6851 | SKIP(5); |
| 6852 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6853 | if (!IS_BLANK(RAW)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6854 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6855 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6856 | ctxt->sax->error(ctxt->userData, "Blank needed after '<?xml'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6857 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6858 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6859 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6860 | SKIP_BLANKS; |
| 6861 | |
| 6862 | /* |
| 6863 | * We should have the VersionInfo here. |
| 6864 | */ |
| 6865 | version = xmlParseVersionInfo(ctxt); |
| 6866 | if (version == NULL) |
| 6867 | version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6868 | ctxt->version = xmlStrdup(version); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 6869 | xmlFree(version); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6870 | |
| 6871 | /* |
| 6872 | * We may have the encoding declaration |
| 6873 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6874 | if (!IS_BLANK(RAW)) { |
| 6875 | if ((RAW == '?') && (NXT(1) == '>')) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6876 | SKIP(2); |
| 6877 | return; |
| 6878 | } |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6879 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6880 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6881 | ctxt->sax->error(ctxt->userData, "Blank needed here\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6882 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6883 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6884 | } |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 6885 | xmlParseEncodingDecl(ctxt); |
| 6886 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 6887 | /* |
| 6888 | * The XML REC instructs us to stop parsing right here |
| 6889 | */ |
| 6890 | return; |
| 6891 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6892 | |
| 6893 | /* |
| 6894 | * We may have the standalone status. |
| 6895 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6896 | if ((ctxt->input->encoding != NULL) && (!IS_BLANK(RAW))) { |
| 6897 | if ((RAW == '?') && (NXT(1) == '>')) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6898 | SKIP(2); |
| 6899 | return; |
| 6900 | } |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6901 | ctxt->errNo = XML_ERR_SPACE_REQUIRED; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6902 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6903 | ctxt->sax->error(ctxt->userData, "Blank needed here\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6904 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6905 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6906 | } |
| 6907 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6908 | ctxt->input->standalone = xmlParseSDDecl(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6909 | |
| 6910 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6911 | if ((RAW == '?') && (NXT(1) == '>')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6912 | SKIP(2); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6913 | } else if (RAW == '>') { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6914 | /* Deprecated old WD ... */ |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6915 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6916 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6917 | ctxt->sax->error(ctxt->userData, |
| 6918 | "XML declaration must end-up with '?>'\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6919 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6920 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6921 | NEXT; |
| 6922 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 6923 | ctxt->errNo = XML_ERR_XMLDECL_NOT_FINISHED; |
Daniel Veillard | e3bffb9 | 1998-11-08 14:40:56 +0000 | [diff] [blame] | 6924 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 6925 | ctxt->sax->error(ctxt->userData, |
| 6926 | "parsing XML declaration: '?>' expected\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6927 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6928 | ctxt->disableSAX = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6929 | MOVETO_ENDTAG(CUR_PTR); |
| 6930 | NEXT; |
| 6931 | } |
| 6932 | } |
| 6933 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6934 | /** |
| 6935 | * xmlParseMisc: |
| 6936 | * @ctxt: an XML parser context |
| 6937 | * |
| 6938 | * parse an XML Misc* optionnal field. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6939 | * |
| 6940 | * [27] Misc ::= Comment | PI | S |
| 6941 | */ |
| 6942 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6943 | void |
| 6944 | xmlParseMisc(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6945 | while (((RAW == '<') && (NXT(1) == '?')) || |
| 6946 | ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6947 | (NXT(2) == '-') && (NXT(3) == '-')) || |
| 6948 | IS_BLANK(CUR)) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6949 | if ((RAW == '<') && (NXT(1) == '?')) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6950 | xmlParsePI(ctxt); |
| 6951 | } else if (IS_BLANK(CUR)) { |
| 6952 | NEXT; |
| 6953 | } else |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 6954 | xmlParseComment(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6955 | } |
| 6956 | } |
| 6957 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6958 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6959 | * xmlParseDocument: |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6960 | * @ctxt: an XML parser context |
| 6961 | * |
| 6962 | * parse an XML document (and build a tree if using the standard SAX |
| 6963 | * interface). |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6964 | * |
| 6965 | * [1] document ::= prolog element Misc* |
| 6966 | * |
| 6967 | * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6968 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 6969 | * Returns 0, -1 in case of error. the parser context is augmented |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 6970 | * as a result of the parsing. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6971 | */ |
| 6972 | |
Daniel Veillard | 0ba4d53 | 1998-11-01 19:34:31 +0000 | [diff] [blame] | 6973 | int |
| 6974 | xmlParseDocument(xmlParserCtxtPtr ctxt) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6975 | xmlChar start[4]; |
| 6976 | xmlCharEncoding enc; |
| 6977 | |
Daniel Veillard | bc76530 | 2000-10-01 18:23:35 +0000 | [diff] [blame] | 6978 | xmlInitParser(); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6979 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 6980 | GROW; |
| 6981 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6982 | /* |
| 6983 | * SAX: beginning of the document processing. |
| 6984 | */ |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 6985 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 6986 | ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6987 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6988 | /* |
| 6989 | * Get the 4 first bytes and decode the charset |
| 6990 | * if enc != XML_CHAR_ENCODING_NONE |
| 6991 | * plug some encoding conversion routines. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 6992 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 6993 | start[0] = RAW; |
| 6994 | start[1] = NXT(1); |
| 6995 | start[2] = NXT(2); |
| 6996 | start[3] = NXT(3); |
| 6997 | enc = xmlDetectCharEncoding(start, 4); |
| 6998 | if (enc != XML_CHAR_ENCODING_NONE) { |
| 6999 | xmlSwitchEncoding(ctxt, enc); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7000 | } |
| 7001 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7002 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7003 | if (CUR == 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7004 | ctxt->errNo = XML_ERR_DOCUMENT_EMPTY; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7005 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 7006 | ctxt->sax->error(ctxt->userData, "Document is empty\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7007 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7008 | ctxt->disableSAX = 1; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7009 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7010 | |
| 7011 | /* |
| 7012 | * Check for the XMLDecl in the Prolog. |
| 7013 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 7014 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7015 | if ((RAW == '<') && (NXT(1) == '?') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7016 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
Daniel Veillard | 686d6b6 | 2000-01-03 11:08:02 +0000 | [diff] [blame] | 7017 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 7018 | |
| 7019 | /* |
| 7020 | * Note that we will switch encoding on the fly. |
| 7021 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7022 | xmlParseXMLDecl(ctxt); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 7023 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 7024 | /* |
| 7025 | * The XML REC instructs us to stop parsing right here |
| 7026 | */ |
| 7027 | return(-1); |
| 7028 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7029 | ctxt->standalone = ctxt->input->standalone; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7030 | SKIP_BLANKS; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7031 | } else { |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 7032 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7033 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7034 | if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 7035 | ctxt->sax->startDocument(ctxt->userData); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7036 | |
| 7037 | /* |
| 7038 | * The Misc part of the Prolog |
| 7039 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 7040 | GROW; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7041 | xmlParseMisc(ctxt); |
| 7042 | |
| 7043 | /* |
| 7044 | * Then possibly doc type declaration(s) and more Misc |
| 7045 | * (doctypedecl Misc*)? |
| 7046 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 7047 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7048 | if ((RAW == '<') && (NXT(1) == '!') && |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7049 | (NXT(2) == 'D') && (NXT(3) == 'O') && |
| 7050 | (NXT(4) == 'C') && (NXT(5) == 'T') && |
| 7051 | (NXT(6) == 'Y') && (NXT(7) == 'P') && |
| 7052 | (NXT(8) == 'E')) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7053 | |
| 7054 | ctxt->inSubset = 1; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7055 | xmlParseDocTypeDecl(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7056 | if (RAW == '[') { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7057 | ctxt->instate = XML_PARSER_DTD; |
| 7058 | xmlParseInternalSubset(ctxt); |
| 7059 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7060 | |
| 7061 | /* |
| 7062 | * Create and update the external subset. |
| 7063 | */ |
| 7064 | ctxt->inSubset = 2; |
| 7065 | if ((ctxt->sax != NULL) && (ctxt->sax->externalSubset != NULL) && |
| 7066 | (!ctxt->disableSAX)) |
| 7067 | ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName, |
| 7068 | ctxt->extSubSystem, ctxt->extSubURI); |
| 7069 | ctxt->inSubset = 0; |
| 7070 | |
| 7071 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 7072 | ctxt->instate = XML_PARSER_PROLOG; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7073 | xmlParseMisc(ctxt); |
| 7074 | } |
| 7075 | |
| 7076 | /* |
| 7077 | * Time to start parsing the tree itself |
| 7078 | */ |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 7079 | GROW; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7080 | if (RAW != '<') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7081 | ctxt->errNo = XML_ERR_DOCUMENT_EMPTY; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7082 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 7083 | ctxt->sax->error(ctxt->userData, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7084 | "Start tag expected, '<' not found\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7085 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7086 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7087 | ctxt->instate = XML_PARSER_EOF; |
| 7088 | } else { |
| 7089 | ctxt->instate = XML_PARSER_CONTENT; |
| 7090 | xmlParseElement(ctxt); |
| 7091 | ctxt->instate = XML_PARSER_EPILOG; |
| 7092 | |
| 7093 | |
| 7094 | /* |
| 7095 | * The Misc part at the end |
| 7096 | */ |
| 7097 | xmlParseMisc(ctxt); |
| 7098 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7099 | if (RAW != 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7100 | ctxt->errNo = XML_ERR_DOCUMENT_END; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7101 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7102 | ctxt->sax->error(ctxt->userData, |
| 7103 | "Extra content at the end of the document\n"); |
| 7104 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7105 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7106 | } |
| 7107 | ctxt->instate = XML_PARSER_EOF; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7108 | } |
| 7109 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7110 | /* |
| 7111 | * SAX: end of the document processing. |
| 7112 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7113 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL) && |
| 7114 | (!ctxt->disableSAX)) |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 7115 | ctxt->sax->endDocument(ctxt->userData); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7116 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 7117 | if (! ctxt->wellFormed) return(-1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7118 | return(0); |
| 7119 | } |
| 7120 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7121 | /** |
| 7122 | * xmlParseExtParsedEnt: |
| 7123 | * @ctxt: an XML parser context |
| 7124 | * |
| 7125 | * parse a genreral parsed entity |
| 7126 | * An external general parsed entity is well-formed if it matches the |
| 7127 | * production labeled extParsedEnt. |
| 7128 | * |
| 7129 | * [78] extParsedEnt ::= TextDecl? content |
| 7130 | * |
| 7131 | * Returns 0, -1 in case of error. the parser context is augmented |
| 7132 | * as a result of the parsing. |
| 7133 | */ |
| 7134 | |
| 7135 | int |
| 7136 | xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { |
| 7137 | xmlChar start[4]; |
| 7138 | xmlCharEncoding enc; |
| 7139 | |
| 7140 | xmlDefaultSAXHandlerInit(); |
| 7141 | |
| 7142 | GROW; |
| 7143 | |
| 7144 | /* |
| 7145 | * SAX: beginning of the document processing. |
| 7146 | */ |
| 7147 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
| 7148 | ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); |
| 7149 | |
| 7150 | /* |
| 7151 | * Get the 4 first bytes and decode the charset |
| 7152 | * if enc != XML_CHAR_ENCODING_NONE |
| 7153 | * plug some encoding conversion routines. |
| 7154 | */ |
| 7155 | start[0] = RAW; |
| 7156 | start[1] = NXT(1); |
| 7157 | start[2] = NXT(2); |
| 7158 | start[3] = NXT(3); |
| 7159 | enc = xmlDetectCharEncoding(start, 4); |
| 7160 | if (enc != XML_CHAR_ENCODING_NONE) { |
| 7161 | xmlSwitchEncoding(ctxt, enc); |
| 7162 | } |
| 7163 | |
| 7164 | |
| 7165 | if (CUR == 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7166 | ctxt->errNo = XML_ERR_DOCUMENT_EMPTY; |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7167 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7168 | ctxt->sax->error(ctxt->userData, "Document is empty\n"); |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7169 | ctxt->wellFormed = 0; |
| 7170 | ctxt->disableSAX = 1; |
| 7171 | } |
| 7172 | |
| 7173 | /* |
| 7174 | * Check for the XMLDecl in the Prolog. |
| 7175 | */ |
| 7176 | GROW; |
| 7177 | if ((RAW == '<') && (NXT(1) == '?') && |
| 7178 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 7179 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 7180 | |
| 7181 | /* |
| 7182 | * Note that we will switch encoding on the fly. |
| 7183 | */ |
| 7184 | xmlParseXMLDecl(ctxt); |
| 7185 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 7186 | /* |
| 7187 | * The XML REC instructs us to stop parsing right here |
| 7188 | */ |
| 7189 | return(-1); |
| 7190 | } |
| 7191 | SKIP_BLANKS; |
| 7192 | } else { |
| 7193 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); |
| 7194 | } |
| 7195 | if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) |
| 7196 | ctxt->sax->startDocument(ctxt->userData); |
| 7197 | |
| 7198 | /* |
| 7199 | * Doing validity checking on chunk doesn't make sense |
| 7200 | */ |
| 7201 | ctxt->instate = XML_PARSER_CONTENT; |
| 7202 | ctxt->validate = 0; |
| 7203 | ctxt->depth = 0; |
| 7204 | |
| 7205 | xmlParseContent(ctxt); |
| 7206 | |
| 7207 | if ((RAW == '<') && (NXT(1) == '/')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7208 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7209 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7210 | ctxt->sax->error(ctxt->userData, |
| 7211 | "chunk is not well balanced\n"); |
| 7212 | ctxt->wellFormed = 0; |
| 7213 | ctxt->disableSAX = 1; |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7214 | } else if (RAW != 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7215 | ctxt->errNo = XML_ERR_EXTRA_CONTENT; |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7216 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7217 | ctxt->sax->error(ctxt->userData, |
| 7218 | "extra content at the end of well balanced chunk\n"); |
| 7219 | ctxt->wellFormed = 0; |
| 7220 | ctxt->disableSAX = 1; |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | /* |
| 7224 | * SAX: end of the document processing. |
| 7225 | */ |
| 7226 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL) && |
| 7227 | (!ctxt->disableSAX)) |
| 7228 | ctxt->sax->endDocument(ctxt->userData); |
| 7229 | |
| 7230 | if (! ctxt->wellFormed) return(-1); |
| 7231 | return(0); |
| 7232 | } |
| 7233 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 7234 | /************************************************************************ |
| 7235 | * * |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7236 | * Progressive parsing interfaces * |
| 7237 | * * |
| 7238 | ************************************************************************/ |
| 7239 | |
| 7240 | /** |
| 7241 | * xmlParseLookupSequence: |
| 7242 | * @ctxt: an XML parser context |
| 7243 | * @first: the first char to lookup |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7244 | * @next: the next char to lookup or zero |
| 7245 | * @third: the next char to lookup or zero |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7246 | * |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7247 | * Try to find if a sequence (first, next, third) or just (first next) or |
| 7248 | * (first) is available in the input stream. |
| 7249 | * This function has a side effect of (possibly) incrementing ctxt->checkIndex |
| 7250 | * to avoid rescanning sequences of bytes, it DOES change the state of the |
| 7251 | * parser, do not use liberally. |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7252 | * |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7253 | * Returns the index to the current parsing point if the full sequence |
| 7254 | * is available, -1 otherwise. |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7255 | */ |
| 7256 | int |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7257 | xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar first, |
| 7258 | xmlChar next, xmlChar third) { |
| 7259 | int base, len; |
| 7260 | xmlParserInputPtr in; |
| 7261 | const xmlChar *buf; |
| 7262 | |
| 7263 | in = ctxt->input; |
| 7264 | if (in == NULL) return(-1); |
| 7265 | base = in->cur - in->base; |
| 7266 | if (base < 0) return(-1); |
| 7267 | if (ctxt->checkIndex > base) |
| 7268 | base = ctxt->checkIndex; |
| 7269 | if (in->buf == NULL) { |
| 7270 | buf = in->base; |
| 7271 | len = in->length; |
| 7272 | } else { |
| 7273 | buf = in->buf->buffer->content; |
| 7274 | len = in->buf->buffer->use; |
| 7275 | } |
| 7276 | /* take into account the sequence length */ |
| 7277 | if (third) len -= 2; |
| 7278 | else if (next) len --; |
| 7279 | for (;base < len;base++) { |
| 7280 | if (buf[base] == first) { |
| 7281 | if (third != 0) { |
| 7282 | if ((buf[base + 1] != next) || |
| 7283 | (buf[base + 2] != third)) continue; |
| 7284 | } else if (next != 0) { |
| 7285 | if (buf[base + 1] != next) continue; |
| 7286 | } |
| 7287 | ctxt->checkIndex = 0; |
| 7288 | #ifdef DEBUG_PUSH |
| 7289 | if (next == 0) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7290 | xmlGenericError(xmlGenericErrorContext, |
| 7291 | "PP: lookup '%c' found at %d\n", |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7292 | first, base); |
| 7293 | else if (third == 0) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7294 | xmlGenericError(xmlGenericErrorContext, |
| 7295 | "PP: lookup '%c%c' found at %d\n", |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7296 | first, next, base); |
| 7297 | else |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7298 | xmlGenericError(xmlGenericErrorContext, |
| 7299 | "PP: lookup '%c%c%c' found at %d\n", |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7300 | first, next, third, base); |
| 7301 | #endif |
| 7302 | return(base - (in->cur - in->base)); |
| 7303 | } |
| 7304 | } |
| 7305 | ctxt->checkIndex = base; |
| 7306 | #ifdef DEBUG_PUSH |
| 7307 | if (next == 0) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7308 | xmlGenericError(xmlGenericErrorContext, |
| 7309 | "PP: lookup '%c' failed\n", first); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7310 | else if (third == 0) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7311 | xmlGenericError(xmlGenericErrorContext, |
| 7312 | "PP: lookup '%c%c' failed\n", first, next); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7313 | else |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7314 | xmlGenericError(xmlGenericErrorContext, |
| 7315 | "PP: lookup '%c%c%c' failed\n", first, next, third); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7316 | #endif |
| 7317 | return(-1); |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7318 | } |
| 7319 | |
| 7320 | /** |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7321 | * xmlParseTryOrFinish: |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7322 | * @ctxt: an XML parser context |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7323 | * @terminate: last chunk indicator |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7324 | * |
| 7325 | * Try to progress on parsing |
| 7326 | * |
| 7327 | * Returns zero if no parsing was possible |
| 7328 | */ |
| 7329 | int |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7330 | xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7331 | int ret = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7332 | int avail; |
| 7333 | xmlChar cur, next; |
| 7334 | |
| 7335 | #ifdef DEBUG_PUSH |
| 7336 | switch (ctxt->instate) { |
| 7337 | case XML_PARSER_EOF: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7338 | xmlGenericError(xmlGenericErrorContext, |
| 7339 | "PP: try EOF\n"); break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7340 | case XML_PARSER_START: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7341 | xmlGenericError(xmlGenericErrorContext, |
| 7342 | "PP: try START\n"); break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7343 | case XML_PARSER_MISC: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7344 | xmlGenericError(xmlGenericErrorContext, |
| 7345 | "PP: try MISC\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7346 | case XML_PARSER_COMMENT: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7347 | xmlGenericError(xmlGenericErrorContext, |
| 7348 | "PP: try COMMENT\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7349 | case XML_PARSER_PROLOG: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7350 | xmlGenericError(xmlGenericErrorContext, |
| 7351 | "PP: try PROLOG\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7352 | case XML_PARSER_START_TAG: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7353 | xmlGenericError(xmlGenericErrorContext, |
| 7354 | "PP: try START_TAG\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7355 | case XML_PARSER_CONTENT: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7356 | xmlGenericError(xmlGenericErrorContext, |
| 7357 | "PP: try CONTENT\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7358 | case XML_PARSER_CDATA_SECTION: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7359 | xmlGenericError(xmlGenericErrorContext, |
| 7360 | "PP: try CDATA_SECTION\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7361 | case XML_PARSER_END_TAG: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7362 | xmlGenericError(xmlGenericErrorContext, |
| 7363 | "PP: try END_TAG\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7364 | case XML_PARSER_ENTITY_DECL: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7365 | xmlGenericError(xmlGenericErrorContext, |
| 7366 | "PP: try ENTITY_DECL\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7367 | case XML_PARSER_ENTITY_VALUE: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7368 | xmlGenericError(xmlGenericErrorContext, |
| 7369 | "PP: try ENTITY_VALUE\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7370 | case XML_PARSER_ATTRIBUTE_VALUE: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7371 | xmlGenericError(xmlGenericErrorContext, |
| 7372 | "PP: try ATTRIBUTE_VALUE\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7373 | case XML_PARSER_DTD: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7374 | xmlGenericError(xmlGenericErrorContext, |
| 7375 | "PP: try DTD\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7376 | case XML_PARSER_EPILOG: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7377 | xmlGenericError(xmlGenericErrorContext, |
| 7378 | "PP: try EPILOG\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7379 | case XML_PARSER_PI: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7380 | xmlGenericError(xmlGenericErrorContext, |
| 7381 | "PP: try PI\n");break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7382 | } |
| 7383 | #endif |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7384 | |
| 7385 | while (1) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7386 | /* |
| 7387 | * Pop-up of finished entities. |
| 7388 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7389 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7390 | xmlPopInput(ctxt); |
| 7391 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7392 | if (ctxt->input ==NULL) break; |
| 7393 | if (ctxt->input->buf == NULL) |
| 7394 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7395 | else |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7396 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7397 | if (avail < 1) |
| 7398 | goto done; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7399 | switch (ctxt->instate) { |
| 7400 | case XML_PARSER_EOF: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7401 | /* |
| 7402 | * Document parsing is done ! |
| 7403 | */ |
| 7404 | goto done; |
| 7405 | case XML_PARSER_START: |
| 7406 | /* |
| 7407 | * Very first chars read from the document flow. |
| 7408 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7409 | cur = ctxt->input->cur[0]; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7410 | if (IS_BLANK(cur)) { |
| 7411 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
| 7412 | ctxt->sax->setDocumentLocator(ctxt->userData, |
| 7413 | &xmlDefaultSAXLocator); |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7414 | ctxt->errNo = XML_ERR_DOCUMENT_START; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7415 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7416 | ctxt->sax->error(ctxt->userData, |
| 7417 | "Extra spaces at the beginning of the document are not allowed\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7418 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7419 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7420 | SKIP_BLANKS; |
| 7421 | ret++; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7422 | if (ctxt->input->buf == NULL) |
| 7423 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7424 | else |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7425 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7426 | } |
| 7427 | if (avail < 2) |
| 7428 | goto done; |
| 7429 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7430 | cur = ctxt->input->cur[0]; |
| 7431 | next = ctxt->input->cur[1]; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7432 | if (cur == 0) { |
| 7433 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
| 7434 | ctxt->sax->setDocumentLocator(ctxt->userData, |
| 7435 | &xmlDefaultSAXLocator); |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7436 | ctxt->errNo = XML_ERR_DOCUMENT_EMPTY; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7437 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7438 | ctxt->sax->error(ctxt->userData, "Document is empty\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7439 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7440 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7441 | ctxt->instate = XML_PARSER_EOF; |
| 7442 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7443 | xmlGenericError(xmlGenericErrorContext, |
| 7444 | "PP: entering EOF\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7445 | #endif |
| 7446 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) |
| 7447 | ctxt->sax->endDocument(ctxt->userData); |
| 7448 | goto done; |
| 7449 | } |
| 7450 | if ((cur == '<') && (next == '?')) { |
| 7451 | /* PI or XML decl */ |
| 7452 | if (avail < 5) return(ret); |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7453 | if ((!terminate) && |
| 7454 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7455 | return(ret); |
| 7456 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
| 7457 | ctxt->sax->setDocumentLocator(ctxt->userData, |
| 7458 | &xmlDefaultSAXLocator); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7459 | if ((ctxt->input->cur[2] == 'x') && |
| 7460 | (ctxt->input->cur[3] == 'm') && |
| 7461 | (ctxt->input->cur[4] == 'l') && |
| 7462 | (IS_BLANK(ctxt->input->cur[5]))) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7463 | ret += 5; |
| 7464 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7465 | xmlGenericError(xmlGenericErrorContext, |
| 7466 | "PP: Parsing XML Decl\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7467 | #endif |
| 7468 | xmlParseXMLDecl(ctxt); |
Daniel Veillard | 496a1cf | 2000-05-03 14:20:55 +0000 | [diff] [blame] | 7469 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 7470 | /* |
| 7471 | * The XML REC instructs us to stop parsing right |
| 7472 | * here |
| 7473 | */ |
| 7474 | ctxt->instate = XML_PARSER_EOF; |
| 7475 | return(0); |
| 7476 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7477 | ctxt->standalone = ctxt->input->standalone; |
| 7478 | if ((ctxt->encoding == NULL) && |
| 7479 | (ctxt->input->encoding != NULL)) |
| 7480 | ctxt->encoding = xmlStrdup(ctxt->input->encoding); |
| 7481 | if ((ctxt->sax) && (ctxt->sax->startDocument) && |
| 7482 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7483 | ctxt->sax->startDocument(ctxt->userData); |
| 7484 | ctxt->instate = XML_PARSER_MISC; |
| 7485 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7486 | xmlGenericError(xmlGenericErrorContext, |
| 7487 | "PP: entering MISC\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7488 | #endif |
| 7489 | } else { |
| 7490 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7491 | if ((ctxt->sax) && (ctxt->sax->startDocument) && |
| 7492 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7493 | ctxt->sax->startDocument(ctxt->userData); |
| 7494 | ctxt->instate = XML_PARSER_MISC; |
| 7495 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7496 | xmlGenericError(xmlGenericErrorContext, |
| 7497 | "PP: entering MISC\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7498 | #endif |
| 7499 | } |
| 7500 | } else { |
| 7501 | if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) |
| 7502 | ctxt->sax->setDocumentLocator(ctxt->userData, |
| 7503 | &xmlDefaultSAXLocator); |
| 7504 | ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7505 | if ((ctxt->sax) && (ctxt->sax->startDocument) && |
| 7506 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7507 | ctxt->sax->startDocument(ctxt->userData); |
| 7508 | ctxt->instate = XML_PARSER_MISC; |
| 7509 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7510 | xmlGenericError(xmlGenericErrorContext, |
| 7511 | "PP: entering MISC\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7512 | #endif |
| 7513 | } |
| 7514 | break; |
| 7515 | case XML_PARSER_MISC: |
| 7516 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7517 | if (ctxt->input->buf == NULL) |
| 7518 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7519 | else |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7520 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7521 | if (avail < 2) |
| 7522 | goto done; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7523 | cur = ctxt->input->cur[0]; |
| 7524 | next = ctxt->input->cur[1]; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7525 | if ((cur == '<') && (next == '?')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7526 | if ((!terminate) && |
| 7527 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7528 | goto done; |
| 7529 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7530 | xmlGenericError(xmlGenericErrorContext, |
| 7531 | "PP: Parsing PI\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7532 | #endif |
| 7533 | xmlParsePI(ctxt); |
| 7534 | } else if ((cur == '<') && (next == '!') && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7535 | (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7536 | if ((!terminate) && |
| 7537 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7538 | goto done; |
| 7539 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7540 | xmlGenericError(xmlGenericErrorContext, |
| 7541 | "PP: Parsing Comment\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7542 | #endif |
| 7543 | xmlParseComment(ctxt); |
| 7544 | ctxt->instate = XML_PARSER_MISC; |
| 7545 | } else if ((cur == '<') && (next == '!') && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7546 | (ctxt->input->cur[2] == 'D') && (ctxt->input->cur[3] == 'O') && |
| 7547 | (ctxt->input->cur[4] == 'C') && (ctxt->input->cur[5] == 'T') && |
| 7548 | (ctxt->input->cur[6] == 'Y') && (ctxt->input->cur[7] == 'P') && |
| 7549 | (ctxt->input->cur[8] == 'E')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7550 | if ((!terminate) && |
| 7551 | (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7552 | goto done; |
| 7553 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7554 | xmlGenericError(xmlGenericErrorContext, |
| 7555 | "PP: Parsing internal subset\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7556 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7557 | ctxt->inSubset = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7558 | xmlParseDocTypeDecl(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7559 | if (RAW == '[') { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7560 | ctxt->instate = XML_PARSER_DTD; |
| 7561 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7562 | xmlGenericError(xmlGenericErrorContext, |
| 7563 | "PP: entering DTD\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7564 | #endif |
| 7565 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7566 | /* |
| 7567 | * Create and update the external subset. |
| 7568 | */ |
| 7569 | ctxt->inSubset = 2; |
| 7570 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
| 7571 | (ctxt->sax->externalSubset != NULL)) |
| 7572 | ctxt->sax->externalSubset(ctxt->userData, |
| 7573 | ctxt->intSubName, ctxt->extSubSystem, |
| 7574 | ctxt->extSubURI); |
| 7575 | ctxt->inSubset = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7576 | ctxt->instate = XML_PARSER_PROLOG; |
| 7577 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7578 | xmlGenericError(xmlGenericErrorContext, |
| 7579 | "PP: entering PROLOG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7580 | #endif |
| 7581 | } |
| 7582 | } else if ((cur == '<') && (next == '!') && |
| 7583 | (avail < 9)) { |
| 7584 | goto done; |
| 7585 | } else { |
| 7586 | ctxt->instate = XML_PARSER_START_TAG; |
| 7587 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7588 | xmlGenericError(xmlGenericErrorContext, |
| 7589 | "PP: entering START_TAG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7590 | #endif |
| 7591 | } |
| 7592 | break; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7593 | case XML_PARSER_PROLOG: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7594 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7595 | if (ctxt->input->buf == NULL) |
| 7596 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7597 | else |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7598 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7599 | if (avail < 2) |
| 7600 | goto done; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7601 | cur = ctxt->input->cur[0]; |
| 7602 | next = ctxt->input->cur[1]; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7603 | if ((cur == '<') && (next == '?')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7604 | if ((!terminate) && |
| 7605 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7606 | goto done; |
| 7607 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7608 | xmlGenericError(xmlGenericErrorContext, |
| 7609 | "PP: Parsing PI\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7610 | #endif |
| 7611 | xmlParsePI(ctxt); |
| 7612 | } else if ((cur == '<') && (next == '!') && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7613 | (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7614 | if ((!terminate) && |
| 7615 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7616 | goto done; |
| 7617 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7618 | xmlGenericError(xmlGenericErrorContext, |
| 7619 | "PP: Parsing Comment\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7620 | #endif |
| 7621 | xmlParseComment(ctxt); |
| 7622 | ctxt->instate = XML_PARSER_PROLOG; |
| 7623 | } else if ((cur == '<') && (next == '!') && |
| 7624 | (avail < 4)) { |
| 7625 | goto done; |
| 7626 | } else { |
| 7627 | ctxt->instate = XML_PARSER_START_TAG; |
| 7628 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7629 | xmlGenericError(xmlGenericErrorContext, |
| 7630 | "PP: entering START_TAG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7631 | #endif |
| 7632 | } |
| 7633 | break; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 7634 | case XML_PARSER_EPILOG: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7635 | SKIP_BLANKS; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7636 | if (ctxt->input->buf == NULL) |
| 7637 | avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7638 | else |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7639 | avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7640 | if (avail < 2) |
| 7641 | goto done; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7642 | cur = ctxt->input->cur[0]; |
| 7643 | next = ctxt->input->cur[1]; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7644 | if ((cur == '<') && (next == '?')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7645 | if ((!terminate) && |
| 7646 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7647 | goto done; |
| 7648 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7649 | xmlGenericError(xmlGenericErrorContext, |
| 7650 | "PP: Parsing PI\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7651 | #endif |
| 7652 | xmlParsePI(ctxt); |
| 7653 | ctxt->instate = XML_PARSER_EPILOG; |
| 7654 | } else if ((cur == '<') && (next == '!') && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7655 | (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7656 | if ((!terminate) && |
| 7657 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7658 | goto done; |
| 7659 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7660 | xmlGenericError(xmlGenericErrorContext, |
| 7661 | "PP: Parsing Comment\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7662 | #endif |
| 7663 | xmlParseComment(ctxt); |
| 7664 | ctxt->instate = XML_PARSER_EPILOG; |
| 7665 | } else if ((cur == '<') && (next == '!') && |
| 7666 | (avail < 4)) { |
| 7667 | goto done; |
| 7668 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7669 | ctxt->errNo = XML_ERR_DOCUMENT_END; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7670 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7671 | ctxt->sax->error(ctxt->userData, |
| 7672 | "Extra content at the end of the document\n"); |
| 7673 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7674 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7675 | ctxt->instate = XML_PARSER_EOF; |
| 7676 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7677 | xmlGenericError(xmlGenericErrorContext, |
| 7678 | "PP: entering EOF\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7679 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7680 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL) && |
| 7681 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7682 | ctxt->sax->endDocument(ctxt->userData); |
| 7683 | goto done; |
| 7684 | } |
| 7685 | break; |
| 7686 | case XML_PARSER_START_TAG: { |
| 7687 | xmlChar *name, *oldname; |
| 7688 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7689 | if ((avail < 2) && (ctxt->inputNr == 1)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7690 | goto done; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7691 | cur = ctxt->input->cur[0]; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7692 | if (cur != '<') { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7693 | ctxt->errNo = XML_ERR_DOCUMENT_EMPTY; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7694 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7695 | ctxt->sax->error(ctxt->userData, |
| 7696 | "Start tag expect, '<' not found\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7697 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7698 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7699 | ctxt->instate = XML_PARSER_EOF; |
| 7700 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7701 | xmlGenericError(xmlGenericErrorContext, |
| 7702 | "PP: entering EOF\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7703 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7704 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL) && |
| 7705 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7706 | ctxt->sax->endDocument(ctxt->userData); |
| 7707 | goto done; |
| 7708 | } |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7709 | if ((!terminate) && |
| 7710 | (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7711 | goto done; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7712 | if (ctxt->spaceNr == 0) |
| 7713 | spacePush(ctxt, -1); |
| 7714 | else |
| 7715 | spacePush(ctxt, *ctxt->space); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7716 | name = xmlParseStartTag(ctxt); |
| 7717 | if (name == NULL) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7718 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7719 | ctxt->instate = XML_PARSER_EOF; |
| 7720 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7721 | xmlGenericError(xmlGenericErrorContext, |
| 7722 | "PP: entering EOF\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7723 | #endif |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7724 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL) && |
| 7725 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7726 | ctxt->sax->endDocument(ctxt->userData); |
| 7727 | goto done; |
| 7728 | } |
| 7729 | namePush(ctxt, xmlStrdup(name)); |
| 7730 | |
| 7731 | /* |
| 7732 | * [ VC: Root Element Type ] |
| 7733 | * The Name in the document type declaration must match |
| 7734 | * the element type of the root element. |
| 7735 | */ |
| 7736 | if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7737 | ctxt->node && (ctxt->node == ctxt->myDoc->children)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7738 | ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); |
| 7739 | |
| 7740 | /* |
| 7741 | * Check for an Empty Element. |
| 7742 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7743 | if ((RAW == '/') && (NXT(1) == '>')) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7744 | SKIP(2); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7745 | if ((ctxt->sax != NULL) && |
| 7746 | (ctxt->sax->endElement != NULL) && (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7747 | ctxt->sax->endElement(ctxt->userData, name); |
| 7748 | xmlFree(name); |
| 7749 | oldname = namePop(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7750 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7751 | if (oldname != NULL) { |
| 7752 | #ifdef DEBUG_STACK |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7753 | xmlGenericError(xmlGenericErrorContext,"Close: popped %s\n", oldname); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7754 | #endif |
| 7755 | xmlFree(oldname); |
| 7756 | } |
| 7757 | if (ctxt->name == NULL) { |
| 7758 | ctxt->instate = XML_PARSER_EPILOG; |
| 7759 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7760 | xmlGenericError(xmlGenericErrorContext, |
| 7761 | "PP: entering EPILOG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7762 | #endif |
| 7763 | } else { |
| 7764 | ctxt->instate = XML_PARSER_CONTENT; |
| 7765 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7766 | xmlGenericError(xmlGenericErrorContext, |
| 7767 | "PP: entering CONTENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7768 | #endif |
| 7769 | } |
| 7770 | break; |
| 7771 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7772 | if (RAW == '>') { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7773 | NEXT; |
| 7774 | } else { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7775 | ctxt->errNo = XML_ERR_GT_REQUIRED; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7776 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7777 | ctxt->sax->error(ctxt->userData, |
| 7778 | "Couldn't find end of Start Tag %s\n", |
| 7779 | name); |
| 7780 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7781 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7782 | |
| 7783 | /* |
| 7784 | * end of parsing of this node. |
| 7785 | */ |
| 7786 | nodePop(ctxt); |
| 7787 | oldname = namePop(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7788 | spacePop(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7789 | if (oldname != NULL) { |
| 7790 | #ifdef DEBUG_STACK |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7791 | xmlGenericError(xmlGenericErrorContext,"Close: popped %s\n", oldname); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7792 | #endif |
| 7793 | xmlFree(oldname); |
| 7794 | } |
| 7795 | } |
| 7796 | xmlFree(name); |
| 7797 | ctxt->instate = XML_PARSER_CONTENT; |
| 7798 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7799 | xmlGenericError(xmlGenericErrorContext, |
| 7800 | "PP: entering CONTENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7801 | #endif |
| 7802 | break; |
| 7803 | } |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 7804 | case XML_PARSER_CONTENT: { |
| 7805 | const xmlChar *test; |
| 7806 | int cons; |
| 7807 | xmlChar tok; |
| 7808 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7809 | /* |
| 7810 | * Handle preparsed entities and charRef |
| 7811 | */ |
| 7812 | if (ctxt->token != 0) { |
| 7813 | xmlChar cur[2] = { 0 , 0 } ; |
| 7814 | |
| 7815 | cur[0] = (xmlChar) ctxt->token; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7816 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
| 7817 | (ctxt->sax->characters != NULL)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7818 | ctxt->sax->characters(ctxt->userData, cur, 1); |
| 7819 | ctxt->token = 0; |
| 7820 | } |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7821 | if ((avail < 2) && (ctxt->inputNr == 1)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7822 | goto done; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7823 | cur = ctxt->input->cur[0]; |
| 7824 | next = ctxt->input->cur[1]; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 7825 | |
| 7826 | test = CUR_PTR; |
| 7827 | cons = ctxt->input->consumed; |
| 7828 | tok = ctxt->token; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7829 | if ((cur == '<') && (next == '?')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7830 | if ((!terminate) && |
| 7831 | (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7832 | goto done; |
| 7833 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7834 | xmlGenericError(xmlGenericErrorContext, |
| 7835 | "PP: Parsing PI\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7836 | #endif |
| 7837 | xmlParsePI(ctxt); |
| 7838 | } else if ((cur == '<') && (next == '!') && |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7839 | (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7840 | if ((!terminate) && |
| 7841 | (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7842 | goto done; |
| 7843 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7844 | xmlGenericError(xmlGenericErrorContext, |
| 7845 | "PP: Parsing Comment\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7846 | #endif |
| 7847 | xmlParseComment(ctxt); |
| 7848 | ctxt->instate = XML_PARSER_CONTENT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7849 | } else if ((cur == '<') && (ctxt->input->cur[1] == '!') && |
| 7850 | (ctxt->input->cur[2] == '[') && (NXT(3) == 'C') && |
| 7851 | (ctxt->input->cur[4] == 'D') && (NXT(5) == 'A') && |
| 7852 | (ctxt->input->cur[6] == 'T') && (NXT(7) == 'A') && |
| 7853 | (ctxt->input->cur[8] == '[')) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7854 | SKIP(9); |
| 7855 | ctxt->instate = XML_PARSER_CDATA_SECTION; |
| 7856 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7857 | xmlGenericError(xmlGenericErrorContext, |
| 7858 | "PP: entering CDATA_SECTION\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7859 | #endif |
| 7860 | break; |
| 7861 | } else if ((cur == '<') && (next == '!') && |
| 7862 | (avail < 9)) { |
| 7863 | goto done; |
| 7864 | } else if ((cur == '<') && (next == '/')) { |
| 7865 | ctxt->instate = XML_PARSER_END_TAG; |
| 7866 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7867 | xmlGenericError(xmlGenericErrorContext, |
| 7868 | "PP: entering END_TAG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7869 | #endif |
| 7870 | break; |
| 7871 | } else if (cur == '<') { |
| 7872 | ctxt->instate = XML_PARSER_START_TAG; |
| 7873 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7874 | xmlGenericError(xmlGenericErrorContext, |
| 7875 | "PP: entering START_TAG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7876 | #endif |
| 7877 | break; |
| 7878 | } else if (cur == '&') { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7879 | if ((!terminate) && |
| 7880 | (xmlParseLookupSequence(ctxt, ';', 0, 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7881 | goto done; |
| 7882 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7883 | xmlGenericError(xmlGenericErrorContext, |
| 7884 | "PP: Parsing Reference\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7885 | #endif |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7886 | xmlParseReference(ctxt); |
| 7887 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7888 | /* TODO Avoid the extra copy, handle directly !!! */ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7889 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7890 | * Goal of the following test is: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7891 | * - minimize calls to the SAX 'character' callback |
| 7892 | * when they are mergeable |
| 7893 | * - handle an problem for isBlank when we only parse |
| 7894 | * a sequence of blank chars and the next one is |
| 7895 | * not available to check against '<' presence. |
| 7896 | * - tries to homogenize the differences in SAX |
| 7897 | * callbacks beween the push and pull versions |
| 7898 | * of the parser. |
| 7899 | */ |
| 7900 | if ((ctxt->inputNr == 1) && |
| 7901 | (avail < XML_PARSER_BIG_BUFFER_SIZE)) { |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7902 | if ((!terminate) && |
| 7903 | (xmlParseLookupSequence(ctxt, '<', 0, 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7904 | goto done; |
| 7905 | } |
| 7906 | ctxt->checkIndex = 0; |
| 7907 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7908 | xmlGenericError(xmlGenericErrorContext, |
| 7909 | "PP: Parsing char data\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7910 | #endif |
| 7911 | xmlParseCharData(ctxt, 0); |
| 7912 | } |
| 7913 | /* |
| 7914 | * Pop-up of finished entities. |
| 7915 | */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7916 | while ((RAW == 0) && (ctxt->inputNr > 1)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7917 | xmlPopInput(ctxt); |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 7918 | if ((cons == ctxt->input->consumed) && (test == CUR_PTR) && |
| 7919 | (tok == ctxt->token)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 7920 | ctxt->errNo = XML_ERR_INTERNAL_ERROR; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 7921 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 7922 | ctxt->sax->error(ctxt->userData, |
| 7923 | "detected an error in element content\n"); |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 7924 | ctxt->wellFormed = 0; |
| 7925 | ctxt->disableSAX = 1; |
| 7926 | ctxt->instate = XML_PARSER_EOF; |
| 7927 | break; |
| 7928 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7929 | break; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 7930 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7931 | case XML_PARSER_CDATA_SECTION: { |
| 7932 | /* |
| 7933 | * The Push mode need to have the SAX callback for |
| 7934 | * cdataBlock merge back contiguous callbacks. |
| 7935 | */ |
| 7936 | int base; |
| 7937 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7938 | base = xmlParseLookupSequence(ctxt, ']', ']', '>'); |
| 7939 | if (base < 0) { |
| 7940 | if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7941 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7942 | if (ctxt->sax->cdataBlock != NULL) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7943 | ctxt->sax->cdataBlock(ctxt->userData, ctxt->input->cur, |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7944 | XML_PARSER_BIG_BUFFER_SIZE); |
| 7945 | } |
| 7946 | SKIP(XML_PARSER_BIG_BUFFER_SIZE); |
| 7947 | ctxt->checkIndex = 0; |
| 7948 | } |
| 7949 | goto done; |
| 7950 | } else { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7951 | if ((ctxt->sax != NULL) && (base > 0) && |
| 7952 | (!ctxt->disableSAX)) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7953 | if (ctxt->sax->cdataBlock != NULL) |
| 7954 | ctxt->sax->cdataBlock(ctxt->userData, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 7955 | ctxt->input->cur, base); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7956 | } |
| 7957 | SKIP(base + 3); |
| 7958 | ctxt->checkIndex = 0; |
| 7959 | ctxt->instate = XML_PARSER_CONTENT; |
| 7960 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7961 | xmlGenericError(xmlGenericErrorContext, |
| 7962 | "PP: entering CONTENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7963 | #endif |
| 7964 | } |
| 7965 | break; |
| 7966 | } |
Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 7967 | case XML_PARSER_END_TAG: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7968 | if (avail < 2) |
| 7969 | goto done; |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 7970 | if ((!terminate) && |
| 7971 | (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7972 | goto done; |
| 7973 | xmlParseEndTag(ctxt); |
| 7974 | if (ctxt->name == NULL) { |
| 7975 | ctxt->instate = XML_PARSER_EPILOG; |
| 7976 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7977 | xmlGenericError(xmlGenericErrorContext, |
| 7978 | "PP: entering EPILOG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7979 | #endif |
| 7980 | } else { |
| 7981 | ctxt->instate = XML_PARSER_CONTENT; |
| 7982 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 7983 | xmlGenericError(xmlGenericErrorContext, |
| 7984 | "PP: entering CONTENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7985 | #endif |
| 7986 | } |
| 7987 | break; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 7988 | case XML_PARSER_DTD: { |
| 7989 | /* |
| 7990 | * Sorry but progressive parsing of the internal subset |
| 7991 | * is not expected to be supported. We first check that |
| 7992 | * the full content of the internal subset is available and |
| 7993 | * the parsing is launched only at that point. |
| 7994 | * Internal subset ends up with "']' S? '>'" in an unescaped |
| 7995 | * section and not in a ']]>' sequence which are conditional |
| 7996 | * sections (whoever argued to keep that crap in XML deserve |
| 7997 | * a place in hell !). |
| 7998 | */ |
| 7999 | int base, i; |
| 8000 | xmlChar *buf; |
| 8001 | xmlChar quote = 0; |
| 8002 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8003 | base = ctxt->input->cur - ctxt->input->base; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8004 | if (base < 0) return(0); |
| 8005 | if (ctxt->checkIndex > base) |
| 8006 | base = ctxt->checkIndex; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8007 | buf = ctxt->input->buf->buffer->content; |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 8008 | for (;(unsigned int) base < ctxt->input->buf->buffer->use; |
| 8009 | base++) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8010 | if (quote != 0) { |
| 8011 | if (buf[base] == quote) |
| 8012 | quote = 0; |
| 8013 | continue; |
| 8014 | } |
| 8015 | if (buf[base] == '"') { |
| 8016 | quote = '"'; |
| 8017 | continue; |
| 8018 | } |
| 8019 | if (buf[base] == '\'') { |
| 8020 | quote = '\''; |
| 8021 | continue; |
| 8022 | } |
| 8023 | if (buf[base] == ']') { |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 8024 | if ((unsigned int) base +1 >= |
| 8025 | ctxt->input->buf->buffer->use) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8026 | break; |
| 8027 | if (buf[base + 1] == ']') { |
| 8028 | /* conditional crap, skip both ']' ! */ |
| 8029 | base++; |
| 8030 | continue; |
| 8031 | } |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 8032 | for (i = 0; |
| 8033 | (unsigned int) base + i < ctxt->input->buf->buffer->use; |
| 8034 | i++) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8035 | if (buf[base + i] == '>') |
| 8036 | goto found_end_int_subset; |
| 8037 | } |
| 8038 | break; |
| 8039 | } |
| 8040 | } |
| 8041 | /* |
| 8042 | * We didn't found the end of the Internal subset |
| 8043 | */ |
| 8044 | if (quote == 0) |
| 8045 | ctxt->checkIndex = base; |
| 8046 | #ifdef DEBUG_PUSH |
| 8047 | if (next == 0) |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8048 | xmlGenericError(xmlGenericErrorContext, |
| 8049 | "PP: lookup of int subset end filed\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8050 | #endif |
| 8051 | goto done; |
| 8052 | |
| 8053 | found_end_int_subset: |
| 8054 | xmlParseInternalSubset(ctxt); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8055 | ctxt->inSubset = 2; |
| 8056 | if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
| 8057 | (ctxt->sax->externalSubset != NULL)) |
| 8058 | ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName, |
| 8059 | ctxt->extSubSystem, ctxt->extSubURI); |
| 8060 | ctxt->inSubset = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8061 | ctxt->instate = XML_PARSER_PROLOG; |
| 8062 | ctxt->checkIndex = 0; |
| 8063 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8064 | xmlGenericError(xmlGenericErrorContext, |
| 8065 | "PP: entering PROLOG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8066 | #endif |
| 8067 | break; |
| 8068 | } |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 8069 | case XML_PARSER_COMMENT: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8070 | xmlGenericError(xmlGenericErrorContext, |
| 8071 | "PP: internal error, state == COMMENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8072 | ctxt->instate = XML_PARSER_CONTENT; |
| 8073 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8074 | xmlGenericError(xmlGenericErrorContext, |
| 8075 | "PP: entering CONTENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8076 | #endif |
| 8077 | break; |
| 8078 | case XML_PARSER_PI: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8079 | xmlGenericError(xmlGenericErrorContext, |
| 8080 | "PP: internal error, state == PI\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8081 | ctxt->instate = XML_PARSER_CONTENT; |
| 8082 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8083 | xmlGenericError(xmlGenericErrorContext, |
| 8084 | "PP: entering CONTENT\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8085 | #endif |
| 8086 | break; |
| 8087 | case XML_PARSER_ENTITY_DECL: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8088 | xmlGenericError(xmlGenericErrorContext, |
| 8089 | "PP: internal error, state == ENTITY_DECL\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8090 | ctxt->instate = XML_PARSER_DTD; |
| 8091 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8092 | xmlGenericError(xmlGenericErrorContext, |
| 8093 | "PP: entering DTD\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8094 | #endif |
| 8095 | break; |
| 8096 | case XML_PARSER_ENTITY_VALUE: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8097 | xmlGenericError(xmlGenericErrorContext, |
| 8098 | "PP: internal error, state == ENTITY_VALUE\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8099 | ctxt->instate = XML_PARSER_CONTENT; |
| 8100 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8101 | xmlGenericError(xmlGenericErrorContext, |
| 8102 | "PP: entering DTD\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8103 | #endif |
| 8104 | break; |
| 8105 | case XML_PARSER_ATTRIBUTE_VALUE: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8106 | xmlGenericError(xmlGenericErrorContext, |
| 8107 | "PP: internal error, state == ATTRIBUTE_VALUE\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8108 | ctxt->instate = XML_PARSER_START_TAG; |
| 8109 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8110 | xmlGenericError(xmlGenericErrorContext, |
| 8111 | "PP: entering START_TAG\n"); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8112 | #endif |
| 8113 | break; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8114 | case XML_PARSER_SYSTEM_LITERAL: |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8115 | xmlGenericError(xmlGenericErrorContext, |
| 8116 | "PP: internal error, state == SYSTEM_LITERAL\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8117 | ctxt->instate = XML_PARSER_START_TAG; |
| 8118 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8119 | xmlGenericError(xmlGenericErrorContext, |
| 8120 | "PP: entering START_TAG\n"); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8121 | #endif |
| 8122 | break; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 8123 | } |
| 8124 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8125 | done: |
| 8126 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8127 | xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8128 | #endif |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 8129 | return(ret); |
| 8130 | } |
| 8131 | |
| 8132 | /** |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 8133 | * xmlParseTry: |
| 8134 | * @ctxt: an XML parser context |
| 8135 | * |
| 8136 | * Try to progress on parsing |
| 8137 | * |
| 8138 | * Returns zero if no parsing was possible |
| 8139 | */ |
| 8140 | int |
| 8141 | xmlParseTry(xmlParserCtxtPtr ctxt) { |
| 8142 | return(xmlParseTryOrFinish(ctxt, 0)); |
| 8143 | } |
| 8144 | |
| 8145 | /** |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 8146 | * xmlParseChunk: |
| 8147 | * @ctxt: an XML parser context |
| 8148 | * @chunk: an char array |
| 8149 | * @size: the size in byte of the chunk |
| 8150 | * @terminate: last chunk indicator |
| 8151 | * |
| 8152 | * Parse a Chunk of memory |
| 8153 | * |
| 8154 | * Returns zero if no error, the xmlParserErrors otherwise. |
| 8155 | */ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8156 | int |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 8157 | xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, |
| 8158 | int terminate) { |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 8159 | if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8160 | (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { |
| 8161 | int base = ctxt->input->base - ctxt->input->buf->buffer->content; |
| 8162 | int cur = ctxt->input->cur - ctxt->input->base; |
| 8163 | |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 8164 | xmlParserInputBufferPush(ctxt->input->buf, size, chunk); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8165 | ctxt->input->base = ctxt->input->buf->buffer->content + base; |
| 8166 | ctxt->input->cur = ctxt->input->base + cur; |
| 8167 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8168 | xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8169 | #endif |
| 8170 | |
Daniel Veillard | d0f7f74 | 2000-02-02 17:42:48 +0000 | [diff] [blame] | 8171 | if ((terminate) || (ctxt->input->buf->buffer->use > 80)) |
| 8172 | xmlParseTryOrFinish(ctxt, terminate); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8173 | } else if (ctxt->instate != XML_PARSER_EOF) |
Daniel Veillard | c2def84 | 2000-11-07 14:21:01 +0000 | [diff] [blame^] | 8174 | if ((ctxt->input != NULL) && ctxt->input->buf != NULL) { |
| 8175 | xmlParserInputBufferPtr in = ctxt->input->buf; |
| 8176 | int nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); |
| 8177 | if (nbchars < 0) { |
| 8178 | xmlGenericError(xmlGenericErrorContext, |
| 8179 | "xmlParseChunk: encoder error\n"); |
| 8180 | return(XML_ERR_INVALID_ENCODING); |
| 8181 | } |
| 8182 | } |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 8183 | xmlParseTryOrFinish(ctxt, terminate); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8184 | if (terminate) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8185 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8186 | * Check for termination |
| 8187 | */ |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8188 | if ((ctxt->instate != XML_PARSER_EOF) && |
| 8189 | (ctxt->instate != XML_PARSER_EPILOG)) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8190 | ctxt->errNo = XML_ERR_DOCUMENT_END; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8191 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8192 | ctxt->sax->error(ctxt->userData, |
| 8193 | "Extra content at the end of the document\n"); |
| 8194 | ctxt->wellFormed = 0; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8195 | ctxt->disableSAX = 1; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8196 | } |
| 8197 | if (ctxt->instate != XML_PARSER_EOF) { |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8198 | if ((ctxt->sax) && (ctxt->sax->endDocument != NULL) && |
| 8199 | (!ctxt->disableSAX)) |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8200 | ctxt->sax->endDocument(ctxt->userData); |
| 8201 | } |
| 8202 | ctxt->instate = XML_PARSER_EOF; |
Daniel Veillard | 7f85850 | 1999-11-17 17:32:38 +0000 | [diff] [blame] | 8203 | } |
| 8204 | return((xmlParserErrors) ctxt->errNo); |
| 8205 | } |
| 8206 | |
| 8207 | /************************************************************************ |
| 8208 | * * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 8209 | * I/O front end functions to the parser * |
| 8210 | * * |
| 8211 | ************************************************************************/ |
| 8212 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 8213 | /** |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 8214 | * xmlStopParser: |
Daniel Veillard | 3f6f7f6 | 2000-06-30 17:58:25 +0000 | [diff] [blame] | 8215 | * @ctxt: an XML parser context |
| 8216 | * |
| 8217 | * Blocks further parser processing |
| 8218 | */ |
| 8219 | void |
| 8220 | xmlStopParser(xmlParserCtxtPtr ctxt) { |
| 8221 | ctxt->instate = XML_PARSER_EOF; |
| 8222 | if (ctxt->input != NULL) |
| 8223 | ctxt->input->cur = BAD_CAST""; |
| 8224 | } |
| 8225 | |
| 8226 | /** |
| 8227 | * xmlCreatePushParserCtxt: |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8228 | * @sax: a SAX handler |
| 8229 | * @user_data: The user data returned on SAX callbacks |
| 8230 | * @chunk: a pointer to an array of chars |
| 8231 | * @size: number of chars in the array |
| 8232 | * @filename: an optional file name or URI |
| 8233 | * |
| 8234 | * Create a parser context for using the XML parser in push mode |
| 8235 | * To allow content encoding detection, @size should be >= 4 |
| 8236 | * The value of @filename is used for fetching external entities |
| 8237 | * and error/warning reports. |
| 8238 | * |
| 8239 | * Returns the new parser context or NULL |
| 8240 | */ |
| 8241 | xmlParserCtxtPtr |
| 8242 | xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, |
| 8243 | const char *chunk, int size, const char *filename) { |
| 8244 | xmlParserCtxtPtr ctxt; |
| 8245 | xmlParserInputPtr inputStream; |
| 8246 | xmlParserInputBufferPtr buf; |
| 8247 | xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; |
| 8248 | |
| 8249 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8250 | * plug some encoding conversion routines |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8251 | */ |
| 8252 | if ((chunk != NULL) && (size >= 4)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8253 | enc = xmlDetectCharEncoding((const xmlChar *) chunk, size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8254 | |
| 8255 | buf = xmlAllocParserInputBuffer(enc); |
| 8256 | if (buf == NULL) return(NULL); |
| 8257 | |
| 8258 | ctxt = xmlNewParserCtxt(); |
| 8259 | if (ctxt == NULL) { |
| 8260 | xmlFree(buf); |
| 8261 | return(NULL); |
| 8262 | } |
| 8263 | if (sax != NULL) { |
| 8264 | if (ctxt->sax != &xmlDefaultSAXHandler) |
| 8265 | xmlFree(ctxt->sax); |
| 8266 | ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); |
| 8267 | if (ctxt->sax == NULL) { |
| 8268 | xmlFree(buf); |
| 8269 | xmlFree(ctxt); |
| 8270 | return(NULL); |
| 8271 | } |
| 8272 | memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); |
| 8273 | if (user_data != NULL) |
| 8274 | ctxt->userData = user_data; |
| 8275 | } |
| 8276 | if (filename == NULL) { |
| 8277 | ctxt->directory = NULL; |
| 8278 | } else { |
| 8279 | ctxt->directory = xmlParserGetDirectory(filename); |
| 8280 | } |
| 8281 | |
| 8282 | inputStream = xmlNewInputStream(ctxt); |
| 8283 | if (inputStream == NULL) { |
| 8284 | xmlFreeParserCtxt(ctxt); |
| 8285 | return(NULL); |
| 8286 | } |
| 8287 | |
| 8288 | if (filename == NULL) |
| 8289 | inputStream->filename = NULL; |
| 8290 | else |
| 8291 | inputStream->filename = xmlMemStrdup(filename); |
| 8292 | inputStream->buf = buf; |
| 8293 | inputStream->base = inputStream->buf->buffer->content; |
| 8294 | inputStream->cur = inputStream->buf->buffer->content; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8295 | if (enc != XML_CHAR_ENCODING_NONE) { |
| 8296 | xmlSwitchEncoding(ctxt, enc); |
| 8297 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8298 | |
| 8299 | inputPush(ctxt, inputStream); |
| 8300 | |
| 8301 | if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && |
| 8302 | (ctxt->input->buf != NULL)) { |
| 8303 | xmlParserInputBufferPush(ctxt->input->buf, size, chunk); |
| 8304 | #ifdef DEBUG_PUSH |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8305 | xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 8306 | #endif |
| 8307 | } |
| 8308 | |
| 8309 | return(ctxt); |
| 8310 | } |
| 8311 | |
| 8312 | /** |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 8313 | * xmlCreateIOParserCtxt: |
| 8314 | * @sax: a SAX handler |
| 8315 | * @user_data: The user data returned on SAX callbacks |
| 8316 | * @ioread: an I/O read function |
| 8317 | * @ioclose: an I/O close function |
| 8318 | * @ioctx: an I/O handler |
| 8319 | * @enc: the charset encoding if known |
| 8320 | * |
| 8321 | * Create a parser context for using the XML parser with an existing |
| 8322 | * I/O stream |
| 8323 | * |
| 8324 | * Returns the new parser context or NULL |
| 8325 | */ |
| 8326 | xmlParserCtxtPtr |
| 8327 | xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, |
| 8328 | xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, |
| 8329 | void *ioctx, xmlCharEncoding enc) { |
| 8330 | xmlParserCtxtPtr ctxt; |
| 8331 | xmlParserInputPtr inputStream; |
| 8332 | xmlParserInputBufferPtr buf; |
| 8333 | |
| 8334 | buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc); |
| 8335 | if (buf == NULL) return(NULL); |
| 8336 | |
| 8337 | ctxt = xmlNewParserCtxt(); |
| 8338 | if (ctxt == NULL) { |
| 8339 | xmlFree(buf); |
| 8340 | return(NULL); |
| 8341 | } |
| 8342 | if (sax != NULL) { |
| 8343 | if (ctxt->sax != &xmlDefaultSAXHandler) |
| 8344 | xmlFree(ctxt->sax); |
| 8345 | ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); |
| 8346 | if (ctxt->sax == NULL) { |
| 8347 | xmlFree(buf); |
| 8348 | xmlFree(ctxt); |
| 8349 | return(NULL); |
| 8350 | } |
| 8351 | memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); |
| 8352 | if (user_data != NULL) |
| 8353 | ctxt->userData = user_data; |
| 8354 | } |
| 8355 | |
| 8356 | inputStream = xmlNewIOInputStream(ctxt, buf, enc); |
| 8357 | if (inputStream == NULL) { |
| 8358 | xmlFreeParserCtxt(ctxt); |
| 8359 | return(NULL); |
| 8360 | } |
| 8361 | inputPush(ctxt, inputStream); |
| 8362 | |
| 8363 | return(ctxt); |
| 8364 | } |
| 8365 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 8366 | /************************************************************************ |
| 8367 | * * |
| 8368 | * Front ends when parsing a Dtd * |
| 8369 | * * |
| 8370 | ************************************************************************/ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 8371 | |
| 8372 | /** |
Daniel Veillard | 2ffc359 | 2000-10-30 15:36:47 +0000 | [diff] [blame] | 8373 | * xmlIOParseDTD: |
| 8374 | * @sax: the SAX handler block or NULL |
| 8375 | * @input: an Input Buffer |
| 8376 | * @enc: the charset encoding if known |
| 8377 | * |
| 8378 | * Load and parse a DTD |
| 8379 | * |
| 8380 | * Returns the resulting xmlDtdPtr or NULL in case of error. |
Daniel Veillard | a4964b7 | 2000-10-31 18:23:44 +0000 | [diff] [blame] | 8381 | * @input will be freed at parsing end. |
Daniel Veillard | 2ffc359 | 2000-10-30 15:36:47 +0000 | [diff] [blame] | 8382 | */ |
| 8383 | |
| 8384 | xmlDtdPtr |
| 8385 | xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, |
| 8386 | xmlCharEncoding enc) { |
| 8387 | xmlDtdPtr ret = NULL; |
| 8388 | xmlParserCtxtPtr ctxt; |
| 8389 | xmlParserInputPtr pinput = NULL; |
| 8390 | |
| 8391 | if (input == NULL) |
| 8392 | return(NULL); |
| 8393 | |
| 8394 | ctxt = xmlNewParserCtxt(); |
| 8395 | if (ctxt == NULL) { |
| 8396 | return(NULL); |
| 8397 | } |
| 8398 | |
| 8399 | /* |
| 8400 | * Set-up the SAX context |
| 8401 | */ |
| 8402 | if (sax != NULL) { |
| 8403 | if (ctxt->sax != NULL) |
| 8404 | xmlFree(ctxt->sax); |
| 8405 | ctxt->sax = sax; |
| 8406 | ctxt->userData = NULL; |
| 8407 | } |
| 8408 | |
| 8409 | /* |
| 8410 | * generate a parser input from the I/O handler |
| 8411 | */ |
| 8412 | |
| 8413 | pinput = xmlNewIOInputStream(ctxt, input, enc); |
| 8414 | if (pinput == NULL) { |
| 8415 | if (sax != NULL) ctxt->sax = NULL; |
| 8416 | xmlFreeParserCtxt(ctxt); |
| 8417 | return(NULL); |
| 8418 | } |
| 8419 | |
| 8420 | /* |
| 8421 | * plug some encoding conversion routines here. |
| 8422 | */ |
| 8423 | xmlPushInput(ctxt, pinput); |
| 8424 | |
| 8425 | pinput->filename = NULL; |
| 8426 | pinput->line = 1; |
| 8427 | pinput->col = 1; |
| 8428 | pinput->base = ctxt->input->cur; |
| 8429 | pinput->cur = ctxt->input->cur; |
| 8430 | pinput->free = NULL; |
| 8431 | |
| 8432 | /* |
| 8433 | * let's parse that entity knowing it's an external subset. |
| 8434 | */ |
| 8435 | ctxt->inSubset = 2; |
| 8436 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); |
| 8437 | ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", |
| 8438 | BAD_CAST "none", BAD_CAST "none"); |
| 8439 | xmlParseExternalSubset(ctxt, BAD_CAST "none", BAD_CAST "none"); |
| 8440 | |
| 8441 | if (ctxt->myDoc != NULL) { |
| 8442 | if (ctxt->wellFormed) { |
| 8443 | ret = ctxt->myDoc->extSubset; |
| 8444 | ctxt->myDoc->extSubset = NULL; |
| 8445 | } else { |
| 8446 | ret = NULL; |
| 8447 | } |
| 8448 | xmlFreeDoc(ctxt->myDoc); |
| 8449 | ctxt->myDoc = NULL; |
| 8450 | } |
| 8451 | if (sax != NULL) ctxt->sax = NULL; |
| 8452 | xmlFreeParserCtxt(ctxt); |
| 8453 | |
| 8454 | return(ret); |
| 8455 | } |
| 8456 | |
| 8457 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8458 | * xmlSAXParseDTD: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8459 | * @sax: the SAX handler block |
| 8460 | * @ExternalID: a NAME* containing the External ID of the DTD |
| 8461 | * @SystemID: a NAME* containing the URL to the DTD |
| 8462 | * |
| 8463 | * Load and parse an external subset. |
| 8464 | * |
| 8465 | * Returns the resulting xmlDtdPtr or NULL in case of error. |
| 8466 | */ |
| 8467 | |
| 8468 | xmlDtdPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 8469 | xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, |
| 8470 | const xmlChar *SystemID) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8471 | xmlDtdPtr ret = NULL; |
| 8472 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 8473 | xmlParserInputPtr input = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8474 | xmlCharEncoding enc; |
| 8475 | |
| 8476 | if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); |
| 8477 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 8478 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8479 | if (ctxt == NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8480 | return(NULL); |
| 8481 | } |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8482 | |
| 8483 | /* |
| 8484 | * Set-up the SAX context |
| 8485 | */ |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8486 | if (sax != NULL) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 8487 | if (ctxt->sax != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 8488 | xmlFree(ctxt->sax); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8489 | ctxt->sax = sax; |
| 8490 | ctxt->userData = NULL; |
| 8491 | } |
| 8492 | |
| 8493 | /* |
| 8494 | * Ask the Entity resolver to load the damn thing |
| 8495 | */ |
| 8496 | |
| 8497 | if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) |
| 8498 | input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, SystemID); |
| 8499 | if (input == NULL) { |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 8500 | if (sax != NULL) ctxt->sax = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8501 | xmlFreeParserCtxt(ctxt); |
| 8502 | return(NULL); |
| 8503 | } |
| 8504 | |
| 8505 | /* |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8506 | * plug some encoding conversion routines here. |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8507 | */ |
| 8508 | xmlPushInput(ctxt, input); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8509 | enc = xmlDetectCharEncoding(ctxt->input->cur, 4); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8510 | xmlSwitchEncoding(ctxt, enc); |
| 8511 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 8512 | if (input->filename == NULL) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8513 | input->filename = (char *) xmlStrdup(SystemID); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8514 | input->line = 1; |
| 8515 | input->col = 1; |
| 8516 | input->base = ctxt->input->cur; |
| 8517 | input->cur = ctxt->input->cur; |
| 8518 | input->free = NULL; |
| 8519 | |
| 8520 | /* |
| 8521 | * let's parse that entity knowing it's an external subset. |
| 8522 | */ |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 8523 | ctxt->inSubset = 2; |
| 8524 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); |
| 8525 | ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", |
| 8526 | ExternalID, SystemID); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8527 | xmlParseExternalSubset(ctxt, ExternalID, SystemID); |
| 8528 | |
| 8529 | if (ctxt->myDoc != NULL) { |
| 8530 | if (ctxt->wellFormed) { |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 8531 | ret = ctxt->myDoc->extSubset; |
| 8532 | ctxt->myDoc->extSubset = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8533 | } else { |
| 8534 | ret = NULL; |
| 8535 | } |
| 8536 | xmlFreeDoc(ctxt->myDoc); |
| 8537 | ctxt->myDoc = NULL; |
| 8538 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 8539 | if (sax != NULL) ctxt->sax = NULL; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8540 | xmlFreeParserCtxt(ctxt); |
| 8541 | |
| 8542 | return(ret); |
| 8543 | } |
| 8544 | |
| 8545 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8546 | * xmlParseDTD: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8547 | * @ExternalID: a NAME* containing the External ID of the DTD |
| 8548 | * @SystemID: a NAME* containing the URL to the DTD |
| 8549 | * |
| 8550 | * Load and parse an external subset. |
| 8551 | * |
| 8552 | * Returns the resulting xmlDtdPtr or NULL in case of error. |
| 8553 | */ |
| 8554 | |
| 8555 | xmlDtdPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 8556 | xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8557 | return(xmlSAXParseDTD(NULL, ExternalID, SystemID)); |
| 8558 | } |
| 8559 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 8560 | /************************************************************************ |
| 8561 | * * |
| 8562 | * Front ends when parsing an Entity * |
| 8563 | * * |
| 8564 | ************************************************************************/ |
| 8565 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 8566 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8567 | * xmlSAXParseBalancedChunk: |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 8568 | * @ctx: an XML parser context (possibly NULL) |
| 8569 | * @sax: the SAX handler bloc (possibly NULL) |
| 8570 | * @user_data: The user data returned on SAX callbacks (possibly NULL) |
| 8571 | * @input: a parser input stream |
| 8572 | * @enc: the encoding |
| 8573 | * |
| 8574 | * Parse a well-balanced chunk of an XML document |
| 8575 | * The user has to provide SAX callback block whose routines will be |
| 8576 | * called by the parser |
| 8577 | * The allowed sequence for the Well Balanced Chunk is the one defined by |
| 8578 | * the content production in the XML grammar: |
| 8579 | * |
| 8580 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* |
| 8581 | * |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8582 | * Returns 0 if the chunk is well balanced, -1 in case of args problem and |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 8583 | * the error code otherwise |
| 8584 | */ |
| 8585 | |
| 8586 | int |
| 8587 | xmlSAXParseBalancedChunk(xmlParserCtxtPtr ctx, xmlSAXHandlerPtr sax, |
| 8588 | void *user_data, xmlParserInputPtr input, |
| 8589 | xmlCharEncoding enc) { |
| 8590 | xmlParserCtxtPtr ctxt; |
| 8591 | int ret; |
| 8592 | |
| 8593 | if (input == NULL) return(-1); |
| 8594 | |
| 8595 | if (ctx != NULL) |
| 8596 | ctxt = ctx; |
| 8597 | else { |
| 8598 | ctxt = xmlNewParserCtxt(); |
| 8599 | if (ctxt == NULL) |
| 8600 | return(-1); |
| 8601 | if (sax == NULL) |
| 8602 | ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); |
| 8603 | } |
| 8604 | |
| 8605 | /* |
| 8606 | * Set-up the SAX context |
| 8607 | */ |
| 8608 | if (sax != NULL) { |
| 8609 | if (ctxt->sax != NULL) |
| 8610 | xmlFree(ctxt->sax); |
| 8611 | ctxt->sax = sax; |
| 8612 | ctxt->userData = user_data; |
| 8613 | } |
| 8614 | |
| 8615 | /* |
| 8616 | * plug some encoding conversion routines here. |
| 8617 | */ |
| 8618 | xmlPushInput(ctxt, input); |
| 8619 | if (enc != XML_CHAR_ENCODING_NONE) |
| 8620 | xmlSwitchEncoding(ctxt, enc); |
| 8621 | |
| 8622 | /* |
| 8623 | * let's parse that entity knowing it's an external subset. |
| 8624 | */ |
| 8625 | xmlParseContent(ctxt); |
| 8626 | ret = ctxt->errNo; |
| 8627 | |
| 8628 | if (ctx == NULL) { |
| 8629 | if (sax != NULL) |
| 8630 | ctxt->sax = NULL; |
| 8631 | else |
| 8632 | xmlFreeDoc(ctxt->myDoc); |
| 8633 | xmlFreeParserCtxt(ctxt); |
| 8634 | } |
| 8635 | return(ret); |
| 8636 | } |
| 8637 | |
| 8638 | /** |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8639 | * xmlParseCtxtExternalEntity: |
| 8640 | * @ctx: the existing parsing context |
| 8641 | * @URL: the URL for the entity to load |
| 8642 | * @ID: the System ID for the entity to load |
| 8643 | * @list: the return value for the set of parsed nodes |
| 8644 | * |
| 8645 | * Parse an external general entity within an existing parsing context |
| 8646 | * An external general parsed entity is well-formed if it matches the |
| 8647 | * production labeled extParsedEnt. |
| 8648 | * |
| 8649 | * [78] extParsedEnt ::= TextDecl? content |
| 8650 | * |
| 8651 | * Returns 0 if the entity is well formed, -1 in case of args problem and |
| 8652 | * the parser error code otherwise |
| 8653 | */ |
| 8654 | |
| 8655 | int |
| 8656 | xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL, |
| 8657 | const xmlChar *ID, xmlNodePtr *list) { |
| 8658 | xmlParserCtxtPtr ctxt; |
| 8659 | xmlDocPtr newDoc; |
| 8660 | xmlSAXHandlerPtr oldsax = NULL; |
| 8661 | int ret = 0; |
| 8662 | |
| 8663 | if (ctx->depth > 40) { |
| 8664 | return(XML_ERR_ENTITY_LOOP); |
| 8665 | } |
| 8666 | |
| 8667 | if (list != NULL) |
| 8668 | *list = NULL; |
| 8669 | if ((URL == NULL) && (ID == NULL)) |
| 8670 | return(-1); |
| 8671 | if (ctx->myDoc == NULL) /* @@ relax but check for dereferences */ |
| 8672 | return(-1); |
| 8673 | |
| 8674 | |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 8675 | ctxt = xmlCreateEntityParserCtxt(URL, ID, NULL); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8676 | if (ctxt == NULL) return(-1); |
| 8677 | ctxt->userData = ctxt; |
| 8678 | oldsax = ctxt->sax; |
| 8679 | ctxt->sax = ctx->sax; |
| 8680 | newDoc = xmlNewDoc(BAD_CAST "1.0"); |
| 8681 | if (newDoc == NULL) { |
| 8682 | xmlFreeParserCtxt(ctxt); |
| 8683 | return(-1); |
| 8684 | } |
| 8685 | if (ctx->myDoc != NULL) { |
| 8686 | newDoc->intSubset = ctx->myDoc->intSubset; |
| 8687 | newDoc->extSubset = ctx->myDoc->extSubset; |
| 8688 | } |
| 8689 | if (ctx->myDoc->URL != NULL) { |
| 8690 | newDoc->URL = xmlStrdup(ctx->myDoc->URL); |
| 8691 | } |
| 8692 | newDoc->children = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); |
| 8693 | if (newDoc->children == NULL) { |
| 8694 | ctxt->sax = oldsax; |
| 8695 | xmlFreeParserCtxt(ctxt); |
| 8696 | newDoc->intSubset = NULL; |
| 8697 | newDoc->extSubset = NULL; |
| 8698 | xmlFreeDoc(newDoc); |
| 8699 | return(-1); |
| 8700 | } |
| 8701 | nodePush(ctxt, newDoc->children); |
| 8702 | if (ctx->myDoc == NULL) { |
| 8703 | ctxt->myDoc = newDoc; |
| 8704 | } else { |
| 8705 | ctxt->myDoc = ctx->myDoc; |
| 8706 | newDoc->children->doc = ctx->myDoc; |
| 8707 | } |
| 8708 | |
| 8709 | /* |
| 8710 | * Parse a possible text declaration first |
| 8711 | */ |
| 8712 | GROW; |
| 8713 | if ((RAW == '<') && (NXT(1) == '?') && |
| 8714 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 8715 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 8716 | xmlParseTextDecl(ctxt); |
| 8717 | } |
| 8718 | |
| 8719 | /* |
| 8720 | * Doing validity checking on chunk doesn't make sense |
| 8721 | */ |
| 8722 | ctxt->instate = XML_PARSER_CONTENT; |
| 8723 | ctxt->validate = ctx->validate; |
| 8724 | ctxt->depth = ctx->depth + 1; |
| 8725 | ctxt->replaceEntities = ctx->replaceEntities; |
| 8726 | if (ctxt->validate) { |
| 8727 | ctxt->vctxt.error = ctx->vctxt.error; |
| 8728 | ctxt->vctxt.warning = ctx->vctxt.warning; |
| 8729 | /* Allocate the Node stack */ |
| 8730 | ctxt->vctxt.nodeTab = (xmlNodePtr *) xmlMalloc(4 * sizeof(xmlNodePtr)); |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 8731 | if (ctxt->vctxt.nodeTab == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 8732 | xmlGenericError(xmlGenericErrorContext, |
| 8733 | "xmlParseCtxtExternalEntity: out of memory\n"); |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 8734 | ctxt->validate = 0; |
| 8735 | ctxt->vctxt.error = NULL; |
| 8736 | ctxt->vctxt.warning = NULL; |
| 8737 | } else { |
| 8738 | ctxt->vctxt.nodeNr = 0; |
| 8739 | ctxt->vctxt.nodeMax = 4; |
| 8740 | ctxt->vctxt.node = NULL; |
| 8741 | } |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8742 | } else { |
| 8743 | ctxt->vctxt.error = NULL; |
| 8744 | ctxt->vctxt.warning = NULL; |
| 8745 | } |
| 8746 | |
| 8747 | xmlParseContent(ctxt); |
| 8748 | |
| 8749 | if ((RAW == '<') && (NXT(1) == '/')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8750 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8751 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8752 | ctxt->sax->error(ctxt->userData, |
| 8753 | "chunk is not well balanced\n"); |
| 8754 | ctxt->wellFormed = 0; |
| 8755 | ctxt->disableSAX = 1; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8756 | } else if (RAW != 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8757 | ctxt->errNo = XML_ERR_EXTRA_CONTENT; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8758 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8759 | ctxt->sax->error(ctxt->userData, |
| 8760 | "extra content at the end of well balanced chunk\n"); |
| 8761 | ctxt->wellFormed = 0; |
| 8762 | ctxt->disableSAX = 1; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8763 | } |
| 8764 | if (ctxt->node != newDoc->children) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8765 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8766 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8767 | ctxt->sax->error(ctxt->userData, |
| 8768 | "chunk is not well balanced\n"); |
| 8769 | ctxt->wellFormed = 0; |
| 8770 | ctxt->disableSAX = 1; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8771 | } |
| 8772 | |
| 8773 | if (!ctxt->wellFormed) { |
| 8774 | if (ctxt->errNo == 0) |
| 8775 | ret = 1; |
| 8776 | else |
| 8777 | ret = ctxt->errNo; |
| 8778 | } else { |
| 8779 | if (list != NULL) { |
| 8780 | xmlNodePtr cur; |
| 8781 | |
| 8782 | /* |
| 8783 | * Return the newly created nodeset after unlinking it from |
| 8784 | * they pseudo parent. |
| 8785 | */ |
| 8786 | cur = newDoc->children->children; |
| 8787 | *list = cur; |
| 8788 | while (cur != NULL) { |
| 8789 | cur->parent = NULL; |
| 8790 | cur = cur->next; |
| 8791 | } |
| 8792 | newDoc->children->children = NULL; |
| 8793 | } |
| 8794 | ret = 0; |
| 8795 | } |
| 8796 | ctxt->sax = oldsax; |
| 8797 | xmlFreeParserCtxt(ctxt); |
| 8798 | newDoc->intSubset = NULL; |
| 8799 | newDoc->extSubset = NULL; |
| 8800 | xmlFreeDoc(newDoc); |
| 8801 | |
| 8802 | return(ret); |
| 8803 | } |
| 8804 | |
| 8805 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8806 | * xmlParseExternalEntity: |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 8807 | * @doc: the document the chunk pertains to |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8808 | * @sax: the SAX handler bloc (possibly NULL) |
| 8809 | * @user_data: The user data returned on SAX callbacks (possibly NULL) |
| 8810 | * @depth: Used for loop detection, use 0 |
| 8811 | * @URL: the URL for the entity to load |
| 8812 | * @ID: the System ID for the entity to load |
| 8813 | * @list: the return value for the set of parsed nodes |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 8814 | * |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8815 | * Parse an external general entity |
| 8816 | * An external general parsed entity is well-formed if it matches the |
| 8817 | * production labeled extParsedEnt. |
| 8818 | * |
| 8819 | * [78] extParsedEnt ::= TextDecl? content |
| 8820 | * |
| 8821 | * Returns 0 if the entity is well formed, -1 in case of args problem and |
| 8822 | * the parser error code otherwise |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 8823 | */ |
| 8824 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8825 | int |
| 8826 | xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data, |
| 8827 | int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *list) { |
| 8828 | xmlParserCtxtPtr ctxt; |
| 8829 | xmlDocPtr newDoc; |
| 8830 | xmlSAXHandlerPtr oldsax = NULL; |
| 8831 | int ret = 0; |
| 8832 | |
| 8833 | if (depth > 40) { |
| 8834 | return(XML_ERR_ENTITY_LOOP); |
| 8835 | } |
| 8836 | |
| 8837 | |
| 8838 | |
| 8839 | if (list != NULL) |
| 8840 | *list = NULL; |
| 8841 | if ((URL == NULL) && (ID == NULL)) |
| 8842 | return(-1); |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 8843 | if (doc == NULL) /* @@ relax but check for dereferences */ |
| 8844 | return(-1); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8845 | |
| 8846 | |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 8847 | ctxt = xmlCreateEntityParserCtxt(URL, ID, NULL); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8848 | if (ctxt == NULL) return(-1); |
| 8849 | ctxt->userData = ctxt; |
| 8850 | if (sax != NULL) { |
| 8851 | oldsax = ctxt->sax; |
| 8852 | ctxt->sax = sax; |
| 8853 | if (user_data != NULL) |
| 8854 | ctxt->userData = user_data; |
| 8855 | } |
| 8856 | newDoc = xmlNewDoc(BAD_CAST "1.0"); |
| 8857 | if (newDoc == NULL) { |
| 8858 | xmlFreeParserCtxt(ctxt); |
| 8859 | return(-1); |
| 8860 | } |
| 8861 | if (doc != NULL) { |
| 8862 | newDoc->intSubset = doc->intSubset; |
| 8863 | newDoc->extSubset = doc->extSubset; |
| 8864 | } |
| 8865 | if (doc->URL != NULL) { |
| 8866 | newDoc->URL = xmlStrdup(doc->URL); |
| 8867 | } |
| 8868 | newDoc->children = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); |
| 8869 | if (newDoc->children == NULL) { |
| 8870 | if (sax != NULL) |
| 8871 | ctxt->sax = oldsax; |
| 8872 | xmlFreeParserCtxt(ctxt); |
| 8873 | newDoc->intSubset = NULL; |
| 8874 | newDoc->extSubset = NULL; |
| 8875 | xmlFreeDoc(newDoc); |
| 8876 | return(-1); |
| 8877 | } |
| 8878 | nodePush(ctxt, newDoc->children); |
| 8879 | if (doc == NULL) { |
| 8880 | ctxt->myDoc = newDoc; |
| 8881 | } else { |
| 8882 | ctxt->myDoc = doc; |
| 8883 | newDoc->children->doc = doc; |
| 8884 | } |
| 8885 | |
| 8886 | /* |
| 8887 | * Parse a possible text declaration first |
| 8888 | */ |
| 8889 | GROW; |
| 8890 | if ((RAW == '<') && (NXT(1) == '?') && |
| 8891 | (NXT(2) == 'x') && (NXT(3) == 'm') && |
| 8892 | (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) { |
| 8893 | xmlParseTextDecl(ctxt); |
| 8894 | } |
| 8895 | |
| 8896 | /* |
| 8897 | * Doing validity checking on chunk doesn't make sense |
| 8898 | */ |
| 8899 | ctxt->instate = XML_PARSER_CONTENT; |
| 8900 | ctxt->validate = 0; |
| 8901 | ctxt->depth = depth; |
| 8902 | |
| 8903 | xmlParseContent(ctxt); |
| 8904 | |
| 8905 | if ((RAW == '<') && (NXT(1) == '/')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8906 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8907 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8908 | ctxt->sax->error(ctxt->userData, |
| 8909 | "chunk is not well balanced\n"); |
| 8910 | ctxt->wellFormed = 0; |
| 8911 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8912 | } else if (RAW != 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8913 | ctxt->errNo = XML_ERR_EXTRA_CONTENT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8914 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8915 | ctxt->sax->error(ctxt->userData, |
| 8916 | "extra content at the end of well balanced chunk\n"); |
| 8917 | ctxt->wellFormed = 0; |
| 8918 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8919 | } |
| 8920 | if (ctxt->node != newDoc->children) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 8921 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8922 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 8923 | ctxt->sax->error(ctxt->userData, |
| 8924 | "chunk is not well balanced\n"); |
| 8925 | ctxt->wellFormed = 0; |
| 8926 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8927 | } |
| 8928 | |
| 8929 | if (!ctxt->wellFormed) { |
| 8930 | if (ctxt->errNo == 0) |
| 8931 | ret = 1; |
| 8932 | else |
| 8933 | ret = ctxt->errNo; |
| 8934 | } else { |
| 8935 | if (list != NULL) { |
| 8936 | xmlNodePtr cur; |
| 8937 | |
| 8938 | /* |
| 8939 | * Return the newly created nodeset after unlinking it from |
| 8940 | * they pseudo parent. |
| 8941 | */ |
| 8942 | cur = newDoc->children->children; |
| 8943 | *list = cur; |
| 8944 | while (cur != NULL) { |
| 8945 | cur->parent = NULL; |
| 8946 | cur = cur->next; |
| 8947 | } |
| 8948 | newDoc->children->children = NULL; |
| 8949 | } |
| 8950 | ret = 0; |
| 8951 | } |
| 8952 | if (sax != NULL) |
| 8953 | ctxt->sax = oldsax; |
| 8954 | xmlFreeParserCtxt(ctxt); |
| 8955 | newDoc->intSubset = NULL; |
| 8956 | newDoc->extSubset = NULL; |
| 8957 | xmlFreeDoc(newDoc); |
| 8958 | |
| 8959 | return(ret); |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 8960 | } |
| 8961 | |
| 8962 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 8963 | * xmlParseBalancedChunk: |
| 8964 | * @doc: the document the chunk pertains to |
| 8965 | * @sax: the SAX handler bloc (possibly NULL) |
| 8966 | * @user_data: The user data returned on SAX callbacks (possibly NULL) |
| 8967 | * @depth: Used for loop detection, use 0 |
| 8968 | * @string: the input string in UTF8 or ISO-Latin (zero terminated) |
| 8969 | * @list: the return value for the set of parsed nodes |
| 8970 | * |
| 8971 | * Parse a well-balanced chunk of an XML document |
| 8972 | * called by the parser |
| 8973 | * The allowed sequence for the Well Balanced Chunk is the one defined by |
| 8974 | * the content production in the XML grammar: |
| 8975 | * |
| 8976 | * [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)* |
| 8977 | * |
| 8978 | * Returns 0 if the chunk is well balanced, -1 in case of args problem and |
| 8979 | * the parser error code otherwise |
| 8980 | */ |
| 8981 | |
| 8982 | int |
| 8983 | xmlParseBalancedChunkMemory(xmlDocPtr doc, xmlSAXHandlerPtr sax, |
| 8984 | void *user_data, int depth, const xmlChar *string, xmlNodePtr *list) { |
| 8985 | xmlParserCtxtPtr ctxt; |
| 8986 | xmlDocPtr newDoc; |
| 8987 | xmlSAXHandlerPtr oldsax = NULL; |
| 8988 | int size; |
| 8989 | int ret = 0; |
| 8990 | |
| 8991 | if (depth > 40) { |
| 8992 | return(XML_ERR_ENTITY_LOOP); |
| 8993 | } |
| 8994 | |
| 8995 | |
| 8996 | if (list != NULL) |
| 8997 | *list = NULL; |
| 8998 | if (string == NULL) |
| 8999 | return(-1); |
| 9000 | |
| 9001 | size = xmlStrlen(string); |
| 9002 | |
| 9003 | ctxt = xmlCreateMemoryParserCtxt((char *) string, size); |
| 9004 | if (ctxt == NULL) return(-1); |
| 9005 | ctxt->userData = ctxt; |
| 9006 | if (sax != NULL) { |
| 9007 | oldsax = ctxt->sax; |
| 9008 | ctxt->sax = sax; |
| 9009 | if (user_data != NULL) |
| 9010 | ctxt->userData = user_data; |
| 9011 | } |
| 9012 | newDoc = xmlNewDoc(BAD_CAST "1.0"); |
| 9013 | if (newDoc == NULL) { |
| 9014 | xmlFreeParserCtxt(ctxt); |
| 9015 | return(-1); |
| 9016 | } |
| 9017 | if (doc != NULL) { |
| 9018 | newDoc->intSubset = doc->intSubset; |
| 9019 | newDoc->extSubset = doc->extSubset; |
| 9020 | } |
| 9021 | newDoc->children = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); |
| 9022 | if (newDoc->children == NULL) { |
| 9023 | if (sax != NULL) |
| 9024 | ctxt->sax = oldsax; |
| 9025 | xmlFreeParserCtxt(ctxt); |
| 9026 | newDoc->intSubset = NULL; |
| 9027 | newDoc->extSubset = NULL; |
| 9028 | xmlFreeDoc(newDoc); |
| 9029 | return(-1); |
| 9030 | } |
| 9031 | nodePush(ctxt, newDoc->children); |
| 9032 | if (doc == NULL) { |
| 9033 | ctxt->myDoc = newDoc; |
| 9034 | } else { |
| 9035 | ctxt->myDoc = doc; |
| 9036 | newDoc->children->doc = doc; |
| 9037 | } |
| 9038 | ctxt->instate = XML_PARSER_CONTENT; |
| 9039 | ctxt->depth = depth; |
| 9040 | |
| 9041 | /* |
| 9042 | * Doing validity checking on chunk doesn't make sense |
| 9043 | */ |
| 9044 | ctxt->validate = 0; |
| 9045 | |
| 9046 | xmlParseContent(ctxt); |
| 9047 | |
| 9048 | if ((RAW == '<') && (NXT(1) == '/')) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 9049 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9050 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 9051 | ctxt->sax->error(ctxt->userData, |
| 9052 | "chunk is not well balanced\n"); |
| 9053 | ctxt->wellFormed = 0; |
| 9054 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9055 | } else if (RAW != 0) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 9056 | ctxt->errNo = XML_ERR_EXTRA_CONTENT; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9057 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 9058 | ctxt->sax->error(ctxt->userData, |
| 9059 | "extra content at the end of well balanced chunk\n"); |
| 9060 | ctxt->wellFormed = 0; |
| 9061 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9062 | } |
| 9063 | if (ctxt->node != newDoc->children) { |
Daniel Veillard | a2c6da9 | 2000-09-16 18:15:00 +0000 | [diff] [blame] | 9064 | ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9065 | if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) |
| 9066 | ctxt->sax->error(ctxt->userData, |
| 9067 | "chunk is not well balanced\n"); |
| 9068 | ctxt->wellFormed = 0; |
| 9069 | ctxt->disableSAX = 1; |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9070 | } |
| 9071 | |
| 9072 | if (!ctxt->wellFormed) { |
| 9073 | if (ctxt->errNo == 0) |
| 9074 | ret = 1; |
| 9075 | else |
| 9076 | ret = ctxt->errNo; |
| 9077 | } else { |
| 9078 | if (list != NULL) { |
| 9079 | xmlNodePtr cur; |
| 9080 | |
| 9081 | /* |
| 9082 | * Return the newly created nodeset after unlinking it from |
| 9083 | * they pseudo parent. |
| 9084 | */ |
| 9085 | cur = newDoc->children->children; |
| 9086 | *list = cur; |
| 9087 | while (cur != NULL) { |
| 9088 | cur->parent = NULL; |
| 9089 | cur = cur->next; |
| 9090 | } |
| 9091 | newDoc->children->children = NULL; |
| 9092 | } |
| 9093 | ret = 0; |
| 9094 | } |
| 9095 | if (sax != NULL) |
| 9096 | ctxt->sax = oldsax; |
| 9097 | xmlFreeParserCtxt(ctxt); |
| 9098 | newDoc->intSubset = NULL; |
| 9099 | newDoc->extSubset = NULL; |
| 9100 | xmlFreeDoc(newDoc); |
| 9101 | |
| 9102 | return(ret); |
| 9103 | } |
| 9104 | |
| 9105 | /** |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9106 | * xmlSAXParseEntity: |
| 9107 | * @sax: the SAX handler block |
| 9108 | * @filename: the filename |
Daniel Veillard | 0142b84 | 2000-01-14 14:45:24 +0000 | [diff] [blame] | 9109 | * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9110 | * parse an XML external entity out of context and build a tree. |
| 9111 | * It use the given SAX function block to handle the parsing callback. |
| 9112 | * If sax is NULL, fallback to the default DOM tree building routines. |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9113 | * |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9114 | * [78] extParsedEnt ::= TextDecl? content |
| 9115 | * |
| 9116 | * This correspond to a "Well Balanced" chunk |
| 9117 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9118 | * Returns the resulting document tree |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9119 | */ |
| 9120 | |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9121 | xmlDocPtr |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9122 | xmlSAXParseEntity(xmlSAXHandlerPtr sax, const char *filename) { |
| 9123 | xmlDocPtr ret; |
| 9124 | xmlParserCtxtPtr ctxt; |
| 9125 | char *directory = NULL; |
| 9126 | |
| 9127 | ctxt = xmlCreateFileParserCtxt(filename); |
| 9128 | if (ctxt == NULL) { |
| 9129 | return(NULL); |
| 9130 | } |
| 9131 | if (sax != NULL) { |
| 9132 | if (ctxt->sax != NULL) |
| 9133 | xmlFree(ctxt->sax); |
| 9134 | ctxt->sax = sax; |
| 9135 | ctxt->userData = NULL; |
| 9136 | } |
| 9137 | |
| 9138 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 9139 | directory = xmlParserGetDirectory(filename); |
| 9140 | |
| 9141 | xmlParseExtParsedEnt(ctxt); |
| 9142 | |
| 9143 | if (ctxt->wellFormed) |
| 9144 | ret = ctxt->myDoc; |
| 9145 | else { |
| 9146 | ret = NULL; |
| 9147 | xmlFreeDoc(ctxt->myDoc); |
| 9148 | ctxt->myDoc = NULL; |
| 9149 | } |
| 9150 | if (sax != NULL) |
| 9151 | ctxt->sax = NULL; |
| 9152 | xmlFreeParserCtxt(ctxt); |
| 9153 | |
| 9154 | return(ret); |
| 9155 | } |
| 9156 | |
| 9157 | /** |
| 9158 | * xmlParseEntity: |
| 9159 | * @filename: the filename |
| 9160 | * |
| 9161 | * parse an XML external entity out of context and build a tree. |
| 9162 | * |
| 9163 | * [78] extParsedEnt ::= TextDecl? content |
| 9164 | * |
| 9165 | * This correspond to a "Well Balanced" chunk |
| 9166 | * |
| 9167 | * Returns the resulting document tree |
| 9168 | */ |
| 9169 | |
| 9170 | xmlDocPtr |
| 9171 | xmlParseEntity(const char *filename) { |
| 9172 | return(xmlSAXParseEntity(NULL, filename)); |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9173 | } |
| 9174 | |
| 9175 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9176 | * xmlCreateEntityParserCtxt: |
| 9177 | * @URL: the entity URL |
| 9178 | * @ID: the entity PUBLIC ID |
| 9179 | * @base: a posible base for the target URI |
| 9180 | * |
| 9181 | * Create a parser context for an external entity |
| 9182 | * Automatic support for ZLIB/Compress compressed document is provided |
| 9183 | * by default if found at compile-time. |
| 9184 | * |
| 9185 | * Returns the new parser context or NULL |
| 9186 | */ |
| 9187 | xmlParserCtxtPtr |
| 9188 | xmlCreateEntityParserCtxt(const xmlChar *URL, const xmlChar *ID, |
| 9189 | const xmlChar *base) { |
| 9190 | xmlParserCtxtPtr ctxt; |
| 9191 | xmlParserInputPtr inputStream; |
| 9192 | char *directory = NULL; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 9193 | xmlChar *uri; |
| 9194 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9195 | ctxt = xmlNewParserCtxt(); |
| 9196 | if (ctxt == NULL) { |
| 9197 | return(NULL); |
| 9198 | } |
| 9199 | |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 9200 | uri = xmlBuildURI(URL, base); |
| 9201 | |
| 9202 | if (uri == NULL) { |
| 9203 | inputStream = xmlLoadExternalEntity((char *)URL, (char *)ID, ctxt); |
| 9204 | if (inputStream == NULL) { |
| 9205 | xmlFreeParserCtxt(ctxt); |
| 9206 | return(NULL); |
| 9207 | } |
| 9208 | |
| 9209 | inputPush(ctxt, inputStream); |
| 9210 | |
| 9211 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 9212 | directory = xmlParserGetDirectory((char *)URL); |
| 9213 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 9214 | ctxt->directory = directory; |
| 9215 | } else { |
| 9216 | inputStream = xmlLoadExternalEntity((char *)uri, (char *)ID, ctxt); |
| 9217 | if (inputStream == NULL) { |
| 9218 | xmlFreeParserCtxt(ctxt); |
| 9219 | return(NULL); |
| 9220 | } |
| 9221 | |
| 9222 | inputPush(ctxt, inputStream); |
| 9223 | |
| 9224 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 9225 | directory = xmlParserGetDirectory((char *)uri); |
| 9226 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 9227 | ctxt->directory = directory; |
| 9228 | xmlFree(uri); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9229 | } |
| 9230 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9231 | return(ctxt); |
| 9232 | } |
| 9233 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9234 | /************************************************************************ |
| 9235 | * * |
| 9236 | * Front ends when parsing from a file * |
| 9237 | * * |
| 9238 | ************************************************************************/ |
| 9239 | |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9240 | /** |
| 9241 | * xmlCreateFileParserCtxt: |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 9242 | * @filename: the filename |
| 9243 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9244 | * Create a parser context for a file content. |
| 9245 | * Automatic support for ZLIB/Compress compressed document is provided |
| 9246 | * by default if found at compile-time. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 9247 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9248 | * Returns the new parser context or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9249 | */ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9250 | xmlParserCtxtPtr |
| 9251 | xmlCreateFileParserCtxt(const char *filename) |
| 9252 | { |
| 9253 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9254 | xmlParserInputPtr inputStream; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 9255 | xmlParserInputBufferPtr buf; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9256 | char *directory = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9257 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 9258 | buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 9259 | if (buf == NULL) { |
| 9260 | return(NULL); |
| 9261 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9262 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9263 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9264 | if (ctxt == NULL) { |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 9265 | if (xmlDefaultSAXHandler.error != NULL) { |
| 9266 | xmlDefaultSAXHandler.error(NULL, "out of memory\n"); |
| 9267 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9268 | return(NULL); |
| 9269 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9270 | |
| 9271 | inputStream = xmlNewInputStream(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9272 | if (inputStream == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9273 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9274 | return(NULL); |
| 9275 | } |
| 9276 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 9277 | inputStream->filename = xmlMemStrdup(filename); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 9278 | inputStream->buf = buf; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 9279 | inputStream->base = inputStream->buf->buffer->content; |
| 9280 | inputStream->cur = inputStream->buf->buffer->content; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9281 | |
| 9282 | inputPush(ctxt, inputStream); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9283 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 9284 | directory = xmlParserGetDirectory(filename); |
| 9285 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 9286 | ctxt->directory = directory; |
| 9287 | |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9288 | return(ctxt); |
| 9289 | } |
| 9290 | |
| 9291 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9292 | * xmlSAXParseFile: |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9293 | * @sax: the SAX handler block |
| 9294 | * @filename: the filename |
| 9295 | * @recovery: work in recovery mode, i.e. tries to read no Well Formed |
| 9296 | * documents |
| 9297 | * |
| 9298 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress |
| 9299 | * compressed document is provided by default if found at compile-time. |
| 9300 | * It use the given SAX function block to handle the parsing callback. |
| 9301 | * If sax is NULL, fallback to the default DOM tree building routines. |
| 9302 | * |
| 9303 | * Returns the resulting document tree |
| 9304 | */ |
| 9305 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 9306 | xmlDocPtr |
| 9307 | xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename, |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9308 | int recovery) { |
| 9309 | xmlDocPtr ret; |
| 9310 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9311 | char *directory = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9312 | |
| 9313 | ctxt = xmlCreateFileParserCtxt(filename); |
Daniel Veillard | 39c7d71 | 2000-09-10 16:14:55 +0000 | [diff] [blame] | 9314 | if (ctxt == NULL) { |
| 9315 | return(NULL); |
| 9316 | } |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 9317 | if (sax != NULL) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 9318 | if (ctxt->sax != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 9319 | xmlFree(ctxt->sax); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 9320 | ctxt->sax = sax; |
| 9321 | ctxt->userData = NULL; |
| 9322 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9323 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9324 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 9325 | directory = xmlParserGetDirectory(filename); |
| 9326 | if ((ctxt->directory == NULL) && (directory != NULL)) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9327 | ctxt->directory = (char *) xmlStrdup((xmlChar *) directory); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9328 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9329 | xmlParseDocument(ctxt); |
| 9330 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 9331 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9332 | else { |
| 9333 | ret = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 9334 | xmlFreeDoc(ctxt->myDoc); |
| 9335 | ctxt->myDoc = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9336 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 9337 | if (sax != NULL) |
| 9338 | ctxt->sax = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9339 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9340 | |
| 9341 | return(ret); |
| 9342 | } |
| 9343 | |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9344 | /** |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9345 | * xmlRecoverDoc: |
| 9346 | * @cur: a pointer to an array of xmlChar |
| 9347 | * |
| 9348 | * parse an XML in-memory document and build a tree. |
| 9349 | * In the case the document is not Well Formed, a tree is built anyway |
| 9350 | * |
| 9351 | * Returns the resulting document tree |
| 9352 | */ |
| 9353 | |
| 9354 | xmlDocPtr |
| 9355 | xmlRecoverDoc(xmlChar *cur) { |
| 9356 | return(xmlSAXParseDoc(NULL, cur, 1)); |
| 9357 | } |
| 9358 | |
| 9359 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9360 | * xmlParseFile: |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9361 | * @filename: the filename |
| 9362 | * |
| 9363 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress |
| 9364 | * compressed document is provided by default if found at compile-time. |
| 9365 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9366 | * Returns the resulting document tree |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9367 | */ |
| 9368 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 9369 | xmlDocPtr |
| 9370 | xmlParseFile(const char *filename) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9371 | return(xmlSAXParseFile(NULL, filename, 0)); |
| 9372 | } |
| 9373 | |
| 9374 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9375 | * xmlRecoverFile: |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9376 | * @filename: the filename |
| 9377 | * |
| 9378 | * parse an XML file and build a tree. Automatic support for ZLIB/Compress |
| 9379 | * compressed document is provided by default if found at compile-time. |
| 9380 | * In the case the document is not Well Formed, a tree is built anyway |
| 9381 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9382 | * Returns the resulting document tree |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9383 | */ |
| 9384 | |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 9385 | xmlDocPtr |
| 9386 | xmlRecoverFile(const char *filename) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9387 | return(xmlSAXParseFile(NULL, filename, 1)); |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9388 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9389 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9390 | |
| 9391 | /** |
| 9392 | * xmlSetupParserForBuffer: |
| 9393 | * @ctxt: an XML parser context |
| 9394 | * @buffer: a xmlChar * buffer |
| 9395 | * @filename: a file name |
| 9396 | * |
| 9397 | * Setup the parser context to parse a new buffer; Clears any prior |
| 9398 | * contents from the parser context. The buffer parameter must not be |
| 9399 | * NULL, but the filename parameter can be |
| 9400 | */ |
| 9401 | void |
| 9402 | xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, |
| 9403 | const char* filename) |
| 9404 | { |
| 9405 | xmlParserInputPtr input; |
| 9406 | |
| 9407 | input = xmlNewInputStream(ctxt); |
| 9408 | if (input == NULL) { |
| 9409 | perror("malloc"); |
| 9410 | xmlFree(ctxt); |
| 9411 | return; |
| 9412 | } |
| 9413 | |
| 9414 | xmlClearParserCtxt(ctxt); |
| 9415 | if (filename != NULL) |
| 9416 | input->filename = xmlMemStrdup(filename); |
| 9417 | input->base = buffer; |
| 9418 | input->cur = buffer; |
| 9419 | inputPush(ctxt, input); |
| 9420 | } |
| 9421 | |
| 9422 | /** |
| 9423 | * xmlSAXUserParseFile: |
| 9424 | * @sax: a SAX handler |
| 9425 | * @user_data: The user data returned on SAX callbacks |
| 9426 | * @filename: a file name |
| 9427 | * |
| 9428 | * parse an XML file and call the given SAX handler routines. |
| 9429 | * Automatic support for ZLIB/Compress compressed document is provided |
| 9430 | * |
| 9431 | * Returns 0 in case of success or a error number otherwise |
| 9432 | */ |
| 9433 | int |
| 9434 | xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, |
| 9435 | const char *filename) { |
| 9436 | int ret = 0; |
| 9437 | xmlParserCtxtPtr ctxt; |
| 9438 | |
| 9439 | ctxt = xmlCreateFileParserCtxt(filename); |
| 9440 | if (ctxt == NULL) return -1; |
| 9441 | if (ctxt->sax != &xmlDefaultSAXHandler) |
| 9442 | xmlFree(ctxt->sax); |
| 9443 | ctxt->sax = sax; |
| 9444 | if (user_data != NULL) |
| 9445 | ctxt->userData = user_data; |
| 9446 | |
| 9447 | xmlParseDocument(ctxt); |
| 9448 | |
| 9449 | if (ctxt->wellFormed) |
| 9450 | ret = 0; |
| 9451 | else { |
| 9452 | if (ctxt->errNo != 0) |
| 9453 | ret = ctxt->errNo; |
| 9454 | else |
| 9455 | ret = -1; |
| 9456 | } |
| 9457 | if (sax != NULL) |
| 9458 | ctxt->sax = NULL; |
| 9459 | xmlFreeParserCtxt(ctxt); |
| 9460 | |
| 9461 | return ret; |
| 9462 | } |
| 9463 | |
| 9464 | /************************************************************************ |
| 9465 | * * |
| 9466 | * Front ends when parsing from memory * |
| 9467 | * * |
| 9468 | ************************************************************************/ |
| 9469 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 9470 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9471 | * xmlCreateMemoryParserCtxt: |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9472 | * @buffer: a pointer to a char array |
| 9473 | * @size: the size of the array |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 9474 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9475 | * Create a parser context for an XML in-memory document. |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 9476 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9477 | * Returns the new parser context or NULL |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9478 | */ |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9479 | xmlParserCtxtPtr |
| 9480 | xmlCreateMemoryParserCtxt(char *buffer, int size) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9481 | xmlParserCtxtPtr ctxt; |
| 9482 | xmlParserInputPtr input; |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 9483 | xmlParserInputBufferPtr buf; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9484 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9485 | if (buffer == NULL) |
| 9486 | return(NULL); |
| 9487 | if (size <= 0) |
Daniel Veillard | b566ce1 | 2000-03-04 11:39:42 +0000 | [diff] [blame] | 9488 | return(NULL); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9489 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9490 | ctxt = xmlNewParserCtxt(); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9491 | if (ctxt == NULL) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9492 | return(NULL); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9493 | |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 9494 | buf = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE); |
| 9495 | if (buf == NULL) return(NULL); |
| 9496 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9497 | input = xmlNewInputStream(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9498 | if (input == NULL) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9499 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9500 | return(NULL); |
| 9501 | } |
| 9502 | |
| 9503 | input->filename = NULL; |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 9504 | input->buf = buf; |
| 9505 | input->base = input->buf->buffer->content; |
| 9506 | input->cur = input->buf->buffer->content; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9507 | |
| 9508 | inputPush(ctxt, input); |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9509 | return(ctxt); |
| 9510 | } |
| 9511 | |
| 9512 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9513 | * xmlSAXParseMemory: |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9514 | * @sax: the SAX handler block |
| 9515 | * @buffer: an pointer to a char array |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 9516 | * @size: the size of the array |
| 9517 | * @recovery: work in recovery mode, i.e. tries to read not Well Formed |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9518 | * documents |
| 9519 | * |
| 9520 | * parse an XML in-memory block and use the given SAX function block |
| 9521 | * to handle the parsing callback. If sax is NULL, fallback to the default |
| 9522 | * DOM tree building routines. |
| 9523 | * |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9524 | * Returns the resulting document tree |
| 9525 | */ |
| 9526 | xmlDocPtr |
| 9527 | xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer, int size, int recovery) { |
| 9528 | xmlDocPtr ret; |
| 9529 | xmlParserCtxtPtr ctxt; |
| 9530 | |
| 9531 | ctxt = xmlCreateMemoryParserCtxt(buffer, size); |
| 9532 | if (ctxt == NULL) return(NULL); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 9533 | if (sax != NULL) { |
| 9534 | ctxt->sax = sax; |
| 9535 | ctxt->userData = NULL; |
| 9536 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9537 | |
| 9538 | xmlParseDocument(ctxt); |
| 9539 | |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 9540 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9541 | else { |
| 9542 | ret = NULL; |
Daniel Veillard | 517752b | 1999-04-05 12:20:10 +0000 | [diff] [blame] | 9543 | xmlFreeDoc(ctxt->myDoc); |
| 9544 | ctxt->myDoc = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9545 | } |
Daniel Veillard | 97fea18 | 1999-06-26 23:07:37 +0000 | [diff] [blame] | 9546 | if (sax != NULL) |
| 9547 | ctxt->sax = NULL; |
Daniel Veillard | d692aa4 | 1999-02-28 21:54:31 +0000 | [diff] [blame] | 9548 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9549 | |
| 9550 | return(ret); |
| 9551 | } |
| 9552 | |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9553 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9554 | * xmlParseMemory: |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9555 | * @buffer: an pointer to a char array |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9556 | * @size: the size of the array |
| 9557 | * |
| 9558 | * parse an XML in-memory block and build a tree. |
| 9559 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9560 | * Returns the resulting document tree |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9561 | */ |
| 9562 | |
| 9563 | xmlDocPtr xmlParseMemory(char *buffer, int size) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9564 | return(xmlSAXParseMemory(NULL, buffer, size, 0)); |
| 9565 | } |
| 9566 | |
| 9567 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9568 | * xmlRecoverMemory: |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9569 | * @buffer: an pointer to a char array |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9570 | * @size: the size of the array |
| 9571 | * |
| 9572 | * parse an XML in-memory block and build a tree. |
| 9573 | * In the case the document is not Well Formed, a tree is built anyway |
| 9574 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 9575 | * Returns the resulting document tree |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 9576 | */ |
| 9577 | |
| 9578 | xmlDocPtr xmlRecoverMemory(char *buffer, int size) { |
| 9579 | return(xmlSAXParseMemory(NULL, buffer, size, 1)); |
Daniel Veillard | 42dc9b3 | 1998-11-09 01:17:21 +0000 | [diff] [blame] | 9580 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9581 | |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 9582 | /** |
| 9583 | * xmlSAXUserParseMemory: |
| 9584 | * @sax: a SAX handler |
| 9585 | * @user_data: The user data returned on SAX callbacks |
| 9586 | * @buffer: an in-memory XML document input |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 9587 | * @size: the length of the XML document in bytes |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 9588 | * |
| 9589 | * A better SAX parsing routine. |
| 9590 | * parse an XML in-memory buffer and call the given SAX handler routines. |
| 9591 | * |
| 9592 | * Returns 0 in case of success or a error number otherwise |
| 9593 | */ |
| 9594 | int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data, |
| 9595 | char *buffer, int size) { |
| 9596 | int ret = 0; |
| 9597 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 9598 | xmlSAXHandlerPtr oldsax = NULL; |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 9599 | |
| 9600 | ctxt = xmlCreateMemoryParserCtxt(buffer, size); |
| 9601 | if (ctxt == NULL) return -1; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 9602 | if (sax != NULL) { |
| 9603 | oldsax = ctxt->sax; |
| 9604 | ctxt->sax = sax; |
| 9605 | } |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 9606 | ctxt->userData = user_data; |
| 9607 | |
| 9608 | xmlParseDocument(ctxt); |
| 9609 | |
| 9610 | if (ctxt->wellFormed) |
| 9611 | ret = 0; |
| 9612 | else { |
| 9613 | if (ctxt->errNo != 0) |
| 9614 | ret = ctxt->errNo; |
| 9615 | else |
| 9616 | ret = -1; |
| 9617 | } |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 9618 | if (sax != NULL) { |
| 9619 | ctxt->sax = oldsax; |
| 9620 | } |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 9621 | xmlFreeParserCtxt(ctxt); |
| 9622 | |
| 9623 | return ret; |
| 9624 | } |
| 9625 | |
Daniel Veillard | b1059e2 | 2000-09-16 14:02:43 +0000 | [diff] [blame] | 9626 | /** |
| 9627 | * xmlCreateDocParserCtxt: |
| 9628 | * @cur: a pointer to an array of xmlChar |
| 9629 | * |
| 9630 | * Creates a parser context for an XML in-memory document. |
| 9631 | * |
| 9632 | * Returns the new parser context or NULL |
| 9633 | */ |
| 9634 | xmlParserCtxtPtr |
| 9635 | xmlCreateDocParserCtxt(xmlChar *cur) { |
| 9636 | int len; |
| 9637 | |
| 9638 | if (cur == NULL) |
| 9639 | return(NULL); |
| 9640 | len = xmlStrlen(cur); |
| 9641 | return(xmlCreateMemoryParserCtxt((char *)cur, len)); |
| 9642 | } |
| 9643 | |
| 9644 | /** |
| 9645 | * xmlSAXParseDoc: |
| 9646 | * @sax: the SAX handler block |
| 9647 | * @cur: a pointer to an array of xmlChar |
| 9648 | * @recovery: work in recovery mode, i.e. tries to read no Well Formed |
| 9649 | * documents |
| 9650 | * |
| 9651 | * parse an XML in-memory document and build a tree. |
| 9652 | * It use the given SAX function block to handle the parsing callback. |
| 9653 | * If sax is NULL, fallback to the default DOM tree building routines. |
| 9654 | * |
| 9655 | * Returns the resulting document tree |
| 9656 | */ |
| 9657 | |
| 9658 | xmlDocPtr |
| 9659 | xmlSAXParseDoc(xmlSAXHandlerPtr sax, xmlChar *cur, int recovery) { |
| 9660 | xmlDocPtr ret; |
| 9661 | xmlParserCtxtPtr ctxt; |
| 9662 | |
| 9663 | if (cur == NULL) return(NULL); |
| 9664 | |
| 9665 | |
| 9666 | ctxt = xmlCreateDocParserCtxt(cur); |
| 9667 | if (ctxt == NULL) return(NULL); |
| 9668 | if (sax != NULL) { |
| 9669 | ctxt->sax = sax; |
| 9670 | ctxt->userData = NULL; |
| 9671 | } |
| 9672 | |
| 9673 | xmlParseDocument(ctxt); |
| 9674 | if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; |
| 9675 | else { |
| 9676 | ret = NULL; |
| 9677 | xmlFreeDoc(ctxt->myDoc); |
| 9678 | ctxt->myDoc = NULL; |
| 9679 | } |
| 9680 | if (sax != NULL) |
| 9681 | ctxt->sax = NULL; |
| 9682 | xmlFreeParserCtxt(ctxt); |
| 9683 | |
| 9684 | return(ret); |
| 9685 | } |
| 9686 | |
| 9687 | /** |
| 9688 | * xmlParseDoc: |
| 9689 | * @cur: a pointer to an array of xmlChar |
| 9690 | * |
| 9691 | * parse an XML in-memory document and build a tree. |
| 9692 | * |
| 9693 | * Returns the resulting document tree |
| 9694 | */ |
| 9695 | |
| 9696 | xmlDocPtr |
| 9697 | xmlParseDoc(xmlChar *cur) { |
| 9698 | return(xmlSAXParseDoc(NULL, cur, 0)); |
| 9699 | } |
| 9700 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 9701 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9702 | /************************************************************************ |
| 9703 | * * |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 9704 | * Miscellaneous * |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9705 | * * |
| 9706 | ************************************************************************/ |
| 9707 | |
Daniel Veillard | 7cfce32 | 2000-10-04 12:40:27 +0000 | [diff] [blame] | 9708 | #ifdef LIBXML_XPATH_ENABLED |
| 9709 | #include <libxml/xpath.h> |
| 9710 | #endif |
| 9711 | |
Daniel Veillard | bc76530 | 2000-10-01 18:23:35 +0000 | [diff] [blame] | 9712 | static int xmlParserInitialized = 0; |
| 9713 | |
| 9714 | /** |
| 9715 | * xmlInitParser: |
| 9716 | * |
| 9717 | * Initialization function for the XML parser. |
| 9718 | * This is not reentrant. Call once before processing in case of |
| 9719 | * use in multithreaded programs. |
| 9720 | */ |
| 9721 | |
| 9722 | void |
| 9723 | xmlInitParser(void) { |
| 9724 | if (xmlParserInitialized) return; |
| 9725 | |
| 9726 | xmlInitCharEncodingHandlers(); |
| 9727 | xmlInitializePredefinedEntities(); |
| 9728 | xmlDefaultSAXHandlerInit(); |
Daniel Veillard | 7cfce32 | 2000-10-04 12:40:27 +0000 | [diff] [blame] | 9729 | xmlRegisterDefaultInputCallbacks(); |
| 9730 | xmlRegisterDefaultOutputCallbacks(); |
Daniel Veillard | bc76530 | 2000-10-01 18:23:35 +0000 | [diff] [blame] | 9731 | #ifdef LIBXML_HTML_ENABLED |
| 9732 | htmlInitAutoClose(); |
| 9733 | htmlDefaultSAXHandlerInit(); |
| 9734 | #endif |
Daniel Veillard | 7cfce32 | 2000-10-04 12:40:27 +0000 | [diff] [blame] | 9735 | #ifdef LIBXML_XPATH_ENABLED |
| 9736 | xmlXPathInit(); |
| 9737 | #endif |
Daniel Veillard | bc76530 | 2000-10-01 18:23:35 +0000 | [diff] [blame] | 9738 | xmlParserInitialized = 1; |
| 9739 | } |
| 9740 | |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 9741 | /** |
| 9742 | * xmlCleanupParser: |
| 9743 | * |
| 9744 | * Cleanup function for the XML parser. It tries to reclaim all |
| 9745 | * parsing related global memory allocated for the parser processing. |
| 9746 | * It doesn't deallocate any document related memory. Calling this |
| 9747 | * function should not prevent reusing the parser. |
| 9748 | */ |
| 9749 | |
| 9750 | void |
| 9751 | xmlCleanupParser(void) { |
Daniel Veillard | bc76530 | 2000-10-01 18:23:35 +0000 | [diff] [blame] | 9752 | xmlParserInitialized = 0; |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 9753 | xmlCleanupCharEncodingHandlers(); |
Daniel Veillard | f5c2c87 | 1999-12-01 09:51:45 +0000 | [diff] [blame] | 9754 | xmlCleanupPredefinedEntities(); |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 9755 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9756 | |
Daniel Veillard | 11e0058 | 1998-10-24 18:27:49 +0000 | [diff] [blame] | 9757 | /** |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 9758 | * xmlPedanticParserDefault: |
| 9759 | * @val: int 0 or 1 |
| 9760 | * |
| 9761 | * Set and return the previous value for enabling pedantic warnings. |
| 9762 | * |
| 9763 | * Returns the last value for 0 for no substitution, 1 for substitution. |
| 9764 | */ |
| 9765 | |
| 9766 | int |
| 9767 | xmlPedanticParserDefault(int val) { |
| 9768 | int old = xmlPedanticParserDefaultValue; |
| 9769 | |
| 9770 | xmlPedanticParserDefaultValue = val; |
| 9771 | return(old); |
| 9772 | } |
| 9773 | |
| 9774 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 9775 | * xmlSubstituteEntitiesDefault: |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 9776 | * @val: int 0 or 1 |
| 9777 | * |
| 9778 | * Set and return the previous value for default entity support. |
| 9779 | * Initially the parser always keep entity references instead of substituting |
| 9780 | * entity values in the output. This function has to be used to change the |
| 9781 | * default parser behaviour |
| 9782 | * SAX::subtituteEntities() has to be used for changing that on a file by |
| 9783 | * file basis. |
| 9784 | * |
| 9785 | * Returns the last value for 0 for no substitution, 1 for substitution. |
| 9786 | */ |
| 9787 | |
| 9788 | int |
| 9789 | xmlSubstituteEntitiesDefault(int val) { |
| 9790 | int old = xmlSubstituteEntitiesDefaultValue; |
| 9791 | |
| 9792 | xmlSubstituteEntitiesDefaultValue = val; |
| 9793 | return(old); |
| 9794 | } |
| 9795 | |
Daniel Veillard | fb76c40 | 2000-03-04 11:39:42 +0000 | [diff] [blame] | 9796 | /** |
| 9797 | * xmlKeepBlanksDefault: |
| 9798 | * @val: int 0 or 1 |
| 9799 | * |
| 9800 | * Set and return the previous value for default blanks text nodes support. |
| 9801 | * The 1.x version of the parser used an heuristic to try to detect |
| 9802 | * ignorable white spaces. As a result the SAX callback was generating |
| 9803 | * ignorableWhitespace() callbacks instead of characters() one, and when |
| 9804 | * using the DOM output text nodes containing those blanks were not generated. |
| 9805 | * The 2.x and later version will switch to the XML standard way and |
| 9806 | * ignorableWhitespace() are only generated when running the parser in |
| 9807 | * validating mode and when the current element doesn't allow CDATA or |
| 9808 | * mixed content. |
| 9809 | * This function is provided as a way to force the standard behaviour |
| 9810 | * on 1.X libs and to switch back to the old mode for compatibility when |
| 9811 | * running 1.X client code on 2.X . Upgrade of 1.X code should be done |
| 9812 | * by using xmlIsBlankNode() commodity function to detect the "empty" |
| 9813 | * nodes generated. |
| 9814 | * This value also affect autogeneration of indentation when saving code |
| 9815 | * if blanks sections are kept, indentation is not generated. |
| 9816 | * |
| 9817 | * Returns the last value for 0 for no substitution, 1 for substitution. |
| 9818 | */ |
| 9819 | |
| 9820 | int |
| 9821 | xmlKeepBlanksDefault(int val) { |
| 9822 | int old = xmlKeepBlanksDefaultValue; |
| 9823 | |
| 9824 | xmlKeepBlanksDefaultValue = val; |
| 9825 | xmlIndentTreeOutput = !val; |
| 9826 | return(old); |
| 9827 | } |
| 9828 | |