diff options
Diffstat (limited to 'Swiften/Parser')
365 files changed, 11333 insertions, 11333 deletions
diff --git a/Swiften/Parser/Attribute.h b/Swiften/Parser/Attribute.h index 1c4ad77..f54317e 100644 --- a/Swiften/Parser/Attribute.h +++ b/Swiften/Parser/Attribute.h @@ -9,25 +9,25 @@ #include <string> namespace Swift { - class Attribute { - public: - Attribute(const std::string& name, const std::string& ns) : name(name), ns(ns) { - } + class Attribute { + public: + Attribute(const std::string& name, const std::string& ns) : name(name), ns(ns) { + } - const std::string& getName() const { - return name; - } + const std::string& getName() const { + return name; + } - const std::string& getNamespace() const { - return ns; - } + const std::string& getNamespace() const { + return ns; + } - bool operator==(const Attribute& o) const { - return o.name == name && o.ns == ns; - } + bool operator==(const Attribute& o) const { + return o.name == name && o.ns == ns; + } - private: - std::string name; - std::string ns; - }; + private: + std::string name; + std::string ns; + }; } diff --git a/Swiften/Parser/AttributeMap.cpp b/Swiften/Parser/AttributeMap.cpp index 3fb8faf..c112d52 100644 --- a/Swiften/Parser/AttributeMap.cpp +++ b/Swiften/Parser/AttributeMap.cpp @@ -19,38 +19,38 @@ AttributeMap::AttributeMap() { } std::string AttributeMap::getAttribute(const std::string& attribute, const std::string& ns) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), - lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, ns)); - if (i == attributes.end()) { - return ""; - } - else { - return i->getValue(); - } + AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), + lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, ns)); + if (i == attributes.end()) { + return ""; + } + else { + return i->getValue(); + } } bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultValue) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), - lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, "")); - if (i == attributes.end()) { - return defaultValue; - } - else { - return i->getValue() == "true" || i->getValue() == "1"; - } + AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), + lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, "")); + if (i == attributes.end()) { + return defaultValue; + } + else { + return i->getValue() == "true" || i->getValue() == "1"; + } } boost::optional<std::string> AttributeMap::getAttributeValue(const std::string& attribute) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), - lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, "")); - if (i == attributes.end()) { - return boost::optional<std::string>(); - } - else { - return i->getValue(); - } + AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), + lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, "")); + if (i == attributes.end()) { + return boost::optional<std::string>(); + } + else { + return i->getValue(); + } } void AttributeMap::addAttribute(const std::string& name, const std::string& ns, const std::string& value) { - attributes.push_back(Entry(Attribute(name, ns), value)); + attributes.push_back(Entry(Attribute(name, ns), value)); } diff --git a/Swiften/Parser/AttributeMap.h b/Swiften/Parser/AttributeMap.h index 336f4cd..798649a 100644 --- a/Swiften/Parser/AttributeMap.h +++ b/Swiften/Parser/AttributeMap.h @@ -16,40 +16,40 @@ #include <Swiften/Parser/Attribute.h> namespace Swift { - class SWIFTEN_API AttributeMap { - public: - class Entry { - public: - Entry(const Attribute& attribute, const std::string& value) : attribute(attribute), value(value) { - } - - const Attribute& getAttribute() const { - return attribute; - } - - const std::string& getValue() const { - return value; - } - - private: - Attribute attribute; - std::string value; - }; - - AttributeMap(); - - std::string getAttribute(const std::string& attribute, const std::string& ns = "") const; - bool getBoolAttribute(const std::string& attribute, bool defaultValue = false) const; - boost::optional<std::string> getAttributeValue(const std::string&) const; - - void addAttribute(const std::string& name, const std::string& ns, const std::string& value); - - const std::vector<Entry>& getEntries() const { - return attributes; - } - - private: - typedef std::vector<Entry> AttributeValueMap; - AttributeValueMap attributes; - }; + class SWIFTEN_API AttributeMap { + public: + class Entry { + public: + Entry(const Attribute& attribute, const std::string& value) : attribute(attribute), value(value) { + } + + const Attribute& getAttribute() const { + return attribute; + } + + const std::string& getValue() const { + return value; + } + + private: + Attribute attribute; + std::string value; + }; + + AttributeMap(); + + std::string getAttribute(const std::string& attribute, const std::string& ns = "") const; + bool getBoolAttribute(const std::string& attribute, bool defaultValue = false) const; + boost::optional<std::string> getAttributeValue(const std::string&) const; + + void addAttribute(const std::string& name, const std::string& ns, const std::string& value); + + const std::vector<Entry>& getEntries() const { + return attributes; + } + + private: + typedef std::vector<Entry> AttributeValueMap; + AttributeValueMap attributes; + }; } diff --git a/Swiften/Parser/AuthChallengeParser.cpp b/Swiften/Parser/AuthChallengeParser.cpp index 42f5ca6..cf69672 100644 --- a/Swiften/Parser/AuthChallengeParser.cpp +++ b/Swiften/Parser/AuthChallengeParser.cpp @@ -14,18 +14,18 @@ AuthChallengeParser::AuthChallengeParser() : GenericElementParser<AuthChallenge> } void AuthChallengeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void AuthChallengeParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setValue(Base64::decode(text)); - } + --depth; + if (depth == 0) { + getElementGeneric()->setValue(Base64::decode(text)); + } } void AuthChallengeParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/AuthChallengeParser.h b/Swiften/Parser/AuthChallengeParser.h index 464f0c1..48e2bfb 100644 --- a/Swiften/Parser/AuthChallengeParser.h +++ b/Swiften/Parser/AuthChallengeParser.h @@ -13,16 +13,16 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API AuthChallengeParser : public GenericElementParser<AuthChallenge> { - public: - AuthChallengeParser(); + class SWIFTEN_API AuthChallengeParser : public GenericElementParser<AuthChallenge> { + public: + AuthChallengeParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/AuthFailureParser.h b/Swiften/Parser/AuthFailureParser.h index 3148222..1706290 100644 --- a/Swiften/Parser/AuthFailureParser.h +++ b/Swiften/Parser/AuthFailureParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API AuthFailureParser : public GenericElementParser<AuthFailure> { - public: - AuthFailureParser() : GenericElementParser<AuthFailure>() {} - }; + class SWIFTEN_API AuthFailureParser : public GenericElementParser<AuthFailure> { + public: + AuthFailureParser() : GenericElementParser<AuthFailure>() {} + }; } diff --git a/Swiften/Parser/AuthRequestParser.cpp b/Swiften/Parser/AuthRequestParser.cpp index 2fb311c..a24be8d 100644 --- a/Swiften/Parser/AuthRequestParser.cpp +++ b/Swiften/Parser/AuthRequestParser.cpp @@ -14,21 +14,21 @@ AuthRequestParser::AuthRequestParser() : GenericElementParser<AuthRequest>(), de } void AuthRequestParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attribute) { - if (depth_ == 0) { - getElementGeneric()->setMechanism(attribute.getAttribute("mechanism")); - } - ++depth_; + if (depth_ == 0) { + getElementGeneric()->setMechanism(attribute.getAttribute("mechanism")); + } + ++depth_; } void AuthRequestParser::handleEndElement(const std::string&, const std::string&) { - --depth_; - if (depth_ == 0) { - getElementGeneric()->setMessage(createSafeByteArray(Base64::decode(text_))); - } + --depth_; + if (depth_ == 0) { + getElementGeneric()->setMessage(createSafeByteArray(Base64::decode(text_))); + } } void AuthRequestParser::handleCharacterData(const std::string& text) { - text_ += text; + text_ += text; } } diff --git a/Swiften/Parser/AuthRequestParser.h b/Swiften/Parser/AuthRequestParser.h index 005bd48..ac94abf 100644 --- a/Swiften/Parser/AuthRequestParser.h +++ b/Swiften/Parser/AuthRequestParser.h @@ -13,16 +13,16 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API AuthRequestParser : public GenericElementParser<AuthRequest> { - public: - AuthRequestParser(); + class SWIFTEN_API AuthRequestParser : public GenericElementParser<AuthRequest> { + public: + AuthRequestParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - std::string text_; - int depth_; - }; + private: + std::string text_; + int depth_; + }; } diff --git a/Swiften/Parser/AuthResponseParser.cpp b/Swiften/Parser/AuthResponseParser.cpp index 64fe6c8..59f6455 100644 --- a/Swiften/Parser/AuthResponseParser.cpp +++ b/Swiften/Parser/AuthResponseParser.cpp @@ -14,18 +14,18 @@ AuthResponseParser::AuthResponseParser() : GenericElementParser<AuthResponse>(), } void AuthResponseParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void AuthResponseParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setValue(createSafeByteArray(Base64::decode(text))); - } + --depth; + if (depth == 0) { + getElementGeneric()->setValue(createSafeByteArray(Base64::decode(text))); + } } void AuthResponseParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/AuthResponseParser.h b/Swiften/Parser/AuthResponseParser.h index 1846a41..6cbfa22 100644 --- a/Swiften/Parser/AuthResponseParser.h +++ b/Swiften/Parser/AuthResponseParser.h @@ -13,16 +13,16 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API AuthResponseParser : public GenericElementParser<AuthResponse> { - public: - AuthResponseParser(); + class SWIFTEN_API AuthResponseParser : public GenericElementParser<AuthResponse> { + public: + AuthResponseParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/AuthSuccessParser.cpp b/Swiften/Parser/AuthSuccessParser.cpp index c50fab3..964fd6c 100644 --- a/Swiften/Parser/AuthSuccessParser.cpp +++ b/Swiften/Parser/AuthSuccessParser.cpp @@ -14,18 +14,18 @@ AuthSuccessParser::AuthSuccessParser() : GenericElementParser<AuthSuccess>(), de } void AuthSuccessParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void AuthSuccessParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setValue(Base64::decode(text)); - } + --depth; + if (depth == 0) { + getElementGeneric()->setValue(Base64::decode(text)); + } } void AuthSuccessParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/AuthSuccessParser.h b/Swiften/Parser/AuthSuccessParser.h index a35f61e..cedc8d1 100644 --- a/Swiften/Parser/AuthSuccessParser.h +++ b/Swiften/Parser/AuthSuccessParser.h @@ -13,16 +13,16 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API AuthSuccessParser : public GenericElementParser<AuthSuccess> { - public: - AuthSuccessParser(); + class SWIFTEN_API AuthSuccessParser : public GenericElementParser<AuthSuccess> { + public: + AuthSuccessParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp index e0a37df..c5723be 100644 --- a/Swiften/Parser/BOSHBodyExtractor.cpp +++ b/Swiften/Parser/BOSHBodyExtractor.cpp @@ -16,124 +16,124 @@ namespace Swift { class BOSHBodyParserClient : public XMLParserClient { - public: - BOSHBodyParserClient(BOSHBodyExtractor* bodyExtractor) : bodyExtractor(bodyExtractor) { - } + public: + BOSHBodyParserClient(BOSHBodyExtractor* bodyExtractor) : bodyExtractor(bodyExtractor) { + } - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - bodyExtractor->body->attributes = attributes; - } + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + bodyExtractor->body->attributes = attributes; + } - virtual void handleEndElement(const std::string&, const std::string&) { - } + virtual void handleEndElement(const std::string&, const std::string&) { + } - virtual void handleCharacterData(const std::string&) { - } + virtual void handleCharacterData(const std::string&) { + } - private: - BOSHBodyExtractor* bodyExtractor; + private: + BOSHBodyExtractor* bodyExtractor; }; inline bool isWhitespace(unsigned char c) { - return c == ' ' || c == '\n' || c == '\t' || c == '\r'; + return c == ' ' || c == '\n' || c == '\t' || c == '\r'; } BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const ByteArray& data) { - // Look for the opening body element - ByteArray::const_iterator i = data.begin(); - while (i < data.end() && isWhitespace(*i)) { - ++i; - } - if (std::distance(i, data.end()) < 6 || *i != '<' || *(i+1) != 'b' || *(i+2) != 'o' || *(i+3) != 'd' || *(i+4) != 'y' || !(isWhitespace(*(i+5)) || *(i+5) == '>' || *(i+5) == '/')) { - return; - } - i += 5; - - // Parse until end of element - bool inSingleQuote = false; - bool inDoubleQuote = false; - bool endStartTagSeen = false; - bool endElementSeen = false; - for (; i != data.end(); ++i) { - char c = static_cast<char>(*i); - if (inSingleQuote) { - if (c == '\'') { - inSingleQuote = false; - } - } - else if (inDoubleQuote) { - if (c == '"') { - inDoubleQuote = false; - } - } - else if (c == '\'') { - inSingleQuote = true; - } - else if (c == '"') { - inDoubleQuote = true; - } - else if (c == '/') { - if (i + 1 == data.end() || *(i+1) != '>') { - return; - } - else { - endElementSeen = true; - endStartTagSeen = true; - i += 2; - break; - } - } - else if (c == '>') { - endStartTagSeen = true; - i += 1; - break; - } - } - - if (!endStartTagSeen) { - return; - } - - // Look for the end of the element - ByteArray::const_reverse_iterator j = data.rbegin(); - if (!endElementSeen) { - while (isWhitespace(*j) && j < data.rend()) { - ++j; - } - - if (j == data.rend() || *j != '>') { - return; - } - ++j; - - while (j < data.rend() && isWhitespace(*j)) { - ++j; - } - - if (std::distance(j, data.rend()) < 6 || *(j+5) != '<' || *(j+4) != '/' || *(j+3) != 'b' || *(j+2) != 'o' || *(j+1) != 'd' || *j != 'y') { - return; - } - j += 6; - } - - body = BOSHBody(); - if (!endElementSeen) { - body->content = std::string( - reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)), - boost::numeric_cast<size_t>(std::distance(i, j.base()))); - } - - // Parse the body element - BOSHBodyParserClient parserClient(this); - boost::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); - if (!parser->parse(std::string( - reinterpret_cast<const char*>(vecptr(data)), - boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) { - /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at - the correct higher layer */ - body = boost::optional<BOSHBody>(); - return; - } + // Look for the opening body element + ByteArray::const_iterator i = data.begin(); + while (i < data.end() && isWhitespace(*i)) { + ++i; + } + if (std::distance(i, data.end()) < 6 || *i != '<' || *(i+1) != 'b' || *(i+2) != 'o' || *(i+3) != 'd' || *(i+4) != 'y' || !(isWhitespace(*(i+5)) || *(i+5) == '>' || *(i+5) == '/')) { + return; + } + i += 5; + + // Parse until end of element + bool inSingleQuote = false; + bool inDoubleQuote = false; + bool endStartTagSeen = false; + bool endElementSeen = false; + for (; i != data.end(); ++i) { + char c = static_cast<char>(*i); + if (inSingleQuote) { + if (c == '\'') { + inSingleQuote = false; + } + } + else if (inDoubleQuote) { + if (c == '"') { + inDoubleQuote = false; + } + } + else if (c == '\'') { + inSingleQuote = true; + } + else if (c == '"') { + inDoubleQuote = true; + } + else if (c == '/') { + if (i + 1 == data.end() || *(i+1) != '>') { + return; + } + else { + endElementSeen = true; + endStartTagSeen = true; + i += 2; + break; + } + } + else if (c == '>') { + endStartTagSeen = true; + i += 1; + break; + } + } + + if (!endStartTagSeen) { + return; + } + + // Look for the end of the element + ByteArray::const_reverse_iterator j = data.rbegin(); + if (!endElementSeen) { + while (isWhitespace(*j) && j < data.rend()) { + ++j; + } + + if (j == data.rend() || *j != '>') { + return; + } + ++j; + + while (j < data.rend() && isWhitespace(*j)) { + ++j; + } + + if (std::distance(j, data.rend()) < 6 || *(j+5) != '<' || *(j+4) != '/' || *(j+3) != 'b' || *(j+2) != 'o' || *(j+1) != 'd' || *j != 'y') { + return; + } + j += 6; + } + + body = BOSHBody(); + if (!endElementSeen) { + body->content = std::string( + reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)), + boost::numeric_cast<size_t>(std::distance(i, j.base()))); + } + + // Parse the body element + BOSHBodyParserClient parserClient(this); + boost::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); + if (!parser->parse(std::string( + reinterpret_cast<const char*>(vecptr(data)), + boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) { + /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at + the correct higher layer */ + body = boost::optional<BOSHBody>(); + return; + } } } diff --git a/Swiften/Parser/BOSHBodyExtractor.h b/Swiften/Parser/BOSHBodyExtractor.h index 2112ff7..ba56b41 100644 --- a/Swiften/Parser/BOSHBodyExtractor.h +++ b/Swiften/Parser/BOSHBodyExtractor.h @@ -13,23 +13,23 @@ #include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class XMLParserFactory; - - class SWIFTEN_API BOSHBodyExtractor { - friend class BOSHBodyParserClient; - public: - struct BOSHBody { - AttributeMap attributes; - std::string content; - }; - - BOSHBodyExtractor(XMLParserFactory* parserFactory, const ByteArray& data); - - const boost::optional<BOSHBody>& getBody() const { - return body; - } - - private: - boost::optional<BOSHBody> body; - }; + class XMLParserFactory; + + class SWIFTEN_API BOSHBodyExtractor { + friend class BOSHBodyParserClient; + public: + struct BOSHBody { + AttributeMap attributes; + std::string content; + }; + + BOSHBodyExtractor(XMLParserFactory* parserFactory, const ByteArray& data); + + const boost::optional<BOSHBody>& getBody() const { + return body; + } + + private: + boost::optional<BOSHBody> body; + }; } diff --git a/Swiften/Parser/ComponentHandshakeParser.cpp b/Swiften/Parser/ComponentHandshakeParser.cpp index 3899763..f98503d 100644 --- a/Swiften/Parser/ComponentHandshakeParser.cpp +++ b/Swiften/Parser/ComponentHandshakeParser.cpp @@ -14,18 +14,18 @@ ComponentHandshakeParser::ComponentHandshakeParser() : GenericElementParser<Comp } void ComponentHandshakeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void ComponentHandshakeParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setData(text); - } + --depth; + if (depth == 0) { + getElementGeneric()->setData(text); + } } void ComponentHandshakeParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/ComponentHandshakeParser.h b/Swiften/Parser/ComponentHandshakeParser.h index b9e4e76..5f4af80 100644 --- a/Swiften/Parser/ComponentHandshakeParser.h +++ b/Swiften/Parser/ComponentHandshakeParser.h @@ -13,16 +13,16 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API ComponentHandshakeParser : public GenericElementParser<ComponentHandshake> { - public: - ComponentHandshakeParser(); + class SWIFTEN_API ComponentHandshakeParser : public GenericElementParser<ComponentHandshake> { + public: + ComponentHandshakeParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/CompressFailureParser.h b/Swiften/Parser/CompressFailureParser.h index cee6ade..5c171ee 100644 --- a/Swiften/Parser/CompressFailureParser.h +++ b/Swiften/Parser/CompressFailureParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API CompressFailureParser : public GenericElementParser<CompressFailure> { - public: - CompressFailureParser() : GenericElementParser<CompressFailure>() {} - }; + class SWIFTEN_API CompressFailureParser : public GenericElementParser<CompressFailure> { + public: + CompressFailureParser() : GenericElementParser<CompressFailure>() {} + }; } diff --git a/Swiften/Parser/CompressParser.cpp b/Swiften/Parser/CompressParser.cpp index 1d69af6..00f762f 100644 --- a/Swiften/Parser/CompressParser.cpp +++ b/Swiften/Parser/CompressParser.cpp @@ -12,23 +12,23 @@ CompressParser::CompressParser() : GenericElementParser<CompressRequest>(), curr } void CompressParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (currentDepth_ == 1 && element == "method") { - inMethod_ = true; - currentText_ = ""; - } - ++currentDepth_; + if (currentDepth_ == 1 && element == "method") { + inMethod_ = true; + currentText_ = ""; + } + ++currentDepth_; } void CompressParser::handleEndElement(const std::string&, const std::string&) { - --currentDepth_; - if (currentDepth_ == 1 && inMethod_) { - getElementGeneric()->setMethod(currentText_); - inMethod_ = false; - } + --currentDepth_; + if (currentDepth_ == 1 && inMethod_) { + getElementGeneric()->setMethod(currentText_); + inMethod_ = false; + } } void CompressParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/CompressParser.h b/Swiften/Parser/CompressParser.h index 8a546dc..6f0a0cb 100644 --- a/Swiften/Parser/CompressParser.h +++ b/Swiften/Parser/CompressParser.h @@ -13,18 +13,18 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API CompressParser : public GenericElementParser<CompressRequest> { - public: - CompressParser(); + class SWIFTEN_API CompressParser : public GenericElementParser<CompressRequest> { + public: + CompressParser(); - private: - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + private: + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - private: - int currentDepth_; - std::string currentText_; - bool inMethod_; - }; + private: + int currentDepth_; + std::string currentText_; + bool inMethod_; + }; } diff --git a/Swiften/Parser/CompressedParser.h b/Swiften/Parser/CompressedParser.h index a1cf4ea..859b509 100644 --- a/Swiften/Parser/CompressedParser.h +++ b/Swiften/Parser/CompressedParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API CompressedParser : public GenericElementParser<Compressed> { - public: - CompressedParser() : GenericElementParser<Compressed>() {} - }; + class SWIFTEN_API CompressedParser : public GenericElementParser<Compressed> { + public: + CompressedParser() : GenericElementParser<Compressed>() {} + }; } diff --git a/Swiften/Parser/ElementParser.h b/Swiften/Parser/ElementParser.h index 7653276..12c6c38 100644 --- a/Swiften/Parser/ElementParser.h +++ b/Swiften/Parser/ElementParser.h @@ -15,14 +15,14 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class SWIFTEN_API ElementParser { - public: - virtual ~ElementParser(); + class SWIFTEN_API ElementParser { + public: + virtual ~ElementParser(); - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; - virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; - virtual void handleCharacterData(const std::string& data) = 0; + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; + virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; + virtual void handleCharacterData(const std::string& data) = 0; - virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; - }; + virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; + }; } diff --git a/Swiften/Parser/EnableStreamManagementParser.h b/Swiften/Parser/EnableStreamManagementParser.h index 7fa8547..b010740 100644 --- a/Swiften/Parser/EnableStreamManagementParser.h +++ b/Swiften/Parser/EnableStreamManagementParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API EnableStreamManagementParser : public GenericElementParser<EnableStreamManagement> { - public: - EnableStreamManagementParser() : GenericElementParser<EnableStreamManagement>() {} - }; + class SWIFTEN_API EnableStreamManagementParser : public GenericElementParser<EnableStreamManagement> { + public: + EnableStreamManagementParser() : GenericElementParser<EnableStreamManagement>() {} + }; } diff --git a/Swiften/Parser/EnumParser.h b/Swiften/Parser/EnumParser.h index b49d290..cf17ead 100644 --- a/Swiften/Parser/EnumParser.h +++ b/Swiften/Parser/EnumParser.h @@ -16,23 +16,23 @@ #include <Swiften/Base/Override.h> namespace Swift { - template<typename T> - class SWIFTEN_API EnumParser { - public: - EnumParser() { - } - - EnumParser& operator()(T value, const std::string& text) { - values[text] = value; - return *this; - } - - boost::optional<T> parse(const std::string& value) { - typename std::map<std::string, T>::const_iterator i = values.find(value); - return i == values.end() ? boost::optional<T>() : i->second; - } - - private: - std::map<std::string, T> values; - }; + template<typename T> + class SWIFTEN_API EnumParser { + public: + EnumParser() { + } + + EnumParser& operator()(T value, const std::string& text) { + values[text] = value; + return *this; + } + + boost::optional<T> parse(const std::string& value) { + typename std::map<std::string, T>::const_iterator i = values.find(value); + return i == values.end() ? boost::optional<T>() : i->second; + } + + private: + std::map<std::string, T> values; + }; } diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp index 60ee81e..fba82e2 100644 --- a/Swiften/Parser/ExpatParser.cpp +++ b/Swiften/Parser/ExpatParser.cpp @@ -21,75 +21,75 @@ namespace Swift { static const char NAMESPACE_SEPARATOR = '\x01'; struct ExpatParser::Private { - XML_Parser parser_; + XML_Parser parser_; }; static void handleStartElement(void* parser, const XML_Char* name, const XML_Char** attributes) { - std::pair<std::string,std::string> nsTagPair = String::getSplittedAtFirst(name, NAMESPACE_SEPARATOR); - if (nsTagPair.second == "") { - nsTagPair.second = nsTagPair.first; - nsTagPair.first = ""; - } - AttributeMap attributeValues; - const XML_Char** currentAttribute = attributes; - while (*currentAttribute) { - std::pair<std::string,std::string> nsAttributePair = String::getSplittedAtFirst(*currentAttribute, NAMESPACE_SEPARATOR); - if (nsAttributePair.second == "") { - nsAttributePair.second = nsAttributePair.first; - nsAttributePair.first = ""; - } - attributeValues.addAttribute(nsAttributePair.second, nsAttributePair.first, std::string(*(currentAttribute+1))); - currentAttribute += 2; - } - - static_cast<XMLParser*>(parser)->getClient()->handleStartElement(nsTagPair.second, nsTagPair.first, attributeValues); + std::pair<std::string,std::string> nsTagPair = String::getSplittedAtFirst(name, NAMESPACE_SEPARATOR); + if (nsTagPair.second == "") { + nsTagPair.second = nsTagPair.first; + nsTagPair.first = ""; + } + AttributeMap attributeValues; + const XML_Char** currentAttribute = attributes; + while (*currentAttribute) { + std::pair<std::string,std::string> nsAttributePair = String::getSplittedAtFirst(*currentAttribute, NAMESPACE_SEPARATOR); + if (nsAttributePair.second == "") { + nsAttributePair.second = nsAttributePair.first; + nsAttributePair.first = ""; + } + attributeValues.addAttribute(nsAttributePair.second, nsAttributePair.first, std::string(*(currentAttribute+1))); + currentAttribute += 2; + } + + static_cast<XMLParser*>(parser)->getClient()->handleStartElement(nsTagPair.second, nsTagPair.first, attributeValues); } static void handleEndElement(void* parser, const XML_Char* name) { - std::pair<std::string,std::string> nsTagPair = String::getSplittedAtFirst(name, NAMESPACE_SEPARATOR); - if (nsTagPair.second == "") { - nsTagPair.second = nsTagPair.first; - nsTagPair.first = ""; - } - static_cast<XMLParser*>(parser)->getClient()->handleEndElement(nsTagPair.second, nsTagPair.first); + std::pair<std::string,std::string> nsTagPair = String::getSplittedAtFirst(name, NAMESPACE_SEPARATOR); + if (nsTagPair.second == "") { + nsTagPair.second = nsTagPair.first; + nsTagPair.first = ""; + } + static_cast<XMLParser*>(parser)->getClient()->handleEndElement(nsTagPair.second, nsTagPair.first); } static void handleCharacterData(void* parser, const XML_Char* data, int len) { - assert(len >= 0); - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(data, static_cast<size_t>(len))); + assert(len >= 0); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(data, static_cast<size_t>(len))); } static void handleXMLDeclaration(void*, const XML_Char*, const XML_Char*, int) { } static void handleEntityDeclaration(void* parser, const XML_Char*, int, const XML_Char*, int, const XML_Char*, const XML_Char*, const XML_Char*, const XML_Char*) { - static_cast<ExpatParser*>(parser)->stopParser(); + static_cast<ExpatParser*>(parser)->stopParser(); } ExpatParser::ExpatParser(XMLParserClient* client) : XMLParser(client), p(new Private()) { - p->parser_ = XML_ParserCreateNS("UTF-8", NAMESPACE_SEPARATOR); - XML_SetUserData(p->parser_, this); - XML_SetElementHandler(p->parser_, handleStartElement, handleEndElement); - XML_SetCharacterDataHandler(p->parser_, handleCharacterData); - XML_SetXmlDeclHandler(p->parser_, handleXMLDeclaration); - XML_SetEntityDeclHandler(p->parser_, handleEntityDeclaration); + p->parser_ = XML_ParserCreateNS("UTF-8", NAMESPACE_SEPARATOR); + XML_SetUserData(p->parser_, this); + XML_SetElementHandler(p->parser_, handleStartElement, handleEndElement); + XML_SetCharacterDataHandler(p->parser_, handleCharacterData); + XML_SetXmlDeclHandler(p->parser_, handleXMLDeclaration); + XML_SetEntityDeclHandler(p->parser_, handleEntityDeclaration); } ExpatParser::~ExpatParser() { - XML_ParserFree(p->parser_); + XML_ParserFree(p->parser_); } bool ExpatParser::parse(const std::string& data) { - bool success = XML_Parse(p->parser_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_STATUS_OK; - /*if (!success) { - std::cout << "ERROR: " << XML_ErrorString(XML_GetErrorCode(p->parser_)) << " while parsing " << data << std::endl; - }*/ - return success; + bool success = XML_Parse(p->parser_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_STATUS_OK; + /*if (!success) { + std::cout << "ERROR: " << XML_ErrorString(XML_GetErrorCode(p->parser_)) << " while parsing " << data << std::endl; + }*/ + return success; } void ExpatParser::stopParser() { - XML_StopParser(p->parser_, static_cast<XML_Bool>(0)); + XML_StopParser(p->parser_, static_cast<XML_Bool>(0)); } } diff --git a/Swiften/Parser/ExpatParser.h b/Swiften/Parser/ExpatParser.h index c0c38c1..581847b 100644 --- a/Swiften/Parser/ExpatParser.h +++ b/Swiften/Parser/ExpatParser.h @@ -13,17 +13,17 @@ #include <Swiften/Parser/XMLParser.h> namespace Swift { - class SWIFTEN_API ExpatParser : public XMLParser, public boost::noncopyable { - public: - ExpatParser(XMLParserClient* client); - ~ExpatParser(); + class SWIFTEN_API ExpatParser : public XMLParser, public boost::noncopyable { + public: + ExpatParser(XMLParserClient* client); + ~ExpatParser(); - bool parse(const std::string& data); + bool parse(const std::string& data); - void stopParser(); + void stopParser(); - private: - struct Private; - boost::shared_ptr<Private> p; - }; + private: + struct Private; + boost::shared_ptr<Private> p; + }; } diff --git a/Swiften/Parser/GenericElementParser.h b/Swiften/Parser/GenericElementParser.h index 9cdec23..7a0f989 100644 --- a/Swiften/Parser/GenericElementParser.h +++ b/Swiften/Parser/GenericElementParser.h @@ -13,35 +13,35 @@ #include <Swiften/Parser/ElementParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - template<typename ElementType> - class SWIFTEN_API GenericElementParser : public ElementParser { - public: - GenericElementParser() { - stanza_ = boost::make_shared<ElementType>(); - } + class PayloadParserFactoryCollection; - virtual boost::shared_ptr<ToplevelElement> getElement() const { - return stanza_; - } + template<typename ElementType> + class SWIFTEN_API GenericElementParser : public ElementParser { + public: + GenericElementParser() { + stanza_ = boost::make_shared<ElementType>(); + } - virtual boost::shared_ptr<ElementType> getElementGeneric() const { - return stanza_; - } + virtual boost::shared_ptr<ToplevelElement> getElement() const { + return stanza_; + } - private: - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + virtual boost::shared_ptr<ElementType> getElementGeneric() const { + return stanza_; + } - virtual void handleEndElement(const std::string&, const std::string&) { - } + private: + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - virtual void handleCharacterData(const std::string&) { - } + virtual void handleEndElement(const std::string&, const std::string&) { + } - private: - boost::shared_ptr<ElementType> stanza_; - }; + virtual void handleCharacterData(const std::string&) { + } + + private: + boost::shared_ptr<ElementType> stanza_; + }; } diff --git a/Swiften/Parser/GenericPayloadParser.h b/Swiften/Parser/GenericPayloadParser.h index b6cd2d7..be0172c 100644 --- a/Swiften/Parser/GenericPayloadParser.h +++ b/Swiften/Parser/GenericPayloadParser.h @@ -13,31 +13,31 @@ #include <Swiften/Parser/PayloadParser.h> namespace Swift { - - class FormParser; - - /** - * A generic payload parser for payloads of the given type. - * - * This class provides getPayloadInternal() for retrieving the actual - * payload. - */ - template<typename PAYLOAD_TYPE> - class GenericPayloadParser : public PayloadParser { - public: - GenericPayloadParser() : PayloadParser() { - payload_ = boost::make_shared<PAYLOAD_TYPE>(); - } - - virtual boost::shared_ptr<Payload> getPayload() const { - return payload_; - } - - virtual boost::shared_ptr<PAYLOAD_TYPE> getPayloadInternal() const { - return payload_; - } - - private: - boost::shared_ptr<PAYLOAD_TYPE> payload_; - }; + + class FormParser; + + /** + * A generic payload parser for payloads of the given type. + * + * This class provides getPayloadInternal() for retrieving the actual + * payload. + */ + template<typename PAYLOAD_TYPE> + class GenericPayloadParser : public PayloadParser { + public: + GenericPayloadParser() : PayloadParser() { + payload_ = boost::make_shared<PAYLOAD_TYPE>(); + } + + virtual boost::shared_ptr<Payload> getPayload() const { + return payload_; + } + + virtual boost::shared_ptr<PAYLOAD_TYPE> getPayloadInternal() const { + return payload_; + } + + private: + boost::shared_ptr<PAYLOAD_TYPE> payload_; + }; } diff --git a/Swiften/Parser/GenericPayloadParserFactory.h b/Swiften/Parser/GenericPayloadParserFactory.h index c980073..fcdec62 100644 --- a/Swiften/Parser/GenericPayloadParserFactory.h +++ b/Swiften/Parser/GenericPayloadParserFactory.h @@ -13,27 +13,27 @@ namespace Swift { - /** - * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). - */ - template<typename PARSER_TYPE> - class GenericPayloadParserFactory : public PayloadParserFactory { - public: - /** - * Construct a parser factory that can parse the given top-level tag in the given namespace. - */ - GenericPayloadParserFactory(const std::string& tag, const std::string& xmlns = "") : tag_(tag), xmlns_(xmlns) {} - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); - } - - virtual PayloadParser* createPayloadParser() { - return new PARSER_TYPE(); - } - - private: - std::string tag_; - std::string xmlns_; - }; + /** + * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). + */ + template<typename PARSER_TYPE> + class GenericPayloadParserFactory : public PayloadParserFactory { + public: + /** + * Construct a parser factory that can parse the given top-level tag in the given namespace. + */ + GenericPayloadParserFactory(const std::string& tag, const std::string& xmlns = "") : tag_(tag), xmlns_(xmlns) {} + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); + } + + virtual PayloadParser* createPayloadParser() { + return new PARSER_TYPE(); + } + + private: + std::string tag_; + std::string xmlns_; + }; } diff --git a/Swiften/Parser/GenericPayloadParserFactory2.h b/Swiften/Parser/GenericPayloadParserFactory2.h index 7591897..f55d317 100644 --- a/Swiften/Parser/GenericPayloadParserFactory2.h +++ b/Swiften/Parser/GenericPayloadParserFactory2.h @@ -12,30 +12,30 @@ #include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { - class PayloadParserFactoryCollection; - - /** - * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). - */ - template<typename PARSER_TYPE> - class GenericPayloadParserFactory2 : public PayloadParserFactory { - public: - /** - * Construct a parser factory that can parse the given top-level tag in the given namespace. - */ - GenericPayloadParserFactory2(const std::string& tag, const std::string& xmlns, PayloadParserFactoryCollection* parsers) : tag_(tag), xmlns_(xmlns), parsers_(parsers) {} - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); - } - - virtual PayloadParser* createPayloadParser() { - return new PARSER_TYPE(parsers_); - } - - private: - std::string tag_; - std::string xmlns_; - PayloadParserFactoryCollection* parsers_; - }; + class PayloadParserFactoryCollection; + + /** + * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). + */ + template<typename PARSER_TYPE> + class GenericPayloadParserFactory2 : public PayloadParserFactory { + public: + /** + * Construct a parser factory that can parse the given top-level tag in the given namespace. + */ + GenericPayloadParserFactory2(const std::string& tag, const std::string& xmlns, PayloadParserFactoryCollection* parsers) : tag_(tag), xmlns_(xmlns), parsers_(parsers) {} + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); + } + + virtual PayloadParser* createPayloadParser() { + return new PARSER_TYPE(parsers_); + } + + private: + std::string tag_; + std::string xmlns_; + PayloadParserFactoryCollection* parsers_; + }; } diff --git a/Swiften/Parser/GenericPayloadTreeParser.h b/Swiften/Parser/GenericPayloadTreeParser.h index 37505ac..2a7e190 100644 --- a/Swiften/Parser/GenericPayloadTreeParser.h +++ b/Swiften/Parser/GenericPayloadTreeParser.h @@ -16,39 +16,39 @@ #include <Swiften/Parser/Tree/ParserElement.h> namespace Swift { - /** - * Generic parser offering something a bit like a DOM to work with. - */ - template<typename PAYLOAD_TYPE> - class GenericPayloadTreeParser : public GenericPayloadParser<PAYLOAD_TYPE> { - public: - virtual void handleStartElement(const std::string& element, const std::string& xmlns, const AttributeMap& attributes) { - if (!root_) { - root_ = boost::make_shared<ParserElement>(element, xmlns, attributes); - elementStack_.push_back(root_); - } - else { - ParserElement::ref current = *elementStack_.rbegin(); - elementStack_.push_back(current->addChild(element, xmlns, attributes)); - } - } - - virtual void handleEndElement(const std::string& /*element*/, const std::string&) { - elementStack_.pop_back(); - if (elementStack_.empty()) { - handleTree(root_); - } - } - - virtual void handleCharacterData(const std::string& data) { - ParserElement::ref current = *elementStack_.rbegin(); - current->appendCharacterData(data); - } - - virtual void handleTree(ParserElement::ref root) = 0; - - private: - std::deque<ParserElement::ref> elementStack_; - ParserElement::ref root_; - }; + /** + * Generic parser offering something a bit like a DOM to work with. + */ + template<typename PAYLOAD_TYPE> + class GenericPayloadTreeParser : public GenericPayloadParser<PAYLOAD_TYPE> { + public: + virtual void handleStartElement(const std::string& element, const std::string& xmlns, const AttributeMap& attributes) { + if (!root_) { + root_ = boost::make_shared<ParserElement>(element, xmlns, attributes); + elementStack_.push_back(root_); + } + else { + ParserElement::ref current = *elementStack_.rbegin(); + elementStack_.push_back(current->addChild(element, xmlns, attributes)); + } + } + + virtual void handleEndElement(const std::string& /*element*/, const std::string&) { + elementStack_.pop_back(); + if (elementStack_.empty()) { + handleTree(root_); + } + } + + virtual void handleCharacterData(const std::string& data) { + ParserElement::ref current = *elementStack_.rbegin(); + current->appendCharacterData(data); + } + + virtual void handleTree(ParserElement::ref root) = 0; + + private: + std::deque<ParserElement::ref> elementStack_; + ParserElement::ref root_; + }; } diff --git a/Swiften/Parser/GenericStanzaParser.h b/Swiften/Parser/GenericStanzaParser.h index c9d7f70..7d16a0c 100644 --- a/Swiften/Parser/GenericStanzaParser.h +++ b/Swiften/Parser/GenericStanzaParser.h @@ -13,26 +13,26 @@ #include <Swiften/Parser/StanzaParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - template<typename STANZA_TYPE> - class SWIFTEN_API GenericStanzaParser : public StanzaParser { - public: - GenericStanzaParser(PayloadParserFactoryCollection* collection) : - StanzaParser(collection) { - stanza_ = boost::make_shared<STANZA_TYPE>(); - } - - virtual boost::shared_ptr<ToplevelElement> getElement() const { - return stanza_; - } - - virtual boost::shared_ptr<STANZA_TYPE> getStanzaGeneric() const { - return stanza_; - } - - private: - boost::shared_ptr<STANZA_TYPE> stanza_; - }; + + class PayloadParserFactoryCollection; + + template<typename STANZA_TYPE> + class SWIFTEN_API GenericStanzaParser : public StanzaParser { + public: + GenericStanzaParser(PayloadParserFactoryCollection* collection) : + StanzaParser(collection) { + stanza_ = boost::make_shared<STANZA_TYPE>(); + } + + virtual boost::shared_ptr<ToplevelElement> getElement() const { + return stanza_; + } + + virtual boost::shared_ptr<STANZA_TYPE> getStanzaGeneric() const { + return stanza_; + } + + private: + boost::shared_ptr<STANZA_TYPE> stanza_; + }; } diff --git a/Swiften/Parser/IQParser.cpp b/Swiften/Parser/IQParser.cpp index ee8f2ff..573ce07 100644 --- a/Swiften/Parser/IQParser.cpp +++ b/Swiften/Parser/IQParser.cpp @@ -12,30 +12,30 @@ namespace Swift { -IQParser::IQParser(PayloadParserFactoryCollection* factories) : - GenericStanzaParser<IQ>(factories) { +IQParser::IQParser(PayloadParserFactoryCollection* factories) : + GenericStanzaParser<IQ>(factories) { } void IQParser::handleStanzaAttributes(const AttributeMap& attributes) { - boost::optional<std::string> type = attributes.getAttributeValue("type"); - if (type) { - if (*type == "set") { - getStanzaGeneric()->setType(IQ::Set); - } - else if (*type == "get") { - getStanzaGeneric()->setType(IQ::Get); - } - else if (*type == "result") { - getStanzaGeneric()->setType(IQ::Result); - } - else if (*type == "error") { - getStanzaGeneric()->setType(IQ::Error); - } - else { - std::cerr << "Unknown IQ type: " << *type << std::endl; - getStanzaGeneric()->setType(IQ::Get); - } - } + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "set") { + getStanzaGeneric()->setType(IQ::Set); + } + else if (*type == "get") { + getStanzaGeneric()->setType(IQ::Get); + } + else if (*type == "result") { + getStanzaGeneric()->setType(IQ::Result); + } + else if (*type == "error") { + getStanzaGeneric()->setType(IQ::Error); + } + else { + std::cerr << "Unknown IQ type: " << *type << std::endl; + getStanzaGeneric()->setType(IQ::Get); + } + } } } diff --git a/Swiften/Parser/IQParser.h b/Swiften/Parser/IQParser.h index fa1f66e..5250bfb 100644 --- a/Swiften/Parser/IQParser.h +++ b/Swiften/Parser/IQParser.h @@ -11,11 +11,11 @@ #include <Swiften/Parser/GenericStanzaParser.h> namespace Swift { - class SWIFTEN_API IQParser : public GenericStanzaParser<IQ> { - public: - IQParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API IQParser : public GenericStanzaParser<IQ> { + public: + IQParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStanzaAttributes(const AttributeMap&); - }; + private: + virtual void handleStanzaAttributes(const AttributeMap&); + }; } diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index db14174..62484fa 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -20,45 +20,45 @@ namespace Swift { struct LibXMLParser::Private { - xmlSAXHandler handler_; - xmlParserCtxtPtr context_; + xmlSAXHandler handler_; + xmlParserCtxtPtr context_; }; static void handleStartElement(void* parser, const xmlChar* name, const xmlChar*, const xmlChar* xmlns, int, const xmlChar**, int nbAttributes, int nbDefaulted, const xmlChar ** attributes) { - AttributeMap attributeValues; - if (nbDefaulted != 0) { - // Just because i don't understand what this means yet :-) - std::cerr << "Unexpected nbDefaulted on XML element" << std::endl; - } - for (int i = 0; i < nbAttributes*5; i += 5) { - std::string attributeNS = ""; - if (attributes[i+2]) { - attributeNS = std::string(reinterpret_cast<const char*>(attributes[i+2])); - } - attributeValues.addAttribute( - std::string(reinterpret_cast<const char*>(attributes[i])), - attributeNS, - std::string(reinterpret_cast<const char*>(attributes[i+3]), - boost::numeric_cast<size_t>(attributes[i+4]-attributes[i+3]))); - } - static_cast<XMLParser*>(parser)->getClient()->handleStartElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string()), attributeValues); + AttributeMap attributeValues; + if (nbDefaulted != 0) { + // Just because i don't understand what this means yet :-) + std::cerr << "Unexpected nbDefaulted on XML element" << std::endl; + } + for (int i = 0; i < nbAttributes*5; i += 5) { + std::string attributeNS = ""; + if (attributes[i+2]) { + attributeNS = std::string(reinterpret_cast<const char*>(attributes[i+2])); + } + attributeValues.addAttribute( + std::string(reinterpret_cast<const char*>(attributes[i])), + attributeNS, + std::string(reinterpret_cast<const char*>(attributes[i+3]), + boost::numeric_cast<size_t>(attributes[i+4]-attributes[i+3]))); + } + static_cast<XMLParser*>(parser)->getClient()->handleStartElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string()), attributeValues); } static void handleEndElement(void *parser, const xmlChar* name, const xmlChar*, const xmlChar* xmlns) { - static_cast<XMLParser*>(parser)->getClient()->handleEndElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string())); + static_cast<XMLParser*>(parser)->getClient()->handleEndElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string())); } static void handleCharacterData(void* parser, const xmlChar* data, int len) { - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), boost::numeric_cast<size_t>(len))); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), boost::numeric_cast<size_t>(len))); } static void handleError(void*, const char* /*m*/, ... ) { - /* - va_list args; - va_start(args, m); - vfprintf(stdout, m, args); - va_end(args); - */ + /* + va_list args; + va_start(args, m); + vfprintf(stdout, m, args); + va_end(args); + */ } static void handleWarning(void*, const char*, ... ) { @@ -67,42 +67,42 @@ static void handleWarning(void*, const char*, ... ) { bool LibXMLParser::initialized = false; LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client), p(new Private()) { - // Initialize libXML for multithreaded applications - if (!initialized) { - xmlInitParser(); - initialized = true; - } - - memset(&p->handler_, 0, sizeof(p->handler_) ); - p->handler_.initialized = XML_SAX2_MAGIC; - p->handler_.startElementNs = &handleStartElement; - p->handler_.endElementNs = &handleEndElement; - p->handler_.characters = &handleCharacterData; - p->handler_.warning = &handleWarning; - p->handler_.error = &handleError; - - p->context_ = xmlCreatePushParserCtxt(&p->handler_, this, 0, 0, 0); - xmlCtxtUseOptions(p->context_, XML_PARSE_NOENT); - assert(p->context_); + // Initialize libXML for multithreaded applications + if (!initialized) { + xmlInitParser(); + initialized = true; + } + + memset(&p->handler_, 0, sizeof(p->handler_) ); + p->handler_.initialized = XML_SAX2_MAGIC; + p->handler_.startElementNs = &handleStartElement; + p->handler_.endElementNs = &handleEndElement; + p->handler_.characters = &handleCharacterData; + p->handler_.warning = &handleWarning; + p->handler_.error = &handleError; + + p->context_ = xmlCreatePushParserCtxt(&p->handler_, this, 0, 0, 0); + xmlCtxtUseOptions(p->context_, XML_PARSE_NOENT); + assert(p->context_); } LibXMLParser::~LibXMLParser() { - if (p->context_) { - xmlFreeParserCtxt(p->context_); - } + if (p->context_) { + xmlFreeParserCtxt(p->context_); + } } bool LibXMLParser::parse(const std::string& data) { - if (xmlParseChunk(p->context_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_ERR_OK) { - return true; - } - xmlError* error = xmlCtxtGetLastError(p->context_); - if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) { - xmlCtxtResetLastError(p->context_); - p->context_->errNo = XML_ERR_OK; - return true; - } - return false; + if (xmlParseChunk(p->context_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_ERR_OK) { + return true; + } + xmlError* error = xmlCtxtGetLastError(p->context_); + if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) { + xmlCtxtResetLastError(p->context_); + p->context_->errNo = XML_ERR_OK; + return true; + } + return false; } } diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h index c247548..eb2a038 100644 --- a/Swiften/Parser/LibXMLParser.h +++ b/Swiften/Parser/LibXMLParser.h @@ -12,21 +12,21 @@ #include <Swiften/Parser/XMLParser.h> namespace Swift { - /** - * Warning: This constructor is not thread-safe, because it depends on global state to - * check whether it is initialized. - */ - class LibXMLParser : public XMLParser, public boost::noncopyable { - public: - LibXMLParser(XMLParserClient* client); - virtual ~LibXMLParser(); + /** + * Warning: This constructor is not thread-safe, because it depends on global state to + * check whether it is initialized. + */ + class LibXMLParser : public XMLParser, public boost::noncopyable { + public: + LibXMLParser(XMLParserClient* client); + virtual ~LibXMLParser(); - bool parse(const std::string& data); + bool parse(const std::string& data); - private: - static bool initialized; + private: + static bool initialized; - struct Private; - boost::shared_ptr<Private> p; - }; + struct Private; + boost::shared_ptr<Private> p; + }; } diff --git a/Swiften/Parser/MessageParser.cpp b/Swiften/Parser/MessageParser.cpp index 5de0038..1dd7675 100644 --- a/Swiften/Parser/MessageParser.cpp +++ b/Swiften/Parser/MessageParser.cpp @@ -10,30 +10,30 @@ namespace Swift { -MessageParser::MessageParser(PayloadParserFactoryCollection* factories) : - GenericStanzaParser<Message>(factories) { - GenericStanzaParser<Message>::getStanzaGeneric()->setType(Message::Normal); +MessageParser::MessageParser(PayloadParserFactoryCollection* factories) : + GenericStanzaParser<Message>(factories) { + GenericStanzaParser<Message>::getStanzaGeneric()->setType(Message::Normal); } void MessageParser::handleStanzaAttributes(const AttributeMap& attributes) { - boost::optional<std::string> type = attributes.getAttributeValue("type"); - if (type) { - if (*type == "chat") { - getStanzaGeneric()->setType(Message::Chat); - } - else if (*type == "error") { - getStanzaGeneric()->setType(Message::Error); - } - else if (*type == "groupchat") { - getStanzaGeneric()->setType(Message::Groupchat); - } - else if (*type == "headline") { - getStanzaGeneric()->setType(Message::Headline); - } - else { - getStanzaGeneric()->setType(Message::Normal); - } - } + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "chat") { + getStanzaGeneric()->setType(Message::Chat); + } + else if (*type == "error") { + getStanzaGeneric()->setType(Message::Error); + } + else if (*type == "groupchat") { + getStanzaGeneric()->setType(Message::Groupchat); + } + else if (*type == "headline") { + getStanzaGeneric()->setType(Message::Headline); + } + else { + getStanzaGeneric()->setType(Message::Normal); + } + } } } diff --git a/Swiften/Parser/MessageParser.h b/Swiften/Parser/MessageParser.h index 05e8b20..cfbfc38 100644 --- a/Swiften/Parser/MessageParser.h +++ b/Swiften/Parser/MessageParser.h @@ -11,11 +11,11 @@ #include <Swiften/Parser/GenericStanzaParser.h> namespace Swift { - class SWIFTEN_API MessageParser : public GenericStanzaParser<Message> { - public: - MessageParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API MessageParser : public GenericStanzaParser<Message> { + public: + MessageParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStanzaAttributes(const AttributeMap&); - }; + private: + virtual void handleStanzaAttributes(const AttributeMap&); + }; } diff --git a/Swiften/Parser/PayloadParser.h b/Swiften/Parser/PayloadParser.h index 815d246..cb50061 100644 --- a/Swiften/Parser/PayloadParser.h +++ b/Swiften/Parser/PayloadParser.h @@ -13,38 +13,38 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - - - /** - * A parser for XMPP stanza payloads. - * - * The parser is event driven: handleStartElement, handleEndElement, and handleCharacterData will be called - * when the parser detects start and end of XML elements, or character data. - * After the data for the given top-level element is processed, getPayload() will be called to retrieve the - * payload. - */ - class SWIFTEN_API PayloadParser { - public: - virtual ~PayloadParser(); - - /** - * Handle the start of an XML element. - */ - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; - - /** - * Handle the end of an XML element. - */ - virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; - - /** - * Handle character data. - */ - virtual void handleCharacterData(const std::string& data) = 0; - - /** - * Retrieve a pointer to the payload. - */ - virtual boost::shared_ptr<Payload> getPayload() const = 0; - }; + + + /** + * A parser for XMPP stanza payloads. + * + * The parser is event driven: handleStartElement, handleEndElement, and handleCharacterData will be called + * when the parser detects start and end of XML elements, or character data. + * After the data for the given top-level element is processed, getPayload() will be called to retrieve the + * payload. + */ + class SWIFTEN_API PayloadParser { + public: + virtual ~PayloadParser(); + + /** + * Handle the start of an XML element. + */ + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; + + /** + * Handle the end of an XML element. + */ + virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; + + /** + * Handle character data. + */ + virtual void handleCharacterData(const std::string& data) = 0; + + /** + * Retrieve a pointer to the payload. + */ + virtual boost::shared_ptr<Payload> getPayload() const = 0; + }; } diff --git a/Swiften/Parser/PayloadParserFactory.h b/Swiften/Parser/PayloadParserFactory.h index a73d50d..84f11ff 100644 --- a/Swiften/Parser/PayloadParserFactory.h +++ b/Swiften/Parser/PayloadParserFactory.h @@ -10,24 +10,24 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - - class PayloadParser; - /** - * A factory for PayloadParsers. - */ - class SWIFTEN_API PayloadParserFactory { - public: - virtual ~PayloadParserFactory(); + class PayloadParser; - /** - * Checks whether this factory can parse the given top-level element in the given namespace (with the given attributes). - */ - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap& attributes) const = 0; + /** + * A factory for PayloadParsers. + */ + class SWIFTEN_API PayloadParserFactory { + public: + virtual ~PayloadParserFactory(); - /** - * Creates a new payload parser. - */ - virtual PayloadParser* createPayloadParser() = 0; - }; + /** + * Checks whether this factory can parse the given top-level element in the given namespace (with the given attributes). + */ + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap& attributes) const = 0; + + /** + * Creates a new payload parser. + */ + virtual PayloadParser* createPayloadParser() = 0; + }; } diff --git a/Swiften/Parser/PayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParserFactoryCollection.cpp index 6b86305..f1c1c03 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParserFactoryCollection.cpp @@ -18,22 +18,22 @@ PayloadParserFactoryCollection::PayloadParserFactoryCollection() : defaultFactor } void PayloadParserFactoryCollection::addFactory(PayloadParserFactory* factory) { - factories_.push_back(factory); + factories_.push_back(factory); } void PayloadParserFactoryCollection::removeFactory(PayloadParserFactory* factory) { - factories_.erase(std::remove(factories_.begin(), factories_.end(), factory), factories_.end()); + factories_.erase(std::remove(factories_.begin(), factories_.end(), factory), factories_.end()); } void PayloadParserFactoryCollection::setDefaultFactory(PayloadParserFactory* factory) { - defaultFactory_ = factory; + defaultFactory_ = factory; } PayloadParserFactory* PayloadParserFactoryCollection::getPayloadParserFactory(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - std::vector<PayloadParserFactory*>::reverse_iterator i = std::find_if( - factories_.rbegin(), factories_.rend(), - boost::bind(&PayloadParserFactory::canParse, _1, element, ns, attributes)); - return (i != factories_.rend() ? *i : defaultFactory_); + std::vector<PayloadParserFactory*>::reverse_iterator i = std::find_if( + factories_.rbegin(), factories_.rend(), + boost::bind(&PayloadParserFactory::canParse, _1, element, ns, attributes)); + return (i != factories_.rend() ? *i : defaultFactory_); } } diff --git a/Swiften/Parser/PayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParserFactoryCollection.h index 757b4e7..06e334e 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParserFactoryCollection.h @@ -12,20 +12,20 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class PayloadParserFactory; + class PayloadParserFactory; - class SWIFTEN_API PayloadParserFactoryCollection { - public: - PayloadParserFactoryCollection(); + class SWIFTEN_API PayloadParserFactoryCollection { + public: + PayloadParserFactoryCollection(); - void addFactory(PayloadParserFactory* factory); - void removeFactory(PayloadParserFactory* factory); - void setDefaultFactory(PayloadParserFactory* factory); + void addFactory(PayloadParserFactory* factory); + void removeFactory(PayloadParserFactory* factory); + void setDefaultFactory(PayloadParserFactory* factory); - PayloadParserFactory* getPayloadParserFactory(const std::string& element, const std::string& ns, const AttributeMap& attributes); + PayloadParserFactory* getPayloadParserFactory(const std::string& element, const std::string& ns, const AttributeMap& attributes); - private: - std::vector<PayloadParserFactory*> factories_; - PayloadParserFactory* defaultFactory_; - }; + private: + std::vector<PayloadParserFactory*> factories_; + PayloadParserFactory* defaultFactory_; + }; } diff --git a/Swiften/Parser/PayloadParsers/BlockParser.h b/Swiften/Parser/PayloadParsers/BlockParser.h index 2e615a5..1724feb 100644 --- a/Swiften/Parser/PayloadParsers/BlockParser.h +++ b/Swiften/Parser/PayloadParsers/BlockParser.h @@ -12,30 +12,30 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - template<typename BLOCK_ELEMENT> - class SWIFTEN_API BlockParser : public GenericPayloadParser<BLOCK_ELEMENT> { - public: - BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>(), level(0) { - } + template<typename BLOCK_ELEMENT> + class SWIFTEN_API BlockParser : public GenericPayloadParser<BLOCK_ELEMENT> { + public: + BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>(), level(0) { + } - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 1 && element == "item") { - JID jid(attributes.getAttribute("jid")); - if (jid.isValid()) { - GenericPayloadParser<BLOCK_ELEMENT>::getPayloadInternal()->addItem(jid); - } - } - ++level; - } + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 1 && element == "item") { + JID jid(attributes.getAttribute("jid")); + if (jid.isValid()) { + GenericPayloadParser<BLOCK_ELEMENT>::getPayloadInternal()->addItem(jid); + } + } + ++level; + } - virtual void handleEndElement(const std::string&, const std::string&) { - --level; - } + virtual void handleEndElement(const std::string&, const std::string&) { + --level; + } - virtual void handleCharacterData(const std::string&) { - } + virtual void handleCharacterData(const std::string&) { + } - private: - int level; - }; + private: + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/BodyParser.cpp b/Swiften/Parser/PayloadParsers/BodyParser.cpp index 96a7b18..5741c90 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.cpp +++ b/Swiften/Parser/PayloadParsers/BodyParser.cpp @@ -12,18 +12,18 @@ BodyParser::BodyParser() : level_(0) { } void BodyParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void BodyParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void BodyParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/BodyParser.h b/Swiften/Parser/PayloadParsers/BodyParser.h index 6b6a206..bcf762b 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.h +++ b/Swiften/Parser/PayloadParsers/BodyParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API BodyParser : public GenericPayloadParser<Body> { - public: - BodyParser(); + class SWIFTEN_API BodyParser : public GenericPayloadParser<Body> { + public: + BodyParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp index 35ee1fd..8a0ecd2 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp @@ -19,26 +19,26 @@ BytestreamsParser::~BytestreamsParser() { } void BytestreamsParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); - } - else if (level == PayloadLevel) { - if (element == "streamhost") { - try { - getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::lexical_cast<int>(attributes.getAttribute("port")))); - } - catch (boost::bad_lexical_cast&) { - } - } - else if (element == "streamhost-used") { - getPayloadInternal()->setUsedStreamHost(JID(attributes.getAttribute("jid"))); - } - } - ++level; + if (level == TopLevel) { + getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); + } + else if (level == PayloadLevel) { + if (element == "streamhost") { + try { + getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::lexical_cast<int>(attributes.getAttribute("port")))); + } + catch (boost::bad_lexical_cast&) { + } + } + else if (element == "streamhost-used") { + getPayloadInternal()->setUsedStreamHost(JID(attributes.getAttribute("jid"))); + } + } + ++level; } void BytestreamsParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } void BytestreamsParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.h b/Swiften/Parser/PayloadParsers/BytestreamsParser.h index 4180ff9..01cb60f 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.h +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.h @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API BytestreamsParser : public GenericPayloadParser<Bytestreams> { - public: - BytestreamsParser(); - ~BytestreamsParser(); + class SWIFTEN_API BytestreamsParser : public GenericPayloadParser<Bytestreams> { + public: + BytestreamsParser(); + ~BytestreamsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp index 7843c78..546df57 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp @@ -14,16 +14,16 @@ CapsInfoParser::CapsInfoParser() : level(0) { } void CapsInfoParser::handleStartElement(const std::string&, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level == 0) { - getPayloadInternal()->setHash(attributes.getAttribute("hash")); - getPayloadInternal()->setNode(attributes.getAttribute("node")); - getPayloadInternal()->setVersion(attributes.getAttribute("ver")); - } - ++level; + if (level == 0) { + getPayloadInternal()->setHash(attributes.getAttribute("hash")); + getPayloadInternal()->setNode(attributes.getAttribute("node")); + getPayloadInternal()->setVersion(attributes.getAttribute("ver")); + } + ++level; } void CapsInfoParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } void CapsInfoParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/CapsInfoParser.h b/Swiften/Parser/PayloadParsers/CapsInfoParser.h index 6e4610a..9556a4d 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.h +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CapsInfoParser : public GenericPayloadParser<CapsInfo> { - public: - CapsInfoParser(); + class SWIFTEN_API CapsInfoParser : public GenericPayloadParser<CapsInfo> { + public: + CapsInfoParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level; - }; + private: + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp index 7e26f3b..b8bd4b5 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp @@ -8,19 +8,19 @@ namespace Swift { - CarbonsDisableParser::CarbonsDisableParser() : GenericPayloadParser<CarbonsDisable>() { - } + CarbonsDisableParser::CarbonsDisableParser() : GenericPayloadParser<CarbonsDisable>() { + } - CarbonsDisableParser::~CarbonsDisableParser() { - } + CarbonsDisableParser::~CarbonsDisableParser() { + } - void CarbonsDisableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + void CarbonsDisableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - void CarbonsDisableParser::handleEndElement(const std::string&, const std::string&) { - } + void CarbonsDisableParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsDisableParser::handleCharacterData(const std::string&) { + } - void CarbonsDisableParser::handleCharacterData(const std::string&) { - } - } diff --git a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h index 56f6787..7a5f4a4 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h @@ -11,13 +11,13 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CarbonsDisableParser : public GenericPayloadParser<CarbonsDisable> { - public: - CarbonsDisableParser(); - virtual ~CarbonsDisableParser(); + class SWIFTEN_API CarbonsDisableParser : public GenericPayloadParser<CarbonsDisable> { + public: + CarbonsDisableParser(); + virtual ~CarbonsDisableParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string&); - }; + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string&); + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp index 52bf6d7..700f939 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp @@ -8,19 +8,19 @@ namespace Swift { - CarbonsEnableParser::CarbonsEnableParser() : GenericPayloadParser<CarbonsEnable>() { - } + CarbonsEnableParser::CarbonsEnableParser() : GenericPayloadParser<CarbonsEnable>() { + } - CarbonsEnableParser::~CarbonsEnableParser() { - } + CarbonsEnableParser::~CarbonsEnableParser() { + } - void CarbonsEnableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + void CarbonsEnableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - void CarbonsEnableParser::handleEndElement(const std::string&, const std::string&) { - } + void CarbonsEnableParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsEnableParser::handleCharacterData(const std::string&) { + } - void CarbonsEnableParser::handleCharacterData(const std::string&) { - } - } diff --git a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h index d0e5771..0488f97 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h @@ -11,12 +11,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CarbonsEnableParser : public GenericPayloadParser<CarbonsEnable> { - public: - CarbonsEnableParser(); - virtual ~CarbonsEnableParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string&); - }; + class SWIFTEN_API CarbonsEnableParser : public GenericPayloadParser<CarbonsEnable> { + public: + CarbonsEnableParser(); + virtual ~CarbonsEnableParser(); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string&); + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp index 888edf1..b2038db 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp @@ -8,19 +8,19 @@ namespace Swift { - CarbonsPrivateParser::CarbonsPrivateParser() : GenericPayloadParser<CarbonsPrivate>() { - } + CarbonsPrivateParser::CarbonsPrivateParser() : GenericPayloadParser<CarbonsPrivate>() { + } - CarbonsPrivateParser::~CarbonsPrivateParser() { - } + CarbonsPrivateParser::~CarbonsPrivateParser() { + } - void CarbonsPrivateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + void CarbonsPrivateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - void CarbonsPrivateParser::handleEndElement(const std::string&, const std::string&) { - } + void CarbonsPrivateParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsPrivateParser::handleCharacterData(const std::string&) { + } - void CarbonsPrivateParser::handleCharacterData(const std::string&) { - } - } diff --git a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h index 2797808..2ae3bae 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h @@ -11,12 +11,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CarbonsPrivateParser : public GenericPayloadParser<CarbonsPrivate> { - public: - CarbonsPrivateParser(); - virtual ~CarbonsPrivateParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string&); - }; + class SWIFTEN_API CarbonsPrivateParser : public GenericPayloadParser<CarbonsPrivate> { + public: + CarbonsPrivateParser(); + virtual ~CarbonsPrivateParser(); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string&); + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp index 267c541..d6fb6be 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp @@ -7,39 +7,39 @@ #include <Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h> namespace Swift { - CarbonsReceivedParser::CarbonsReceivedParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsReceived>(), factories_(factories), level_(TopLevel) { - } + CarbonsReceivedParser::CarbonsReceivedParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsReceived>(), factories_(factories), level_(TopLevel) { + } - CarbonsReceivedParser::~CarbonsReceivedParser() { - } + CarbonsReceivedParser::~CarbonsReceivedParser() { + } - void CarbonsReceivedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "forwarded") { - forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_)); - } - } - if (forwardedParser_) { - forwardedParser_->handleStartElement(element, ns, attributes); - } - ++level_; - } + void CarbonsReceivedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "forwarded") { + forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_)); + } + } + if (forwardedParser_) { + forwardedParser_->handleStartElement(element, ns, attributes); + } + ++level_; + } - void CarbonsReceivedParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (forwardedParser_ && level_ >= PayloadLevel) { - forwardedParser_->handleEndElement(element, ns); - } - if (forwardedParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); - forwardedParser_.reset(); - } - } + void CarbonsReceivedParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (forwardedParser_ && level_ >= PayloadLevel) { + forwardedParser_->handleEndElement(element, ns); + } + if (forwardedParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); + forwardedParser_.reset(); + } + } - void CarbonsReceivedParser::handleCharacterData(const std::string& data) { - if (forwardedParser_) { - forwardedParser_->handleCharacterData(data); - } - } + void CarbonsReceivedParser::handleCharacterData(const std::string& data) { + if (forwardedParser_) { + forwardedParser_->handleCharacterData(data); + } + } } diff --git a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h index 6aa6326..666f20b 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h @@ -12,24 +12,24 @@ #include <Swiften/Parser/PayloadParsers/ForwardedParser.h> namespace Swift { - class SWIFTEN_API CarbonsReceivedParser : public GenericPayloadParser<CarbonsReceived> { - public: - CarbonsReceivedParser(PayloadParserFactoryCollection* factories); - virtual ~CarbonsReceivedParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string&); + class SWIFTEN_API CarbonsReceivedParser : public GenericPayloadParser<CarbonsReceived> { + public: + CarbonsReceivedParser(PayloadParserFactoryCollection* factories); + virtual ~CarbonsReceivedParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string&); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<ForwardedParser> forwardedParser_; - int level_; - }; + private: + PayloadParserFactoryCollection* factories_; + boost::shared_ptr<ForwardedParser> forwardedParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp index b430249..e616211 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp @@ -7,39 +7,39 @@ #include <Swiften/Parser/PayloadParsers/CarbonsSentParser.h> namespace Swift { - CarbonsSentParser::CarbonsSentParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsSent>(), factories_(factories), level_(TopLevel) { - } + CarbonsSentParser::CarbonsSentParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsSent>(), factories_(factories), level_(TopLevel) { + } - CarbonsSentParser::~CarbonsSentParser() { - } + CarbonsSentParser::~CarbonsSentParser() { + } - void CarbonsSentParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "forwarded") { - forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_)); - } - } - if (forwardedParser_) { - forwardedParser_->handleStartElement(element, ns, attributes); - } - ++level_; - } + void CarbonsSentParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "forwarded") { + forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_)); + } + } + if (forwardedParser_) { + forwardedParser_->handleStartElement(element, ns, attributes); + } + ++level_; + } - void CarbonsSentParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (forwardedParser_ && level_ >= PayloadLevel) { - forwardedParser_->handleEndElement(element, ns); - } - if (forwardedParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); - forwardedParser_.reset(); - } - } + void CarbonsSentParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (forwardedParser_ && level_ >= PayloadLevel) { + forwardedParser_->handleEndElement(element, ns); + } + if (forwardedParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); + forwardedParser_.reset(); + } + } - void CarbonsSentParser::handleCharacterData(const std::string& data) { - if (forwardedParser_) { - forwardedParser_->handleCharacterData(data); - } - } + void CarbonsSentParser::handleCharacterData(const std::string& data) { + if (forwardedParser_) { + forwardedParser_->handleCharacterData(data); + } + } } diff --git a/Swiften/Parser/PayloadParsers/CarbonsSentParser.h b/Swiften/Parser/PayloadParsers/CarbonsSentParser.h index 91c3292..9faf62d 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsSentParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsSentParser.h @@ -12,24 +12,24 @@ #include <Swiften/Parser/PayloadParsers/ForwardedParser.h> namespace Swift { - class SWIFTEN_API CarbonsSentParser : public GenericPayloadParser<CarbonsSent> { - public: - CarbonsSentParser(PayloadParserFactoryCollection* factories); - virtual ~CarbonsSentParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string&); + class SWIFTEN_API CarbonsSentParser : public GenericPayloadParser<CarbonsSent> { + public: + CarbonsSentParser(PayloadParserFactoryCollection* factories); + virtual ~CarbonsSentParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string&); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<ForwardedParser> forwardedParser_; - int level_; - }; + private: + PayloadParserFactoryCollection* factories_; + boost::shared_ptr<ForwardedParser> forwardedParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp index bd5ecbe..75ec699 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp @@ -12,26 +12,26 @@ ChatStateParser::ChatStateParser() : level_(0) { } void ChatStateParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (level_ == 0) { - ChatState::ChatStateType state = ChatState::Active; - if (element == "active") { - state = ChatState::Active; - } else if (element == "composing") { - state = ChatState::Composing; - } else if (element == "inactive") { - state = ChatState::Inactive; - } else if (element == "paused") { - state = ChatState::Paused; - } else if (element == "gone") { - state = ChatState::Gone; - } - getPayloadInternal()->setChatState(state); - } - ++level_; + if (level_ == 0) { + ChatState::ChatStateType state = ChatState::Active; + if (element == "active") { + state = ChatState::Active; + } else if (element == "composing") { + state = ChatState::Composing; + } else if (element == "inactive") { + state = ChatState::Inactive; + } else if (element == "paused") { + state = ChatState::Paused; + } else if (element == "gone") { + state = ChatState::Gone; + } + getPayloadInternal()->setChatState(state); + } + ++level_; } void ChatStateParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void ChatStateParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.h b/Swiften/Parser/PayloadParsers/ChatStateParser.h index e18e17b..b932a5c 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ChatStateParser : public GenericPayloadParser<ChatState> { - public: - ChatStateParser(); + class SWIFTEN_API ChatStateParser : public GenericPayloadParser<ChatState> { + public: + ChatStateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h index ac1c14d..cf226cc 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h @@ -11,22 +11,22 @@ #include <Swiften/Parser/PayloadParsers/ChatStateParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API ChatStateParserFactory : public PayloadParserFactory { - public: - ChatStateParserFactory() { - } + class SWIFTEN_API ChatStateParserFactory : public PayloadParserFactory { + public: + ChatStateParserFactory() { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return ns == "http://jabber.org/protocol/chatstates" && - (element == "active" || element == "composing" - || element == "paused" || element == "inactive" || element == "gone"); - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "http://jabber.org/protocol/chatstates" && + (element == "active" || element == "composing" + || element == "paused" || element == "inactive" || element == "gone"); + } - virtual PayloadParser* createPayloadParser() { - return new ChatStateParser(); - } + virtual PayloadParser* createPayloadParser() { + return new ChatStateParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/CommandParser.cpp b/Swiften/Parser/PayloadParsers/CommandParser.cpp index 91384db..1d2ddea 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.cpp +++ b/Swiften/Parser/PayloadParsers/CommandParser.cpp @@ -14,130 +14,130 @@ namespace Swift { CommandParser::CommandParser() : level_(TopLevel), inNote_(false), inActions_(false), noteType_(Command::Note::Info), formParser_(0) { - formParserFactory_ = new FormParserFactory(); + formParserFactory_ = new FormParserFactory(); } CommandParser::~CommandParser() { - delete formParserFactory_; + delete formParserFactory_; } void CommandParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - if (level_ == PayloadLevel) { - boost::optional<Command::Action> action = parseAction(attributes.getAttribute("action")); - if (action) { - getPayloadInternal()->setAction(*action); - } + ++level_; + if (level_ == PayloadLevel) { + boost::optional<Command::Action> action = parseAction(attributes.getAttribute("action")); + if (action) { + getPayloadInternal()->setAction(*action); + } - std::string status = attributes.getAttribute("status"); - if (status == "executing") { - getPayloadInternal()->setStatus(Command::Executing); - } - else if (status == "completed") { - getPayloadInternal()->setStatus(Command::Completed); - } - else if (status == "canceled") { - getPayloadInternal()->setStatus(Command::Canceled); - } + std::string status = attributes.getAttribute("status"); + if (status == "executing") { + getPayloadInternal()->setStatus(Command::Executing); + } + else if (status == "completed") { + getPayloadInternal()->setStatus(Command::Completed); + } + else if (status == "canceled") { + getPayloadInternal()->setStatus(Command::Canceled); + } - getPayloadInternal()->setNode(attributes.getAttribute("node")); - getPayloadInternal()->setSessionID(attributes.getAttribute("sessionid")); - } - else if (level_ == FormOrNoteOrActionsLevel) { - assert(!formParser_); - if (formParserFactory_->canParse(element, ns, attributes)) { - formParser_ = boost::polymorphic_downcast<FormParser*>(formParserFactory_->createPayloadParser()); - assert(formParser_); - } - else if (element == "note") { - inNote_ = true; - currentText_.clear(); - std::string noteType = attributes.getAttribute("type"); - if (noteType == "info") { - noteType_ = Command::Note::Info; - } - else if (noteType == "warn") { - noteType_ = Command::Note::Warn; - } - else if (noteType == "error") { - noteType_ = Command::Note::Error; - } - else { - noteType_ = Command::Note::Info; - } - } - else if (element == "actions") { - inActions_ = true; - boost::optional<Command::Action> action = parseAction(attributes.getAttribute("execute")); - if (action) { - getPayloadInternal()->setExecuteAction(*action); - } - } - } - else if (level_ == ActionsActionLevel) { - } + getPayloadInternal()->setNode(attributes.getAttribute("node")); + getPayloadInternal()->setSessionID(attributes.getAttribute("sessionid")); + } + else if (level_ == FormOrNoteOrActionsLevel) { + assert(!formParser_); + if (formParserFactory_->canParse(element, ns, attributes)) { + formParser_ = boost::polymorphic_downcast<FormParser*>(formParserFactory_->createPayloadParser()); + assert(formParser_); + } + else if (element == "note") { + inNote_ = true; + currentText_.clear(); + std::string noteType = attributes.getAttribute("type"); + if (noteType == "info") { + noteType_ = Command::Note::Info; + } + else if (noteType == "warn") { + noteType_ = Command::Note::Warn; + } + else if (noteType == "error") { + noteType_ = Command::Note::Error; + } + else { + noteType_ = Command::Note::Info; + } + } + else if (element == "actions") { + inActions_ = true; + boost::optional<Command::Action> action = parseAction(attributes.getAttribute("execute")); + if (action) { + getPayloadInternal()->setExecuteAction(*action); + } + } + } + else if (level_ == ActionsActionLevel) { + } - if (formParser_) { - formParser_->handleStartElement(element, ns, attributes); - } + if (formParser_) { + formParser_->handleStartElement(element, ns, attributes); + } } void CommandParser::handleEndElement(const std::string& element, const std::string& ns) { - if (formParser_) { - formParser_->handleEndElement(element, ns); - } + if (formParser_) { + formParser_->handleEndElement(element, ns); + } - if (level_ == FormOrNoteOrActionsLevel) { - if (formParser_) { - Form::ref form(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); - assert(form); - getPayloadInternal()->setForm(form); - delete formParser_; - formParser_ = 0; - } - else if (inNote_) { - inNote_ = false; - getPayloadInternal()->addNote(Command::Note(currentText_, noteType_)); - } - else if (inActions_) { - inActions_ = false; - } - } - else if (level_ == ActionsActionLevel && inActions_) { - boost::optional<Command::Action> action = parseAction(element); - if (action) { - getPayloadInternal()->addAvailableAction(*action); - } - } - --level_; + if (level_ == FormOrNoteOrActionsLevel) { + if (formParser_) { + Form::ref form(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); + assert(form); + getPayloadInternal()->setForm(form); + delete formParser_; + formParser_ = 0; + } + else if (inNote_) { + inNote_ = false; + getPayloadInternal()->addNote(Command::Note(currentText_, noteType_)); + } + else if (inActions_) { + inActions_ = false; + } + } + else if (level_ == ActionsActionLevel && inActions_) { + boost::optional<Command::Action> action = parseAction(element); + if (action) { + getPayloadInternal()->addAvailableAction(*action); + } + } + --level_; } void CommandParser::handleCharacterData(const std::string& data) { - if (formParser_) { - formParser_->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (formParser_) { + formParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } } boost::optional<Command::Action> CommandParser::parseAction(const std::string& action) { - if (action == "execute") { - return Command::Execute; - } - else if (action == "cancel") { - return Command::Cancel; - } - else if (action == "prev") { - return Command::Prev; - } - else if (action == "next") { - return Command::Next; - } - else if (action == "complete") { - return Command::Complete; - } - return boost::optional<Command::Action>(); + if (action == "execute") { + return Command::Execute; + } + else if (action == "cancel") { + return Command::Cancel; + } + else if (action == "prev") { + return Command::Prev; + } + else if (action == "next") { + return Command::Next; + } + else if (action == "complete") { + return Command::Complete; + } + return boost::optional<Command::Action>(); } } diff --git a/Swiften/Parser/PayloadParsers/CommandParser.h b/Swiften/Parser/PayloadParsers/CommandParser.h index 11badd4..105953a 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.h +++ b/Swiften/Parser/PayloadParsers/CommandParser.h @@ -13,34 +13,34 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; - - class SWIFTEN_API CommandParser : public GenericPayloadParser<Command> { - public: - CommandParser(); - ~CommandParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - static boost::optional<Command::Action> parseAction(const std::string& action); - - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - FormOrNoteOrActionsLevel = 2, - ActionsActionLevel = 3 - }; - int level_; - bool inNote_; - bool inActions_; - Command::Note::Type noteType_; - FormParserFactory* formParserFactory_; - FormParser* formParser_; - std::string currentText_; - }; + class FormParserFactory; + class FormParser; + + class SWIFTEN_API CommandParser : public GenericPayloadParser<Command> { + public: + CommandParser(); + ~CommandParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + static boost::optional<Command::Action> parseAction(const std::string& action); + + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + FormOrNoteOrActionsLevel = 2, + ActionsActionLevel = 3 + }; + int level_; + bool inNote_; + bool inActions_; + Command::Note::Type noteType_; + FormParserFactory* formParserFactory_; + FormParser* formParser_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DelayParser.cpp b/Swiften/Parser/PayloadParsers/DelayParser.cpp index b8e72d8..95371b7 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.cpp +++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp @@ -14,19 +14,19 @@ DelayParser::DelayParser() : level_(0) { } void DelayParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level_ == 0) { - boost::posix_time::ptime stamp = stringToDateTime(attributes.getAttribute("stamp")); - getPayloadInternal()->setStamp(stamp); - if (!attributes.getAttribute("from").empty()) { - std::string from = attributes.getAttribute("from"); - getPayloadInternal()->setFrom(JID(from)); - } - } - ++level_; + if (level_ == 0) { + boost::posix_time::ptime stamp = stringToDateTime(attributes.getAttribute("stamp")); + getPayloadInternal()->setStamp(stamp); + if (!attributes.getAttribute("from").empty()) { + std::string from = attributes.getAttribute("from"); + getPayloadInternal()->setFrom(JID(from)); + } + } + ++level_; } void DelayParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void DelayParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/DelayParser.h b/Swiften/Parser/PayloadParsers/DelayParser.h index d5fa58f..d9bf44b 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.h +++ b/Swiften/Parser/PayloadParsers/DelayParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DelayParser : public GenericPayloadParser<Delay> { - public: - DelayParser(); + class SWIFTEN_API DelayParser : public GenericPayloadParser<Delay> { + public: + DelayParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp index 347200d..b6f0a86 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp @@ -14,18 +14,18 @@ DeliveryReceiptParser::DeliveryReceiptParser() : level_(0) { } void DeliveryReceiptParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap) { - if (level_ == 0) { - if (element == "received") { - if (attributeMap.getAttributeValue("id").is_initialized()) { - getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get()); - } - } - } - ++level_; + if (level_ == 0) { + if (element == "received") { + if (attributeMap.getAttributeValue("id").is_initialized()) { + getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get()); + } + } + } + ++level_; } void DeliveryReceiptParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void DeliveryReceiptParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h index bcb73f3..5cc0009 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h @@ -17,15 +17,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DeliveryReceiptParser : public GenericPayloadParser<DeliveryReceipt> { - public: - DeliveryReceiptParser(); + class SWIFTEN_API DeliveryReceiptParser : public GenericPayloadParser<DeliveryReceipt> { + public: + DeliveryReceiptParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h index aa5d856..dc0c311 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h @@ -17,20 +17,20 @@ #include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API DeliveryReceiptParserFactory : public PayloadParserFactory { - public: - DeliveryReceiptParserFactory() { - } + class SWIFTEN_API DeliveryReceiptParserFactory : public PayloadParserFactory { + public: + DeliveryReceiptParserFactory() { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return ns == "urn:xmpp:receipts" && element == "received"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:receipts" && element == "received"; + } - virtual PayloadParser* createPayloadParser() { - return new DeliveryReceiptParser(); - } + virtual PayloadParser* createPayloadParser() { + return new DeliveryReceiptParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h index 5bf27fa..d8a68b0 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h @@ -17,12 +17,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DeliveryReceiptRequestParser : public GenericPayloadParser<DeliveryReceiptRequest> { - public: - DeliveryReceiptRequestParser(); + class SWIFTEN_API DeliveryReceiptRequestParser : public GenericPayloadParser<DeliveryReceiptRequest> { + public: + DeliveryReceiptRequestParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string& data); - }; + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string& data); + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h index 509db63..a858285 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h @@ -17,20 +17,20 @@ #include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API DeliveryReceiptRequestParserFactory : public PayloadParserFactory { - public: - DeliveryReceiptRequestParserFactory() { - } + class SWIFTEN_API DeliveryReceiptRequestParserFactory : public PayloadParserFactory { + public: + DeliveryReceiptRequestParserFactory() { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return ns == "urn:xmpp:receipts" && element == "request"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:receipts" && element == "request"; + } - virtual PayloadParser* createPayloadParser() { - return new DeliveryReceiptRequestParser(); - } + virtual PayloadParser* createPayloadParser() { + return new DeliveryReceiptRequestParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp index 9786b37..7dffa88 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -16,45 +16,45 @@ DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(NULL) { } void DiscoInfoParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - if (attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributes.getAttributeValue("node")); - } - } - else if (level_ == PayloadLevel) { - if (element == "identity") { - getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); - } - else if (element == "feature") { - getPayloadInternal()->addFeature(attributes.getAttribute("var")); - } - else if (element == "x" && ns == "jabber:x:data") { - assert(!formParser_); - formParser_ = new FormParser(); - } - } - if (formParser_) { - formParser_->handleStartElement(element, ns, attributes); - } - ++level_; + if (level_ == TopLevel) { + if (attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributes.getAttributeValue("node")); + } + } + else if (level_ == PayloadLevel) { + if (element == "identity") { + getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); + } + else if (element == "feature") { + getPayloadInternal()->addFeature(attributes.getAttribute("var")); + } + else if (element == "x" && ns == "jabber:x:data") { + assert(!formParser_); + formParser_ = new FormParser(); + } + } + if (formParser_) { + formParser_->handleStartElement(element, ns, attributes); + } + ++level_; } void DiscoInfoParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (formParser_) { - formParser_->handleEndElement(element, ns); - } - if (level_ == PayloadLevel && formParser_) { - getPayloadInternal()->addExtension(formParser_->getPayloadInternal()); - delete formParser_; - formParser_ = NULL; - } + --level_; + if (formParser_) { + formParser_->handleEndElement(element, ns); + } + if (level_ == PayloadLevel && formParser_) { + getPayloadInternal()->addExtension(formParser_->getPayloadInternal()); + delete formParser_; + formParser_ = NULL; + } } void DiscoInfoParser::handleCharacterData(const std::string& data) { - if (formParser_) { - formParser_->handleCharacterData(data); - } + if (formParser_) { + formParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h index 3d10c4b..28bfff1 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { - public: - DiscoInfoParser(); + class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { + public: + DiscoInfoParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - FormParser* formParser_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + FormParser* formParser_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp index 179fb29..a3b9245 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -12,21 +12,21 @@ DiscoItemsParser::DiscoItemsParser() : level_(TopLevel) { } void DiscoItemsParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "item") { - getPayloadInternal()->addItem(DiscoItems::Item(attributes.getAttribute("name"), JID(attributes.getAttribute("jid")), attributes.getAttribute("node"))); - } - } - else if (level_ == TopLevel) { - if (element == "query") { - getPayloadInternal()->setNode(attributes.getAttribute("node")); - } - } - ++level_; + if (level_ == PayloadLevel) { + if (element == "item") { + getPayloadInternal()->addItem(DiscoItems::Item(attributes.getAttribute("name"), JID(attributes.getAttribute("jid")), attributes.getAttribute("node"))); + } + } + else if (level_ == TopLevel) { + if (element == "query") { + getPayloadInternal()->setNode(attributes.getAttribute("node")); + } + } + ++level_; } void DiscoItemsParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void DiscoItemsParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h index b467ca1..3197b79 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DiscoItemsParser : public GenericPayloadParser<DiscoItems> { - public: - DiscoItemsParser(); + class SWIFTEN_API DiscoItemsParser : public GenericPayloadParser<DiscoItems> { + public: + DiscoItemsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.cpp b/Swiften/Parser/PayloadParsers/ErrorParser.cpp index ace305b..222bcbd 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/ErrorParser.cpp @@ -15,132 +15,132 @@ ErrorParser::ErrorParser(PayloadParserFactoryCollection* factories) : factories( } void ErrorParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - std::string type = attributes.getAttribute("type"); - if (type == "continue") { - getPayloadInternal()->setType(ErrorPayload::Continue); - } - else if (type == "modify") { - getPayloadInternal()->setType(ErrorPayload::Modify); - } - else if (type == "auth") { - getPayloadInternal()->setType(ErrorPayload::Auth); - } - else if (type == "wait") { - getPayloadInternal()->setType(ErrorPayload::Wait); - } - else { - getPayloadInternal()->setType(ErrorPayload::Cancel); - } - } - else if (level_ == PayloadLevel) { - if (element == "text") { + if (level_ == TopLevel) { + std::string type = attributes.getAttribute("type"); + if (type == "continue") { + getPayloadInternal()->setType(ErrorPayload::Continue); + } + else if (type == "modify") { + getPayloadInternal()->setType(ErrorPayload::Modify); + } + else if (type == "auth") { + getPayloadInternal()->setType(ErrorPayload::Auth); + } + else if (type == "wait") { + getPayloadInternal()->setType(ErrorPayload::Wait); + } + else { + getPayloadInternal()->setType(ErrorPayload::Cancel); + } + } + else if (level_ == PayloadLevel) { + if (element == "text") { - } - else if (element == "bad-request") { - getPayloadInternal()->setCondition(ErrorPayload::BadRequest); - } - else if (element == "conflict") { - getPayloadInternal()->setCondition(ErrorPayload::Conflict); - } - else if (element == "feature-not-implemented") { - getPayloadInternal()->setCondition(ErrorPayload::FeatureNotImplemented); - } - else if (element == "forbidden") { - getPayloadInternal()->setCondition(ErrorPayload::Forbidden); - } - else if (element == "gone") { - getPayloadInternal()->setCondition(ErrorPayload::Gone); - } - else if (element == "internal-server-error") { - getPayloadInternal()->setCondition(ErrorPayload::InternalServerError); - } - else if (element == "item-not-found") { - getPayloadInternal()->setCondition(ErrorPayload::ItemNotFound); - } - else if (element == "jid-malformed") { - getPayloadInternal()->setCondition(ErrorPayload::JIDMalformed); - } - else if (element == "not-acceptable") { - getPayloadInternal()->setCondition(ErrorPayload::NotAcceptable); - } - else if (element == "not-allowed") { - getPayloadInternal()->setCondition(ErrorPayload::NotAllowed); - } - else if (element == "not-authorized") { - getPayloadInternal()->setCondition(ErrorPayload::NotAuthorized); - } - else if (element == "payment-required") { - getPayloadInternal()->setCondition(ErrorPayload::PaymentRequired); - } - else if (element == "recipient-unavailable") { - getPayloadInternal()->setCondition(ErrorPayload::RecipientUnavailable); - } - else if (element == "redirect") { - getPayloadInternal()->setCondition(ErrorPayload::Redirect); - } - else if (element == "registration-required") { - getPayloadInternal()->setCondition(ErrorPayload::RegistrationRequired); - } - else if (element == "remote-server-not-found") { - getPayloadInternal()->setCondition(ErrorPayload::RemoteServerNotFound); - } - else if (element == "remote-server-timeout") { - getPayloadInternal()->setCondition(ErrorPayload::RemoteServerTimeout); - } - else if (element == "resource-constraint") { - getPayloadInternal()->setCondition(ErrorPayload::ResourceConstraint); - } - else if (element == "service-unavailable") { - getPayloadInternal()->setCondition(ErrorPayload::ServiceUnavailable); - } - else if (element == "subscription-required") { - getPayloadInternal()->setCondition(ErrorPayload::SubscriptionRequired); - } - else if (element == "unexpected-request") { - getPayloadInternal()->setCondition(ErrorPayload::UnexpectedRequest); - } - else { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } else { - getPayloadInternal()->setCondition(ErrorPayload::UndefinedCondition); - } - } - } - if (level_ >= PayloadLevel && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level_; + } + else if (element == "bad-request") { + getPayloadInternal()->setCondition(ErrorPayload::BadRequest); + } + else if (element == "conflict") { + getPayloadInternal()->setCondition(ErrorPayload::Conflict); + } + else if (element == "feature-not-implemented") { + getPayloadInternal()->setCondition(ErrorPayload::FeatureNotImplemented); + } + else if (element == "forbidden") { + getPayloadInternal()->setCondition(ErrorPayload::Forbidden); + } + else if (element == "gone") { + getPayloadInternal()->setCondition(ErrorPayload::Gone); + } + else if (element == "internal-server-error") { + getPayloadInternal()->setCondition(ErrorPayload::InternalServerError); + } + else if (element == "item-not-found") { + getPayloadInternal()->setCondition(ErrorPayload::ItemNotFound); + } + else if (element == "jid-malformed") { + getPayloadInternal()->setCondition(ErrorPayload::JIDMalformed); + } + else if (element == "not-acceptable") { + getPayloadInternal()->setCondition(ErrorPayload::NotAcceptable); + } + else if (element == "not-allowed") { + getPayloadInternal()->setCondition(ErrorPayload::NotAllowed); + } + else if (element == "not-authorized") { + getPayloadInternal()->setCondition(ErrorPayload::NotAuthorized); + } + else if (element == "payment-required") { + getPayloadInternal()->setCondition(ErrorPayload::PaymentRequired); + } + else if (element == "recipient-unavailable") { + getPayloadInternal()->setCondition(ErrorPayload::RecipientUnavailable); + } + else if (element == "redirect") { + getPayloadInternal()->setCondition(ErrorPayload::Redirect); + } + else if (element == "registration-required") { + getPayloadInternal()->setCondition(ErrorPayload::RegistrationRequired); + } + else if (element == "remote-server-not-found") { + getPayloadInternal()->setCondition(ErrorPayload::RemoteServerNotFound); + } + else if (element == "remote-server-timeout") { + getPayloadInternal()->setCondition(ErrorPayload::RemoteServerTimeout); + } + else if (element == "resource-constraint") { + getPayloadInternal()->setCondition(ErrorPayload::ResourceConstraint); + } + else if (element == "service-unavailable") { + getPayloadInternal()->setCondition(ErrorPayload::ServiceUnavailable); + } + else if (element == "subscription-required") { + getPayloadInternal()->setCondition(ErrorPayload::SubscriptionRequired); + } + else if (element == "unexpected-request") { + getPayloadInternal()->setCondition(ErrorPayload::UnexpectedRequest); + } + else { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } else { + getPayloadInternal()->setCondition(ErrorPayload::UndefinedCondition); + } + } + } + if (level_ >= PayloadLevel && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level_; } void ErrorParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (currentPayloadParser) { - if (level_ >= PayloadLevel) { - currentPayloadParser->handleEndElement(element, ns); - } + --level_; + if (currentPayloadParser) { + if (level_ >= PayloadLevel) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level_ == PayloadLevel) { - getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); - currentPayloadParser.reset(); - } - } - else if (level_ == PayloadLevel) { - if (element == "text") { - getPayloadInternal()->setText(currentText_); - } - } + if (level_ == PayloadLevel) { + getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } + else if (level_ == PayloadLevel) { + if (element == "text") { + getPayloadInternal()->setText(currentText_); + } + } } void ErrorParser::handleCharacterData(const std::string& data) { - if (level_ > PayloadLevel && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (level_ > PayloadLevel && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } + else { + currentText_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.h b/Swiften/Parser/PayloadParsers/ErrorParser.h index fc4a5cb..dd1aa95 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.h +++ b/Swiften/Parser/PayloadParsers/ErrorParser.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class SWIFTEN_API ErrorParser : public GenericPayloadParser<ErrorPayload> { - public: - ErrorParser(PayloadParserFactoryCollection* factories); + class PayloadParserFactoryCollection; + class SWIFTEN_API ErrorParser : public GenericPayloadParser<ErrorPayload> { + public: + ErrorParser(PayloadParserFactoryCollection* factories); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - PayloadParserFactoryCollection* factories; - int level_; - std::string currentText_; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + PayloadParserFactoryCollection* factories; + int level_; + std::string currentText_; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/ErrorParserFactory.h b/Swiften/Parser/PayloadParsers/ErrorParserFactory.h index bcced8b..d8f09bf 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ErrorParserFactory.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/PayloadParsers/ErrorParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API ErrorParserFactory : public PayloadParserFactory { - public: - ErrorParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API ErrorParserFactory : public PayloadParserFactory { + public: + ErrorParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& /*ns*/, const AttributeMap&) const { - return element == "error"; - } + virtual bool canParse(const std::string& element, const std::string& /*ns*/, const AttributeMap&) const { + return element == "error"; + } - virtual PayloadParser* createPayloadParser() { - return new ErrorParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new ErrorParser(factories); + } - private: - PayloadParserFactoryCollection* factories; + private: + PayloadParserFactoryCollection* factories; - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index b66dadc..3a2c880 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -16,240 +16,240 @@ FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReporte } void FormParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level_ == TopLevel) { - std::string type = attributes.getAttribute("type"); - if (type == "form") { - getPayloadInternal()->setType(Form::FormType); - } - else if (type == "submit") { - getPayloadInternal()->setType(Form::SubmitType); - } - else if (type == "cancel") { - getPayloadInternal()->setType(Form::CancelType); - } - else if (type == "result") { - getPayloadInternal()->setType(Form::ResultType); - } - } - else if (level_ == PayloadLevel) { - if (element == "title") { - currentText_.clear(); - } - else if (element == "instructions") { - currentText_.clear(); - } - else if (element == "reported") { - parsingReported_ = true; - } - else if (element == "item") { - parsingItem_ = true; - } - else if (element == "page") { - currentPage_ = boost::make_shared<FormPage>(); - currentPage_->setLabel(attributes.getAttribute("label")); - } - } - else if (level_ == FieldLevel && currentField_) { - currentText_.clear(); - if (element == "option") { - currentOptionLabel_ = attributes.getAttribute("label"); - currentOptionValue_ = ""; - parsingOption_ = true; - } - } - if (level_ >= PayloadLevel) { - if (element == "field") { - currentField_ = boost::make_shared<FormField>(); - std::string type = attributes.getAttribute("type"); - FormField::Type fieldType = FormField::UnknownType; - if (type == "boolean") { - fieldType = FormField::BooleanType; - } - if (type == "fixed") { - fieldType = FormField::FixedType; - } - if (type == "hidden") { - fieldType = FormField::HiddenType; - } - if (type == "list-single") { - fieldType = FormField::ListSingleType; - } - if (type == "text-multi") { - fieldType = FormField::TextMultiType; - } - if (type == "text-private") { - fieldType = FormField::TextPrivateType; - } - if (type == "text-single") { - fieldType = FormField::TextSingleType; - } - if (type == "jid-single") { - fieldType = FormField::JIDSingleType; - } - if (type == "jid-multi") { - fieldType = FormField::JIDMultiType; - } - if (type == "list-multi") { - fieldType = FormField::ListMultiType; - } - currentField_->setType(fieldType); - currentField_->setName(attributes.getAttribute("var")); - currentField_->setLabel(attributes.getAttribute("label")); - } - else if (element == "value") { - currentText_.clear(); - } - } - if (level_ > PayloadLevel) { - if (element == "section") { - currentSection_ = boost::make_shared<FormSection>(); - currentSection_->setLabel(attributes.getAttribute("label")); - sectionStack_.push_back(currentSection_); - currentSections_.push_back(currentSection_); - } - if (element == "reportedref") { - currentReportedRef_ = boost::make_shared<FormReportedRef>(); - } - if (element == "fieldref") { - currentText_.clear(); - currentFieldRef_ = attributes.getAttribute("var"); - if (sectionStack_.size() > 0) { - sectionStack_.at(sectionStack_.size()-1)->addFieldRef(currentFieldRef_); - } else if (currentPage_) { - currentPage_->addFieldRef(currentFieldRef_); - } - } - if (element == "text") { - currentText_.clear(); - currentTextElement_ = boost::make_shared<FormText>(); - } - } - ++level_; + if (level_ == TopLevel) { + std::string type = attributes.getAttribute("type"); + if (type == "form") { + getPayloadInternal()->setType(Form::FormType); + } + else if (type == "submit") { + getPayloadInternal()->setType(Form::SubmitType); + } + else if (type == "cancel") { + getPayloadInternal()->setType(Form::CancelType); + } + else if (type == "result") { + getPayloadInternal()->setType(Form::ResultType); + } + } + else if (level_ == PayloadLevel) { + if (element == "title") { + currentText_.clear(); + } + else if (element == "instructions") { + currentText_.clear(); + } + else if (element == "reported") { + parsingReported_ = true; + } + else if (element == "item") { + parsingItem_ = true; + } + else if (element == "page") { + currentPage_ = boost::make_shared<FormPage>(); + currentPage_->setLabel(attributes.getAttribute("label")); + } + } + else if (level_ == FieldLevel && currentField_) { + currentText_.clear(); + if (element == "option") { + currentOptionLabel_ = attributes.getAttribute("label"); + currentOptionValue_ = ""; + parsingOption_ = true; + } + } + if (level_ >= PayloadLevel) { + if (element == "field") { + currentField_ = boost::make_shared<FormField>(); + std::string type = attributes.getAttribute("type"); + FormField::Type fieldType = FormField::UnknownType; + if (type == "boolean") { + fieldType = FormField::BooleanType; + } + if (type == "fixed") { + fieldType = FormField::FixedType; + } + if (type == "hidden") { + fieldType = FormField::HiddenType; + } + if (type == "list-single") { + fieldType = FormField::ListSingleType; + } + if (type == "text-multi") { + fieldType = FormField::TextMultiType; + } + if (type == "text-private") { + fieldType = FormField::TextPrivateType; + } + if (type == "text-single") { + fieldType = FormField::TextSingleType; + } + if (type == "jid-single") { + fieldType = FormField::JIDSingleType; + } + if (type == "jid-multi") { + fieldType = FormField::JIDMultiType; + } + if (type == "list-multi") { + fieldType = FormField::ListMultiType; + } + currentField_->setType(fieldType); + currentField_->setName(attributes.getAttribute("var")); + currentField_->setLabel(attributes.getAttribute("label")); + } + else if (element == "value") { + currentText_.clear(); + } + } + if (level_ > PayloadLevel) { + if (element == "section") { + currentSection_ = boost::make_shared<FormSection>(); + currentSection_->setLabel(attributes.getAttribute("label")); + sectionStack_.push_back(currentSection_); + currentSections_.push_back(currentSection_); + } + if (element == "reportedref") { + currentReportedRef_ = boost::make_shared<FormReportedRef>(); + } + if (element == "fieldref") { + currentText_.clear(); + currentFieldRef_ = attributes.getAttribute("var"); + if (sectionStack_.size() > 0) { + sectionStack_.at(sectionStack_.size()-1)->addFieldRef(currentFieldRef_); + } else if (currentPage_) { + currentPage_->addFieldRef(currentFieldRef_); + } + } + if (element == "text") { + currentText_.clear(); + currentTextElement_ = boost::make_shared<FormText>(); + } + } + ++level_; } void FormParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel) { - if (element == "title") { - std::string currentTitle = getPayloadInternal()->getTitle(); - if (currentTitle.empty()) { - getPayloadInternal()->setTitle(currentText_); - } - else { - getPayloadInternal()->setTitle(currentTitle + "\n" + currentText_); - } - } - else if (element == "instructions") { - std::string currentInstructions = getPayloadInternal()->getInstructions(); - if (currentInstructions.empty()) { - getPayloadInternal()->setInstructions(currentText_); - } - else { - getPayloadInternal()->setInstructions(currentInstructions + "\n" + currentText_); - } - } - else if (element == "reported") { - parsingReported_ = false; - } - else if (element == "item") { - parsingItem_ = false; - getPayloadInternal()->addItem(currentFields_); - currentFields_.clear(); - } - else if (element == "page") { - getPayloadInternal()->addPage(currentPage_); - currentPages_.push_back(currentPage_); - } - } - else if (currentField_) { - if (element == "required") { - currentField_->setRequired(true); - } - else if (element == "desc") { - currentField_->setDescription(currentText_); - } - else if (element == "option") { - currentField_->addOption(FormField::Option(currentOptionLabel_, currentOptionValue_)); - parsingOption_ = false; - } - else if (element == "value") { - if (parsingOption_) { - currentOptionValue_ = currentText_; - } - else { - currentField_->addValue(currentText_); - } - } - } - if (level_ >= PayloadLevel && currentField_) { - if (element == "field") { - if (parsingReported_) { - getPayloadInternal()->addReportedField(currentField_); - } - else if (parsingItem_) { - currentFields_.push_back(currentField_); - } - else { - if (currentPages_.size() > 0) { - foreach (boost::shared_ptr<FormPage> page, currentPages_) { - foreach (std::string pageRef, page->getFieldRefs()) { - if (pageRef == currentField_->getName()) { - page->addField(currentField_); - } - } - } - foreach (boost::shared_ptr<FormSection> section, currentSections_) { - foreach (std::string sectionRef, section->getFieldRefs()) { - if (sectionRef == currentField_->getName()) { - section->addField(currentField_); - } - } - } - } else { - getPayloadInternal()->addField(currentField_); - } - } - currentField_.reset(); - } - } - if (level_ > PayloadLevel) { - if (element == "section") { - if (sectionStack_.size() > 1) { - // Add the section at the top of the stack to the level below - sectionStack_.at(sectionStack_.size()-2)->addChildSection(sectionStack_.at(sectionStack_.size()-1)); - sectionStack_.pop_back(); - } - else if (sectionStack_.size() == 1) { - // Add the remaining section on the stack to its parent page - currentPage_->addChildSection(sectionStack_.at(sectionStack_.size()-1)); - sectionStack_.pop_back(); - } - } - if (currentReportedRef_ && !hasReportedRef_) { - if (sectionStack_.size() > 0) { - sectionStack_.at(sectionStack_.size()-1)->addReportedRef(currentReportedRef_); - } else if (currentPage_) { - currentPage_->addReportedRef(currentReportedRef_); - } - hasReportedRef_ = true; - currentReportedRef_.reset(); - } - if (currentTextElement_) { - if (element == "text") { - currentTextElement_->setTextString(currentText_); - } - if (sectionStack_.size() > 0) { - sectionStack_.at(sectionStack_.size()-1)->addTextElement(currentTextElement_); - } else if (currentPage_) { - currentPage_->addTextElement(currentTextElement_); - } - currentTextElement_.reset(); - } - } + --level_; + if (level_ == PayloadLevel) { + if (element == "title") { + std::string currentTitle = getPayloadInternal()->getTitle(); + if (currentTitle.empty()) { + getPayloadInternal()->setTitle(currentText_); + } + else { + getPayloadInternal()->setTitle(currentTitle + "\n" + currentText_); + } + } + else if (element == "instructions") { + std::string currentInstructions = getPayloadInternal()->getInstructions(); + if (currentInstructions.empty()) { + getPayloadInternal()->setInstructions(currentText_); + } + else { + getPayloadInternal()->setInstructions(currentInstructions + "\n" + currentText_); + } + } + else if (element == "reported") { + parsingReported_ = false; + } + else if (element == "item") { + parsingItem_ = false; + getPayloadInternal()->addItem(currentFields_); + currentFields_.clear(); + } + else if (element == "page") { + getPayloadInternal()->addPage(currentPage_); + currentPages_.push_back(currentPage_); + } + } + else if (currentField_) { + if (element == "required") { + currentField_->setRequired(true); + } + else if (element == "desc") { + currentField_->setDescription(currentText_); + } + else if (element == "option") { + currentField_->addOption(FormField::Option(currentOptionLabel_, currentOptionValue_)); + parsingOption_ = false; + } + else if (element == "value") { + if (parsingOption_) { + currentOptionValue_ = currentText_; + } + else { + currentField_->addValue(currentText_); + } + } + } + if (level_ >= PayloadLevel && currentField_) { + if (element == "field") { + if (parsingReported_) { + getPayloadInternal()->addReportedField(currentField_); + } + else if (parsingItem_) { + currentFields_.push_back(currentField_); + } + else { + if (currentPages_.size() > 0) { + foreach (boost::shared_ptr<FormPage> page, currentPages_) { + foreach (std::string pageRef, page->getFieldRefs()) { + if (pageRef == currentField_->getName()) { + page->addField(currentField_); + } + } + } + foreach (boost::shared_ptr<FormSection> section, currentSections_) { + foreach (std::string sectionRef, section->getFieldRefs()) { + if (sectionRef == currentField_->getName()) { + section->addField(currentField_); + } + } + } + } else { + getPayloadInternal()->addField(currentField_); + } + } + currentField_.reset(); + } + } + if (level_ > PayloadLevel) { + if (element == "section") { + if (sectionStack_.size() > 1) { + // Add the section at the top of the stack to the level below + sectionStack_.at(sectionStack_.size()-2)->addChildSection(sectionStack_.at(sectionStack_.size()-1)); + sectionStack_.pop_back(); + } + else if (sectionStack_.size() == 1) { + // Add the remaining section on the stack to its parent page + currentPage_->addChildSection(sectionStack_.at(sectionStack_.size()-1)); + sectionStack_.pop_back(); + } + } + if (currentReportedRef_ && !hasReportedRef_) { + if (sectionStack_.size() > 0) { + sectionStack_.at(sectionStack_.size()-1)->addReportedRef(currentReportedRef_); + } else if (currentPage_) { + currentPage_->addReportedRef(currentReportedRef_); + } + hasReportedRef_ = true; + currentReportedRef_.reset(); + } + if (currentTextElement_) { + if (element == "text") { + currentTextElement_->setTextString(currentText_); + } + if (sectionStack_.size() > 0) { + sectionStack_.at(sectionStack_.size()-1)->addTextElement(currentTextElement_); + } else if (currentPage_) { + currentPage_->addTextElement(currentTextElement_); + } + currentTextElement_.reset(); + } + } } void FormParser::handleCharacterData(const std::string& text) { - currentText_ += text; + currentText_ += text; } } diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h index c8c2294..81032ee 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -11,36 +11,36 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API FormParser : public GenericPayloadParser<Form> { - public: - FormParser(); + class SWIFTEN_API FormParser : public GenericPayloadParser<Form> { + public: + FormParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - enum Level { - TopLevel = 0, - PayloadLevel = 1, - FieldLevel = 2 - }; - int level_; - std::string currentText_; - std::string currentOptionLabel_; - std::string currentOptionValue_; - std::string currentFieldRef_; - bool parsingItem_; - bool parsingReported_; - bool parsingOption_; - bool hasReportedRef_; - FormField::ref currentField_; - std::vector<FormField::ref> currentFields_; - FormText::text currentTextElement_; - FormReportedRef::ref currentReportedRef_; - FormPage::page currentPage_; - FormSection::section currentSection_; - std::vector<boost::shared_ptr<FormPage> > currentPages_; - std::vector<boost::shared_ptr<FormSection> > sectionStack_; - std::vector<boost::shared_ptr<FormSection> > currentSections_; - }; + enum Level { + TopLevel = 0, + PayloadLevel = 1, + FieldLevel = 2 + }; + int level_; + std::string currentText_; + std::string currentOptionLabel_; + std::string currentOptionValue_; + std::string currentFieldRef_; + bool parsingItem_; + bool parsingReported_; + bool parsingOption_; + bool hasReportedRef_; + FormField::ref currentField_; + std::vector<FormField::ref> currentFields_; + FormText::text currentTextElement_; + FormReportedRef::ref currentReportedRef_; + FormPage::page currentPage_; + FormSection::section currentSection_; + std::vector<boost::shared_ptr<FormPage> > currentPages_; + std::vector<boost::shared_ptr<FormSection> > sectionStack_; + std::vector<boost::shared_ptr<FormSection> > currentSections_; + }; } diff --git a/Swiften/Parser/PayloadParsers/FormParserFactory.h b/Swiften/Parser/PayloadParsers/FormParserFactory.h index 74b2d35..851b302 100644 --- a/Swiften/Parser/PayloadParsers/FormParserFactory.h +++ b/Swiften/Parser/PayloadParsers/FormParserFactory.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API FormParserFactory : public PayloadParserFactory { - public: - FormParserFactory() { - } + class SWIFTEN_API FormParserFactory : public PayloadParserFactory { + public: + FormParserFactory() { + } - virtual bool canParse(const std::string& /*element*/, const std::string& ns, const AttributeMap&) const { - return ns == "jabber:x:data"; - } + virtual bool canParse(const std::string& /*element*/, const std::string& ns, const AttributeMap&) const { + return ns == "jabber:x:data"; + } - virtual PayloadParser* createPayloadParser() { - return new FormParser(); - } + virtual PayloadParser* createPayloadParser() { + return new FormParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/ForwardedParser.cpp b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp index 1e3d339..35d20a9 100644 --- a/Swiften/Parser/PayloadParsers/ForwardedParser.cpp +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp @@ -23,51 +23,51 @@ ForwardedParser::ForwardedParser(PayloadParserFactoryCollection* factories) : fa } void ForwardedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "iq" && ns == "jabber:client") { /* begin parsing a nested stanza? */ - childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<IQParser>(factories_)); - } else if (element == "message" && ns == "jabber:client") { - childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<MessageParser>(factories_)); - } else if (element == "presence" && ns == "jabber:client") { - childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<PresenceParser>(factories_)); - } else if (element == "delay" && ns == "urn:xmpp:delay") { /* nested delay payload */ - delayParser_ = boost::make_shared<DelayParser>(); - } - } - if (childParser_) { /* parsing a nested stanza? */ - childParser_->handleStartElement(element, ns, attributes); - } - if (delayParser_) { /* parsing a nested delay payload? */ - delayParser_->handleStartElement(element, ns, attributes); - } - ++level_; + if (level_ == PayloadLevel) { + if (element == "iq" && ns == "jabber:client") { /* begin parsing a nested stanza? */ + childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<IQParser>(factories_)); + } else if (element == "message" && ns == "jabber:client") { + childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<MessageParser>(factories_)); + } else if (element == "presence" && ns == "jabber:client") { + childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<PresenceParser>(factories_)); + } else if (element == "delay" && ns == "urn:xmpp:delay") { /* nested delay payload */ + delayParser_ = boost::make_shared<DelayParser>(); + } + } + if (childParser_) { /* parsing a nested stanza? */ + childParser_->handleStartElement(element, ns, attributes); + } + if (delayParser_) { /* parsing a nested delay payload? */ + delayParser_->handleStartElement(element, ns, attributes); + } + ++level_; } void ForwardedParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (childParser_ && level_ >= PayloadLevel) { - childParser_->handleEndElement(element, ns); - } - if (childParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setStanza(childParser_->getStanza()); - childParser_.reset(); - } - if (delayParser_ && level_ >= PayloadLevel) { - delayParser_->handleEndElement(element, ns); - } - if (delayParser_ && level_ == PayloadLevel) { - /* done parsing nested delay payload */ - getPayloadInternal()->setDelay(boost::dynamic_pointer_cast<Delay>(delayParser_->getPayload())); - delayParser_.reset(); - } + --level_; + if (childParser_ && level_ >= PayloadLevel) { + childParser_->handleEndElement(element, ns); + } + if (childParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setStanza(childParser_->getStanza()); + childParser_.reset(); + } + if (delayParser_ && level_ >= PayloadLevel) { + delayParser_->handleEndElement(element, ns); + } + if (delayParser_ && level_ == PayloadLevel) { + /* done parsing nested delay payload */ + getPayloadInternal()->setDelay(boost::dynamic_pointer_cast<Delay>(delayParser_->getPayload())); + delayParser_.reset(); + } } void ForwardedParser::handleCharacterData(const std::string& data) { - if (childParser_) { - childParser_->handleCharacterData(data); - } - if (delayParser_) { - delayParser_->handleCharacterData(data); - } + if (childParser_) { + childParser_->handleCharacterData(data); + } + if (delayParser_) { + delayParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/ForwardedParser.h b/Swiften/Parser/PayloadParsers/ForwardedParser.h index 6d7b4f5..70eecdf 100644 --- a/Swiften/Parser/PayloadParsers/ForwardedParser.h +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.h @@ -14,27 +14,27 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class StanzaParser; - class DelayParser; - - class SWIFTEN_API ForwardedParser : public GenericPayloadParser<Forwarded> { - public: - ForwardedParser(PayloadParserFactoryCollection* factories); - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - - private: - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<StanzaParser> childParser_; - boost::shared_ptr<DelayParser> delayParser_; - int level_; - }; + class PayloadParserFactoryCollection; + class StanzaParser; + class DelayParser; + + class SWIFTEN_API ForwardedParser : public GenericPayloadParser<Forwarded> { + public: + ForwardedParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + PayloadParserFactoryCollection* factories_; + boost::shared_ptr<StanzaParser> childParser_; + boost::shared_ptr<DelayParser> delayParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 7e7123f..0d0c424 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -94,94 +94,94 @@ using namespace boost; namespace Swift { FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IBBParser> >("", "http://jabber.org/protocol/ibb")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StatusShowParser> >("show")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StatusParser> >("status")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "http://swift.im/protocol/replace")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "urn:xmpp:message-correct:0")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<LastParser> >("query", "jabber:iq:last")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BodyParser> >("body")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SubjectParser> >("subject")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ThreadParser> >("thread")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<PriorityParser> >("priority")); - factories_.push_back(boost::make_shared<ErrorParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DelayParser> >("delay", "urn:xmpp:delay")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SoftwareVersionParser> >("query", "jabber:iq:version")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StorageParser> >("storage", "storage:bookmarks")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RosterItemExchangeParser> >("x", "http://jabber.org/protocol/rosterx")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RosterParser> >("query", "jabber:iq:roster")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DiscoInfoParser> >("query", "http://jabber.org/protocol/disco#info")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DiscoItemsParser> >("query", "http://jabber.org/protocol/disco#items")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CapsInfoParser> >("c", "http://jabber.org/protocol/caps")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResourceBindParser> >("bind", "urn:ietf:params:xml:ns:xmpp-bind")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StartSessionParser> >("session", "urn:ietf:params:xml:ns:xmpp-session")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<BlockPayload> > >("block", "urn:xmpp:blocking")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<BlockListPayload> > >("blocklist", "urn:xmpp:blocking")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<UnblockPayload> > >("unblock", "urn:xmpp:blocking")); - factories_.push_back(boost::make_shared<SecurityLabelParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SecurityLabelsCatalogParser> >("catalog", "urn:xmpp:sec-label:catalog:2")); - factories_.push_back(boost::make_shared<FormParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CommandParser> >("command", "http://jabber.org/protocol/commands")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<InBandRegistrationPayloadParser> >("query", "jabber:iq:register")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SearchPayloadParser> >("query", "jabber:iq:search")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationParser> >("si", "http://jabber.org/protocol/si")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BytestreamsParser> >("query", "http://jabber.org/protocol/bytestreams")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<VCardUpdateParser> >("x", "vcard-temp:x:update")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<VCardParser> >("vCard", "vcard-temp")); - factories_.push_back(boost::make_shared<PrivateStorageParserFactory>(this)); - factories_.push_back(boost::make_shared<ChatStateParserFactory>()); - factories_.push_back(boost::make_shared<MUCUserPayloadParserFactory>(this)); - factories_.push_back(boost::make_shared<MUCOwnerPayloadParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCInvitationPayloadParser> >("x", "jabber:x:conference")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<NicknameParser> >("nick", "http://jabber.org/protocol/nick")); - factories_.push_back(boost::make_shared<JingleParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleReasonParser> >("reason", "urn:xmpp:jingle:1")); - factories_.push_back(boost::make_shared<JingleContentPayloadParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:ibb:1")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:s5b:1")); - factories_.push_back(boost::make_shared<JingleFileTransferDescriptionParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationFileInfoParser> >("file", "http://jabber.org/protocol/si/profile/file-transfer")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferFileInfoParser> >("file", "urn:xmpp:jingle:apps:file-transfer:4")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune")); - factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>()); - factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this)); - factories_.push_back(boost::make_shared<PubSubErrorParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResultSetParser> >("set", "http://jabber.org/protocol/rsm")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMFinParser> >("fin", "urn:xmpp:mam:0")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsEnableParser> >("enable", "urn:xmpp:carbons:2")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsDisableParser> >("disable", "urn:xmpp:carbons:2")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<CarbonsReceivedParser> >("received", "urn:xmpp:carbons:2", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<CarbonsSentParser> >("sent", "urn:xmpp:carbons:2", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsPrivateParser> >("private", "urn:xmpp:carbons:2")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IBBParser> >("", "http://jabber.org/protocol/ibb")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StatusShowParser> >("show")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StatusParser> >("status")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "http://swift.im/protocol/replace")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "urn:xmpp:message-correct:0")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<LastParser> >("query", "jabber:iq:last")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BodyParser> >("body")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SubjectParser> >("subject")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ThreadParser> >("thread")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<PriorityParser> >("priority")); + factories_.push_back(boost::make_shared<ErrorParserFactory>(this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DelayParser> >("delay", "urn:xmpp:delay")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SoftwareVersionParser> >("query", "jabber:iq:version")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StorageParser> >("storage", "storage:bookmarks")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RosterItemExchangeParser> >("x", "http://jabber.org/protocol/rosterx")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RosterParser> >("query", "jabber:iq:roster")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DiscoInfoParser> >("query", "http://jabber.org/protocol/disco#info")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DiscoItemsParser> >("query", "http://jabber.org/protocol/disco#items")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CapsInfoParser> >("c", "http://jabber.org/protocol/caps")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResourceBindParser> >("bind", "urn:ietf:params:xml:ns:xmpp-bind")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StartSessionParser> >("session", "urn:ietf:params:xml:ns:xmpp-session")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<BlockPayload> > >("block", "urn:xmpp:blocking")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<BlockListPayload> > >("blocklist", "urn:xmpp:blocking")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<UnblockPayload> > >("unblock", "urn:xmpp:blocking")); + factories_.push_back(boost::make_shared<SecurityLabelParserFactory>()); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SecurityLabelsCatalogParser> >("catalog", "urn:xmpp:sec-label:catalog:2")); + factories_.push_back(boost::make_shared<FormParserFactory>()); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CommandParser> >("command", "http://jabber.org/protocol/commands")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<InBandRegistrationPayloadParser> >("query", "jabber:iq:register")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SearchPayloadParser> >("query", "jabber:iq:search")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationParser> >("si", "http://jabber.org/protocol/si")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BytestreamsParser> >("query", "http://jabber.org/protocol/bytestreams")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<VCardUpdateParser> >("x", "vcard-temp:x:update")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<VCardParser> >("vCard", "vcard-temp")); + factories_.push_back(boost::make_shared<PrivateStorageParserFactory>(this)); + factories_.push_back(boost::make_shared<ChatStateParserFactory>()); + factories_.push_back(boost::make_shared<MUCUserPayloadParserFactory>(this)); + factories_.push_back(boost::make_shared<MUCOwnerPayloadParserFactory>(this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCInvitationPayloadParser> >("x", "jabber:x:conference")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<NicknameParser> >("nick", "http://jabber.org/protocol/nick")); + factories_.push_back(boost::make_shared<JingleParserFactory>(this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleReasonParser> >("reason", "urn:xmpp:jingle:1")); + factories_.push_back(boost::make_shared<JingleContentPayloadParserFactory>(this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:ibb:1")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:s5b:1")); + factories_.push_back(boost::make_shared<JingleFileTransferDescriptionParserFactory>(this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationFileInfoParser> >("file", "http://jabber.org/protocol/si/profile/file-transfer")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferFileInfoParser> >("file", "urn:xmpp:jingle:apps:file-transfer:4")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune")); + factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>()); + factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>()); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this)); + factories_.push_back(boost::make_shared<PubSubErrorParserFactory>()); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResultSetParser> >("set", "http://jabber.org/protocol/rsm")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMFinParser> >("fin", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsEnableParser> >("enable", "urn:xmpp:carbons:2")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsDisableParser> >("disable", "urn:xmpp:carbons:2")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<CarbonsReceivedParser> >("received", "urn:xmpp:carbons:2", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<CarbonsSentParser> >("sent", "urn:xmpp:carbons:2", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsPrivateParser> >("private", "urn:xmpp:carbons:2")); - foreach(shared_ptr<PayloadParserFactory> factory, factories_) { - addFactory(factory.get()); - } - defaultFactory_ = new RawXMLPayloadParserFactory(); - setDefaultFactory(defaultFactory_); + foreach(shared_ptr<PayloadParserFactory> factory, factories_) { + addFactory(factory.get()); + } + defaultFactory_ = new RawXMLPayloadParserFactory(); + setDefaultFactory(defaultFactory_); } FullPayloadParserFactoryCollection::~FullPayloadParserFactoryCollection() { - setDefaultFactory(NULL); - delete defaultFactory_; - foreach(shared_ptr<PayloadParserFactory> factory, factories_) { - removeFactory(factory.get()); - } + setDefaultFactory(NULL); + delete defaultFactory_; + foreach(shared_ptr<PayloadParserFactory> factory, factories_) { + removeFactory(factory.get()); + } } } diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h index 3346e47..210e85e 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h @@ -15,13 +15,13 @@ #include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { - class SWIFTEN_API FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { - public: - FullPayloadParserFactoryCollection(); - ~FullPayloadParserFactoryCollection(); + class SWIFTEN_API FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { + public: + FullPayloadParserFactoryCollection(); + ~FullPayloadParserFactoryCollection(); - private: - std::vector< boost::shared_ptr<PayloadParserFactory> > factories_; - PayloadParserFactory* defaultFactory_; - }; + private: + std::vector< boost::shared_ptr<PayloadParserFactory> > factories_; + PayloadParserFactory* defaultFactory_; + }; } diff --git a/Swiften/Parser/PayloadParsers/IBBParser.cpp b/Swiften/Parser/PayloadParsers/IBBParser.cpp index c04e3cc..3aeb04c 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.cpp +++ b/Swiften/Parser/PayloadParsers/IBBParser.cpp @@ -20,57 +20,57 @@ IBBParser::~IBBParser() { } void IBBParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - if (element == "data") { - getPayloadInternal()->setAction(IBB::Data); - getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); - try { - getPayloadInternal()->setSequenceNumber(boost::lexical_cast<int>(attributes.getAttribute("seq"))); - } - catch (boost::bad_lexical_cast&) { - } - } - else if (element == "open") { - getPayloadInternal()->setAction(IBB::Open); - getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); - if (attributes.getAttribute("stanza") == "message") { - getPayloadInternal()->setStanzaType(IBB::MessageStanza); - } - else { - getPayloadInternal()->setStanzaType(IBB::IQStanza); - } - try { - getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttribute("block-size"))); - } - catch (boost::bad_lexical_cast&) { - } - } - else if (element == "close") { - getPayloadInternal()->setAction(IBB::Close); - getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); - } - } - ++level; + if (level == TopLevel) { + if (element == "data") { + getPayloadInternal()->setAction(IBB::Data); + getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); + try { + getPayloadInternal()->setSequenceNumber(boost::lexical_cast<int>(attributes.getAttribute("seq"))); + } + catch (boost::bad_lexical_cast&) { + } + } + else if (element == "open") { + getPayloadInternal()->setAction(IBB::Open); + getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); + if (attributes.getAttribute("stanza") == "message") { + getPayloadInternal()->setStanzaType(IBB::MessageStanza); + } + else { + getPayloadInternal()->setStanzaType(IBB::IQStanza); + } + try { + getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttribute("block-size"))); + } + catch (boost::bad_lexical_cast&) { + } + } + else if (element == "close") { + getPayloadInternal()->setAction(IBB::Close); + getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); + } + } + ++level; } void IBBParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == TopLevel) { - if (element == "data") { - std::vector<char> data; - for (size_t i = 0; i < currentText.size(); ++i) { - char c = currentText[i]; - if ((c >= 48 && c <= 122) || c == 47 || c == 43) { - data.push_back(c); - } - } - getPayloadInternal()->setData(Base64::decode(std::string(&data[0], data.size()))); - } - } + --level; + if (level == TopLevel) { + if (element == "data") { + std::vector<char> data; + for (size_t i = 0; i < currentText.size(); ++i) { + char c = currentText[i]; + if ((c >= 48 && c <= 122) || c == 47 || c == 43) { + data.push_back(c); + } + } + getPayloadInternal()->setData(Base64::decode(std::string(&data[0], data.size()))); + } + } } void IBBParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } diff --git a/Swiften/Parser/PayloadParsers/IBBParser.h b/Swiften/Parser/PayloadParsers/IBBParser.h index 95fe61a..7ef3e6f 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.h +++ b/Swiften/Parser/PayloadParsers/IBBParser.h @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API IBBParser : public GenericPayloadParser<IBB> { - public: - IBBParser(); - ~IBBParser(); + class SWIFTEN_API IBBParser : public GenericPayloadParser<IBB> { + public: + IBBParser(); + ~IBBParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0 - }; - int level; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/IdleParser.cpp b/Swiften/Parser/PayloadParsers/IdleParser.cpp index 51aa34b..e985576 100644 --- a/Swiften/Parser/PayloadParsers/IdleParser.cpp +++ b/Swiften/Parser/PayloadParsers/IdleParser.cpp @@ -14,15 +14,15 @@ IdleParser::IdleParser() : level_(0) { } void IdleParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level_ == 0) { - boost::posix_time::ptime since = stringToDateTime(attributes.getAttribute("since")); - getPayloadInternal()->setSince(since); - } - ++level_; + if (level_ == 0) { + boost::posix_time::ptime since = stringToDateTime(attributes.getAttribute("since")); + getPayloadInternal()->setSince(since); + } + ++level_; } void IdleParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void IdleParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/IdleParser.h b/Swiften/Parser/PayloadParsers/IdleParser.h index d8bbd1d..c1922c0 100644 --- a/Swiften/Parser/PayloadParsers/IdleParser.h +++ b/Swiften/Parser/PayloadParsers/IdleParser.h @@ -17,15 +17,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API IdleParser : public GenericPayloadParser<Idle> { - public: - IdleParser(); + class SWIFTEN_API IdleParser : public GenericPayloadParser<Idle> { + public: + IdleParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp index d29fa73..b019626 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp @@ -14,118 +14,118 @@ namespace Swift { InBandRegistrationPayloadParser::InBandRegistrationPayloadParser() : level(TopLevel), formParser(NULL) { - formParserFactory = new FormParserFactory(); + formParserFactory = new FormParserFactory(); } InBandRegistrationPayloadParser::~InBandRegistrationPayloadParser() { - delete formParserFactory; + delete formParserFactory; } void InBandRegistrationPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (element == "x" && ns == "jabber:x:data") { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - else { - currentText.clear(); - } - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + else { + currentText.clear(); + } + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } - ++level; + ++level; } void InBandRegistrationPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; + --level; - if (formParser) { - formParser->handleEndElement(element, ns); - } + if (formParser) { + formParser->handleEndElement(element, ns); + } - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (formParser) { - getPayloadInternal()->setForm(formParser->getPayloadInternal()); - delete formParser; - formParser = NULL; - } - else if (element == "registered") { - getPayloadInternal()->setRegistered(true); - } - else if (element == "remove") { - getPayloadInternal()->setRemove(true); - } - else if (element == "instructions") { - getPayloadInternal()->setInstructions(currentText); - } - else if (element == "username") { - getPayloadInternal()->setUsername(currentText); - } - else if (element == "nick") { - getPayloadInternal()->setNick(currentText); - } - else if (element == "password") { - getPayloadInternal()->setPassword(currentText); - } - else if (element == "name") { - getPayloadInternal()->setName(currentText); - } - else if (element == "first") { - getPayloadInternal()->setFirst(currentText); - } - else if (element == "last") { - getPayloadInternal()->setLast(currentText); - } - else if (element == "email") { - getPayloadInternal()->setEMail(currentText); - } - else if (element == "address") { - getPayloadInternal()->setAddress(currentText); - } - else if (element == "city") { - getPayloadInternal()->setCity(currentText); - } - else if (element == "state") { - getPayloadInternal()->setState(currentText); - } - else if (element == "zip") { - getPayloadInternal()->setZip(currentText); - } - else if (element == "phone") { - getPayloadInternal()->setPhone(currentText); - } - else if (element == "url") { - getPayloadInternal()->setURL(currentText); - } - else if (element == "date") { - getPayloadInternal()->setDate(currentText); - } - else if (element == "misc") { - getPayloadInternal()->setMisc(currentText); - } - else if (element == "text") { - getPayloadInternal()->setText(currentText); - } - else if (element == "key") { - getPayloadInternal()->setKey(currentText); - } - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (formParser) { + getPayloadInternal()->setForm(formParser->getPayloadInternal()); + delete formParser; + formParser = NULL; + } + else if (element == "registered") { + getPayloadInternal()->setRegistered(true); + } + else if (element == "remove") { + getPayloadInternal()->setRemove(true); + } + else if (element == "instructions") { + getPayloadInternal()->setInstructions(currentText); + } + else if (element == "username") { + getPayloadInternal()->setUsername(currentText); + } + else if (element == "nick") { + getPayloadInternal()->setNick(currentText); + } + else if (element == "password") { + getPayloadInternal()->setPassword(currentText); + } + else if (element == "name") { + getPayloadInternal()->setName(currentText); + } + else if (element == "first") { + getPayloadInternal()->setFirst(currentText); + } + else if (element == "last") { + getPayloadInternal()->setLast(currentText); + } + else if (element == "email") { + getPayloadInternal()->setEMail(currentText); + } + else if (element == "address") { + getPayloadInternal()->setAddress(currentText); + } + else if (element == "city") { + getPayloadInternal()->setCity(currentText); + } + else if (element == "state") { + getPayloadInternal()->setState(currentText); + } + else if (element == "zip") { + getPayloadInternal()->setZip(currentText); + } + else if (element == "phone") { + getPayloadInternal()->setPhone(currentText); + } + else if (element == "url") { + getPayloadInternal()->setURL(currentText); + } + else if (element == "date") { + getPayloadInternal()->setDate(currentText); + } + else if (element == "misc") { + getPayloadInternal()->setMisc(currentText); + } + else if (element == "text") { + getPayloadInternal()->setText(currentText); + } + else if (element == "key") { + getPayloadInternal()->setKey(currentText); + } + } } void InBandRegistrationPayloadParser::handleCharacterData(const std::string& data) { - if (formParser) { - formParser->handleCharacterData(data); - } - else { - currentText += data; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h index cd8c452..7e2a4a4 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h @@ -13,26 +13,26 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class SWIFTEN_API InBandRegistrationPayloadParser : public GenericPayloadParser<InBandRegistrationPayload> { - public: - InBandRegistrationPayloadParser(); - ~InBandRegistrationPayloadParser(); + class SWIFTEN_API InBandRegistrationPayloadParser : public GenericPayloadParser<InBandRegistrationPayload> { + public: + InBandRegistrationPayloadParser(); + ~InBandRegistrationPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level; - FormParserFactory* formParserFactory; - FormParser* formParser; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level; + FormParserFactory* formParserFactory; + FormParser* formParser; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp index 483654a..6bdd517 100644 --- a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp @@ -24,36 +24,36 @@ IsodeIQDelegationParser::~IsodeIQDelegationParser() { } void IsodeIQDelegationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level == 1) { - if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { - currentPayloadParser.reset(factory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void IsodeIQDelegationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->setForward(boost::dynamic_pointer_cast<Forwarded>(currentPayloadParser->getPayload())); - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setForward(boost::dynamic_pointer_cast<Forwarded>(currentPayloadParser->getPayload())); + currentPayloadParser.reset(); + } + } } void IsodeIQDelegationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h index 6115761..cf86a1a 100644 --- a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser<IsodeIQDelegation> { - public: - IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers); - virtual ~IsodeIQDelegationParser(); + class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser<IsodeIQDelegation> { + public: + IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers); + virtual ~IsodeIQDelegationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp index e6eecd7..30404f3 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp @@ -18,63 +18,63 @@ #include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { - JingleContentPayloadParser::JingleContentPayloadParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { - - } - - void JingleContentPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - std::string creator = attributes.getAttributeValue("creator").get_value_or(""); - if (creator == "initiator") { - getPayloadInternal()->setCreator(JingleContentPayload::InitiatorCreator); - } else if (creator == "responder") { - getPayloadInternal()->setCreator(JingleContentPayload::ResponderCreator); - } else { - getPayloadInternal()->setCreator(JingleContentPayload::UnknownCreator); - } - - getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); - } - - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - - ++level; - } - - void JingleContentPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - boost::shared_ptr<JingleTransportPayload> transport = boost::dynamic_pointer_cast<JingleTransportPayload>(currentPayloadParser->getPayload()); - if (transport) { - getPayloadInternal()->addTransport(transport); - } - - boost::shared_ptr<JingleDescription> description = boost::dynamic_pointer_cast<JingleDescription>(currentPayloadParser->getPayload()); - if (description) { - getPayloadInternal()->addDescription(description); - } - } - } - } - - void JingleContentPayloadParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } - } + JingleContentPayloadParser::JingleContentPayloadParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { + + } + + void JingleContentPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + std::string creator = attributes.getAttributeValue("creator").get_value_or(""); + if (creator == "initiator") { + getPayloadInternal()->setCreator(JingleContentPayload::InitiatorCreator); + } else if (creator == "responder") { + getPayloadInternal()->setCreator(JingleContentPayload::ResponderCreator); + } else { + getPayloadInternal()->setCreator(JingleContentPayload::UnknownCreator); + } + + getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); + } + + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + + ++level; + } + + void JingleContentPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + boost::shared_ptr<JingleTransportPayload> transport = boost::dynamic_pointer_cast<JingleTransportPayload>(currentPayloadParser->getPayload()); + if (transport) { + getPayloadInternal()->addTransport(transport); + } + + boost::shared_ptr<JingleDescription> description = boost::dynamic_pointer_cast<JingleDescription>(currentPayloadParser->getPayload()); + if (description) { + getPayloadInternal()->addDescription(description); + } + } + } + } + + void JingleContentPayloadParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } + } } diff --git a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h index 977d2eb..eaa8ff6 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h @@ -21,17 +21,17 @@ namespace Swift { class PayloadParserFactoryCollection; class SWIFTEN_API JingleContentPayloadParser : public GenericPayloadParser<JingleContentPayload> { - public: - JingleContentPayloadParser(PayloadParserFactoryCollection* factories); + public: + JingleContentPayloadParser(PayloadParserFactoryCollection* factories); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + private: + PayloadParserFactoryCollection* factories; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h index b343c24..8e9741d 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h @@ -17,26 +17,26 @@ #include <Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class SWIFTEN_API JingleContentPayloadParserFactory : public PayloadParserFactory { - public: - JingleContentPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "content" && ns == "urn:xmpp:jingle:1"; - } - - virtual PayloadParser* createPayloadParser() { - return new JingleContentPayloadParser(factories); - } - - private: - PayloadParserFactoryCollection* factories; - - }; + + class PayloadParserFactoryCollection; + + class SWIFTEN_API JingleContentPayloadParserFactory : public PayloadParserFactory { + public: + JingleContentPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "content" && ns == "urn:xmpp:jingle:1"; + } + + virtual PayloadParser* createPayloadParser() { + return new JingleContentPayloadParser(factories); + } + + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp index 0e4e636..32a6e4c 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp @@ -26,37 +26,37 @@ JingleFileTransferDescriptionParser::JingleFileTransferDescriptionParser(Payload } void JingleFileTransferDescriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void JingleFileTransferDescriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 0) { - boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); - if (info) { - getPayloadInternal()->setFileInfo(*info); - } - } + --level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 0) { + boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); + if (info) { + getPayloadInternal()->setFileInfo(*info); + } + } } void JingleFileTransferDescriptionParser::handleCharacterData(const std::string& data) { - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h index 52dd232..c7f80e1 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h @@ -22,17 +22,17 @@ namespace Swift { class PayloadParserFactoryCollection; class SWIFTEN_API JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFileTransferDescription> { - public: - JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories); + public: + JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + private: + PayloadParserFactoryCollection* factories; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h index f8a340c..c75125f 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h @@ -17,26 +17,26 @@ #include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class SWIFTEN_API JingleFileTransferDescriptionParserFactory : public PayloadParserFactory { - public: - JingleFileTransferDescriptionParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "description" && ns == "urn:xmpp:jingle:apps:file-transfer:4"; - } - - virtual PayloadParser* createPayloadParser() { - return new JingleFileTransferDescriptionParser(factories); - } - - private: - PayloadParserFactoryCollection* factories; - - }; + + class PayloadParserFactoryCollection; + + class SWIFTEN_API JingleFileTransferDescriptionParserFactory : public PayloadParserFactory { + public: + JingleFileTransferDescriptionParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "description" && ns == "urn:xmpp:jingle:apps:file-transfer:4"; + } + + virtual PayloadParser* createPayloadParser() { + return new JingleFileTransferDescriptionParser(factories); + } + + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp index 51c13e9..4f8b9a9 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp @@ -14,66 +14,66 @@ namespace Swift { -JingleFileTransferFileInfoParser::JingleFileTransferFileInfoParser() : level(0) { +JingleFileTransferFileInfoParser::JingleFileTransferFileInfoParser() : level(0) { } template<typename T> boost::optional<T> safeLexicalCast(const std::string& str) { - boost::optional<T> ret; - try { - ret = boost::lexical_cast<T>(str); - } catch (boost::bad_lexical_cast &) { + boost::optional<T> ret; + try { + ret = boost::lexical_cast<T>(str); + } catch (boost::bad_lexical_cast &) { - } - return ret; + } + return ret; } void JingleFileTransferFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - charData.clear(); - if (element == "hash") { - hashAlg = attributes.getAttributeValue("algo").get_value_or(""); - } - else if (element == "range") { - rangeOffset = safeLexicalCast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("")); - } + charData.clear(); + if (element == "hash") { + hashAlg = attributes.getAttributeValue("algo").get_value_or(""); + } + else if (element == "range") { + rangeOffset = safeLexicalCast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("")); + } - ++level; + ++level; } void JingleFileTransferFileInfoParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == 1) { - if (element == "date") { - getPayloadInternal()->setDate(stringToDateTime(charData)); - } - else if (element == "desc") { - getPayloadInternal()->setDescription(charData); - } - else if (element == "media-type") { - getPayloadInternal()->setMediaType(charData); - } - else if (element == "name") { - getPayloadInternal()->setName(charData); - } - else if (element == "size") { - boost::optional<boost::uintmax_t> size = safeLexicalCast<boost::uintmax_t>(charData); - if (size) { - getPayloadInternal()->setSize(size.get()); - } - } - else if (element == "range") { - getPayloadInternal()->setSupportsRangeRequests(true); - if (rangeOffset) { - getPayloadInternal()->setRangeOffset(rangeOffset.get_value_or(0)); - } - } - else if (element == "hash") { - getPayloadInternal()->addHash(HashElement(hashAlg, Base64::decode(charData))); - } - } + --level; + if (level == 1) { + if (element == "date") { + getPayloadInternal()->setDate(stringToDateTime(charData)); + } + else if (element == "desc") { + getPayloadInternal()->setDescription(charData); + } + else if (element == "media-type") { + getPayloadInternal()->setMediaType(charData); + } + else if (element == "name") { + getPayloadInternal()->setName(charData); + } + else if (element == "size") { + boost::optional<boost::uintmax_t> size = safeLexicalCast<boost::uintmax_t>(charData); + if (size) { + getPayloadInternal()->setSize(size.get()); + } + } + else if (element == "range") { + getPayloadInternal()->setSupportsRangeRequests(true); + if (rangeOffset) { + getPayloadInternal()->setRangeOffset(rangeOffset.get_value_or(0)); + } + } + else if (element == "hash") { + getPayloadInternal()->addHash(HashElement(hashAlg, Base64::decode(charData))); + } + } } void JingleFileTransferFileInfoParser::handleCharacterData(const std::string& data) { - charData += data; + charData += data; } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h index e49ee69..237f105 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h @@ -13,18 +13,18 @@ namespace Swift { class SWIFTEN_API JingleFileTransferFileInfoParser : public GenericPayloadParser<JingleFileTransferFileInfo> { - public: - JingleFileTransferFileInfoParser(); + public: + JingleFileTransferFileInfoParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - int level; - std::string charData; - std::string hashAlg; - boost::optional<boost::uintmax_t> rangeOffset; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level; + std::string charData; + std::string hashAlg; + boost::optional<boost::uintmax_t> rangeOffset; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp index 7c6c0d4..a890a99 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp @@ -23,36 +23,36 @@ namespace Swift { JingleFileTransferHashParser::JingleFileTransferHashParser() : level(0) { } - + void JingleFileTransferHashParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1 && element == "file") { - currentPayloadParser = boost::make_shared<JingleFileTransferFileInfoParser>(); - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1 && element == "file") { + currentPayloadParser = boost::make_shared<JingleFileTransferFileInfoParser>(); + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void JingleFileTransferHashParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); - if (info) { - getPayloadInternal()->setFileInfo(*info); - } - } + --level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); + if (info) { + getPayloadInternal()->setFileInfo(*info); + } + } } void JingleFileTransferHashParser::handleCharacterData(const std::string& data) { - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h index 15d3294..8a28d5a 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h @@ -20,15 +20,15 @@ namespace Swift { class SWIFTEN_API JingleFileTransferHashParser : public GenericPayloadParser<JingleFileTransferHash> { public: - JingleFileTransferHashParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - + JingleFileTransferHashParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + private: - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp index e446575..438420b 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp @@ -18,30 +18,30 @@ #include <Swiften/Base/Log.h> namespace Swift { - JingleIBBTransportMethodPayloadParser::JingleIBBTransportMethodPayloadParser() : level(0) { - - } - - void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - try { - boost::optional<std::string> blockSize = attributes.getAttributeValue("block-size"); - if (blockSize) { - getPayloadInternal()->setBlockSize(boost::lexical_cast<unsigned int>(*blockSize)); - } - } - catch (boost::bad_lexical_cast &) { - } - getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); - ++level; - } - - void JingleIBBTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { - --level; - - - } - - void JingleIBBTransportMethodPayloadParser::handleCharacterData(const std::string&) { - - } + JingleIBBTransportMethodPayloadParser::JingleIBBTransportMethodPayloadParser() : level(0) { + + } + + void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + try { + boost::optional<std::string> blockSize = attributes.getAttributeValue("block-size"); + if (blockSize) { + getPayloadInternal()->setBlockSize(boost::lexical_cast<unsigned int>(*blockSize)); + } + } + catch (boost::bad_lexical_cast &) { + } + getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); + ++level; + } + + void JingleIBBTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { + --level; + + + } + + void JingleIBBTransportMethodPayloadParser::handleCharacterData(const std::string&) { + + } } diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h index 4e22943..e406b9f 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h @@ -19,15 +19,15 @@ namespace Swift { class SWIFTEN_API JingleIBBTransportMethodPayloadParser : public GenericPayloadParser<JingleIBBTransportPayload> { - public: - JingleIBBTransportMethodPayloadParser(); + public: + JingleIBBTransportMethodPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level; + private: + int level; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleParser.cpp b/Swiften/Parser/PayloadParsers/JingleParser.cpp index 21f415b..48507af 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleParser.cpp @@ -21,100 +21,100 @@ namespace Swift { - JingleParser::JingleParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { - - } - - void JingleParser::handleStartElement(const std::string& element, const std::string &ns, const AttributeMap& attributes) { - if (level == 0) { - // <jingle > tag - JinglePayload::ref payload = getPayloadInternal(); - payload->setAction(stringToAction(attributes.getAttributeValue("action").get_value_or(""))); - payload->setInitiator(JID(attributes.getAttributeValue("initiator").get_value_or(""))); - payload->setResponder(JID(attributes.getAttributeValue("responder").get_value_or(""))); - payload->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); - } - - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - - ++level; - } - - void JingleParser::handleEndElement(const std::string& element, const std::string &ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - boost::shared_ptr<JinglePayload::Reason> reason = boost::dynamic_pointer_cast<JinglePayload::Reason>(currentPayloadParser->getPayload()); - if (reason) { - getPayloadInternal()->setReason(*reason); - } - - boost::shared_ptr<JingleContentPayload> payload = boost::dynamic_pointer_cast<JingleContentPayload>(currentPayloadParser->getPayload()); - if (payload) { - getPayloadInternal()->addContent(payload); - } - - boost::shared_ptr<JingleFileTransferHash> hash = boost::dynamic_pointer_cast<JingleFileTransferHash>(currentPayloadParser->getPayload()); - if (hash) { - getPayloadInternal()->addPayload(hash); - } - } - } - } - - void JingleParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } - } - - JinglePayload::Action JingleParser::stringToAction(const std::string &str) const { - if (str == "content-accept") { - return JinglePayload::ContentAccept; - } else if (str == "content-add") { - return JinglePayload::ContentAdd; - } else if (str == "content-modify") { - return JinglePayload::ContentModify; - } else if (str == "content-reject") { - return JinglePayload::ContentReject; - } else if (str == "content-remove") { - return JinglePayload::ContentRemove; - } else if (str == "description-info") { - return JinglePayload::DescriptionInfo; - } else if (str == "security-info") { - return JinglePayload::SecurityInfo; - } else if (str == "session-accept") { - return JinglePayload::SessionAccept; - } else if (str == "session-info") { - return JinglePayload::SessionInfo; - } else if (str == "session-initiate") { - return JinglePayload::SessionInitiate; - } else if (str == "session-terminate") { - return JinglePayload::SessionTerminate; - } else if (str == "transport-accept") { - return JinglePayload::TransportAccept; - } else if (str == "transport-info") { - return JinglePayload::TransportInfo; - } else if (str == "transport-reject") { - return JinglePayload::TransportReject; - } else if (str == "transport-replace") { - return JinglePayload::TransportReplace; - } else { - return JinglePayload::UnknownAction; - } - - } + JingleParser::JingleParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { + + } + + void JingleParser::handleStartElement(const std::string& element, const std::string &ns, const AttributeMap& attributes) { + if (level == 0) { + // <jingle > tag + JinglePayload::ref payload = getPayloadInternal(); + payload->setAction(stringToAction(attributes.getAttributeValue("action").get_value_or(""))); + payload->setInitiator(JID(attributes.getAttributeValue("initiator").get_value_or(""))); + payload->setResponder(JID(attributes.getAttributeValue("responder").get_value_or(""))); + payload->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); + } + + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + + ++level; + } + + void JingleParser::handleEndElement(const std::string& element, const std::string &ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + boost::shared_ptr<JinglePayload::Reason> reason = boost::dynamic_pointer_cast<JinglePayload::Reason>(currentPayloadParser->getPayload()); + if (reason) { + getPayloadInternal()->setReason(*reason); + } + + boost::shared_ptr<JingleContentPayload> payload = boost::dynamic_pointer_cast<JingleContentPayload>(currentPayloadParser->getPayload()); + if (payload) { + getPayloadInternal()->addContent(payload); + } + + boost::shared_ptr<JingleFileTransferHash> hash = boost::dynamic_pointer_cast<JingleFileTransferHash>(currentPayloadParser->getPayload()); + if (hash) { + getPayloadInternal()->addPayload(hash); + } + } + } + } + + void JingleParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } + } + + JinglePayload::Action JingleParser::stringToAction(const std::string &str) const { + if (str == "content-accept") { + return JinglePayload::ContentAccept; + } else if (str == "content-add") { + return JinglePayload::ContentAdd; + } else if (str == "content-modify") { + return JinglePayload::ContentModify; + } else if (str == "content-reject") { + return JinglePayload::ContentReject; + } else if (str == "content-remove") { + return JinglePayload::ContentRemove; + } else if (str == "description-info") { + return JinglePayload::DescriptionInfo; + } else if (str == "security-info") { + return JinglePayload::SecurityInfo; + } else if (str == "session-accept") { + return JinglePayload::SessionAccept; + } else if (str == "session-info") { + return JinglePayload::SessionInfo; + } else if (str == "session-initiate") { + return JinglePayload::SessionInitiate; + } else if (str == "session-terminate") { + return JinglePayload::SessionTerminate; + } else if (str == "transport-accept") { + return JinglePayload::TransportAccept; + } else if (str == "transport-info") { + return JinglePayload::TransportInfo; + } else if (str == "transport-reject") { + return JinglePayload::TransportReject; + } else if (str == "transport-replace") { + return JinglePayload::TransportReplace; + } else { + return JinglePayload::UnknownAction; + } + + } } diff --git a/Swiften/Parser/PayloadParsers/JingleParser.h b/Swiften/Parser/PayloadParsers/JingleParser.h index ad49e96..28850e2 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.h +++ b/Swiften/Parser/PayloadParsers/JingleParser.h @@ -20,20 +20,20 @@ namespace Swift { class SWIFTEN_API JingleParser : public GenericPayloadParser<JinglePayload> { - public: - JingleParser(PayloadParserFactoryCollection* factories); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - JinglePayload::Action stringToAction(const std::string &str) const; - - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + public: + JingleParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + JinglePayload::Action stringToAction(const std::string &str) const; + + private: + PayloadParserFactoryCollection* factories; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleParserFactory.h b/Swiften/Parser/PayloadParsers/JingleParserFactory.h index 73395fc..5f9b45b 100644 --- a/Swiften/Parser/PayloadParsers/JingleParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleParserFactory.h @@ -17,26 +17,26 @@ #include <Swiften/Parser/PayloadParsers/JingleParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class SWIFTEN_API JingleParserFactory : public PayloadParserFactory { - public: - JingleParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "jingle" && ns == "urn:xmpp:jingle:1"; - } - - virtual PayloadParser* createPayloadParser() { - return new JingleParser(factories); - } - - private: - PayloadParserFactoryCollection* factories; - - }; + + class PayloadParserFactoryCollection; + + class SWIFTEN_API JingleParserFactory : public PayloadParserFactory { + public: + JingleParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "jingle" && ns == "urn:xmpp:jingle:1"; + } + + virtual PayloadParser* createPayloadParser() { + return new JingleParser(factories); + } + + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp b/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp index d144cbd..9a81e5f 100644 --- a/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp @@ -15,73 +15,73 @@ #include <Swiften/Base/Log.h> namespace Swift { - JingleReasonParser::JingleReasonParser() : level(0), parseText(false) { - - } - - void JingleReasonParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (level == 1) { - if (element == "text") { - parseText = true; - } else { - // reason type - getPayloadInternal()->type = stringToReasonType(element); - } - } - ++level; - } - - void JingleReasonParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (element == "text") { - parseText = false; - getPayloadInternal()->text = text; - } - } - - void JingleReasonParser::handleCharacterData(const std::string& data) { - if (parseText) { - text += data; - } - } - - JinglePayload::Reason::Type JingleReasonParser::stringToReasonType(const std::string& type) const { - if (type == "alternative-session") { - return JinglePayload::Reason::AlternativeSession; - } else if (type == "busy") { - return JinglePayload::Reason::Busy; - } else if (type == "cancel") { - return JinglePayload::Reason::Cancel; - } else if (type == "connectivity-error") { - return JinglePayload::Reason::ConnectivityError; - } else if (type == "decline") { - return JinglePayload::Reason::Decline; - } else if (type == "expired") { - return JinglePayload::Reason::Expired; - } else if (type == "failed-application") { - return JinglePayload::Reason::FailedApplication; - } else if (type == "failed-transport") { - return JinglePayload::Reason::FailedTransport; - } else if (type == "general-error") { - return JinglePayload::Reason::GeneralError; - } else if (type == "gone") { - return JinglePayload::Reason::Gone; - } else if (type == "incompatible-parameters") { - return JinglePayload::Reason::IncompatibleParameters; - } else if (type == "media-error") { - return JinglePayload::Reason::MediaError; - } else if (type == "security-error") { - return JinglePayload::Reason::SecurityError; - } else if (type == "success") { - return JinglePayload::Reason::Success; - } else if (type == "timeout") { - return JinglePayload::Reason::Timeout; - } else if (type == "unsupported-applications") { - return JinglePayload::Reason::UnsupportedApplications; - } else if (type == "unsupported-transports") { - return JinglePayload::Reason::UnsupportedTransports; - } else { - return JinglePayload::Reason::UnknownType; - } - } + JingleReasonParser::JingleReasonParser() : level(0), parseText(false) { + + } + + void JingleReasonParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { + if (level == 1) { + if (element == "text") { + parseText = true; + } else { + // reason type + getPayloadInternal()->type = stringToReasonType(element); + } + } + ++level; + } + + void JingleReasonParser::handleEndElement(const std::string& element, const std::string&) { + --level; + if (element == "text") { + parseText = false; + getPayloadInternal()->text = text; + } + } + + void JingleReasonParser::handleCharacterData(const std::string& data) { + if (parseText) { + text += data; + } + } + + JinglePayload::Reason::Type JingleReasonParser::stringToReasonType(const std::string& type) const { + if (type == "alternative-session") { + return JinglePayload::Reason::AlternativeSession; + } else if (type == "busy") { + return JinglePayload::Reason::Busy; + } else if (type == "cancel") { + return JinglePayload::Reason::Cancel; + } else if (type == "connectivity-error") { + return JinglePayload::Reason::ConnectivityError; + } else if (type == "decline") { + return JinglePayload::Reason::Decline; + } else if (type == "expired") { + return JinglePayload::Reason::Expired; + } else if (type == "failed-application") { + return JinglePayload::Reason::FailedApplication; + } else if (type == "failed-transport") { + return JinglePayload::Reason::FailedTransport; + } else if (type == "general-error") { + return JinglePayload::Reason::GeneralError; + } else if (type == "gone") { + return JinglePayload::Reason::Gone; + } else if (type == "incompatible-parameters") { + return JinglePayload::Reason::IncompatibleParameters; + } else if (type == "media-error") { + return JinglePayload::Reason::MediaError; + } else if (type == "security-error") { + return JinglePayload::Reason::SecurityError; + } else if (type == "success") { + return JinglePayload::Reason::Success; + } else if (type == "timeout") { + return JinglePayload::Reason::Timeout; + } else if (type == "unsupported-applications") { + return JinglePayload::Reason::UnsupportedApplications; + } else if (type == "unsupported-transports") { + return JinglePayload::Reason::UnsupportedTransports; + } else { + return JinglePayload::Reason::UnknownType; + } + } } diff --git a/Swiften/Parser/PayloadParsers/JingleReasonParser.h b/Swiften/Parser/PayloadParsers/JingleReasonParser.h index 4fe334e..a445448 100644 --- a/Swiften/Parser/PayloadParsers/JingleReasonParser.h +++ b/Swiften/Parser/PayloadParsers/JingleReasonParser.h @@ -19,19 +19,19 @@ namespace Swift { class SWIFTEN_API JingleReasonParser : public GenericPayloadParser<JinglePayload::Reason> { - public: - JingleReasonParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - private: - JinglePayload::Reason::Type stringToReasonType(const std::string& type) const; - - private: - int level; - bool parseText; - std::string text; + public: + JingleReasonParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + private: + JinglePayload::Reason::Type stringToReasonType(const std::string& type) const; + + private: + int level; + bool parseText; + std::string text; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp index 4a7e6c1..859dcec 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp @@ -18,78 +18,78 @@ #include <Swiften/Base/Log.h> namespace Swift { - JingleS5BTransportMethodPayloadParser::JingleS5BTransportMethodPayloadParser() : level(0) { - - } - - void JingleS5BTransportMethodPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 0) { - getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); - std::string mode = attributes.getAttributeValue("mode").get_value_or("tcp"); - if (mode == "tcp") { - getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); - } else if(mode == "udp") { - getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); - } else { - SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; - getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); - } - getPayloadInternal()->setDstAddr(attributes.getAttributeValue("dstaddr").get_value_or("")); - } else if (level == 1) { - if (element == "candidate") { - JingleS5BTransportPayload::Candidate candidate; - candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); - - int port = -1; - try { - port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); - } catch(boost::bad_lexical_cast &) { } - candidate.hostPort = HostAddressPort(HostAddress(attributes.getAttributeValue("host").get_value_or("")), port); - candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); - int priority = -1; - try { - priority = boost::lexical_cast<int>(attributes.getAttributeValue("priority").get_value_or("-1")); - } catch(boost::bad_lexical_cast &) { } - candidate.priority = priority; - candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or("direct")); - - getPayloadInternal()->addCandidate(candidate); - } else if (element == "candidate-used") { - getPayloadInternal()->setCandidateUsed(attributes.getAttributeValue("cid").get_value_or("")); - } else if (element == "candidate-error") { - getPayloadInternal()->setCandidateError(true); - } else if (element == "activated") { - getPayloadInternal()->setActivated(attributes.getAttributeValue("cid").get_value_or("")); - } else if (element == "proxy-error") { - getPayloadInternal()->setProxyError(true); - } - } - - ++level; - } - - void JingleS5BTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { - --level; - - - } - - void JingleS5BTransportMethodPayloadParser::handleCharacterData(const std::string&) { - - } - - JingleS5BTransportPayload::Candidate::Type JingleS5BTransportMethodPayloadParser::stringToType(const std::string &str) const { - if (str == "direct") { - return JingleS5BTransportPayload::Candidate::DirectType; - } else if (str == "assisted") { - return JingleS5BTransportPayload::Candidate::AssistedType; - } else if (str == "tunnel") { - return JingleS5BTransportPayload::Candidate::TunnelType; - } else if (str == "proxy") { - return JingleS5BTransportPayload::Candidate::ProxyType; - } else { - SWIFT_LOG(warning) << "Unknown candidate type; falling back to default!"; - return JingleS5BTransportPayload::Candidate::DirectType; - } - } + JingleS5BTransportMethodPayloadParser::JingleS5BTransportMethodPayloadParser() : level(0) { + + } + + void JingleS5BTransportMethodPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 0) { + getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); + std::string mode = attributes.getAttributeValue("mode").get_value_or("tcp"); + if (mode == "tcp") { + getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); + } else if(mode == "udp") { + getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); + } else { + SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; + getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); + } + getPayloadInternal()->setDstAddr(attributes.getAttributeValue("dstaddr").get_value_or("")); + } else if (level == 1) { + if (element == "candidate") { + JingleS5BTransportPayload::Candidate candidate; + candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); + + int port = -1; + try { + port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); + } catch(boost::bad_lexical_cast &) { } + candidate.hostPort = HostAddressPort(HostAddress(attributes.getAttributeValue("host").get_value_or("")), port); + candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); + int priority = -1; + try { + priority = boost::lexical_cast<int>(attributes.getAttributeValue("priority").get_value_or("-1")); + } catch(boost::bad_lexical_cast &) { } + candidate.priority = priority; + candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or("direct")); + + getPayloadInternal()->addCandidate(candidate); + } else if (element == "candidate-used") { + getPayloadInternal()->setCandidateUsed(attributes.getAttributeValue("cid").get_value_or("")); + } else if (element == "candidate-error") { + getPayloadInternal()->setCandidateError(true); + } else if (element == "activated") { + getPayloadInternal()->setActivated(attributes.getAttributeValue("cid").get_value_or("")); + } else if (element == "proxy-error") { + getPayloadInternal()->setProxyError(true); + } + } + + ++level; + } + + void JingleS5BTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { + --level; + + + } + + void JingleS5BTransportMethodPayloadParser::handleCharacterData(const std::string&) { + + } + + JingleS5BTransportPayload::Candidate::Type JingleS5BTransportMethodPayloadParser::stringToType(const std::string &str) const { + if (str == "direct") { + return JingleS5BTransportPayload::Candidate::DirectType; + } else if (str == "assisted") { + return JingleS5BTransportPayload::Candidate::AssistedType; + } else if (str == "tunnel") { + return JingleS5BTransportPayload::Candidate::TunnelType; + } else if (str == "proxy") { + return JingleS5BTransportPayload::Candidate::ProxyType; + } else { + SWIFT_LOG(warning) << "Unknown candidate type; falling back to default!"; + return JingleS5BTransportPayload::Candidate::DirectType; + } + } } diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h index ccf0b1b..f48c4b5 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h @@ -19,18 +19,18 @@ namespace Swift { class SWIFTEN_API JingleS5BTransportMethodPayloadParser : public GenericPayloadParser<JingleS5BTransportPayload> { - public: - JingleS5BTransportMethodPayloadParser(); + public: + JingleS5BTransportMethodPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - JingleS5BTransportPayload::Candidate::Type stringToType(const std::string &str) const; + private: + JingleS5BTransportPayload::Candidate::Type stringToType(const std::string &str) const; - private: - int level; + private: + int level; }; } diff --git a/Swiften/Parser/PayloadParsers/LastParser.cpp b/Swiften/Parser/PayloadParsers/LastParser.cpp index 896a554..89d39ac 100644 --- a/Swiften/Parser/PayloadParsers/LastParser.cpp +++ b/Swiften/Parser/PayloadParsers/LastParser.cpp @@ -14,16 +14,16 @@ LastParser::LastParser() : level_(0) { } void LastParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level_ == 0) { - int seconds = 0; - try { - seconds = boost::lexical_cast<int>(attributes.getAttribute("seconds")); - } - catch (boost::bad_lexical_cast&) { - } - getPayloadInternal()->setSeconds(seconds); - } - ++level_; + if (level_ == 0) { + int seconds = 0; + try { + seconds = boost::lexical_cast<int>(attributes.getAttribute("seconds")); + } + catch (boost::bad_lexical_cast&) { + } + getPayloadInternal()->setSeconds(seconds); + } + ++level_; } diff --git a/Swiften/Parser/PayloadParsers/LastParser.h b/Swiften/Parser/PayloadParsers/LastParser.h index 58cde22..70bfdcb 100644 --- a/Swiften/Parser/PayloadParsers/LastParser.h +++ b/Swiften/Parser/PayloadParsers/LastParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API LastParser : public GenericPayloadParser<Last> { - public: - LastParser(); + class SWIFTEN_API LastParser : public GenericPayloadParser<Last> { + public: + LastParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.cpp b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp index e972381..a29a7c4 100644 --- a/Swiften/Parser/PayloadParsers/MAMFinParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp @@ -20,42 +20,42 @@ MAMFinParser::MAMFinParser() : level_(TopLevel) { } void MAMFinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false)); - getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true)); - boost::optional<std::string> attributeValue; - if ((attributeValue = attributes.getAttributeValue("queryid"))) { - getPayloadInternal()->setQueryID(*attributeValue); - } - } - else if (level_ == PayloadLevel) { - if (element == "set" && ns == "http://jabber.org/protocol/rsm") { - resultSetParser_ = boost::make_shared<ResultSetParser>(); - } - } - - if (resultSetParser_) { /* parsing a nested ResultSet */ - resultSetParser_->handleStartElement(element, ns, attributes); - } - - ++level_; + if (level_ == TopLevel) { + getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false)); + getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true)); + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } + else if (level_ == PayloadLevel) { + if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = boost::make_shared<ResultSetParser>(); + } + } + + if (resultSetParser_) { /* parsing a nested ResultSet */ + resultSetParser_->handleStartElement(element, ns, attributes); + } + + ++level_; } void MAMFinParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - - if (resultSetParser_ && level_ >= PayloadLevel) { - resultSetParser_->handleEndElement(element, ns); - } - if (resultSetParser_ && level_ == PayloadLevel) { - /* done parsing nested ResultSet */ - getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); - resultSetParser_.reset(); - } + --level_; + + if (resultSetParser_ && level_ >= PayloadLevel) { + resultSetParser_->handleEndElement(element, ns); + } + if (resultSetParser_ && level_ == PayloadLevel) { + /* done parsing nested ResultSet */ + getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } } void MAMFinParser::handleCharacterData(const std::string& data) { - if (resultSetParser_) { - resultSetParser_->handleCharacterData(data); - } + if (resultSetParser_) { + resultSetParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.h b/Swiften/Parser/PayloadParsers/MAMFinParser.h index 6f2d942..2e805ad 100644 --- a/Swiften/Parser/PayloadParsers/MAMFinParser.h +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.h @@ -14,23 +14,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class ResultSetParser; + class ResultSetParser; - class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> { - public: - MAMFinParser(); + class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> { + public: + MAMFinParser(); - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - boost::shared_ptr<ResultSetParser> resultSetParser_; - int level_; - }; + private: + boost::shared_ptr<ResultSetParser> resultSetParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp index 3be997b..41fbbb7 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp @@ -19,60 +19,60 @@ MAMQueryParser::MAMQueryParser() : level_(TopLevel) { } void MAMQueryParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - boost::optional<std::string> attributeValue; - if ((attributeValue = attributes.getAttributeValue("queryid"))) { - getPayloadInternal()->setQueryID(*attributeValue); - } - if ((attributeValue = attributes.getAttributeValue("node"))) { - getPayloadInternal()->setNode(*attributeValue); - } - } else if (level_ == PayloadLevel) { - if (element == "x" && ns == "jabber:x:data") { - formParser_ = boost::make_shared<FormParser>(); - } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { - resultSetParser_ = boost::make_shared<ResultSetParser>(); - } - } + if (level_ == TopLevel) { + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + if ((attributeValue = attributes.getAttributeValue("node"))) { + getPayloadInternal()->setNode(*attributeValue); + } + } else if (level_ == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + formParser_ = boost::make_shared<FormParser>(); + } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = boost::make_shared<ResultSetParser>(); + } + } - if (formParser_) { /* parsing a nested Form */ - formParser_->handleStartElement(element, ns, attributes); - } + if (formParser_) { /* parsing a nested Form */ + formParser_->handleStartElement(element, ns, attributes); + } - if (resultSetParser_) { /* parsing a nested ResultSet */ - resultSetParser_->handleStartElement(element, ns, attributes); - } + if (resultSetParser_) { /* parsing a nested ResultSet */ + resultSetParser_->handleStartElement(element, ns, attributes); + } - ++level_; + ++level_; } void MAMQueryParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; + --level_; - if (formParser_ && level_ >= PayloadLevel) { - formParser_->handleEndElement(element, ns); - } - if (formParser_ && level_ == PayloadLevel) { - /* done parsing nested Form */ - getPayloadInternal()->setForm(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); - formParser_.reset(); - } + if (formParser_ && level_ >= PayloadLevel) { + formParser_->handleEndElement(element, ns); + } + if (formParser_ && level_ == PayloadLevel) { + /* done parsing nested Form */ + getPayloadInternal()->setForm(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); + formParser_.reset(); + } - if (resultSetParser_ && level_ >= PayloadLevel) { - resultSetParser_->handleEndElement(element, ns); - } - if (resultSetParser_ && level_ == PayloadLevel) { - /* done parsing nested ResultSet */ - getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); - resultSetParser_.reset(); - } + if (resultSetParser_ && level_ >= PayloadLevel) { + resultSetParser_->handleEndElement(element, ns); + } + if (resultSetParser_ && level_ == PayloadLevel) { + /* done parsing nested ResultSet */ + getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } } void MAMQueryParser::handleCharacterData(const std::string& data) { - if (formParser_) { - formParser_->handleCharacterData(data); - } - if (resultSetParser_) { - resultSetParser_->handleCharacterData(data); - } + if (formParser_) { + formParser_->handleCharacterData(data); + } + if (resultSetParser_) { + resultSetParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.h b/Swiften/Parser/PayloadParsers/MAMQueryParser.h index 119f956..4f5bd47 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.h +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.h @@ -16,25 +16,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class ResultSetParser; - class FormParser; - - class SWIFTEN_API MAMQueryParser : public GenericPayloadParser<MAMQuery> { - public: - MAMQueryParser(); - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - - private: - boost::shared_ptr<FormParser> formParser_; - boost::shared_ptr<ResultSetParser> resultSetParser_; - int level_; - }; + class ResultSetParser; + class FormParser; + + class SWIFTEN_API MAMQueryParser : public GenericPayloadParser<MAMQuery> { + public: + MAMQueryParser(); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + boost::shared_ptr<FormParser> formParser_; + boost::shared_ptr<ResultSetParser> resultSetParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp index ac32100..e39ed94 100644 --- a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp @@ -18,42 +18,42 @@ MAMResultParser::MAMResultParser(PayloadParserFactoryCollection* factories) : fa } void MAMResultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - boost::optional<std::string> attributeValue; - if ((attributeValue = attributes.getAttributeValue("id"))) { - getPayloadInternal()->setID(*attributeValue); - } - if ((attributeValue = attributes.getAttributeValue("queryid"))) { - getPayloadInternal()->setQueryID(*attributeValue); - } - } else if (level_ == PayloadLevel) { - if (element == "forwarded" && ns == "urn:xmpp:forward:0") { - payloadParser_ = boost::make_shared<ForwardedParser>(factories_); - } - } - - if (payloadParser_) { - /* parsing a nested payload */ - payloadParser_->handleStartElement(element, ns, attributes); - } - - ++level_; + if (level_ == TopLevel) { + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("id"))) { + getPayloadInternal()->setID(*attributeValue); + } + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } else if (level_ == PayloadLevel) { + if (element == "forwarded" && ns == "urn:xmpp:forward:0") { + payloadParser_ = boost::make_shared<ForwardedParser>(factories_); + } + } + + if (payloadParser_) { + /* parsing a nested payload */ + payloadParser_->handleStartElement(element, ns, attributes); + } + + ++level_; } void MAMResultParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (payloadParser_ && level_ >= PayloadLevel) { - payloadParser_->handleEndElement(element, ns); - } - if (payloadParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); - payloadParser_.reset(); - } + --level_; + if (payloadParser_ && level_ >= PayloadLevel) { + payloadParser_->handleEndElement(element, ns); + } + if (payloadParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); + payloadParser_.reset(); + } } void MAMResultParser::handleCharacterData(const std::string& data) { - if (payloadParser_) { - payloadParser_->handleCharacterData(data); - } + if (payloadParser_) { + payloadParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.h b/Swiften/Parser/PayloadParsers/MAMResultParser.h index e1b0b8e..5177f8b 100644 --- a/Swiften/Parser/PayloadParsers/MAMResultParser.h +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.h @@ -16,25 +16,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class ForwardedParser; - - class SWIFTEN_API MAMResultParser : public GenericPayloadParser<MAMResult> { - public: - MAMResultParser(PayloadParserFactoryCollection* factories); - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - - private: - boost::shared_ptr<ForwardedParser> payloadParser_; - PayloadParserFactoryCollection* factories_; - int level_; - }; + class PayloadParserFactoryCollection; + class ForwardedParser; + + class SWIFTEN_API MAMResultParser : public GenericPayloadParser<MAMResult> { + public: + MAMResultParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + boost::shared_ptr<ForwardedParser> payloadParser_; + PayloadParserFactoryCollection* factories_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp index 717fc60..1fbff1c 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp @@ -14,10 +14,10 @@ namespace Swift { void MUCAdminPayloadParser::handleTree(ParserElement::ref root) { - foreach (ParserElement::ref itemElement, root->getChildren("item", "http://jabber.org/protocol/muc#admin")) { - MUCItem item = MUCItemParser::itemFromTree(itemElement); - getPayloadInternal()->addItem(item); - } + foreach (ParserElement::ref itemElement, root->getChildren("item", "http://jabber.org/protocol/muc#admin")) { + MUCItem item = MUCItemParser::itemFromTree(itemElement); + getPayloadInternal()->addItem(item); + } } } diff --git a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h index 9174c7d..de46690 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h @@ -14,8 +14,8 @@ #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class SWIFTEN_API MUCAdminPayloadParser : public GenericPayloadTreeParser<MUCAdminPayload> { - public: - virtual void handleTree(ParserElement::ref root); - }; + class SWIFTEN_API MUCAdminPayloadParser : public GenericPayloadTreeParser<MUCAdminPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp index b70c1d4..95ff8c5 100644 --- a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp @@ -11,12 +11,12 @@ namespace Swift { void MUCDestroyPayloadParser::handleTree(ParserElement::ref root) { - std::string ns = root->getNamespace(); - std::string jid = root->getAttributes().getAttribute("jid"); - if (!jid.empty()) { - getPayloadInternal()->setNewVenue(JID(jid)); - } - getPayloadInternal()->setReason(root->getChild("reason", ns)->getText()); + std::string ns = root->getNamespace(); + std::string jid = root->getAttributes().getAttribute("jid"); + if (!jid.empty()) { + getPayloadInternal()->setNewVenue(JID(jid)); + } + getPayloadInternal()->setReason(root->getChild("reason", ns)->getText()); } } diff --git a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h index 1e5d545..e79d9a6 100644 --- a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h @@ -13,8 +13,8 @@ #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class SWIFTEN_API MUCDestroyPayloadParser : public GenericPayloadTreeParser<MUCDestroyPayload> { - public: - virtual void handleTree(ParserElement::ref root); - }; + class SWIFTEN_API MUCDestroyPayloadParser : public GenericPayloadTreeParser<MUCDestroyPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp index 376353d..20e5f2b 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp @@ -11,14 +11,14 @@ namespace Swift { void MUCInvitationPayloadParser::handleTree(ParserElement::ref root) { - MUCInvitationPayload::ref invite = getPayloadInternal(); - invite->setIsContinuation(root->getAttributes().getBoolAttribute("continue", false)); - invite->setJID(JID(root->getAttributes().getAttribute("jid"))); - invite->setPassword(root->getAttributes().getAttribute("password")); - invite->setReason(root->getAttributes().getAttribute("reason")); - invite->setThread(root->getAttributes().getAttribute("thread")); - ParserElement::ref impromptuNode = root->getChild("impromptu", "http://swift.im/impromptu"); - invite->setIsImpromptu(!boost::dynamic_pointer_cast<NullParserElement>(impromptuNode)); + MUCInvitationPayload::ref invite = getPayloadInternal(); + invite->setIsContinuation(root->getAttributes().getBoolAttribute("continue", false)); + invite->setJID(JID(root->getAttributes().getAttribute("jid"))); + invite->setPassword(root->getAttributes().getAttribute("password")); + invite->setReason(root->getAttributes().getAttribute("reason")); + invite->setThread(root->getAttributes().getAttribute("thread")); + ParserElement::ref impromptuNode = root->getChild("impromptu", "http://swift.im/impromptu"); + invite->setIsImpromptu(!boost::dynamic_pointer_cast<NullParserElement>(impromptuNode)); } } diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h index f79c971..7b76166 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class SWIFTEN_API MUCInvitationPayloadParser : public GenericPayloadTreeParser<MUCInvitationPayload> { - public: - virtual void handleTree(ParserElement::ref root); - }; + class SWIFTEN_API MUCInvitationPayloadParser : public GenericPayloadTreeParser<MUCInvitationPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCItemParser.cpp b/Swiften/Parser/PayloadParsers/MUCItemParser.cpp index 332df11..0486cb4 100644 --- a/Swiften/Parser/PayloadParsers/MUCItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCItemParser.cpp @@ -16,65 +16,65 @@ namespace Swift { MUCItem MUCItemParser::itemFromTree(ParserElement::ref root) { - MUCItem item; - std::string affiliation = root->getAttributes().getAttribute("affiliation"); - std::string role = root->getAttributes().getAttribute("role"); - std::string nick = root->getAttributes().getAttribute("nick"); - std::string jid = root->getAttributes().getAttribute("jid"); - item.affiliation = parseAffiliation(affiliation); - item.role = parseRole(role); - if (!jid.empty()) { - item.realJID = JID(jid); - } - if (!nick.empty()) { - item.nick = nick; - } - std::string xmlns = root->getNamespace(); - std::string reason = root->getChild("reason", xmlns)->getText(); - std::string actor = root->getChild("actor", xmlns)->getAttributes().getAttribute("jid"); - if (!reason.empty()) { - item.reason = reason; - } - if (!actor.empty()) { - item.actor = JID(actor); - } + MUCItem item; + std::string affiliation = root->getAttributes().getAttribute("affiliation"); + std::string role = root->getAttributes().getAttribute("role"); + std::string nick = root->getAttributes().getAttribute("nick"); + std::string jid = root->getAttributes().getAttribute("jid"); + item.affiliation = parseAffiliation(affiliation); + item.role = parseRole(role); + if (!jid.empty()) { + item.realJID = JID(jid); + } + if (!nick.empty()) { + item.nick = nick; + } + std::string xmlns = root->getNamespace(); + std::string reason = root->getChild("reason", xmlns)->getText(); + std::string actor = root->getChild("actor", xmlns)->getAttributes().getAttribute("jid"); + if (!reason.empty()) { + item.reason = reason; + } + if (!actor.empty()) { + item.actor = JID(actor); + } - return item; + return item; } boost::optional<MUCOccupant::Role> MUCItemParser::parseRole(const std::string& roleString) { - if (roleString == "moderator") { - return MUCOccupant::Moderator; - } - if (roleString == "participant") { - return MUCOccupant::Participant; - } - if (roleString == "visitor") { - return MUCOccupant::Visitor; - } - if (roleString == "none") { - return MUCOccupant::NoRole; - } - return boost::optional<MUCOccupant::Role>(); + if (roleString == "moderator") { + return MUCOccupant::Moderator; + } + if (roleString == "participant") { + return MUCOccupant::Participant; + } + if (roleString == "visitor") { + return MUCOccupant::Visitor; + } + if (roleString == "none") { + return MUCOccupant::NoRole; + } + return boost::optional<MUCOccupant::Role>(); } boost::optional<MUCOccupant::Affiliation> MUCItemParser::parseAffiliation(const std::string& affiliationString) { - if (affiliationString == "owner") { - return MUCOccupant::Owner; - } - if (affiliationString == "admin") { - return MUCOccupant::Admin; - } - if (affiliationString == "member") { - return MUCOccupant::Member; - } - if (affiliationString == "outcast") { - return MUCOccupant::Outcast; - } - if (affiliationString == "none") { - return MUCOccupant::NoAffiliation; - } - return boost::optional<MUCOccupant::Affiliation>(); + if (affiliationString == "owner") { + return MUCOccupant::Owner; + } + if (affiliationString == "admin") { + return MUCOccupant::Admin; + } + if (affiliationString == "member") { + return MUCOccupant::Member; + } + if (affiliationString == "outcast") { + return MUCOccupant::Outcast; + } + if (affiliationString == "none") { + return MUCOccupant::NoAffiliation; + } + return boost::optional<MUCOccupant::Affiliation>(); } } diff --git a/Swiften/Parser/PayloadParsers/MUCItemParser.h b/Swiften/Parser/PayloadParsers/MUCItemParser.h index fc5d657..6f80d54 100644 --- a/Swiften/Parser/PayloadParsers/MUCItemParser.h +++ b/Swiften/Parser/PayloadParsers/MUCItemParser.h @@ -11,11 +11,11 @@ #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class SWIFTEN_API MUCItemParser { - public: - static MUCItem itemFromTree(ParserElement::ref root); - private: - static boost::optional<MUCOccupant::Role> parseRole(const std::string& itemString); - static boost::optional<MUCOccupant::Affiliation> parseAffiliation(const std::string& statusString); - }; + class SWIFTEN_API MUCItemParser { + public: + static MUCItem itemFromTree(ParserElement::ref root); + private: + static boost::optional<MUCOccupant::Role> parseRole(const std::string& itemString); + static boost::optional<MUCOccupant::Affiliation> parseAffiliation(const std::string& statusString); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp index b4cc7b6..7e7c0d4 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp @@ -15,36 +15,36 @@ MUCOwnerPayloadParser::MUCOwnerPayloadParser(PayloadParserFactoryCollection* fac } void MUCOwnerPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void MUCOwnerPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); + } + } } void MUCOwnerPayloadParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h index 85db82f..6502512 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API MUCOwnerPayloadParser : public GenericPayloadParser<MUCOwnerPayload> { - public: - MUCOwnerPayloadParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API MUCOwnerPayloadParser : public GenericPayloadParser<MUCOwnerPayload> { + public: + MUCOwnerPayloadParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + private: + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* factories; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h index 9270dc7..d6399e7 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API MUCOwnerPayloadParserFactory : public PayloadParserFactory { - public: - MUCOwnerPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API MUCOwnerPayloadParserFactory : public PayloadParserFactory { + public: + MUCOwnerPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "query" && ns == "http://jabber.org/protocol/muc#owner"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "query" && ns == "http://jabber.org/protocol/muc#owner"; + } - virtual PayloadParser* createPayloadParser() { - return new MUCOwnerPayloadParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new MUCOwnerPayloadParser(factories); + } - private: - PayloadParserFactoryCollection* factories; + private: + PayloadParserFactoryCollection* factories; - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp index 39e216c..00a5d4f 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp @@ -17,42 +17,42 @@ namespace Swift { void MUCUserPayloadParser::handleTree(ParserElement::ref root) { - foreach (ParserElement::ref child, root->getAllChildren()) { - if (child->getName() == "item" && child->getNamespace() == root->getNamespace()) { - MUCItem item = MUCItemParser::itemFromTree(child); - getPayloadInternal()->addItem(item); - } - else if (child->getName() == "password" && child->getNamespace() == root->getNamespace()) { - getPayloadInternal()->setPassword(child->getText()); - } - else if (child->getName() == "invite" && child->getNamespace() == root->getNamespace()) { - MUCUserPayload::Invite invite; - std::string to = child->getAttributes().getAttribute("to"); - if (!to.empty()) { - invite.to = to; - } - std::string from = child->getAttributes().getAttribute("from"); - if (!from.empty()) { - invite.from = from; - } - ParserElement::ref reason = child->getChild("reason", root->getNamespace()); - if (reason) { - invite.reason = reason->getText(); - } - getPayloadInternal()->setInvite(invite); - } - else if (child->getName() == "status" && child->getNamespace() == root->getNamespace()) { - MUCUserPayload::StatusCode status; - try { - status.code = boost::lexical_cast<int>(child->getAttributes().getAttribute("code").c_str()); - getPayloadInternal()->addStatusCode(status); - } catch (boost::bad_lexical_cast&) { - } - } - else { - getPayloadInternal()->setPayload(TreeReparser::parseTree(child, factories)); - } - } + foreach (ParserElement::ref child, root->getAllChildren()) { + if (child->getName() == "item" && child->getNamespace() == root->getNamespace()) { + MUCItem item = MUCItemParser::itemFromTree(child); + getPayloadInternal()->addItem(item); + } + else if (child->getName() == "password" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setPassword(child->getText()); + } + else if (child->getName() == "invite" && child->getNamespace() == root->getNamespace()) { + MUCUserPayload::Invite invite; + std::string to = child->getAttributes().getAttribute("to"); + if (!to.empty()) { + invite.to = to; + } + std::string from = child->getAttributes().getAttribute("from"); + if (!from.empty()) { + invite.from = from; + } + ParserElement::ref reason = child->getChild("reason", root->getNamespace()); + if (reason) { + invite.reason = reason->getText(); + } + getPayloadInternal()->setInvite(invite); + } + else if (child->getName() == "status" && child->getNamespace() == root->getNamespace()) { + MUCUserPayload::StatusCode status; + try { + status.code = boost::lexical_cast<int>(child->getAttributes().getAttribute("code").c_str()); + getPayloadInternal()->addStatusCode(status); + } catch (boost::bad_lexical_cast&) { + } + } + else { + getPayloadInternal()->setPayload(TreeReparser::parseTree(child, factories)); + } + } } } diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h index 3d7a53b..3d6dbab 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h @@ -14,12 +14,12 @@ #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class SWIFTEN_API MUCUserPayloadParser : public GenericPayloadTreeParser<MUCUserPayload> { - public: - MUCUserPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {} - virtual void handleTree(ParserElement::ref root); - private: - PayloadParserFactoryCollection* factories; - }; + class PayloadParserFactoryCollection; + class SWIFTEN_API MUCUserPayloadParser : public GenericPayloadTreeParser<MUCUserPayload> { + public: + MUCUserPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {} + virtual void handleTree(ParserElement::ref root); + private: + PayloadParserFactoryCollection* factories; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h index 4cc9134..4a0380d 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> namespace Swift { - class SWIFTEN_API MUCUserPayloadParserFactory : public PayloadParserFactory { - public: - MUCUserPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API MUCUserPayloadParserFactory : public PayloadParserFactory { + public: + MUCUserPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "x" && ns == "http://jabber.org/protocol/muc#user"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "x" && ns == "http://jabber.org/protocol/muc#user"; + } - virtual PayloadParser* createPayloadParser() { - return new MUCUserPayloadParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new MUCUserPayloadParser(factories); + } - private: - PayloadParserFactoryCollection* factories; - }; + private: + PayloadParserFactoryCollection* factories; + }; } diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.cpp b/Swiften/Parser/PayloadParsers/NicknameParser.cpp index a3ce952..331355a 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.cpp +++ b/Swiften/Parser/PayloadParsers/NicknameParser.cpp @@ -12,18 +12,18 @@ NicknameParser::NicknameParser() : level(0) { } void NicknameParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level; + ++level; } void NicknameParser::handleEndElement(const std::string&, const std::string&) { - --level; - if (level == 0) { - getPayloadInternal()->setNickname(text); - } + --level; + if (level == 0) { + getPayloadInternal()->setNickname(text); + } } void NicknameParser::handleCharacterData(const std::string& data) { - text += data; + text += data; } } diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.h b/Swiften/Parser/PayloadParsers/NicknameParser.h index d8ac5b5..1bdd600 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.h +++ b/Swiften/Parser/PayloadParsers/NicknameParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API NicknameParser : public GenericPayloadParser<Nickname> { - public: - NicknameParser(); + class SWIFTEN_API NicknameParser : public GenericPayloadParser<Nickname> { + public: + NicknameParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level; - std::string text; - }; + private: + int level; + std::string text; + }; } diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.cpp b/Swiften/Parser/PayloadParsers/PriorityParser.cpp index 862d219..88eef0d 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.cpp +++ b/Swiften/Parser/PayloadParsers/PriorityParser.cpp @@ -14,24 +14,24 @@ PriorityParser::PriorityParser() : level_(0) { } void PriorityParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void PriorityParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - int priority = 0; - try { - priority = boost::lexical_cast<int>(text_); - } - catch (boost::bad_lexical_cast&) { - } - getPayloadInternal()->setPriority(priority); - } + --level_; + if (level_ == 0) { + int priority = 0; + try { + priority = boost::lexical_cast<int>(text_); + } + catch (boost::bad_lexical_cast&) { + } + getPayloadInternal()->setPriority(priority); + } } void PriorityParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.h b/Swiften/Parser/PayloadParsers/PriorityParser.h index 6c34e3b..e6bf059 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.h +++ b/Swiften/Parser/PayloadParsers/PriorityParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API PriorityParser : public GenericPayloadParser<Priority> { - public: - PriorityParser(); + class SWIFTEN_API PriorityParser : public GenericPayloadParser<Priority> { + public: + PriorityParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp index 0dca7b1..e40249a 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp @@ -15,36 +15,36 @@ PrivateStorageParser::PrivateStorageParser(PayloadParserFactoryCollection* facto } void PrivateStorageParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PrivateStorageParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); + } + } } void PrivateStorageParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h index 57e4136..761a019 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API PrivateStorageParser : public GenericPayloadParser<PrivateStorage> { - public: - PrivateStorageParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API PrivateStorageParser : public GenericPayloadParser<PrivateStorage> { + public: + PrivateStorageParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + private: + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* factories; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h index e8db9af..550177c 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API PrivateStorageParserFactory : public PayloadParserFactory { - public: - PrivateStorageParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API PrivateStorageParserFactory : public PayloadParserFactory { + public: + PrivateStorageParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "query" && ns == "jabber:iq:private"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "query" && ns == "jabber:iq:private"; + } - virtual PayloadParser* createPayloadParser() { - return new PrivateStorageParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new PrivateStorageParser(factories); + } - private: - PayloadParserFactoryCollection* factories; - - }; + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp index 9a470a4..cba3816 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp @@ -24,41 +24,41 @@ PubSubAffiliationParser::~PubSubAffiliationParser() { } void PubSubAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { - if (boost::optional<PubSubAffiliation::Type> value = EnumParser<PubSubAffiliation::Type>()(PubSubAffiliation::None, "none")(PubSubAffiliation::Member, "member")(PubSubAffiliation::Outcast, "outcast")(PubSubAffiliation::Owner, "owner")(PubSubAffiliation::Publisher, "publisher")(PubSubAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { - getPayloadInternal()->setType(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { + if (boost::optional<PubSubAffiliation::Type> value = EnumParser<PubSubAffiliation::Type>()(PubSubAffiliation::None, "none")(PubSubAffiliation::Member, "member")(PubSubAffiliation::Outcast, "outcast")(PubSubAffiliation::Owner, "owner")(PubSubAffiliation::Publisher, "publisher")(PubSubAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubAffiliationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h index 08cddea..1d3f4fd 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> { - public: - PubSubAffiliationParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubAffiliationParser(); + class SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> { + public: + PubSubAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp index b316134..8a11553 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp @@ -24,42 +24,42 @@ PubSubAffiliationsParser::~PubSubAffiliationsParser() { } void PubSubAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubAffiliationParser>(parsers); - } - } + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubAffiliationParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubAffiliation>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubAffiliationsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h index a52e1c1..a26942f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> { - public: - PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubAffiliationsParser(); + class SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> { + public: + PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp index cac9924..f3af12f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp @@ -24,38 +24,38 @@ PubSubConfigureParser::~PubSubConfigureParser() { } void PubSubConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubConfigureParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubConfigureParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h index 0364ed4..33a3da5 100644 --- a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> { - public: - PubSubConfigureParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubConfigureParser(); + class SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> { + public: + PubSubConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubConfigureParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp index fbf2eba..e299ddb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp @@ -24,36 +24,36 @@ PubSubCreateParser::~PubSubCreateParser() { } void PubSubCreateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubCreateParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubCreateParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h index b4f82a0..3f277ed 100644 --- a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> { - public: - PubSubCreateParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubCreateParser(); + class SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> { + public: + PubSubCreateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubCreateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp index bf5a210..78c6d0b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp @@ -24,41 +24,41 @@ PubSubDefaultParser::~PubSubDefaultParser() { } void PubSubDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) { - if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) { - getPayloadInternal()->setType(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) { + if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubDefaultParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h index e3596d6..b0f0e25 100644 --- a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> { - public: - PubSubDefaultParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubDefaultParser(); + class SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> { + public: + PubSubDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubDefaultParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp index f399717..99a306d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp @@ -9,95 +9,95 @@ using namespace Swift; PubSubErrorParser::PubSubErrorParser() : level(0) { - typeParser - (PubSubError::ClosedNode, "closed-node") - (PubSubError::ConfigurationRequired, "configuration-required") - (PubSubError::InvalidJID, "invalid-jid") - (PubSubError::InvalidOptions, "invalid-options") - (PubSubError::InvalidPayload, "invalid-payload") - (PubSubError::InvalidSubscriptionID, "invalid-subid") - (PubSubError::ItemForbidden, "item-forbidden") - (PubSubError::ItemRequired, "item-required") - (PubSubError::JIDRequired, "jid-required") - (PubSubError::MaximumItemsExceeded, "max-items-exceeded") - (PubSubError::MaximumNodesExceeded, "max-nodes-exceeded") - (PubSubError::NodeIDRequired, "nodeid-required") - (PubSubError::NotInRosterGroup, "not-in-roster-group") - (PubSubError::NotSubscribed, "not-subscribed") - (PubSubError::PayloadTooBig, "payload-too-big") - (PubSubError::PayloadRequired, "payload-required") - (PubSubError::PendingSubscription, "pending-subscription") - (PubSubError::PresenceSubscriptionRequired, "presence-subscription-required") - (PubSubError::SubscriptionIDRequired, "subid-required") - (PubSubError::TooManySubscriptions, "too-many-subscriptions") - (PubSubError::Unsupported, "unsupported") - (PubSubError::UnsupportedAccessModel, "unsupported-access-model"); - unsupportedTypeParser - (PubSubError::AccessAuthorize, "access-authorize") - (PubSubError::AccessOpen, "access-open") - (PubSubError::AccessPresence, "access-presence") - (PubSubError::AccessRoster, "access-roster") - (PubSubError::AccessWhitelist, "access-whitelist") - (PubSubError::AutoCreate, "auto-create") - (PubSubError::AutoSubscribe, "auto-subscribe") - (PubSubError::Collections, "collections") - (PubSubError::ConfigNode, "config-node") - (PubSubError::CreateAndConfigure, "create-and-configure") - (PubSubError::CreateNodes, "create-nodes") - (PubSubError::DeleteItems, "delete-items") - (PubSubError::DeleteNodes, "delete-nodes") - (PubSubError::FilteredNotifications, "filtered-notifications") - (PubSubError::GetPending, "get-pending") - (PubSubError::InstantNodes, "instant-nodes") - (PubSubError::ItemIDs, "item-ids") - (PubSubError::LastPublished, "last-published") - (PubSubError::LeasedSubscription, "leased-subscription") - (PubSubError::ManageSubscriptions, "manage-subscriptions") - (PubSubError::MemberAffiliation, "member-affiliation") - (PubSubError::MetaData, "meta-data") - (PubSubError::ModifyAffiliations, "modify-affiliations") - (PubSubError::MultiCollection, "multi-collection") - (PubSubError::MultiSubscribe, "multi-subscribe") - (PubSubError::OutcastAffiliation, "outcast-affiliation") - (PubSubError::PersistentItems, "persistent-items") - (PubSubError::PresenceNotifications, "presence-notifications") - (PubSubError::PresenceSubscribe, "presence-subscribe") - (PubSubError::Publish, "publish") - (PubSubError::PublishOptions, "publish-options") - (PubSubError::PublishOnlyAffiliation, "publish-only-affiliation") - (PubSubError::PublisherAffiliation, "publisher-affiliation") - (PubSubError::PurgeNodes, "purge-nodes") - (PubSubError::RetractItems, "retract-items") - (PubSubError::RetrieveAffiliations, "retrieve-affiliations") - (PubSubError::RetrieveDefault, "retrieve-default") - (PubSubError::RetrieveItems, "retrieve-items") - (PubSubError::RetrieveSubscriptions, "retrieve-subscriptions") - (PubSubError::Subscribe, "subscribe") - (PubSubError::SubscriptionOptions, "subscription-options") - (PubSubError::SubscriptionNotifications, "subscription-notifications"); + typeParser + (PubSubError::ClosedNode, "closed-node") + (PubSubError::ConfigurationRequired, "configuration-required") + (PubSubError::InvalidJID, "invalid-jid") + (PubSubError::InvalidOptions, "invalid-options") + (PubSubError::InvalidPayload, "invalid-payload") + (PubSubError::InvalidSubscriptionID, "invalid-subid") + (PubSubError::ItemForbidden, "item-forbidden") + (PubSubError::ItemRequired, "item-required") + (PubSubError::JIDRequired, "jid-required") + (PubSubError::MaximumItemsExceeded, "max-items-exceeded") + (PubSubError::MaximumNodesExceeded, "max-nodes-exceeded") + (PubSubError::NodeIDRequired, "nodeid-required") + (PubSubError::NotInRosterGroup, "not-in-roster-group") + (PubSubError::NotSubscribed, "not-subscribed") + (PubSubError::PayloadTooBig, "payload-too-big") + (PubSubError::PayloadRequired, "payload-required") + (PubSubError::PendingSubscription, "pending-subscription") + (PubSubError::PresenceSubscriptionRequired, "presence-subscription-required") + (PubSubError::SubscriptionIDRequired, "subid-required") + (PubSubError::TooManySubscriptions, "too-many-subscriptions") + (PubSubError::Unsupported, "unsupported") + (PubSubError::UnsupportedAccessModel, "unsupported-access-model"); + unsupportedTypeParser + (PubSubError::AccessAuthorize, "access-authorize") + (PubSubError::AccessOpen, "access-open") + (PubSubError::AccessPresence, "access-presence") + (PubSubError::AccessRoster, "access-roster") + (PubSubError::AccessWhitelist, "access-whitelist") + (PubSubError::AutoCreate, "auto-create") + (PubSubError::AutoSubscribe, "auto-subscribe") + (PubSubError::Collections, "collections") + (PubSubError::ConfigNode, "config-node") + (PubSubError::CreateAndConfigure, "create-and-configure") + (PubSubError::CreateNodes, "create-nodes") + (PubSubError::DeleteItems, "delete-items") + (PubSubError::DeleteNodes, "delete-nodes") + (PubSubError::FilteredNotifications, "filtered-notifications") + (PubSubError::GetPending, "get-pending") + (PubSubError::InstantNodes, "instant-nodes") + (PubSubError::ItemIDs, "item-ids") + (PubSubError::LastPublished, "last-published") + (PubSubError::LeasedSubscription, "leased-subscription") + (PubSubError::ManageSubscriptions, "manage-subscriptions") + (PubSubError::MemberAffiliation, "member-affiliation") + (PubSubError::MetaData, "meta-data") + (PubSubError::ModifyAffiliations, "modify-affiliations") + (PubSubError::MultiCollection, "multi-collection") + (PubSubError::MultiSubscribe, "multi-subscribe") + (PubSubError::OutcastAffiliation, "outcast-affiliation") + (PubSubError::PersistentItems, "persistent-items") + (PubSubError::PresenceNotifications, "presence-notifications") + (PubSubError::PresenceSubscribe, "presence-subscribe") + (PubSubError::Publish, "publish") + (PubSubError::PublishOptions, "publish-options") + (PubSubError::PublishOnlyAffiliation, "publish-only-affiliation") + (PubSubError::PublisherAffiliation, "publisher-affiliation") + (PubSubError::PurgeNodes, "purge-nodes") + (PubSubError::RetractItems, "retract-items") + (PubSubError::RetrieveAffiliations, "retrieve-affiliations") + (PubSubError::RetrieveDefault, "retrieve-default") + (PubSubError::RetrieveItems, "retrieve-items") + (PubSubError::RetrieveSubscriptions, "retrieve-subscriptions") + (PubSubError::Subscribe, "subscribe") + (PubSubError::SubscriptionOptions, "subscription-options") + (PubSubError::SubscriptionNotifications, "subscription-notifications"); } PubSubErrorParser::~PubSubErrorParser() { } void PubSubErrorParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 1) { - if (boost::optional<PubSubError::Type> type = typeParser.parse(element)) { - getPayloadInternal()->setType(*type); - if (type == PubSubError::Unsupported) { - if (boost::optional<std::string> feature = attributes.getAttributeValue("feature")) { - if (boost::optional<PubSubError::UnsupportedFeatureType> unsupportedType = unsupportedTypeParser.parse(*feature)) { - getPayloadInternal()->setUnsupportedFeatureType(*unsupportedType); - } - } - } - } - } - ++level; + if (level == 1) { + if (boost::optional<PubSubError::Type> type = typeParser.parse(element)) { + getPayloadInternal()->setType(*type); + if (type == PubSubError::Unsupported) { + if (boost::optional<std::string> feature = attributes.getAttributeValue("feature")) { + if (boost::optional<PubSubError::UnsupportedFeatureType> unsupportedType = unsupportedTypeParser.parse(*feature)) { + getPayloadInternal()->setUnsupportedFeatureType(*unsupportedType); + } + } + } + } + } + ++level; } void PubSubErrorParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } void PubSubErrorParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h index 73f4207..749fb1a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h @@ -15,21 +15,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { - public: - PubSubErrorParser(); - virtual ~PubSubErrorParser(); + class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { + public: + PubSubErrorParser(); + virtual ~PubSubErrorParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - int level; - EnumParser<PubSubError::Type> typeParser; - EnumParser<PubSubError::UnsupportedFeatureType> unsupportedTypeParser; - }; + private: + int level; + EnumParser<PubSubError::Type> typeParser; + EnumParser<PubSubError::UnsupportedFeatureType> unsupportedTypeParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h index e421581..c7a3614 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> namespace Swift { - class SWIFTEN_API PubSubErrorParserFactory : public PayloadParserFactory { - public: - PubSubErrorParserFactory() { - } - ~PubSubErrorParserFactory(); + class SWIFTEN_API PubSubErrorParserFactory : public PayloadParserFactory { + public: + PubSubErrorParserFactory() { + } + ~PubSubErrorParserFactory(); - virtual bool canParse(const std::string&, const std::string& ns, const AttributeMap&) const { - return ns == "http://jabber.org/protocol/pubsub#errors"; - } + virtual bool canParse(const std::string&, const std::string& ns, const AttributeMap&) const { + return ns == "http://jabber.org/protocol/pubsub#errors"; + } - virtual PayloadParser* createPayloadParser() { - return new PubSubErrorParser(); - } - }; + virtual PayloadParser* createPayloadParser() { + return new PubSubErrorParser(); + } + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp index dd740b3..c5d8959 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp @@ -24,36 +24,36 @@ PubSubEventAssociateParser::~PubSubEventAssociateParser() { } void PubSubEventAssociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventAssociateParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventAssociateParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h index 3e87523..c2cc9f6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> { - public: - PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventAssociateParser(); + class SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> { + public: + PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventAssociateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp index 373d971..bb167e3 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp @@ -25,48 +25,48 @@ PubSubEventCollectionParser::~PubSubEventCollectionParser() { } void PubSubEventCollectionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventDisassociateParser>(parsers); - } - if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventAssociateParser>(parsers); - } - } + if (level == 1) { + if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventDisassociateParser>(parsers); + } + if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventAssociateParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventCollectionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->setDisassociate(boost::dynamic_pointer_cast<PubSubEventDisassociate>(currentPayloadParser->getPayload())); - } - if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->setAssociate(boost::dynamic_pointer_cast<PubSubEventAssociate>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setDisassociate(boost::dynamic_pointer_cast<PubSubEventDisassociate>(currentPayloadParser->getPayload())); + } + if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setAssociate(boost::dynamic_pointer_cast<PubSubEventAssociate>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventCollectionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h index 26d580b..a2b1663 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> { - public: - PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventCollectionParser(); + class SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> { + public: + PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventCollectionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp index 97e5ad9..d118ab8 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp @@ -24,42 +24,42 @@ PubSubEventConfigurationParser::~PubSubEventConfigurationParser() { } void PubSubEventConfigurationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventConfigurationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventConfigurationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h index f1f07b2..e3fcab6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> { - public: - PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventConfigurationParser(); + class SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> { + public: + PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventConfigurationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp index 9641a03..167a682 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp @@ -24,42 +24,42 @@ PubSubEventDeleteParser::~PubSubEventDeleteParser() { } void PubSubEventDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventRedirectParser>(parsers); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventRedirectParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventDeleteParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->setRedirects(boost::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setRedirects(boost::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventDeleteParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h index 8a6f0eb..24d6b6b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> { - public: - PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventDeleteParser(); + class SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> { + public: + PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDeleteParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp index 25ec3a9..d0da109 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp @@ -24,36 +24,36 @@ PubSubEventDisassociateParser::~PubSubEventDisassociateParser() { } void PubSubEventDisassociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventDisassociateParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventDisassociateParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h index a5dae6b..6835602 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> { - public: - PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventDisassociateParser(); + class SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> { + public: + PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDisassociateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp index e245e63..fca2df8 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp @@ -24,46 +24,46 @@ PubSubEventItemParser::~PubSubEventItemParser() { } void PubSubEventItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("publisher")) { - getPayloadInternal()->setPublisher(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { - getPayloadInternal()->setID(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("publisher")) { + getPayloadInternal()->setPublisher(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } - if (level == 1) { - if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { - currentPayloadParser.reset(factory->createPayloadParser()); - } - } + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventItemParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - getPayloadInternal()->addData(currentPayloadParser->getPayload()); - currentPayloadParser.reset(); - } - } + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } } void PubSubEventItemParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h index faee9d3..4b34a26 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> { - public: - PubSubEventItemParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventItemParser(); + class SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> { + public: + PubSubEventItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp index 2aafb74..90d3fe8 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp @@ -25,48 +25,48 @@ PubSubEventItemsParser::~PubSubEventItemsParser() { } void PubSubEventItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventItemParser>(parsers); - } - if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventRetractParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventItemParser>(parsers); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventRetractParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventItemsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubEventItem>(currentPayloadParser->getPayload())); - } - if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->addRetract(boost::dynamic_pointer_cast<PubSubEventRetract>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubEventItem>(currentPayloadParser->getPayload())); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->addRetract(boost::dynamic_pointer_cast<PubSubEventRetract>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventItemsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h index 1847be5..6cb0148 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> { - public: - PubSubEventItemsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventItemsParser(); + class SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> { + public: + PubSubEventItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp index 34db2f8..ae0439c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp @@ -29,53 +29,53 @@ PubSubEventParser::~PubSubEventParser() { } void PubSubEventParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - if (level == 1) { - if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventItemsParser>(parsers); - } - if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventCollectionParser>(parsers); - } - if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventPurgeParser>(parsers); - } - if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventConfigurationParser>(parsers); - } - if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventDeleteParser>(parsers); - } - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventSubscriptionParser>(parsers); - } - } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventItemsParser>(parsers); + } + if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventCollectionParser>(parsers); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventPurgeParser>(parsers); + } + if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventConfigurationParser>(parsers); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventDeleteParser>(parsers); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventSubscriptionParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (currentPayloadParser) { - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubEventPayload>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (currentPayloadParser) { + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubEventPayload>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.h b/Swiften/Parser/PayloadParsers/PubSubEventParser.h index fc63528..a4fc5a6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> { - public: - PubSubEventParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventParser(); + class SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> { + public: + PubSubEventParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp index cdd3808..09ceeea 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp @@ -24,36 +24,36 @@ PubSubEventPurgeParser::~PubSubEventPurgeParser() { } void PubSubEventPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventPurgeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventPurgeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h index c174d5b..7afc754 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> { - public: - PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventPurgeParser(); + class SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> { + public: + PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventPurgeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp index 8ea236e..899c039 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp @@ -24,36 +24,36 @@ PubSubEventRedirectParser::~PubSubEventRedirectParser() { } void PubSubEventRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { - getPayloadInternal()->setURI(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { + getPayloadInternal()->setURI(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventRedirectParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventRedirectParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h index 3905285..ecdeca5 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> { - public: - PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventRedirectParser(); + class SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> { + public: + PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRedirectParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp index 7a4df14..32d88b4 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp @@ -24,36 +24,36 @@ PubSubEventRetractParser::~PubSubEventRetractParser() { } void PubSubEventRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { - getPayloadInternal()->setID(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventRetractParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventRetractParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h index 99cc164..8bc6a9c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> { - public: - PubSubEventRetractParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventRetractParser(); + class SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> { + public: + PubSubEventRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRetractParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp index 9308101..92d1a0c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp @@ -25,52 +25,52 @@ PubSubEventSubscriptionParser::~PubSubEventSubscriptionParser() { } void PubSubEventSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { - if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { - getPayloadInternal()->setSubscription(*value); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) { - getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue)); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) { + getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue)); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventSubscriptionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h index 24ce22a..b43e64a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> { - public: - PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventSubscriptionParser(); + class SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> { + public: + PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventSubscriptionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp index a2b22ac..8537ecb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp @@ -24,40 +24,40 @@ PubSubItemParser::~PubSubItemParser() { } void PubSubItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { - getPayloadInternal()->setID(*attributeValue); - } - } - - if (level == 1) { - if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { - currentPayloadParser.reset(factory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubItemParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->addData(currentPayloadParser->getPayload()); - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } } void PubSubItemParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.h b/Swiften/Parser/PayloadParsers/PubSubItemParser.h index e584797..39d24bc 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> { - public: - PubSubItemParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubItemParser(); + class SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> { + public: + PubSubItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp index f07b6fa..643eb85 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp @@ -24,52 +24,52 @@ PubSubItemsParser::~PubSubItemsParser() { } void PubSubItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) { - try { - getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue)); - } - catch (boost::bad_lexical_cast&) { - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) { + try { + getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue)); + } + catch (boost::bad_lexical_cast&) { + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubItemsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubItemsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h index 5f3afd3..84c8f79 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> { - public: - PubSubItemsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubItemsParser(); + class SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> { + public: + PubSubItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp index 438d728..2683ae6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp @@ -24,50 +24,50 @@ PubSubOptionsParser::~PubSubOptionsParser() { } void PubSubOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h index 3070cec..52d374c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> { - public: - PubSubOptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOptionsParser(); + class SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> { + public: + PubSubOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp index 3a8ceb8..eb63696 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp @@ -24,43 +24,43 @@ PubSubOwnerAffiliationParser::~PubSubOwnerAffiliationParser() { } void PubSubOwnerAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { - if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { - getPayloadInternal()->setType(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { + if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubOwnerAffiliationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h index f412ab5..972930c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> { - public: - PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerAffiliationParser(); + class SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> { + public: + PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp index df3813e..247bf4c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp @@ -24,42 +24,42 @@ PubSubOwnerAffiliationsParser::~PubSubOwnerAffiliationsParser() { } void PubSubOwnerAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationParser>(parsers); - } - } + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { - getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerAffiliationsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h index c1cc4a0..870d809 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> { - public: - PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerAffiliationsParser(); + class SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> { + public: + PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp index 1cc8660..62dd1ac 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp @@ -24,42 +24,42 @@ PubSubOwnerConfigureParser::~PubSubOwnerConfigureParser() { } void PubSubOwnerConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerConfigureParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerConfigureParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h index 0a96aa7..914a309 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> { - public: - PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerConfigureParser(); + class SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> { + public: + PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerConfigureParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp index a704411..36ccbaf 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp @@ -24,38 +24,38 @@ PubSubOwnerDefaultParser::~PubSubOwnerDefaultParser() { } void PubSubOwnerDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerDefaultParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h index 5ab8f8f..3106854 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> { - public: - PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerDefaultParser(); + class SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> { + public: + PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDefaultParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp index 9817793..047fe8b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp @@ -24,42 +24,42 @@ PubSubOwnerDeleteParser::~PubSubOwnerDeleteParser() { } void PubSubOwnerDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerRedirectParser>(parsers); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerRedirectParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerDeleteParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { - getPayloadInternal()->setRedirect(boost::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->setRedirect(boost::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerDeleteParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h index 25a1f03..f56ae3c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> { - public: - PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerDeleteParser(); + class SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> { + public: + PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDeleteParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp index 71b1c16..aa7310e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp @@ -29,53 +29,53 @@ PubSubOwnerPubSubParser::~PubSubOwnerPubSubParser() { } void PubSubOwnerPubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - if (level == 1) { - if (element == "configure" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerConfigureParser>(parsers); - } - if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionsParser>(parsers); - } - if (element == "default" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerDefaultParser>(parsers); - } - if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerPurgeParser>(parsers); - } - if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationsParser>(parsers); - } - if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerDeleteParser>(parsers); - } - } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerConfigureParser>(parsers); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionsParser>(parsers); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerDefaultParser>(parsers); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerPurgeParser>(parsers); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationsParser>(parsers); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerDeleteParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerPubSubParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (currentPayloadParser) { - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubOwnerPayload>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (currentPayloadParser) { + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubOwnerPayload>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerPubSubParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h index bd6f3a5..d4d67f9 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> { - public: - PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerPubSubParser(); + class SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> { + public: + PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPubSubParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp index f417ec2..68224f6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp @@ -24,36 +24,36 @@ PubSubOwnerPurgeParser::~PubSubOwnerPurgeParser() { } void PubSubOwnerPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerPurgeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubOwnerPurgeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h index baccb9a..364de29 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> { - public: - PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerPurgeParser(); + class SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> { + public: + PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPurgeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp index e4ad149..72c19dd 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp @@ -24,36 +24,36 @@ PubSubOwnerRedirectParser::~PubSubOwnerRedirectParser() { } void PubSubOwnerRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { - getPayloadInternal()->setURI(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { + getPayloadInternal()->setURI(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerRedirectParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubOwnerRedirectParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h index b277af9..fd48dbb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> { - public: - PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerRedirectParser(); + class SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> { + public: + PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerRedirectParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp index 9e2fdee..ee4c34f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp @@ -24,43 +24,43 @@ PubSubOwnerSubscriptionParser::~PubSubOwnerSubscriptionParser() { } void PubSubOwnerSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { - if (boost::optional<PubSubOwnerSubscription::SubscriptionType> value = EnumParser<PubSubOwnerSubscription::SubscriptionType>()(PubSubOwnerSubscription::None, "none")(PubSubOwnerSubscription::Pending, "pending")(PubSubOwnerSubscription::Subscribed, "subscribed")(PubSubOwnerSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { - getPayloadInternal()->setSubscription(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubOwnerSubscription::SubscriptionType> value = EnumParser<PubSubOwnerSubscription::SubscriptionType>()(PubSubOwnerSubscription::None, "none")(PubSubOwnerSubscription::Pending, "pending")(PubSubOwnerSubscription::Subscribed, "subscribed")(PubSubOwnerSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubOwnerSubscriptionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h index c76734f..46df820 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> { - public: - PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerSubscriptionParser(); + class SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> { + public: + PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp index 857bd87..e08d782 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp @@ -24,42 +24,42 @@ PubSubOwnerSubscriptionsParser::~PubSubOwnerSubscriptionsParser() { } void PubSubOwnerSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionParser>(parsers); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { - getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerSubscriptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h index 35a18fb..10c11e4 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> { - public: - PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerSubscriptionsParser(); + class SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> { + public: + PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubParser.cpp index c6574a8..9c86c21 100644 --- a/Swiften/Parser/PayloadParsers/PubSubParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubParser.cpp @@ -36,90 +36,90 @@ PubSubParser::~PubSubParser() { } void PubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - if (element == "items" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemsParser>(parsers); - } - if (element == "create" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubCreateParser>(parsers); - } - if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubPublishParser>(parsers); - } - if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubAffiliationsParser>(parsers); - } - if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubRetractParser>(parsers); - } - if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubOptionsParser>(parsers); - } - if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubConfigureParser>(parsers); - } - if (element == "default" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubDefaultParser>(parsers); - } - if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscriptionsParser>(parsers); - } - if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscribeParser>(parsers); - } - if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubUnsubscribeParser>(parsers); - } - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); - } - } + if (level == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemsParser>(parsers); + } + if (element == "create" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubCreateParser>(parsers); + } + if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubPublishParser>(parsers); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubAffiliationsParser>(parsers); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubRetractParser>(parsers); + } + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubOptionsParser>(parsers); + } + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubConfigureParser>(parsers); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubDefaultParser>(parsers); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionsParser>(parsers); + } + if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscribeParser>(parsers); + } + if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubUnsubscribeParser>(parsers); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (currentPayloadParser) { - if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { - optionsPayload = boost::dynamic_pointer_cast<PubSubOptions>(currentPayloadParser->getPayload()); - } - else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { - configurePayload = boost::dynamic_pointer_cast<PubSubConfigure>(currentPayloadParser->getPayload()); - } - else { - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubPayload>(currentPayloadParser->getPayload())); - } - } - currentPayloadParser.reset(); - } + if (level == 1) { + if (currentPayloadParser) { + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + optionsPayload = boost::dynamic_pointer_cast<PubSubOptions>(currentPayloadParser->getPayload()); + } + else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + configurePayload = boost::dynamic_pointer_cast<PubSubConfigure>(currentPayloadParser->getPayload()); + } + else { + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubPayload>(currentPayloadParser->getPayload())); + } + } + currentPayloadParser.reset(); + } - if (level == 0) { - if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(getPayloadInternal()->getPayload())) { - if (configurePayload) { - create->setConfigure(configurePayload); - } - } - if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(getPayloadInternal()->getPayload())) { - if (optionsPayload) { - subscribe->setOptions(optionsPayload); - } - } - } - } + if (level == 0) { + if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(getPayloadInternal()->getPayload())) { + if (configurePayload) { + create->setConfigure(configurePayload); + } + } + if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(getPayloadInternal()->getPayload())) { + if (optionsPayload) { + subscribe->setOptions(optionsPayload); + } + } + } + } } void PubSubParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubParser.h index 1ccae54..a8043fc 100644 --- a/Swiften/Parser/PayloadParsers/PubSubParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubParser.h @@ -14,25 +14,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; - class PubSubOptions; - class PubSubConfigure; + class PayloadParserFactoryCollection; + class PayloadParser; + class PubSubOptions; + class PubSubConfigure; - class SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> { - public: - PubSubParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubParser(); + class SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> { + public: + PubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - boost::shared_ptr<PubSubConfigure> configurePayload; - boost::shared_ptr<PubSubOptions> optionsPayload; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + boost::shared_ptr<PubSubConfigure> configurePayload; + boost::shared_ptr<PubSubOptions> optionsPayload; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp index 2b52edc..3bd3ac0 100644 --- a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp @@ -24,42 +24,42 @@ PubSubPublishParser::~PubSubPublishParser() { } void PubSubPublishParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubPublishParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubPublishParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h index 6b60457..1df7c6f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> { - public: - PubSubPublishParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubPublishParser(); + class SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> { + public: + PubSubPublishParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubPublishParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp index 909e82f..e710fad 100644 --- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp @@ -24,45 +24,45 @@ PubSubRetractParser::~PubSubRetractParser() { } void PubSubRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) { - getPayloadInternal()->setNotify(*attributeValue == "true" ? true : false); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) { + getPayloadInternal()->setNotify(*attributeValue == "true" ? true : false); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubRetractParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubRetractParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h index 9b1a052..ece2a52 100644 --- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> { - public: - PubSubRetractParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubRetractParser(); + class SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> { + public: + PubSubRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubRetractParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp index 64bea49..120d704 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp @@ -24,34 +24,34 @@ PubSubSubscribeOptionsParser::~PubSubSubscribeOptionsParser() { } void PubSubSubscribeOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscribeOptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "required") { - getPayloadInternal()->setRequired(true); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "required") { + getPayloadInternal()->setRequired(true); + } + currentPayloadParser.reset(); + } + } } void PubSubSubscribeOptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h index 7fb140a..9136f44 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> { - public: - PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscribeOptionsParser(); + class SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> { + public: + PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeOptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp index 3f34fc7..f049642 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp @@ -24,41 +24,41 @@ PubSubSubscribeParser::~PubSubSubscribeParser() { } void PubSubSubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubSubscribeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h index 72d0233..823c086 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> { - public: - PubSubSubscribeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscribeParser(); + class SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> { + public: + PubSubSubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp index b78c841..5954bf1 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp @@ -25,55 +25,55 @@ PubSubSubscriptionParser::~PubSubSubscriptionParser() { } void PubSubSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { - if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { - getPayloadInternal()->setSubscription(*value); - } - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + } - if (level == 1) { - if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers); - } - } + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->setOptions(boost::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->setOptions(boost::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubSubscriptionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h index b5eeb5a..771a74a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> { - public: - PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscriptionParser(); + class SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> { + public: + PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp index 85929a4..30198a5 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp @@ -24,42 +24,42 @@ PubSubSubscriptionsParser::~PubSubSubscriptionsParser() { } void PubSubSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubSubscriptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h index 0b5378e..9f18376 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> { - public: - PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscriptionsParser(); + class SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> { + public: + PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp index 1b1808e..e3e7d23 100644 --- a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp @@ -24,44 +24,44 @@ PubSubUnsubscribeParser::~PubSubUnsubscribeParser() { } void PubSubUnsubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubUnsubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubUnsubscribeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h index 0de1fab..d33d33c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h @@ -14,21 +14,21 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> { - public: - PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubUnsubscribeParser(); + class SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> { + public: + PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubUnsubscribeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp index 700624f..97abce3 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp @@ -14,20 +14,20 @@ RawXMLPayloadParser::RawXMLPayloadParser() : level_(0) { } void RawXMLPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - serializingParser_.handleStartElement(element, ns, attributes); + ++level_; + serializingParser_.handleStartElement(element, ns, attributes); } void RawXMLPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - serializingParser_.handleEndElement(element, ns); - --level_; - if (level_ == 0) { - getPayloadInternal()->setRawXML(serializingParser_.getResult()); - } + serializingParser_.handleEndElement(element, ns); + --level_; + if (level_ == 0) { + getPayloadInternal()->setRawXML(serializingParser_.getResult()); + } } void RawXMLPayloadParser::handleCharacterData(const std::string& data) { - serializingParser_.handleCharacterData(data); + serializingParser_.handleCharacterData(data); } } diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h index e3c5993..1f20105 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h @@ -12,18 +12,18 @@ #include <Swiften/Parser/SerializingParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> { - public: - RawXMLPayloadParser(); + class SWIFTEN_API RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> { + public: + RawXMLPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - SerializingParser serializingParser_; - }; + private: + int level_; + SerializingParser serializingParser_; + }; } diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h index c7bae9d..f7b7601 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h @@ -13,16 +13,16 @@ #include <Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h> namespace Swift { - class SWIFTEN_API RawXMLPayloadParserFactory : public PayloadParserFactory { - public: - RawXMLPayloadParserFactory() {} + class SWIFTEN_API RawXMLPayloadParserFactory : public PayloadParserFactory { + public: + RawXMLPayloadParserFactory() {} - virtual bool canParse(const std::string&, const std::string&, const AttributeMap&) const { - return true; - } + virtual bool canParse(const std::string&, const std::string&, const AttributeMap&) const { + return true; + } - virtual PayloadParser* createPayloadParser() { - return new RawXMLPayloadParser(); - } - }; + virtual PayloadParser* createPayloadParser() { + return new RawXMLPayloadParser(); + } + }; } diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp index f3483be..66e219a 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp @@ -16,22 +16,22 @@ namespace Swift { - ReplaceParser::ReplaceParser() : level_(0) { - } - - void ReplaceParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level_ == 0) { - std::string id = attributes.getAttribute("id"); - getPayloadInternal()->setID(id); - } - level_++; - } - - void ReplaceParser::handleEndElement(const std::string&, const std::string&) { - --level_; - } - - void ReplaceParser::handleCharacterData(const std::string&) { - } + ReplaceParser::ReplaceParser() : level_(0) { + } + + void ReplaceParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + std::string id = attributes.getAttribute("id"); + getPayloadInternal()->setID(id); + } + level_++; + } + + void ReplaceParser::handleEndElement(const std::string&, const std::string&) { + --level_; + } + + void ReplaceParser::handleCharacterData(const std::string&) { + } } diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.h b/Swiften/Parser/PayloadParsers/ReplaceParser.h index 3c1fbbc..21d7322 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.h +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.h @@ -17,14 +17,14 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ReplaceParser : public GenericPayloadParser<Replace> { - public: - ReplaceParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + class SWIFTEN_API ReplaceParser : public GenericPayloadParser<Replace> { + public: + ReplaceParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp index c49f9a4..2965d66 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp @@ -12,32 +12,32 @@ ResourceBindParser::ResourceBindParser() : level_(0), inJID_(false), inResource_ } void ResourceBindParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (level_ == 1) { - text_ = ""; - if (element == "resource") { - inResource_ = true; - } - if (element == "jid") { - inJID_ = true; - } - } - ++level_; + if (level_ == 1) { + text_ = ""; + if (element == "resource") { + inResource_ = true; + } + if (element == "jid") { + inJID_ = true; + } + } + ++level_; } void ResourceBindParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 1) { - if (inJID_) { - getPayloadInternal()->setJID(JID(text_)); - } - else if (inResource_) { - getPayloadInternal()->setResource(text_); - } - } + --level_; + if (level_ == 1) { + if (inJID_) { + getPayloadInternal()->setJID(JID(text_)); + } + else if (inResource_) { + getPayloadInternal()->setResource(text_); + } + } } void ResourceBindParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/ResourceBindParser.h b/Swiften/Parser/PayloadParsers/ResourceBindParser.h index 134bf14..3619c0b 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.h +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.h @@ -11,18 +11,18 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ResourceBindParser : public GenericPayloadParser<ResourceBind> { - public: - ResourceBindParser(); + class SWIFTEN_API ResourceBindParser : public GenericPayloadParser<ResourceBind> { + public: + ResourceBindParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - bool inJID_; - bool inResource_; - std::string text_; - }; + private: + int level_; + bool inJID_; + bool inResource_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp index c6cb964..80d89d7 100644 --- a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp @@ -18,50 +18,50 @@ ResultSetParser::ResultSetParser() : level_(TopLevel) { } void ResultSetParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - currentText_ = ""; - if (level_ == PayloadLevel) { - if (element == "first" && ns == "http://jabber.org/protocol/rsm") { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("index")) { - try { - getPayloadInternal()->setFirstIDIndex(boost::lexical_cast<int>(*attributeValue)); - } catch(boost::bad_lexical_cast&) { - } - } - } - } - ++level_; + currentText_ = ""; + if (level_ == PayloadLevel) { + if (element == "first" && ns == "http://jabber.org/protocol/rsm") { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("index")) { + try { + getPayloadInternal()->setFirstIDIndex(boost::lexical_cast<int>(*attributeValue)); + } catch(boost::bad_lexical_cast&) { + } + } + } + } + ++level_; } void ResultSetParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel) { - if (element == "max") { - try { - getPayloadInternal()->setMaxItems(boost::lexical_cast<int>(currentText_)); - } catch(boost::bad_lexical_cast&) { - } - } else if (element == "count") { - try { - getPayloadInternal()->setCount(boost::lexical_cast<int>(currentText_)); - } catch(boost::bad_lexical_cast&) { - } - } else if (element == "index") { - try { - getPayloadInternal()->setIndex(boost::lexical_cast<int>(currentText_)); - } catch(boost::bad_lexical_cast&) { - } - } else if (element == "first") { - getPayloadInternal()->setFirstID(currentText_); - } else if (element == "last") { - getPayloadInternal()->setLastID(currentText_); - } else if (element == "before") { - getPayloadInternal()->setBefore(currentText_); - } else if (element == "after") { - getPayloadInternal()->setAfter(currentText_); - } - } + --level_; + if (level_ == PayloadLevel) { + if (element == "max") { + try { + getPayloadInternal()->setMaxItems(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "count") { + try { + getPayloadInternal()->setCount(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "index") { + try { + getPayloadInternal()->setIndex(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "first") { + getPayloadInternal()->setFirstID(currentText_); + } else if (element == "last") { + getPayloadInternal()->setLastID(currentText_); + } else if (element == "before") { + getPayloadInternal()->setBefore(currentText_); + } else if (element == "after") { + getPayloadInternal()->setAfter(currentText_); + } + } } void ResultSetParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.h b/Swiften/Parser/PayloadParsers/ResultSetParser.h index 1066375..335a798 100644 --- a/Swiften/Parser/PayloadParsers/ResultSetParser.h +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.h @@ -14,23 +14,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API ResultSetParser : public GenericPayloadParser<ResultSet> { - public: - ResultSetParser(); + class SWIFTEN_API ResultSetParser : public GenericPayloadParser<ResultSet> { + public: + ResultSetParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - std::string currentText_; - int level_; - }; + private: + std::string currentText_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp index de6caa1..f99f592 100644 --- a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp @@ -20,56 +20,56 @@ RosterItemExchangeParser::RosterItemExchangeParser() : level_(TopLevel), inItem_ } void RosterItemExchangeParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "item") { - inItem_ = true; + if (level_ == PayloadLevel) { + if (element == "item") { + inItem_ = true; - currentItem_ = RosterItemExchangePayload::Item(); + currentItem_ = RosterItemExchangePayload::Item(); - currentItem_.setJID(JID(attributes.getAttribute("jid"))); - currentItem_.setName(attributes.getAttribute("name")); + currentItem_.setJID(JID(attributes.getAttribute("jid"))); + currentItem_.setName(attributes.getAttribute("name")); - std::string action = attributes.getAttribute("action"); - if (action == "add") { - currentItem_.setAction(RosterItemExchangePayload::Item::Add); - } - else if (action == "modify") { - currentItem_.setAction(RosterItemExchangePayload::Item::Modify); - } - else if (action == "delete") { - currentItem_.setAction(RosterItemExchangePayload::Item::Delete); - } - else { - // Add is default action according to XEP - currentItem_.setAction(RosterItemExchangePayload::Item::Add); - } - } - } - else if (level_ == ItemLevel) { - if (element == "group") { - currentText_ = ""; - } - } - ++level_; + std::string action = attributes.getAttribute("action"); + if (action == "add") { + currentItem_.setAction(RosterItemExchangePayload::Item::Add); + } + else if (action == "modify") { + currentItem_.setAction(RosterItemExchangePayload::Item::Modify); + } + else if (action == "delete") { + currentItem_.setAction(RosterItemExchangePayload::Item::Delete); + } + else { + // Add is default action according to XEP + currentItem_.setAction(RosterItemExchangePayload::Item::Add); + } + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentText_ = ""; + } + } + ++level_; } void RosterItemExchangeParser::handleEndElement(const std::string& element, const std::string& /*ns*/) { - --level_; - if (level_ == PayloadLevel) { - if (inItem_) { - getPayloadInternal()->addItem(currentItem_); - inItem_ = false; - } - } - else if (level_ == ItemLevel) { - if (element == "group") { - currentItem_.addGroup(currentText_); - } - } + --level_; + if (level_ == PayloadLevel) { + if (inItem_) { + getPayloadInternal()->addItem(currentItem_); + inItem_ = false; + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentItem_.addGroup(currentText_); + } + } } void RosterItemExchangeParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h index bf3dace..40e010a 100644 --- a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h @@ -17,25 +17,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API RosterItemExchangeParser : public GenericPayloadParser<RosterItemExchangePayload> { - public: - RosterItemExchangeParser(); + class SWIFTEN_API RosterItemExchangeParser : public GenericPayloadParser<RosterItemExchangePayload> { + public: + RosterItemExchangeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2 - }; - int level_; - bool inItem_; - RosterItemExchangePayload::Item currentItem_; - std::string currentText_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level_; + bool inItem_; + RosterItemExchangePayload::Item currentItem_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/RosterParser.cpp b/Swiften/Parser/PayloadParsers/RosterParser.cpp index b35d598..0cb47d3 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterParser.cpp @@ -16,89 +16,89 @@ RosterParser::RosterParser() : level_(TopLevel), inItem_(false), unknownContentP } void RosterParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - boost::optional<std::string> ver = attributes.getAttributeValue("ver"); - if (ver) { - getPayloadInternal()->setVersion(*ver); - } - } - else if (level_ == PayloadLevel) { - if (element == "item") { - inItem_ = true; - currentItem_ = RosterItemPayload(); + if (level_ == TopLevel) { + boost::optional<std::string> ver = attributes.getAttributeValue("ver"); + if (ver) { + getPayloadInternal()->setVersion(*ver); + } + } + else if (level_ == PayloadLevel) { + if (element == "item") { + inItem_ = true; + currentItem_ = RosterItemPayload(); - currentItem_.setJID(JID(attributes.getAttribute("jid"))); - currentItem_.setName(attributes.getAttribute("name")); + currentItem_.setJID(JID(attributes.getAttribute("jid"))); + currentItem_.setName(attributes.getAttribute("name")); - std::string subscription = attributes.getAttribute("subscription"); - if (subscription == "both") { - currentItem_.setSubscription(RosterItemPayload::Both); - } - else if (subscription == "to") { - currentItem_.setSubscription(RosterItemPayload::To); - } - else if (subscription == "from") { - currentItem_.setSubscription(RosterItemPayload::From); - } - else if (subscription == "remove") { - currentItem_.setSubscription(RosterItemPayload::Remove); - } - else { - currentItem_.setSubscription(RosterItemPayload::None); - } + std::string subscription = attributes.getAttribute("subscription"); + if (subscription == "both") { + currentItem_.setSubscription(RosterItemPayload::Both); + } + else if (subscription == "to") { + currentItem_.setSubscription(RosterItemPayload::To); + } + else if (subscription == "from") { + currentItem_.setSubscription(RosterItemPayload::From); + } + else if (subscription == "remove") { + currentItem_.setSubscription(RosterItemPayload::Remove); + } + else { + currentItem_.setSubscription(RosterItemPayload::None); + } - if (attributes.getAttribute("ask") == "subscribe") { - currentItem_.setSubscriptionRequested(); - } - } - } - else if (level_ == ItemLevel) { - if (element == "group") { - currentText_ = ""; - } - else { - assert(!unknownContentParser_); - unknownContentParser_ = new SerializingParser(); - unknownContentParser_->handleStartElement(element, ns, attributes); - } - } - else if (unknownContentParser_) { - unknownContentParser_->handleStartElement(element, ns, attributes); - } - ++level_; + if (attributes.getAttribute("ask") == "subscribe") { + currentItem_.setSubscriptionRequested(); + } + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentText_ = ""; + } + else { + assert(!unknownContentParser_); + unknownContentParser_ = new SerializingParser(); + unknownContentParser_->handleStartElement(element, ns, attributes); + } + } + else if (unknownContentParser_) { + unknownContentParser_->handleStartElement(element, ns, attributes); + } + ++level_; } void RosterParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (level_ == PayloadLevel) { - if (inItem_) { - getPayloadInternal()->addItem(currentItem_); - inItem_ = false; - } - } - else if (level_ == ItemLevel) { - if (unknownContentParser_) { - unknownContentParser_->handleEndElement(element, ns); - currentItem_.addUnknownContent(unknownContentParser_->getResult()); - delete unknownContentParser_; - unknownContentParser_ = NULL; - } - else if (element == "group") { - currentItem_.addGroup(currentText_); - } - } - else if (unknownContentParser_) { - unknownContentParser_->handleEndElement(element, ns); - } + --level_; + if (level_ == PayloadLevel) { + if (inItem_) { + getPayloadInternal()->addItem(currentItem_); + inItem_ = false; + } + } + else if (level_ == ItemLevel) { + if (unknownContentParser_) { + unknownContentParser_->handleEndElement(element, ns); + currentItem_.addUnknownContent(unknownContentParser_->getResult()); + delete unknownContentParser_; + unknownContentParser_ = NULL; + } + else if (element == "group") { + currentItem_.addGroup(currentText_); + } + } + else if (unknownContentParser_) { + unknownContentParser_->handleEndElement(element, ns); + } } void RosterParser::handleCharacterData(const std::string& data) { - if (unknownContentParser_) { - unknownContentParser_->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (unknownContentParser_) { + unknownContentParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/RosterParser.h b/Swiften/Parser/PayloadParsers/RosterParser.h index 3440825..2989f46 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.h +++ b/Swiften/Parser/PayloadParsers/RosterParser.h @@ -11,26 +11,26 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API RosterParser : public GenericPayloadParser<RosterPayload> { - public: - RosterParser(); + class SWIFTEN_API RosterParser : public GenericPayloadParser<RosterPayload> { + public: + RosterParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2 - }; - int level_; - bool inItem_; - RosterItemPayload currentItem_; - std::string currentText_; - SerializingParser* unknownContentParser_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level_; + bool inItem_; + RosterItemPayload currentItem_; + std::string currentText_; + SerializingParser* unknownContentParser_; + }; } diff --git a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp index e0b0a95..502f400 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp @@ -24,48 +24,48 @@ S5BProxyRequestParser::~S5BProxyRequestParser() { } void S5BProxyRequestParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (element == "streamhost") { - if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { - std::string host = attributes.getAttributeValue("host").get_value_or(""); - int port = -1; - JID jid = attributes.getAttributeValue("jid").get_value_or(""); + if (element == "streamhost") { + if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { + std::string host = attributes.getAttributeValue("host").get_value_or(""); + int port = -1; + JID jid = attributes.getAttributeValue("jid").get_value_or(""); - try { - port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get()); - } catch (boost::bad_lexical_cast &) { - port = -1; - } - if (!host.empty() && port != -1 && jid.isValid()) { - S5BProxyRequest::StreamHost streamHost; - streamHost.host = host; - streamHost.port = port; - streamHost.jid = jid; - getPayloadInternal()->setStreamHost(streamHost); - } - } - } else if (element == "activate") { - parseActivate = true; - } else if (element == "query") { - if (attributes.getAttributeValue("sid")) { - getPayloadInternal()->setSID(attributes.getAttributeValue("sid").get()); - } - } + try { + port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get()); + } catch (boost::bad_lexical_cast &) { + port = -1; + } + if (!host.empty() && port != -1 && jid.isValid()) { + S5BProxyRequest::StreamHost streamHost; + streamHost.host = host; + streamHost.port = port; + streamHost.jid = jid; + getPayloadInternal()->setStreamHost(streamHost); + } + } + } else if (element == "activate") { + parseActivate = true; + } else if (element == "query") { + if (attributes.getAttributeValue("sid")) { + getPayloadInternal()->setSID(attributes.getAttributeValue("sid").get()); + } + } } void S5BProxyRequestParser::handleEndElement(const std::string& element, const std::string&) { - if (element == "activate") { - JID activate = JID(activateJID); - if (activate.isValid()) { - getPayloadInternal()->setActivate(activate); - } - parseActivate = false; - } + if (element == "activate") { + JID activate = JID(activateJID); + if (activate.isValid()) { + getPayloadInternal()->setActivate(activate); + } + parseActivate = false; + } } void S5BProxyRequestParser::handleCharacterData(const std::string& data) { - if (parseActivate) { - activateJID = activateJID + data; - } + if (parseActivate) { + activateJID = activateJID + data; + } } } diff --git a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h index 408bb5a..1d5fd64 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h @@ -22,16 +22,16 @@ namespace Swift { class SWIFTEN_API S5BProxyRequestParser : public GenericPayloadParser<S5BProxyRequest> { public: - S5BProxyRequestParser(); - virtual ~S5BProxyRequestParser(); + S5BProxyRequestParser(); + virtual ~S5BProxyRequestParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); private: - bool parseActivate; - std::string activateJID; + bool parseActivate; + std::string activateJID; }; } diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp index 532ee83..5322b4c 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp @@ -14,100 +14,100 @@ namespace Swift { SearchPayloadParser::SearchPayloadParser() : level(TopLevel), formParser(NULL) { - formParserFactory = new FormParserFactory(); + formParserFactory = new FormParserFactory(); } SearchPayloadParser::~SearchPayloadParser() { - delete formParserFactory; + delete formParserFactory; } void SearchPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (element == "x" && ns == "jabber:x:data") { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - else if (element == "item") { - assert(!currentItem); - currentItem.reset(SearchPayload::Item()); - currentItem->jid = JID(attributes.getAttribute("jid")); - } - else { - currentText.clear(); - } - } - else if (level == ItemLevel && currentItem) { - currentText.clear(); - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + else if (element == "item") { + assert(!currentItem); + currentItem.reset(SearchPayload::Item()); + currentItem->jid = JID(attributes.getAttribute("jid")); + } + else { + currentText.clear(); + } + } + else if (level == ItemLevel && currentItem) { + currentText.clear(); + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } - ++level; + ++level; } void SearchPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; + --level; - if (formParser) { - formParser->handleEndElement(element, ns); - } + if (formParser) { + formParser->handleEndElement(element, ns); + } - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (formParser) { - getPayloadInternal()->setForm(formParser->getPayloadInternal()); - delete formParser; - formParser = NULL; - } - else if (element == "item") { - assert(currentItem); - getPayloadInternal()->addItem(*currentItem); - currentItem.reset(); - } - else if (element == "instructions") { - getPayloadInternal()->setInstructions(currentText); - } - else if (element == "nick") { - getPayloadInternal()->setNick(currentText); - } - else if (element == "first") { - getPayloadInternal()->setFirst(currentText); - } - else if (element == "last") { - getPayloadInternal()->setLast(currentText); - } - else if (element == "email") { - getPayloadInternal()->setEMail(currentText); - } - } - else if (level == ItemLevel && currentItem) { - if (element == "nick") { - currentItem->nick = currentText; - } - else if (element == "first") { - currentItem->first = currentText; - } - else if (element == "last") { - currentItem->last = currentText; - } - else if (element == "email") { - currentItem->email = currentText; - } - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (formParser) { + getPayloadInternal()->setForm(formParser->getPayloadInternal()); + delete formParser; + formParser = NULL; + } + else if (element == "item") { + assert(currentItem); + getPayloadInternal()->addItem(*currentItem); + currentItem.reset(); + } + else if (element == "instructions") { + getPayloadInternal()->setInstructions(currentText); + } + else if (element == "nick") { + getPayloadInternal()->setNick(currentText); + } + else if (element == "first") { + getPayloadInternal()->setFirst(currentText); + } + else if (element == "last") { + getPayloadInternal()->setLast(currentText); + } + else if (element == "email") { + getPayloadInternal()->setEMail(currentText); + } + } + else if (level == ItemLevel && currentItem) { + if (element == "nick") { + currentItem->nick = currentText; + } + else if (element == "first") { + currentItem->first = currentText; + } + else if (element == "last") { + currentItem->last = currentText; + } + else if (element == "email") { + currentItem->email = currentText; + } + } } void SearchPayloadParser::handleCharacterData(const std::string& data) { - if (formParser) { - formParser->handleCharacterData(data); - } - else { - currentText += data; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h index bfcb86d..aa0cf4a 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h @@ -13,28 +13,28 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class SWIFTEN_API SearchPayloadParser : public GenericPayloadParser<SearchPayload> { - public: - SearchPayloadParser(); - ~SearchPayloadParser(); + class SWIFTEN_API SearchPayloadParser : public GenericPayloadParser<SearchPayload> { + public: + SearchPayloadParser(); + ~SearchPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2 - }; - int level; - FormParserFactory* formParserFactory; - FormParser* formParser; - std::string currentText; - boost::optional<SearchPayload::Item> currentItem; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level; + FormParserFactory* formParserFactory; + FormParser* formParser; + std::string currentText; + boost::optional<SearchPayload::Item> currentItem; + }; } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp index 7176403..43b8043 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp @@ -14,57 +14,57 @@ SecurityLabelParser::SecurityLabelParser() : level_(TopLevel), labelParser_(0) { } void SecurityLabelParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - if (level_ == DisplayMarkingOrLabelLevel) { - if (element == "displaymarking") { - currentText_ = ""; - getPayloadInternal()->setBackgroundColor(attributes.getAttribute("bgcolor")); - getPayloadInternal()->setForegroundColor(attributes.getAttribute("fgcolor")); - } - else if (element == "label" || element == "equivalentlabel") { - assert(!labelParser_); - labelParser_ = new SerializingParser(); - } - } - else if (level_ >= SecurityLabelLevel && labelParser_) { - labelParser_->handleStartElement(element, ns, attributes); - } + ++level_; + if (level_ == DisplayMarkingOrLabelLevel) { + if (element == "displaymarking") { + currentText_ = ""; + getPayloadInternal()->setBackgroundColor(attributes.getAttribute("bgcolor")); + getPayloadInternal()->setForegroundColor(attributes.getAttribute("fgcolor")); + } + else if (element == "label" || element == "equivalentlabel") { + assert(!labelParser_); + labelParser_ = new SerializingParser(); + } + } + else if (level_ >= SecurityLabelLevel && labelParser_) { + labelParser_->handleStartElement(element, ns, attributes); + } } void SecurityLabelParser::handleEndElement(const std::string& element, const std::string& ns) { - if (level_ == DisplayMarkingOrLabelLevel) { - if (element == "displaymarking") { - getPayloadInternal()->setDisplayMarking(currentText_); - } - else if (labelParser_) { - if (element == "label") { - getPayloadInternal()->setLabel(labelParser_->getResult()); - } - else { - getPayloadInternal()->addEquivalentLabel(labelParser_->getResult()); - } - delete labelParser_; - labelParser_ = 0; - } - } - else if (labelParser_ && level_ >= SecurityLabelLevel) { - labelParser_->handleEndElement(element, ns); - } - --level_; + if (level_ == DisplayMarkingOrLabelLevel) { + if (element == "displaymarking") { + getPayloadInternal()->setDisplayMarking(currentText_); + } + else if (labelParser_) { + if (element == "label") { + getPayloadInternal()->setLabel(labelParser_->getResult()); + } + else { + getPayloadInternal()->addEquivalentLabel(labelParser_->getResult()); + } + delete labelParser_; + labelParser_ = 0; + } + } + else if (labelParser_ && level_ >= SecurityLabelLevel) { + labelParser_->handleEndElement(element, ns); + } + --level_; } void SecurityLabelParser::handleCharacterData(const std::string& data) { - if (labelParser_) { - labelParser_->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (labelParser_) { + labelParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } } boost::shared_ptr<SecurityLabel> SecurityLabelParser::getLabelPayload() const { - return getPayloadInternal(); + return getPayloadInternal(); } } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h index 857df6a..d5b0466 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h @@ -11,25 +11,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API SecurityLabelParser : public GenericPayloadParser<SecurityLabel> { - public: - SecurityLabelParser(); + class SWIFTEN_API SecurityLabelParser : public GenericPayloadParser<SecurityLabel> { + public: + SecurityLabelParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - boost::shared_ptr<SecurityLabel> getLabelPayload() const; - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - DisplayMarkingOrLabelLevel = 2, - SecurityLabelLevel = 3 - }; - int level_; - SerializingParser* labelParser_; - std::string currentText_; - }; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + boost::shared_ptr<SecurityLabel> getLabelPayload() const; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + DisplayMarkingOrLabelLevel = 2, + SecurityLabelLevel = 3 + }; + int level_; + SerializingParser* labelParser_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h index 1eabb07..7e6d4fd 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> namespace Swift { - class SWIFTEN_API SecurityLabelParserFactory : public GenericPayloadParserFactory<SecurityLabelParser> { - public: - SecurityLabelParserFactory() : GenericPayloadParserFactory<SecurityLabelParser>("securitylabel", "urn:xmpp:sec-label:0") {} - }; + class SWIFTEN_API SecurityLabelParserFactory : public GenericPayloadParserFactory<SecurityLabelParser> { + public: + SecurityLabelParserFactory() : GenericPayloadParserFactory<SecurityLabelParser>("securitylabel", "urn:xmpp:sec-label:0") {} + }; } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp index 715929a..0aa4100 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp @@ -14,62 +14,62 @@ namespace Swift { SecurityLabelsCatalogParser::SecurityLabelsCatalogParser() : level_(TopLevel), labelParser_(0) { - labelParserFactory_ = new SecurityLabelParserFactory(); + labelParserFactory_ = new SecurityLabelParserFactory(); } SecurityLabelsCatalogParser::~SecurityLabelsCatalogParser() { - delete labelParserFactory_; + delete labelParserFactory_; } void SecurityLabelsCatalogParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - if (level_ == PayloadLevel) { - getPayloadInternal()->setTo(JID(attributes.getAttribute("to"))); - getPayloadInternal()->setName(attributes.getAttribute("name")); - getPayloadInternal()->setDescription(attributes.getAttribute("desc")); - } - else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { - currentItem_ = boost::make_shared<SecurityLabelsCatalog::Item>(); - currentItem_->setSelector(attributes.getAttribute("selector")); - currentItem_->setIsDefault(attributes.getBoolAttribute("default", false)); - } - else if (level_ == LabelLevel) { - assert(!labelParser_); - if (labelParserFactory_->canParse(element, ns, attributes)) { - labelParser_ = dynamic_cast<SecurityLabelParser*>(labelParserFactory_->createPayloadParser()); - assert(labelParser_); - } - } + ++level_; + if (level_ == PayloadLevel) { + getPayloadInternal()->setTo(JID(attributes.getAttribute("to"))); + getPayloadInternal()->setName(attributes.getAttribute("name")); + getPayloadInternal()->setDescription(attributes.getAttribute("desc")); + } + else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { + currentItem_ = boost::make_shared<SecurityLabelsCatalog::Item>(); + currentItem_->setSelector(attributes.getAttribute("selector")); + currentItem_->setIsDefault(attributes.getBoolAttribute("default", false)); + } + else if (level_ == LabelLevel) { + assert(!labelParser_); + if (labelParserFactory_->canParse(element, ns, attributes)) { + labelParser_ = dynamic_cast<SecurityLabelParser*>(labelParserFactory_->createPayloadParser()); + assert(labelParser_); + } + } - if (labelParser_) { - labelParser_->handleStartElement(element, ns, attributes); - } + if (labelParser_) { + labelParser_->handleStartElement(element, ns, attributes); + } } void SecurityLabelsCatalogParser::handleEndElement(const std::string& element, const std::string& ns) { - if (labelParser_) { - labelParser_->handleEndElement(element, ns); - } - if (level_ == LabelLevel && labelParser_ && currentItem_) { - boost::shared_ptr<SecurityLabel> currentLabel = labelParser_->getLabelPayload(); - assert(currentLabel); - currentItem_->setLabel(currentLabel); - delete labelParser_; - labelParser_ = 0; - } - else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { - if (currentItem_) { - getPayloadInternal()->addItem(SecurityLabelsCatalog::Item(*currentItem_)); - currentItem_.reset(); - } - } - --level_; + if (labelParser_) { + labelParser_->handleEndElement(element, ns); + } + if (level_ == LabelLevel && labelParser_ && currentItem_) { + boost::shared_ptr<SecurityLabel> currentLabel = labelParser_->getLabelPayload(); + assert(currentLabel); + currentItem_->setLabel(currentLabel); + delete labelParser_; + labelParser_ = 0; + } + else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { + if (currentItem_) { + getPayloadInternal()->addItem(SecurityLabelsCatalog::Item(*currentItem_)); + currentItem_.reset(); + } + } + --level_; } void SecurityLabelsCatalogParser::handleCharacterData(const std::string& data) { - if (labelParser_) { - labelParser_->handleCharacterData(data); - } + if (labelParser_) { + labelParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h index 689ebb8..bb44369 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h @@ -11,28 +11,28 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SecurityLabelParserFactory; - class SecurityLabelParser; + class SecurityLabelParserFactory; + class SecurityLabelParser; - class SWIFTEN_API SecurityLabelsCatalogParser : public GenericPayloadParser<SecurityLabelsCatalog> { - public: - SecurityLabelsCatalogParser(); - ~SecurityLabelsCatalogParser(); + class SWIFTEN_API SecurityLabelsCatalogParser : public GenericPayloadParser<SecurityLabelsCatalog> { + public: + SecurityLabelsCatalogParser(); + ~SecurityLabelsCatalogParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2, - LabelLevel = 3 - }; - int level_; - SecurityLabelParserFactory* labelParserFactory_; - SecurityLabelParser* labelParser_; - boost::shared_ptr<SecurityLabelsCatalog::Item> currentItem_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2, + LabelLevel = 3 + }; + int level_; + SecurityLabelParserFactory* labelParserFactory_; + SecurityLabelParser* labelParser_; + boost::shared_ptr<SecurityLabelsCatalog::Item> currentItem_; + }; } diff --git a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp index c0122fa..56b62c8 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp @@ -12,27 +12,27 @@ SoftwareVersionParser::SoftwareVersionParser() : level_(TopLevel) { } void SoftwareVersionParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void SoftwareVersionParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel) { - if (element == "name") { - getPayloadInternal()->setName(currentText_); - } - else if (element == "version") { - getPayloadInternal()->setVersion(currentText_); - } - else if (element == "os") { - getPayloadInternal()->setOS(currentText_); - } - currentText_ = ""; - } + --level_; + if (level_ == PayloadLevel) { + if (element == "name") { + getPayloadInternal()->setName(currentText_); + } + else if (element == "version") { + getPayloadInternal()->setVersion(currentText_); + } + else if (element == "os") { + getPayloadInternal()->setOS(currentText_); + } + currentText_ = ""; + } } void SoftwareVersionParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h index a66dd1a..29f700c 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API SoftwareVersionParser : public GenericPayloadParser<SoftwareVersion> { - public: - SoftwareVersionParser(); + class SWIFTEN_API SoftwareVersionParser : public GenericPayloadParser<SoftwareVersion> { + public: + SoftwareVersionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - std::string currentText_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/StartSessionParser.h b/Swiften/Parser/PayloadParsers/StartSessionParser.h index d5a9c2e..e0013af 100644 --- a/Swiften/Parser/PayloadParsers/StartSessionParser.h +++ b/Swiften/Parser/PayloadParsers/StartSessionParser.h @@ -11,12 +11,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StartSessionParser : public GenericPayloadParser<StartSession> { - public: - StartSessionParser() {} + class SWIFTEN_API StartSessionParser : public GenericPayloadParser<StartSession> { + public: + StartSessionParser() {} - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} - virtual void handleEndElement(const std::string&, const std::string&) {} - virtual void handleCharacterData(const std::string&) {} - }; + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} + virtual void handleEndElement(const std::string&, const std::string&) {} + virtual void handleCharacterData(const std::string&) {} + }; } diff --git a/Swiften/Parser/PayloadParsers/StatusParser.cpp b/Swiften/Parser/PayloadParsers/StatusParser.cpp index a8b49f4..128a675 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusParser.cpp @@ -12,18 +12,18 @@ StatusParser::StatusParser() : level_(0) { } void StatusParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void StatusParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void StatusParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/StatusParser.h b/Swiften/Parser/PayloadParsers/StatusParser.h index 689897b..cebf0cd 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.h +++ b/Swiften/Parser/PayloadParsers/StatusParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StatusParser : public GenericPayloadParser<Status> { - public: - StatusParser(); + class SWIFTEN_API StatusParser : public GenericPayloadParser<Status> { + public: + StatusParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp index 5fac74c..761a411 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp @@ -12,32 +12,32 @@ StatusShowParser::StatusShowParser() : level_(0) { } void StatusShowParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void StatusShowParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - if (text_ == "away") { - getPayloadInternal()->setType(StatusShow::Away); - } - else if (text_ == "chat") { - getPayloadInternal()->setType(StatusShow::FFC); - } - else if (text_ == "xa") { - getPayloadInternal()->setType(StatusShow::XA); - } - else if (text_ == "dnd") { - getPayloadInternal()->setType(StatusShow::DND); - } - else { - getPayloadInternal()->setType(StatusShow::Online); - } - } + --level_; + if (level_ == 0) { + if (text_ == "away") { + getPayloadInternal()->setType(StatusShow::Away); + } + else if (text_ == "chat") { + getPayloadInternal()->setType(StatusShow::FFC); + } + else if (text_ == "xa") { + getPayloadInternal()->setType(StatusShow::XA); + } + else if (text_ == "dnd") { + getPayloadInternal()->setType(StatusShow::DND); + } + else { + getPayloadInternal()->setType(StatusShow::Online); + } + } } void StatusShowParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/StatusShowParser.h b/Swiften/Parser/PayloadParsers/StatusShowParser.h index 2bdcd56..8cbb365 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.h +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StatusShowParser : public GenericPayloadParser<StatusShow> { - public: - StatusShowParser(); + class SWIFTEN_API StatusShowParser : public GenericPayloadParser<StatusShow> { + public: + StatusShowParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/StorageParser.cpp b/Swiften/Parser/PayloadParsers/StorageParser.cpp index 1a131a9..9628ea8 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/StorageParser.cpp @@ -14,53 +14,53 @@ StorageParser::StorageParser() : level(TopLevel) { } void StorageParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == BookmarkLevel) { - if (element == "conference") { - assert(!room); - room = Storage::Room(); - room->autoJoin = attributes.getBoolAttribute("autojoin", false); - room->jid = JID(attributes.getAttribute("jid")); - room->name = attributes.getAttribute("name"); - } - else if (element == "url") { - assert(!url); - url = Storage::URL(); - url->name = attributes.getAttribute("name"); - url->url = attributes.getAttribute("url"); - } - } - else if (level == DetailLevel) { - currentText = ""; - } - ++level; + if (level == BookmarkLevel) { + if (element == "conference") { + assert(!room); + room = Storage::Room(); + room->autoJoin = attributes.getBoolAttribute("autojoin", false); + room->jid = JID(attributes.getAttribute("jid")); + room->name = attributes.getAttribute("name"); + } + else if (element == "url") { + assert(!url); + url = Storage::URL(); + url->name = attributes.getAttribute("name"); + url->url = attributes.getAttribute("url"); + } + } + else if (level == DetailLevel) { + currentText = ""; + } + ++level; } void StorageParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == BookmarkLevel) { - if (element == "conference") { - assert(room); - getPayloadInternal()->addRoom(*room); - room.reset(); - } - else if (element == "url") { - assert(url); - getPayloadInternal()->addURL(*url); - url.reset(); - } - } - else if (level == DetailLevel && room) { - if (element == "nick") { - room->nick = currentText; - } - else if (element == "password") { - room->password = currentText; - } - } + --level; + if (level == BookmarkLevel) { + if (element == "conference") { + assert(room); + getPayloadInternal()->addRoom(*room); + room.reset(); + } + else if (element == "url") { + assert(url); + getPayloadInternal()->addURL(*url); + url.reset(); + } + } + else if (level == DetailLevel && room) { + if (element == "nick") { + room->nick = currentText; + } + else if (element == "password") { + room->password = currentText; + } + } } void StorageParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } } diff --git a/Swiften/Parser/PayloadParsers/StorageParser.h b/Swiften/Parser/PayloadParsers/StorageParser.h index 0fea4c9..92417c2 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.h +++ b/Swiften/Parser/PayloadParsers/StorageParser.h @@ -13,23 +13,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StorageParser : public GenericPayloadParser<Storage> { - public: - StorageParser(); + class SWIFTEN_API StorageParser : public GenericPayloadParser<Storage> { + public: + StorageParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - BookmarkLevel = 1, - DetailLevel = 2 - }; - int level; - std::string currentText; - boost::optional<Storage::Room> room; - boost::optional<Storage::URL> url; - }; + private: + enum Level { + TopLevel = 0, + BookmarkLevel = 1, + DetailLevel = 2 + }; + int level; + std::string currentText; + boost::optional<Storage::Room> room; + boost::optional<Storage::URL> url; + }; } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp index da5aa79..ab5dbbe 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp @@ -21,55 +21,55 @@ namespace Swift { StreamInitiationFileInfoParser::StreamInitiationFileInfoParser() : level(0), parseDescription(false) { - + } void StreamInitiationFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 0) { - getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); - getPayloadInternal()->setHash(attributes.getAttributeValue("hash").get_value_or("")); - getPayloadInternal()->setAlgo(attributes.getAttributeValue("algo").get_value_or("md5")); - try { - getPayloadInternal()->setSize(boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("size").get_value_or("0"))); - } catch (boost::bad_lexical_cast &) { - getPayloadInternal()->setSize(0); - } - getPayloadInternal()->setDate(stringToDateTime(attributes.getAttributeValue("date").get_value_or(""))); - } else if (level == 1) { - if (element == "desc") { - parseDescription = true; - } else { - parseDescription = false; - if (element == "range") { - boost::uintmax_t offset = 0; - try { - offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0")); - } catch (boost::bad_lexical_cast &) { - offset = 0; - } - if (offset == 0) { - getPayloadInternal()->setSupportsRangeRequests(true); - } else { - getPayloadInternal()->setRangeOffset(offset); - } - } - } - } - ++level; + if (level == 0) { + getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); + getPayloadInternal()->setHash(attributes.getAttributeValue("hash").get_value_or("")); + getPayloadInternal()->setAlgo(attributes.getAttributeValue("algo").get_value_or("md5")); + try { + getPayloadInternal()->setSize(boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("size").get_value_or("0"))); + } catch (boost::bad_lexical_cast &) { + getPayloadInternal()->setSize(0); + } + getPayloadInternal()->setDate(stringToDateTime(attributes.getAttributeValue("date").get_value_or(""))); + } else if (level == 1) { + if (element == "desc") { + parseDescription = true; + } else { + parseDescription = false; + if (element == "range") { + boost::uintmax_t offset = 0; + try { + offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0")); + } catch (boost::bad_lexical_cast &) { + offset = 0; + } + if (offset == 0) { + getPayloadInternal()->setSupportsRangeRequests(true); + } else { + getPayloadInternal()->setRangeOffset(offset); + } + } + } + } + ++level; } void StreamInitiationFileInfoParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (parseDescription && element == "desc") { - parseDescription = false; - getPayloadInternal()->setDescription(desc); - } + --level; + if (parseDescription && element == "desc") { + parseDescription = false; + getPayloadInternal()->setDescription(desc); + } } void StreamInitiationFileInfoParser::handleCharacterData(const std::string& data) { - if (parseDescription) { - desc += data; - } + if (parseDescription) { + desc += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h index 722797d..a1e386c 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h @@ -19,17 +19,17 @@ namespace Swift { class SWIFTEN_API StreamInitiationFileInfoParser : public GenericPayloadParser<StreamInitiationFileInfo> { - public: - StreamInitiationFileInfoParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - int level; - bool parseDescription; - std::string desc; + public: + StreamInitiationFileInfoParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level; + bool parseDescription; + std::string desc; }; } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index 32c85a3..8be93c4 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -20,101 +20,101 @@ namespace Swift { StreamInitiationParser::StreamInitiationParser() : level(TopLevel), formParser(0), inFile(false), inFeature(false) { - formParserFactory = new FormParserFactory(); + formParserFactory = new FormParserFactory(); } StreamInitiationParser::~StreamInitiationParser() { - delete formParserFactory; + delete formParserFactory; } void StreamInitiationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == TopLevel) { - getPayloadInternal()->setID(attributes.getAttribute("id")); - if (!attributes.getAttribute("profile").empty()) { - getPayloadInternal()->setIsFileTransfer(attributes.getAttribute("profile") == FILE_TRANSFER_NS); - } - } - else if (level == PayloadLevel) { - if (element == "file") { - inFile = true; - currentFile = StreamInitiationFileInfo(); - currentFile.setName(attributes.getAttribute("name")); - try { - currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size"))); - } - catch (boost::bad_lexical_cast&) { - } - } - else if (element == "feature" && ns == FEATURE_NEG_NS) { - inFeature = true; - } - } - else if (level == FileOrFeatureLevel) { - if (inFile && element == "desc") { - currentText.clear(); - } - else if (inFeature && formParserFactory->canParse(element, ns, attributes)) { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - } + if (level == TopLevel) { + getPayloadInternal()->setID(attributes.getAttribute("id")); + if (!attributes.getAttribute("profile").empty()) { + getPayloadInternal()->setIsFileTransfer(attributes.getAttribute("profile") == FILE_TRANSFER_NS); + } + } + else if (level == PayloadLevel) { + if (element == "file") { + inFile = true; + currentFile = StreamInitiationFileInfo(); + currentFile.setName(attributes.getAttribute("name")); + try { + currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size"))); + } + catch (boost::bad_lexical_cast&) { + } + } + else if (element == "feature" && ns == FEATURE_NEG_NS) { + inFeature = true; + } + } + else if (level == FileOrFeatureLevel) { + if (inFile && element == "desc") { + currentText.clear(); + } + else if (inFeature && formParserFactory->canParse(element, ns, attributes)) { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } - ++level; + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } + ++level; } void StreamInitiationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (formParser) { - formParser->handleEndElement(element, ns); - } - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (element == "file") { - getPayloadInternal()->setFileInfo(currentFile); - inFile = false; - } - else if (element == "feature" && ns == FEATURE_NEG_NS) { - inFeature = false; - } - } - else if (level == FileOrFeatureLevel) { - if (inFile && element == "desc") { - currentFile.setDescription(currentText); - } - else if (formParser) { - Form::ref form = formParser->getPayloadInternal(); - if (form) { - FormField::ref field = boost::dynamic_pointer_cast<FormField>(form->getField("stream-method")); - if (field) { - if (form->getType() == Form::FormType) { - foreach (const FormField::Option& option, field->getOptions()) { - getPayloadInternal()->addProvidedMethod(option.value); - } - } - else if (form->getType() == Form::SubmitType) { - if (!field->getValues().empty()) { - getPayloadInternal()->setRequestedMethod(field->getValues()[0]); - } - } - } - } - delete formParser; - formParser = NULL; - } - } + --level; + if (formParser) { + formParser->handleEndElement(element, ns); + } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (element == "file") { + getPayloadInternal()->setFileInfo(currentFile); + inFile = false; + } + else if (element == "feature" && ns == FEATURE_NEG_NS) { + inFeature = false; + } + } + else if (level == FileOrFeatureLevel) { + if (inFile && element == "desc") { + currentFile.setDescription(currentText); + } + else if (formParser) { + Form::ref form = formParser->getPayloadInternal(); + if (form) { + FormField::ref field = boost::dynamic_pointer_cast<FormField>(form->getField("stream-method")); + if (field) { + if (form->getType() == Form::FormType) { + foreach (const FormField::Option& option, field->getOptions()) { + getPayloadInternal()->addProvidedMethod(option.value); + } + } + else if (form->getType() == Form::SubmitType) { + if (!field->getValues().empty()) { + getPayloadInternal()->setRequestedMethod(field->getValues()[0]); + } + } + } + } + delete formParser; + formParser = NULL; + } + } } void StreamInitiationParser::handleCharacterData(const std::string& data) { - if (formParser) { - formParser->handleCharacterData(data); - } - else { - currentText += data; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h index 66ce778..42de8ba 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h @@ -13,31 +13,31 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class SWIFTEN_API StreamInitiationParser : public GenericPayloadParser<StreamInitiation> { - public: - StreamInitiationParser(); - ~StreamInitiationParser(); + class SWIFTEN_API StreamInitiationParser : public GenericPayloadParser<StreamInitiation> { + public: + StreamInitiationParser(); + ~StreamInitiationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - FileOrFeatureLevel = 2, - FormOrDescriptionLevel = 3 - }; - int level; - FormParserFactory* formParserFactory; - FormParser* formParser; - bool inFile; - bool inFeature; - StreamInitiationFileInfo currentFile; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + FileOrFeatureLevel = 2, + FormOrDescriptionLevel = 3 + }; + int level; + FormParserFactory* formParserFactory; + FormParser* formParser; + bool inFile; + bool inFeature; + StreamInitiationFileInfo currentFile; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.cpp b/Swiften/Parser/PayloadParsers/SubjectParser.cpp index 7b2d885..19a5488 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.cpp +++ b/Swiften/Parser/PayloadParsers/SubjectParser.cpp @@ -12,20 +12,20 @@ SubjectParser::SubjectParser() : level_(0) { } void SubjectParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void SubjectParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void SubjectParser::handleCharacterData(const std::string& data) { - if (level_ == 1) { - text_ += data; - } + if (level_ == 1) { + text_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.h b/Swiften/Parser/PayloadParsers/SubjectParser.h index 804c50b..a400283 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.h +++ b/Swiften/Parser/PayloadParsers/SubjectParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API SubjectParser : public GenericPayloadParser<Subject> { - public: - SubjectParser(); + class SWIFTEN_API SubjectParser : public GenericPayloadParser<Subject> { + public: + SubjectParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ThreadParser.cpp b/Swiften/Parser/PayloadParsers/ThreadParser.cpp index 0d0aca8..f416d32 100644 --- a/Swiften/Parser/PayloadParsers/ThreadParser.cpp +++ b/Swiften/Parser/PayloadParsers/ThreadParser.cpp @@ -17,23 +17,23 @@ ThreadParser::~ThreadParser() { } void ThreadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - ++level_; - if (element == "thread") { - getPayloadInternal()->setParent(attributes.getAttributeValue("parent").get_value_or("")); - } + ++level_; + if (element == "thread") { + getPayloadInternal()->setParent(attributes.getAttributeValue("parent").get_value_or("")); + } } void ThreadParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void ThreadParser::handleCharacterData(const std::string& data) { - if (level_ == 1) { - text_ += data; - } + if (level_ == 1) { + text_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/ThreadParser.h b/Swiften/Parser/PayloadParsers/ThreadParser.h index 270ea99..371c535 100644 --- a/Swiften/Parser/PayloadParsers/ThreadParser.h +++ b/Swiften/Parser/PayloadParsers/ThreadParser.h @@ -11,17 +11,17 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ThreadParser : public GenericPayloadParser<Thread> { - public: - ThreadParser(); - virtual ~ThreadParser(); + class SWIFTEN_API ThreadParser : public GenericPayloadParser<Thread> { + public: + ThreadParser(); + virtual ~ThreadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp index 4a104c8..17a800e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp @@ -23,55 +23,55 @@ using namespace Swift; class BlockParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BlockParserTest); - CPPUNIT_TEST(testExample4); - CPPUNIT_TEST(testExample6); - CPPUNIT_TEST(testExample10); - CPPUNIT_TEST_SUITE_END(); - - public: - BlockParserTest() {} - - void testExample4() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<blocklist xmlns='urn:xmpp:blocking'>" - "<item jid='romeo@montague.net'/>" - "<item jid='iago@shakespeare.lit'/>" - "</blocklist>")); - - BlockListPayload* payload = dynamic_cast<BlockListPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(2 == payload->getItems().size()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); - CPPUNIT_ASSERT_EQUAL(JID("iago@shakespeare.lit"), payload->getItems()[1]); - } - - void testExample6() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<block xmlns='urn:xmpp:blocking'>" - "<item jid='romeo@montague.net'/>" - "</block>")); - - BlockPayload* payload = dynamic_cast<BlockPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(1 == payload->getItems().size()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); - } - - void testExample10() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<unblock xmlns='urn:xmpp:blocking'>" - "<item jid='romeo@montague.net'/>" - "</unblock>")); - - UnblockPayload* payload = dynamic_cast<UnblockPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(1 == payload->getItems().size()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); - } + CPPUNIT_TEST_SUITE(BlockParserTest); + CPPUNIT_TEST(testExample4); + CPPUNIT_TEST(testExample6); + CPPUNIT_TEST(testExample10); + CPPUNIT_TEST_SUITE_END(); + + public: + BlockParserTest() {} + + void testExample4() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<blocklist xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>" + "<item jid='iago@shakespeare.lit'/>" + "</blocklist>")); + + BlockListPayload* payload = dynamic_cast<BlockListPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(2 == payload->getItems().size()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); + CPPUNIT_ASSERT_EQUAL(JID("iago@shakespeare.lit"), payload->getItems()[1]); + } + + void testExample6() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<block xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>" + "</block>")); + + BlockPayload* payload = dynamic_cast<BlockPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(1 == payload->getItems().size()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); + } + + void testExample10() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<unblock xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>" + "</unblock>")); + + UnblockPayload* payload = dynamic_cast<UnblockPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(1 == payload->getItems().size()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(BlockParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp index b409ed4..002da16 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp @@ -14,21 +14,21 @@ using namespace Swift; class BodyParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BodyParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(BodyParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - BodyParserTest() {} + public: + BodyParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<body>foo<baz>bar</baz>fum</body>")); + CPPUNIT_ASSERT(parser.parse("<body>foo<baz>bar</baz>fum</body>")); - Body* payload = dynamic_cast<Body*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); - } + Body* payload = dynamic_cast<Body*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(BodyParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp index 7700a5c..f85efb2 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp @@ -20,108 +20,108 @@ using namespace Swift; class CarbonsParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(CarbonsParserTest); - CPPUNIT_TEST(testParseExample3); - CPPUNIT_TEST(testParseExample6); - CPPUNIT_TEST(testParseExample12); - CPPUNIT_TEST(testParseExample14); - CPPUNIT_TEST(testParseExample15); - CPPUNIT_TEST_SUITE_END(); - - public: - CarbonsParserTest() {} - - /* - * Test parsing of example 3 in XEP-0280. - */ - void testParseExample3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<enable xmlns='urn:xmpp:carbons:2' />")); - - CarbonsEnable::ref enable = parser.getPayload<CarbonsEnable>(); - CPPUNIT_ASSERT(enable); - } - - /* - * Test parsing of example 6 in XEP-0280. - */ - void testParseExample6() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<disable xmlns='urn:xmpp:carbons:2' />")); - - CarbonsDisable::ref disable = parser.getPayload<CarbonsDisable>(); - CPPUNIT_ASSERT(disable); - } - - /* - * Test parsing of example 12 in XEP-0280. - */ - void testParseExample12() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:carbons:2'>" - "<forwarded xmlns='urn:xmpp:forward:0'>" - "<message xmlns='jabber:client'" - " from='juliet@capulet.example/balcony'" - " to='romeo@montague.example/garden'" - " type='chat'>" - "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" - "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" - "</message>" - "</forwarded>" - "</received>")); - - CarbonsReceived::ref received = parser.getPayload<CarbonsReceived>(); - CPPUNIT_ASSERT(received); - - boost::shared_ptr<Forwarded> forwarded = received->getForwarded(); - CPPUNIT_ASSERT(forwarded); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); - CPPUNIT_ASSERT(message); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getFrom()); - - boost::shared_ptr<Thread> thread = message->getPayload<Thread>(); - CPPUNIT_ASSERT(thread); - CPPUNIT_ASSERT_EQUAL(std::string("0e3141cd80894871a68e6fe6b1ec56fa"), thread->getText()); - } - - /* - * Test parsing of example 14 in XEP-0280. - */ - void testParseExample14() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<sent xmlns='urn:xmpp:carbons:2'>" - "<forwarded xmlns='urn:xmpp:forward:0'>" - "<message xmlns='jabber:client'" - " to='juliet@capulet.example/balcony'" - " from='romeo@montague.example/home'" - " type='chat'>" - "<body>Neither, fair saint, if either thee dislike.</body>" - "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" - "</message>" - "</forwarded>" - "</sent>")); - - CarbonsSent::ref sent = parser.getPayload<CarbonsSent>(); - CPPUNIT_ASSERT(sent); - - boost::shared_ptr<Forwarded> forwarded = sent->getForwarded(); - CPPUNIT_ASSERT(forwarded); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); - CPPUNIT_ASSERT(message); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getTo()); - } - - /* - * Test parsing of example 15 in XEP-0280. - */ - void testParseExample15() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<private xmlns='urn:xmpp:carbons:2'/>")); - - CPPUNIT_ASSERT(parser.getPayload<CarbonsPrivate>()); - } + CPPUNIT_TEST_SUITE(CarbonsParserTest); + CPPUNIT_TEST(testParseExample3); + CPPUNIT_TEST(testParseExample6); + CPPUNIT_TEST(testParseExample12); + CPPUNIT_TEST(testParseExample14); + CPPUNIT_TEST(testParseExample15); + CPPUNIT_TEST_SUITE_END(); + + public: + CarbonsParserTest() {} + + /* + * Test parsing of example 3 in XEP-0280. + */ + void testParseExample3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<enable xmlns='urn:xmpp:carbons:2' />")); + + CarbonsEnable::ref enable = parser.getPayload<CarbonsEnable>(); + CPPUNIT_ASSERT(enable); + } + + /* + * Test parsing of example 6 in XEP-0280. + */ + void testParseExample6() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<disable xmlns='urn:xmpp:carbons:2' />")); + + CarbonsDisable::ref disable = parser.getPayload<CarbonsDisable>(); + CPPUNIT_ASSERT(disable); + } + + /* + * Test parsing of example 12 in XEP-0280. + */ + void testParseExample12() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:carbons:2'>" + "<forwarded xmlns='urn:xmpp:forward:0'>" + "<message xmlns='jabber:client'" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" + "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" + "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" + "</message>" + "</forwarded>" + "</received>")); + + CarbonsReceived::ref received = parser.getPayload<CarbonsReceived>(); + CPPUNIT_ASSERT(received); + + boost::shared_ptr<Forwarded> forwarded = received->getForwarded(); + CPPUNIT_ASSERT(forwarded); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(message); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getFrom()); + + boost::shared_ptr<Thread> thread = message->getPayload<Thread>(); + CPPUNIT_ASSERT(thread); + CPPUNIT_ASSERT_EQUAL(std::string("0e3141cd80894871a68e6fe6b1ec56fa"), thread->getText()); + } + + /* + * Test parsing of example 14 in XEP-0280. + */ + void testParseExample14() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<sent xmlns='urn:xmpp:carbons:2'>" + "<forwarded xmlns='urn:xmpp:forward:0'>" + "<message xmlns='jabber:client'" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" + "<body>Neither, fair saint, if either thee dislike.</body>" + "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" + "</message>" + "</forwarded>" + "</sent>")); + + CarbonsSent::ref sent = parser.getPayload<CarbonsSent>(); + CPPUNIT_ASSERT(sent); + + boost::shared_ptr<Forwarded> forwarded = sent->getForwarded(); + CPPUNIT_ASSERT(forwarded); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(message); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getTo()); + } + + /* + * Test parsing of example 15 in XEP-0280. + */ + void testParseExample15() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<private xmlns='urn:xmpp:carbons:2'/>")); + + CPPUNIT_ASSERT(parser.getPayload<CarbonsPrivate>()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(CarbonsParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp index c47682c..fa8d014 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp @@ -13,74 +13,74 @@ using namespace Swift; class CommandParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(CommandParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Result); - CPPUNIT_TEST(testParse_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(CommandParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Result); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; + public: + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<command xmlns='http://jabber.org/protocol/commands' node='list' action='prev' sessionid='myid'/>" - )); + CPPUNIT_ASSERT(parser.parse( + "<command xmlns='http://jabber.org/protocol/commands' node='list' action='prev' sessionid='myid'/>" + )); - Command::ref payload = parser.getPayload<Command>(); - CPPUNIT_ASSERT_EQUAL(Command::Prev, payload->getAction()); - CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getNode()); - CPPUNIT_ASSERT_EQUAL(std::string("myid"), payload->getSessionID()); - } + Command::ref payload = parser.getPayload<Command>(); + CPPUNIT_ASSERT_EQUAL(Command::Prev, payload->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("myid"), payload->getSessionID()); + } - void testParse_Result() { - PayloadsParserTester parser; + void testParse_Result() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed' sessionid='myid'>" - "<note type='warn'>Service 'httpd' has been configured.</note>" - "<note type='error'>I lied.</note>" - "<actions execute='next'>" - "<prev/>" - "<next/>" - "</actions>" - "</command>" - )); + CPPUNIT_ASSERT(parser.parse( + "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed' sessionid='myid'>" + "<note type='warn'>Service 'httpd' has been configured.</note>" + "<note type='error'>I lied.</note>" + "<actions execute='next'>" + "<prev/>" + "<next/>" + "</actions>" + "</command>" + )); - Command::ref payload = parser.getPayload<Command>(); - CPPUNIT_ASSERT_EQUAL(Command::Completed, payload->getStatus()); - std::vector<Command::Note> notes = payload->getNotes(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(notes.size())); - CPPUNIT_ASSERT_EQUAL(Command::Note::Warn, notes[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("Service 'httpd' has been configured."), notes[0].note); - CPPUNIT_ASSERT_EQUAL(Command::Note::Error, notes[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("I lied."), notes[1].note); - std::vector<Command::Action> actions = payload->getAvailableActions(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(actions.size())); - CPPUNIT_ASSERT_EQUAL(Command::Prev, actions[0]); - CPPUNIT_ASSERT_EQUAL(Command::Next, actions[1]); - CPPUNIT_ASSERT_EQUAL(Command::Next, payload->getExecuteAction()); - } + Command::ref payload = parser.getPayload<Command>(); + CPPUNIT_ASSERT_EQUAL(Command::Completed, payload->getStatus()); + std::vector<Command::Note> notes = payload->getNotes(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(notes.size())); + CPPUNIT_ASSERT_EQUAL(Command::Note::Warn, notes[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("Service 'httpd' has been configured."), notes[0].note); + CPPUNIT_ASSERT_EQUAL(Command::Note::Error, notes[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("I lied."), notes[1].note); + std::vector<Command::Action> actions = payload->getAvailableActions(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(actions.size())); + CPPUNIT_ASSERT_EQUAL(Command::Prev, actions[0]); + CPPUNIT_ASSERT_EQUAL(Command::Next, actions[1]); + CPPUNIT_ASSERT_EQUAL(Command::Next, payload->getExecuteAction()); + } - void testParse_Form() { - PayloadsParserTester parser; + void testParse_Form() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed'>" - "<x type=\"result\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "<instructions>Fill out this form to configure your new bot!</instructions>" - "</x>" - "</command>" - )); + CPPUNIT_ASSERT(parser.parse( + "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed'>" + "<x type=\"result\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "<instructions>Fill out this form to configure your new bot!</instructions>" + "</x>" + "</command>" + )); - Command::ref payload = parser.getPayload<Command>(); - Form::ref form = payload->getForm(); - CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), form->getTitle()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), form->getInstructions()); - CPPUNIT_ASSERT_EQUAL(Form::ResultType, form->getType()); - } + Command::ref payload = parser.getPayload<Command>(); + Form::ref form = payload->getForm(); + CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), form->getTitle()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), form->getInstructions()); + CPPUNIT_ASSERT_EQUAL(Form::ResultType, form->getType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(CommandParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp index 919c342..d18e1b4 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp @@ -15,29 +15,29 @@ using namespace Swift; class DeliveryReceiptParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DeliveryReceiptParserTest); - CPPUNIT_TEST(testParseXEP0184Example3); - CPPUNIT_TEST(testParseXEP0184Example4); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(DeliveryReceiptParserTest); + CPPUNIT_TEST(testParseXEP0184Example3); + CPPUNIT_TEST(testParseXEP0184Example4); + CPPUNIT_TEST_SUITE_END(); - public: - void testParseXEP0184Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<request xmlns='urn:xmpp:receipts'/>")); + public: + void testParseXEP0184Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<request xmlns='urn:xmpp:receipts'/>")); - DeliveryReceiptRequest::ref request = boost::dynamic_pointer_cast<DeliveryReceiptRequest>(parser.getPayload()); + DeliveryReceiptRequest::ref request = boost::dynamic_pointer_cast<DeliveryReceiptRequest>(parser.getPayload()); - CPPUNIT_ASSERT(request); - } + CPPUNIT_ASSERT(request); + } - void testParseXEP0184Example4() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>")); + void testParseXEP0184Example4() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>")); - DeliveryReceipt::ref receipt = boost::dynamic_pointer_cast<DeliveryReceipt>(parser.getPayload()); + DeliveryReceipt::ref receipt = boost::dynamic_pointer_cast<DeliveryReceipt>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("richard2-4.1.247"), receipt->getReceivedID()); - } + CPPUNIT_ASSERT_EQUAL(std::string("richard2-4.1.247"), receipt->getReceivedID()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index 35995c9..c23b1d0 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -13,91 +13,91 @@ using namespace Swift; class DiscoInfoParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DiscoInfoParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Node); - CPPUNIT_TEST(testParse_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(DiscoInfoParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Node); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; + public: + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"http://jabber.org/protocol/disco#info\">" - "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" - "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" - "<feature var=\"foo-feature\"/>" - "<feature var=\"bar-feature\"/>" - "<feature var=\"baz-feature\"/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" + "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" + "<feature var=\"foo-feature\"/>" + "<feature var=\"bar-feature\"/>" + "<feature var=\"baz-feature\"/>" + "</query>")); - DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); - CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); - CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); - CPPUNIT_ASSERT(payload->getNode().empty()); - } + DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); + CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); + CPPUNIT_ASSERT(payload->getNode().empty()); + } - void testParse_Node() { - PayloadsParserTester parser; + void testParse_Node() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"blahblah\">" - "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" - "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" - "<feature var=\"foo-feature\"/>" - "<feature var=\"bar-feature\"/>" - "<feature var=\"baz-feature\"/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"blahblah\">" + "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" + "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" + "<feature var=\"foo-feature\"/>" + "<feature var=\"bar-feature\"/>" + "<feature var=\"baz-feature\"/>" + "</query>")); - DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); - CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); - CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); - CPPUNIT_ASSERT_EQUAL(std::string("blahblah"), payload->getNode()); - } + DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); + CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); + CPPUNIT_ASSERT_EQUAL(std::string("blahblah"), payload->getNode()); + } - void testParse_Form() { - PayloadsParserTester parser; + void testParse_Form() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"http://jabber.org/protocol/disco#info\">" - "<feature var=\"foo-feature\"/>" - "<x type=\"submit\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "</x>" - "<feature var=\"bar-feature\"/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<feature var=\"foo-feature\"/>" + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "</x>" + "<feature var=\"bar-feature\"/>" + "</query>")); - DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getExtensions().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getExtensions()[0]->getTitle()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFeatures().size())); - CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); - } + DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getExtensions().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getExtensions()[0]->getTitle()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp index ee234ad..01db978 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp @@ -13,30 +13,30 @@ using namespace Swift; class DiscoItemsParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DiscoItemsParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands'>" - "<item jid='responder@domain' node='list' name='List Service Configurations'/>" - "<item jid='responder@domain' node='config' name='Configure Service'/>" - "</query>")); - - boost::shared_ptr<DiscoItems> payload = boost::dynamic_pointer_cast<DiscoItems>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); - CPPUNIT_ASSERT_EQUAL(std::string("List Service Configurations"), payload->getItems()[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getItems()[0].getNode()); - CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[0].getJID().toString()); - CPPUNIT_ASSERT_EQUAL(std::string("Configure Service"), payload->getItems()[1].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("config"), payload->getItems()[1].getNode()); - CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[1].getJID().toString()); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/commands"), payload->getNode()); - } + CPPUNIT_TEST_SUITE(DiscoItemsParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands'>" + "<item jid='responder@domain' node='list' name='List Service Configurations'/>" + "<item jid='responder@domain' node='config' name='Configure Service'/>" + "</query>")); + + boost::shared_ptr<DiscoItems> payload = boost::dynamic_pointer_cast<DiscoItems>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(std::string("List Service Configurations"), payload->getItems()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getItems()[0].getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[0].getJID().toString()); + CPPUNIT_ASSERT_EQUAL(std::string("Configure Service"), payload->getItems()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("config"), payload->getItems()[1].getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[1].getJID().toString()); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/commands"), payload->getNode()); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp index 6b0391d..529d573 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp @@ -14,44 +14,44 @@ using namespace Swift; class ErrorParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ErrorParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParseWithPayload); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<error type=\"modify\">" - "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" - "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" - "</error>")); - - ErrorPayload::ref payload = boost::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); - CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); - CPPUNIT_ASSERT(!payload->getPayload()); - } - - void testParseWithPayload() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<error type=\"modify\">" - "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" - "<delay xmlns='urn:xmpp:delay' from='juliet@capulet.com/balcony' stamp='2002-09-10T23:41:07Z'/>" - "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" - "</error>")); - - ErrorPayload::ref payload = boost::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); - CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); - CPPUNIT_ASSERT(boost::dynamic_pointer_cast<Delay>(payload->getPayload())); - } + CPPUNIT_TEST_SUITE(ErrorParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParseWithPayload); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<error type=\"modify\">" + "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" + "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" + "</error>")); + + ErrorPayload::ref payload = boost::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); + CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); + CPPUNIT_ASSERT(!payload->getPayload()); + } + + void testParseWithPayload() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<error type=\"modify\">" + "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" + "<delay xmlns='urn:xmpp:delay' from='juliet@capulet.com/balcony' stamp='2002-09-10T23:41:07Z'/>" + "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" + "</error>")); + + ErrorPayload::ref payload = boost::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); + CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); + CPPUNIT_ASSERT(boost::dynamic_pointer_cast<Delay>(payload->getPayload())); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp index 0c70b5c..4ffc776 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp @@ -13,216 +13,216 @@ using namespace Swift; class FormParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(FormParserTest); - CPPUNIT_TEST(testParse_FormInformation); - CPPUNIT_TEST(testParse_FormLayout); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_FormItems); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_FormInformation() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<x type=\"submit\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "<instructions>Fill out this form to configure your new bot!</instructions>" - "</x>" - )); - - Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getTitle()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), payload->getInstructions()); - CPPUNIT_ASSERT_EQUAL(Form::SubmitType, payload->getType()); - } - - void testParse_FormLayout() { - PayloadsParserTester parser; - - // P1 = page one, S1 = section one, F1 = field one, T1 = text one - CPPUNIT_ASSERT(parser.parse( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" - "<reportedref/>" - "<text>P1T1</text>" - "<fieldref var=\"P1F1\"/>" - "<section label=\"P1S1\">" - "<text>P1S1T1</text>" - "<fieldref var=\"P1S1F1\"/>" - "</section>" - "</page>" - "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" - "<section label=\"P2S1\">" - "<section label=\"P2S2\">" - "<section label=\"P2S3\"/>" - "</section>" - "</section>" - "</page>" - "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>" - "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>" - "</x>")); - - Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getFields().size())); - // PAGE ONE - parsing of element types - CPPUNIT_ASSERT_EQUAL(std::string("P1"), payload->getPages()[0]->getLabel()); - CPPUNIT_ASSERT(payload->getPages()[0]->getReportedRefs()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("P1T1"), payload->getPages()[0]->getTextElements()[0]->getTextString()); - CPPUNIT_ASSERT_EQUAL(std::string("P1F1"), payload->getPages()[0]->getFields()[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("P1S1"), payload->getPages()[0]->getChildSections()[0]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P1S1T1"), payload->getPages()[0]->getChildSections()[0]->getTextElements()[0]->getTextString()); - CPPUNIT_ASSERT_EQUAL(std::string("P1S1F1"), payload->getPages()[0]->getChildSections()[0]->getFields()[0]->getName()); - // PAGE TWO - parsing of nested elements - CPPUNIT_ASSERT_EQUAL(std::string("P2"), payload->getPages()[1]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P2S1"), payload->getPages()[1]->getChildSections()[0]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P2S2"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P2S3"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getChildSections()[0]->getLabel()); - } - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:bot</value>" - "</field>" - "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>" - "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>" - "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>" - "<field label=\"Public bot?\" type=\"boolean\" var=\"public\">" - "<required/>" - "<value>1</value>" - "</field>" - "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" - "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" - "<option label=\"Contests\"><value>contests</value></option>" - "<option label=\"News\"><value>news</value></option>" - "<option label=\"Polls\"><value>polls</value></option>" - "<option label=\"Reminders\"><value>reminders</value></option>" - "<option label=\"Search\"><value>search</value></option>" - "<value>news</value>" - "<value>search</value>" - "</field>" - "<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">" - "<value>20</value>" - "<option label=\"10\"><value>10</value></option>" - "<option label=\"20\"><value>20</value></option>" - "<option label=\"30\"><value>30</value></option>" - "<option label=\"50\"><value>50</value></option>" - "<option label=\"100\"><value>100</value></option>" - "<option label=\"None\"><value>none</value></option>" - "</field>" - "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">" - "<desc>Tell all your friends about your new bot!</desc>" - "<value>foo@bar.com</value>" - "<value>baz@fum.org</value>" - "</field>" - "<field var=\"untyped\">" - "<value>foo</value>" - "</field>" - "</x>")); - - Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - - CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size())); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), payload->getFields()[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("FORM_TYPE"), payload->getFields()[0]->getName()); - CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired()); - - CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), payload->getFields()[1]->getValues()[0]); - - CPPUNIT_ASSERT_EQUAL(std::string("The name of your bot"), payload->getFields()[2]->getLabel()); - - CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue()); - - CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue()); - CPPUNIT_ASSERT(payload->getFields()[4]->getRequired()); - CPPUNIT_ASSERT_EQUAL(std::string("1"), payload->getFields()[4]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFields()[6]->getValues().size())); - CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getValues()[1]); - CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Contests"), payload->getFields()[6]->getOptions()[0].label); - CPPUNIT_ASSERT_EQUAL(std::string("contests"), payload->getFields()[6]->getOptions()[0].value); - CPPUNIT_ASSERT_EQUAL(std::string("News"), payload->getFields()[6]->getOptions()[1].label); - CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value); - - CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]); - - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), payload->getFields()[8]->getJIDMultiValue(0)); - CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), payload->getFields()[8]->getJIDMultiValue(1)); - CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription()); - - CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->getFields()[9]->getValues()[0]); - } - - void testParse_FormItems() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<x xmlns='jabber:x:data' type='result'>" - "<field type='hidden' var='FORM_TYPE'>" - "<value>jabber:iq:search</value>" - "</field>" - "<reported>" - "<field var='first' label='Given Name' type='text-single'/>" - "<field var='last' label='Family Name' type='text-single'/>" - "<field var='jid' label='Jabber ID' type='jid-single'/>" - "<field var='x-gender' label='Gender' type='list-single'/>" - "</reported>" - "<item>" - "<field var='first'><value>Benvolio</value></field>" - "<field var='last'><value>Montague</value></field>" - "<field var='jid'><value>benvolio@montague.net</value></field>" - "<field var='x-gender'><value>male</value></field>" - "</item>" - "<item>" - "<field var='first'><value>Romeo</value></field>" - "<field var='last'><value>Montague</value></field>" - "<field var='jid'><value>romeo@montague.net</value></field>" - "<field var='x-gender'><value>male</value></field>" - "</item>" - "</x>")); - - Form* dataForm = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT(dataForm); - - Form::FormItem reported = dataForm->getReportedFields(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); - - std::vector<Form::FormItem> items = dataForm->getItems(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - Form::FormItem item = items[0]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - boost::shared_ptr<FormField> jidField = item[2]; - CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getJIDSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - - item = items[1]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - jidField = item[2]; - CPPUNIT_ASSERT(jidField); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getJIDSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - } + CPPUNIT_TEST_SUITE(FormParserTest); + CPPUNIT_TEST(testParse_FormInformation); + CPPUNIT_TEST(testParse_FormLayout); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_FormItems); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_FormInformation() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "<instructions>Fill out this form to configure your new bot!</instructions>" + "</x>" + )); + + Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getTitle()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), payload->getInstructions()); + CPPUNIT_ASSERT_EQUAL(Form::SubmitType, payload->getType()); + } + + void testParse_FormLayout() { + PayloadsParserTester parser; + + // P1 = page one, S1 = section one, F1 = field one, T1 = text one + CPPUNIT_ASSERT(parser.parse( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" + "<reportedref/>" + "<text>P1T1</text>" + "<fieldref var=\"P1F1\"/>" + "<section label=\"P1S1\">" + "<text>P1S1T1</text>" + "<fieldref var=\"P1S1F1\"/>" + "</section>" + "</page>" + "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" + "<section label=\"P2S1\">" + "<section label=\"P2S2\">" + "<section label=\"P2S3\"/>" + "</section>" + "</section>" + "</page>" + "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>" + "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>" + "</x>")); + + Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getFields().size())); + // PAGE ONE - parsing of element types + CPPUNIT_ASSERT_EQUAL(std::string("P1"), payload->getPages()[0]->getLabel()); + CPPUNIT_ASSERT(payload->getPages()[0]->getReportedRefs()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("P1T1"), payload->getPages()[0]->getTextElements()[0]->getTextString()); + CPPUNIT_ASSERT_EQUAL(std::string("P1F1"), payload->getPages()[0]->getFields()[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("P1S1"), payload->getPages()[0]->getChildSections()[0]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P1S1T1"), payload->getPages()[0]->getChildSections()[0]->getTextElements()[0]->getTextString()); + CPPUNIT_ASSERT_EQUAL(std::string("P1S1F1"), payload->getPages()[0]->getChildSections()[0]->getFields()[0]->getName()); + // PAGE TWO - parsing of nested elements + CPPUNIT_ASSERT_EQUAL(std::string("P2"), payload->getPages()[1]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P2S1"), payload->getPages()[1]->getChildSections()[0]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P2S2"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P2S3"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getChildSections()[0]->getLabel()); + } + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:bot</value>" + "</field>" + "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>" + "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>" + "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>" + "<field label=\"Public bot?\" type=\"boolean\" var=\"public\">" + "<required/>" + "<value>1</value>" + "</field>" + "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" + "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" + "<option label=\"Contests\"><value>contests</value></option>" + "<option label=\"News\"><value>news</value></option>" + "<option label=\"Polls\"><value>polls</value></option>" + "<option label=\"Reminders\"><value>reminders</value></option>" + "<option label=\"Search\"><value>search</value></option>" + "<value>news</value>" + "<value>search</value>" + "</field>" + "<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">" + "<value>20</value>" + "<option label=\"10\"><value>10</value></option>" + "<option label=\"20\"><value>20</value></option>" + "<option label=\"30\"><value>30</value></option>" + "<option label=\"50\"><value>50</value></option>" + "<option label=\"100\"><value>100</value></option>" + "<option label=\"None\"><value>none</value></option>" + "</field>" + "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">" + "<desc>Tell all your friends about your new bot!</desc>" + "<value>foo@bar.com</value>" + "<value>baz@fum.org</value>" + "</field>" + "<field var=\"untyped\">" + "<value>foo</value>" + "</field>" + "</x>")); + + Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); + + CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size())); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), payload->getFields()[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("FORM_TYPE"), payload->getFields()[0]->getName()); + CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired()); + + CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), payload->getFields()[1]->getValues()[0]); + + CPPUNIT_ASSERT_EQUAL(std::string("The name of your bot"), payload->getFields()[2]->getLabel()); + + CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue()); + + CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue()); + CPPUNIT_ASSERT(payload->getFields()[4]->getRequired()); + CPPUNIT_ASSERT_EQUAL(std::string("1"), payload->getFields()[4]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFields()[6]->getValues().size())); + CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getValues()[1]); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Contests"), payload->getFields()[6]->getOptions()[0].label); + CPPUNIT_ASSERT_EQUAL(std::string("contests"), payload->getFields()[6]->getOptions()[0].value); + CPPUNIT_ASSERT_EQUAL(std::string("News"), payload->getFields()[6]->getOptions()[1].label); + CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value); + + CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), payload->getFields()[8]->getJIDMultiValue(0)); + CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), payload->getFields()[8]->getJIDMultiValue(1)); + CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription()); + + CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->getFields()[9]->getValues()[0]); + } + + void testParse_FormItems() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<x xmlns='jabber:x:data' type='result'>" + "<field type='hidden' var='FORM_TYPE'>" + "<value>jabber:iq:search</value>" + "</field>" + "<reported>" + "<field var='first' label='Given Name' type='text-single'/>" + "<field var='last' label='Family Name' type='text-single'/>" + "<field var='jid' label='Jabber ID' type='jid-single'/>" + "<field var='x-gender' label='Gender' type='list-single'/>" + "</reported>" + "<item>" + "<field var='first'><value>Benvolio</value></field>" + "<field var='last'><value>Montague</value></field>" + "<field var='jid'><value>benvolio@montague.net</value></field>" + "<field var='x-gender'><value>male</value></field>" + "</item>" + "<item>" + "<field var='first'><value>Romeo</value></field>" + "<field var='last'><value>Montague</value></field>" + "<field var='jid'><value>romeo@montague.net</value></field>" + "<field var='x-gender'><value>male</value></field>" + "</item>" + "</x>")); + + Form* dataForm = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT(dataForm); + + Form::FormItem reported = dataForm->getReportedFields(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); + + std::vector<Form::FormItem> items = dataForm->getItems(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + Form::FormItem item = items[0]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + boost::shared_ptr<FormField> jidField = item[2]; + CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getJIDSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + + item = items[1]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + jidField = item[2]; + CPPUNIT_ASSERT(jidField); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getJIDSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(FormParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp index fae259f..30af3ec 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp @@ -19,100 +19,100 @@ using namespace Swift; class ForwardedParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ForwardedParserTest); - CPPUNIT_TEST(testParseIQ); - CPPUNIT_TEST(testParseMessage); - CPPUNIT_TEST(testParseMessageNoDelay); - CPPUNIT_TEST(testParsePresence); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParseIQ() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" - "<iq xmlns=\"jabber:client\" type=\"get\" from=\"kindanormal@example.com/IM\" to=\"stupidnewbie@example.com\" id=\"id0\"/>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); - - boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(payload->getStanza()); - CPPUNIT_ASSERT(!!iq); - CPPUNIT_ASSERT_EQUAL(JID("stupidnewbie@example.com"), iq->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("kindanormal@example.com/IM"), iq->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("id0"), iq->getID()); - CPPUNIT_ASSERT_EQUAL(IQ::Get, iq->getType()); - } - - void testParseMessage() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" - "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); - CPPUNIT_ASSERT(!!message); - const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; - CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); - CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); - } - - void testParseMessageNoDelay() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(!payload->getDelay()); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); - CPPUNIT_ASSERT(!!message); - const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; - CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); - CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); - } - - void testParsePresence() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" - "<presence xmlns=\"jabber:client\" from=\"alice@wonderland.lit/rabbithole\" to=\"madhatter@wonderland.lit\" type=\"unavailable\"/>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); - - boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(payload->getStanza()); - CPPUNIT_ASSERT(!!presence); - CPPUNIT_ASSERT_EQUAL(JID("madhatter@wonderland.lit"), presence->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/rabbithole"), presence->getFrom()); - CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presence->getType()); - } + CPPUNIT_TEST_SUITE(ForwardedParserTest); + CPPUNIT_TEST(testParseIQ); + CPPUNIT_TEST(testParseMessage); + CPPUNIT_TEST(testParseMessageNoDelay); + CPPUNIT_TEST(testParsePresence); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParseIQ() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<iq xmlns=\"jabber:client\" type=\"get\" from=\"kindanormal@example.com/IM\" to=\"stupidnewbie@example.com\" id=\"id0\"/>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(payload->getStanza()); + CPPUNIT_ASSERT(!!iq); + CPPUNIT_ASSERT_EQUAL(JID("stupidnewbie@example.com"), iq->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("kindanormal@example.com/IM"), iq->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), iq->getID()); + CPPUNIT_ASSERT_EQUAL(IQ::Get, iq->getType()); + } + + void testParseMessage() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } + + void testParseMessageNoDelay() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(!payload->getDelay()); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } + + void testParsePresence() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<presence xmlns=\"jabber:client\" from=\"alice@wonderland.lit/rabbithole\" to=\"madhatter@wonderland.lit\" type=\"unavailable\"/>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(payload->getStanza()); + CPPUNIT_ASSERT(!!presence); + CPPUNIT_ASSERT_EQUAL(JID("madhatter@wonderland.lit"), presence->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/rabbithole"), presence->getFrom()); + CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presence->getType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp index b7adead..782cb32 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp @@ -14,26 +14,26 @@ using namespace Swift; class IBBParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IBBParserTest); - CPPUNIT_TEST(testParse_Data); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_Data() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<data xmlns='http://jabber.org/protocol/ibb' seq='4'>\n" - "\t YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1\n" - "\t Njc4OTAK\n" - "</data>" - )); - - IBB::ref ibb = parser.getPayload<IBB>(); - CPPUNIT_ASSERT(ibb->getAction() == IBB::Data); - CPPUNIT_ASSERT(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a") == ibb->getData()); - CPPUNIT_ASSERT_EQUAL(4, ibb->getSequenceNumber()); - } + CPPUNIT_TEST_SUITE(IBBParserTest); + CPPUNIT_TEST(testParse_Data); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_Data() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<data xmlns='http://jabber.org/protocol/ibb' seq='4'>\n" + "\t YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1\n" + "\t Njc4OTAK\n" + "</data>" + )); + + IBB::ref ibb = parser.getPayload<IBB>(); + CPPUNIT_ASSERT(ibb->getAction() == IBB::Data); + CPPUNIT_ASSERT(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a") == ibb->getData()); + CPPUNIT_ASSERT_EQUAL(4, ibb->getSequenceNumber()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(IBBParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp index 7975352..462247a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp @@ -21,24 +21,24 @@ using namespace Swift; class IdleParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IdleParserTest); - CPPUNIT_TEST(testParse_XepWhatever_Example1); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(IdleParserTest); + CPPUNIT_TEST(testParse_XepWhatever_Example1); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse_XepWhatever_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<presence from='juliet@capulet.com/balcony'>\n" - "<show>away</show>\n" - "<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n" - "</presence>\n" - )); + public: + void testParse_XepWhatever_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<presence from='juliet@capulet.com/balcony'>\n" + "<show>away</show>\n" + "<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n" + "</presence>\n" + )); - Presence::ref presence = parser.getPayload<Presence>(); - CPPUNIT_ASSERT(presence); - Idle::ref idle = presence->getPayload<Idle>(); - CPPUNIT_ASSERT(idle); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == idle->getSince()); - } + Presence::ref presence = parser.getPayload<Presence>(); + CPPUNIT_ASSERT(presence); + Idle::ref idle = presence->getPayload<Idle>(); + CPPUNIT_ASSERT(idle); + CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == idle->getSince()); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp index ea33e82..6d08812 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp @@ -14,7 +14,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/Elements/Form.h> -#include <Swiften/Elements/InBandRegistrationPayload.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> #include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> @@ -22,53 +22,53 @@ using namespace Swift; class InBandRegistrationPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); - public: - InBandRegistrationPayloadParserTest() {} + public: + InBandRegistrationPayloadParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:register\">" - "<registered/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:register\">" + "<registered/>" + "</query>")); - InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(payload->isRegistered()); - } + InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(payload->isRegistered()); + } - void testParse_Form() { - PayloadsParserTester parser; + void testParse_Form() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:register\">" - "<instructions>Use the enclosed form to register.</instructions>" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<title>Contest Registration</title>" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:iq:register</value>" - "</field>" - "</x>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:register\">" + "<instructions>Use the enclosed form to register.</instructions>" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<title>Contest Registration</title>" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:register</value>" + "</field>" + "</x>" + "</query>")); - InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - boost::optional<std::string> instruction = payload->getInstructions(); - CPPUNIT_ASSERT(instruction); - CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get()); + InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + boost::optional<std::string> instruction = payload->getInstructions(); + CPPUNIT_ASSERT(instruction); + CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get()); - Form::ref form = payload->getForm(); - CPPUNIT_ASSERT(form); - CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle()); - CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType()); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType()); - } + Form::ref form = payload->getForm(); + CPPUNIT_ASSERT(form); + CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle()); + CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp index 56143ef..3bf79a5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp @@ -26,592 +26,592 @@ using namespace Swift; class JingleParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(JingleParserTest); - CPPUNIT_TEST(testParse_Xep0166_Example3); - CPPUNIT_TEST(testParse_Xep0166_Example8); - - CPPUNIT_TEST(testParse_Xep0261_Example1); - CPPUNIT_TEST(testParse_Xep0261_Example3); - CPPUNIT_TEST(testParse_Xep0261_Example9); - CPPUNIT_TEST(testParse_Xep0261_Example13); - - CPPUNIT_TEST(testParse_Xep0234_Example1); - CPPUNIT_TEST(testParse_Xep0234_Example3); - CPPUNIT_TEST(testParse_Xep0234_Example5); - CPPUNIT_TEST(testParse_Xep0234_Example8); - CPPUNIT_TEST(testParse_Xep0234_Example10); - - CPPUNIT_TEST(testParse_Xep0260_Example1); - CPPUNIT_TEST(testParse_Xep0260_Example3); - CPPUNIT_TEST_SUITE_END(); - - public: - //http://xmpp.org/extensions/xep-0166.html#example-3 - void testParse_Xep0166_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-terminate'\n" - " sid='a73sjjvkla37jfea'>\n" - " <reason>\n" - " <success/>\n" - " </reason>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, - jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); - } - - //http://xmpp.org/extensions/xep-0166.html#example-8 - void testParse_Xep0166_Example8() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-terminate'\n" - " sid='a73sjjvkla37jfea'>\n" - " <reason>\n" - " <success/>\n" - " <text>Sorry, gotta go!</text>\n" - " </reason>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, - jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); - CPPUNIT_ASSERT_EQUAL(std::string("Sorry, gotta go!"), - jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).text); - } - - // IBB Transport Method Examples - - // http://xmpp.org/extensions/xep-0261.html#example-1 - void testParse_Xep0261_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" - " block-size='4096'\n" - " sid='ch3d9s71'/>\n" - " </content>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); - JingleContentPayload::ref payload = payloads[0]; - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); - - JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); - CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(4096U, *transportPaylod->getBlockSize()); - CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); - } - - // http://xmpp.org/extensions/xep-0261.html#example-1 - void testParse_Xep0261_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-accept'\n" - " initiator='romeo@montague.lit/orchard'\n" - " responder='juliet@capulet.lit/balcony'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" - " block-size='2048'\n" - " sid='ch3d9s71'/>\n" - " </content>\n" - " </jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), jingle->getResponder()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); - JingleContentPayload::ref payload = payloads[0]; - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); - - JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); - CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); - CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); - } - - // http://xmpp.org/extensions/xep-0261.html#example-9 - void testParse_Xep0261_Example9() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='transport-info'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" - " block-size='2048'\n" - " sid='bt8a71h6'/>\n" - " </content>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); - JingleContentPayload::ref payload = payloads[0]; - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); - - JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); - CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); - CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID()); - } - - // http://xmpp.org/extensions/xep-0261.html#example-13 - void testParse_Xep0261_Example13() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-terminate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <reason><success/></reason>\n" - " </jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason()).type); - - } - - // Jingle File Transfer Examples - - // http://xmpp.org/extensions/xep-0234.html#example-1 - void testParse_Xep0234_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='851ba2'>\n" - "<content creator='initiator' name='a-file-offer'>\n" - "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - "<file>\n" - "<date>1969-07-21T02:56:15Z</date>\n" - "<desc>This is a test. If this were a real file...</desc>\n" - "<media-type>text/plain</media-type>\n" - "<name>test.txt</name>\n" - "<range/>\n" - "<size>1022</size>\n" - "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - "</file>\n" - "</description>\n" - "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - "<candidate cid='hft54dqy'\n" - " host='192.168.4.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5086'\n" - " priority='8257636'\n" - " type='direct'/>\n" - "<candidate cid='hutr46fe'\n" - " host='24.24.24.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5087'\n" - " priority='8258636'\n" - " type='direct'/>\n" - "</transport>\n" - "</content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> contents = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); - - JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); - - CPPUNIT_ASSERT(description); - JingleFileTransferFileInfo fileInfo = description->getFileInfo(); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); - CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); - CPPUNIT_ASSERT(1022 == fileInfo.getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); - CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-3 - void testParse_Xep0234_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-accept'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='851ba2'>\n" - "<content creator='initiator' name='a-file-offer'>\n" - "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - "<file>\n" - "<date>1969-07-21T02:56:15Z</date>\n" - "<desc>This is a test. If this were a real file...</desc>\n" - "<media-type>text/plain</media-type>\n" - "<name>test.txt</name>\n" - "<range/>\n" - "<size>1022</size>\n" - "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - "</file>\n" - "</description>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - " <candidate cid='ht567dq'\n" - " host='192.169.1.10'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hr65dqyd'\n" - " host='134.102.201.180'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='16453'\n" - " priority='7929856'\n" - " type='assisted'/>\n" - " <candidate cid='grt654q2'\n" - " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257606'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> contents = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); - - JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); - - CPPUNIT_ASSERT(description); - - JingleFileTransferFileInfo fileInfo = description->getFileInfo(); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); - CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); - CPPUNIT_ASSERT(1022 == fileInfo.getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); - CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-5 - void testParse_Xep0234_Example5() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='transport-info'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " sid='vj3hs98y'>\n" - " <candidate-used cid='hr65dqyd'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> contents = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); - - JingleS5BTransportPayload::ref transport = contents[0]->getTransport<JingleS5BTransportPayload>(); - CPPUNIT_ASSERT(transport); - - CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), transport->getSessionID()); - CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), transport->getCandidateUsed()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-8 - void testParse_Xep0234_Example8() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-info'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - " <file>\n" - " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - " </file>\n" - " </checksum>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - JingleFileTransferHash::ref hash = jingle->getPayload<JingleFileTransferHash>(); - CPPUNIT_ASSERT(hash); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(hash->getFileInfo().getHash("sha-1").get())); - } - - // http://xmpp.org/extensions/xep-0234.html#example-10 - void testParse_Xep0234_Example10() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='uj3b2'>\n" - " <content creator='initiator' name='a-file-request'>\n" - " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - " <file>\n" - " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - " <range offset='270336'/>\n" - " </file>\n" - " </description>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='xig361fj'>\n" - " <candidate cid='ht567dq'\n" - " host='192.169.1.10'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hr65dqyd'\n" - " host='134.102.201.180'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='16453'\n" - " priority='7929856'\n" - " type='assisted'/>\n" - " <candidate cid='grt654q2'\n" - " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257606'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("uj3b2"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - - JingleFileTransferFileInfo file = content->getDescription<JingleFileTransferDescription>()->getFileInfo(); - CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), file.getHashes().begin()->first); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(file.getHashes().begin()->second)); - CPPUNIT_ASSERT_EQUAL(static_cast<boost::uintmax_t>(270336), file.getRangeOffset()); - CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); - } - - // http://xmpp.org/extensions/xep-0260.html#example-1 - void testParse_Xep0260_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - " <candidate cid='hft54dqy'\n" - " host='192.168.4.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5086'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hutr46fe'\n" - " host='24.24.24.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5087'\n" - " priority='8258636'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - - JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); - CPPUNIT_ASSERT(s5bPayload); - - CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), s5bPayload->getCandidates().size()); - - JingleS5BTransportPayload::Candidate candidate; - candidate = s5bPayload->getCandidates()[0]; - CPPUNIT_ASSERT_EQUAL(std::string("hft54dqy"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.168.4.1"), 5086) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - - candidate = s5bPayload->getCandidates()[1]; - CPPUNIT_ASSERT_EQUAL(std::string("hutr46fe"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("24.24.24.1"), 5087) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8258636, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - } - - // http://xmpp.org/extensions/xep-0260.html#example-3 - void testParse_Xep0260_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-accept'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " dstaddr='1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - " <candidate cid='ht567dq'\n" - " host='192.169.1.10'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hr65dqyd'\n" - " host='134.102.201.180'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='16453'\n" - " priority='7929856'\n" - " type='assisted'/>\n" - " <candidate cid='grt654q2'\n" - " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257606'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - - JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); - CPPUNIT_ASSERT(s5bPayload); - - CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); - CPPUNIT_ASSERT_EQUAL(std::string("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"), s5bPayload->getDstAddr()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), s5bPayload->getCandidates().size()); - - JingleS5BTransportPayload::Candidate candidate; - candidate = s5bPayload->getCandidates()[0]; - CPPUNIT_ASSERT_EQUAL(std::string("ht567dq"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.169.1.10"), 6539) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - - candidate = s5bPayload->getCandidates()[1]; - CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("134.102.201.180"), 16453) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(7929856, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::AssistedType, candidate.type); - - candidate = s5bPayload->getCandidates()[2]; - CPPUNIT_ASSERT_EQUAL(std::string("grt654q2"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("2001:638:708:30c9:219:d1ff:fea4:a17d"), 6539) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8257606, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - } + CPPUNIT_TEST_SUITE(JingleParserTest); + CPPUNIT_TEST(testParse_Xep0166_Example3); + CPPUNIT_TEST(testParse_Xep0166_Example8); + + CPPUNIT_TEST(testParse_Xep0261_Example1); + CPPUNIT_TEST(testParse_Xep0261_Example3); + CPPUNIT_TEST(testParse_Xep0261_Example9); + CPPUNIT_TEST(testParse_Xep0261_Example13); + + CPPUNIT_TEST(testParse_Xep0234_Example1); + CPPUNIT_TEST(testParse_Xep0234_Example3); + CPPUNIT_TEST(testParse_Xep0234_Example5); + CPPUNIT_TEST(testParse_Xep0234_Example8); + CPPUNIT_TEST(testParse_Xep0234_Example10); + + CPPUNIT_TEST(testParse_Xep0260_Example1); + CPPUNIT_TEST(testParse_Xep0260_Example3); + CPPUNIT_TEST_SUITE_END(); + + public: + //http://xmpp.org/extensions/xep-0166.html#example-3 + void testParse_Xep0166_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-terminate'\n" + " sid='a73sjjvkla37jfea'>\n" + " <reason>\n" + " <success/>\n" + " </reason>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, + jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); + } + + //http://xmpp.org/extensions/xep-0166.html#example-8 + void testParse_Xep0166_Example8() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-terminate'\n" + " sid='a73sjjvkla37jfea'>\n" + " <reason>\n" + " <success/>\n" + " <text>Sorry, gotta go!</text>\n" + " </reason>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, + jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); + CPPUNIT_ASSERT_EQUAL(std::string("Sorry, gotta go!"), + jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).text); + } + + // IBB Transport Method Examples + + // http://xmpp.org/extensions/xep-0261.html#example-1 + void testParse_Xep0261_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" + " block-size='4096'\n" + " sid='ch3d9s71'/>\n" + " </content>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); + JingleContentPayload::ref payload = payloads[0]; + CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); + CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); + + JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); + CPPUNIT_ASSERT(transportPaylod); + CPPUNIT_ASSERT_EQUAL(4096U, *transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); + } + + // http://xmpp.org/extensions/xep-0261.html#example-1 + void testParse_Xep0261_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-accept'\n" + " initiator='romeo@montague.lit/orchard'\n" + " responder='juliet@capulet.lit/balcony'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" + " block-size='2048'\n" + " sid='ch3d9s71'/>\n" + " </content>\n" + " </jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), jingle->getResponder()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); + JingleContentPayload::ref payload = payloads[0]; + CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); + CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); + + JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); + CPPUNIT_ASSERT(transportPaylod); + CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); + } + + // http://xmpp.org/extensions/xep-0261.html#example-9 + void testParse_Xep0261_Example9() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='transport-info'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" + " block-size='2048'\n" + " sid='bt8a71h6'/>\n" + " </content>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); + JingleContentPayload::ref payload = payloads[0]; + CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); + CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); + + JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); + CPPUNIT_ASSERT(transportPaylod); + CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID()); + } + + // http://xmpp.org/extensions/xep-0261.html#example-13 + void testParse_Xep0261_Example13() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-terminate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <reason><success/></reason>\n" + " </jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason()).type); + + } + + // Jingle File Transfer Examples + + // http://xmpp.org/extensions/xep-0234.html#example-1 + void testParse_Xep0234_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='851ba2'>\n" + "<content creator='initiator' name='a-file-offer'>\n" + "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + "<file>\n" + "<date>1969-07-21T02:56:15Z</date>\n" + "<desc>This is a test. If this were a real file...</desc>\n" + "<media-type>text/plain</media-type>\n" + "<name>test.txt</name>\n" + "<range/>\n" + "<size>1022</size>\n" + "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + "</file>\n" + "</description>\n" + "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + "<candidate cid='hft54dqy'\n" + " host='192.168.4.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5086'\n" + " priority='8257636'\n" + " type='direct'/>\n" + "<candidate cid='hutr46fe'\n" + " host='24.24.24.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5087'\n" + " priority='8258636'\n" + " type='direct'/>\n" + "</transport>\n" + "</content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> contents = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); + + JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); + + CPPUNIT_ASSERT(description); + JingleFileTransferFileInfo fileInfo = description->getFileInfo(); + CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); + CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); + CPPUNIT_ASSERT(1022 == fileInfo.getSize()); + CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); + CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); + CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); + } + + // http://xmpp.org/extensions/xep-0234.html#example-3 + void testParse_Xep0234_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-accept'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='851ba2'>\n" + "<content creator='initiator' name='a-file-offer'>\n" + "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + "<file>\n" + "<date>1969-07-21T02:56:15Z</date>\n" + "<desc>This is a test. If this were a real file...</desc>\n" + "<media-type>text/plain</media-type>\n" + "<name>test.txt</name>\n" + "<range/>\n" + "<size>1022</size>\n" + "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + "</file>\n" + "</description>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + " <candidate cid='ht567dq'\n" + " host='192.169.1.10'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hr65dqyd'\n" + " host='134.102.201.180'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='16453'\n" + " priority='7929856'\n" + " type='assisted'/>\n" + " <candidate cid='grt654q2'\n" + " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257606'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> contents = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); + + JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); + + CPPUNIT_ASSERT(description); + + JingleFileTransferFileInfo fileInfo = description->getFileInfo(); + CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); + CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); + CPPUNIT_ASSERT(1022 == fileInfo.getSize()); + CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); + CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); + CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); + } + + // http://xmpp.org/extensions/xep-0234.html#example-5 + void testParse_Xep0234_Example5() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='transport-info'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " sid='vj3hs98y'>\n" + " <candidate-used cid='hr65dqyd'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> contents = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); + + JingleS5BTransportPayload::ref transport = contents[0]->getTransport<JingleS5BTransportPayload>(); + CPPUNIT_ASSERT(transport); + + CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), transport->getSessionID()); + CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), transport->getCandidateUsed()); + } + + // http://xmpp.org/extensions/xep-0234.html#example-8 + void testParse_Xep0234_Example8() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-info'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + " <file>\n" + " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + " </file>\n" + " </checksum>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + JingleFileTransferHash::ref hash = jingle->getPayload<JingleFileTransferHash>(); + CPPUNIT_ASSERT(hash); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(hash->getFileInfo().getHash("sha-1").get())); + } + + // http://xmpp.org/extensions/xep-0234.html#example-10 + void testParse_Xep0234_Example10() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='uj3b2'>\n" + " <content creator='initiator' name='a-file-request'>\n" + " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + " <file>\n" + " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + " <range offset='270336'/>\n" + " </file>\n" + " </description>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='xig361fj'>\n" + " <candidate cid='ht567dq'\n" + " host='192.169.1.10'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hr65dqyd'\n" + " host='134.102.201.180'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='16453'\n" + " priority='7929856'\n" + " type='assisted'/>\n" + " <candidate cid='grt654q2'\n" + " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257606'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("uj3b2"), jingle->getSessionID()); + + JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); + CPPUNIT_ASSERT(content); + + JingleFileTransferFileInfo file = content->getDescription<JingleFileTransferDescription>()->getFileInfo(); + CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), file.getHashes().begin()->first); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(file.getHashes().begin()->second)); + CPPUNIT_ASSERT_EQUAL(static_cast<boost::uintmax_t>(270336), file.getRangeOffset()); + CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); + } + + // http://xmpp.org/extensions/xep-0260.html#example-1 + void testParse_Xep0260_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + " <candidate cid='hft54dqy'\n" + " host='192.168.4.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5086'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hutr46fe'\n" + " host='24.24.24.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5087'\n" + " priority='8258636'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); + CPPUNIT_ASSERT(content); + + JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); + CPPUNIT_ASSERT(s5bPayload); + + CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), s5bPayload->getCandidates().size()); + + JingleS5BTransportPayload::Candidate candidate; + candidate = s5bPayload->getCandidates()[0]; + CPPUNIT_ASSERT_EQUAL(std::string("hft54dqy"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.168.4.1"), 5086) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + + candidate = s5bPayload->getCandidates()[1]; + CPPUNIT_ASSERT_EQUAL(std::string("hutr46fe"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress("24.24.24.1"), 5087) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8258636, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + } + + // http://xmpp.org/extensions/xep-0260.html#example-3 + void testParse_Xep0260_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-accept'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " dstaddr='1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + " <candidate cid='ht567dq'\n" + " host='192.169.1.10'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hr65dqyd'\n" + " host='134.102.201.180'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='16453'\n" + " priority='7929856'\n" + " type='assisted'/>\n" + " <candidate cid='grt654q2'\n" + " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257606'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); + CPPUNIT_ASSERT(content); + + JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); + CPPUNIT_ASSERT(s5bPayload); + + CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); + CPPUNIT_ASSERT_EQUAL(std::string("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"), s5bPayload->getDstAddr()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), s5bPayload->getCandidates().size()); + + JingleS5BTransportPayload::Candidate candidate; + candidate = s5bPayload->getCandidates()[0]; + CPPUNIT_ASSERT_EQUAL(std::string("ht567dq"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.169.1.10"), 6539) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + + candidate = s5bPayload->getCandidates()[1]; + CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress("134.102.201.180"), 16453) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(7929856, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::AssistedType, candidate.type); + + candidate = s5bPayload->getCandidates()[2]; + CPPUNIT_ASSERT_EQUAL(std::string("grt654q2"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress("2001:638:708:30c9:219:d1ff:fea4:a17d"), 6539) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8257606, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(JingleParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp index dd6263d..b045ca5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp @@ -14,46 +14,46 @@ using namespace Swift; class MAMFinParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMFinParserTest); - CPPUNIT_TEST(testParse_XEP0313_Exmaple1); - CPPUNIT_TEST(testParse_XEP0313_Exmaple9); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_XEP0313_Exmaple1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<fin xmlns='urn:xmpp:mam:0' queryid='f27' />")); - - boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT_EQUAL(false, payload->isComplete()); - CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); - - boost::optional<std::string> queryID = payload->getQueryID(); - CPPUNIT_ASSERT(queryID); - CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get()); - } - - void testParse_XEP0313_Exmaple9() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<fin xmlns='urn:xmpp:mam:0' complete='true'>" - "<set xmlns='http://jabber.org/protocol/rsm'>" - "<first index='0'>23452-4534-1</first>" - "<last>390-2342-22</last>" - "<count>16</count>" - "</set>" - "</fin>")); - - boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT_EQUAL(true, payload->isComplete()); - CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); - - CPPUNIT_ASSERT(!!payload->getResultSet()); - boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); - } + CPPUNIT_TEST_SUITE(MAMFinParserTest); + CPPUNIT_TEST(testParse_XEP0313_Exmaple1); + CPPUNIT_TEST(testParse_XEP0313_Exmaple9); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_XEP0313_Exmaple1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<fin xmlns='urn:xmpp:mam:0' queryid='f27' />")); + + boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(false, payload->isComplete()); + CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); + + boost::optional<std::string> queryID = payload->getQueryID(); + CPPUNIT_ASSERT(queryID); + CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get()); + } + + void testParse_XEP0313_Exmaple9() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<fin xmlns='urn:xmpp:mam:0' complete='true'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<first index='0'>23452-4534-1</first>" + "<last>390-2342-22</last>" + "<count>16</count>" + "</set>" + "</fin>")); + + boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(true, payload->isComplete()); + CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); + + CPPUNIT_ASSERT(!!payload->getResultSet()); + boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp index ff89ed1..8bdefc1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp @@ -15,108 +15,108 @@ using namespace Swift; class MAMQueryParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMQueryParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_XEP0313_Example3); - CPPUNIT_TEST(testParse_XEP0313_Example4); - CPPUNIT_TEST(testParseEmpty); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\" node=\"node1\">" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"text-single\" var=\"FORM_TYPE\">" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field type=\"text-single\" var=\"start\">" - "<value>2010-08-07T00:00:00Z</value>" - "</field>" - "</x>" - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>10</max>" - "</set>" - "</query>")); - - - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("node1"), *payload->getNode()); - - CPPUNIT_ASSERT(payload->getForm()); - boost::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); - CPPUNIT_ASSERT(fieldType); - CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue()); - boost::shared_ptr<FormField> fieldStart = payload->getForm()->getField("start"); - CPPUNIT_ASSERT(fieldStart); - CPPUNIT_ASSERT_EQUAL(std::string("2010-08-07T00:00:00Z"), fieldStart->getTextSingleValue()); - - CPPUNIT_ASSERT(payload->getResultSet()); - boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); - CPPUNIT_ASSERT(resultSet->getMaxItems()); - CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); - } - - void testParse_XEP0313_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='urn:xmpp:mam:0'>" - "<x xmlns='jabber:x:data'>" - "<field var='FORM_TYPE'>" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field var='with'>" - "<value>juliet@capulet.lit</value>" - "</field>" - "</x>" - "</query>")); - - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with")); - CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue()); - } - - void testParse_XEP0313_Example4() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='urn:xmpp:mam:0'>" - "<x xmlns='jabber:x:data'>" - "<field var='FORM_TYPE'>" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field var='start'>" - "<value>2010-06-07T00:00:00Z</value>" - "</field>" - "<field var='end'>" - "<value>2010-07-07T13:23:54Z</value>" - "</field>" - "</x>" - "</query>")); - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start")); - CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue()); - } - - void testParseEmpty() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" - "</query>")); - - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); - CPPUNIT_ASSERT(!payload->getForm()); - CPPUNIT_ASSERT(!payload->getResultSet()); - } + CPPUNIT_TEST_SUITE(MAMQueryParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_XEP0313_Example3); + CPPUNIT_TEST(testParse_XEP0313_Example4); + CPPUNIT_TEST(testParseEmpty); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\" node=\"node1\">" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"text-single\" var=\"FORM_TYPE\">" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field type=\"text-single\" var=\"start\">" + "<value>2010-08-07T00:00:00Z</value>" + "</field>" + "</x>" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "</set>" + "</query>")); + + + boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("node1"), *payload->getNode()); + + CPPUNIT_ASSERT(payload->getForm()); + boost::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); + CPPUNIT_ASSERT(fieldType); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue()); + boost::shared_ptr<FormField> fieldStart = payload->getForm()->getField("start"); + CPPUNIT_ASSERT(fieldStart); + CPPUNIT_ASSERT_EQUAL(std::string("2010-08-07T00:00:00Z"), fieldStart->getTextSingleValue()); + + CPPUNIT_ASSERT(payload->getResultSet()); + boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); + CPPUNIT_ASSERT(resultSet->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); + } + + void testParse_XEP0313_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='urn:xmpp:mam:0'>" + "<x xmlns='jabber:x:data'>" + "<field var='FORM_TYPE'>" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field var='with'>" + "<value>juliet@capulet.lit</value>" + "</field>" + "</x>" + "</query>")); + + boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with")); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue()); + } + + void testParse_XEP0313_Example4() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='urn:xmpp:mam:0'>" + "<x xmlns='jabber:x:data'>" + "<field var='FORM_TYPE'>" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field var='start'>" + "<value>2010-06-07T00:00:00Z</value>" + "</field>" + "<field var='end'>" + "<value>2010-07-07T13:23:54Z</value>" + "</field>" + "</x>" + "</query>")); + boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start")); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue()); + } + + void testParseEmpty() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "</query>")); + + boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + CPPUNIT_ASSERT(!payload->getForm()); + CPPUNIT_ASSERT(!payload->getResultSet()); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp index a4c2f08..7393630 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp @@ -18,41 +18,41 @@ using namespace Swift; class MAMResultParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMResultParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<message xmlns=\"jabber:client\" from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>" - "</result>")); - - boost::shared_ptr<MAMResult> payload = parser.getPayload<MAMResult>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID()); - CPPUNIT_ASSERT(payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("f27"), *payload->getQueryID()); - - boost::shared_ptr<Forwarded> forwarded = payload->getPayload(); - CPPUNIT_ASSERT(forwarded->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp())); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); - CPPUNIT_ASSERT(!!message); - const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; - CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); - CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); - } + CPPUNIT_TEST_SUITE(MAMResultParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<message xmlns=\"jabber:client\" from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>" + "</result>")); + + boost::shared_ptr<MAMResult> payload = parser.getPayload<MAMResult>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID()); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("f27"), *payload->getQueryID()); + + boost::shared_ptr<Forwarded> forwarded = payload->getPayload(); + CPPUNIT_ASSERT(forwarded->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp())); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMResultParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp index f49ca19..495aefe 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp @@ -14,25 +14,25 @@ using namespace Swift; class MUCAdminPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MUCAdminPayloadParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(MUCAdminPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - MUCAdminPayloadParserTest() {} + public: + MUCAdminPayloadParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>")); + CPPUNIT_ASSERT(parser.parse("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>")); - MUCAdminPayload::ref payload = boost::dynamic_pointer_cast<MUCAdminPayload>(parser.getPayload()); - MUCItem item = payload->getItems()[0]; - CPPUNIT_ASSERT_EQUAL(MUCOccupant::Owner, item.affiliation.get()); - CPPUNIT_ASSERT_EQUAL(MUCOccupant::Visitor, item.role.get()); - CPPUNIT_ASSERT_EQUAL(JID("kev@tester.lit"), item.actor.get()); - CPPUNIT_ASSERT_EQUAL(std::string("malice"), item.reason.get()); - } + MUCAdminPayload::ref payload = boost::dynamic_pointer_cast<MUCAdminPayload>(parser.getPayload()); + MUCItem item = payload->getItems()[0]; + CPPUNIT_ASSERT_EQUAL(MUCOccupant::Owner, item.affiliation.get()); + CPPUNIT_ASSERT_EQUAL(MUCOccupant::Visitor, item.role.get()); + CPPUNIT_ASSERT_EQUAL(JID("kev@tester.lit"), item.actor.get()); + CPPUNIT_ASSERT_EQUAL(std::string("malice"), item.reason.get()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MUCAdminPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp index 89c51d8..a8cf246 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp @@ -16,78 +16,78 @@ using namespace Swift; class MUCUserPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MUCUserPayloadParserTest); - CPPUNIT_TEST(testParseEmpty); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParseDestroy); - CPPUNIT_TEST(testParseInvite); - CPPUNIT_TEST_SUITE_END(); - - public: - MUCUserPayloadParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><status code='110'/><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item><status code='210'/></x>")); - - bool found110 = false; - bool found210 = false; - - MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - - foreach (MUCUserPayload::StatusCode status, payload->getStatusCodes()) { - if (status.code == 110) found110 = true; - if (status.code == 210) found210 = true; - } - - MUCItem item = payload->getItems()[0]; - CPPUNIT_ASSERT_EQUAL(MUCOccupant::Owner, item.affiliation.get()); - CPPUNIT_ASSERT_EQUAL(MUCOccupant::Visitor, item.role.get()); - CPPUNIT_ASSERT_EQUAL(JID("kev@tester.lit"), item.actor.get()); - CPPUNIT_ASSERT_EQUAL(std::string("malice"), item.reason.get()); - CPPUNIT_ASSERT(found110); - CPPUNIT_ASSERT(found210); - } - - void testParseEmpty() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"/>")); - - MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(payload->getItems().empty()); - } - - void testParseDestroy() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><destroy jid='alice@wonderland.lit'><reason>bert</reason></destroy></x>")); - - MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - MUCDestroyPayload::ref destroy = boost::dynamic_pointer_cast<MUCDestroyPayload>(payload->getPayload()); - CPPUNIT_ASSERT(destroy); - CPPUNIT_ASSERT_EQUAL(std::string("bert"), destroy->getReason()); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), destroy->getNewVenue()); - } - - void testParseInvite() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><invite from='crone1@shakespeare.lit/desktop' to='alice@wonderland.lit/xxx'> <reason>Hey Hecate, this is the place for all good witches!</reason> </invite> <password>cauldronburn</password></x>")); - - MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(payload->getInvite()); - CPPUNIT_ASSERT(payload->getPassword()); - CPPUNIT_ASSERT_EQUAL(std::string("cauldronburn"), *payload->getPassword()); - MUCUserPayload::Invite invite = *payload->getInvite(); - CPPUNIT_ASSERT_EQUAL(std::string("Hey Hecate, this is the place for all good witches!"), invite.reason); - CPPUNIT_ASSERT_EQUAL(JID("crone1@shakespeare.lit/desktop"), invite.from); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/xxx"), invite.to); - } + CPPUNIT_TEST_SUITE(MUCUserPayloadParserTest); + CPPUNIT_TEST(testParseEmpty); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParseDestroy); + CPPUNIT_TEST(testParseInvite); + CPPUNIT_TEST_SUITE_END(); + + public: + MUCUserPayloadParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><status code='110'/><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item><status code='210'/></x>")); + + bool found110 = false; + bool found210 = false; + + MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); + + foreach (MUCUserPayload::StatusCode status, payload->getStatusCodes()) { + if (status.code == 110) found110 = true; + if (status.code == 210) found210 = true; + } + + MUCItem item = payload->getItems()[0]; + CPPUNIT_ASSERT_EQUAL(MUCOccupant::Owner, item.affiliation.get()); + CPPUNIT_ASSERT_EQUAL(MUCOccupant::Visitor, item.role.get()); + CPPUNIT_ASSERT_EQUAL(JID("kev@tester.lit"), item.actor.get()); + CPPUNIT_ASSERT_EQUAL(std::string("malice"), item.reason.get()); + CPPUNIT_ASSERT(found110); + CPPUNIT_ASSERT(found210); + } + + void testParseEmpty() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"/>")); + + MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(payload->getItems().empty()); + } + + void testParseDestroy() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><destroy jid='alice@wonderland.lit'><reason>bert</reason></destroy></x>")); + + MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + MUCDestroyPayload::ref destroy = boost::dynamic_pointer_cast<MUCDestroyPayload>(payload->getPayload()); + CPPUNIT_ASSERT(destroy); + CPPUNIT_ASSERT_EQUAL(std::string("bert"), destroy->getReason()); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), destroy->getNewVenue()); + } + + void testParseInvite() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><invite from='crone1@shakespeare.lit/desktop' to='alice@wonderland.lit/xxx'> <reason>Hey Hecate, this is the place for all good witches!</reason> </invite> <password>cauldronburn</password></x>")); + + MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(payload->getInvite()); + CPPUNIT_ASSERT(payload->getPassword()); + CPPUNIT_ASSERT_EQUAL(std::string("cauldronburn"), *payload->getPassword()); + MUCUserPayload::Invite invite = *payload->getInvite(); + CPPUNIT_ASSERT_EQUAL(std::string("Hey Hecate, this is the place for all good witches!"), invite.reason); + CPPUNIT_ASSERT_EQUAL(JID("crone1@shakespeare.lit/desktop"), invite.from); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/xxx"), invite.to); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h index bb6450f..a85a692 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h @@ -10,5 +10,5 @@ #include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { - typedef ParserTester<PayloadParser> PayloadParserTester; + typedef ParserTester<PayloadParser> PayloadParserTester; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h index ca33d48..8e871b2 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -14,53 +14,53 @@ #include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class PayloadsParserTester : public XMLParserClient { - public: - PayloadsParserTester() : level(0) { - xmlParser = PlatformXMLParserFactory().createXMLParser(this); - } + class PayloadsParserTester : public XMLParserClient { + public: + PayloadsParserTester() : level(0) { + xmlParser = PlatformXMLParserFactory().createXMLParser(this); + } - ~PayloadsParserTester() { - delete xmlParser; - } + ~PayloadsParserTester() { + delete xmlParser; + } - bool parse(const std::string& data) { - return xmlParser->parse(data); - } + bool parse(const std::string& data) { + return xmlParser->parse(data); + } - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - assert(!payloadParser.get()); - PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); - assert(payloadParserFactory); - payloadParser.reset(payloadParserFactory->createPayloadParser()); - } - payloadParser->handleStartElement(element, ns, attributes); - level++; - } + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + assert(!payloadParser.get()); + PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); + assert(payloadParserFactory); + payloadParser.reset(payloadParserFactory->createPayloadParser()); + } + payloadParser->handleStartElement(element, ns, attributes); + level++; + } - virtual void handleEndElement(const std::string& element, const std::string& ns) { - level--; - payloadParser->handleEndElement(element, ns); - } + virtual void handleEndElement(const std::string& element, const std::string& ns) { + level--; + payloadParser->handleEndElement(element, ns); + } - virtual void handleCharacterData(const std::string& data) { - payloadParser->handleCharacterData(data); - } + virtual void handleCharacterData(const std::string& data) { + payloadParser->handleCharacterData(data); + } - boost::shared_ptr<Payload> getPayload() const { - return payloadParser->getPayload(); - } + boost::shared_ptr<Payload> getPayload() const { + return payloadParser->getPayload(); + } - template<typename T> - boost::shared_ptr<T> getPayload() const { - return boost::dynamic_pointer_cast<T>(payloadParser->getPayload()); - } + template<typename T> + boost::shared_ptr<T> getPayload() const { + return boost::dynamic_pointer_cast<T>(payloadParser->getPayload()); + } - private: - XMLParser* xmlParser; - FullPayloadParserFactoryCollection factories; - boost::shared_ptr<PayloadParser> payloadParser; - int level; - }; + private: + XMLParser* xmlParser; + FullPayloadParserFactoryCollection factories; + boost::shared_ptr<PayloadParser> payloadParser; + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp index 285ac56..e724090 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp @@ -13,29 +13,29 @@ using namespace Swift; class PriorityParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PriorityParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Invalid); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PriorityParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Invalid); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; + public: + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<priority>-120</priority>")); + CPPUNIT_ASSERT(parser.parse("<priority>-120</priority>")); - boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority()); - } + boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority()); + } - void testParse_Invalid() { - PayloadsParserTester parser; + void testParse_Invalid() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<priority>invalid</priority>")); + CPPUNIT_ASSERT(parser.parse("<priority>invalid</priority>")); - boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(0, payload->getPriority()); - } + boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(0, payload->getPriority()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(PriorityParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp index f38a0bd..2975485 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp @@ -15,81 +15,81 @@ using namespace Swift; class PrivateStorageParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PrivateStorageParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_NoPayload); - CPPUNIT_TEST(testParse_MultiplePayloads); - CPPUNIT_TEST_SUITE_END(); - - public: - PrivateStorageParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:private'>" - "<storage xmlns='storage:bookmarks'>" - "<conference name='Swift' jid='swift@rooms.swift.im'>" - "<nick>Alice</nick>" - "</conference>" - "</storage>" - "</query>")); - - boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - boost::shared_ptr<Storage> storage = boost::dynamic_pointer_cast<Storage>(payload->getPayload()); - CPPUNIT_ASSERT(storage); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), storage->getRooms()[0].nick); - CPPUNIT_ASSERT_EQUAL(JID("swift@rooms.swift.im"), storage->getRooms()[0].jid); - } - - void testParse_NoPayload() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:private'/>")); - - boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(!payload->getPayload()); - } - - void testParse_MultiplePayloads() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:private'>" - "<storage xmlns='storage:bookmarks'>" - "<conference name='Swift' jid='swift@rooms.swift.im'>" - "<nick>Alice</nick>" - "</conference>" - "</storage>" - "<storage xmlns='storage:bookmarks'>" - "<conference name='Swift' jid='swift@rooms.swift.im'>" - "<nick>Rabbit</nick>" - "</conference>" - "</storage>" - "</query>")); - - boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - boost::shared_ptr<Storage> storage = boost::dynamic_pointer_cast<Storage>(payload->getPayload()); - CPPUNIT_ASSERT(storage); - CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), storage->getRooms()[0].nick); - } - - void testParse_UnsupportedPayload() { - PayloadParserFactoryCollection factories; - PrivateStorageParser testling(&factories); - PayloadParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:private'>" - "<foo>Bar</foo>" - "</query>")); - - CPPUNIT_ASSERT(!boost::dynamic_pointer_cast<PrivateStorage>(testling.getPayload())->getPayload()); - } + CPPUNIT_TEST_SUITE(PrivateStorageParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_NoPayload); + CPPUNIT_TEST(testParse_MultiplePayloads); + CPPUNIT_TEST_SUITE_END(); + + public: + PrivateStorageParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:private'>" + "<storage xmlns='storage:bookmarks'>" + "<conference name='Swift' jid='swift@rooms.swift.im'>" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "</query>")); + + boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + boost::shared_ptr<Storage> storage = boost::dynamic_pointer_cast<Storage>(payload->getPayload()); + CPPUNIT_ASSERT(storage); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), storage->getRooms()[0].nick); + CPPUNIT_ASSERT_EQUAL(JID("swift@rooms.swift.im"), storage->getRooms()[0].jid); + } + + void testParse_NoPayload() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:private'/>")); + + boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(!payload->getPayload()); + } + + void testParse_MultiplePayloads() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:private'>" + "<storage xmlns='storage:bookmarks'>" + "<conference name='Swift' jid='swift@rooms.swift.im'>" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "<storage xmlns='storage:bookmarks'>" + "<conference name='Swift' jid='swift@rooms.swift.im'>" + "<nick>Rabbit</nick>" + "</conference>" + "</storage>" + "</query>")); + + boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + boost::shared_ptr<Storage> storage = boost::dynamic_pointer_cast<Storage>(payload->getPayload()); + CPPUNIT_ASSERT(storage); + CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), storage->getRooms()[0].nick); + } + + void testParse_UnsupportedPayload() { + PayloadParserFactoryCollection factories; + PrivateStorageParser testling(&factories); + PayloadParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:private'>" + "<foo>Bar</foo>" + "</query>")); + + CPPUNIT_ASSERT(!boost::dynamic_pointer_cast<PrivateStorage>(testling.getPayload())->getPayload()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(PrivateStorageParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp index 800f48c..2deca6e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp @@ -14,27 +14,27 @@ using namespace Swift; class RawXMLPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RawXMLPayloadParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - RawXMLPayloadParserTest() {} - - void testParse() { - RawXMLPayloadParser testling; - PayloadParserTester parser(&testling); - - std::string xml = - "<foo foo-attr=\"foo-val\" xmlns=\"ns:foo\">" - "<bar bar-attr=\"bar-val\" xmlns=\"ns:bar\"/>" - "<baz baz-attr=\"baz-val\" xmlns=\"ns:baz\"/>" - "</foo>"; - CPPUNIT_ASSERT(parser.parse(xml)); - - RawXMLPayload* payload = dynamic_cast<RawXMLPayload*>(testling.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(xml, payload->getRawXML()); - } + CPPUNIT_TEST_SUITE(RawXMLPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + RawXMLPayloadParserTest() {} + + void testParse() { + RawXMLPayloadParser testling; + PayloadParserTester parser(&testling); + + std::string xml = + "<foo foo-attr=\"foo-val\" xmlns=\"ns:foo\">" + "<bar bar-attr=\"bar-val\" xmlns=\"ns:bar\"/>" + "<baz baz-attr=\"baz-val\" xmlns=\"ns:baz\"/>" + "</foo>"; + CPPUNIT_ASSERT(parser.parse(xml)); + + RawXMLPayload* payload = dynamic_cast<RawXMLPayload*>(testling.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(xml, payload->getRawXML()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RawXMLPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp index c3f410f..3e42788 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp @@ -13,24 +13,24 @@ using namespace Swift; class ReplaceParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ReplaceParserTest); - CPPUNIT_TEST(testParseTrivial); - CPPUNIT_TEST(testParseChild); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ReplaceParserTest); + CPPUNIT_TEST(testParseTrivial); + CPPUNIT_TEST(testParseChild); + CPPUNIT_TEST_SUITE_END(); - public: - void testParseTrivial() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace'/>")); - Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); - } - void testParseChild() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace' ><child xmlns='blah' id=\"hi\"/></replace>")); - Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); - } + public: + void testParseTrivial() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace'/>")); + Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); + } + void testParseChild() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace' ><child xmlns='blah' id=\"hi\"/></replace>")); + Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp index 4c2b377..5c786c5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp @@ -14,31 +14,31 @@ using namespace Swift; class ResourceBindParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ResourceBindParserTest); - CPPUNIT_TEST(testParse_JID); - CPPUNIT_TEST(testParse_Resource); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ResourceBindParserTest); + CPPUNIT_TEST(testParse_JID); + CPPUNIT_TEST(testParse_Resource); + CPPUNIT_TEST_SUITE_END(); - public: - ResourceBindParserTest() {} + public: + ResourceBindParserTest() {} - void testParse_JID() { - PayloadsParserTester parser; + void testParse_JID() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>somenode@example.com/someresource</jid></bind>")); + CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>somenode@example.com/someresource</jid></bind>")); - ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(JID("somenode@example.com/someresource"), payload->getJID()); - } + ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(JID("somenode@example.com/someresource"), payload->getJID()); + } - void testParse_Resource() { - PayloadsParserTester parser; + void testParse_Resource() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>someresource</resource></bind>")); + CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>someresource</resource></bind>")); - ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("someresource"), payload->getResource()); - } + ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("someresource"), payload->getResource()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ResourceBindParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp index e01a811..7924e05 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -14,58 +14,58 @@ using namespace Swift; class ResultSetParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ResultSetParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParseFirstNoIndex); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ResultSetParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParseFirstNoIndex); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>100</max>" - "<count>800</count>" - "<index>0</index>" - "<first index=\"123\">stpeter@jabber.org</first>" - "<last>peterpan@neverland.lit</last>" - "<before>decaf-badba-dbad1</before>" - "<after>09af3-cc343-b409f</after>" - "</set>")); + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>100</max>" + "<count>800</count>" + "<index>0</index>" + "<first index=\"123\">stpeter@jabber.org</first>" + "<last>peterpan@neverland.lit</last>" + "<before>decaf-badba-dbad1</before>" + "<after>09af3-cc343-b409f</after>" + "</set>")); - boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getMaxItems()); - CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems()); - CPPUNIT_ASSERT(payload->getCount()); - CPPUNIT_ASSERT_EQUAL(800, *payload->getCount()); - CPPUNIT_ASSERT(payload->getIndex()); - CPPUNIT_ASSERT_EQUAL(0, *payload->getIndex()); - CPPUNIT_ASSERT(payload->getFirstID()); - CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); - CPPUNIT_ASSERT(payload->getFirstIDIndex()); - CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex()); - CPPUNIT_ASSERT(payload->getLastID()); - CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID()); - CPPUNIT_ASSERT(payload->getBefore()); - CPPUNIT_ASSERT_EQUAL(std::string("decaf-badba-dbad1"), *payload->getBefore()); - CPPUNIT_ASSERT(payload->getAfter()); - CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter()); - } + boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems()); + CPPUNIT_ASSERT(payload->getCount()); + CPPUNIT_ASSERT_EQUAL(800, *payload->getCount()); + CPPUNIT_ASSERT(payload->getIndex()); + CPPUNIT_ASSERT_EQUAL(0, *payload->getIndex()); + CPPUNIT_ASSERT(payload->getFirstID()); + CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); + CPPUNIT_ASSERT(payload->getFirstIDIndex()); + CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex()); + CPPUNIT_ASSERT(payload->getLastID()); + CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID()); + CPPUNIT_ASSERT(payload->getBefore()); + CPPUNIT_ASSERT_EQUAL(std::string("decaf-badba-dbad1"), *payload->getBefore()); + CPPUNIT_ASSERT(payload->getAfter()); + CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter()); + } - void testParseFirstNoIndex() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<first>stpeter@jabber.org</first>" - "</set>")); + void testParseFirstNoIndex() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first>stpeter@jabber.org</first>" + "</set>")); - boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getFirstID()); - CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); - CPPUNIT_ASSERT(!payload->getFirstIDIndex()); - } + boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getFirstID()); + CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); + CPPUNIT_ASSERT(!payload->getFirstIDIndex()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp index 1a18d6d..a94a6fe 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp @@ -14,39 +14,39 @@ using namespace Swift; class RosterItemExchangeParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterItemExchangeParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<x xmlns=\"http://jabber.org/protocol/rosterx\">" - "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" - "<group>Group 1</group>" - "<group>Group 2</group>" - "</item>" - "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" - "</x>")); - - RosterItemExchangePayload* payload = dynamic_cast<RosterItemExchangePayload*>(parser.getPayload().get()); - const RosterItemExchangePayload::RosterItemExchangePayloadItems& items = payload->getItems(); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Add, items[0].getAction()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); - - CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Modify, items[1].getAction()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); - } + CPPUNIT_TEST_SUITE(RosterItemExchangeParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<x xmlns=\"http://jabber.org/protocol/rosterx\">" + "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" + "</x>")); + + RosterItemExchangePayload* payload = dynamic_cast<RosterItemExchangePayload*>(parser.getPayload().get()); + const RosterItemExchangePayload::RosterItemExchangePayloadItems& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Add, items[0].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + + CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Modify, items[1].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp index d1e1b45..261dad2 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp @@ -14,88 +14,88 @@ using namespace Swift; class RosterParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_ItemWithUnknownContent); - CPPUNIT_TEST(testParse_WithVersion); - CPPUNIT_TEST(testParse_WithEmptyVersion); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:roster'>" - " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" - " <group>Group 1</group>" - " <group>Group 2</group>" - " </item>" - " <item jid='baz@blo.com' name='Baz'/>" - "</query>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - - CPPUNIT_ASSERT(!payload->getVersion()); - const RosterPayload::RosterItemPayloads& items = payload->getItems(); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::From, items[0].getSubscription()); - CPPUNIT_ASSERT(items[0].getSubscriptionRequested()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); - - CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::None, items[1].getSubscription()); - CPPUNIT_ASSERT(!items[1].getSubscriptionRequested()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); - } - - void testParse_ItemWithUnknownContent() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:roster'>" - " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" - " <group>Group 1</group>" - " <foo xmlns=\"http://example.com\"><bar>Baz</bar></foo>" - " <group>Group 2</group>" - " <baz><fum>foo</fum></baz>" - " </item>" - "</query>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - const RosterPayload::RosterItemPayloads& items = payload->getItems(); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), items.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); - CPPUNIT_ASSERT_EQUAL(std::string( - "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" - "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" - ), items[0].getUnknownContent()); - } - - void testParse_WithVersion() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver='ver10'/>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string("ver10"), *payload->getVersion()); - } - - void testParse_WithEmptyVersion() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver=''/>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string(""), *payload->getVersion()); - } + CPPUNIT_TEST_SUITE(RosterParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_ItemWithUnknownContent); + CPPUNIT_TEST(testParse_WithVersion); + CPPUNIT_TEST(testParse_WithEmptyVersion); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:roster'>" + " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" + " <group>Group 1</group>" + " <group>Group 2</group>" + " </item>" + " <item jid='baz@blo.com' name='Baz'/>" + "</query>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + + CPPUNIT_ASSERT(!payload->getVersion()); + const RosterPayload::RosterItemPayloads& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::From, items[0].getSubscription()); + CPPUNIT_ASSERT(items[0].getSubscriptionRequested()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + + CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::None, items[1].getSubscription()); + CPPUNIT_ASSERT(!items[1].getSubscriptionRequested()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); + } + + void testParse_ItemWithUnknownContent() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:roster'>" + " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" + " <group>Group 1</group>" + " <foo xmlns=\"http://example.com\"><bar>Baz</bar></foo>" + " <group>Group 2</group>" + " <baz><fum>foo</fum></baz>" + " </item>" + "</query>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + const RosterPayload::RosterItemPayloads& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), items.size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + CPPUNIT_ASSERT_EQUAL(std::string( + "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" + "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" + ), items[0].getUnknownContent()); + } + + void testParse_WithVersion() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver='ver10'/>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("ver10"), *payload->getVersion()); + } + + void testParse_WithEmptyVersion() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver=''/>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string(""), *payload->getVersion()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp index 4b903e0..5fe4168 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp @@ -13,169 +13,169 @@ using namespace Swift; class SearchPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SearchPayloadParserTest); - CPPUNIT_TEST(testParse_FormRequestResponse); - CPPUNIT_TEST(testParse_Results); - CPPUNIT_TEST(testParse_FormRequestResponse_XDATA); - CPPUNIT_TEST(testParse_Results_XDATA); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_FormRequestResponse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:search\">" - "<instructions>Foo</instructions>" - "<first/>" - "<last/>" - "</query>" - )); - - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT_EQUAL(std::string("Foo"), *payload->getInstructions()); - CPPUNIT_ASSERT(payload->getFirst()); - CPPUNIT_ASSERT(payload->getLast()); - CPPUNIT_ASSERT(!payload->getNick()); - } - - void testParse_Results() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:search\">" - "<item jid=\"juliet@capulet.com\">" - "<first>Juliet</first>" - "<last>Capulet</last>" - "<nick>JuliC</nick>" - "<email>juliet@shakespeare.lit</email>" - "</item>" - "<item jid=\"tybalt@shakespeare.lit\">" - "<first>Tybalt</first>" - "<last>Capulet</last>" - "<nick>ty</nick>" - "<email>tybalt@shakespeare.lit</email>" - "</item>" - "</query>" - )); - - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.com"), payload->getItems()[0].jid); - CPPUNIT_ASSERT_EQUAL(std::string("Juliet"), payload->getItems()[0].first); - CPPUNIT_ASSERT_EQUAL(std::string("Capulet"), payload->getItems()[0].last); - CPPUNIT_ASSERT_EQUAL(std::string("JuliC"), payload->getItems()[0].nick); - CPPUNIT_ASSERT_EQUAL(std::string("juliet@shakespeare.lit"), payload->getItems()[0].email); - CPPUNIT_ASSERT_EQUAL(JID("tybalt@shakespeare.lit"), payload->getItems()[1].jid); - } - - void testParse_FormRequestResponse_XDATA() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:search'>" - "<instructions>" - "Use the enclosed form to search. If your Jabber client does not" - " support Data Forms, visit http://shakespeare.lit/" - "</instructions>" - "<x xmlns='jabber:x:data' type='form'>" - "<title>User Directory Search</title>" - "<instructions>" - "Please provide the following information" - " to search for Shakespearean characters." - "</instructions>" - "<field type='hidden'" - " var='FORM_TYPE'>" - "<value>jabber:iq:search</value>" - "</field>" - "<field type='text-single'" - " label='Given Name'" - " var='first'/>" - "<field type='text-single'" - " label='Family Name'" - " var='last'/>" - "<field type='list-single'" - " label='Gender'" - " var='x-gender'>" - "<option label='Male'><value>male</value></option>" - "<option label='Female'><value>female</value></option>" - "</field>" - "</x>" - "</query>" - )); - - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to search. If your Jabber client does not" - " support Data Forms, visit http://shakespeare.lit/"), *payload->getInstructions()); - CPPUNIT_ASSERT(payload->getForm()); - CPPUNIT_ASSERT_EQUAL(std::string("Please provide the following information" - " to search for Shakespearean characters."), payload->getForm()->getInstructions()); - } - - void testParse_Results_XDATA() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:search'>" - " <x xmlns='jabber:x:data' type='result'>" - " <field type='hidden' var='FORM_TYPE'>" - " <value>jabber:iq:search</value>" - " </field>" - " <reported>" - " <field var='first' label='Given Name' type='text-single'/>" - " <field var='last' label='Family Name' type='text-single'/>" - " <field var='jid' label='Jabber ID' type='jid-single'/>" - " <field var='x-gender' label='Gender' type='list-single'/>" - " </reported>" - " <item>" - " <field var='first'><value>Benvolio</value></field>" - " <field var='last'><value>Montague</value></field>" - " <field var='jid'><value>benvolio@montague.net</value></field>" - " <field var='x-gender'><value>male</value></field>" - " </item>" - " <item>" - " <field var='first'><value>Romeo</value></field>" - " <field var='last'><value>Montague</value></field>" - " <field var='jid'><value>romeo@montague.net</value></field>" - " <field var='x-gender'><value>male</value></field>" - " </item>" - " </x>" - "</query>")); - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT(payload); - - Form::ref dataForm = payload->getForm(); - CPPUNIT_ASSERT(dataForm); - - Form::FormItem reported = dataForm->getReportedFields(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); - - std::vector<Form::FormItem> items = dataForm->getItems(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - Form::FormItem item = items[0]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("benvolio@montague.net"), item[2]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - - item = items[1]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("romeo@montague.net"), item[2]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - } + CPPUNIT_TEST_SUITE(SearchPayloadParserTest); + CPPUNIT_TEST(testParse_FormRequestResponse); + CPPUNIT_TEST(testParse_Results); + CPPUNIT_TEST(testParse_FormRequestResponse_XDATA); + CPPUNIT_TEST(testParse_Results_XDATA); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_FormRequestResponse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:search\">" + "<instructions>Foo</instructions>" + "<first/>" + "<last/>" + "</query>" + )); + + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT_EQUAL(std::string("Foo"), *payload->getInstructions()); + CPPUNIT_ASSERT(payload->getFirst()); + CPPUNIT_ASSERT(payload->getLast()); + CPPUNIT_ASSERT(!payload->getNick()); + } + + void testParse_Results() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:search\">" + "<item jid=\"juliet@capulet.com\">" + "<first>Juliet</first>" + "<last>Capulet</last>" + "<nick>JuliC</nick>" + "<email>juliet@shakespeare.lit</email>" + "</item>" + "<item jid=\"tybalt@shakespeare.lit\">" + "<first>Tybalt</first>" + "<last>Capulet</last>" + "<nick>ty</nick>" + "<email>tybalt@shakespeare.lit</email>" + "</item>" + "</query>" + )); + + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.com"), payload->getItems()[0].jid); + CPPUNIT_ASSERT_EQUAL(std::string("Juliet"), payload->getItems()[0].first); + CPPUNIT_ASSERT_EQUAL(std::string("Capulet"), payload->getItems()[0].last); + CPPUNIT_ASSERT_EQUAL(std::string("JuliC"), payload->getItems()[0].nick); + CPPUNIT_ASSERT_EQUAL(std::string("juliet@shakespeare.lit"), payload->getItems()[0].email); + CPPUNIT_ASSERT_EQUAL(JID("tybalt@shakespeare.lit"), payload->getItems()[1].jid); + } + + void testParse_FormRequestResponse_XDATA() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:search'>" + "<instructions>" + "Use the enclosed form to search. If your Jabber client does not" + " support Data Forms, visit http://shakespeare.lit/" + "</instructions>" + "<x xmlns='jabber:x:data' type='form'>" + "<title>User Directory Search</title>" + "<instructions>" + "Please provide the following information" + " to search for Shakespearean characters." + "</instructions>" + "<field type='hidden'" + " var='FORM_TYPE'>" + "<value>jabber:iq:search</value>" + "</field>" + "<field type='text-single'" + " label='Given Name'" + " var='first'/>" + "<field type='text-single'" + " label='Family Name'" + " var='last'/>" + "<field type='list-single'" + " label='Gender'" + " var='x-gender'>" + "<option label='Male'><value>male</value></option>" + "<option label='Female'><value>female</value></option>" + "</field>" + "</x>" + "</query>" + )); + + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to search. If your Jabber client does not" + " support Data Forms, visit http://shakespeare.lit/"), *payload->getInstructions()); + CPPUNIT_ASSERT(payload->getForm()); + CPPUNIT_ASSERT_EQUAL(std::string("Please provide the following information" + " to search for Shakespearean characters."), payload->getForm()->getInstructions()); + } + + void testParse_Results_XDATA() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:search'>" + " <x xmlns='jabber:x:data' type='result'>" + " <field type='hidden' var='FORM_TYPE'>" + " <value>jabber:iq:search</value>" + " </field>" + " <reported>" + " <field var='first' label='Given Name' type='text-single'/>" + " <field var='last' label='Family Name' type='text-single'/>" + " <field var='jid' label='Jabber ID' type='jid-single'/>" + " <field var='x-gender' label='Gender' type='list-single'/>" + " </reported>" + " <item>" + " <field var='first'><value>Benvolio</value></field>" + " <field var='last'><value>Montague</value></field>" + " <field var='jid'><value>benvolio@montague.net</value></field>" + " <field var='x-gender'><value>male</value></field>" + " </item>" + " <item>" + " <field var='first'><value>Romeo</value></field>" + " <field var='last'><value>Montague</value></field>" + " <field var='jid'><value>romeo@montague.net</value></field>" + " <field var='x-gender'><value>male</value></field>" + " </item>" + " </x>" + "</query>")); + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT(payload); + + Form::ref dataForm = payload->getForm(); + CPPUNIT_ASSERT(dataForm); + + Form::FormItem reported = dataForm->getReportedFields(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); + + std::vector<Form::FormItem> items = dataForm->getItems(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + Form::FormItem item = items[0]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("benvolio@montague.net"), item[2]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + + item = items[1]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("romeo@montague.net"), item[2]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SearchPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp index 14f1f17..c27b716 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp @@ -14,38 +14,38 @@ using namespace Swift; class SecurityLabelParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SecurityLabelParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - SecurityLabelParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking fgcolor=\"black\" bgcolor=\"red\">SECRET</displaymarking>" - "<label>" - "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" - "</label>" - "<equivalentlabel>" - "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" - "</equivalentlabel>" - "<equivalentlabel>" - "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" - "</equivalentlabel>" - "</securitylabel>")); - - SecurityLabel* payload = dynamic_cast<SecurityLabel*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getDisplayMarking()); - CPPUNIT_ASSERT_EQUAL(std::string("black"), payload->getForegroundColor()); - CPPUNIT_ASSERT_EQUAL(std::string("red"), payload->getBackgroundColor()); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("<icismlabel classification=\"S\" disseminationControls=\"FOUO\" ownerProducer=\"USA\" xmlns=\"http://example.gov/IC-ISM/0\"/>"), payload->getEquivalentLabels()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"), payload->getEquivalentLabels()[1]); - } + CPPUNIT_TEST_SUITE(SecurityLabelParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + SecurityLabelParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking fgcolor=\"black\" bgcolor=\"red\">SECRET</displaymarking>" + "<label>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" + "</label>" + "<equivalentlabel>" + "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" + "</equivalentlabel>" + "<equivalentlabel>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" + "</equivalentlabel>" + "</securitylabel>")); + + SecurityLabel* payload = dynamic_cast<SecurityLabel*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("black"), payload->getForegroundColor()); + CPPUNIT_ASSERT_EQUAL(std::string("red"), payload->getBackgroundColor()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("<icismlabel classification=\"S\" disseminationControls=\"FOUO\" ownerProducer=\"USA\" xmlns=\"http://example.gov/IC-ISM/0\"/>"), payload->getEquivalentLabels()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"), payload->getEquivalentLabels()[1]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp index f1745d0..2b992b1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp @@ -14,50 +14,50 @@ using namespace Swift; class SecurityLabelsCatalogParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SecurityLabelsCatalogParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - SecurityLabelsCatalogParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" - "<item selector='Classified|SECRET'>" - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" - "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" - "</securitylabel>" - "</item>" - "<item selector='Classified|CONFIDENTIAL' default='true'>" - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" - "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" - "</securitylabel>" - "</item>" - "<item selector='Unclassified|UNCLASSIFIED'/>" - "</catalog>")); - - SecurityLabelsCatalog* payload = dynamic_cast<SecurityLabelsCatalog*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Default"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("an example set of labels"), payload->getDescription()); - CPPUNIT_ASSERT_EQUAL(JID("example.com"), payload->getTo()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getItems().size())); - CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getItems()[0].getLabel()->getDisplayMarking()); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getItems()[0].getLabel()->getLabel()); - CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[0].getIsDefault()); - CPPUNIT_ASSERT_EQUAL(std::string("Classified|SECRET"), payload->getItems()[0].getSelector()); - CPPUNIT_ASSERT_EQUAL(std::string("CONFIDENTIAL"), payload->getItems()[1].getLabel()->getDisplayMarking()); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"), payload->getItems()[1].getLabel()->getLabel()); - CPPUNIT_ASSERT_EQUAL(true, payload->getItems()[1].getIsDefault()); - CPPUNIT_ASSERT_EQUAL(std::string("Classified|CONFIDENTIAL"), payload->getItems()[1].getSelector()); - CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[2].getIsDefault()); - CPPUNIT_ASSERT_EQUAL(std::string("Unclassified|UNCLASSIFIED"), payload->getItems()[2].getSelector()); - CPPUNIT_ASSERT(!payload->getItems()[2].getLabel()); - } + CPPUNIT_TEST_SUITE(SecurityLabelsCatalogParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + SecurityLabelsCatalogParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" + "<item selector='Classified|SECRET'>" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector='Classified|CONFIDENTIAL' default='true'>" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector='Unclassified|UNCLASSIFIED'/>" + "</catalog>")); + + SecurityLabelsCatalog* payload = dynamic_cast<SecurityLabelsCatalog*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Default"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("an example set of labels"), payload->getDescription()); + CPPUNIT_ASSERT_EQUAL(JID("example.com"), payload->getTo()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getItems()[0].getLabel()->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getItems()[0].getLabel()->getLabel()); + CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[0].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Classified|SECRET"), payload->getItems()[0].getSelector()); + CPPUNIT_ASSERT_EQUAL(std::string("CONFIDENTIAL"), payload->getItems()[1].getLabel()->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"), payload->getItems()[1].getLabel()->getLabel()); + CPPUNIT_ASSERT_EQUAL(true, payload->getItems()[1].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Classified|CONFIDENTIAL"), payload->getItems()[1].getSelector()); + CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[2].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Unclassified|UNCLASSIFIED"), payload->getItems()[2].getSelector()); + CPPUNIT_ASSERT(!payload->getItems()[2].getLabel()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelsCatalogParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp index 6650cb7..7471856 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp @@ -14,28 +14,28 @@ using namespace Swift; class SoftwareVersionParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SoftwareVersionParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - SoftwareVersionParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:version\">" - "<name>myclient</name>" - "<version>1.0</version>" - "<os>Mac OS X</os>" - "</query>")); - - SoftwareVersion* payload = dynamic_cast<SoftwareVersion*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("myclient"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("1.0"), payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string("Mac OS X"), payload->getOS()); - } + CPPUNIT_TEST_SUITE(SoftwareVersionParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + SoftwareVersionParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:version\">" + "<name>myclient</name>" + "<version>1.0</version>" + "<os>Mac OS X</os>" + "</query>")); + + SoftwareVersion* payload = dynamic_cast<SoftwareVersion*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("myclient"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("1.0"), payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("Mac OS X"), payload->getOS()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SoftwareVersionParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp index 5c7f467..6b93637 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp @@ -14,21 +14,21 @@ using namespace Swift; class StatusParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatusParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StatusParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - StatusParserTest() {} + public: + StatusParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<status>foo<baz>bar</baz>fum</status>")); + CPPUNIT_ASSERT(parser.parse("<status>foo<baz>bar</baz>fum</status>")); - Status* payload = dynamic_cast<Status*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); - } + Status* payload = dynamic_cast<Status*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StatusParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp index 98653ef..94f14c6 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp @@ -14,61 +14,61 @@ using namespace Swift; class StatusShowParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatusShowParserTest); - CPPUNIT_TEST(testParse_Invalid); - CPPUNIT_TEST(testParse_Away); - CPPUNIT_TEST(testParse_FFC); - CPPUNIT_TEST(testParse_XA); - CPPUNIT_TEST(testParse_DND); - CPPUNIT_TEST_SUITE_END(); - - public: - StatusShowParserTest() {} - - void testParse_Invalid() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>invalid</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::Online == payload->getType()); - } - - void testParse_Away() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>away</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::Away == payload->getType()); - } - - void testParse_FFC() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>chat</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::FFC == payload->getType()); - } - - void testParse_XA() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>xa</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::XA == payload->getType()); - } - - void testParse_DND() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>dnd</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::DND == payload->getType()); - } + CPPUNIT_TEST_SUITE(StatusShowParserTest); + CPPUNIT_TEST(testParse_Invalid); + CPPUNIT_TEST(testParse_Away); + CPPUNIT_TEST(testParse_FFC); + CPPUNIT_TEST(testParse_XA); + CPPUNIT_TEST(testParse_DND); + CPPUNIT_TEST_SUITE_END(); + + public: + StatusShowParserTest() {} + + void testParse_Invalid() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>invalid</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::Online == payload->getType()); + } + + void testParse_Away() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>away</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::Away == payload->getType()); + } + + void testParse_FFC() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>chat</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::FFC == payload->getType()); + } + + void testParse_XA() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>xa</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::XA == payload->getType()); + } + + void testParse_DND() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>dnd</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::DND == payload->getType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StatusShowParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp index 9797b6a..4430668 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp @@ -13,74 +13,74 @@ using namespace Swift; class StorageParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StorageParserTest); - CPPUNIT_TEST(testParse_Room); - CPPUNIT_TEST(testParse_MultipleRooms); - CPPUNIT_TEST(testParse_URL); - CPPUNIT_TEST_SUITE_END(); - - public: - StorageParserTest() {} - - void testParse_Room() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<storage xmlns='storage:bookmarks'>" - "<conference " - "name='Council of Oberon' " - "autojoin='true' jid='council@conference.underhill.org'>" - "<nick>Puck</nick>" - "<password>MyPass</password>" - "</conference>" - "</storage>")); - - Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); - std::vector<Storage::Room> rooms = payload->getRooms(); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rooms.size())); - CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); - CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); - CPPUNIT_ASSERT(rooms[0].autoJoin); - CPPUNIT_ASSERT_EQUAL(std::string("Puck"), rooms[0].nick); - CPPUNIT_ASSERT_EQUAL(std::string("MyPass"), *rooms[0].password); - } - - void testParse_MultipleRooms() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<storage xmlns='storage:bookmarks'>" - "<conference " - "name='Council of Oberon' " - "jid='council@conference.underhill.org' />" - "<conference " - "name='Tea & jam party' " - "jid='teaparty@wonderland.lit' />" - "</storage>")); - - Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); - std::vector<Storage::Room> rooms = payload->getRooms(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rooms.size())); - CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); - CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); - CPPUNIT_ASSERT_EQUAL(std::string("Tea & jam party"), rooms[1].name); - CPPUNIT_ASSERT_EQUAL(JID("teaparty@wonderland.lit"), rooms[1].jid); - } - - void testParse_URL() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<storage xmlns='storage:bookmarks'>" - "<url name='Complete Works of Shakespeare' url='http://the-tech.mit.edu/Shakespeare/'/>" - "</storage>")); - - Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); - std::vector<Storage::URL> urls = payload->getURLs(); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(urls.size())); - CPPUNIT_ASSERT_EQUAL(std::string("Complete Works of Shakespeare"), urls[0].name); - CPPUNIT_ASSERT_EQUAL(std::string("http://the-tech.mit.edu/Shakespeare/"), urls[0].url); - } + CPPUNIT_TEST_SUITE(StorageParserTest); + CPPUNIT_TEST(testParse_Room); + CPPUNIT_TEST(testParse_MultipleRooms); + CPPUNIT_TEST(testParse_URL); + CPPUNIT_TEST_SUITE_END(); + + public: + StorageParserTest() {} + + void testParse_Room() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<storage xmlns='storage:bookmarks'>" + "<conference " + "name='Council of Oberon' " + "autojoin='true' jid='council@conference.underhill.org'>" + "<nick>Puck</nick>" + "<password>MyPass</password>" + "</conference>" + "</storage>")); + + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); + std::vector<Storage::Room> rooms = payload->getRooms(); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rooms.size())); + CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); + CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); + CPPUNIT_ASSERT(rooms[0].autoJoin); + CPPUNIT_ASSERT_EQUAL(std::string("Puck"), rooms[0].nick); + CPPUNIT_ASSERT_EQUAL(std::string("MyPass"), *rooms[0].password); + } + + void testParse_MultipleRooms() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<storage xmlns='storage:bookmarks'>" + "<conference " + "name='Council of Oberon' " + "jid='council@conference.underhill.org' />" + "<conference " + "name='Tea & jam party' " + "jid='teaparty@wonderland.lit' />" + "</storage>")); + + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); + std::vector<Storage::Room> rooms = payload->getRooms(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rooms.size())); + CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); + CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); + CPPUNIT_ASSERT_EQUAL(std::string("Tea & jam party"), rooms[1].name); + CPPUNIT_ASSERT_EQUAL(JID("teaparty@wonderland.lit"), rooms[1].jid); + } + + void testParse_URL() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<storage xmlns='storage:bookmarks'>" + "<url name='Complete Works of Shakespeare' url='http://the-tech.mit.edu/Shakespeare/'/>" + "</storage>")); + + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); + std::vector<Storage::URL> urls = payload->getURLs(); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(urls.size())); + CPPUNIT_ASSERT_EQUAL(std::string("Complete Works of Shakespeare"), urls[0].name); + CPPUNIT_ASSERT_EQUAL(std::string("http://the-tech.mit.edu/Shakespeare/"), urls[0].url); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp index dbbaca8..9b0679d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp @@ -13,63 +13,63 @@ using namespace Swift; class StreamInitiationParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StreamInitiationParserTest); - CPPUNIT_TEST(testParse_Request); - CPPUNIT_TEST(testParse_Response); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StreamInitiationParserTest); + CPPUNIT_TEST(testParse_Request); + CPPUNIT_TEST(testParse_Response); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse_Request() { - PayloadsParserTester parser; + public: + void testParse_Request() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<si xmlns='http://jabber.org/protocol/si' id='a0' mime-type='text/plain' profile='http://jabber.org/protocol/si/profile/file-transfer'>" - "<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='test.txt' size='1022'>" - "<desc>This is info about the file.</desc>" - "</file>" - "<feature xmlns='http://jabber.org/protocol/feature-neg'>" - "<x xmlns='jabber:x:data' type='form'>" - "<field var='stream-method' type='list-single'>" - "<option><value>http://jabber.org/protocol/bytestreams</value></option>" - "<option><value>jabber:iq:oob</value></option>" - "<option><value>http://jabber.org/protocol/ibb</value></option>" - "</field>" - "</x>" - "</feature>" - "</si>" - )); + CPPUNIT_ASSERT(parser.parse( + "<si xmlns='http://jabber.org/protocol/si' id='a0' mime-type='text/plain' profile='http://jabber.org/protocol/si/profile/file-transfer'>" + "<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='test.txt' size='1022'>" + "<desc>This is info about the file.</desc>" + "</file>" + "<feature xmlns='http://jabber.org/protocol/feature-neg'>" + "<x xmlns='jabber:x:data' type='form'>" + "<field var='stream-method' type='list-single'>" + "<option><value>http://jabber.org/protocol/bytestreams</value></option>" + "<option><value>jabber:iq:oob</value></option>" + "<option><value>http://jabber.org/protocol/ibb</value></option>" + "</field>" + "</x>" + "</feature>" + "</si>" + )); - StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); - CPPUNIT_ASSERT(si->getIsFileTransfer()); - CPPUNIT_ASSERT(si->getFileInfo()); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), si->getFileInfo()->getName()); - CPPUNIT_ASSERT(1022 == si->getFileInfo()->getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is info about the file."), si->getFileInfo()->getDescription()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(si->getProvidedMethods().size())); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getProvidedMethods()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:oob"), si->getProvidedMethods()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/ibb"), si->getProvidedMethods()[2]); - } + StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); + CPPUNIT_ASSERT(si->getIsFileTransfer()); + CPPUNIT_ASSERT(si->getFileInfo()); + CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), si->getFileInfo()->getName()); + CPPUNIT_ASSERT(1022 == si->getFileInfo()->getSize()); + CPPUNIT_ASSERT_EQUAL(std::string("This is info about the file."), si->getFileInfo()->getDescription()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(si->getProvidedMethods().size())); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getProvidedMethods()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:oob"), si->getProvidedMethods()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/ibb"), si->getProvidedMethods()[2]); + } - void testParse_Response() { - PayloadsParserTester parser; + void testParse_Response() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<si xmlns='http://jabber.org/protocol/si'>" - "<feature xmlns='http://jabber.org/protocol/feature-neg'>" - "<x xmlns='jabber:x:data' type='submit'>" - "<field var='stream-method'>" - "<value>http://jabber.org/protocol/bytestreams</value>" - "</field>" - "</x>" - "</feature>" - "</si>" - )); + CPPUNIT_ASSERT(parser.parse( + "<si xmlns='http://jabber.org/protocol/si'>" + "<feature xmlns='http://jabber.org/protocol/feature-neg'>" + "<x xmlns='jabber:x:data' type='submit'>" + "<field var='stream-method'>" + "<value>http://jabber.org/protocol/bytestreams</value>" + "</field>" + "</x>" + "</feature>" + "</si>" + )); - StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); - CPPUNIT_ASSERT(si->getIsFileTransfer()); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getRequestedMethod()); - } + StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); + CPPUNIT_ASSERT(si->getIsFileTransfer()); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getRequestedMethod()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamInitiationParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp index d3bf378..6d16377 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp @@ -13,7 +13,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Base/DateTime.h> +#include <Swiften/Base/DateTime.h> #include <Swiften/Elements/UserLocation.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Parser/PayloadParsers/UserLocationParser.h> @@ -22,89 +22,89 @@ using namespace Swift; class UserLocationParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(UserLocationParserTest); - CPPUNIT_TEST(testParse_with_all_variables); - CPPUNIT_TEST(testParse_with_Some_variables); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(UserLocationParserTest); + CPPUNIT_TEST(testParse_with_all_variables); + CPPUNIT_TEST(testParse_with_Some_variables); + CPPUNIT_TEST_SUITE_END(); - public: - UserLocationParserTest() {} + public: + UserLocationParserTest() {} - void testParse_with_all_variables() { - PayloadsParserTester parser; + void testParse_with_all_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" - "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" - "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" - "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" - "<building>First</building><room>E315</room><country>USA</country>" - "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" - "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" - "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>")); + CPPUNIT_ASSERT(parser.parse( + "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + "<building>First</building><room>E315</room><country>USA</country>" + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" + "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>")); - UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); - CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); - CPPUNIT_ASSERT_EQUAL(1.670F, payload->getLatitude().get()); - CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); - CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); - CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); - CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); - CPPUNIT_ASSERT_EQUAL(std::string("First"), payload->getBuilding().get()); - CPPUNIT_ASSERT_EQUAL(std::string("E315"), payload->getRoom().get()); - CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getCountry().get()); - CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); - CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); - CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); - CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); - CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); - CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Datee"), payload->getDatum().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Highway"), payload->getStreet().get()); - CPPUNIT_ASSERT_EQUAL(56.77F, payload->getSpeed().get()); - } + UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); + CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); + CPPUNIT_ASSERT_EQUAL(1.670F, payload->getLatitude().get()); + CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); + CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); + CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); + CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); + CPPUNIT_ASSERT_EQUAL(std::string("First"), payload->getBuilding().get()); + CPPUNIT_ASSERT_EQUAL(std::string("E315"), payload->getRoom().get()); + CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getCountry().get()); + CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); + CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); + CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); + CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); + CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); + CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Datee"), payload->getDatum().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Highway"), payload->getStreet().get()); + CPPUNIT_ASSERT_EQUAL(56.77F, payload->getSpeed().get()); + } - void testParse_with_Some_variables() { - PayloadsParserTester parser; + void testParse_with_Some_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" - "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" - "<accuracy>0.95</accuracy><description>Nice</description>" - "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" - "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" - "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>")); + CPPUNIT_ASSERT(parser.parse( + "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + "<accuracy>0.95</accuracy><description>Nice</description>" + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>")); - UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); - CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); - CPPUNIT_ASSERT(!payload->getLatitude()); - CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); - CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); - CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); - CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); - CPPUNIT_ASSERT(!payload->getBuilding()); - CPPUNIT_ASSERT(!payload->getRoom()); - CPPUNIT_ASSERT(!payload->getCountry()); - CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); - CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); - CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); - CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); - CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); - CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); - CPPUNIT_ASSERT(!payload->getDatum()); - CPPUNIT_ASSERT(!payload->getStreet()); - CPPUNIT_ASSERT(!payload->getSpeed()); - } + UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); + CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); + CPPUNIT_ASSERT(!payload->getLatitude()); + CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); + CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); + CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); + CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); + CPPUNIT_ASSERT(!payload->getBuilding()); + CPPUNIT_ASSERT(!payload->getRoom()); + CPPUNIT_ASSERT(!payload->getCountry()); + CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); + CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); + CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); + CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); + CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); + CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); + CPPUNIT_ASSERT(!payload->getDatum()); + CPPUNIT_ASSERT(!payload->getStreet()); + CPPUNIT_ASSERT(!payload->getSpeed()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(UserLocationParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp index b1070c5..3783231 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp @@ -13,7 +13,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Base/DateTime.h> +#include <Swiften/Base/DateTime.h> #include <Swiften/Elements/UserTune.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Parser/PayloadParsers/UserTuneParser.h> @@ -22,49 +22,49 @@ using namespace Swift; class UserTuneParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(UserTuneParserTest); - CPPUNIT_TEST(testParse_with_all_variables); - CPPUNIT_TEST(testParse_with_Some_variables); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(UserTuneParserTest); + CPPUNIT_TEST(testParse_with_all_variables); + CPPUNIT_TEST(testParse_with_Some_variables); + CPPUNIT_TEST_SUITE_END(); - public: - UserTuneParserTest() {} + public: + UserTuneParserTest() {} - void testParse_with_all_variables() { - PayloadsParserTester parser; + void testParse_with_all_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<tune xmlns=\"http://jabber.org/protocol/tune\">" - "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>")); + CPPUNIT_ASSERT(parser.parse( + "<tune xmlns=\"http://jabber.org/protocol/tune\">" + "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>")); - UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), payload->getRating().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Ice"), payload->getArtist().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Fire"), payload->getURI().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); - } + UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), payload->getRating().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Ice"), payload->getArtist().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Fire"), payload->getURI().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); + } - void testParse_with_Some_variables() { - PayloadsParserTester parser; + void testParse_with_Some_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<tune xmlns=\"http://jabber.org/protocol/tune\">" - "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>")); + CPPUNIT_ASSERT(parser.parse( + "<tune xmlns=\"http://jabber.org/protocol/tune\">" + "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>")); - UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(!payload->getRating()); - CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); - CPPUNIT_ASSERT(!payload->getArtist()); - CPPUNIT_ASSERT(!payload->getURI()); - CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); - } + UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(!payload->getRating()); + CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); + CPPUNIT_ASSERT(!payload->getArtist()); + CPPUNIT_ASSERT(!payload->getURI()); + CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index 9e841a7..e02eb7a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -18,190 +18,190 @@ using namespace Swift; class VCardParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(VCardParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Photo); - CPPUNIT_TEST(testParse_NewlinedPhoto); - CPPUNIT_TEST(testParse_Nickname); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns=\"vcard-temp\">" - "<VERSION>2.0</VERSION>" - "<FN>Alice In Wonderland</FN>" - "<N>" - "<FAMILY>Wonderland</FAMILY>" - "<GIVEN>Alice</GIVEN>" - "<MIDDLE>In</MIDDLE>" - "<PREFIX>Mrs</PREFIX>" - "<SUFFIX>PhD</SUFFIX>" - "</N>" - "<EMAIL>" - "<USERID>alice@wonderland.lit</USERID>" - "<HOME/>" - "<INTERNET/>" - "<PREF/>" - "</EMAIL>" - "<EMAIL>" - "<USERID>alice@teaparty.lit</USERID>" - "<WORK/>" - "<X400/>" - "</EMAIL>" - "<TEL>" - "<NUMBER>555-6273</NUMBER>" - "<HOME/>" - "<VOICE/>" - "</TEL>" - "<ADR>" - "<LOCALITY>Any Town</LOCALITY>" - "<STREET>Fake Street 123</STREET>" - "<PCODE>12345</PCODE>" - "<CTRY>USA</CTRY>" - "<HOME/>" - "</ADR>" - "<LABEL>" - "<LINE>Fake Street 123</LINE>" - "<LINE>12345 Any Town</LINE>" - "<LINE>USA</LINE>" - "<HOME/>" - "</LABEL>" - "<NICKNAME>DreamGirl</NICKNAME>" - "<BDAY>1865-05-04</BDAY>" - "<JID>alice@teaparty.lit</JID>" - "<JID>alice@wonderland.lit</JID>" - "<DESC>I once fell down a rabbit hole.</DESC>" - "<ORG>" - "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" - "</ORG>" - "<TITLE>Some Title</TITLE>" - "<ROLE>Main Character</ROLE>" - "<URL>http://wonderland.lit/~alice</URL>" - "<URL>http://teaparty.lit/~alice2</URL>" - "<MAILER>mutt</MAILER>" - "</vCard>")); - - boost::shared_ptr<VCard> payload = boost::dynamic_pointer_cast<VCard>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("2.0"), payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), payload->getFullName()); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), payload->getGivenName()); - CPPUNIT_ASSERT_EQUAL(std::string("In"), payload->getMiddleName()); - CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), payload->getFamilyName()); - CPPUNIT_ASSERT_EQUAL(std::string("Mrs"), payload->getPrefix()); - CPPUNIT_ASSERT_EQUAL(std::string("PhD"), payload->getSuffix()); - CPPUNIT_ASSERT_EQUAL(std::string("DreamGirl"), payload->getNickname()); - CPPUNIT_ASSERT_EQUAL(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4)), payload->getBirthday()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getEMailAddresses().size())); - CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland.lit"), payload->getEMailAddresses()[0].address); - CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isHome); - CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isInternet); - CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isPreferred); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isWork); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isX400); - CPPUNIT_ASSERT_EQUAL(std::string("alice@teaparty.lit"), payload->getEMailAddresses()[1].address); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isHome); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isInternet); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isPreferred); - CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isWork); - CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isX400); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTelephones().size())); - CPPUNIT_ASSERT_EQUAL(std::string("555-6273"), payload->getTelephones()[0].number); - CPPUNIT_ASSERT(payload->getTelephones()[0].isHome); - CPPUNIT_ASSERT(payload->getTelephones()[0].isVoice); - CPPUNIT_ASSERT(!payload->getTelephones()[0].isPreferred); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddresses().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Any Town"), payload->getAddresses()[0].locality); - CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddresses()[0].street); - CPPUNIT_ASSERT_EQUAL(std::string("12345"), payload->getAddresses()[0].postalCode); - CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddresses()[0].country); - CPPUNIT_ASSERT(payload->getAddresses()[0].isHome); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddressLabels().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddressLabels()[0].lines[0]); - CPPUNIT_ASSERT_EQUAL(std::string("12345 Any Town"), payload->getAddressLabels()[0].lines[1]); - CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddressLabels()[0].lines[2]); - CPPUNIT_ASSERT(payload->getAddressLabels()[0].isHome); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getJIDs().size())); - CPPUNIT_ASSERT_EQUAL(JID("alice@teaparty.lit"), payload->getJIDs()[0]); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), payload->getJIDs()[1]); - - CPPUNIT_ASSERT_EQUAL(std::string("I once fell down a rabbit hole."), payload->getDescription()); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getOrganizations().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland Inc."), payload->getOrganizations()[0].name); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getOrganizations()[0].units.size())); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTitles().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Some Title"), payload->getTitles()[0]); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getRoles().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Main Character"), payload->getRoles()[0]); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getURLs().size())); - CPPUNIT_ASSERT_EQUAL(std::string("http://wonderland.lit/~alice"), payload->getURLs()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("http://teaparty.lit/~alice2"), payload->getURLs()[1]); - - CPPUNIT_ASSERT_EQUAL(std::string("<MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent()); - } - - void testParse_Photo() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns='vcard-temp'>" - "<PHOTO>" - "<TYPE>image/jpeg</TYPE>" - "<BINVAL>" - "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" - "EyMzQ1Njc4OTA=" - "</BINVAL>" - "</PHOTO>" - "</vCard>")); - - VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); - CPPUNIT_ASSERT_EQUAL(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto()); - } - - void testParse_NewlinedPhoto() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns='vcard-temp'>" - "<PHOTO>" - "<TYPE>image/jpeg</TYPE>" - "<BINVAL>" - "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n" - "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n" - "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n" - "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n" - "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo=" - "</BINVAL>" - "</PHOTO>" - "</vCard>")); - - VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); - CPPUNIT_ASSERT_EQUAL(createByteArray("\x75\x3B\x04\x4C\xA4\x80\xB2\x48\x2E\xDB\xF0\x6A\x54\xEF\xA8\x81\xCB\xB7\x0C\x9C\xB8\x40\x04\xC6\x26\xAA\x6C\x6B\xAC\xE7\x5B\x03\x46\x88\xB9\xD5\x12\x55\x55\x07\xA3\xED\x4B\xE9\x93\x88\x75\x17\xB2\xB3\xA5\x2A\xF4\x63\xB6\xFC\xD5\x54\x39\x27\x35\xA4\x45\xE7\xC1\x25\x9A\xEE\x44\x0B\xA5\x68\x0A\x59\x41\x10\x40\x7F\x94\x57\xF4\x7A\x66\x27\xDA\x09\x29\xD1\x7D\x64\x84\xD8\xBB\xE5\xD9\x7E\xAC\xE8\xFD\xE4\x0A\xFA\x5E\xEC\x0B\x87\xE6\x68\x49\x2B\x6A\xC0\xE5\xA3\xA4\x8A\x71\x99\x99\x95\xC3\xB1\x3A\xF6\xAA\xF4\x15\x8D\x28\x23\x7C\xDC\x6B\x15\xF0\xCC\x7C\x3B\x2F\x1F\x50\x7F\x8B\x07\xEE\xE7\xD0\xBC\x83\x7C\xF2\x06\xBE\x87\x0A\x7C\x32\x25\xDE\xBE\x1D\xC0\x73\xCA\x4D\xD3\x49\x20\x20\xD9\x6A\xF4\x06\x3F\x6D\x82\x4B\xE3\x5F\x18\xFF\xAC\x16\xB0\x96\xE0\x9A\xB2\x7F\x37\xBF\x30\x48\xCA\x42\xED\x55\x6C\xCC\xB0\x59\x56\xFF\x2E\x16\x7B\xA9\xB9\xBC\xA2\xF0\xEA\x61\x77\xFD\x70\x21\x65\xB3\x3C\xFC\x00\x6C\x18\x5E\xA5\x65\x5B\xD6\x83\xE2\x14\x40\x53\xE4\xC3\x4A\x08\xC4\xCF\x12\x2D\x27\xA5\x7B\x5E\x75\x5C\xF4\x1D\x06\xDB\x3C\xD2\x15\xC2\x6A", 257), payload->getPhoto()); - } - - - - void testParse_Nickname() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns='vcard-temp'>" - "<NICKNAME>mynick</NICKNAME>" - "</vCard>")); - - VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("mynick"), payload->getNickname()); - } + CPPUNIT_TEST_SUITE(VCardParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Photo); + CPPUNIT_TEST(testParse_NewlinedPhoto); + CPPUNIT_TEST(testParse_Nickname); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns=\"vcard-temp\">" + "<VERSION>2.0</VERSION>" + "<FN>Alice In Wonderland</FN>" + "<N>" + "<FAMILY>Wonderland</FAMILY>" + "<GIVEN>Alice</GIVEN>" + "<MIDDLE>In</MIDDLE>" + "<PREFIX>Mrs</PREFIX>" + "<SUFFIX>PhD</SUFFIX>" + "</N>" + "<EMAIL>" + "<USERID>alice@wonderland.lit</USERID>" + "<HOME/>" + "<INTERNET/>" + "<PREF/>" + "</EMAIL>" + "<EMAIL>" + "<USERID>alice@teaparty.lit</USERID>" + "<WORK/>" + "<X400/>" + "</EMAIL>" + "<TEL>" + "<NUMBER>555-6273</NUMBER>" + "<HOME/>" + "<VOICE/>" + "</TEL>" + "<ADR>" + "<LOCALITY>Any Town</LOCALITY>" + "<STREET>Fake Street 123</STREET>" + "<PCODE>12345</PCODE>" + "<CTRY>USA</CTRY>" + "<HOME/>" + "</ADR>" + "<LABEL>" + "<LINE>Fake Street 123</LINE>" + "<LINE>12345 Any Town</LINE>" + "<LINE>USA</LINE>" + "<HOME/>" + "</LABEL>" + "<NICKNAME>DreamGirl</NICKNAME>" + "<BDAY>1865-05-04</BDAY>" + "<JID>alice@teaparty.lit</JID>" + "<JID>alice@wonderland.lit</JID>" + "<DESC>I once fell down a rabbit hole.</DESC>" + "<ORG>" + "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" + "</ORG>" + "<TITLE>Some Title</TITLE>" + "<ROLE>Main Character</ROLE>" + "<URL>http://wonderland.lit/~alice</URL>" + "<URL>http://teaparty.lit/~alice2</URL>" + "<MAILER>mutt</MAILER>" + "</vCard>")); + + boost::shared_ptr<VCard> payload = boost::dynamic_pointer_cast<VCard>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("2.0"), payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), payload->getFullName()); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), payload->getGivenName()); + CPPUNIT_ASSERT_EQUAL(std::string("In"), payload->getMiddleName()); + CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), payload->getFamilyName()); + CPPUNIT_ASSERT_EQUAL(std::string("Mrs"), payload->getPrefix()); + CPPUNIT_ASSERT_EQUAL(std::string("PhD"), payload->getSuffix()); + CPPUNIT_ASSERT_EQUAL(std::string("DreamGirl"), payload->getNickname()); + CPPUNIT_ASSERT_EQUAL(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4)), payload->getBirthday()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getEMailAddresses().size())); + CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland.lit"), payload->getEMailAddresses()[0].address); + CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isHome); + CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isInternet); + CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isPreferred); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isWork); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isX400); + CPPUNIT_ASSERT_EQUAL(std::string("alice@teaparty.lit"), payload->getEMailAddresses()[1].address); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isHome); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isInternet); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isPreferred); + CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isWork); + CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isX400); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTelephones().size())); + CPPUNIT_ASSERT_EQUAL(std::string("555-6273"), payload->getTelephones()[0].number); + CPPUNIT_ASSERT(payload->getTelephones()[0].isHome); + CPPUNIT_ASSERT(payload->getTelephones()[0].isVoice); + CPPUNIT_ASSERT(!payload->getTelephones()[0].isPreferred); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddresses().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Any Town"), payload->getAddresses()[0].locality); + CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddresses()[0].street); + CPPUNIT_ASSERT_EQUAL(std::string("12345"), payload->getAddresses()[0].postalCode); + CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddresses()[0].country); + CPPUNIT_ASSERT(payload->getAddresses()[0].isHome); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddressLabels().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddressLabels()[0].lines[0]); + CPPUNIT_ASSERT_EQUAL(std::string("12345 Any Town"), payload->getAddressLabels()[0].lines[1]); + CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddressLabels()[0].lines[2]); + CPPUNIT_ASSERT(payload->getAddressLabels()[0].isHome); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getJIDs().size())); + CPPUNIT_ASSERT_EQUAL(JID("alice@teaparty.lit"), payload->getJIDs()[0]); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), payload->getJIDs()[1]); + + CPPUNIT_ASSERT_EQUAL(std::string("I once fell down a rabbit hole."), payload->getDescription()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getOrganizations().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland Inc."), payload->getOrganizations()[0].name); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getOrganizations()[0].units.size())); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTitles().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Some Title"), payload->getTitles()[0]); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getRoles().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Main Character"), payload->getRoles()[0]); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getURLs().size())); + CPPUNIT_ASSERT_EQUAL(std::string("http://wonderland.lit/~alice"), payload->getURLs()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("http://teaparty.lit/~alice2"), payload->getURLs()[1]); + + CPPUNIT_ASSERT_EQUAL(std::string("<MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent()); + } + + void testParse_Photo() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<PHOTO>" + "<TYPE>image/jpeg</TYPE>" + "<BINVAL>" + "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" + "EyMzQ1Njc4OTA=" + "</BINVAL>" + "</PHOTO>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); + CPPUNIT_ASSERT_EQUAL(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto()); + } + + void testParse_NewlinedPhoto() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<PHOTO>" + "<TYPE>image/jpeg</TYPE>" + "<BINVAL>" + "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n" + "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n" + "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n" + "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n" + "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo=" + "</BINVAL>" + "</PHOTO>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); + CPPUNIT_ASSERT_EQUAL(createByteArray("\x75\x3B\x04\x4C\xA4\x80\xB2\x48\x2E\xDB\xF0\x6A\x54\xEF\xA8\x81\xCB\xB7\x0C\x9C\xB8\x40\x04\xC6\x26\xAA\x6C\x6B\xAC\xE7\x5B\x03\x46\x88\xB9\xD5\x12\x55\x55\x07\xA3\xED\x4B\xE9\x93\x88\x75\x17\xB2\xB3\xA5\x2A\xF4\x63\xB6\xFC\xD5\x54\x39\x27\x35\xA4\x45\xE7\xC1\x25\x9A\xEE\x44\x0B\xA5\x68\x0A\x59\x41\x10\x40\x7F\x94\x57\xF4\x7A\x66\x27\xDA\x09\x29\xD1\x7D\x64\x84\xD8\xBB\xE5\xD9\x7E\xAC\xE8\xFD\xE4\x0A\xFA\x5E\xEC\x0B\x87\xE6\x68\x49\x2B\x6A\xC0\xE5\xA3\xA4\x8A\x71\x99\x99\x95\xC3\xB1\x3A\xF6\xAA\xF4\x15\x8D\x28\x23\x7C\xDC\x6B\x15\xF0\xCC\x7C\x3B\x2F\x1F\x50\x7F\x8B\x07\xEE\xE7\xD0\xBC\x83\x7C\xF2\x06\xBE\x87\x0A\x7C\x32\x25\xDE\xBE\x1D\xC0\x73\xCA\x4D\xD3\x49\x20\x20\xD9\x6A\xF4\x06\x3F\x6D\x82\x4B\xE3\x5F\x18\xFF\xAC\x16\xB0\x96\xE0\x9A\xB2\x7F\x37\xBF\x30\x48\xCA\x42\xED\x55\x6C\xCC\xB0\x59\x56\xFF\x2E\x16\x7B\xA9\xB9\xBC\xA2\xF0\xEA\x61\x77\xFD\x70\x21\x65\xB3\x3C\xFC\x00\x6C\x18\x5E\xA5\x65\x5B\xD6\x83\xE2\x14\x40\x53\xE4\xC3\x4A\x08\xC4\xCF\x12\x2D\x27\xA5\x7B\x5E\x75\x5C\xF4\x1D\x06\xDB\x3C\xD2\x15\xC2\x6A", 257), payload->getPhoto()); + } + + + + void testParse_Nickname() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<NICKNAME>mynick</NICKNAME>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("mynick"), payload->getNickname()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp index 7cf975a..11e8ded 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp @@ -14,24 +14,24 @@ using namespace Swift; class VCardUpdateParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(VCardUpdateParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(VCardUpdateParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - VCardUpdateParserTest() {} + public: + VCardUpdateParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<x xmlns='vcard-temp:x:update'>" - "<photo>sha1-hash-of-image</photo>" - "</x>")); + CPPUNIT_ASSERT(parser.parse( + "<x xmlns='vcard-temp:x:update'>" + "<photo>sha1-hash-of-image</photo>" + "</x>")); - VCardUpdate* payload = dynamic_cast<VCardUpdate*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("sha1-hash-of-image"), payload->getPhotoHash()); - } + VCardUpdate* payload = dynamic_cast<VCardUpdate*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("sha1-hash-of-image"), payload->getPhotoHash()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateParserTest); diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp index 4e98910..77a0fa1 100644 --- a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp @@ -19,88 +19,88 @@ UserLocationParser::~UserLocationParser() { } void UserLocationParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - if (level == 1) { - currentText = ""; - } - ++level; + if (level == 1) { + currentText = ""; + } + ++level; } void UserLocationParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == 1) { - try { - if (element == "accuracy") { - getPayloadInternal()->setAccuracy(boost::lexical_cast<float>(currentText)); - } - else if (element == "alt") { - getPayloadInternal()->setAltitude(boost::lexical_cast<float>(currentText)); - } - else if (element == "area") { - getPayloadInternal()->setArea(currentText); - } - else if (element == "bearing") { - getPayloadInternal()->setBearing(boost::lexical_cast<float>(currentText)); - } - else if (element == "building") { - getPayloadInternal()->setBuilding(currentText); - } - else if (element == "country") { - getPayloadInternal()->setCountry(currentText); - } - else if (element == "countrycode") { - getPayloadInternal()->setCountryCode(currentText); - } - else if (element == "datum") { - getPayloadInternal()->setDatum(currentText); - } - else if (element == "description") { - getPayloadInternal()->setDescription(currentText); - } - else if (element == "error") { - getPayloadInternal()->setError(boost::lexical_cast<float>(currentText)); - } - else if (element == "floor") { - getPayloadInternal()->setFloor(currentText); - } - else if (element == "lat") { - getPayloadInternal()->setLatitude(boost::lexical_cast<float>(currentText)); - } - else if (element == "locality") { - getPayloadInternal()->setLocality(currentText); - } - else if (element == "lon") { - getPayloadInternal()->setLongitude(boost::lexical_cast<float>(currentText)); - } - else if (element == "postalcode") { - getPayloadInternal()->setPostalCode(currentText); - } - else if (element == "region") { - getPayloadInternal()->setRegion(currentText); - } - else if (element == "room") { - getPayloadInternal()->setRoom(currentText); - } - else if (element == "speed") { - getPayloadInternal()->setSpeed(boost::lexical_cast<float>(currentText)); - } - else if (element == "street") { - getPayloadInternal()->setStreet(currentText); - } - else if (element == "text") { - getPayloadInternal()->setText(currentText); - } - else if (element == "timestamp") { - getPayloadInternal()->setTimestamp(stringToDateTime(currentText)); - } - else if (element == "uri") { - getPayloadInternal()->setURI(currentText); - } - } - catch (const boost::bad_lexical_cast&) { - } - } + --level; + if (level == 1) { + try { + if (element == "accuracy") { + getPayloadInternal()->setAccuracy(boost::lexical_cast<float>(currentText)); + } + else if (element == "alt") { + getPayloadInternal()->setAltitude(boost::lexical_cast<float>(currentText)); + } + else if (element == "area") { + getPayloadInternal()->setArea(currentText); + } + else if (element == "bearing") { + getPayloadInternal()->setBearing(boost::lexical_cast<float>(currentText)); + } + else if (element == "building") { + getPayloadInternal()->setBuilding(currentText); + } + else if (element == "country") { + getPayloadInternal()->setCountry(currentText); + } + else if (element == "countrycode") { + getPayloadInternal()->setCountryCode(currentText); + } + else if (element == "datum") { + getPayloadInternal()->setDatum(currentText); + } + else if (element == "description") { + getPayloadInternal()->setDescription(currentText); + } + else if (element == "error") { + getPayloadInternal()->setError(boost::lexical_cast<float>(currentText)); + } + else if (element == "floor") { + getPayloadInternal()->setFloor(currentText); + } + else if (element == "lat") { + getPayloadInternal()->setLatitude(boost::lexical_cast<float>(currentText)); + } + else if (element == "locality") { + getPayloadInternal()->setLocality(currentText); + } + else if (element == "lon") { + getPayloadInternal()->setLongitude(boost::lexical_cast<float>(currentText)); + } + else if (element == "postalcode") { + getPayloadInternal()->setPostalCode(currentText); + } + else if (element == "region") { + getPayloadInternal()->setRegion(currentText); + } + else if (element == "room") { + getPayloadInternal()->setRoom(currentText); + } + else if (element == "speed") { + getPayloadInternal()->setSpeed(boost::lexical_cast<float>(currentText)); + } + else if (element == "street") { + getPayloadInternal()->setStreet(currentText); + } + else if (element == "text") { + getPayloadInternal()->setText(currentText); + } + else if (element == "timestamp") { + getPayloadInternal()->setTimestamp(stringToDateTime(currentText)); + } + else if (element == "uri") { + getPayloadInternal()->setURI(currentText); + } + } + catch (const boost::bad_lexical_cast&) { + } + } } void UserLocationParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.h b/Swiften/Parser/PayloadParsers/UserLocationParser.h index 5782dc0..c2a226e 100644 --- a/Swiften/Parser/PayloadParsers/UserLocationParser.h +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.h @@ -16,17 +16,17 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> { - public: - UserLocationParser(); - virtual ~UserLocationParser(); + class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> { + public: + UserLocationParser(); + virtual ~UserLocationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - int level; - std::string currentText; - }; + private: + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.cpp b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp index f3f42ef..f030f8f 100644 --- a/Swiften/Parser/PayloadParsers/UserTuneParser.cpp +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp @@ -17,43 +17,43 @@ UserTuneParser::~UserTuneParser() { } void UserTuneParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - if (level == 1) { - currentText = ""; - } - ++level; + if (level == 1) { + currentText = ""; + } + ++level; } void UserTuneParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == 1) { - try { - if (element == "artist") { - getPayloadInternal()->setArtist(currentText); - } - else if (element == "length") { - getPayloadInternal()->setLength(boost::lexical_cast<unsigned int>(currentText)); - } - else if (element == "rating") { - getPayloadInternal()->setRating(boost::lexical_cast<unsigned int>(currentText)); - } - else if (element == "source") { - getPayloadInternal()->setSource(currentText); - } - else if (element == "title") { - getPayloadInternal()->setTitle(currentText); - } - else if (element == "track") { - getPayloadInternal()->setTrack(currentText); - } - else if (element == "URI") { - getPayloadInternal()->setURI(currentText); - } - } - catch (const boost::bad_lexical_cast&) { - } - } + --level; + if (level == 1) { + try { + if (element == "artist") { + getPayloadInternal()->setArtist(currentText); + } + else if (element == "length") { + getPayloadInternal()->setLength(boost::lexical_cast<unsigned int>(currentText)); + } + else if (element == "rating") { + getPayloadInternal()->setRating(boost::lexical_cast<unsigned int>(currentText)); + } + else if (element == "source") { + getPayloadInternal()->setSource(currentText); + } + else if (element == "title") { + getPayloadInternal()->setTitle(currentText); + } + else if (element == "track") { + getPayloadInternal()->setTrack(currentText); + } + else if (element == "URI") { + getPayloadInternal()->setURI(currentText); + } + } + catch (const boost::bad_lexical_cast&) { + } + } } void UserTuneParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.h b/Swiften/Parser/PayloadParsers/UserTuneParser.h index b208784..5c35074 100644 --- a/Swiften/Parser/PayloadParsers/UserTuneParser.h +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.h @@ -16,17 +16,17 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> { - public: - UserTuneParser(); - virtual ~UserTuneParser(); + class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> { + public: + UserTuneParser(); + virtual ~UserTuneParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - int level; - std::string currentText; - }; + private: + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index faf29d2..9f22c23 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -17,273 +17,273 @@ VCardParser::VCardParser() : unknownContentParser_(NULL) { } void VCardParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - elementStack_.push_back(element); - std::string elementHierarchy = getElementHierarchy(); - if (elementHierarchy == "/vCard/EMAIL") { - currentEMailAddress_ = VCard::EMailAddress(); - } - if (elementHierarchy == "/vCard/TEL") { - currentTelephone_ = VCard::Telephone(); - } - if (elementHierarchy == "/vCard/ADR") { - currentAddress_ = VCard::Address(); - } - if (elementHierarchy == "/vCard/LABEL") { - currentAddressLabel_ = VCard::AddressLabel(); - } - if (elementHierarchy == "/vCard/ORG") { - currentOrganization_ = VCard::Organization(); - } - if (elementStack_.size() == 2) { - assert(!unknownContentParser_); - unknownContentParser_ = new SerializingParser(); - unknownContentParser_->handleStartElement(element, ns, attributes); - } - else if (unknownContentParser_) { - unknownContentParser_->handleStartElement(element, ns, attributes); - } + elementStack_.push_back(element); + std::string elementHierarchy = getElementHierarchy(); + if (elementHierarchy == "/vCard/EMAIL") { + currentEMailAddress_ = VCard::EMailAddress(); + } + if (elementHierarchy == "/vCard/TEL") { + currentTelephone_ = VCard::Telephone(); + } + if (elementHierarchy == "/vCard/ADR") { + currentAddress_ = VCard::Address(); + } + if (elementHierarchy == "/vCard/LABEL") { + currentAddressLabel_ = VCard::AddressLabel(); + } + if (elementHierarchy == "/vCard/ORG") { + currentOrganization_ = VCard::Organization(); + } + if (elementStack_.size() == 2) { + assert(!unknownContentParser_); + unknownContentParser_ = new SerializingParser(); + unknownContentParser_->handleStartElement(element, ns, attributes); + } + else if (unknownContentParser_) { + unknownContentParser_->handleStartElement(element, ns, attributes); + } - currentText_ = ""; + currentText_ = ""; } void VCardParser::handleEndElement(const std::string& element, const std::string& ns) { - if (unknownContentParser_) { - unknownContentParser_->handleEndElement(element, ns); - } + if (unknownContentParser_) { + unknownContentParser_->handleEndElement(element, ns); + } - std::string elementHierarchy = getElementHierarchy(); - if (elementHierarchy == "/vCard/VERSION") { - getPayloadInternal()->setVersion(currentText_); - } - else if (elementHierarchy == "/vCard/FN") { - getPayloadInternal()->setFullName(currentText_); - } - else if (elementHierarchy == "/vCard/N/FAMILY") { - getPayloadInternal()->setFamilyName(currentText_); - } - else if (elementHierarchy == "/vCard/N/GIVEN") { - getPayloadInternal()->setGivenName(currentText_); - } - else if (elementHierarchy == "/vCard/N/MIDDLE") { - getPayloadInternal()->setMiddleName(currentText_); - } - else if (elementHierarchy == "/vCard/N/PREFIX") { - getPayloadInternal()->setPrefix(currentText_); - } - else if (elementHierarchy == "/vCard/N/SUFFIX") { - getPayloadInternal()->setSuffix(currentText_); - } - else if (elementHierarchy == "/vCard/N") { - } - else if (elementHierarchy == "/vCard/NICKNAME") { - getPayloadInternal()->setNickname(currentText_); - } - else if (elementHierarchy == "/vCard/PHOTO/TYPE") { - getPayloadInternal()->setPhotoType(currentText_); - } - else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { - currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\n'), currentText_.end()); - currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\r'), currentText_.end()); - getPayloadInternal()->setPhoto(Base64::decode(currentText_)); - } - else if (elementHierarchy == "/vCard/PHOTO") { - } - else if (elementHierarchy == "/vCard/EMAIL/USERID") { - currentEMailAddress_.address = currentText_; - } - else if (elementHierarchy == "/vCard/EMAIL/HOME") { - currentEMailAddress_.isHome = true; - } - else if (elementHierarchy == "/vCard/EMAIL/WORK") { - currentEMailAddress_.isWork = true; - } - else if (elementHierarchy == "/vCard/EMAIL/INTERNET") { - currentEMailAddress_.isInternet = true; - } - else if (elementHierarchy == "/vCard/EMAIL/X400") { - currentEMailAddress_.isX400 = true; - } - else if (elementHierarchy == "/vCard/EMAIL/PREF") { - currentEMailAddress_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/EMAIL" && !currentEMailAddress_.address.empty()) { - getPayloadInternal()->addEMailAddress(currentEMailAddress_); - } - else if (elementHierarchy == "/vCard/BDAY" && !currentText_.empty()) { - getPayloadInternal()->setBirthday(stringToDateTime(currentText_)); - } - else if (elementHierarchy == "/vCard/TEL/NUMBER") { - currentTelephone_.number = currentText_; - } - else if (elementHierarchy == "/vCard/TEL/HOME") { - currentTelephone_.isHome = true; - } - else if (elementHierarchy == "/vCard/TEL/WORK") { - currentTelephone_.isWork = true; - } - else if (elementHierarchy == "/vCard/TEL/VOICE") { - currentTelephone_.isVoice = true; - } - else if (elementHierarchy == "/vCard/TEL/FAX") { - currentTelephone_.isFax = true; - } - else if (elementHierarchy == "/vCard/TEL/PAGER") { - currentTelephone_.isPager = true; - } - else if (elementHierarchy == "/vCard/TEL/MSG") { - currentTelephone_.isMSG = true; - } - else if (elementHierarchy == "/vCard/TEL/CELL") { - currentTelephone_.isCell = true; - } - else if (elementHierarchy == "/vCard/TEL/VIDEO") { - currentTelephone_.isVideo = true; - } - else if (elementHierarchy == "/vCard/TEL/BBS") { - currentTelephone_.isBBS = true; - } - else if (elementHierarchy == "/vCard/TEL/MODEM") { - currentTelephone_.isModem = true; - } - else if (elementHierarchy == "/vCard/TEL/ISDN") { - currentTelephone_.isISDN = true; - } - else if (elementHierarchy == "/vCard/TEL/PCS") { - currentTelephone_.isPCS = true; - } - else if (elementHierarchy == "/vCard/TEL/PREF") { - currentTelephone_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/TEL" && !currentTelephone_.number.empty()) { - getPayloadInternal()->addTelephone(currentTelephone_); - } - else if (elementHierarchy == "/vCard/ADR/HOME") { - currentAddress_.isHome = true; - } - else if (elementHierarchy == "/vCard/ADR/WORK") { - currentAddress_.isWork = true; - } - else if (elementHierarchy == "/vCard/ADR/POSTAL") { - currentAddress_.isPostal = true; - } - else if (elementHierarchy == "/vCard/ADR/PARCEL") { - currentAddress_.isParcel = true; - } - else if (elementHierarchy == "/vCard/ADR/DOM") { - currentAddress_.deliveryType = VCard::DomesticDelivery; - } - else if (elementHierarchy == "/vCard/ADR/INTL") { - currentAddress_.deliveryType = VCard::InternationalDelivery; - } - else if (elementHierarchy == "/vCard/ADR/PREF") { - currentAddress_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/ADR/POBOX") { - currentAddress_.poBox = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/EXTADD") { - currentAddress_.addressExtension = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/STREET") { - currentAddress_.street = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/LOCALITY") { - currentAddress_.locality = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/REGION") { - currentAddress_.region = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/PCODE") { - currentAddress_.postalCode = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/CTRY") { - currentAddress_.country = currentText_; - } - else if (elementHierarchy == "/vCard/ADR") { - if (!currentAddress_.poBox.empty() || !currentAddress_.addressExtension.empty() || - !currentAddress_.street.empty() || !currentAddress_.locality.empty() || - !currentAddress_.region.empty() || !currentAddress_.region.empty() || - !currentAddress_.postalCode.empty() || !currentAddress_.country.empty()) { - getPayloadInternal()->addAddress(currentAddress_); - } - } - else if (elementHierarchy == "/vCard/LABEL/HOME") { - currentAddressLabel_.isHome = true; - } - else if (elementHierarchy == "/vCard/LABEL/WORK") { - currentAddressLabel_.isWork = true; - } - else if (elementHierarchy == "/vCard/LABEL/POSTAL") { - currentAddressLabel_.isPostal = true; - } - else if (elementHierarchy == "/vCard/LABEL/PARCEL") { - currentAddressLabel_.isParcel = true; - } - else if (elementHierarchy == "/vCard/LABEL/DOM") { - currentAddressLabel_.deliveryType = VCard::DomesticDelivery; - } - else if (elementHierarchy == "/vCard/LABEL/INTL") { - currentAddressLabel_.deliveryType = VCard::InternationalDelivery; - } - else if (elementHierarchy == "/vCard/LABEL/PREF") { - currentAddressLabel_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/LABEL/LINE") { - currentAddressLabel_.lines.push_back(currentText_); - } - else if (elementHierarchy == "/vCard/LABEL") { - getPayloadInternal()->addAddressLabel(currentAddressLabel_); - } - else if (elementHierarchy == "/vCard/JID" && !currentText_.empty()) { - getPayloadInternal()->addJID(JID(currentText_)); - } - else if (elementHierarchy == "/vCard/DESC") { - getPayloadInternal()->setDescription(currentText_); - } - else if (elementHierarchy == "/vCard/ORG/ORGNAME") { - currentOrganization_.name = currentText_; - } - else if (elementHierarchy == "/vCard/ORG/ORGUNIT" && !currentText_.empty()) { - currentOrganization_.units.push_back(currentText_); - } - else if (elementHierarchy == "/vCard/ORG") { - if (!currentOrganization_.name.empty() || !currentOrganization_.units.empty()) { - getPayloadInternal()->addOrganization(currentOrganization_); - } - } - else if (elementHierarchy == "/vCard/TITLE" && !currentText_.empty()) { - getPayloadInternal()->addTitle(currentText_); - } - else if (elementHierarchy == "/vCard/ROLE" && !currentText_.empty()) { - getPayloadInternal()->addRole(currentText_); - } - else if (elementHierarchy == "/vCard/URL" && !currentText_.empty()) { - getPayloadInternal()->addURL(currentText_); - } - else if (elementStack_.size() == 2 && unknownContentParser_) { - getPayloadInternal()->addUnknownContent(unknownContentParser_->getResult()); - } + std::string elementHierarchy = getElementHierarchy(); + if (elementHierarchy == "/vCard/VERSION") { + getPayloadInternal()->setVersion(currentText_); + } + else if (elementHierarchy == "/vCard/FN") { + getPayloadInternal()->setFullName(currentText_); + } + else if (elementHierarchy == "/vCard/N/FAMILY") { + getPayloadInternal()->setFamilyName(currentText_); + } + else if (elementHierarchy == "/vCard/N/GIVEN") { + getPayloadInternal()->setGivenName(currentText_); + } + else if (elementHierarchy == "/vCard/N/MIDDLE") { + getPayloadInternal()->setMiddleName(currentText_); + } + else if (elementHierarchy == "/vCard/N/PREFIX") { + getPayloadInternal()->setPrefix(currentText_); + } + else if (elementHierarchy == "/vCard/N/SUFFIX") { + getPayloadInternal()->setSuffix(currentText_); + } + else if (elementHierarchy == "/vCard/N") { + } + else if (elementHierarchy == "/vCard/NICKNAME") { + getPayloadInternal()->setNickname(currentText_); + } + else if (elementHierarchy == "/vCard/PHOTO/TYPE") { + getPayloadInternal()->setPhotoType(currentText_); + } + else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { + currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\n'), currentText_.end()); + currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\r'), currentText_.end()); + getPayloadInternal()->setPhoto(Base64::decode(currentText_)); + } + else if (elementHierarchy == "/vCard/PHOTO") { + } + else if (elementHierarchy == "/vCard/EMAIL/USERID") { + currentEMailAddress_.address = currentText_; + } + else if (elementHierarchy == "/vCard/EMAIL/HOME") { + currentEMailAddress_.isHome = true; + } + else if (elementHierarchy == "/vCard/EMAIL/WORK") { + currentEMailAddress_.isWork = true; + } + else if (elementHierarchy == "/vCard/EMAIL/INTERNET") { + currentEMailAddress_.isInternet = true; + } + else if (elementHierarchy == "/vCard/EMAIL/X400") { + currentEMailAddress_.isX400 = true; + } + else if (elementHierarchy == "/vCard/EMAIL/PREF") { + currentEMailAddress_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/EMAIL" && !currentEMailAddress_.address.empty()) { + getPayloadInternal()->addEMailAddress(currentEMailAddress_); + } + else if (elementHierarchy == "/vCard/BDAY" && !currentText_.empty()) { + getPayloadInternal()->setBirthday(stringToDateTime(currentText_)); + } + else if (elementHierarchy == "/vCard/TEL/NUMBER") { + currentTelephone_.number = currentText_; + } + else if (elementHierarchy == "/vCard/TEL/HOME") { + currentTelephone_.isHome = true; + } + else if (elementHierarchy == "/vCard/TEL/WORK") { + currentTelephone_.isWork = true; + } + else if (elementHierarchy == "/vCard/TEL/VOICE") { + currentTelephone_.isVoice = true; + } + else if (elementHierarchy == "/vCard/TEL/FAX") { + currentTelephone_.isFax = true; + } + else if (elementHierarchy == "/vCard/TEL/PAGER") { + currentTelephone_.isPager = true; + } + else if (elementHierarchy == "/vCard/TEL/MSG") { + currentTelephone_.isMSG = true; + } + else if (elementHierarchy == "/vCard/TEL/CELL") { + currentTelephone_.isCell = true; + } + else if (elementHierarchy == "/vCard/TEL/VIDEO") { + currentTelephone_.isVideo = true; + } + else if (elementHierarchy == "/vCard/TEL/BBS") { + currentTelephone_.isBBS = true; + } + else if (elementHierarchy == "/vCard/TEL/MODEM") { + currentTelephone_.isModem = true; + } + else if (elementHierarchy == "/vCard/TEL/ISDN") { + currentTelephone_.isISDN = true; + } + else if (elementHierarchy == "/vCard/TEL/PCS") { + currentTelephone_.isPCS = true; + } + else if (elementHierarchy == "/vCard/TEL/PREF") { + currentTelephone_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/TEL" && !currentTelephone_.number.empty()) { + getPayloadInternal()->addTelephone(currentTelephone_); + } + else if (elementHierarchy == "/vCard/ADR/HOME") { + currentAddress_.isHome = true; + } + else if (elementHierarchy == "/vCard/ADR/WORK") { + currentAddress_.isWork = true; + } + else if (elementHierarchy == "/vCard/ADR/POSTAL") { + currentAddress_.isPostal = true; + } + else if (elementHierarchy == "/vCard/ADR/PARCEL") { + currentAddress_.isParcel = true; + } + else if (elementHierarchy == "/vCard/ADR/DOM") { + currentAddress_.deliveryType = VCard::DomesticDelivery; + } + else if (elementHierarchy == "/vCard/ADR/INTL") { + currentAddress_.deliveryType = VCard::InternationalDelivery; + } + else if (elementHierarchy == "/vCard/ADR/PREF") { + currentAddress_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/ADR/POBOX") { + currentAddress_.poBox = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/EXTADD") { + currentAddress_.addressExtension = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/STREET") { + currentAddress_.street = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/LOCALITY") { + currentAddress_.locality = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/REGION") { + currentAddress_.region = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/PCODE") { + currentAddress_.postalCode = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/CTRY") { + currentAddress_.country = currentText_; + } + else if (elementHierarchy == "/vCard/ADR") { + if (!currentAddress_.poBox.empty() || !currentAddress_.addressExtension.empty() || + !currentAddress_.street.empty() || !currentAddress_.locality.empty() || + !currentAddress_.region.empty() || !currentAddress_.region.empty() || + !currentAddress_.postalCode.empty() || !currentAddress_.country.empty()) { + getPayloadInternal()->addAddress(currentAddress_); + } + } + else if (elementHierarchy == "/vCard/LABEL/HOME") { + currentAddressLabel_.isHome = true; + } + else if (elementHierarchy == "/vCard/LABEL/WORK") { + currentAddressLabel_.isWork = true; + } + else if (elementHierarchy == "/vCard/LABEL/POSTAL") { + currentAddressLabel_.isPostal = true; + } + else if (elementHierarchy == "/vCard/LABEL/PARCEL") { + currentAddressLabel_.isParcel = true; + } + else if (elementHierarchy == "/vCard/LABEL/DOM") { + currentAddressLabel_.deliveryType = VCard::DomesticDelivery; + } + else if (elementHierarchy == "/vCard/LABEL/INTL") { + currentAddressLabel_.deliveryType = VCard::InternationalDelivery; + } + else if (elementHierarchy == "/vCard/LABEL/PREF") { + currentAddressLabel_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/LABEL/LINE") { + currentAddressLabel_.lines.push_back(currentText_); + } + else if (elementHierarchy == "/vCard/LABEL") { + getPayloadInternal()->addAddressLabel(currentAddressLabel_); + } + else if (elementHierarchy == "/vCard/JID" && !currentText_.empty()) { + getPayloadInternal()->addJID(JID(currentText_)); + } + else if (elementHierarchy == "/vCard/DESC") { + getPayloadInternal()->setDescription(currentText_); + } + else if (elementHierarchy == "/vCard/ORG/ORGNAME") { + currentOrganization_.name = currentText_; + } + else if (elementHierarchy == "/vCard/ORG/ORGUNIT" && !currentText_.empty()) { + currentOrganization_.units.push_back(currentText_); + } + else if (elementHierarchy == "/vCard/ORG") { + if (!currentOrganization_.name.empty() || !currentOrganization_.units.empty()) { + getPayloadInternal()->addOrganization(currentOrganization_); + } + } + else if (elementHierarchy == "/vCard/TITLE" && !currentText_.empty()) { + getPayloadInternal()->addTitle(currentText_); + } + else if (elementHierarchy == "/vCard/ROLE" && !currentText_.empty()) { + getPayloadInternal()->addRole(currentText_); + } + else if (elementHierarchy == "/vCard/URL" && !currentText_.empty()) { + getPayloadInternal()->addURL(currentText_); + } + else if (elementStack_.size() == 2 && unknownContentParser_) { + getPayloadInternal()->addUnknownContent(unknownContentParser_->getResult()); + } - if (elementStack_.size() == 2 && unknownContentParser_) { - delete unknownContentParser_; - unknownContentParser_ = NULL; - } - elementStack_.pop_back(); + if (elementStack_.size() == 2 && unknownContentParser_) { + delete unknownContentParser_; + unknownContentParser_ = NULL; + } + elementStack_.pop_back(); } void VCardParser::handleCharacterData(const std::string& text) { - if (unknownContentParser_) { - unknownContentParser_->handleCharacterData(text); - } - currentText_ += text; + if (unknownContentParser_) { + unknownContentParser_->handleCharacterData(text); + } + currentText_ += text; } std::string VCardParser::getElementHierarchy() const { - std::string result; - foreach(const std::string& element, elementStack_) { - result += "/" + element; - } - return result; + std::string result; + foreach(const std::string& element, elementStack_) { + result += "/" + element; + } + return result; } } diff --git a/Swiften/Parser/PayloadParsers/VCardParser.h b/Swiften/Parser/PayloadParsers/VCardParser.h index f0dbf06..5a47cbf 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.h +++ b/Swiften/Parser/PayloadParsers/VCardParser.h @@ -11,27 +11,27 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API VCardParser : public GenericPayloadParser<VCard> { - public: - VCardParser(); + class SWIFTEN_API VCardParser : public GenericPayloadParser<VCard> { + public: + VCardParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - std::string getElementHierarchy() const; + private: + std::string getElementHierarchy() const; - private: - std::vector<std::string> elementStack_; - VCard::EMailAddress currentEMailAddress_; - VCard::Telephone currentTelephone_; - VCard::Address currentAddress_; - VCard::AddressLabel currentAddressLabel_; - VCard::Organization currentOrganization_; - SerializingParser* unknownContentParser_; - std::string currentText_; - }; + private: + std::vector<std::string> elementStack_; + VCard::EMailAddress currentEMailAddress_; + VCard::Telephone currentTelephone_; + VCard::Address currentAddress_; + VCard::AddressLabel currentAddressLabel_; + VCard::Organization currentOrganization_; + SerializingParser* unknownContentParser_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp index 4e0cd47..64559ae 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp @@ -12,21 +12,21 @@ VCardUpdateParser::VCardUpdateParser() : level_(TopLevel) { } void VCardUpdateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - if (level_ == PayloadLevel) { - currentText_ = ""; - } - ++level_; + if (level_ == PayloadLevel) { + currentText_ = ""; + } + ++level_; } void VCardUpdateParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel && element == "photo") { - getPayloadInternal()->setPhotoHash(currentText_); - } + --level_; + if (level_ == PayloadLevel && element == "photo") { + getPayloadInternal()->setPhotoHash(currentText_); + } } void VCardUpdateParser::handleCharacterData(const std::string& text) { - currentText_ += text; + currentText_ += text; } } diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h index cbd08e7..914f138 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h @@ -11,22 +11,22 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API VCardUpdateParser : public GenericPayloadParser<VCardUpdate> { - public: - VCardUpdateParser(); + class SWIFTEN_API VCardUpdateParser : public GenericPayloadParser<VCardUpdate> { + public: + VCardUpdateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - std::string currentText_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp index 09f09e3..b9786c9 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp @@ -28,296 +28,296 @@ #include <Swiften/Elements/Whiteboard/WhiteboardUpdateOperation.h> namespace Swift { - WhiteboardParser::WhiteboardParser() : actualIsText(false), level_(0) { - } + WhiteboardParser::WhiteboardParser() : actualIsText(false), level_(0) { + } - void WhiteboardParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level_ == 0) { - getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or(""))); - } else if (level_ == 1) { - std::string type = attributes.getAttributeValue("type").get_value_or(""); - if (type == "insert") { - WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>(); - operation = insertOp; - } else if (type == "update") { - WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(); - std::string move = attributes.getAttributeValue("newpos").get_value_or("0"); - updateOp->setNewPos(boost::lexical_cast<int>(attributes.getAttributeValue("newpos").get_value_or("0"))); - operation = updateOp; - } else if (type == "delete") { - WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>(); - deleteOp->setElementID(attributes.getAttributeValue("elementid").get_value_or("")); - operation = deleteOp; - } - if (operation) { - try { - operation->setID(attributes.getAttributeValue("id").get_value_or("")); - operation->setParentID(attributes.getAttributeValue("parentid").get_value_or("")); - operation->setPos(boost::lexical_cast<int>(attributes.getAttributeValue("pos").get_value_or("0"))); - } catch (boost::bad_lexical_cast&) { - } - } + void WhiteboardParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or(""))); + } else if (level_ == 1) { + std::string type = attributes.getAttributeValue("type").get_value_or(""); + if (type == "insert") { + WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>(); + operation = insertOp; + } else if (type == "update") { + WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(); + std::string move = attributes.getAttributeValue("newpos").get_value_or("0"); + updateOp->setNewPos(boost::lexical_cast<int>(attributes.getAttributeValue("newpos").get_value_or("0"))); + operation = updateOp; + } else if (type == "delete") { + WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>(); + deleteOp->setElementID(attributes.getAttributeValue("elementid").get_value_or("")); + operation = deleteOp; + } + if (operation) { + try { + operation->setID(attributes.getAttributeValue("id").get_value_or("")); + operation->setParentID(attributes.getAttributeValue("parentid").get_value_or("")); + operation->setPos(boost::lexical_cast<int>(attributes.getAttributeValue("pos").get_value_or("0"))); + } catch (boost::bad_lexical_cast&) { + } + } - } else if (level_ == 2) { - if (element == "line") { - int x1 = 0; - int y1 = 0; - int x2 = 0; - int y2 = 0; - try { - x1 = boost::lexical_cast<int>(attributes.getAttributeValue("x1").get_value_or("0")); - y1 = boost::lexical_cast<int>(attributes.getAttributeValue("y1").get_value_or("0")); - x2 = boost::lexical_cast<int>(attributes.getAttributeValue("x2").get_value_or("0")); - y2 = boost::lexical_cast<int>(attributes.getAttributeValue("y2").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } - WhiteboardLineElement::ref whiteboardElement = boost::make_shared<WhiteboardLineElement>(x1, y1, x2, y2); + } else if (level_ == 2) { + if (element == "line") { + int x1 = 0; + int y1 = 0; + int x2 = 0; + int y2 = 0; + try { + x1 = boost::lexical_cast<int>(attributes.getAttributeValue("x1").get_value_or("0")); + y1 = boost::lexical_cast<int>(attributes.getAttributeValue("y1").get_value_or("0")); + x2 = boost::lexical_cast<int>(attributes.getAttributeValue("x2").get_value_or("0")); + y2 = boost::lexical_cast<int>(attributes.getAttributeValue("y2").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } + WhiteboardLineElement::ref whiteboardElement = boost::make_shared<WhiteboardLineElement>(x1, y1, x2, y2); - WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); - color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - whiteboardElement->setColor(color); + WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); + color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + whiteboardElement->setColor(color); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "path") { - WhiteboardFreehandPathElement::ref whiteboardElement = boost::make_shared<WhiteboardFreehandPathElement>(); - std::string pathData = attributes.getAttributeValue("d").get_value_or(""); - std::vector<std::pair<int, int> > points; - if (pathData[0] == 'M') { - size_t pos = 1; - size_t npos; - int x, y; - if (pathData[pos] == ' ') { - pos++; - } - try { - npos = pathData.find(' ', pos); - x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - npos = pathData.find('L', pos); - y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - if (pathData[pos] == ' ') { - pos++; - } - points.push_back(std::pair<int, int>(x, y)); - while (pos < pathData.size()) { - npos = pathData.find(' ', pos); - x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - npos = pathData.find(' ', pos); - y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - points.push_back(std::pair<int, int>(x, y)); - } - } catch (boost::bad_lexical_cast&) { - } - } - whiteboardElement->setPoints(points); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "path") { + WhiteboardFreehandPathElement::ref whiteboardElement = boost::make_shared<WhiteboardFreehandPathElement>(); + std::string pathData = attributes.getAttributeValue("d").get_value_or(""); + std::vector<std::pair<int, int> > points; + if (pathData[0] == 'M') { + size_t pos = 1; + size_t npos; + int x, y; + if (pathData[pos] == ' ') { + pos++; + } + try { + npos = pathData.find(' ', pos); + x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + npos = pathData.find('L', pos); + y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + if (pathData[pos] == ' ') { + pos++; + } + points.push_back(std::pair<int, int>(x, y)); + while (pos < pathData.size()) { + npos = pathData.find(' ', pos); + x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + npos = pathData.find(' ', pos); + y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + points.push_back(std::pair<int, int>(x, y)); + } + } catch (boost::bad_lexical_cast&) { + } + } + whiteboardElement->setPoints(points); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); - color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - whiteboardElement->setColor(color); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "rect") { - int x = 0; - int y = 0; - int width = 0; - int height = 0; - try { - x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); - y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); - width = boost::lexical_cast<int>(attributes.getAttributeValue("width").get_value_or("0")); - height = boost::lexical_cast<int>(attributes.getAttributeValue("height").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } + WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); + color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + whiteboardElement->setColor(color); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "rect") { + int x = 0; + int y = 0; + int width = 0; + int height = 0; + try { + x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); + y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); + width = boost::lexical_cast<int>(attributes.getAttributeValue("width").get_value_or("0")); + height = boost::lexical_cast<int>(attributes.getAttributeValue("height").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } - WhiteboardRectElement::ref whiteboardElement = boost::make_shared<WhiteboardRectElement>(x, y, width, height); + WhiteboardRectElement::ref whiteboardElement = boost::make_shared<WhiteboardRectElement>(x, y, width, height); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); - WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); - penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); - whiteboardElement->setPenColor(penColor); - whiteboardElement->setBrushColor(brushColor); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "polygon") { - WhiteboardPolygonElement::ref whiteboardElement = boost::make_shared<WhiteboardPolygonElement>(); + WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "polygon") { + WhiteboardPolygonElement::ref whiteboardElement = boost::make_shared<WhiteboardPolygonElement>(); - std::string pointsData = attributes.getAttributeValue("points").get_value_or(""); - std::vector<std::pair<int, int> > points; - size_t pos = 0; - size_t npos; - int x, y; - try { - while (pos < pointsData.size()) { - npos = pointsData.find(',', pos); - x = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); - pos = npos+1; - npos = pointsData.find(' ', pos); - y = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); - pos = npos+1; - points.push_back(std::pair<int, int>(x, y)); - } - } catch (boost::bad_lexical_cast&) { - } + std::string pointsData = attributes.getAttributeValue("points").get_value_or(""); + std::vector<std::pair<int, int> > points; + size_t pos = 0; + size_t npos; + int x, y; + try { + while (pos < pointsData.size()) { + npos = pointsData.find(',', pos); + x = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); + pos = npos+1; + npos = pointsData.find(' ', pos); + y = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); + pos = npos+1; + points.push_back(std::pair<int, int>(x, y)); + } + } catch (boost::bad_lexical_cast&) { + } - whiteboardElement->setPoints(points); + whiteboardElement->setPoints(points); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); - WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); - penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); - whiteboardElement->setPenColor(penColor); - whiteboardElement->setBrushColor(brushColor); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "text") { - int x = 0; - int y = 0; - try { - x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); - y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } + WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "text") { + int x = 0; + int y = 0; + try { + x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); + y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } - WhiteboardTextElement::ref whiteboardElement = boost::make_shared<WhiteboardTextElement>(x, y); + WhiteboardTextElement::ref whiteboardElement = boost::make_shared<WhiteboardTextElement>(x, y); - actualIsText = true; - WhiteboardColor color(attributes.getAttributeValue("fill").get_value_or("#000000")); - color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - whiteboardElement->setColor(color); + actualIsText = true; + WhiteboardColor color(attributes.getAttributeValue("fill").get_value_or("#000000")); + color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + whiteboardElement->setColor(color); - int fontSize = 1; - try { - fontSize = boost::lexical_cast<int>(attributes.getAttributeValue("font-size").get_value_or("12")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setSize(fontSize); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "ellipse") { - int cx = 0; - int cy = 0; - int rx = 0; - int ry = 0; - try { - cx = boost::lexical_cast<int>(attributes.getAttributeValue("cx").get_value_or("0")); - cy = boost::lexical_cast<int>(attributes.getAttributeValue("cy").get_value_or("0")); - rx = boost::lexical_cast<int>(attributes.getAttributeValue("rx").get_value_or("0")); - ry = boost::lexical_cast<int>(attributes.getAttributeValue("ry").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } + int fontSize = 1; + try { + fontSize = boost::lexical_cast<int>(attributes.getAttributeValue("font-size").get_value_or("12")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setSize(fontSize); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "ellipse") { + int cx = 0; + int cy = 0; + int rx = 0; + int ry = 0; + try { + cx = boost::lexical_cast<int>(attributes.getAttributeValue("cx").get_value_or("0")); + cy = boost::lexical_cast<int>(attributes.getAttributeValue("cy").get_value_or("0")); + rx = boost::lexical_cast<int>(attributes.getAttributeValue("rx").get_value_or("0")); + ry = boost::lexical_cast<int>(attributes.getAttributeValue("ry").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } - WhiteboardEllipseElement::ref whiteboardElement = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry); + WhiteboardEllipseElement::ref whiteboardElement = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); - WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); - penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); - whiteboardElement->setPenColor(penColor); - whiteboardElement->setBrushColor(brushColor); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } - } - ++level_; - } + WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } + } + ++level_; + } - void WhiteboardParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setData(data_); - } else if (level_ == 1) { - WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation); - if (insertOp) { - insertOp->setElement(wbElement); - } + void WhiteboardParser::handleEndElement(const std::string& element, const std::string&) { + --level_; + if (level_ == 0) { + getPayloadInternal()->setData(data_); + } else if (level_ == 1) { + WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation); + if (insertOp) { + insertOp->setElement(wbElement); + } - WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation); - if (updateOp) { - updateOp->setElement(wbElement); - } - getPayloadInternal()->setOperation(operation); - } else if (level_ == 2) { - if (element == "text") { - actualIsText = false; - } - } - } + WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation); + if (updateOp) { + updateOp->setElement(wbElement); + } + getPayloadInternal()->setOperation(operation); + } else if (level_ == 2) { + if (element == "text") { + actualIsText = false; + } + } + } - void WhiteboardParser::handleCharacterData(const std::string& data) { - if (level_ == 3 && actualIsText) { - WhiteboardTextElement::ref element = boost::dynamic_pointer_cast<WhiteboardTextElement>(getPayloadInternal()->getElement()); - element->setText(data); - } - } + void WhiteboardParser::handleCharacterData(const std::string& data) { + if (level_ == 3 && actualIsText) { + WhiteboardTextElement::ref element = boost::dynamic_pointer_cast<WhiteboardTextElement>(getPayloadInternal()->getElement()); + element->setText(data); + } + } - WhiteboardPayload::Type WhiteboardParser::stringToType(const std::string& type) const { - if (type == "data") { - return WhiteboardPayload::Data; - } else if (type == "session-request") { - return WhiteboardPayload::SessionRequest; - } else if (type == "session-accept") { - return WhiteboardPayload::SessionAccept; - } else if (type == "session-terminate") { - return WhiteboardPayload::SessionTerminate; - } else { - return WhiteboardPayload::UnknownType; - } - } + WhiteboardPayload::Type WhiteboardParser::stringToType(const std::string& type) const { + if (type == "data") { + return WhiteboardPayload::Data; + } else if (type == "session-request") { + return WhiteboardPayload::SessionRequest; + } else if (type == "session-accept") { + return WhiteboardPayload::SessionAccept; + } else if (type == "session-terminate") { + return WhiteboardPayload::SessionTerminate; + } else { + return WhiteboardPayload::UnknownType; + } + } - int WhiteboardParser::opacityToAlpha(std::string opacity) const { - int value = 255; - if (opacity.find('.') != std::string::npos) { - opacity = opacity.substr(opacity.find('.')+1, 2); - try { - value = boost::lexical_cast<int>(opacity)*255/100; - } catch (boost::bad_lexical_cast&) { - } - } - return value; - } + int WhiteboardParser::opacityToAlpha(std::string opacity) const { + int value = 255; + if (opacity.find('.') != std::string::npos) { + opacity = opacity.substr(opacity.find('.')+1, 2); + try { + value = boost::lexical_cast<int>(opacity)*255/100; + } catch (boost::bad_lexical_cast&) { + } + } + return value; + } } diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.h b/Swiften/Parser/PayloadParsers/WhiteboardParser.h index 55a997d..2f22624 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.h +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h @@ -19,23 +19,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> { - public: - WhiteboardParser(); + class SWIFTEN_API WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> { + public: + WhiteboardParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - WhiteboardPayload::Type stringToType(const std::string& type) const; - int opacityToAlpha(std::string opacity) const; + private: + WhiteboardPayload::Type stringToType(const std::string& type) const; + int opacityToAlpha(std::string opacity) const; - private: - bool actualIsText; - int level_; - std::string data_; - WhiteboardElement::ref wbElement; - WhiteboardOperation::ref operation; - }; + private: + bool actualIsText; + int level_; + std::string data_; + WhiteboardElement::ref wbElement; + WhiteboardOperation::ref operation; + }; } diff --git a/Swiften/Parser/PlatformXMLParserFactory.cpp b/Swiften/Parser/PlatformXMLParserFactory.cpp index 924ef59..87f70d1 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.cpp +++ b/Swiften/Parser/PlatformXMLParserFactory.cpp @@ -22,9 +22,9 @@ PlatformXMLParserFactory::PlatformXMLParserFactory() { XMLParser* PlatformXMLParserFactory::createXMLParser(XMLParserClient* client) { #ifdef HAVE_LIBXML - return new LibXMLParser(client); + return new LibXMLParser(client); #else - return new ExpatParser(client); + return new ExpatParser(client); #endif } diff --git a/Swiften/Parser/PlatformXMLParserFactory.h b/Swiften/Parser/PlatformXMLParserFactory.h index 2422ded..82b8573 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.h +++ b/Swiften/Parser/PlatformXMLParserFactory.h @@ -10,10 +10,10 @@ #include <Swiften/Parser/XMLParserFactory.h> namespace Swift { - class SWIFTEN_API PlatformXMLParserFactory : public XMLParserFactory { - public: - PlatformXMLParserFactory(); + class SWIFTEN_API PlatformXMLParserFactory : public XMLParserFactory { + public: + PlatformXMLParserFactory(); - virtual XMLParser* createXMLParser(XMLParserClient*); - }; + virtual XMLParser* createXMLParser(XMLParserClient*); + }; } diff --git a/Swiften/Parser/PresenceParser.cpp b/Swiften/Parser/PresenceParser.cpp index 6d6424e..4a27a24 100644 --- a/Swiften/Parser/PresenceParser.cpp +++ b/Swiften/Parser/PresenceParser.cpp @@ -12,42 +12,42 @@ namespace Swift { -PresenceParser::PresenceParser(PayloadParserFactoryCollection* factories) : - GenericStanzaParser<Presence>(factories) { +PresenceParser::PresenceParser(PayloadParserFactoryCollection* factories) : + GenericStanzaParser<Presence>(factories) { } void PresenceParser::handleStanzaAttributes(const AttributeMap& attributes) { - boost::optional<std::string> type = attributes.getAttributeValue("type"); - if (type) { - if (*type == "unavailable") { - getStanzaGeneric()->setType(Presence::Unavailable); - } - else if (*type == "probe") { - getStanzaGeneric()->setType(Presence::Probe); - } - else if (*type == "subscribe") { - getStanzaGeneric()->setType(Presence::Subscribe); - } - else if (*type == "subscribed") { - getStanzaGeneric()->setType(Presence::Subscribed); - } - else if (*type == "unsubscribe") { - getStanzaGeneric()->setType(Presence::Unsubscribe); - } - else if (*type == "unsubscribed") { - getStanzaGeneric()->setType(Presence::Unsubscribed); - } - else if (*type == "error") { - getStanzaGeneric()->setType(Presence::Error); - } - else { - std::cerr << "Unknown Presence type: " << *type << std::endl; - getStanzaGeneric()->setType(Presence::Available); - } - } - else { - getStanzaGeneric()->setType(Presence::Available); - } + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "unavailable") { + getStanzaGeneric()->setType(Presence::Unavailable); + } + else if (*type == "probe") { + getStanzaGeneric()->setType(Presence::Probe); + } + else if (*type == "subscribe") { + getStanzaGeneric()->setType(Presence::Subscribe); + } + else if (*type == "subscribed") { + getStanzaGeneric()->setType(Presence::Subscribed); + } + else if (*type == "unsubscribe") { + getStanzaGeneric()->setType(Presence::Unsubscribe); + } + else if (*type == "unsubscribed") { + getStanzaGeneric()->setType(Presence::Unsubscribed); + } + else if (*type == "error") { + getStanzaGeneric()->setType(Presence::Error); + } + else { + std::cerr << "Unknown Presence type: " << *type << std::endl; + getStanzaGeneric()->setType(Presence::Available); + } + } + else { + getStanzaGeneric()->setType(Presence::Available); + } } } diff --git a/Swiften/Parser/PresenceParser.h b/Swiften/Parser/PresenceParser.h index 60d5490..76753f8 100644 --- a/Swiften/Parser/PresenceParser.h +++ b/Swiften/Parser/PresenceParser.h @@ -11,11 +11,11 @@ #include <Swiften/Parser/GenericStanzaParser.h> namespace Swift { - class SWIFTEN_API PresenceParser : public GenericStanzaParser<Presence> { - public: - PresenceParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API PresenceParser : public GenericStanzaParser<Presence> { + public: + PresenceParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStanzaAttributes(const AttributeMap&); - }; + private: + virtual void handleStanzaAttributes(const AttributeMap&); + }; } diff --git a/Swiften/Parser/SerializingParser.cpp b/Swiften/Parser/SerializingParser.cpp index e939c9f..b58ccd6 100644 --- a/Swiften/Parser/SerializingParser.cpp +++ b/Swiften/Parser/SerializingParser.cpp @@ -17,34 +17,34 @@ SerializingParser::SerializingParser() { } void SerializingParser::handleStartElement(const std::string& tag, const std::string& ns, const AttributeMap& attributes) { - boost::shared_ptr<XMLElement> element = boost::make_shared<XMLElement>(tag, ns); - // FIXME: Ignoring attribute namespace - foreach (const AttributeMap::Entry& e, attributes.getEntries()) { - element->setAttribute(e.getAttribute().getName(), e.getValue()); - } - - if (elementStack_.empty()) { - rootElement_ = element; - } - else { - (*(elementStack_.end() - 1))->addNode(element); - } - elementStack_.push_back(element); + boost::shared_ptr<XMLElement> element = boost::make_shared<XMLElement>(tag, ns); + // FIXME: Ignoring attribute namespace + foreach (const AttributeMap::Entry& e, attributes.getEntries()) { + element->setAttribute(e.getAttribute().getName(), e.getValue()); + } + + if (elementStack_.empty()) { + rootElement_ = element; + } + else { + (*(elementStack_.end() - 1))->addNode(element); + } + elementStack_.push_back(element); } void SerializingParser::handleEndElement(const std::string&, const std::string&) { - assert(!elementStack_.empty()); - elementStack_.pop_back(); + assert(!elementStack_.empty()); + elementStack_.pop_back(); } void SerializingParser::handleCharacterData(const std::string& data) { - if (!elementStack_.empty()) { - (*(elementStack_.end()-1))->addNode(boost::make_shared<XMLTextNode>(data)); - } + if (!elementStack_.empty()) { + (*(elementStack_.end()-1))->addNode(boost::make_shared<XMLTextNode>(data)); + } } std::string SerializingParser::getResult() const { - return (rootElement_ ? rootElement_->serialize() : ""); + return (rootElement_ ? rootElement_->serialize() : ""); } } diff --git a/Swiften/Parser/SerializingParser.h b/Swiften/Parser/SerializingParser.h index ba6cc80..b94d2b8 100644 --- a/Swiften/Parser/SerializingParser.h +++ b/Swiften/Parser/SerializingParser.h @@ -13,18 +13,18 @@ #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { - class SWIFTEN_API SerializingParser { - public: - SerializingParser(); + class SWIFTEN_API SerializingParser { + public: + SerializingParser(); - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - std::string getResult() const; + std::string getResult() const; - private: - std::vector< boost::shared_ptr<XMLElement> > elementStack_; - boost::shared_ptr<XMLElement> rootElement_; - }; + private: + std::vector< boost::shared_ptr<XMLElement> > elementStack_; + boost::shared_ptr<XMLElement> rootElement_; + }; } diff --git a/Swiften/Parser/StanzaAckParser.cpp b/Swiften/Parser/StanzaAckParser.cpp index b4fd1c1..de0287e 100644 --- a/Swiften/Parser/StanzaAckParser.cpp +++ b/Swiften/Parser/StanzaAckParser.cpp @@ -14,19 +14,19 @@ StanzaAckParser::StanzaAckParser() : GenericElementParser<StanzaAck>(), depth(0) } void StanzaAckParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (depth == 0) { - std::string handledStanzasString = attributes.getAttribute("h"); - try { - getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<int>(handledStanzasString)); - } - catch (const boost::bad_lexical_cast &) { - } - } - ++depth; + if (depth == 0) { + std::string handledStanzasString = attributes.getAttribute("h"); + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<int>(handledStanzasString)); + } + catch (const boost::bad_lexical_cast &) { + } + } + ++depth; } void StanzaAckParser::handleEndElement(const std::string&, const std::string&) { - --depth; + --depth; } } diff --git a/Swiften/Parser/StanzaAckParser.h b/Swiften/Parser/StanzaAckParser.h index c0e5d83..7e5a75f 100644 --- a/Swiften/Parser/StanzaAckParser.h +++ b/Swiften/Parser/StanzaAckParser.h @@ -11,14 +11,14 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StanzaAckParser : public GenericElementParser<StanzaAck> { - public: - StanzaAckParser(); + class SWIFTEN_API StanzaAckParser : public GenericElementParser<StanzaAck> { + public: + StanzaAckParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); - private: - int depth; - }; + private: + int depth; + }; } diff --git a/Swiften/Parser/StanzaAckRequestParser.h b/Swiften/Parser/StanzaAckRequestParser.h index 603eefc..9766e98 100644 --- a/Swiften/Parser/StanzaAckRequestParser.h +++ b/Swiften/Parser/StanzaAckRequestParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StanzaAckRequestParser : public GenericElementParser<StanzaAckRequest> { - public: - StanzaAckRequestParser() : GenericElementParser<StanzaAckRequest>() {} - }; + class SWIFTEN_API StanzaAckRequestParser : public GenericElementParser<StanzaAckRequest> { + public: + StanzaAckRequestParser() : GenericElementParser<StanzaAckRequest>() {} + }; } diff --git a/Swiften/Parser/StanzaParser.cpp b/Swiften/Parser/StanzaParser.cpp index 5b06af1..82ddb5c 100644 --- a/Swiften/Parser/StanzaParser.cpp +++ b/Swiften/Parser/StanzaParser.cpp @@ -18,69 +18,69 @@ namespace Swift { -StanzaParser::StanzaParser(PayloadParserFactoryCollection* factories) : - currentDepth_(0), factories_(factories) { +StanzaParser::StanzaParser(PayloadParserFactoryCollection* factories) : + currentDepth_(0), factories_(factories) { } StanzaParser::~StanzaParser() { } void StanzaParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (inStanza()) { - if (!inPayload()) { - assert(!currentPayloadParser_); - PayloadParserFactory* payloadParserFactory = factories_->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser_.reset(payloadParserFactory->createPayloadParser()); - } - else { - currentPayloadParser_.reset(new UnknownPayloadParser()); - } - } - assert(currentPayloadParser_); - currentPayloadParser_->handleStartElement(element, ns, attributes); - } - else { - boost::optional<std::string> from = attributes.getAttributeValue("from"); - if (from) { - getStanza()->setFrom(JID(*from)); - } - boost::optional<std::string> to = attributes.getAttributeValue("to"); - if (to) { - getStanza()->setTo(JID(*to)); - } - boost::optional<std::string> id = attributes.getAttributeValue("id"); - if (id) { - getStanza()->setID(*id); - } - handleStanzaAttributes(attributes); - } - ++currentDepth_; + if (inStanza()) { + if (!inPayload()) { + assert(!currentPayloadParser_); + PayloadParserFactory* payloadParserFactory = factories_->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser_.reset(payloadParserFactory->createPayloadParser()); + } + else { + currentPayloadParser_.reset(new UnknownPayloadParser()); + } + } + assert(currentPayloadParser_); + currentPayloadParser_->handleStartElement(element, ns, attributes); + } + else { + boost::optional<std::string> from = attributes.getAttributeValue("from"); + if (from) { + getStanza()->setFrom(JID(*from)); + } + boost::optional<std::string> to = attributes.getAttributeValue("to"); + if (to) { + getStanza()->setTo(JID(*to)); + } + boost::optional<std::string> id = attributes.getAttributeValue("id"); + if (id) { + getStanza()->setID(*id); + } + handleStanzaAttributes(attributes); + } + ++currentDepth_; } void StanzaParser::handleEndElement(const std::string& element, const std::string& ns) { - assert(inStanza()); - if (inPayload()) { - assert(currentPayloadParser_); - currentPayloadParser_->handleEndElement(element, ns); - --currentDepth_; - if (!inPayload()) { - boost::shared_ptr<Payload> payload(currentPayloadParser_->getPayload()); - if (payload) { - getStanza()->addPayload(payload); - } - currentPayloadParser_.reset(); - } - } - else { - --currentDepth_; - } + assert(inStanza()); + if (inPayload()) { + assert(currentPayloadParser_); + currentPayloadParser_->handleEndElement(element, ns); + --currentDepth_; + if (!inPayload()) { + boost::shared_ptr<Payload> payload(currentPayloadParser_->getPayload()); + if (payload) { + getStanza()->addPayload(payload); + } + currentPayloadParser_.reset(); + } + } + else { + --currentDepth_; + } } void StanzaParser::handleCharacterData(const std::string& data) { - if (currentPayloadParser_) { - currentPayloadParser_->handleCharacterData(data); - } + if (currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/StanzaParser.h b/Swiften/Parser/StanzaParser.h index 0d8016b..866df04 100644 --- a/Swiften/Parser/StanzaParser.h +++ b/Swiften/Parser/StanzaParser.h @@ -17,38 +17,38 @@ #include <Swiften/Parser/ElementParser.h> namespace Swift { - class PayloadParser; - class PayloadParserFactoryCollection; + class PayloadParser; + class PayloadParserFactoryCollection; - class SWIFTEN_API StanzaParser : public ElementParser, public boost::noncopyable { - public: - StanzaParser(PayloadParserFactoryCollection* factories); - ~StanzaParser(); + class SWIFTEN_API StanzaParser : public ElementParser, public boost::noncopyable { + public: + StanzaParser(PayloadParserFactoryCollection* factories); + ~StanzaParser(); - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; - virtual void handleStanzaAttributes(const AttributeMap&) {} + virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; + virtual void handleStanzaAttributes(const AttributeMap&) {} - virtual boost::shared_ptr<Stanza> getStanza() const { - return boost::dynamic_pointer_cast<Stanza>(getElement()); - } + virtual boost::shared_ptr<Stanza> getStanza() const { + return boost::dynamic_pointer_cast<Stanza>(getElement()); + } - private: - bool inPayload() const { - return currentDepth_ > 1; - } + private: + bool inPayload() const { + return currentDepth_ > 1; + } - bool inStanza() const { - return currentDepth_ > 0; - } + bool inStanza() const { + return currentDepth_ > 0; + } - private: - int currentDepth_; - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<PayloadParser> currentPayloadParser_; - }; + private: + int currentDepth_; + PayloadParserFactoryCollection* factories_; + boost::shared_ptr<PayloadParser> currentPayloadParser_; + }; } diff --git a/Swiften/Parser/StartTLSFailureParser.h b/Swiften/Parser/StartTLSFailureParser.h index 3ff4b69..2f13e71 100644 --- a/Swiften/Parser/StartTLSFailureParser.h +++ b/Swiften/Parser/StartTLSFailureParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StartTLSFailureParser : public GenericElementParser<StartTLSFailure> { - public: - StartTLSFailureParser() : GenericElementParser<StartTLSFailure>() {} - }; + class SWIFTEN_API StartTLSFailureParser : public GenericElementParser<StartTLSFailure> { + public: + StartTLSFailureParser() : GenericElementParser<StartTLSFailure>() {} + }; } diff --git a/Swiften/Parser/StartTLSParser.h b/Swiften/Parser/StartTLSParser.h index 997af95..f769d4d 100644 --- a/Swiften/Parser/StartTLSParser.h +++ b/Swiften/Parser/StartTLSParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StartTLSParser : public GenericElementParser<StartTLSRequest> { - public: - StartTLSParser() : GenericElementParser<StartTLSRequest>() {} - }; + class SWIFTEN_API StartTLSParser : public GenericElementParser<StartTLSRequest> { + public: + StartTLSParser() : GenericElementParser<StartTLSRequest>() {} + }; } diff --git a/Swiften/Parser/StreamErrorParser.cpp b/Swiften/Parser/StreamErrorParser.cpp index d42cf2a..64e0681 100644 --- a/Swiften/Parser/StreamErrorParser.cpp +++ b/Swiften/Parser/StreamErrorParser.cpp @@ -12,98 +12,98 @@ StreamErrorParser::StreamErrorParser() : level(TopLevel) { } void StreamErrorParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level; + ++level; } void StreamErrorParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (level == ElementLevel && ns == "urn:ietf:params:xml:ns:xmpp-streams") { - 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 == "not-well-formed") { - getElementGeneric()->setType(StreamError::NotWellFormed); - } - else if(element == "policy-violation") { - getElementGeneric()->setType(StreamError::PolicyViolation); - } - else if(element == "remote-connection-failed") { - getElementGeneric()->setType(StreamError::RemoteConnectionFailed); - } - else if(element == "reset") { - getElementGeneric()->setType(StreamError::Reset); - } - 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 { - getElementGeneric()->setType(StreamError::UndefinedCondition); - } - } + --level; + if (level == ElementLevel && ns == "urn:ietf:params:xml:ns:xmpp-streams") { + 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 == "not-well-formed") { + getElementGeneric()->setType(StreamError::NotWellFormed); + } + else if(element == "policy-violation") { + getElementGeneric()->setType(StreamError::PolicyViolation); + } + else if(element == "remote-connection-failed") { + getElementGeneric()->setType(StreamError::RemoteConnectionFailed); + } + else if(element == "reset") { + getElementGeneric()->setType(StreamError::Reset); + } + 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 { + getElementGeneric()->setType(StreamError::UndefinedCondition); + } + } } void StreamErrorParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } } diff --git a/Swiften/Parser/StreamErrorParser.h b/Swiften/Parser/StreamErrorParser.h index 74f9127..27efc86 100644 --- a/Swiften/Parser/StreamErrorParser.h +++ b/Swiften/Parser/StreamErrorParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamErrorParser : public GenericElementParser<StreamError> { - public: - StreamErrorParser(); + class SWIFTEN_API StreamErrorParser : public GenericElementParser<StreamError> { + public: + StreamErrorParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - ElementLevel = 1 - }; - int level; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0, + ElementLevel = 1 + }; + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/StreamFeaturesParser.cpp b/Swiften/Parser/StreamFeaturesParser.cpp index 913c50d..ce99a1e 100644 --- a/Swiften/Parser/StreamFeaturesParser.cpp +++ b/Swiften/Parser/StreamFeaturesParser.cpp @@ -12,71 +12,71 @@ StreamFeaturesParser::StreamFeaturesParser() : GenericElementParser<StreamFeatur } void StreamFeaturesParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap&) { - if (currentDepth_ == 1) { - if (element == "starttls" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { - getElementGeneric()->setHasStartTLS(); - } - else if (element == "session" && ns == "urn:ietf:params:xml:ns:xmpp-session") { - getElementGeneric()->setHasSession(); - } - else if (element == "bind" && ns == "urn:ietf:params:xml:ns:xmpp-bind") { - getElementGeneric()->setHasResourceBind(); - } - else if (element == "sm" && ns == "urn:xmpp:sm:2") { - getElementGeneric()->setHasStreamManagement(); - } - else if (element == "mechanisms" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - inMechanisms_ = true; - } - else if (element == "compression" && ns == "http://jabber.org/features/compress") { - inCompression_ = true; - } - else if (element == "ver" && ns == "urn:xmpp:features:rosterver") { - getElementGeneric()->setHasRosterVersioning(); - } - } - else if (currentDepth_ == 2) { - if (inCompression_ && element == "method") { - inCompressionMethod_ = true; - currentText_ = ""; - } - else if (inMechanisms_ && element == "mechanism") { - inMechanism_ = true; - currentText_ = ""; - } - else if (inMechanisms_ && element == "hostname" && ns == "urn:xmpp:domain-based-name:1") { - inAuthenticationHostname_ = true; - currentText_ = ""; - } + if (currentDepth_ == 1) { + if (element == "starttls" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { + getElementGeneric()->setHasStartTLS(); + } + else if (element == "session" && ns == "urn:ietf:params:xml:ns:xmpp-session") { + getElementGeneric()->setHasSession(); + } + else if (element == "bind" && ns == "urn:ietf:params:xml:ns:xmpp-bind") { + getElementGeneric()->setHasResourceBind(); + } + else if (element == "sm" && ns == "urn:xmpp:sm:2") { + getElementGeneric()->setHasStreamManagement(); + } + else if (element == "mechanisms" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + inMechanisms_ = true; + } + else if (element == "compression" && ns == "http://jabber.org/features/compress") { + inCompression_ = true; + } + else if (element == "ver" && ns == "urn:xmpp:features:rosterver") { + getElementGeneric()->setHasRosterVersioning(); + } + } + else if (currentDepth_ == 2) { + if (inCompression_ && element == "method") { + inCompressionMethod_ = true; + currentText_ = ""; + } + else if (inMechanisms_ && element == "mechanism") { + inMechanism_ = true; + currentText_ = ""; + } + else if (inMechanisms_ && element == "hostname" && ns == "urn:xmpp:domain-based-name:1") { + inAuthenticationHostname_ = true; + currentText_ = ""; + } - } - ++currentDepth_; + } + ++currentDepth_; } void StreamFeaturesParser::handleEndElement(const std::string&, const std::string&) { - --currentDepth_; - if (currentDepth_ == 1) { - inCompression_ = false; - inMechanisms_ = false; - } - else if (currentDepth_ == 2) { - if (inCompressionMethod_) { - getElementGeneric()->addCompressionMethod(currentText_); - inCompressionMethod_ = false; - } - else if (inMechanism_) { - getElementGeneric()->addAuthenticationMechanism(currentText_); - inMechanism_ = false; - } - else if (inAuthenticationHostname_) { - getElementGeneric()->setAuthenticationHostname(currentText_); - inAuthenticationHostname_ = false; - } - } + --currentDepth_; + if (currentDepth_ == 1) { + inCompression_ = false; + inMechanisms_ = false; + } + else if (currentDepth_ == 2) { + if (inCompressionMethod_) { + getElementGeneric()->addCompressionMethod(currentText_); + inCompressionMethod_ = false; + } + else if (inMechanism_) { + getElementGeneric()->addAuthenticationMechanism(currentText_); + inMechanism_ = false; + } + else if (inAuthenticationHostname_) { + getElementGeneric()->setAuthenticationHostname(currentText_); + inAuthenticationHostname_ = false; + } + } } void StreamFeaturesParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/StreamFeaturesParser.h b/Swiften/Parser/StreamFeaturesParser.h index 1a60c3b..5af8de8 100644 --- a/Swiften/Parser/StreamFeaturesParser.h +++ b/Swiften/Parser/StreamFeaturesParser.h @@ -13,22 +13,22 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamFeaturesParser : public GenericElementParser<StreamFeatures> { - public: - StreamFeaturesParser(); + class SWIFTEN_API StreamFeaturesParser : public GenericElementParser<StreamFeatures> { + public: + StreamFeaturesParser(); - private: - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + private: + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - private: - int currentDepth_; - std::string currentText_; - bool inMechanisms_; - bool inMechanism_; - bool inAuthenticationHostname_; - bool inCompression_; - bool inCompressionMethod_; - }; + private: + int currentDepth_; + std::string currentText_; + bool inMechanisms_; + bool inMechanism_; + bool inAuthenticationHostname_; + bool inCompression_; + bool inCompressionMethod_; + }; } diff --git a/Swiften/Parser/StreamManagementEnabledParser.cpp b/Swiften/Parser/StreamManagementEnabledParser.cpp index 5edcc2a..9e87d65 100644 --- a/Swiften/Parser/StreamManagementEnabledParser.cpp +++ b/Swiften/Parser/StreamManagementEnabledParser.cpp @@ -15,15 +15,15 @@ StreamManagementEnabledParser::~StreamManagementEnabledParser() { } void StreamManagementEnabledParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - if (attributes.getBoolAttribute("resume", false)) { - getElementGeneric()->setResumeSupported(); - } - getElementGeneric()->setResumeID(attributes.getAttribute("id")); - } - ++level; + if (level == TopLevel) { + if (attributes.getBoolAttribute("resume", false)) { + getElementGeneric()->setResumeSupported(); + } + getElementGeneric()->setResumeID(attributes.getAttribute("id")); + } + ++level; } void StreamManagementEnabledParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } diff --git a/Swiften/Parser/StreamManagementEnabledParser.h b/Swiften/Parser/StreamManagementEnabledParser.h index e854212..0f75071 100644 --- a/Swiften/Parser/StreamManagementEnabledParser.h +++ b/Swiften/Parser/StreamManagementEnabledParser.h @@ -11,18 +11,18 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { - public: - StreamManagementEnabledParser(); - ~StreamManagementEnabledParser(); + class SWIFTEN_API StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { + public: + StreamManagementEnabledParser(); + ~StreamManagementEnabledParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); - private: - enum Level { - TopLevel = 0 - }; - int level; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + }; } diff --git a/Swiften/Parser/StreamManagementFailedParser.h b/Swiften/Parser/StreamManagementFailedParser.h index b929bb0..c87beee 100644 --- a/Swiften/Parser/StreamManagementFailedParser.h +++ b/Swiften/Parser/StreamManagementFailedParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamManagementFailedParser : public GenericElementParser<StreamManagementFailed> { - public: - StreamManagementFailedParser() : GenericElementParser<StreamManagementFailed>() {} - }; + class SWIFTEN_API StreamManagementFailedParser : public GenericElementParser<StreamManagementFailed> { + public: + StreamManagementFailedParser() : GenericElementParser<StreamManagementFailed>() {} + }; } diff --git a/Swiften/Parser/StreamResumeParser.cpp b/Swiften/Parser/StreamResumeParser.cpp index 1a9e72f..a6ca444 100644 --- a/Swiften/Parser/StreamResumeParser.cpp +++ b/Swiften/Parser/StreamResumeParser.cpp @@ -17,20 +17,20 @@ StreamResumeParser::~StreamResumeParser() { } void StreamResumeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); - if (handledStanzasCount) { - try { - getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); - } - catch (const boost::bad_lexical_cast &) { - } - } - getElementGeneric()->setResumeID(attributes.getAttribute("previd")); - } - ++level; + if (level == TopLevel) { + boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); + if (handledStanzasCount) { + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); + } + catch (const boost::bad_lexical_cast &) { + } + } + getElementGeneric()->setResumeID(attributes.getAttribute("previd")); + } + ++level; } void StreamResumeParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } diff --git a/Swiften/Parser/StreamResumeParser.h b/Swiften/Parser/StreamResumeParser.h index 4d2bd4c..d3d2498 100644 --- a/Swiften/Parser/StreamResumeParser.h +++ b/Swiften/Parser/StreamResumeParser.h @@ -11,18 +11,18 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamResumeParser : public GenericElementParser<StreamResume> { - public: - StreamResumeParser(); - ~StreamResumeParser(); + class SWIFTEN_API StreamResumeParser : public GenericElementParser<StreamResume> { + public: + StreamResumeParser(); + ~StreamResumeParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); - private: - enum Level { - TopLevel = 0 - }; - int level; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + }; } diff --git a/Swiften/Parser/StreamResumedParser.cpp b/Swiften/Parser/StreamResumedParser.cpp index 9c7be50..f69bad1 100644 --- a/Swiften/Parser/StreamResumedParser.cpp +++ b/Swiften/Parser/StreamResumedParser.cpp @@ -17,20 +17,20 @@ StreamResumedParser::~StreamResumedParser() { } void StreamResumedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); - if (handledStanzasCount) { - try { - getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); - } - catch (const boost::bad_lexical_cast &) { - } - } - getElementGeneric()->setResumeID(attributes.getAttribute("previd")); - } - ++level; + if (level == TopLevel) { + boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); + if (handledStanzasCount) { + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); + } + catch (const boost::bad_lexical_cast &) { + } + } + getElementGeneric()->setResumeID(attributes.getAttribute("previd")); + } + ++level; } void StreamResumedParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } diff --git a/Swiften/Parser/StreamResumedParser.h b/Swiften/Parser/StreamResumedParser.h index da67d50..ca89597 100644 --- a/Swiften/Parser/StreamResumedParser.h +++ b/Swiften/Parser/StreamResumedParser.h @@ -11,18 +11,18 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamResumedParser : public GenericElementParser<StreamResumed> { - public: - StreamResumedParser(); - ~StreamResumedParser(); + class SWIFTEN_API StreamResumedParser : public GenericElementParser<StreamResumed> { + public: + StreamResumedParser(); + ~StreamResumedParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); - private: - enum Level { - TopLevel = 0 - }; - int level; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + }; } diff --git a/Swiften/Parser/TLSProceedParser.h b/Swiften/Parser/TLSProceedParser.h index 6f587a4..da6cfd1 100644 --- a/Swiften/Parser/TLSProceedParser.h +++ b/Swiften/Parser/TLSProceedParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API TLSProceedParser : public GenericElementParser<TLSProceed> { - public: - TLSProceedParser() : GenericElementParser<TLSProceed>() {} - }; + class SWIFTEN_API TLSProceedParser : public GenericElementParser<TLSProceed> { + public: + TLSProceedParser() : GenericElementParser<TLSProceed>() {} + }; } diff --git a/Swiften/Parser/Tree/NullParserElement.h b/Swiften/Parser/Tree/NullParserElement.h index dcfcad2..8dae25d 100644 --- a/Swiften/Parser/Tree/NullParserElement.h +++ b/Swiften/Parser/Tree/NullParserElement.h @@ -12,12 +12,12 @@ #include <Swiften/Parser/Tree/ParserElement.h> namespace Swift { - class SWIFTEN_API NullParserElement : public ParserElement { - public: - NullParserElement() : ParserElement("", "", AttributeMap()) {} + class SWIFTEN_API NullParserElement : public ParserElement { + public: + NullParserElement() : ParserElement("", "", AttributeMap()) {} - virtual operator bool() { return false; } + virtual operator bool() { return false; } - static boost::shared_ptr<NullParserElement> element; - }; + static boost::shared_ptr<NullParserElement> element; + }; } diff --git a/Swiften/Parser/Tree/ParserElement.cpp b/Swiften/Parser/Tree/ParserElement.cpp index 441647c..6bbd93e 100644 --- a/Swiften/Parser/Tree/ParserElement.cpp +++ b/Swiften/Parser/Tree/ParserElement.cpp @@ -25,26 +25,26 @@ ParserElement::~ParserElement() { } ParserElement::ref ParserElement::addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes) { - ParserElement::ref child = boost::make_shared<ParserElement>(name, xmlns, attributes); - children_.push_back(child); - return child; + ParserElement::ref child = boost::make_shared<ParserElement>(name, xmlns, attributes); + children_.push_back(child); + return child; } void ParserElement::appendCharacterData(const std::string& data) { - text_ += data; + text_ += data; } std::vector<ParserElement::ref> ParserElement::getChildren(const std::string& name, const std::string& xmlns) const { - std::vector<ParserElement::ref> result; - std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), - lambda::bind(&ParserElement::getName, *lambda::_1) != name || lambda::bind(&ParserElement::getNamespace, *lambda::_1) != xmlns); - return result; + std::vector<ParserElement::ref> result; + std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), + lambda::bind(&ParserElement::getName, *lambda::_1) != name || lambda::bind(&ParserElement::getNamespace, *lambda::_1) != xmlns); + return result; } ParserElement::ref ParserElement::getChild(const std::string& name, const std::string& xmlns) const { - std::vector<ParserElement::ref> results = getChildren(name, xmlns); - ParserElement::ref result = results.empty() ? NullParserElement::element : results[0]; - return result; + std::vector<ParserElement::ref> results = getChildren(name, xmlns); + ParserElement::ref result = results.empty() ? NullParserElement::element : results[0]; + return result; } } diff --git a/Swiften/Parser/Tree/ParserElement.h b/Swiften/Parser/Tree/ParserElement.h index f0c895f..dc9f31c 100644 --- a/Swiften/Parser/Tree/ParserElement.h +++ b/Swiften/Parser/Tree/ParserElement.h @@ -18,34 +18,34 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class SWIFTEN_API ParserElement { - public: - typedef boost::shared_ptr<ParserElement> ref; - - ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); - virtual ~ParserElement(); - - const std::string& getText() const { return text_; } - const std::string& getName() const { return name_; } - const std::string& getNamespace() const { return xmlns_; } - const AttributeMap& getAttributes() const { return attributes_; } - - ParserElement::ref addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); - void appendCharacterData(const std::string& data); - - std::vector<ParserElement::ref> getChildren(const std::string& name, const std::string& xmlns) const; - const std::vector<ParserElement::ref>& getAllChildren() const {return children_;} - ParserElement::ref getChild(const std::string& name, const std::string& xmlns) const; - - virtual operator bool() { - return true; - } - - private: - std::vector<ParserElement::ref> children_; - std::string name_; - std::string xmlns_; - AttributeMap attributes_; - std::string text_; - }; + class SWIFTEN_API ParserElement { + public: + typedef boost::shared_ptr<ParserElement> ref; + + ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); + virtual ~ParserElement(); + + const std::string& getText() const { return text_; } + const std::string& getName() const { return name_; } + const std::string& getNamespace() const { return xmlns_; } + const AttributeMap& getAttributes() const { return attributes_; } + + ParserElement::ref addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); + void appendCharacterData(const std::string& data); + + std::vector<ParserElement::ref> getChildren(const std::string& name, const std::string& xmlns) const; + const std::vector<ParserElement::ref>& getAllChildren() const {return children_;} + ParserElement::ref getChild(const std::string& name, const std::string& xmlns) const; + + virtual operator bool() { + return true; + } + + private: + std::vector<ParserElement::ref> children_; + std::string name_; + std::string xmlns_; + AttributeMap attributes_; + std::string text_; + }; } diff --git a/Swiften/Parser/Tree/TreeReparser.cpp b/Swiften/Parser/Tree/TreeReparser.cpp index bc2b6b9..269b2ea 100644 --- a/Swiften/Parser/Tree/TreeReparser.cpp +++ b/Swiften/Parser/Tree/TreeReparser.cpp @@ -22,28 +22,28 @@ namespace Swift { typedef std::pair<ParserElement::ref, bool> ElementState; boost::shared_ptr<Payload> TreeReparser::parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection) { - PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); - std::deque<ElementState > stack; - stack.push_back(ElementState(root, true)); - while (!stack.empty()) { - ElementState current = stack.back(); - stack.pop_back(); - if (current.second) { - stack.push_back(ElementState(current.first, false)); - parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); - foreach(ParserElement::ref child, current.first->getAllChildren()) { - stack.push_back(ElementState(child, true)); - } - } else { - parser->handleCharacterData(current.first->getText()); - parser->handleEndElement(current.first->getName(), current.first->getNamespace()); - } - - } - - boost::shared_ptr<Payload> payload = parser->getPayload(); - delete parser; - return payload; + PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); + std::deque<ElementState > stack; + stack.push_back(ElementState(root, true)); + while (!stack.empty()) { + ElementState current = stack.back(); + stack.pop_back(); + if (current.second) { + stack.push_back(ElementState(current.first, false)); + parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); + foreach(ParserElement::ref child, current.first->getAllChildren()) { + stack.push_back(ElementState(child, true)); + } + } else { + parser->handleCharacterData(current.first->getText()); + parser->handleEndElement(current.first->getName(), current.first->getNamespace()); + } + + } + + boost::shared_ptr<Payload> payload = parser->getPayload(); + delete parser; + return payload; } } diff --git a/Swiften/Parser/Tree/TreeReparser.h b/Swiften/Parser/Tree/TreeReparser.h index 80a326b..fb96c1b 100644 --- a/Swiften/Parser/Tree/TreeReparser.h +++ b/Swiften/Parser/Tree/TreeReparser.h @@ -11,10 +11,10 @@ #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class SWIFTEN_API TreeReparser { - public: - static boost::shared_ptr<Payload> parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection); + class PayloadParserFactoryCollection; + class SWIFTEN_API TreeReparser { + public: + static boost::shared_ptr<Payload> parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection); - }; + }; } diff --git a/Swiften/Parser/UnitTest/AttributeMapTest.cpp b/Swiften/Parser/UnitTest/AttributeMapTest.cpp index 55fa964..4529eac 100644 --- a/Swiften/Parser/UnitTest/AttributeMapTest.cpp +++ b/Swiften/Parser/UnitTest/AttributeMapTest.cpp @@ -13,73 +13,73 @@ using namespace Swift; class AttributeMapTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(AttributeMapTest); - CPPUNIT_TEST(testGetAttribute_Namespaced); - CPPUNIT_TEST(testGetBoolAttribute_True); - CPPUNIT_TEST(testGetBoolAttribute_1); - CPPUNIT_TEST(testGetBoolAttribute_False); - CPPUNIT_TEST(testGetBoolAttribute_0); - CPPUNIT_TEST(testGetBoolAttribute_Invalid); - CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultTrue); - CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultFalse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(AttributeMapTest); + CPPUNIT_TEST(testGetAttribute_Namespaced); + CPPUNIT_TEST(testGetBoolAttribute_True); + CPPUNIT_TEST(testGetBoolAttribute_1); + CPPUNIT_TEST(testGetBoolAttribute_False); + CPPUNIT_TEST(testGetBoolAttribute_0); + CPPUNIT_TEST(testGetBoolAttribute_Invalid); + CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultTrue); + CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultFalse); + CPPUNIT_TEST_SUITE_END(); - public: - void testGetAttribute_Namespaced() { - AttributeMap testling; - testling.addAttribute("lang", "", "nl"); - testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); - testling.addAttribute("lang", "", "fr"); + public: + void testGetAttribute_Namespaced() { + AttributeMap testling; + testling.addAttribute("lang", "", "nl"); + testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); + testling.addAttribute("lang", "", "fr"); - CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); - } + CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); + } - void testGetBoolAttribute_True() { - AttributeMap testling; - testling.addAttribute("foo", "", "true"); + void testGetBoolAttribute_True() { + AttributeMap testling; + testling.addAttribute("foo", "", "true"); - CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); - } + CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); + } - void testGetBoolAttribute_1() { - AttributeMap testling; - testling.addAttribute("foo", "", "1"); + void testGetBoolAttribute_1() { + AttributeMap testling; + testling.addAttribute("foo", "", "1"); - CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); - } + CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); + } - void testGetBoolAttribute_False() { - AttributeMap testling; - testling.addAttribute("foo", "", "false"); + void testGetBoolAttribute_False() { + AttributeMap testling; + testling.addAttribute("foo", "", "false"); - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); - } + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); + } - void testGetBoolAttribute_0() { - AttributeMap testling; - testling.addAttribute("foo", "", "0"); + void testGetBoolAttribute_0() { + AttributeMap testling; + testling.addAttribute("foo", "", "0"); - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); - } + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); + } - void testGetBoolAttribute_Invalid() { - AttributeMap testling; - testling.addAttribute("foo", "", "bla"); + void testGetBoolAttribute_Invalid() { + AttributeMap testling; + testling.addAttribute("foo", "", "bla"); - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); - } + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); + } - void testGetBoolAttribute_UnknownWithDefaultTrue() { - AttributeMap testling; + void testGetBoolAttribute_UnknownWithDefaultTrue() { + AttributeMap testling; - CPPUNIT_ASSERT(testling.getBoolAttribute("foo", true)); - } + CPPUNIT_ASSERT(testling.getBoolAttribute("foo", true)); + } - void testGetBoolAttribute_UnknownWithDefaultFalse() { - AttributeMap testling; + void testGetBoolAttribute_UnknownWithDefaultFalse() { + AttributeMap testling; - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", false)); - } + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", false)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(AttributeMapTest); diff --git a/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp b/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp index a72f5aa..f7ed80f 100644 --- a/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp +++ b/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp @@ -13,92 +13,92 @@ using namespace Swift; class BOSHBodyExtractorTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BOSHBodyExtractorTest); - CPPUNIT_TEST(testGetBody); - CPPUNIT_TEST(testGetBody_EmptyContent); - CPPUNIT_TEST(testGetBody_EmptyContent2); - CPPUNIT_TEST(testGetBody_EmptyElementEmptyContent); - CPPUNIT_TEST(testGetBody_InvalidStartTag); - CPPUNIT_TEST(testGetBody_InvalidStartTag2); - CPPUNIT_TEST(testGetBody_IncompleteStartTag); - CPPUNIT_TEST(testGetBody_InvalidEndTag); - CPPUNIT_TEST(testGetBody_InvalidEndTag2); - CPPUNIT_TEST_SUITE_END(); - - public: - void testGetBody() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body a1='a\"1' a2=\"a'2\" boo='bar' >" - "foo <message> <body> bar" - "</body > ")); - - CPPUNIT_ASSERT(testling.getBody()); - CPPUNIT_ASSERT_EQUAL(std::string("a\"1"), testling.getBody()->attributes.getAttribute("a1")); - CPPUNIT_ASSERT_EQUAL(std::string("foo <message> <body> bar"), testling.getBody()->content); - } - - void testGetBody_EmptyContent() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body foo='bar'/>")); - - CPPUNIT_ASSERT(testling.getBody()); - CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); - CPPUNIT_ASSERT(testling.getBody()->content.empty()); - } - - void testGetBody_EmptyContent2() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body foo='bar'></body>")); - - CPPUNIT_ASSERT(testling.getBody()); - CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); - CPPUNIT_ASSERT(testling.getBody()->content.empty()); - } - - void testGetBody_EmptyElementEmptyContent() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body/>")); - - CPPUNIT_ASSERT(testling.getBody()); - } - - void testGetBody_InvalidStartTag() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<bodi></body>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_InvalidStartTag2() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<bodyy></body>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_IncompleteStartTag() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_InvalidEndTag() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body></bodi>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_InvalidEndTag2() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body><b/body>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - private: - PlatformXMLParserFactory parserFactory; + CPPUNIT_TEST_SUITE(BOSHBodyExtractorTest); + CPPUNIT_TEST(testGetBody); + CPPUNIT_TEST(testGetBody_EmptyContent); + CPPUNIT_TEST(testGetBody_EmptyContent2); + CPPUNIT_TEST(testGetBody_EmptyElementEmptyContent); + CPPUNIT_TEST(testGetBody_InvalidStartTag); + CPPUNIT_TEST(testGetBody_InvalidStartTag2); + CPPUNIT_TEST(testGetBody_IncompleteStartTag); + CPPUNIT_TEST(testGetBody_InvalidEndTag); + CPPUNIT_TEST(testGetBody_InvalidEndTag2); + CPPUNIT_TEST_SUITE_END(); + + public: + void testGetBody() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body a1='a\"1' a2=\"a'2\" boo='bar' >" + "foo <message> <body> bar" + "</body > ")); + + CPPUNIT_ASSERT(testling.getBody()); + CPPUNIT_ASSERT_EQUAL(std::string("a\"1"), testling.getBody()->attributes.getAttribute("a1")); + CPPUNIT_ASSERT_EQUAL(std::string("foo <message> <body> bar"), testling.getBody()->content); + } + + void testGetBody_EmptyContent() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body foo='bar'/>")); + + CPPUNIT_ASSERT(testling.getBody()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); + CPPUNIT_ASSERT(testling.getBody()->content.empty()); + } + + void testGetBody_EmptyContent2() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body foo='bar'></body>")); + + CPPUNIT_ASSERT(testling.getBody()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); + CPPUNIT_ASSERT(testling.getBody()->content.empty()); + } + + void testGetBody_EmptyElementEmptyContent() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body/>")); + + CPPUNIT_ASSERT(testling.getBody()); + } + + void testGetBody_InvalidStartTag() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<bodi></body>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_InvalidStartTag2() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<bodyy></body>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_IncompleteStartTag() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_InvalidEndTag() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body></bodi>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_InvalidEndTag2() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body><b/body>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + private: + PlatformXMLParserFactory parserFactory; }; CPPUNIT_TEST_SUITE_REGISTRATION(BOSHBodyExtractorTest); diff --git a/Swiften/Parser/UnitTest/ElementParserTester.h b/Swiften/Parser/UnitTest/ElementParserTester.h index 4ab44bd..299fb50 100644 --- a/Swiften/Parser/UnitTest/ElementParserTester.h +++ b/Swiften/Parser/UnitTest/ElementParserTester.h @@ -9,5 +9,5 @@ #include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { - typedef ParserTester<ElementParser> ElementParserTester; + typedef ParserTester<ElementParser> ElementParserTester; } diff --git a/Swiften/Parser/UnitTest/EnumParserTest.cpp b/Swiften/Parser/UnitTest/EnumParserTest.cpp index fcbf0e9..82b3fa1 100644 --- a/Swiften/Parser/UnitTest/EnumParserTest.cpp +++ b/Swiften/Parser/UnitTest/EnumParserTest.cpp @@ -12,25 +12,25 @@ using namespace Swift; class EnumParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(EnumParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_NoValue); - CPPUNIT_TEST_SUITE_END(); - - public: - enum MyEnum { - MyValue1, - MyValue2, - MyValue3 - }; - - void testParse() { - CPPUNIT_ASSERT(MyValue2 == EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-2")); - } - - void testParse_NoValue() { - CPPUNIT_ASSERT(!EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-4")); - } + CPPUNIT_TEST_SUITE(EnumParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_NoValue); + CPPUNIT_TEST_SUITE_END(); + + public: + enum MyEnum { + MyValue1, + MyValue2, + MyValue3 + }; + + void testParse() { + CPPUNIT_ASSERT(MyValue2 == EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-2")); + } + + void testParse_NoValue() { + CPPUNIT_ASSERT(!EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-4")); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(EnumParserTest); diff --git a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp index 5413e46..cd94ed8 100644 --- a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp +++ b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp @@ -22,44 +22,44 @@ template class __declspec(dllimport) Swift::GenericPayloadParser<RawXMLPayload>; #endif class GenericPayloadTreeParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(GenericPayloadTreeParserTest); - CPPUNIT_TEST(testTree); - CPPUNIT_TEST_SUITE_END(); - - public: - void testTree() { - MyParser testling; - - std::string data = "<topLevel xmlns='urn:test:top'><firstLevelInheritedEmpty/><firstLevelInherited><secondLevelMultiChildren num='1'/><secondLevelMultiChildren num='2'/></firstLevelInherited><firstLevelNS xmlns='urn:test:first'/></topLevel>"; - - PayloadParserTester tester(&testling); - tester.parse(data); - - ParserElement::ref tree = testling.tree; - - CPPUNIT_ASSERT_EQUAL(std::string("topLevel"), tree->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("urn:test:top"), tree->getNamespace()); - CPPUNIT_ASSERT(tree->getChild("firstLevelInheritedEmpty", "urn:test:top")); - CPPUNIT_ASSERT(!*tree->getChild("firstLevelInheritedEmpty", "")); - CPPUNIT_ASSERT(tree->getChild("firstLevelInherited", "urn:test:top")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top").size()); - CPPUNIT_ASSERT_EQUAL(std::string("1"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[0]->getAttributes().getAttribute("num")); - CPPUNIT_ASSERT_EQUAL(std::string("2"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[1]->getAttributes().getAttribute("num")); - CPPUNIT_ASSERT(tree->getChild("firstLevelNS", "urn:test:first")); - } - - private: - - - class MyParser : public GenericPayloadTreeParser<RawXMLPayload> - { - public: - virtual ~MyParser() {} - virtual void handleTree(ParserElement::ref root) { - tree = root; - } - ParserElement::ref tree; - }; + CPPUNIT_TEST_SUITE(GenericPayloadTreeParserTest); + CPPUNIT_TEST(testTree); + CPPUNIT_TEST_SUITE_END(); + + public: + void testTree() { + MyParser testling; + + std::string data = "<topLevel xmlns='urn:test:top'><firstLevelInheritedEmpty/><firstLevelInherited><secondLevelMultiChildren num='1'/><secondLevelMultiChildren num='2'/></firstLevelInherited><firstLevelNS xmlns='urn:test:first'/></topLevel>"; + + PayloadParserTester tester(&testling); + tester.parse(data); + + ParserElement::ref tree = testling.tree; + + CPPUNIT_ASSERT_EQUAL(std::string("topLevel"), tree->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("urn:test:top"), tree->getNamespace()); + CPPUNIT_ASSERT(tree->getChild("firstLevelInheritedEmpty", "urn:test:top")); + CPPUNIT_ASSERT(!*tree->getChild("firstLevelInheritedEmpty", "")); + CPPUNIT_ASSERT(tree->getChild("firstLevelInherited", "urn:test:top")); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top").size()); + CPPUNIT_ASSERT_EQUAL(std::string("1"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[0]->getAttributes().getAttribute("num")); + CPPUNIT_ASSERT_EQUAL(std::string("2"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[1]->getAttributes().getAttribute("num")); + CPPUNIT_ASSERT(tree->getChild("firstLevelNS", "urn:test:first")); + } + + private: + + + class MyParser : public GenericPayloadTreeParser<RawXMLPayload> + { + public: + virtual ~MyParser() {} + virtual void handleTree(ParserElement::ref root) { + tree = root; + } + ParserElement::ref tree; + }; }; diff --git a/Swiften/Parser/UnitTest/IQParserTest.cpp b/Swiften/Parser/UnitTest/IQParserTest.cpp index 95e2d51..5c07757 100644 --- a/Swiften/Parser/UnitTest/IQParserTest.cpp +++ b/Swiften/Parser/UnitTest/IQParserTest.cpp @@ -14,60 +14,60 @@ using namespace Swift; class IQParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IQParserTest); - CPPUNIT_TEST(testParse_Set); - CPPUNIT_TEST(testParse_Get); - CPPUNIT_TEST(testParse_Result); - CPPUNIT_TEST(testParse_Error); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(IQParserTest); + CPPUNIT_TEST(testParse_Set); + CPPUNIT_TEST(testParse_Get); + CPPUNIT_TEST(testParse_Result); + CPPUNIT_TEST(testParse_Error); + CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - } + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } - void tearDown() { - delete factoryCollection_; - } + void tearDown() { + delete factoryCollection_; + } - void testParse_Set() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Set() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"set\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"set\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Set, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Set, testling.getStanzaGeneric()->getType()); + } - void testParse_Get() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Get() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"get\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"get\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Get, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Get, testling.getStanzaGeneric()->getType()); + } - void testParse_Result() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Result() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"result\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"result\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Result, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Result, testling.getStanzaGeneric()->getType()); + } - void testParse_Error() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Error() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"error\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"error\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Error, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Error, testling.getStanzaGeneric()->getType()); + } - private: - PayloadParserFactoryCollection* factoryCollection_; + private: + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(IQParserTest); diff --git a/Swiften/Parser/UnitTest/MessageParserTest.cpp b/Swiften/Parser/UnitTest/MessageParserTest.cpp index 19dafc3..dc55711 100644 --- a/Swiften/Parser/UnitTest/MessageParserTest.cpp +++ b/Swiften/Parser/UnitTest/MessageParserTest.cpp @@ -14,70 +14,70 @@ using namespace Swift; class MessageParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MessageParserTest); - CPPUNIT_TEST(testParse_Normal); - CPPUNIT_TEST(testParse_Chat); - CPPUNIT_TEST(testParse_Error); - CPPUNIT_TEST(testParse_Groupchat); - CPPUNIT_TEST(testParse_Headline); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(MessageParserTest); + CPPUNIT_TEST(testParse_Normal); + CPPUNIT_TEST(testParse_Chat); + CPPUNIT_TEST(testParse_Error); + CPPUNIT_TEST(testParse_Groupchat); + CPPUNIT_TEST(testParse_Headline); + CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - } + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } - void tearDown() { - delete factoryCollection_; - } + void tearDown() { + delete factoryCollection_; + } - void testParse_Chat() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Chat() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"chat\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"chat\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Chat, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Chat, testling.getStanzaGeneric()->getType()); + } - void testParse_Groupchat() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Groupchat() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"groupchat\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"groupchat\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Groupchat, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Groupchat, testling.getStanzaGeneric()->getType()); + } - void testParse_Error() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Error() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"error\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"error\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Error, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Error, testling.getStanzaGeneric()->getType()); + } - void testParse_Headline() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Headline() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"headline\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"headline\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Headline, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Headline, testling.getStanzaGeneric()->getType()); + } - void testParse_Normal() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Normal() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message/>")); + CPPUNIT_ASSERT(parser.parse("<message/>")); - CPPUNIT_ASSERT_EQUAL(Message::Normal, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Normal, testling.getStanzaGeneric()->getType()); + } - private: - PayloadParserFactoryCollection* factoryCollection_; + private: + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(MessageParserTest); diff --git a/Swiften/Parser/UnitTest/ParserTester.h b/Swiften/Parser/UnitTest/ParserTester.h index b843c29..a98eb51 100644 --- a/Swiften/Parser/UnitTest/ParserTester.h +++ b/Swiften/Parser/UnitTest/ParserTester.h @@ -11,37 +11,37 @@ #include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class XMLParser; - - template<typename ParserType> - class ParserTester : public XMLParserClient { - public: - ParserTester(ParserType* parser) : parser_(parser) { - xmlParser_ = PlatformXMLParserFactory().createXMLParser(this); - } - - ~ParserTester() { - delete xmlParser_; - } - - bool parse(const std::string& data) { - return xmlParser_->parse(data); - } - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - parser_->handleStartElement(element, ns, attributes); - } - - virtual void handleEndElement(const std::string& element, const std::string& ns) { - parser_->handleEndElement(element, ns); - } - - virtual void handleCharacterData(const std::string& data) { - parser_->handleCharacterData(data); - } - - private: - XMLParser* xmlParser_; - ParserType* parser_; - }; + class XMLParser; + + template<typename ParserType> + class ParserTester : public XMLParserClient { + public: + ParserTester(ParserType* parser) : parser_(parser) { + xmlParser_ = PlatformXMLParserFactory().createXMLParser(this); + } + + ~ParserTester() { + delete xmlParser_; + } + + bool parse(const std::string& data) { + return xmlParser_->parse(data); + } + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + parser_->handleStartElement(element, ns, attributes); + } + + virtual void handleEndElement(const std::string& element, const std::string& ns) { + parser_->handleEndElement(element, ns); + } + + virtual void handleCharacterData(const std::string& data) { + parser_->handleCharacterData(data); + } + + private: + XMLParser* xmlParser_; + ParserType* parser_; + }; } diff --git a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp index cb01d6f..b2279f8 100644 --- a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp +++ b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp @@ -14,90 +14,90 @@ using namespace Swift; class PayloadParserFactoryCollectionTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PayloadParserFactoryCollectionTest); - CPPUNIT_TEST(testGetPayloadParserFactory); - CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchingFactory); - CPPUNIT_TEST(testGetPayloadParserFactory_TwoMatchingFactories); - CPPUNIT_TEST(testGetPayloadParserFactory_MatchWithDefaultFactory); - CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchWithDefaultFactory); - CPPUNIT_TEST_SUITE_END(); - - public: - PayloadParserFactoryCollectionTest() {} - - void setUp() { - } - - void tearDown() { - } - - void testGetPayloadParserFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2("bar"); - testling.addFactory(&factory2); - DummyFactory factory3("baz"); - testling.addFactory(&factory3); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("bar", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory2); - } - - void testGetPayloadParserFactory_NoMatchingFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory("foo"); - - CPPUNIT_ASSERT(!testling.getPayloadParserFactory("bar", "", AttributeMap())); - } - - void testGetPayloadParserFactory_TwoMatchingFactories() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2("foo"); - testling.addFactory(&factory2); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory2); - } - - void testGetPayloadParserFactory_MatchWithDefaultFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2; - testling.setDefaultFactory(&factory2); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory1); - } - - void testGetPayloadParserFactory_NoMatchWithDefaultFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2; - testling.setDefaultFactory(&factory2); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("baz", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory2); - } - - - private: - struct DummyFactory : public PayloadParserFactory { - DummyFactory(const std::string& element = "") : element(element) {} - virtual bool canParse(const std::string& e, const std::string&, const AttributeMap&) const { - return element.empty() ? true : element == e; - } - virtual PayloadParser* createPayloadParser() { return NULL; } - std::string element; - }; + CPPUNIT_TEST_SUITE(PayloadParserFactoryCollectionTest); + CPPUNIT_TEST(testGetPayloadParserFactory); + CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchingFactory); + CPPUNIT_TEST(testGetPayloadParserFactory_TwoMatchingFactories); + CPPUNIT_TEST(testGetPayloadParserFactory_MatchWithDefaultFactory); + CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchWithDefaultFactory); + CPPUNIT_TEST_SUITE_END(); + + public: + PayloadParserFactoryCollectionTest() {} + + void setUp() { + } + + void tearDown() { + } + + void testGetPayloadParserFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2("bar"); + testling.addFactory(&factory2); + DummyFactory factory3("baz"); + testling.addFactory(&factory3); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("bar", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory2); + } + + void testGetPayloadParserFactory_NoMatchingFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory("foo"); + + CPPUNIT_ASSERT(!testling.getPayloadParserFactory("bar", "", AttributeMap())); + } + + void testGetPayloadParserFactory_TwoMatchingFactories() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2("foo"); + testling.addFactory(&factory2); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory2); + } + + void testGetPayloadParserFactory_MatchWithDefaultFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2; + testling.setDefaultFactory(&factory2); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory1); + } + + void testGetPayloadParserFactory_NoMatchWithDefaultFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2; + testling.setDefaultFactory(&factory2); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("baz", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory2); + } + + + private: + struct DummyFactory : public PayloadParserFactory { + DummyFactory(const std::string& element = "") : element(element) {} + virtual bool canParse(const std::string& e, const std::string&, const AttributeMap&) const { + return element.empty() ? true : element == e; + } + virtual PayloadParser* createPayloadParser() { return NULL; } + std::string element; + }; }; CPPUNIT_TEST_SUITE_REGISTRATION(PayloadParserFactoryCollectionTest); diff --git a/Swiften/Parser/UnitTest/PresenceParserTest.cpp b/Swiften/Parser/UnitTest/PresenceParserTest.cpp index 6dfbefd..2b2c242 100644 --- a/Swiften/Parser/UnitTest/PresenceParserTest.cpp +++ b/Swiften/Parser/UnitTest/PresenceParserTest.cpp @@ -14,100 +14,100 @@ using namespace Swift; class PresenceParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PresenceParserTest); - CPPUNIT_TEST(testParse_Available); - CPPUNIT_TEST(testParse_Unavailable); - CPPUNIT_TEST(testParse_Subscribe); - CPPUNIT_TEST(testParse_Subscribed); - CPPUNIT_TEST(testParse_Unsubscribe); - CPPUNIT_TEST(testParse_Unsubscribed); - CPPUNIT_TEST(testParse_Probe); - CPPUNIT_TEST(testParse_Error); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PresenceParserTest); + CPPUNIT_TEST(testParse_Available); + CPPUNIT_TEST(testParse_Unavailable); + CPPUNIT_TEST(testParse_Subscribe); + CPPUNIT_TEST(testParse_Subscribed); + CPPUNIT_TEST(testParse_Unsubscribe); + CPPUNIT_TEST(testParse_Unsubscribed); + CPPUNIT_TEST(testParse_Probe); + CPPUNIT_TEST(testParse_Error); + CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - } + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } - void tearDown() { - delete factoryCollection_; - } + void tearDown() { + delete factoryCollection_; + } - void testParse_Available() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Available() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence/>")); + CPPUNIT_ASSERT(parser.parse("<presence/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Available, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Available, testling.getStanzaGeneric()->getType()); + } - void testParse_Unavailable() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Unavailable() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"unavailable\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"unavailable\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, testling.getStanzaGeneric()->getType()); + } - void testParse_Probe() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Probe() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"probe\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"probe\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Probe, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Probe, testling.getStanzaGeneric()->getType()); + } - void testParse_Subscribe() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Subscribe() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribe\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribe\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Subscribe, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Subscribe, testling.getStanzaGeneric()->getType()); + } - void testParse_Subscribed() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Subscribed() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribed\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribed\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Subscribed, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Subscribed, testling.getStanzaGeneric()->getType()); + } - void testParse_Unsubscribe() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Unsubscribe() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribe\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribe\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribe, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribe, testling.getStanzaGeneric()->getType()); + } - void testParse_Unsubscribed() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Unsubscribed() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribed\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribed\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribed, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribed, testling.getStanzaGeneric()->getType()); + } - void testParse_Error() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Error() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"error\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"error\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Error, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Error, testling.getStanzaGeneric()->getType()); + } - private: - PayloadParserFactoryCollection* factoryCollection_; + private: + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(PresenceParserTest); diff --git a/Swiften/Parser/UnitTest/SerializingParserTest.cpp b/Swiften/Parser/UnitTest/SerializingParserTest.cpp index 67567ee..1b4eb57 100644 --- a/Swiften/Parser/UnitTest/SerializingParserTest.cpp +++ b/Swiften/Parser/UnitTest/SerializingParserTest.cpp @@ -14,51 +14,51 @@ using namespace Swift; class SerializingParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SerializingParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Empty); - CPPUNIT_TEST(testParse_ToplevelCharacterData); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(SerializingParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Empty); + CPPUNIT_TEST(testParse_ToplevelCharacterData); + CPPUNIT_TEST_SUITE_END(); - public: - SerializingParserTest() {} + public: + SerializingParserTest() {} - void testParse() { - SerializingParser testling; - ParserTester<SerializingParser> parser(&testling); + void testParse() { + SerializingParser testling; + ParserTester<SerializingParser> parser(&testling); - CPPUNIT_ASSERT(parser.parse( - "<message type=\"chat\" to=\"me@foo.com\">" - "<body>Hello<&World</body>" - "<html xmlns=\"http://www.w3.org/1999/xhtml\">" - "foo<b>bar</b>baz" - "</html>" - "</message>")); + CPPUNIT_ASSERT(parser.parse( + "<message type=\"chat\" to=\"me@foo.com\">" + "<body>Hello<&World</body>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "foo<b>bar</b>baz" + "</html>" + "</message>")); - CPPUNIT_ASSERT_EQUAL(std::string( - "<message to=\"me@foo.com\" type=\"chat\">" - "<body>Hello<&World</body>" - "<html xmlns=\"http://www.w3.org/1999/xhtml\">foo<b xmlns=\"http://www.w3.org/1999/xhtml\">bar</b>baz</html>" - "</message>"), testling.getResult()); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<message to=\"me@foo.com\" type=\"chat\">" + "<body>Hello<&World</body>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">foo<b xmlns=\"http://www.w3.org/1999/xhtml\">bar</b>baz</html>" + "</message>"), testling.getResult()); + } - void testParse_Empty() { - SerializingParser testling; + void testParse_Empty() { + SerializingParser testling; - CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResult()); - } + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResult()); + } - void testParse_ToplevelCharacterData() { - SerializingParser testling; - - AttributeMap attributes; - testling.handleCharacterData("foo"); - testling.handleStartElement("message", "", attributes); - testling.handleEndElement("message", ""); - testling.handleCharacterData("bar"); + void testParse_ToplevelCharacterData() { + SerializingParser testling; - CPPUNIT_ASSERT_EQUAL(std::string("<message/>"), testling.getResult()); - } + AttributeMap attributes; + testling.handleCharacterData("foo"); + testling.handleStartElement("message", "", attributes); + testling.handleEndElement("message", ""); + testling.handleCharacterData("bar"); + + CPPUNIT_ASSERT_EQUAL(std::string("<message/>"), testling.getResult()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SerializingParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp index 9a9d00c..4591640 100644 --- a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp @@ -14,40 +14,40 @@ using namespace Swift; class StanzaAckParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StanzaAckParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Invalid); - CPPUNIT_TEST(testParse_Empty); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StanzaAckParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Invalid); + CPPUNIT_TEST(testParse_Empty); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - StanzaAckParser testling; - ElementParserTester parser(&testling); + public: + void testParse() { + StanzaAckParser testling; + ElementParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<a h=\"12\" xmlns=\"urn:xmpp:sm:2\"/>")); + CPPUNIT_ASSERT(parser.parse("<a h=\"12\" xmlns=\"urn:xmpp:sm:2\"/>")); - CPPUNIT_ASSERT(testling.getElementGeneric()->isValid()); - CPPUNIT_ASSERT_EQUAL(12U, testling.getElementGeneric()->getHandledStanzasCount()); - } + CPPUNIT_ASSERT(testling.getElementGeneric()->isValid()); + CPPUNIT_ASSERT_EQUAL(12U, testling.getElementGeneric()->getHandledStanzasCount()); + } - void testParse_Invalid() { - StanzaAckParser testling; - ElementParserTester parser(&testling); + void testParse_Invalid() { + StanzaAckParser testling; + ElementParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<a h=\"invalid\" xmlns=\"urn:xmpp:sm:2\"/>")); + CPPUNIT_ASSERT(parser.parse("<a h=\"invalid\" xmlns=\"urn:xmpp:sm:2\"/>")); - CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); - } + CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); + } - void testParse_Empty() { - StanzaAckParser testling; - ElementParserTester parser(&testling); + void testParse_Empty() { + StanzaAckParser testling; + ElementParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<a xmlns=\"urn:xmpp:sm:2\"/>")); + CPPUNIT_ASSERT(parser.parse("<a xmlns=\"urn:xmpp:sm:2\"/>")); - CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); - } + CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StanzaAckParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaParserTest.cpp b/Swiften/Parser/UnitTest/StanzaParserTest.cpp index d9f39e7..c081b1b 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaParserTest.cpp @@ -17,196 +17,196 @@ using namespace Swift; class StanzaParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StanzaParserTest); - CPPUNIT_TEST(testHandleEndElement_OnePayload); - CPPUNIT_TEST(testHandleEndElement_MultiplePayloads); - CPPUNIT_TEST(testHandleEndElement_StrayCharacterData); - CPPUNIT_TEST(testHandleEndElement_UnknownPayload); - CPPUNIT_TEST(testHandleParse_BasicAttributes); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - factoryCollection_->addFactory(&factory1_); - factoryCollection_->addFactory(&factory2_); - } - - void tearDown() { - delete factoryCollection_; - } - - void testHandleEndElement_OnePayload() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - attributes.addAttribute("foo", "", "fum"); - attributes.addAttribute("bar", "", "baz"); - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleStartElement("child", "", attributes); - testling.handleEndElement("child", ""); - testling.handleEndElement("mypayload1", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()->hasChild); - } - - void testHandleEndElement_MultiplePayloads() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleEndElement("mypayload1", ""); - testling.handleStartElement("mypayload2", "", attributes); - testling.handleEndElement("mypayload2", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); - } - - void testHandleEndElement_StrayCharacterData() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleEndElement("mypayload1", ""); - testling.handleCharacterData("bla"); - testling.handleStartElement("mypayload2", "", attributes); - testling.handleEndElement("mypayload2", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); - } - - void testHandleEndElement_UnknownPayload() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleEndElement("mypayload1", ""); - testling.handleStartElement("unknown-payload", "", attributes); - testling.handleStartElement("unknown-payload-child", "", attributes); - testling.handleEndElement("unknown-payload-child", ""); - testling.handleEndElement("unknown-payload", ""); - testling.handleStartElement("mypayload2", "", attributes); - testling.handleEndElement("mypayload2", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); - } - - void testHandleParse_BasicAttributes() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - attributes.addAttribute("to", "", "foo@example.com/blo"); - attributes.addAttribute("from", "", "bar@example.com/baz"); - attributes.addAttribute("id", "", "id-123"); - testling.handleStartElement("mystanza", "", attributes); - testling.handleEndElement("mypayload1", ""); - - CPPUNIT_ASSERT_EQUAL(JID("foo@example.com/blo"), testling.getStanza()->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("bar@example.com/baz"), testling.getStanza()->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("id-123"), testling.getStanza()->getID()); - } - - private: - class MyPayload1 : public Payload - { - public: - MyPayload1() : hasChild(false) {} - - bool hasChild; - }; - - class MyPayload1Parser : public GenericPayloadParser<MyPayload1> - { - public: - MyPayload1Parser() {} - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (element != "mypayload1") { - getPayloadInternal()->hasChild = true; - } - } - - virtual void handleEndElement(const std::string&, const std::string&) {} - virtual void handleCharacterData(const std::string&) {} - }; - - class MyPayload1ParserFactory : public PayloadParserFactory - { - public: - MyPayload1ParserFactory() {} - - PayloadParser* createPayloadParser() { return new MyPayload1Parser(); } - - bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { - return element == "mypayload1"; - } - }; - - class MyPayload2 : public Payload - { - public: - MyPayload2() {} - }; - - class MyPayload2Parser : public GenericPayloadParser<MyPayload2> - { - public: - MyPayload2Parser() {} - - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} - virtual void handleEndElement(const std::string&, const std::string&) {} - virtual void handleCharacterData(const std::string&) {} - }; - - - class MyPayload2ParserFactory : public PayloadParserFactory - { - public: - MyPayload2ParserFactory() {} - - PayloadParser* createPayloadParser() { return new MyPayload2Parser(); } - bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { - return element == "mypayload2"; - } - }; - - class MyStanza : public Stanza - { - public: - MyStanza() {} - }; - - class MyStanzaParser : public StanzaParser - { - public: - MyStanzaParser(PayloadParserFactoryCollection* collection) : StanzaParser(collection) - { - stanza_ = boost::make_shared<MyStanza>(); - } - - virtual boost::shared_ptr<ToplevelElement> getElement() const { - return stanza_; - } - - private: - boost::shared_ptr<MyStanza> stanza_; - }; - - MyPayload1ParserFactory factory1_; - MyPayload2ParserFactory factory2_; - PayloadParserFactoryCollection* factoryCollection_; + CPPUNIT_TEST_SUITE(StanzaParserTest); + CPPUNIT_TEST(testHandleEndElement_OnePayload); + CPPUNIT_TEST(testHandleEndElement_MultiplePayloads); + CPPUNIT_TEST(testHandleEndElement_StrayCharacterData); + CPPUNIT_TEST(testHandleEndElement_UnknownPayload); + CPPUNIT_TEST(testHandleParse_BasicAttributes); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + factoryCollection_->addFactory(&factory1_); + factoryCollection_->addFactory(&factory2_); + } + + void tearDown() { + delete factoryCollection_; + } + + void testHandleEndElement_OnePayload() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + attributes.addAttribute("foo", "", "fum"); + attributes.addAttribute("bar", "", "baz"); + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleStartElement("child", "", attributes); + testling.handleEndElement("child", ""); + testling.handleEndElement("mypayload1", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()->hasChild); + } + + void testHandleEndElement_MultiplePayloads() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); + } + + void testHandleEndElement_StrayCharacterData() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleCharacterData("bla"); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); + } + + void testHandleEndElement_UnknownPayload() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleStartElement("unknown-payload", "", attributes); + testling.handleStartElement("unknown-payload-child", "", attributes); + testling.handleEndElement("unknown-payload-child", ""); + testling.handleEndElement("unknown-payload", ""); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); + } + + void testHandleParse_BasicAttributes() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + attributes.addAttribute("to", "", "foo@example.com/blo"); + attributes.addAttribute("from", "", "bar@example.com/baz"); + attributes.addAttribute("id", "", "id-123"); + testling.handleStartElement("mystanza", "", attributes); + testling.handleEndElement("mypayload1", ""); + + CPPUNIT_ASSERT_EQUAL(JID("foo@example.com/blo"), testling.getStanza()->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("bar@example.com/baz"), testling.getStanza()->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("id-123"), testling.getStanza()->getID()); + } + + private: + class MyPayload1 : public Payload + { + public: + MyPayload1() : hasChild(false) {} + + bool hasChild; + }; + + class MyPayload1Parser : public GenericPayloadParser<MyPayload1> + { + public: + MyPayload1Parser() {} + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { + if (element != "mypayload1") { + getPayloadInternal()->hasChild = true; + } + } + + virtual void handleEndElement(const std::string&, const std::string&) {} + virtual void handleCharacterData(const std::string&) {} + }; + + class MyPayload1ParserFactory : public PayloadParserFactory + { + public: + MyPayload1ParserFactory() {} + + PayloadParser* createPayloadParser() { return new MyPayload1Parser(); } + + bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { + return element == "mypayload1"; + } + }; + + class MyPayload2 : public Payload + { + public: + MyPayload2() {} + }; + + class MyPayload2Parser : public GenericPayloadParser<MyPayload2> + { + public: + MyPayload2Parser() {} + + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} + virtual void handleEndElement(const std::string&, const std::string&) {} + virtual void handleCharacterData(const std::string&) {} + }; + + + class MyPayload2ParserFactory : public PayloadParserFactory + { + public: + MyPayload2ParserFactory() {} + + PayloadParser* createPayloadParser() { return new MyPayload2Parser(); } + bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { + return element == "mypayload2"; + } + }; + + class MyStanza : public Stanza + { + public: + MyStanza() {} + }; + + class MyStanzaParser : public StanzaParser + { + public: + MyStanzaParser(PayloadParserFactoryCollection* collection) : StanzaParser(collection) + { + stanza_ = boost::make_shared<MyStanza>(); + } + + virtual boost::shared_ptr<ToplevelElement> getElement() const { + return stanza_; + } + + private: + boost::shared_ptr<MyStanza> stanza_; + }; + + MyPayload1ParserFactory factory1_; + MyPayload2ParserFactory factory2_; + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(StanzaParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaParserTester.h b/Swiften/Parser/UnitTest/StanzaParserTester.h index 7d8b22b..36f41c9 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTester.h +++ b/Swiften/Parser/UnitTest/StanzaParserTester.h @@ -10,5 +10,5 @@ #include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { - typedef ParserTester<StanzaParser> StanzaParserTester; + typedef ParserTester<StanzaParser> StanzaParserTester; } diff --git a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp index f6c9336..031f2f3 100644 --- a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp +++ b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp @@ -13,96 +13,96 @@ using namespace Swift; class StreamFeaturesParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StreamFeaturesParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Empty); - CPPUNIT_TEST(testParse_AuthenticationHostname); - CPPUNIT_TEST(testParse_AuthenticationHostnameEmpty); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - StreamFeaturesParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" - "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" - "<compression xmlns=\"http://jabber.org/features/compress\">" - "<method>zlib</method>" - "<method>lzw</method>" - "</compression>" - "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" - "<mechanism>DIGEST-MD5</mechanism>" - "<mechanism>PLAIN</mechanism>" - "</mechanisms>" - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" - "<sm xmlns='urn:xmpp:sm:2'/>" - "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" - "<ver xmlns=\"urn:xmpp:features:rosterver\"/>" - "</stream:features>")); - - StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); - CPPUNIT_ASSERT(element->hasStartTLS()); - CPPUNIT_ASSERT(element->hasSession()); - CPPUNIT_ASSERT(element->hasResourceBind()); - CPPUNIT_ASSERT(element->hasCompressionMethod("zlib")); - CPPUNIT_ASSERT(element->hasCompressionMethod("lzw")); - CPPUNIT_ASSERT(element->hasAuthenticationMechanisms()); - CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); - CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); - CPPUNIT_ASSERT(!element->getAuthenticationHostname()); - CPPUNIT_ASSERT(element->hasStreamManagement()); - CPPUNIT_ASSERT(element->hasRosterVersioning()); - } - - void testParse_Empty() { - StreamFeaturesParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse("<stream:features xmlns:stream='http://etherx.jabber.org/streams'/>")); - - StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); - CPPUNIT_ASSERT(!element->hasStartTLS()); - CPPUNIT_ASSERT(!element->hasSession()); - CPPUNIT_ASSERT(!element->hasResourceBind()); - CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms()); - } - - void testParse_AuthenticationHostname() { - StreamFeaturesParser testling; - ElementParserTester parser(&testling); - std::string hostname("auth42.us.example.com"); - - CPPUNIT_ASSERT(parser.parse( - "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" - "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" - "<mechanism>GSSAPI</mechanism>" - "<hostname xmlns=\"urn:xmpp:domain-based-name:1\">auth42.us.example.com</hostname>" - "</mechanisms>" - "</stream:features>")); - - StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); - CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); - CPPUNIT_ASSERT_EQUAL(*element->getAuthenticationHostname(), hostname); - } - - void testParse_AuthenticationHostnameEmpty() { - StreamFeaturesParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" - "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" - "<mechanism>GSSAPI</mechanism>" - "<hostname xmlns=\"urn:xmpp:domain-based-name:1\"></hostname>" - "</mechanisms>" - "</stream:features>")); - - StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); - CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); - CPPUNIT_ASSERT(element->getAuthenticationHostname()->empty()); - } + CPPUNIT_TEST_SUITE(StreamFeaturesParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Empty); + CPPUNIT_TEST(testParse_AuthenticationHostname); + CPPUNIT_TEST(testParse_AuthenticationHostnameEmpty); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" + "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" + "<compression xmlns=\"http://jabber.org/features/compress\">" + "<method>zlib</method>" + "<method>lzw</method>" + "</compression>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + "<mechanism>DIGEST-MD5</mechanism>" + "<mechanism>PLAIN</mechanism>" + "</mechanisms>" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" + "<sm xmlns='urn:xmpp:sm:2'/>" + "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" + "<ver xmlns=\"urn:xmpp:features:rosterver\"/>" + "</stream:features>")); + + StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(element->hasStartTLS()); + CPPUNIT_ASSERT(element->hasSession()); + CPPUNIT_ASSERT(element->hasResourceBind()); + CPPUNIT_ASSERT(element->hasCompressionMethod("zlib")); + CPPUNIT_ASSERT(element->hasCompressionMethod("lzw")); + CPPUNIT_ASSERT(element->hasAuthenticationMechanisms()); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); + CPPUNIT_ASSERT(!element->getAuthenticationHostname()); + CPPUNIT_ASSERT(element->hasStreamManagement()); + CPPUNIT_ASSERT(element->hasRosterVersioning()); + } + + void testParse_Empty() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse("<stream:features xmlns:stream='http://etherx.jabber.org/streams'/>")); + + StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(!element->hasStartTLS()); + CPPUNIT_ASSERT(!element->hasSession()); + CPPUNIT_ASSERT(!element->hasResourceBind()); + CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms()); + } + + void testParse_AuthenticationHostname() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + std::string hostname("auth42.us.example.com"); + + CPPUNIT_ASSERT(parser.parse( + "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + "<mechanism>GSSAPI</mechanism>" + "<hostname xmlns=\"urn:xmpp:domain-based-name:1\">auth42.us.example.com</hostname>" + "</mechanisms>" + "</stream:features>")); + + StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); + CPPUNIT_ASSERT_EQUAL(*element->getAuthenticationHostname(), hostname); + } + + void testParse_AuthenticationHostnameEmpty() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + "<mechanism>GSSAPI</mechanism>" + "<hostname xmlns=\"urn:xmpp:domain-based-name:1\"></hostname>" + "</mechanisms>" + "</stream:features>")); + + StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); + CPPUNIT_ASSERT(element->getAuthenticationHostname()->empty()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamFeaturesParserTest); diff --git a/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp index a39dc4b..7b4a9cc 100644 --- a/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp +++ b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp @@ -13,22 +13,22 @@ using namespace Swift; class StreamManagementEnabledParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StreamManagementEnabledParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - StreamManagementEnabledParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>")); - - boost::shared_ptr<StreamManagementEnabled> element = boost::dynamic_pointer_cast<StreamManagementEnabled>(testling.getElement()); - CPPUNIT_ASSERT(element->getResumeSupported()); - CPPUNIT_ASSERT_EQUAL(std::string("some-long-sm-id"), element->getResumeID()); - } + CPPUNIT_TEST_SUITE(StreamManagementEnabledParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + StreamManagementEnabledParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>")); + + boost::shared_ptr<StreamManagementEnabled> element = boost::dynamic_pointer_cast<StreamManagementEnabled>(testling.getElement()); + CPPUNIT_ASSERT(element->getResumeSupported()); + CPPUNIT_ASSERT_EQUAL(std::string("some-long-sm-id"), element->getResumeID()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamManagementEnabledParserTest); diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp index 6b7aa93..b593aa7 100644 --- a/Swiften/Parser/UnitTest/XMLParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp @@ -21,337 +21,337 @@ using namespace Swift; template <typename ParserType> class XMLParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(XMLParserTest); - CPPUNIT_TEST(testParse_NestedElements); - CPPUNIT_TEST(testParse_ElementInNamespacedElement); - CPPUNIT_TEST(testParse_CharacterData); - CPPUNIT_TEST(testParse_XMLEntity); - CPPUNIT_TEST(testParse_NamespacePrefix); - CPPUNIT_TEST(testParse_UnhandledXML); - CPPUNIT_TEST(testParse_InvalidXML); - CPPUNIT_TEST(testParse_InErrorState); - CPPUNIT_TEST(testParse_Incremental); - CPPUNIT_TEST(testParse_WhitespaceInAttribute); - CPPUNIT_TEST(testParse_AttributeWithoutNamespace); - CPPUNIT_TEST(testParse_AttributeWithNamespace); - CPPUNIT_TEST(testParse_BillionLaughs); - CPPUNIT_TEST(testParse_InternalEntity); - //CPPUNIT_TEST(testParse_UndefinedPrefix); - //CPPUNIT_TEST(testParse_UndefinedAttributePrefix); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(XMLParserTest); + CPPUNIT_TEST(testParse_NestedElements); + CPPUNIT_TEST(testParse_ElementInNamespacedElement); + CPPUNIT_TEST(testParse_CharacterData); + CPPUNIT_TEST(testParse_XMLEntity); + CPPUNIT_TEST(testParse_NamespacePrefix); + CPPUNIT_TEST(testParse_UnhandledXML); + CPPUNIT_TEST(testParse_InvalidXML); + CPPUNIT_TEST(testParse_InErrorState); + CPPUNIT_TEST(testParse_Incremental); + CPPUNIT_TEST(testParse_WhitespaceInAttribute); + CPPUNIT_TEST(testParse_AttributeWithoutNamespace); + CPPUNIT_TEST(testParse_AttributeWithNamespace); + CPPUNIT_TEST(testParse_BillionLaughs); + CPPUNIT_TEST(testParse_InternalEntity); + //CPPUNIT_TEST(testParse_UndefinedPrefix); + //CPPUNIT_TEST(testParse_UndefinedAttributePrefix); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse_NestedElements() { - ParserType testling(&client_); + public: + void testParse_NestedElements() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse( - "<iq type=\"get\">" - "<query xmlns='jabber:iq:version'/>" - "</iq>")); + CPPUNIT_ASSERT(testling.parse( + "<iq type=\"get\">" + "<query xmlns='jabber:iq:version'/>" + "</iq>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes.getAttribute("type")); - CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes.getAttribute("type")); + CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[0].ns); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[2].ns); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[2].ns); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[3].ns); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[3].ns); + } - void testParse_ElementInNamespacedElement() { - ParserType testling(&client_); + void testParse_ElementInNamespacedElement() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='jabber:iq:version'>" - "<name>Swift</name>" - "</query>")); + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='jabber:iq:version'>" + "<name>Swift</name>" + "</query>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("Swift"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[3].ns); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[3].ns); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[4].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[4].ns); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[4].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[4].ns); + } - void testParse_CharacterData() { - ParserType testling(&client_); + void testParse_CharacterData() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<html>bla<i>bli</i>blo</html>")); + CPPUNIT_ASSERT(testling.parse("<html>bla<i>bli</i>blo</html>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("bli"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("bli"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); - CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[4].data); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); + CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[4].data); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[5].type); - CPPUNIT_ASSERT_EQUAL(std::string("blo"), client_.events[5].data); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[5].type); + CPPUNIT_ASSERT_EQUAL(std::string("blo"), client_.events[5].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[6].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[6].data); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[6].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[6].data); + } - void testParse_XMLEntity() { - ParserType testling(&client_); + void testParse_XMLEntity() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<html><></html>")); + CPPUNIT_ASSERT(testling.parse("<html><></html>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("<"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("<"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string(">"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string(">"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[3].data); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[3].data); + } - void testParse_NamespacePrefix() { - ParserType testling(&client_); + void testParse_NamespacePrefix() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<p:x xmlns:p='bla'><p:y/></p:x>")); + CPPUNIT_ASSERT(testling.parse("<p:x xmlns:p='bla'><p:y/></p:x>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].ns); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].ns); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].ns); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].ns); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[3].ns); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[3].ns); + } - void testParse_UnhandledXML() { - ParserType testling(&client_); + void testParse_UnhandledXML() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>")); + CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); + } - void testParse_InvalidXML() { - ParserType testling(&client_); + void testParse_InvalidXML() { + ParserType testling(&client_); - CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); - } + CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); + } - void testParse_InErrorState() { - ParserType testling(&client_); + void testParse_InErrorState() { + ParserType testling(&client_); - CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); - CPPUNIT_ASSERT(!testling.parse("<iq/>")); - } + CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); + CPPUNIT_ASSERT(!testling.parse("<iq/>")); + } - void testParse_Incremental() { - ParserType testling(&client_); + void testParse_Incremental() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<iq")); - CPPUNIT_ASSERT(testling.parse("></iq>")); + CPPUNIT_ASSERT(testling.parse("<iq")); + CPPUNIT_ASSERT(testling.parse("></iq>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); + } - void testParse_WhitespaceInAttribute() { - ParserType testling(&client_); + void testParse_WhitespaceInAttribute() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='http://www.xmpp.org/extensions/xep-0084.html#ns-data '>")); - CPPUNIT_ASSERT(testling.parse( - "<presence/>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[2].data); - } + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://www.xmpp.org/extensions/xep-0084.html#ns-data '>")); + CPPUNIT_ASSERT(testling.parse( + "<presence/>")); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[2].data); + } - void testParse_AttributeWithoutNamespace() { - ParserType testling(&client_); + void testParse_AttributeWithoutNamespace() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='http://swift.im' attr='3'/>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); - } - - void testParse_AttributeWithNamespace() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' f:attr='3'/>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); - CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); - } - - void testParse_BillionLaughs() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(!testling.parse( - "<?xml version=\"1.0\"?>" - "<!DOCTYPE lolz [" - " <!ENTITY lol \"lol\">" - " <!ENTITY lol2 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">" - " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">" - " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">" - " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">" - " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">" - " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">" - " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">" - " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" - "]>" - "<lolz>&lol9;</lolz>" - )); - } - - void testParse_InternalEntity() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE foo [<!ENTITY bar \"Bar\">]><foo>&bar;</foo>")); - } - - void testParse_UndefinedPrefix() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<foo:bar><bla/></foo:bar>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].ns); - - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[1].ns); - - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[2].ns); - - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[3].ns); - } - - void testParse_UndefinedAttributePrefix() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<foo bar:baz='bla'/>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); - } - - private: - class Client : public XMLParserClient { - public: - enum Type { StartElement, EndElement, CharacterData }; - struct Event { - Event( - Type type, - const std::string& data, - const std::string& ns, - const AttributeMap& attributes) - : type(type), data(data), ns(ns), attributes(attributes) {} - Event(Type type, const std::string& data, const std::string& ns = std::string()) - : type(type), data(data), ns(ns) {} - - Type type; - std::string data; - std::string ns; - AttributeMap attributes; - }; - - Client() {} - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - events.push_back(Event(StartElement, element, ns, attributes)); - } - - virtual void handleEndElement(const std::string& element, const std::string& ns) { - events.push_back(Event(EndElement, element, ns)); - } - - virtual void handleCharacterData(const std::string& data) { - events.push_back(Event(CharacterData, data)); - } - - std::vector<Event> events; - } client_; + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' attr='3'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + } + + void testParse_AttributeWithNamespace() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' f:attr='3'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + } + + void testParse_BillionLaughs() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse( + "<?xml version=\"1.0\"?>" + "<!DOCTYPE lolz [" + " <!ENTITY lol \"lol\">" + " <!ENTITY lol2 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">" + " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">" + " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">" + " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">" + " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">" + " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">" + " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">" + " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" + "]>" + "<lolz>&lol9;</lolz>" + )); + } + + void testParse_InternalEntity() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE foo [<!ENTITY bar \"Bar\">]><foo>&bar;</foo>")); + } + + void testParse_UndefinedPrefix() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<foo:bar><bla/></foo:bar>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].ns); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[1].ns); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[2].ns); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[3].ns); + } + + void testParse_UndefinedAttributePrefix() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<foo bar:baz='bla'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + } + + private: + class Client : public XMLParserClient { + public: + enum Type { StartElement, EndElement, CharacterData }; + struct Event { + Event( + Type type, + const std::string& data, + const std::string& ns, + const AttributeMap& attributes) + : type(type), data(data), ns(ns), attributes(attributes) {} + Event(Type type, const std::string& data, const std::string& ns = std::string()) + : type(type), data(data), ns(ns) {} + + Type type; + std::string data; + std::string ns; + AttributeMap attributes; + }; + + Client() {} + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + events.push_back(Event(StartElement, element, ns, attributes)); + } + + virtual void handleEndElement(const std::string& element, const std::string& ns) { + events.push_back(Event(EndElement, element, ns)); + } + + virtual void handleCharacterData(const std::string& data) { + events.push_back(Event(CharacterData, data)); + } + + std::vector<Event> events; + } client_; }; #ifdef HAVE_EXPAT diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp index 1266350..a4cb7b8 100644 --- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp @@ -25,173 +25,173 @@ using namespace Swift; class XMPPParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(XMPPParserTest); - CPPUNIT_TEST(testParse_SimpleSession); - CPPUNIT_TEST(testParse_SimpleClientFromServerSession); - CPPUNIT_TEST(testParse_Presence); - CPPUNIT_TEST(testParse_IQ); - CPPUNIT_TEST(testParse_Message); - CPPUNIT_TEST(testParse_StreamFeatures); - CPPUNIT_TEST(testParse_UnknownElement); - CPPUNIT_TEST(testParse_StrayCharacterData); - CPPUNIT_TEST(testParse_InvalidStreamStart); - CPPUNIT_TEST(testParse_ElementEndAfterInvalidStreamStart); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_SimpleSession() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); - CPPUNIT_ASSERT(testling.parse("<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' >")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("<iq/>")); - CPPUNIT_ASSERT(testling.parse("</stream:stream>")); - - CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getTo()); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(Client::StreamEnd, client_.events[4].type); - } - - void testParse_SimpleClientFromServerSession() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); - CPPUNIT_ASSERT(testling.parse("<stream:stream from='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='aeab'>")); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("aeab"), client_.events[0].header->getID()); - } - - - void testParse_Presence() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[1].element.get())); - } - - void testParse_IQ() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<iq/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[1].element.get())); - } - - void testParse_Message() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<message/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<Message*>(client_.events[1].element.get())); - } - - void testParse_StreamFeatures() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<stream:features/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<StreamFeatures*>(client_.events[1].element.get())); - } - - void testParse_UnknownElement() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("<foo/>")); - CPPUNIT_ASSERT(testling.parse("<bar/>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - - CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); - CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[2].element.get())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); - CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[3].element.get())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[4].type); - CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[4].element.get())); - } - - void testParse_StrayCharacterData() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("bla")); - CPPUNIT_ASSERT(testling.parse("<iq/>")); - - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); - CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[2].element.get())); - } - - void testParse_InvalidStreamStart() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(!testling.parse("<tream>")); - } - - void testParse_ElementEndAfterInvalidStreamStart() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + CPPUNIT_TEST_SUITE(XMPPParserTest); + CPPUNIT_TEST(testParse_SimpleSession); + CPPUNIT_TEST(testParse_SimpleClientFromServerSession); + CPPUNIT_TEST(testParse_Presence); + CPPUNIT_TEST(testParse_IQ); + CPPUNIT_TEST(testParse_Message); + CPPUNIT_TEST(testParse_StreamFeatures); + CPPUNIT_TEST(testParse_UnknownElement); + CPPUNIT_TEST(testParse_StrayCharacterData); + CPPUNIT_TEST(testParse_InvalidStreamStart); + CPPUNIT_TEST(testParse_ElementEndAfterInvalidStreamStart); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_SimpleSession() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); + CPPUNIT_ASSERT(testling.parse("<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' >")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("<iq/>")); + CPPUNIT_ASSERT(testling.parse("</stream:stream>")); + + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getTo()); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(Client::StreamEnd, client_.events[4].type); + } + + void testParse_SimpleClientFromServerSession() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); + CPPUNIT_ASSERT(testling.parse("<stream:stream from='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='aeab'>")); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("aeab"), client_.events[0].header->getID()); + } + + + void testParse_Presence() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[1].element.get())); + } + + void testParse_IQ() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<iq/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[1].element.get())); + } + + void testParse_Message() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<message/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<Message*>(client_.events[1].element.get())); + } + + void testParse_StreamFeatures() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<stream:features/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<StreamFeatures*>(client_.events[1].element.get())); + } + + void testParse_UnknownElement() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("<foo/>")); + CPPUNIT_ASSERT(testling.parse("<bar/>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); + CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[2].element.get())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); + CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[3].element.get())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[4].type); + CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[4].element.get())); + } + + void testParse_StrayCharacterData() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("bla")); + CPPUNIT_ASSERT(testling.parse("<iq/>")); + + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); + CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[2].element.get())); + } + + void testParse_InvalidStreamStart() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(!testling.parse("<tream>")); + } + + void testParse_ElementEndAfterInvalidStreamStart() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - CPPUNIT_ASSERT(!testling.parse("<tream/>")); - } + CPPUNIT_ASSERT(!testling.parse("<tream/>")); + } - private: - class Client : public XMPPParserClient { - public: - enum Type { StreamStart, ElementEvent, StreamEnd }; - struct Event { - Event(Type type, boost::shared_ptr<ToplevelElement> element) - : type(type), element(element) {} - Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} + private: + class Client : public XMPPParserClient { + public: + enum Type { StreamStart, ElementEvent, StreamEnd }; + struct Event { + Event(Type type, boost::shared_ptr<ToplevelElement> element) + : type(type), element(element) {} + Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} - Event(Type type) : type(type) {} + Event(Type type) : type(type) {} - Type type; - boost::optional<ProtocolHeader> header; - boost::shared_ptr<ToplevelElement> element; - }; + Type type; + boost::optional<ProtocolHeader> header; + boost::shared_ptr<ToplevelElement> element; + }; - Client() {} - - void handleStreamStart(const ProtocolHeader& header) { - events.push_back(Event(StreamStart, header)); - } - - void handleElement(boost::shared_ptr<ToplevelElement> element) { - events.push_back(Event(ElementEvent, element)); - } - - void handleStreamEnd() { - events.push_back(Event(StreamEnd)); - } - - std::vector<Event> events; - } client_; - PayloadParserFactoryCollection factories_; - PlatformXMLParserFactory xmlParserFactory_; + Client() {} + + void handleStreamStart(const ProtocolHeader& header) { + events.push_back(Event(StreamStart, header)); + } + + void handleElement(boost::shared_ptr<ToplevelElement> element) { + events.push_back(Event(ElementEvent, element)); + } + + void handleStreamEnd() { + events.push_back(Event(StreamEnd)); + } + + std::vector<Event> events; + } client_; + PayloadParserFactoryCollection factories_; + PlatformXMLParserFactory xmlParserFactory_; }; CPPUNIT_TEST_SUITE_REGISTRATION(XMPPParserTest); diff --git a/Swiften/Parser/UnknownElementParser.h b/Swiften/Parser/UnknownElementParser.h index 4c7b360..44c5464 100644 --- a/Swiften/Parser/UnknownElementParser.h +++ b/Swiften/Parser/UnknownElementParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API UnknownElementParser : public GenericElementParser<UnknownElement> { - public: - UnknownElementParser() : GenericElementParser<UnknownElement>() {} - }; + class SWIFTEN_API UnknownElementParser : public GenericElementParser<UnknownElement> { + public: + UnknownElementParser() : GenericElementParser<UnknownElement>() {} + }; } diff --git a/Swiften/Parser/UnknownPayloadParser.h b/Swiften/Parser/UnknownPayloadParser.h index 96e7b77..ca49269 100644 --- a/Swiften/Parser/UnknownPayloadParser.h +++ b/Swiften/Parser/UnknownPayloadParser.h @@ -12,16 +12,16 @@ #include <Swiften/Parser/PayloadParser.h> namespace Swift { - class SWIFTEN_API UnknownPayloadParser : public PayloadParser { - public: - UnknownPayloadParser() {} + class SWIFTEN_API UnknownPayloadParser : public PayloadParser { + public: + UnknownPayloadParser() {} - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} - virtual void handleEndElement(const std::string&, const std::string&) {} - virtual void handleCharacterData(const std::string&) {} + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} + virtual void handleEndElement(const std::string&, const std::string&) {} + virtual void handleCharacterData(const std::string&) {} - virtual boost::shared_ptr<Payload> getPayload() const { - return boost::shared_ptr<Payload>(); - } - }; + virtual boost::shared_ptr<Payload> getPayload() const { + return boost::shared_ptr<Payload>(); + } + }; } diff --git a/Swiften/Parser/XMLParser.h b/Swiften/Parser/XMLParser.h index e1f2d62..8a73c3f 100644 --- a/Swiften/Parser/XMLParser.h +++ b/Swiften/Parser/XMLParser.h @@ -11,20 +11,20 @@ #include <Swiften/Base/API.h> namespace Swift { - class XMLParserClient; + class XMLParserClient; - class SWIFTEN_API XMLParser { - public: - XMLParser(XMLParserClient* client); - virtual ~XMLParser(); + class SWIFTEN_API XMLParser { + public: + XMLParser(XMLParserClient* client); + virtual ~XMLParser(); - virtual bool parse(const std::string& data) = 0; + virtual bool parse(const std::string& data) = 0; - XMLParserClient* getClient() const { - return client_; - } + XMLParserClient* getClient() const { + return client_; + } - private: - XMLParserClient* client_; - }; + private: + XMLParserClient* client_; + }; } diff --git a/Swiften/Parser/XMLParserClient.h b/Swiften/Parser/XMLParserClient.h index b387a82..e4346f6 100644 --- a/Swiften/Parser/XMLParserClient.h +++ b/Swiften/Parser/XMLParserClient.h @@ -10,12 +10,12 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class SWIFTEN_API XMLParserClient { - public: - virtual ~XMLParserClient(); + class SWIFTEN_API XMLParserClient { + public: + virtual ~XMLParserClient(); - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; - virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; - virtual void handleCharacterData(const std::string& data) = 0; - }; + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; + virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; + virtual void handleCharacterData(const std::string& data) = 0; + }; } diff --git a/Swiften/Parser/XMLParserFactory.h b/Swiften/Parser/XMLParserFactory.h index 235016a..091f45b 100644 --- a/Swiften/Parser/XMLParserFactory.h +++ b/Swiften/Parser/XMLParserFactory.h @@ -9,13 +9,13 @@ #include <Swiften/Base/API.h> namespace Swift { - class XMLParser; - class XMLParserClient; + class XMLParser; + class XMLParserClient; - class SWIFTEN_API XMLParserFactory { - public: - virtual ~XMLParserFactory(); + class SWIFTEN_API XMLParserFactory { + public: + virtual ~XMLParserFactory(); - virtual XMLParser* createXMLParser(XMLParserClient*) = 0; - }; + virtual XMLParser* createXMLParser(XMLParserClient*) = 0; + }; } diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 12f2460..10083ba 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -47,159 +47,159 @@ namespace Swift { XMPPParser::XMPPParser( - XMPPParserClient* client, - PayloadParserFactoryCollection* payloadParserFactories, - XMLParserFactory* xmlParserFactory) : - xmlParser_(0), - client_(client), - payloadParserFactories_(payloadParserFactories), - level_(0), - currentElementParser_(0), - parseErrorOccurred_(false) { - xmlParser_ = xmlParserFactory->createXMLParser(this); + XMPPParserClient* client, + PayloadParserFactoryCollection* payloadParserFactories, + XMLParserFactory* xmlParserFactory) : + xmlParser_(0), + client_(client), + payloadParserFactories_(payloadParserFactories), + level_(0), + currentElementParser_(0), + parseErrorOccurred_(false) { + xmlParser_ = xmlParserFactory->createXMLParser(this); } XMPPParser::~XMPPParser() { - delete currentElementParser_; - delete xmlParser_; + delete currentElementParser_; + delete xmlParser_; } bool XMPPParser::parse(const std::string& data) { - bool xmlParseResult = xmlParser_->parse(data); - return xmlParseResult && !parseErrorOccurred_; + bool xmlParseResult = xmlParser_->parse(data); + return xmlParseResult && !parseErrorOccurred_; } void XMPPParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (!parseErrorOccurred_) { - if (level_ == TopLevel) { - if (element == "stream" && ns == "http://etherx.jabber.org/streams") { - ProtocolHeader header; - header.setFrom(attributes.getAttribute("from")); - header.setTo(attributes.getAttribute("to")); - header.setID(attributes.getAttribute("id")); - header.setVersion(attributes.getAttribute("version")); - client_->handleStreamStart(header); - } - else { - parseErrorOccurred_ = true; - } - } - else { - if (level_ == StreamLevel) { - assert(!currentElementParser_); - currentElementParser_ = createElementParser(element, ns); - } - currentElementParser_->handleStartElement(element, ns, attributes); - } - } - ++level_; + if (!parseErrorOccurred_) { + if (level_ == TopLevel) { + if (element == "stream" && ns == "http://etherx.jabber.org/streams") { + ProtocolHeader header; + header.setFrom(attributes.getAttribute("from")); + header.setTo(attributes.getAttribute("to")); + header.setID(attributes.getAttribute("id")); + header.setVersion(attributes.getAttribute("version")); + client_->handleStreamStart(header); + } + else { + parseErrorOccurred_ = true; + } + } + else { + if (level_ == StreamLevel) { + assert(!currentElementParser_); + currentElementParser_ = createElementParser(element, ns); + } + currentElementParser_->handleStartElement(element, ns, attributes); + } + } + ++level_; } void XMPPParser::handleEndElement(const std::string& element, const std::string& ns) { - assert(level_ > TopLevel); - --level_; - if (!parseErrorOccurred_) { - if (level_ == TopLevel) { - assert(element == "stream"); - client_->handleStreamEnd(); - } - else { - assert(currentElementParser_); - currentElementParser_->handleEndElement(element, ns); - if (level_ == StreamLevel) { - client_->handleElement(currentElementParser_->getElement()); - delete currentElementParser_; - currentElementParser_ = NULL; - } - } - } + assert(level_ > TopLevel); + --level_; + if (!parseErrorOccurred_) { + if (level_ == TopLevel) { + assert(element == "stream"); + client_->handleStreamEnd(); + } + else { + assert(currentElementParser_); + currentElementParser_->handleEndElement(element, ns); + if (level_ == StreamLevel) { + client_->handleElement(currentElementParser_->getElement()); + delete currentElementParser_; + currentElementParser_ = NULL; + } + } + } } void XMPPParser::handleCharacterData(const std::string& data) { - if (!parseErrorOccurred_) { - if (currentElementParser_) { - currentElementParser_->handleCharacterData(data); - } - //else { - // std::cerr << "XMPPParser: Ignoring stray character data: " << data << std::endl; - //} - } + if (!parseErrorOccurred_) { + if (currentElementParser_) { + currentElementParser_->handleCharacterData(data); + } + //else { + // std::cerr << "XMPPParser: Ignoring stray character data: " << data << std::endl; + //} + } } ElementParser* XMPPParser::createElementParser(const std::string& element, const std::string& ns) { - if (element == "presence") { - return new PresenceParser(payloadParserFactories_); - } - else if (element == "iq") { - return new IQParser(payloadParserFactories_); - } - else if (element == "message") { - return new MessageParser(payloadParserFactories_); - } - else if (element == "features" && ns == "http://etherx.jabber.org/streams") { - return new StreamFeaturesParser(); - } - else if (element == "error" && ns == "http://etherx.jabber.org/streams") { - return new StreamErrorParser(); - } - else if (element == "auth") { - return new AuthRequestParser(); - } - else if (element == "success") { - return new AuthSuccessParser(); - } - else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - return new AuthFailureParser(); - } - else if (element == "challenge" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - return new AuthChallengeParser(); - } - else if (element == "response" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - return new AuthResponseParser(); - } - else if (element == "starttls") { - return new StartTLSParser(); - } - else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { - return new StartTLSFailureParser(); - } - else if (element == "compress") { - return new CompressParser(); - } - else if (element == "compressed") { - return new CompressedParser(); - } - else if (element == "failure" && ns == "http://jabber.org/protocol/compress") { - return new CompressFailureParser(); - } - else if (element == "proceed") { - return new TLSProceedParser(); - } - else if (element == "enable" && ns == "urn:xmpp:sm:2") { - return new EnableStreamManagementParser(); - } - else if (element == "enabled" && ns == "urn:xmpp:sm:2") { - return new StreamManagementEnabledParser(); - } - else if (element == "failed" && ns == "urn:xmpp:sm:2") { - return new StreamManagementFailedParser(); - } - else if (element == "resume" && ns == "urn:xmpp:sm:2") { - return new StreamResumeParser(); - } - else if (element == "resumed" && ns == "urn:xmpp:sm:2") { - return new StreamResumedParser(); - } - else if (element == "a" && ns == "urn:xmpp:sm:2") { - return new StanzaAckParser(); - } - else if (element == "r" && ns == "urn:xmpp:sm:2") { - return new StanzaAckRequestParser(); - } - else if (element == "handshake") { - return new ComponentHandshakeParser(); - } - return new UnknownElementParser(); + if (element == "presence") { + return new PresenceParser(payloadParserFactories_); + } + else if (element == "iq") { + return new IQParser(payloadParserFactories_); + } + else if (element == "message") { + return new MessageParser(payloadParserFactories_); + } + else if (element == "features" && ns == "http://etherx.jabber.org/streams") { + return new StreamFeaturesParser(); + } + else if (element == "error" && ns == "http://etherx.jabber.org/streams") { + return new StreamErrorParser(); + } + else if (element == "auth") { + return new AuthRequestParser(); + } + else if (element == "success") { + return new AuthSuccessParser(); + } + else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + return new AuthFailureParser(); + } + else if (element == "challenge" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + return new AuthChallengeParser(); + } + else if (element == "response" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + return new AuthResponseParser(); + } + else if (element == "starttls") { + return new StartTLSParser(); + } + else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { + return new StartTLSFailureParser(); + } + else if (element == "compress") { + return new CompressParser(); + } + else if (element == "compressed") { + return new CompressedParser(); + } + else if (element == "failure" && ns == "http://jabber.org/protocol/compress") { + return new CompressFailureParser(); + } + else if (element == "proceed") { + return new TLSProceedParser(); + } + else if (element == "enable" && ns == "urn:xmpp:sm:2") { + return new EnableStreamManagementParser(); + } + else if (element == "enabled" && ns == "urn:xmpp:sm:2") { + return new StreamManagementEnabledParser(); + } + else if (element == "failed" && ns == "urn:xmpp:sm:2") { + return new StreamManagementFailedParser(); + } + else if (element == "resume" && ns == "urn:xmpp:sm:2") { + return new StreamResumeParser(); + } + else if (element == "resumed" && ns == "urn:xmpp:sm:2") { + return new StreamResumedParser(); + } + else if (element == "a" && ns == "urn:xmpp:sm:2") { + return new StanzaAckParser(); + } + else if (element == "r" && ns == "urn:xmpp:sm:2") { + return new StanzaAckRequestParser(); + } + else if (element == "handshake") { + return new ComponentHandshakeParser(); + } + return new UnknownElementParser(); } } diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h index dcc98ca..52b2921 100644 --- a/Swiften/Parser/XMPPParser.h +++ b/Swiften/Parser/XMPPParser.h @@ -14,43 +14,43 @@ #include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class XMLParser; - class XMPPParserClient; - class XMLParserFactory; - class ElementParser; - class PayloadParserFactoryCollection; - - class SWIFTEN_API XMPPParser : public XMLParserClient, boost::noncopyable { - public: - XMPPParser( - XMPPParserClient* parserClient, - PayloadParserFactoryCollection* payloadParserFactories, - XMLParserFactory* xmlParserFactory); - virtual ~XMPPParser(); - - bool parse(const std::string&); - - private: - virtual void handleStartElement( - const std::string& element, - const std::string& ns, - const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string& ns); - virtual void handleCharacterData(const std::string& data); - - ElementParser* createElementParser(const std::string& element, const std::string& xmlns); - - private: - XMLParser* xmlParser_; - XMPPParserClient* client_; - PayloadParserFactoryCollection* payloadParserFactories_; - enum Level { - TopLevel = 0, - StreamLevel = 1, - ElementLevel = 2 - }; - int level_; - ElementParser* currentElementParser_; - bool parseErrorOccurred_; - }; + class XMLParser; + class XMPPParserClient; + class XMLParserFactory; + class ElementParser; + class PayloadParserFactoryCollection; + + class SWIFTEN_API XMPPParser : public XMLParserClient, boost::noncopyable { + public: + XMPPParser( + XMPPParserClient* parserClient, + PayloadParserFactoryCollection* payloadParserFactories, + XMLParserFactory* xmlParserFactory); + virtual ~XMPPParser(); + + bool parse(const std::string&); + + private: + virtual void handleStartElement( + const std::string& element, + const std::string& ns, + const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string& ns); + virtual void handleCharacterData(const std::string& data); + + ElementParser* createElementParser(const std::string& element, const std::string& xmlns); + + private: + XMLParser* xmlParser_; + XMPPParserClient* client_; + PayloadParserFactoryCollection* payloadParserFactories_; + enum Level { + TopLevel = 0, + StreamLevel = 1, + ElementLevel = 2 + }; + int level_; + ElementParser* currentElementParser_; + bool parseErrorOccurred_; + }; } diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h index a3ba54e..73f8119 100644 --- a/Swiften/Parser/XMPPParserClient.h +++ b/Swiften/Parser/XMPPParserClient.h @@ -12,15 +12,15 @@ #include <Swiften/Elements/ToplevelElement.h> namespace Swift { - - class ProtocolHeader; - class SWIFTEN_API XMPPParserClient { - public: - virtual ~XMPPParserClient(); + class ProtocolHeader; - virtual void handleStreamStart(const ProtocolHeader&) = 0; - virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; - virtual void handleStreamEnd() = 0; - }; + class SWIFTEN_API XMPPParserClient { + public: + virtual ~XMPPParserClient(); + + virtual void handleStreamStart(const ProtocolHeader&) = 0; + virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; + virtual void handleStreamEnd() = 0; + }; } |