summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/XMPPParser.cpp')
-rw-r--r--Swiften/Parser/XMPPParser.cpp28
1 files changed, 13 insertions, 15 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) {