summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp')
-rw-r--r--Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp172
1 files changed, 172 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp
index 1512c6c..2676a02 100644
--- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp
@@ -13,10 +13,17 @@
#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 {
+boost::shared_ptr<XMLElement> createTextElement(const std::string& elementName, const std::string& text) {
+ boost::shared_ptr<XMLElement> element = boost::make_shared<XMLElement>(elementName);
+ element->addNode(boost::make_shared<XMLTextNode>(text));
+ return element;
+}
+
VCardSerializer::VCardSerializer() : GenericPayloadSerializer<VCard>() {
}
@@ -102,6 +109,171 @@ std::string VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard) c
}
queryElement.addNode(photoElement);
}
+ if (!vcard->getBirthday().is_not_a_date_time()) {
+ XMLElement::ref bdayElement(new XMLElement("BDAY"));
+ bdayElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(dateTimeToString(vcard->getBirthday()))));
+ queryElement.addNode(bdayElement);
+ }
+
+ foreach(const VCard::Telephone& telephone, vcard->getTelephones()) {
+ boost::shared_ptr<XMLElement> telElement(new XMLElement("TEL"));
+ boost::shared_ptr<XMLElement> numberElement(new XMLElement("NUMBER"));
+ numberElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(telephone.number)));
+ telElement->addNode(numberElement);
+ if (telephone.isHome) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("HOME")));
+ }
+ if (telephone.isWork) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("WORK")));
+ }
+ if (telephone.isVoice) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("VOICE")));
+ }
+ if (telephone.isFax) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("FAX")));
+ }
+ if (telephone.isPager) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("PAGER")));
+ }
+ if (telephone.isMSG) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("MSG")));
+ }
+ if (telephone.isCell) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("CELL")));
+ }
+ if (telephone.isVideo) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("VIDEO")));
+ }
+ if (telephone.isBBS) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("BBS")));
+ }
+ if (telephone.isModem) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("MODEM")));
+ }
+ if (telephone.isISDN) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("ISDN")));
+ }
+ if (telephone.isPCS) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("PCS")));
+ }
+ if (telephone.isPreferred) {
+ telElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("PREF")));
+ }
+ queryElement.addNode(telElement);
+ }
+
+ foreach(const VCard::Address& address, vcard->getAddresses()) {
+ boost::shared_ptr<XMLElement> adrElement(new XMLElement("ADR"));
+ if (!address.POBox.empty()) {
+ adrElement->addNode(createTextElement("POBOX", address.POBox));
+ }
+ if (!address.addressExtension.empty()) {
+ adrElement->addNode(createTextElement("EXTADD", address.addressExtension));
+ }
+ if (!address.street.empty()) {
+ adrElement->addNode(createTextElement("STREET", address.street));
+ }
+ if (!address.locality.empty()) {
+ adrElement->addNode(createTextElement("LOCALITY", address.locality));
+ }
+ if (!address.region.empty()) {
+ adrElement->addNode(createTextElement("REGION", address.region));
+ }
+ if (!address.postalCode.empty()) {
+ adrElement->addNode(createTextElement("PCODE", address.postalCode));
+ }
+ if (!address.country.empty()) {
+ adrElement->addNode(createTextElement("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(new XMLElement("LABEL"));
+
+ foreach(const std::string& line, addressLabel.lines) {
+ labelElement->addNode(createTextElement("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(createTextElement("JID", jid.toString()));
+ }
+
+ if (!vcard->getDescription().empty()) {
+ queryElement.addNode(createTextElement("DESC", vcard->getDescription()));
+ }
+
+ foreach(const VCard::Organization& org, vcard->getOrganizations()) {
+ boost::shared_ptr<XMLElement> orgElement(new XMLElement("ORG"));
+ if (!org.name.empty()) {
+ orgElement->addNode(createTextElement("ORGNAME", org.name));
+ }
+ if (!org.units.empty()) {
+ foreach(const std::string& unit, org.units) {
+ orgElement->addNode(createTextElement("ORGUNIT", unit));
+ }
+ }
+ queryElement.addNode(orgElement);
+ }
+
+ foreach(const std::string& title, vcard->getTitles()) {
+ queryElement.addNode(createTextElement("TITLE", title));
+ }
+
+ foreach(const std::string& role, vcard->getRoles()) {
+ queryElement.addNode(createTextElement("ROLE", role));
+ }
+
+ foreach(const std::string& url, vcard->getURLs()) {
+ queryElement.addNode(createTextElement("URL", url));
+ }
+
if (!vcard->getUnknownContent().empty()) {
queryElement.addNode(boost::make_shared<XMLRawTextNode>(vcard->getUnknownContent()));
}