Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SkXMLParser Class Reference

#include <SkXMLParser.h>

Inheritance diagram for SkXMLParser:
SkDOMParser

Public Member Functions

 SkXMLParser (SkXMLParserError *parserError=nullptr)
 
virtual ~SkXMLParser ()
 
bool parse (const char doc[], size_t len)
 
bool parse (SkStream &docStream)
 
bool parse (const SkDOM &, const SkDOMNode *)
 
bool startElement (const char elem[])
 
bool addAttribute (const char name[], const char value[])
 
bool endElement (const char elem[])
 
bool text (const char text[], int len)
 

Static Public Member Functions

static void GetNativeErrorString (int nativeErrorCode, SkString *str)
 

Public Attributes

void * fParser
 

Protected Member Functions

virtual bool onStartElement (const char elem[])
 
virtual bool onAddAttribute (const char name[], const char value[])
 
virtual bool onEndElement (const char elem[])
 
virtual bool onText (const char text[], int len)
 

Protected Attributes

SkXMLParserErrorfError
 

Detailed Description

Definition at line 54 of file SkXMLParser.h.

Constructor & Destructor Documentation

◆ SkXMLParser()

SkXMLParser::SkXMLParser ( SkXMLParserError parserError = nullptr)

Definition at line 136 of file SkXMLParser.cpp.

136 : fParser(nullptr), fError(parserError)
137{
138}
SkXMLParserError * fError
Definition: SkXMLParser.h:82
void * fParser
Definition: SkXMLParser.h:80

◆ ~SkXMLParser()

SkXMLParser::~SkXMLParser ( )
virtual

Definition at line 140 of file SkXMLParser.cpp.

141{
142}

Member Function Documentation

◆ addAttribute()

bool SkXMLParser::addAttribute ( const char  name[],
const char  value[] 
)

Definition at line 221 of file SkXMLParser.cpp.

222{
223 return this->onAddAttribute(name, value);
224}
virtual bool onAddAttribute(const char name[], const char value[])
uint8_t value
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ endElement()

bool SkXMLParser::endElement ( const char  elem[])

Definition at line 226 of file SkXMLParser.cpp.

227{
228 return this->onEndElement(elem);
229}
virtual bool onEndElement(const char elem[])

◆ GetNativeErrorString()

void SkXMLParser::GetNativeErrorString ( int  nativeErrorCode,
SkString str 
)
static

Definition at line 211 of file SkXMLParser.cpp.

212{
213
214}

◆ onAddAttribute()

bool SkXMLParser::onAddAttribute ( const char  name[],
const char  value[] 
)
protectedvirtual

Reimplemented in SkDOMParser.

Definition at line 239 of file SkXMLParser.cpp.

239{return false; }

◆ onEndElement()

bool SkXMLParser::onEndElement ( const char  elem[])
protectedvirtual

Reimplemented in SkDOMParser.

Definition at line 240 of file SkXMLParser.cpp.

240{ return false; }

◆ onStartElement()

bool SkXMLParser::onStartElement ( const char  elem[])
protectedvirtual

Reimplemented in SkDOMParser.

Definition at line 238 of file SkXMLParser.cpp.

238{return false; }

◆ onText()

bool SkXMLParser::onText ( const char  text[],
int  len 
)
protectedvirtual

Reimplemented in SkDOMParser.

Definition at line 241 of file SkXMLParser.cpp.

241{return false; }

◆ parse() [1/3]

bool SkXMLParser::parse ( const char  doc[],
size_t  len 
)

Returns true for success

Definition at line 205 of file SkXMLParser.cpp.

206{
207 SkMemoryStream docStream(doc, len);
208 return this->parse(docStream);
209}
bool parse(const char doc[], size_t len)

◆ parse() [2/3]

bool SkXMLParser::parse ( const SkDOM dom,
const SkDOMNode node 
)

Definition at line 17 of file SkDOM.cpp.

17 {
18 const char* elemName = dom.getName(node);
19
20 if (this->startElement(elemName)) {
21 return false;
22 }
23
24 SkDOM::AttrIter iter(dom, node);
25 const char* name, *value;
26
27 while ((name = iter.next(&value)) != nullptr) {
28 if (this->addAttribute(name, value)) {
29 return false;
30 }
31 }
32
33 if ((node = dom.getFirstChild(node)) != nullptr) {
34 do {
35 if (!this->parse(dom, node)) {
36 return false;
37 }
38 } while ((node = dom.getNextSibling(node)) != nullptr);
39 }
40 return !this->endElement(elemName);
41}
bool startElement(const char elem[])
bool endElement(const char elem[])
bool addAttribute(const char name[], const char value[])
Definition: dom.py:1

◆ parse() [3/3]

bool SkXMLParser::parse ( SkStream docStream)

Definition at line 144 of file SkXMLParser.cpp.

145{
146 ParsingContext ctx(this);
147 if (!ctx.fXMLParser) {
148 SkDEBUGF("could not create XML parser\n");
149 return false;
150 }
151
152 // Avoid calls to rand_s if this is not set. This seed helps prevent DOS
153 // with a known hash sequence so an address is sufficient. The provided
154 // seed should not be zero as that results in a call to rand_s.
155 unsigned long seed = static_cast<unsigned long>(
156 reinterpret_cast<size_t>(kHashSeed) & 0xFFFFFFFF);
157 XML_SetHashSalt(ctx.fXMLParser, seed ? seed : 1);
158
159 XML_SetUserData(ctx.fXMLParser, &ctx);
160 XML_SetElementHandler(ctx.fXMLParser, start_element_handler, end_element_handler);
161 XML_SetCharacterDataHandler(ctx.fXMLParser, text_handler);
162
163 // Disable entity processing, to inhibit internal entity expansion. See expat CVE-2013-0340.
164 XML_SetEntityDeclHandler(ctx.fXMLParser, entity_decl_handler);
165
166 XML_Status status = XML_STATUS_OK;
167 if (docStream.getMemoryBase() && docStream.hasLength()) {
168 const char* base = reinterpret_cast<const char*>(docStream.getMemoryBase());
169 status = XML_Parse(ctx.fXMLParser,
170 base + docStream.getPosition(),
171 docStream.getLength() - docStream.getPosition(),
172 true);
173 } else {
174 static constexpr int kBufferSize = 4096;
175 bool done = false;
176 do {
177 void* buffer = XML_GetBuffer(ctx.fXMLParser, kBufferSize);
178 if (!buffer) {
179 SkDEBUGF("could not buffer enough to continue\n");
180 return false;
181 }
182
183 size_t len = docStream.read(buffer, kBufferSize);
184 done = docStream.isAtEnd();
185 status = XML_ParseBuffer(ctx.fXMLParser, SkToS32(len), done);
186 if (XML_STATUS_ERROR == status) {
187 break;
188 }
189 } while (!done);
190 }
191 if (XML_STATUS_ERROR == status) {
192#if defined(SK_DEBUG)
193 XML_Error error = XML_GetErrorCode(ctx.fXMLParser);
194 int line = XML_GetCurrentLineNumber(ctx.fXMLParser);
195 int column = XML_GetCurrentColumnNumber(ctx.fXMLParser);
196 const XML_LChar* errorString = XML_ErrorString(error);
197 SkDEBUGF("parse error @%d:%d: %d (%s).\n", line, column, error, errorString);
198#endif
199 return false;
200 }
201
202 return true;
203}
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
Definition: DM.cpp:263
#define SkDEBUGF(...)
Definition: SkDebug.h:24
static void XMLCALL start_element_handler(void *data, const char *tag, const char **attributes)
static void XMLCALL end_element_handler(void *data, const char *tag)
static const size_t kBufferSize
Definition: SkString.cpp:27
constexpr int32_t SkToS32(S x)
Definition: SkTo.h:25
virtual size_t getPosition() const
Definition: SkStream.h:119
virtual bool isAtEnd() const =0
virtual size_t getLength() const
Definition: SkStream.h:137
virtual const void * getMemoryBase()
Definition: SkStream.h:141
virtual bool hasLength() const
Definition: SkStream.h:135
virtual size_t read(void *buffer, size_t size)=0
const uint8_t uint32_t uint32_t GError ** error
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ startElement()

bool SkXMLParser::startElement ( const char  elem[])

Definition at line 216 of file SkXMLParser.cpp.

217{
218 return this->onStartElement(elem);
219}
virtual bool onStartElement(const char elem[])

◆ text()

bool SkXMLParser::text ( const char  text[],
int  len 
)

Definition at line 231 of file SkXMLParser.cpp.

232{
233 return this->onText(text, len);
234}
virtual bool onText(const char text[], int len)
bool text(const char text[], int len)

Member Data Documentation

◆ fError

SkXMLParserError* SkXMLParser::fError
protected

Definition at line 82 of file SkXMLParser.h.

◆ fParser

void* SkXMLParser::fParser

Definition at line 80 of file SkXMLParser.h.


The documentation for this class was generated from the following files: