diff options
Diffstat (limited to 'Swiften/Serializer')
7 files changed, 254 insertions, 51 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h index 345463c..10ae8b0 100644 --- a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -10,7 +10,6 @@ #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> -#include <Swiften/Base/foreach.h> namespace Swift { template<typename BLOCK_ELEMENT> @@ -19,11 +18,12 @@ namespace Swift { BlockSerializer(std::string tag) : GenericPayloadSerializer<BLOCK_ELEMENT>(), tag(tag) { } - virtual std::string serializePayload(boost::shared_ptr<BLOCK_ELEMENT> payload) const { + virtual std::string serializePayload(boost::shared_ptr<BLOCK_ELEMENT> payload) const { XMLElement element(tag, "urn:xmpp:blocking"); - foreach (const JID& jid, payload->getItems()) { + const std::vector<JID>& items = payload->getItems(); + for (std::vector<JID>::const_iterator i = items.begin(); i != items.end(); ++i) { boost::shared_ptr<XMLElement> item = boost::make_shared<XMLElement>("item"); - item->setAttribute("jid", jid); + item->setAttribute("jid", *i); } return element.serialize(); } diff --git a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp index ee468bb..d23cad7 100644 --- a/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ChatStateSerializer.cpp @@ -19,7 +19,6 @@ std::string ChatStateSerializer::serializePayload(boost::shared_ptr<ChatState> c case ChatState::Paused: result += "paused"; break; case ChatState::Inactive: result += "inactive"; break; case ChatState::Gone: result += "gone"; break; - default: result += "gone"; break; } result += " xmlns=\"http://jabber.org/protocol/chatstates\"/>"; return result; diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp index fa6a566..954b885 100644 --- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp @@ -20,7 +20,7 @@ std::string ErrorSerializer::serializePayload(boost::shared_ptr<ErrorPayload> er case ErrorPayload::Modify: result += "modify"; break; case ErrorPayload::Auth: result += "auth"; break; case ErrorPayload::Wait: result += "wait"; break; - default: result += "cancel"; break; + case ErrorPayload::Cancel: result += "cancel"; break; } result += "\">"; @@ -47,7 +47,7 @@ std::string ErrorSerializer::serializePayload(boost::shared_ptr<ErrorPayload> er case ErrorPayload::ServiceUnavailable: conditionElement = "service-unavailable"; break; case ErrorPayload::SubscriptionRequired: conditionElement = "subscription-required"; break; case ErrorPayload::UnexpectedRequest: conditionElement = "unexpected-request"; break; - default: conditionElement = "undefined-condition"; break; + case ErrorPayload::UndefinedCondition: conditionElement = "undefined-condition"; break; } result += "<" + conditionElement + " xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"; diff --git a/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp b/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp index e78cdb4..c83b293 100644 --- a/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/IBBSerializer.cpp @@ -8,6 +8,7 @@ #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> +#include <cassert> #include <boost/lexical_cast.hpp> #include <Swiften/Base/foreach.h> @@ -48,6 +49,7 @@ std::string IBBSerializer::serializePayload(boost::shared_ptr<IBB> ibb) const { return ibbElement.serialize(); } } + assert(false); return ""; } diff --git a/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h index 2b5ffcc..2f2623f 100644 --- a/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h @@ -23,7 +23,6 @@ namespace Swift { case MUCOccupant::Member: result = "member"; break; case MUCOccupant::Outcast: result = "outcast"; break; case MUCOccupant::NoAffiliation: result = "none"; break; - default: assert(false); } return result; } @@ -35,7 +34,6 @@ namespace Swift { case MUCOccupant::NoRole: result = "none"; break; case MUCOccupant::Participant: result = "participant"; break; case MUCOccupant::Visitor: result = "visitor"; break; - default: assert(false); } return result; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp index 3ac1d77..01c8e77 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp @@ -31,14 +31,15 @@ class VCardSerializerTest : public CppUnit::TestFixture vcard->setNickname("DreamGirl"); vcard->setPhoto(createByteArray("abcdef")); vcard->setPhotoType("image/png"); - vcard->addUnknownContent("<BDAY>1234</BDAY><MAILER>mutt</MAILER>"); + vcard->setBirthday(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4))); + vcard->addUnknownContent("<MAILER>mutt</MAILER>"); - VCard::EMailAddress address1; - address1.address = "alice@wonderland.lit"; - address1.isHome = true; - address1.isPreferred = true; - address1.isInternet = true; - vcard->addEMailAddress(address1); + VCard::EMailAddress emailAddress1; + emailAddress1.address = "alice@wonderland.lit"; + emailAddress1.isHome = true; + emailAddress1.isPreferred = true; + emailAddress1.isInternet = true; + vcard->addEMailAddress(emailAddress1); VCard::EMailAddress address2; address2.address = "alice@teaparty.lit"; @@ -46,6 +47,41 @@ class VCardSerializerTest : public CppUnit::TestFixture address2.isX400 = true; vcard->addEMailAddress(address2); + VCard::Telephone telephone1; + telephone1.number = "555-6273"; + telephone1.isHome = true; + telephone1.isVoice = true; + vcard->addTelephone(telephone1); + + VCard::Address address1; + address1.locality = "Any Town"; + address1.street = "Fake Street 123"; + address1.postalCode = "12345"; + address1.country = "USA"; + address1.isHome = true; + vcard->addAddress(address1); + + VCard::AddressLabel label1; + label1.lines.push_back("Fake Street 123"); + label1.lines.push_back("12345 Any Town"); + label1.lines.push_back("USA"); + label1.isHome = true; + vcard->addAddressLabel(label1); + + vcard->addJID(JID("alice@teaparty.lit")); + vcard->addJID(JID("alice@wonderland.lit")); + + vcard->setDescription("I once fell down a rabbit hole."); + + VCard::Organization org1; + org1.name = "Alice In Wonderland Inc."; + vcard->addOrganization(org1); + + vcard->addTitle("Some Title"); + vcard->addRole("Main Character"); + vcard->addURL("http://wonderland.lit/~alice"); + vcard->addURL("http://teaparty.lit/~alice2"); + std::string expectedResult = "<vCard xmlns=\"vcard-temp\">" "<VERSION>2.0</VERSION>" @@ -73,7 +109,35 @@ class VCardSerializerTest : public CppUnit::TestFixture "<TYPE>image/png</TYPE>" "<BINVAL>YWJjZGVm</BINVAL>" "</PHOTO>" - "<BDAY>1234</BDAY>" + "<BDAY>1865-05-04T00:00:00Z</BDAY>" + "<TEL>" + "<NUMBER>555-6273</NUMBER>" + "<HOME/>" + "<VOICE/>" + "</TEL>" + "<ADR>" + "<STREET>Fake Street 123</STREET>" + "<LOCALITY>Any Town</LOCALITY>" + "<PCODE>12345</PCODE>" + "<CTRY>USA</CTRY>" + "<HOME/>" + "</ADR>" + "<LABEL>" + "<LINE>Fake Street 123</LINE>" + "<LINE>12345 Any Town</LINE>" + "<LINE>USA</LINE>" + "<HOME/>" + "</LABEL>" + "<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>"; diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp index 1512c6c..22d59b4 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -13,6 +13,7 @@ #include <Swiften/Serializer/XML/XMLTextNode.h> #include <Swiften/Serializer/XML/XMLRawTextNode.h> #include <Swiften/StringCodecs/Base64.h> +#include <Swiften/Base/DateTime.h> #include <Swiften/Base/foreach.h> namespace Swift { @@ -23,49 +24,33 @@ VCardSerializer::VCardSerializer() : GenericPayloadSerializer<VCard>() { std::string VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard) const { XMLElement queryElement("vCard", "vcard-temp"); if (!vcard->getVersion().empty()) { - boost::shared_ptr<XMLElement> versionElement(new XMLElement("VERSION")); - versionElement->addNode(boost::make_shared<XMLTextNode>(vcard->getVersion())); - queryElement.addNode(versionElement); + queryElement.addNode(boost::make_shared<XMLElement>("VERSION", "", vcard->getVersion())); } if (!vcard->getFullName().empty()) { - boost::shared_ptr<XMLElement> fullNameElement(new XMLElement("FN")); - fullNameElement->addNode(boost::make_shared<XMLTextNode>(vcard->getFullName())); - queryElement.addNode(fullNameElement); + queryElement.addNode(boost::make_shared<XMLElement>("FN", "", vcard->getFullName())); } if (!vcard->getGivenName().empty() || !vcard->getFamilyName().empty() || !vcard->getMiddleName().empty() || !vcard->getPrefix().empty() || !vcard->getSuffix().empty()) { boost::shared_ptr<XMLElement> nameElement(new XMLElement("N")); if (!vcard->getFamilyName().empty()) { - boost::shared_ptr<XMLElement> familyNameElement(new XMLElement("FAMILY")); - familyNameElement->addNode(boost::make_shared<XMLTextNode>(vcard->getFamilyName())); - nameElement->addNode(familyNameElement); + nameElement->addNode(boost::make_shared<XMLElement>("FAMILY", "", vcard->getFamilyName())); } if (!vcard->getGivenName().empty()) { - boost::shared_ptr<XMLElement> givenNameElement(new XMLElement("GIVEN")); - givenNameElement->addNode(boost::make_shared<XMLTextNode>(vcard->getGivenName())); - nameElement->addNode(givenNameElement); + nameElement->addNode(boost::make_shared<XMLElement>("GIVEN", "", vcard->getGivenName())); } if (!vcard->getMiddleName().empty()) { - boost::shared_ptr<XMLElement> middleNameElement(new XMLElement("MIDDLE")); - middleNameElement->addNode(boost::make_shared<XMLTextNode>(vcard->getMiddleName())); - nameElement->addNode(middleNameElement); + nameElement->addNode(boost::make_shared<XMLElement>("MIDDLE", "", vcard->getMiddleName())); } if (!vcard->getPrefix().empty()) { - boost::shared_ptr<XMLElement> prefixElement(new XMLElement("PREFIX")); - prefixElement->addNode(boost::make_shared<XMLTextNode>(vcard->getPrefix())); - nameElement->addNode(prefixElement); + nameElement->addNode(boost::make_shared<XMLElement>("PREFIX", "", vcard->getPrefix())); } if (!vcard->getSuffix().empty()) { - boost::shared_ptr<XMLElement> suffixElement(new XMLElement("SUFFIX")); - suffixElement->addNode(boost::make_shared<XMLTextNode>(vcard->getSuffix())); - nameElement->addNode(suffixElement); + nameElement->addNode(boost::make_shared<XMLElement>("SUFFIX", "", vcard->getSuffix())); } queryElement.addNode(nameElement); } foreach(const VCard::EMailAddress& emailAddress, vcard->getEMailAddresses()) { boost::shared_ptr<XMLElement> emailElement(new XMLElement("EMAIL")); - boost::shared_ptr<XMLElement> userIDElement(new XMLElement("USERID")); - userIDElement->addNode(boost::make_shared<XMLTextNode>(emailAddress.address)); - emailElement->addNode(userIDElement); + emailElement->addNode(boost::make_shared<XMLElement>("USERID", "", emailAddress.address)); if (emailAddress.isHome) { emailElement->addNode(boost::make_shared<XMLElement>("HOME")); } @@ -84,24 +69,179 @@ std::string VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard) c queryElement.addNode(emailElement); } if (!vcard->getNickname().empty()) { - boost::shared_ptr<XMLElement> nickElement(new XMLElement("NICKNAME")); - nickElement->addNode(boost::make_shared<XMLTextNode>(vcard->getNickname())); - queryElement.addNode(nickElement); + queryElement.addNode(boost::make_shared<XMLElement>("NICKNAME", "", vcard->getNickname())); } if (!vcard->getPhoto().empty() || !vcard->getPhotoType().empty()) { XMLElement::ref photoElement(new XMLElement("PHOTO")); if (!vcard->getPhotoType().empty()) { - XMLElement::ref typeElement(new XMLElement("TYPE")); - typeElement->addNode(XMLTextNode::ref(new XMLTextNode(vcard->getPhotoType()))); - photoElement->addNode(typeElement); + photoElement->addNode(boost::make_shared<XMLElement>("TYPE", "", vcard->getPhotoType())); } if (!vcard->getPhoto().empty()) { - XMLElement::ref binvalElement(new XMLElement("BINVAL")); - binvalElement->addNode(XMLTextNode::ref(new XMLTextNode(Base64::encode(vcard->getPhoto())))); - photoElement->addNode(binvalElement); + photoElement->addNode(boost::make_shared<XMLElement>("BINVAL", "", Base64::encode(vcard->getPhoto()))); } queryElement.addNode(photoElement); } + if (!vcard->getBirthday().is_not_a_date_time()) { + queryElement.addNode(boost::make_shared<XMLElement>("BDAY", "", dateTimeToString(vcard->getBirthday()))); + } + + foreach(const VCard::Telephone& telephone, vcard->getTelephones()) { + boost::shared_ptr<XMLElement> telElement(new XMLElement("TEL")); + telElement->addNode(boost::make_shared<XMLElement>("NUMBER", "", telephone.number)); + if (telephone.isHome) { + telElement->addNode(boost::make_shared<XMLElement>("HOME")); + } + if (telephone.isWork) { + telElement->addNode(boost::make_shared<XMLElement>("WORK")); + } + if (telephone.isVoice) { + telElement->addNode(boost::make_shared<XMLElement>("VOICE")); + } + if (telephone.isFax) { + telElement->addNode(boost::make_shared<XMLElement>("FAX")); + } + if (telephone.isPager) { + telElement->addNode(boost::make_shared<XMLElement>("PAGER")); + } + if (telephone.isMSG) { + telElement->addNode(boost::make_shared<XMLElement>("MSG")); + } + if (telephone.isCell) { + telElement->addNode(boost::make_shared<XMLElement>("CELL")); + } + if (telephone.isVideo) { + telElement->addNode(boost::make_shared<XMLElement>("VIDEO")); + } + if (telephone.isBBS) { + telElement->addNode(boost::make_shared<XMLElement>("BBS")); + } + if (telephone.isModem) { + telElement->addNode(boost::make_shared<XMLElement>("MODEM")); + } + if (telephone.isISDN) { + telElement->addNode(boost::make_shared<XMLElement>("ISDN")); + } + if (telephone.isPCS) { + telElement->addNode(boost::make_shared<XMLElement>("PCS")); + } + if (telephone.isPreferred) { + telElement->addNode(boost::make_shared<XMLElement>("PREF")); + } + queryElement.addNode(telElement); + } + + foreach(const VCard::Address& address, vcard->getAddresses()) { + boost::shared_ptr<XMLElement> adrElement = boost::make_shared<XMLElement>("ADR"); + if (!address.poBox.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("POBOX", "", address.poBox)); + } + if (!address.addressExtension.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("EXTADD", "", address.addressExtension)); + } + if (!address.street.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("STREET", "", address.street)); + } + if (!address.locality.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("LOCALITY", "", address.locality)); + } + if (!address.region.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("REGION", "", address.region)); + } + if (!address.postalCode.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("PCODE", "", address.postalCode)); + } + if (!address.country.empty()) { + adrElement->addNode(boost::make_shared<XMLElement>("CTRY", "", address.country)); + } + + if (address.isHome) { + adrElement->addNode(boost::make_shared<XMLElement>("HOME")); + } + if (address.isWork) { + adrElement->addNode(boost::make_shared<XMLElement>("WORK")); + } + if (address.isPostal) { + adrElement->addNode(boost::make_shared<XMLElement>("POSTAL")); + } + if (address.isParcel) { + adrElement->addNode(boost::make_shared<XMLElement>("PARCEL")); + } + if (address.deliveryType == VCard::DomesticDelivery) { + adrElement->addNode(boost::make_shared<XMLElement>("DOM")); + } + if (address.deliveryType == VCard::InternationalDelivery) { + adrElement->addNode(boost::make_shared<XMLElement>("INTL")); + } + if (address.isPreferred) { + adrElement->addNode(boost::make_shared<XMLElement>("PREF")); + } + queryElement.addNode(adrElement); + } + + foreach(const VCard::AddressLabel& addressLabel, vcard->getAddressLabels()) { + boost::shared_ptr<XMLElement> labelElement = boost::make_shared<XMLElement>("LABEL"); + + foreach(const std::string& line, addressLabel.lines) { + labelElement->addNode(boost::make_shared<XMLElement>("LINE", "", line)); + } + + if (addressLabel.isHome) { + labelElement->addNode(boost::make_shared<XMLElement>("HOME")); + } + if (addressLabel.isWork) { + labelElement->addNode(boost::make_shared<XMLElement>("WORK")); + } + if (addressLabel.isPostal) { + labelElement->addNode(boost::make_shared<XMLElement>("POSTAL")); + } + if (addressLabel.isParcel) { + labelElement->addNode(boost::make_shared<XMLElement>("PARCEL")); + } + if (addressLabel.deliveryType == VCard::DomesticDelivery) { + labelElement->addNode(boost::make_shared<XMLElement>("DOM")); + } + if (addressLabel.deliveryType == VCard::InternationalDelivery) { + labelElement->addNode(boost::make_shared<XMLElement>("INTL")); + } + if (addressLabel.isPreferred) { + labelElement->addNode(boost::make_shared<XMLElement>("PREF")); + } + queryElement.addNode(labelElement); + } + + foreach(const JID& jid, vcard->getJIDs()) { + queryElement.addNode(boost::make_shared<XMLElement>("JID", "", jid.toString())); + } + + if (!vcard->getDescription().empty()) { + queryElement.addNode(boost::make_shared<XMLElement>("DESC", "", vcard->getDescription())); + } + + foreach(const VCard::Organization& org, vcard->getOrganizations()) { + boost::shared_ptr<XMLElement> orgElement = boost::make_shared<XMLElement>("ORG"); + if (!org.name.empty()) { + orgElement->addNode(boost::make_shared<XMLElement>("ORGNAME", "", org.name)); + } + if (!org.units.empty()) { + foreach(const std::string& unit, org.units) { + orgElement->addNode(boost::make_shared<XMLElement>("ORGUNIT", "", unit)); + } + } + queryElement.addNode(orgElement); + } + + foreach(const std::string& title, vcard->getTitles()) { + queryElement.addNode(boost::make_shared<XMLElement>("TITLE", "", title)); + } + + foreach(const std::string& role, vcard->getRoles()) { + queryElement.addNode(boost::make_shared<XMLElement>("ROLE", "", role)); + } + + foreach(const std::string& url, vcard->getURLs()) { + queryElement.addNode(boost::make_shared<XMLElement>("URL", "", url)); + } + if (!vcard->getUnknownContent().empty()) { queryElement.addNode(boost::make_shared<XMLRawTextNode>(vcard->getUnknownContent())); } |