diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-12-09 21:00:03 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-12-09 21:32:08 (GMT) |
commit | edabab9987aa7fd74f7db5dcfc77677472406180 (patch) | |
tree | 4512825cc540ea9412671f3bc8f970d90415568f /Swiften/Parser | |
parent | f0fec4f31afcc91a55d72aad462a0cc571aacf5d (diff) | |
download | swift-edabab9987aa7fd74f7db5dcfc77677472406180.zip swift-edabab9987aa7fd74f7db5dcfc77677472406180.tar.bz2 |
Added Stream error parserialement.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Parser/StreamErrorParser.cpp | 106 | ||||
-rw-r--r-- | Swiften/Parser/StreamErrorParser.h | 29 | ||||
-rw-r--r-- | Swiften/Parser/XMPPParser.cpp | 4 |
4 files changed, 140 insertions, 0 deletions
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 29398f0..6e77109 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -54,6 +54,7 @@ sources = [ "PresenceParser.cpp", "SerializingParser.cpp", "StanzaParser.cpp", + "StreamErrorParser.cpp", "StreamFeaturesParser.cpp", "XMLParser.cpp", "XMLParserClient.cpp", diff --git a/Swiften/Parser/StreamErrorParser.cpp b/Swiften/Parser/StreamErrorParser.cpp new file mode 100644 index 0000000..b121ef2 --- /dev/null +++ b/Swiften/Parser/StreamErrorParser.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Parser/StreamErrorParser.h> + +namespace Swift { + +StreamErrorParser::StreamErrorParser() : level(TopLevel) { +} + +void StreamErrorParser::handleStartElement(const String&, const String&, const AttributeMap&) { + ++level; +} + +void StreamErrorParser::handleEndElement(const String& element, const String&) { + --level; + if (level == ElementLevel) { + if (element == "text") { + getElementGeneric()->setText(currentText); + } + else if (element == "bad-format") { + getElementGeneric()->setType(StreamError::BadFormat); + } + else if(element == "bad-namespace-prefix") { + getElementGeneric()->setType(StreamError::BadNamespacePrefix); + } + else if(element == "conflict") { + getElementGeneric()->setType(StreamError::Conflict); + } + else if(element == "connection-timeout") { + getElementGeneric()->setType(StreamError::ConnectionTimeout); + } + else if(element == "host-gone") { + getElementGeneric()->setType(StreamError::HostGone); + } + else if(element == "host-unknown") { + getElementGeneric()->setType(StreamError::HostUnknown); + } + else if(element == "improper-addressing") { + getElementGeneric()->setType(StreamError::ImproperAddressing); + } + else if(element == "internal-server-error") { + getElementGeneric()->setType(StreamError::InternalServerError); + } + else if(element == "invalid-from") { + getElementGeneric()->setType(StreamError::InvalidFrom); + } + else if(element == "invalid-id") { + getElementGeneric()->setType(StreamError::InvalidID); + } + else if(element == "invalid-namespace") { + getElementGeneric()->setType(StreamError::InvalidNamespace); + } + else if(element == "invalid-xml") { + getElementGeneric()->setType(StreamError::InvalidXML); + } + else if(element == "not-authorized") { + getElementGeneric()->setType(StreamError::NotAuthorized); + } + else if(element == "policy-violation") { + getElementGeneric()->setType(StreamError::PolicyViolation); + } + else if(element == "remote-connection-failed") { + getElementGeneric()->setType(StreamError::RemoteConnectionFailed); + } + else if(element == "resource-constraint") { + getElementGeneric()->setType(StreamError::ResourceConstraint); + } + else if(element == "restricted-xml") { + getElementGeneric()->setType(StreamError::RestrictedXML); + } + else if(element == "see-other-host") { + getElementGeneric()->setType(StreamError::SeeOtherHost); + } + else if(element == "system-shutdown") { + getElementGeneric()->setType(StreamError::SystemShutdown); + } + else if(element == "undefined-condition") { + getElementGeneric()->setType(StreamError::UndefinedCondition); + } + else if(element == "unsupported-encoding") { + getElementGeneric()->setType(StreamError::UnsupportedEncoding); + } + else if(element == "unsupported-stanza-type") { + getElementGeneric()->setType(StreamError::UnsupportedStanzaType); + } + else if(element == "unsupported-version") { + getElementGeneric()->setType(StreamError::UnsupportedVersion); + } + else if(element == "xml-not-well-formed") { + getElementGeneric()->setType(StreamError::XMLNotWellFormed); + } + else { + getElementGeneric()->setType(StreamError::UndefinedCondition); + } + } +} + +void StreamErrorParser::handleCharacterData(const String& data) { + currentText += data; +} + +} diff --git a/Swiften/Parser/StreamErrorParser.h b/Swiften/Parser/StreamErrorParser.h new file mode 100644 index 0000000..a2aaa67 --- /dev/null +++ b/Swiften/Parser/StreamErrorParser.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Elements/StreamError.h> +#include <Swiften/Parser/GenericElementParser.h> + +namespace Swift { + class StreamErrorParser : public GenericElementParser<StreamError> { + public: + StreamErrorParser(); + + virtual void handleStartElement(const String& element, const String&, const AttributeMap& attributes); + virtual void handleEndElement(const String& element, const String&); + virtual void handleCharacterData(const String& data); + + private: + enum Level { + TopLevel = 0, + ElementLevel = 1 + }; + int level; + String currentText; + }; +} diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 6bd6082..26cebe2 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -20,6 +20,7 @@ #include "Swiften/Parser/IQParser.h" #include "Swiften/Parser/MessageParser.h" #include "Swiften/Parser/StreamFeaturesParser.h" +#include "Swiften/Parser/StreamErrorParser.h" #include "Swiften/Parser/AuthRequestParser.h" #include "Swiften/Parser/AuthSuccessParser.h" #include "Swiften/Parser/AuthFailureParser.h" @@ -136,6 +137,9 @@ ElementParser* XMPPParser::createElementParser(const String& element, const Stri else if (element == "features" && ns == "http://etherx.jabber.org/streams") { return new StreamFeaturesParser(); } + else if (element == "error" && ns == "urn:ietf:params:xml:ns:xmpp-streams") { + return new StreamErrorParser(); + } else if (element == "auth") { return new AuthRequestParser(); } |