diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/VCardParser.cpp')
| -rw-r--r-- | Swiften/Parser/PayloadParsers/VCardParser.cpp | 166 | 
1 files changed, 165 insertions, 1 deletions
diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index 553d26a..620a307 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -6,6 +6,7 @@  #include <Swiften/Parser/PayloadParsers/VCardParser.h>  #include <Swiften/Base/foreach.h> +#include <Swiften/Base/DateTime.h>  #include <Swiften/StringCodecs/Base64.h>  #include <Swiften/Parser/SerializingParser.h> @@ -20,6 +21,18 @@ void VCardParser::handleStartElement(const std::string& element, const std::stri  	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(); @@ -90,9 +103,160 @@ void VCardParser::handleEndElement(const std::string& element, const std::string  	else if (elementHierarchy == "/vCard/EMAIL/PREF") {  		currentEMailAddress_.isPreferred = true;  	} -	else if (elementHierarchy == "/vCard/EMAIL") { +	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());  	}  | 
 Swift