1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QXML_P_H
41#define QXML_P_H
42
43#include <qstack.h>
44#include <qmap.h>
45#include <qhash.h>
46#include <qxml.h>
47
48#include <stack>
49
50QT_BEGIN_NAMESPACE
51
52//
53// W A R N I N G
54// -------------
55//
56// This file is not part of the Qt API. It exists for the convenience of
57// qxml.cpp. This header file may change from version to version without
58// notice, or even be removed.
59//
60// We mean it.
61//
62
63class QXmlSimpleReaderPrivate
64{
65public:
66 ~QXmlSimpleReaderPrivate();
67private:
68 // functions
69 QXmlSimpleReaderPrivate(QXmlSimpleReader *reader);
70 void initIncrementalParsing();
71
72 // used to determine if elements are correctly nested
73 std::stack<QString, QStringList> tags;
74
75 // used by parseReference() and parsePEReference()
76 enum EntityRecognitionContext { InContent, InAttributeValue, InEntityValue, InDTD };
77
78 // used for entity declarations
79 struct ExternParameterEntity
80 {
81 ExternParameterEntity() {}
82 ExternParameterEntity(const QString &p, const QString &s)
83 : publicId(p), systemId(s) {}
84 QString publicId;
85 QString systemId;
86
87 Q_DUMMY_COMPARISON_OPERATOR(ExternParameterEntity)
88 };
89 friend class QTypeInfo<ExternParameterEntity>;
90
91 struct ExternEntity
92 {
93 ExternEntity() {}
94 ExternEntity(const QString &p, const QString &s, const QString &n)
95 : publicId(p), systemId(s), notation(n) {}
96 QString publicId;
97 QString systemId;
98 QString notation;
99 Q_DUMMY_COMPARISON_OPERATOR(ExternEntity)
100 };
101 friend class QTypeInfo<ExternEntity>;
102
103 QMap<QString,ExternParameterEntity> externParameterEntities;
104 QMap<QString,QString> parameterEntities;
105 QMap<QString,ExternEntity> externEntities;
106 QMap<QString,QString> entities;
107
108 // used for parsing of entity references
109 struct XmlRef {
110 XmlRef()
111 : index(0) {}
112 XmlRef(const QString &_name, const QString &_value)
113 : name(_name), value(_value), index(0) {}
114 bool isEmpty() const { return index == value.length(); }
115 QChar next() { return value.at(index++); }
116 QString name;
117 QString value;
118 int index;
119 };
120 friend class QTypeInfo<XmlRef>;
121 QStack<XmlRef> xmlRefStack;
122
123 // used for standalone declaration
124 enum Standalone { Yes, No, Unknown };
125
126 QString doctype; // only used for the doctype
127 QString xmlVersion; // only used to store the version information
128 QString encoding; // only used to store the encoding
129 Standalone standalone; // used to store the value of the standalone declaration
130
131 QString publicId; // used by parseExternalID() to store the public ID
132 QString systemId; // used by parseExternalID() to store the system ID
133
134 // Since publicId/systemId is used as temporary variables by parseExternalID(), it
135 // might overwrite the PUBLIC/SYSTEM for the document we're parsing. In effect, we would
136 // possibly send off an QXmlParseException that has the PUBLIC/SYSTEM of a entity declaration
137 // instead of those of the current document.
138 // Hence we have these two variables for storing the document's data.
139 QString thisPublicId;
140 QString thisSystemId;
141
142 QString attDeclEName; // use by parseAttlistDecl()
143 QString attDeclAName; // use by parseAttlistDecl()
144
145 // flags for some features support
146 bool useNamespaces;
147 bool useNamespacePrefixes;
148 bool reportWhitespaceCharData;
149 bool reportEntities;
150
151 // used to build the attribute list
152 QXmlAttributes attList;
153
154 // used in QXmlSimpleReader::parseContent() to decide whether character
155 // data was read
156 bool contentCharDataRead;
157 // Hack for letting QDom know where the skipped entity occurred
158 bool skipped_entity_in_content;
159
160 // helper classes
161 QScopedPointer<QXmlLocator> locator;
162 QXmlNamespaceSupport namespaceSupport;
163
164 // error string
165 QString error;
166
167 // arguments for parse functions (this is needed to allow incremental
168 // parsing)
169 bool parsePI_xmldecl;
170 bool parseName_useRef;
171 bool parseReference_charDataRead;
172 EntityRecognitionContext parseReference_context;
173 bool parseExternalID_allowPublicID;
174 EntityRecognitionContext parsePEReference_context;
175 QString parseString_s;
176
177 // for incremental parsing
178 struct ParseState {
179 typedef bool (QXmlSimpleReaderPrivate::*ParseFunction)();
180 ParseFunction function;
181 int state;
182 };
183 friend class QTypeInfo<ParseState>;
184 QStack<ParseState> *parseStack;
185
186 // used in parseProlog()
187 bool xmldecl_possible;
188 bool doctype_read;
189
190 // used in parseDoctype()
191 bool startDTDwasReported;
192
193 // used in parseString()
194 signed char Done;
195
196 // variables
197 QXmlContentHandler *contentHnd;
198 QXmlErrorHandler *errorHnd;
199 QXmlDTDHandler *dtdHnd;
200 QXmlEntityResolver *entityRes;
201 QXmlLexicalHandler *lexicalHnd;
202 QXmlDeclHandler *declHnd;
203
204 QXmlInputSource *inputSource;
205
206 QChar c; // the character at reading position
207 int lineNr; // number of line
208 int columnNr; // position in line
209
210 QChar nameArray[256]; // only used for names
211 QString nameValue; // only used for names
212 int nameArrayPos;
213 int nameValueLen;
214 QChar refArray[256]; // only used for references
215 QString refValue; // only used for references
216 int refArrayPos;
217 int refValueLen;
218 QChar stringArray[256]; // used for any other strings that are parsed
219 QString stringValue; // used for any other strings that are parsed
220 int stringArrayPos;
221 int stringValueLen;
222 QString emptyStr;
223
224 QHash<QString, int> literalEntitySizes;
225 // The entity at (QMap<QString,) referenced the entities at (QMap<QString,) (int>) times.
226 QHash<QString, QHash<QString, int> > referencesToOtherEntities;
227 QHash<QString, int> expandedSizes;
228 // The limit to the amount of times the DTD parsing functions can be called
229 // for the DTD currently being parsed.
230 static const int dtdRecursionLimit = 2;
231 // The maximum amount of characters an entity value may contain, after expansion.
232 static const int entityCharacterLimit = 4096;
233
234 const QString &string();
235 void stringClear();
236 void stringAddC(QChar);
237 inline void stringAddC() { stringAddC(c); }
238 const QString &name();
239 void nameClear();
240 void nameAddC(QChar);
241 inline void nameAddC() { nameAddC(c); }
242 const QString &ref();
243 void refClear();
244 void refAddC(QChar);
245 inline void refAddC() { refAddC(c); }
246
247 // private functions
248 bool eat_ws();
249 bool next_eat_ws();
250
251 void QT_FASTCALL next();
252 bool atEnd();
253
254 void init(const QXmlInputSource* i);
255 void initData();
256
257 bool entityExist(const QString&) const;
258
259 bool parseBeginOrContinue(int state, bool incremental);
260
261 bool parseProlog();
262 bool parseElement();
263 bool processElementEmptyTag();
264 bool processElementETagBegin2();
265 bool processElementAttribute();
266 bool parseMisc();
267 bool parseContent();
268
269 bool parsePI();
270 bool parseDoctype();
271 bool parseComment();
272
273 bool parseName();
274 bool parseNmtoken();
275 bool parseAttribute();
276 bool parseReference();
277 bool processReference();
278
279 bool parseExternalID();
280 bool parsePEReference();
281 bool parseMarkupdecl();
282 bool parseAttlistDecl();
283 bool parseAttType();
284 bool parseAttValue();
285 bool parseElementDecl();
286 bool parseNotationDecl();
287 bool parseChoiceSeq();
288 bool parseEntityDecl();
289 bool parseEntityValue();
290
291 bool parseString();
292
293 bool insertXmlRef(const QString&, const QString&, bool);
294
295 bool reportEndEntities();
296 void reportParseError(const QString& error);
297
298 typedef bool (QXmlSimpleReaderPrivate::*ParseFunction) ();
299 void unexpectedEof(ParseFunction where, int state);
300 void parseFailed(ParseFunction where, int state);
301 void pushParseState(ParseFunction function, int state);
302
303 bool isExpandedEntityValueTooLarge(QString *errorMessage);
304
305 Q_DECLARE_PUBLIC(QXmlSimpleReader)
306 QXmlSimpleReader *q_ptr;
307
308 friend class QXmlSimpleReaderLocator;
309 friend class QDomHandler;
310};
311Q_DECLARE_TYPEINFO(QXmlSimpleReaderPrivate::ParseState, Q_PRIMITIVE_TYPE);
312Q_DECLARE_TYPEINFO(QXmlSimpleReaderPrivate::XmlRef, Q_RELOCATABLE_TYPE);
313Q_DECLARE_TYPEINFO(QXmlSimpleReaderPrivate::ExternParameterEntity, Q_RELOCATABLE_TYPE);
314Q_DECLARE_TYPEINFO(QXmlSimpleReaderPrivate::ExternEntity, Q_RELOCATABLE_TYPE);
315
316QT_END_NAMESPACE
317
318#endif // QXML_P_H
319

source code of qt5compat/src/core5/sax/qxml_p.h