summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/XMPPParser.cpp28
-rw-r--r--Swiften/Parser/XMPPParser.h15
2 files changed, 19 insertions, 24 deletions
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index 034077e..795bee6 100644
--- a/Swiften/Parser/XMPPParser.cpp
+++ b/Swiften/Parser/XMPPParser.cpp
@@ -49,7 +49,7 @@ XMPPParser::XMPPParser(
xmlParser_(0),
client_(client),
payloadParserFactories_(payloadParserFactories),
- currentDepth_(0),
+ level_(0),
currentElementParser_(0),
parseErrorOccurred_(false) {
xmlParser_ = PlatformXMLParserFactory().createXMLParser(this);
@@ -66,7 +66,7 @@ bool XMPPParser::parse(const String& data) {
}
void XMPPParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) {
- if (!inStream()) {
+ if (level_ == TopLevel) {
if (element == "stream" && ns == "http://etherx.jabber.org/streams") {
ProtocolHeader header;
header.setFrom(attributes.getAttribute("from"));
@@ -80,33 +80,31 @@ void XMPPParser::handleStartElement(const String& element, const String& ns, con
}
}
else {
- if (!inElement()) {
+ if (level_ == StreamLevel) {
assert(!currentElementParser_);
- delete currentElementParser_;
currentElementParser_ = createElementParser(element, ns);
}
currentElementParser_->handleStartElement(element, ns, attributes);
}
- ++currentDepth_;
+ ++level_;
}
void XMPPParser::handleEndElement(const String& element, const String& ns) {
- assert(inStream());
- if (inElement()) {
+ assert(level_ > TopLevel);
+ --level_;
+ if (level_ == TopLevel) {
+ assert(element == "stream");
+ client_->handleStreamEnd();
+ }
+ else {
assert(currentElementParser_);
currentElementParser_->handleEndElement(element, ns);
- --currentDepth_;
- if (!inElement()) {
+ if (level_ == StreamLevel) {
client_->handleElement(currentElementParser_->getElement());
delete currentElementParser_;
- currentElementParser_ = 0;
+ currentElementParser_ = NULL;
}
}
- else {
- assert(element == "stream");
- --currentDepth_;
- client_->handleStreamEnd();
- }
}
void XMPPParser::handleCharacterData(const String& data) {
diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h
index 45d005c..c1a9323 100644
--- a/Swiften/Parser/XMPPParser.h
+++ b/Swiften/Parser/XMPPParser.h
@@ -37,21 +37,18 @@ namespace Swift {
virtual void handleEndElement(const String& element, const String& ns);
virtual void handleCharacterData(const String& data);
- bool inStream() const {
- return currentDepth_ > 0;
- }
-
- bool inElement() const {
- return currentDepth_ > 1;
- }
-
ElementParser* createElementParser(const String& element, const String& xmlns);
private:
XMLParser* xmlParser_;
XMPPParserClient* client_;
PayloadParserFactoryCollection* payloadParserFactories_;
- int currentDepth_;
+ enum Level {
+ TopLevel = 0,
+ StreamLevel = 1,
+ ElementLevel = 2
+ };
+ int level_;
ElementParser* currentElementParser_;
bool parseErrorOccurred_;
};