ST / NDefLib

Dependents:   NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more

Fork of NDefLib by ST Expansion SW Team

NDEF NFC library

This library provides an abstract API to create NDEF formatted messages and records and to read/write them from/to a Type4 NFC Tag.

Implementations

At the moment, the NDEF API is implemented by X_NUCLEO_NFC01A1 and X_NUCLEO_NFC02A1 Dynamic NFC Tag libraries respectively driving the X-NUCLEO-NFC01A1 and X-NUCLEO-NFC02A1 boards.

Files at this revision

API Documentation at this revision

Comitter:
giovannivisentini
Date:
Thu Dec 10 14:58:43 2015 +0000
Parent:
6:739e3211749d
Child:
8:473f6e0b03df
Commit message:
fix bug + add operator==

Changed in this revision

Message.h Show annotated file Show diff for this revision Revisions of this file
Record.h Show annotated file Show diff for this revision Revisions of this file
RecordHeader.h Show annotated file Show diff for this revision Revisions of this file
RecordType/EmptyRecord.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordAAR.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordAAR.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordGeo.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordGeo.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordMail.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordMail.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordMimeType.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordMimeType.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordSMS.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordSMS.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordText.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordText.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordURI.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordURI.h Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordVCard.cpp Show annotated file Show diff for this revision Revisions of this file
RecordType/RecordVCard.h Show annotated file Show diff for this revision Revisions of this file
--- a/Message.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/Message.h	Thu Dec 10 14:58:43 2015 +0000
@@ -74,7 +74,7 @@
 	 * @return if present a record otherwise NULL
 	 */
 	Record* operator[](const uint32_t index){
-		if (index > mRecords.size())
+		if (index >= mRecords.size())
 			return NULL;
 		return mRecords[index];
 	}
--- a/Record.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/Record.h	Thu Dec 10 14:58:43 2015 +0000
@@ -90,6 +90,13 @@
 	}
 
 	/**
+	 * @return true if it is the fist record in the message
+	 */
+	bool isFirstRecord() const {
+		return mRecordHeader.getMB();
+	}
+
+	/**
 	 * set the record as generic
 	 */
 	void setAsMiddleRecord() {
@@ -97,6 +104,10 @@
 		mRecordHeader.setME(false);
 	}
 
+	bool isMiddleRecord() const{
+		return ! (mRecordHeader.getMB() || mRecordHeader.getME());
+	}
+
 	/**
 	 * get tag type
 	 * @return tag type if not overwrite it return TYPE_UNKNOWN
@@ -105,6 +116,15 @@
 		return TYPE_UNKNOWN;
 	} //getType
 
+
+	/**
+	 * get the record header for this record
+	 * @return record header used for this record
+	 */
+	const RecordHeader& getHeader() const{
+		return mRecordHeader;
+	}
+
 	/**
 	 * number of byte needed for store this record
 	 * @return size header + size record content
--- a/RecordHeader.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordHeader.h	Thu Dec 10 14:58:43 2015 +0000
@@ -66,7 +66,8 @@
 
 
 	RecordHeader() :
-			headerFlags(0), typeLength(0), playloadLength(0) {
+			headerFlags(0), typeLength(0), payloadLength(0) {
+		setSR(true);
 	}
 
 	/**
@@ -77,7 +78,7 @@
 		if (value)
 			headerFlags |= 0x80;
 		else
-			headerFlags &= 0x7F;
+			headerFlags &= ~0x80;
 	}//setMB
 
 	/**
@@ -96,7 +97,7 @@
 		if (value)
 			headerFlags |= 0x40;
 		else
-			headerFlags &= 0xBF;
+			headerFlags &= ~0x40;
 	}//setME
 
 	/**
@@ -116,7 +117,7 @@
 		if (value)
 			headerFlags |= 0x20;
 		else
-			headerFlags &= 0xDF;
+			headerFlags &= ~0x20;
 	}//getCF
 
 	/**
@@ -136,7 +137,7 @@
 		if (value)
 			headerFlags |= 0x10;
 		else
-			headerFlags &= 0xCF;
+			headerFlags &= ~0x10;
 	}//setSR
 
 	/**
@@ -155,7 +156,7 @@
 		if (value)
 			headerFlags |= 0x08;
 		else
-			headerFlags &= 0xAF;
+			headerFlags &= ~0x08;
 	}//setIL
 
 	/**
@@ -186,21 +187,21 @@
 	}
 
 	/**
-	 * set the record playload length
+	 * set the record payload length
 	 * @par this function will update the SR field as needed
-	 * @param length playload length
+	 * @param length payload length
 	 */
-	void setPlayloadLength(uint32_t length) {
-		playloadLength = length;
-		setSR(playloadLength <= 255);
+	void setPayloadLength(uint32_t length) {
+		payloadLength = length;
+		setSR(payloadLength <= 255);
 	}
 
 	/**
-	 * get the playload length
-	 * @return playload length
+	 * get the payload length
+	 * @return payload length
 	 */
-	uint32_t getPlayloadLength() const {
-		return playloadLength;
+	uint32_t getPayloadLength() const {
+		return payloadLength;
 	}
 
 	/**
@@ -224,7 +225,7 @@
 	 * @return 3 or 6
 	 */
 	uint16_t getRecordLength() const {
-		return (getSR() ? 3 : 6) + typeLength + playloadLength;
+		return (getSR() ? 3 : 6) + typeLength + payloadLength;
 	}
 
 	/**
@@ -239,15 +240,15 @@
 		outBuffer[index++] = headerFlags;
 		outBuffer[index++] = typeLength;
 		if (getSR()) {
-			outBuffer[index++] = (uint8_t) playloadLength;
+			outBuffer[index++] = (uint8_t) payloadLength;
 		} else {
-			outBuffer[index++] = (uint8_t) ((playloadLength & 0xFF000000)
+			outBuffer[index++] = (uint8_t) ((payloadLength & 0xFF000000)
 					>> 24);
-			outBuffer[index++] = (uint8_t) ((playloadLength & 0x00FF0000)
+			outBuffer[index++] = (uint8_t) ((payloadLength & 0x00FF0000)
 					>> 16);
-			outBuffer[index++] = (uint8_t) ((playloadLength & 0x0000FF00)
+			outBuffer[index++] = (uint8_t) ((payloadLength & 0x0000FF00)
 					>> 8);
-			outBuffer[index++] = (uint8_t) (playloadLength & 0x000000FF);
+			outBuffer[index++] = (uint8_t) (payloadLength & 0x000000FF);
 		} //if-else
 		return index;
 	} //writeHeader
@@ -262,9 +263,9 @@
 		headerFlags = buffer[index++];
 		typeLength = buffer[index++];
 		if (getSR()) {
-			playloadLength = buffer[index++];
+			payloadLength = buffer[index++];
 		} else {
-			playloadLength = (((uint32_t) buffer[index + 0]) << 24)
+			payloadLength = (((uint32_t) buffer[index + 0]) << 24)
 					| (((uint32_t) buffer[index + 1]) << 16)
 					| (((uint32_t) buffer[index + 2]) << 8)
 					| ((uint32_t) buffer[index + 3]);
@@ -273,11 +274,25 @@
 		return index;
 	} //loadHeader
 
+	/**
+	 * equal operator
+	 * @param other other object to compare
+	 * @return true if the 2 record header are equals
+	 */
+	bool operator==(const RecordHeader &other) const{
+		return (headerFlags==other.headerFlags) &&
+				(typeLength==other.typeLength) &&
+				(payloadLength==other.payloadLength);
+	}
+
+	bool operator!=(const RecordHeader &other) const{
+		return !(*this==other);
+	}
 
 private:
 	uint8_t headerFlags;
 	uint8_t typeLength;
-	uint32_t playloadLength;
+	uint32_t payloadLength;
 };
 
 } /* namespace NDefLib */
--- a/RecordType/EmptyRecord.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/EmptyRecord.h	Thu Dec 10 14:58:43 2015 +0000
@@ -49,26 +49,20 @@
 public:
 
 	EmptyRecord() {
+		mRecordHeader.setFNT(RecordHeader::Empty);
+		mRecordHeader.setMB(true);
+		mRecordHeader.setME(true);
+		mRecordHeader.setTypeLength(0);
+		mRecordHeader.setPayloadLength(0);
 	};
 
 	/**
-	 * empty record size is 3
-	 * @return 3
-	 */
-	virtual uint16_t getByteLength() {
-		return 3;
-	}
-
-	/**
 	 * write the 3 byte used for define an empty record
 	 * @param[out] buffer buffer where write the record
 	 * @return number of write bytes
 	 */
 	virtual uint16_t write(uint8_t *buffer) {
-		buffer[0] = 0x0D;
-		buffer[1] = 0x00;
-		buffer[2] = 0x00;
-		return 3;
+		return mRecordHeader.writeHeader(buffer);
 	} //write
 
 	virtual ~EmptyRecord() {
--- a/RecordType/RecordAAR.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordAAR.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -46,7 +46,7 @@
 		mPackageName(packageName) {
 	mRecordHeader.setFNT(RecordHeader::NFC_external);
 	mRecordHeader.setTypeLength(sizeof(sRecordType));
-	mRecordHeader.setPlayloadLength(mPackageName.size());
+	mRecordHeader.setPayloadLength(mPackageName.size());
 
 }
 
@@ -76,7 +76,7 @@
 
 	return new RecordAAR(
 			std::string((const char*) buffer + offset,
-					header.getPlayloadLength()));
+					header.getPayloadLength()));
 }
 
 } /* namespace NDefLib */
--- a/RecordType/RecordAAR.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordAAR.h	Thu Dec 10 14:58:43 2015 +0000
@@ -85,11 +85,15 @@
 	 */
 	void setPackage(const std::string& package){
 		mPackageName=package;
-		mRecordHeader.setPlayloadLength(mPackageName.size());
+		mRecordHeader.setPayloadLength(mPackageName.size());
 	}
 
 	virtual ~RecordAAR() {	};
 
+	bool operator==(const RecordAAR &other) const{
+		return 	(mPackageName==other.mPackageName);
+	}
+
 private:
 	std::string mPackageName;
 
--- a/RecordType/RecordGeo.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordGeo.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -85,7 +85,7 @@
 	offset += sGeoTag.size();
 
 	const std::string uriContent((const char*) (buffer + offset),
-			header.getPlayloadLength() - offset);
+			header.getPayloadLength() - offset);
 
 	float lat,lon;
 	//build the record only if both the coordinate are available
--- a/RecordType/RecordGeo.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordGeo.h	Thu Dec 10 14:58:43 2015 +0000
@@ -65,7 +65,7 @@
 	 * @param lat latitude
 	 * @param lon longitude
 	 */
-	explicit RecordGeo(const float lat, const float lon);
+	RecordGeo(const float lat, const float lon);
 
 	virtual ~RecordGeo() { };
 
@@ -91,6 +91,11 @@
 		return TYPE_URI_GEOLOCATION;
 	} //getType
 
+	bool operator==(const RecordGeo &other) const {
+		return 	(mLatitiude == other.mLatitiude) &&
+				(mLongitude == other.mLongitude) ;
+	}
+
 protected:
 
 	/**
--- a/RecordType/RecordMail.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordMail.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -64,7 +64,7 @@
         return NULL;
     }
     const std::string uriContent((const char*) (buffer + 2),
-            header.getPlayloadLength() - 1);
+            header.getPayloadLength() - 1);
 
     std::size_t subjectStart = uriContent.find(sSubjectTag);
     if (subjectStart == std::string::npos) //subject not present
--- a/RecordType/RecordMail.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordMail.h	Thu Dec 10 14:58:43 2015 +0000
@@ -64,7 +64,7 @@
 	 * @param subject mail subject
 	 * @param msg message
 	 */
-	explicit RecordMail(const std::string &toAddress, const std::string &subject,
+	RecordMail(const std::string &toAddress, const std::string &subject,
 			const std::string &msg) :
 			RecordURI(RecordURI::MAIL), mToAddress(toAddress), mSubject(
 					subject), mBody(msg),mContentIsChange(true) { }	;
@@ -102,6 +102,12 @@
 		return TYPE_URI_MAIL;
 	} //getType
 
+	bool operator==(const RecordMail& other)const{
+		return mToAddress == other.mToAddress &&
+				mSubject == other.mSubject &&
+				mBody == other.mBody;
+	}
+
 protected:
 	virtual void updateContent();
 
--- a/RecordType/RecordMimeType.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordMimeType.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -43,7 +43,7 @@
 void RecordMimeType::initializeHeaderData() {
 	mRecordHeader.setFNT(RecordHeader::Mime_media_type);
 	mRecordHeader.setTypeLength(mMimeType.size());
-	mRecordHeader.setPlayloadLength(mDataLength);
+	mRecordHeader.setPayloadLength(mDataLength);
 }
 
 RecordMimeType::RecordMimeType(const std::string &mimeType, const uint8_t *data,
@@ -59,6 +59,14 @@
 	initializeHeaderData();
 }
 
+RecordMimeType::RecordMimeType(const std::string &mimeType, const std::string &data) :
+		mMimeType(mimeType), mDataLength(data.size()),mData(new uint8_t[mDataLength]),mDataToFree(true) {
+
+	std::memcpy(mData,data.c_str(),mDataLength);
+
+	initializeHeaderData();
+}
+
 uint16_t RecordMimeType::write(uint8_t *buffer) {
 	uint16_t offset = 0;
 	offset += mRecordHeader.writeHeader(buffer);
@@ -83,7 +91,7 @@
 	uint32_t dataOffset = offset + header.getTypeLength();
 	return new RecordMimeType(
 			std::string((const char*) buffer + offset, header.getTypeLength()),
-			buffer + dataOffset, header.getPlayloadLength());
+			buffer + dataOffset, header.getPayloadLength());
 }
 
 void RecordMimeType::copyMimeData(const uint8_t* data, uint32_t dataLength){
@@ -91,7 +99,7 @@
 		mData = new uint8_t[dataLength];
 		mDataLength=dataLength;
 		std::memcpy(mData,data,dataLength);
-		mRecordHeader.setPlayloadLength(dataLength);
+		mRecordHeader.setPayloadLength(dataLength);
 		mDataToFree=true;
 	}
 
--- a/RecordType/RecordMimeType.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordMimeType.h	Thu Dec 10 14:58:43 2015 +0000
@@ -38,6 +38,7 @@
 #ifndef NDEFLIB_RECORDTYPE_RECORDMIMETYPE_H_
 #define NDEFLIB_RECORDTYPE_RECORDMIMETYPE_H_
 
+#include <cstring>
 #include <string>
 
 #include "NDefLib/Record.h"
@@ -59,9 +60,11 @@
 	 * @param data content
 	 * @param nDataLenght content length in byte
 	 */
-	explicit RecordMimeType(const std::string &mimeType, const uint8_t *data=NULL,
+	RecordMimeType(const std::string &mimeType, const uint8_t *data=NULL,
 			uint32_t nDataLenght=0);
 
+	RecordMimeType(const std::string &mimeType, const std::string &data);
+
 	virtual uint16_t write(uint8_t *buffer);
 
 	const std::string& getMimeType() const {
@@ -80,7 +83,7 @@
 		deleteMimeData();
 		mData = data;
 		mDataLength=dataLength;
-		mRecordHeader.setPlayloadLength(dataLength);
+		mRecordHeader.setPayloadLength(dataLength);
 	}
 
 	/**
@@ -108,6 +111,12 @@
 		deleteMimeData();
 	};
 
+	bool operator==(const RecordMimeType &other) const {
+		return 	mMimeType==other.mMimeType &&
+				mDataLength == other.mDataLength &&
+				(std::memcmp(mData,other.mData,mDataLength)==0);
+	}
+
 private:
 
 	void initializeHeaderData();
@@ -121,6 +130,7 @@
 			delete [] mData;
 			mData=NULL;
 		}//if
+
 	}
 
 	const std::string mMimeType;
--- a/RecordType/RecordSMS.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordSMS.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -50,6 +50,9 @@
 
 void RecordSMS::updateContent(){
 
+	if(!mContentIsChange)
+		return;
+
 	mContent.reserve(mNumber.size()+sBodyTag.size()+mMsg.size());
 
 	mContent  = mNumber;
@@ -73,7 +76,7 @@
 	offset += sSmsTag.size();
 
 	const std::string uriContent((const char*) (buffer + offset),
-			header.getPlayloadLength() - offset);
+			header.getPayloadLength() - offset+1);
 
 	std::size_t numberEnd = uriContent.find(sBodyTag);
 	if (numberEnd == std::string::npos)
--- a/RecordType/RecordSMS.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordSMS.h	Thu Dec 10 14:58:43 2015 +0000
@@ -65,7 +65,7 @@
 	 * @param number number where send the sms
 	 * @param message message to send
 	 */
-	explicit RecordSMS(const std::string &number, const std::string &message);
+	RecordSMS(const std::string &number, const std::string &message);
 
 	virtual RecordType_t getType() const {
 		return TYPE_URI_SMS;
@@ -90,6 +90,11 @@
 		mContentIsChange=true;
 	}
 
+	bool operator==(const RecordSMS &other) const {
+		return (mMsg == other.mMsg) &&
+				(mNumber == other.mNumber);
+	}
+
 	virtual ~RecordSMS() {
 	};
 
--- a/RecordType/RecordText.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordText.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -85,7 +85,7 @@
 		const TextEncoding enc = getEncoding(textStatus);
 		const uint8_t langSize = getLanguageLength(textStatus);
 		//-1 is the textStatus
-		const uint8_t textSize = header.getPlayloadLength() - langSize - 1;
+		const uint8_t textSize = header.getPayloadLength() - langSize - 1;
 
 		return new RecordText(enc,
 				std::string((const char*) (buffer + index), langSize),
--- a/RecordType/RecordText.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordText.h	Thu Dec 10 14:58:43 2015 +0000
@@ -97,6 +97,22 @@
 		updatePlayloadLength();
 	}
 
+
+	const std::string& getLanguage()const{
+		return mLanguage;
+	}
+
+	TextEncoding getEncoding()const{
+		return mEncode;
+	}
+
+	bool operator==(const RecordText &other)const{
+		return 	mTextStatus == other.mTextStatus &&
+				mLanguage == other.mLanguage &&
+				mText == other.mText;
+
+	}
+
 	virtual ~RecordText() {
 	};
 
@@ -105,7 +121,7 @@
 	void setRecordHeader();
 
 	void updatePlayloadLength(){
-		mRecordHeader.setPlayloadLength(1 + mLanguage.size() + mText.size());
+		mRecordHeader.setPayloadLength(1 + mLanguage.size() + mText.size());
 	}
 
 	/**
--- a/RecordType/RecordURI.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordURI.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -63,12 +63,13 @@
 
 RecordURI::RecordURI(knowUriId_t uriId, const std::string &uriContent) :
 		mUriTypeId(uriId), mTypeString("") {
-	storeRemoveingPrefix(sKnowUriPrefix[uriId],uriContent);
+	setContent(uriContent);
 	setRecordHeader();
 }
 
 RecordURI::RecordURI(const std::string &uriType, const std::string &uriContent) :
 		mContent(uriContent),mUriTypeId(UNKNOWN), mTypeString(uriType)  {
+	updateRecordHeader();
 	setRecordHeader();
 }
 
@@ -107,7 +108,7 @@
 	if (uriType != UNKNOWN) {
 		return new RecordURI(uriType,
 				std::string((const char*) buffer + offset,
-						header.getPlayloadLength() - 1));
+						header.getPayloadLength() - 1));
 	} //else
 
 	//is an unknown type with a specific class
@@ -120,7 +121,7 @@
 	//else is an unknown type without a specific class
 	return new RecordURI(uriType,
 			std::string((const char*) buffer + offset,
-					header.getPlayloadLength() - 1));
+					header.getPayloadLength() - 1));
 
 }
 
--- a/RecordType/RecordURI.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordURI.h	Thu Dec 10 14:58:43 2015 +0000
@@ -150,6 +150,13 @@
 		return mTypeString;
 	}
 
+	bool operator==(const RecordURI &other) const {
+		return 	(mUriTypeId==other.mUriTypeId) &&
+				(mTypeString==other.mTypeString) &&
+				(mContent==other.mContent);
+	}
+
+
 	virtual ~RecordURI() {
 	};
 
@@ -163,10 +170,20 @@
 	/**
 	 * a subclass must implement this function for store the tag content inside the mContent
 	 * variable, in this way this class will handle to write the tag
+	 * @par you should not call this function directly but use updateContentAndHeader that keep the
+	 * header information in sync with the content
 	 */
 	virtual void updateContent(){};
 
 	/**
+	 * update the tag content and update the header with the new content size
+	 */
+	void updateContentAndHeader(){
+		updateContent();
+		updateRecordHeader();
+	}
+
+	/**
 	 * the subclass have to store in this variable the content to write in the tag.
 	 * this class will ask to update the content thought the updateContent call
 	 */
@@ -180,19 +197,11 @@
 	void setRecordHeader();
 
 	/**
-	 * update the tag content and update the header with the new content size
-	 */
-	void updateContentAndHeader(){
-		updateContent();
-		updateRecordHeader();
-	}
-
-	/**
-	 * set the correct size of the plaload
+	 * set the correct size of the payload
 	 */
 	void updateRecordHeader(){
 		//+1 = size of the uriTypeId
-		mRecordHeader.setPlayloadLength(1 + mTypeString.size() + mContent.size());
+		mRecordHeader.setPayloadLength(1 + mTypeString.size() + mContent.size());
 	}
 
 	void storeRemoveingPrefix(const std::string &prefix,const std::string &content){
--- a/RecordType/RecordVCard.cpp	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordVCard.cpp	Thu Dec 10 14:58:43 2015 +0000
@@ -120,7 +120,7 @@
 		return NULL;
 	//the version is ok
 	const std::string vCardContent((const char*) buffer + sStartVCardTag.size(),
-			header.getPlayloadLength() - sStartVCardTag.size());
+			header.getPayloadLength() - sStartVCardTag.size());
 	uint16_t offset = 0;
 	buffer += sStartVCardTag.size(); // for debug
 	VCardInfo_t info;
--- a/RecordType/RecordVCard.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordType/RecordVCard.h	Thu Dec 10 14:58:43 2015 +0000
@@ -148,6 +148,10 @@
 		return RecordMimeType::write(buffer);
 	}
 
+	bool operator==(const RecordVCard &other){
+		return (mCardInfo==other.mCardInfo);
+	}
+
 	virtual ~RecordVCard() {
 	}