Utility library to read and write Ndef messages from/to a Type4 NFC tag
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
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.
RecordType/RecordVCard.h@12:ed4d9b8d1410, 2016-01-14 (annotated)
- Committer:
- giovannivisentini
- Date:
- Thu Jan 14 07:54:44 2016 +0000
- Revision:
- 12:ed4d9b8d1410
- Parent:
- 9:689c1f56f359
- Child:
- 19:13d84b136a62
Update documentation 3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 6:739e3211749d | 1 | /** |
giovannivisentini | 6:739e3211749d | 2 | ****************************************************************************** |
giovannivisentini | 6:739e3211749d | 3 | * @file RecordVCard.h |
giovannivisentini | 8:473f6e0b03df | 4 | * @author ST / Central Labs |
giovannivisentini | 6:739e3211749d | 5 | * @version V1.0.0 |
giovannivisentini | 6:739e3211749d | 6 | * @date 16 Nov 2015 |
giovannivisentini | 9:689c1f56f359 | 7 | * @brief {@link RecordMimeType} that contains a VCard data |
giovannivisentini | 6:739e3211749d | 8 | ****************************************************************************** |
giovannivisentini | 6:739e3211749d | 9 | * @attention |
giovannivisentini | 6:739e3211749d | 10 | * |
giovannivisentini | 6:739e3211749d | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
giovannivisentini | 2:760e36ba9c23 | 12 | * |
giovannivisentini | 6:739e3211749d | 13 | * Redistribution and use in source and binary forms, with or without modification, |
giovannivisentini | 6:739e3211749d | 14 | * are permitted provided that the following conditions are met: |
giovannivisentini | 6:739e3211749d | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
giovannivisentini | 6:739e3211749d | 16 | * this list of conditions and the following disclaimer. |
giovannivisentini | 6:739e3211749d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
giovannivisentini | 6:739e3211749d | 18 | * this list of conditions and the following disclaimer in the documentation |
giovannivisentini | 6:739e3211749d | 19 | * and/or other materials provided with the distribution. |
giovannivisentini | 6:739e3211749d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
giovannivisentini | 6:739e3211749d | 21 | * may be used to endorse or promote products derived from this software |
giovannivisentini | 6:739e3211749d | 22 | * without specific prior written permission. |
giovannivisentini | 6:739e3211749d | 23 | * |
giovannivisentini | 6:739e3211749d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
giovannivisentini | 6:739e3211749d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
giovannivisentini | 6:739e3211749d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
giovannivisentini | 6:739e3211749d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
giovannivisentini | 6:739e3211749d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
giovannivisentini | 6:739e3211749d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
giovannivisentini | 6:739e3211749d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
giovannivisentini | 6:739e3211749d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
giovannivisentini | 6:739e3211749d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
giovannivisentini | 6:739e3211749d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
giovannivisentini | 6:739e3211749d | 34 | * |
giovannivisentini | 6:739e3211749d | 35 | ****************************************************************************** |
giovannivisentini | 2:760e36ba9c23 | 36 | */ |
giovannivisentini | 2:760e36ba9c23 | 37 | |
giovannivisentini | 2:760e36ba9c23 | 38 | #ifndef NDEFLIB_RECORDTYPE_RECORDVCARD_H_ |
giovannivisentini | 2:760e36ba9c23 | 39 | #define NDEFLIB_RECORDTYPE_RECORDVCARD_H_ |
giovannivisentini | 2:760e36ba9c23 | 40 | |
giovannivisentini | 2:760e36ba9c23 | 41 | #include <map> |
giovannivisentini | 2:760e36ba9c23 | 42 | #include <string> |
giovannivisentini | 2:760e36ba9c23 | 43 | #include "RecordMimeType.h" |
giovannivisentini | 2:760e36ba9c23 | 44 | |
giovannivisentini | 2:760e36ba9c23 | 45 | namespace NDefLib { |
giovannivisentini | 2:760e36ba9c23 | 46 | |
giovannivisentini | 4:eaf6c49a86e4 | 47 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 48 | * Specialize the {@link RecordMimeType} to store VCard information. |
giovannivisentini | 12:ed4d9b8d1410 | 49 | * This record handles the VCard version 3 format. |
giovannivisentini | 9:689c1f56f359 | 50 | * @see https://en.wikipedia.org/wiki/VCard |
giovannivisentini | 4:eaf6c49a86e4 | 51 | */ |
giovannivisentini | 2:760e36ba9c23 | 52 | class RecordVCard: public RecordMimeType { |
giovannivisentini | 2:760e36ba9c23 | 53 | public: |
giovannivisentini | 12:ed4d9b8d1410 | 54 | |
giovannivisentini | 4:eaf6c49a86e4 | 55 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 56 | * Type of information that you can store inside the tag |
giovannivisentini | 4:eaf6c49a86e4 | 57 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 58 | typedef enum { |
giovannivisentini | 4:eaf6c49a86e4 | 59 | ADDRESS, //!< ADDRESS |
giovannivisentini | 4:eaf6c49a86e4 | 60 | ADDRESS_HOME, //!< ADDRESS_HOME |
giovannivisentini | 4:eaf6c49a86e4 | 61 | ADDRESS_WORK, //!< ADDRESS_WORK |
giovannivisentini | 4:eaf6c49a86e4 | 62 | AGENT, //!< AGENT |
giovannivisentini | 4:eaf6c49a86e4 | 63 | BIRDAY, //!< BIRDAY |
giovannivisentini | 4:eaf6c49a86e4 | 64 | CATEGORIES, //!< CATEGORIES |
giovannivisentini | 4:eaf6c49a86e4 | 65 | EMAIL, //!< EMAIL |
giovannivisentini | 4:eaf6c49a86e4 | 66 | EMAIL_HOME, //!< EMAIL_HOME |
giovannivisentini | 4:eaf6c49a86e4 | 67 | EMAIL_WORK, //!< EMAIL_WORK |
giovannivisentini | 4:eaf6c49a86e4 | 68 | FORMATTED_NAME,//!< FORMATTED_NAME |
giovannivisentini | 4:eaf6c49a86e4 | 69 | GEO, //!< GEO latitude and longitude ; separated |
giovannivisentini | 4:eaf6c49a86e4 | 70 | IMPP, //!< IMPP |
giovannivisentini | 4:eaf6c49a86e4 | 71 | PGPKEY_URL, //!< PGPKEY_URL |
giovannivisentini | 4:eaf6c49a86e4 | 72 | PGPGKEY_BASE64,//!< PGPGKEY_BASE64 |
giovannivisentini | 4:eaf6c49a86e4 | 73 | LOGO, //!< LOGO |
giovannivisentini | 4:eaf6c49a86e4 | 74 | LOGO_URI, //!< LOGO_URI |
giovannivisentini | 4:eaf6c49a86e4 | 75 | LOGO_BASE64, //!< generic hardcoded image add TYPE=XXXX:imagebyte |
giovannivisentini | 4:eaf6c49a86e4 | 76 | NAME, //!< NAME |
giovannivisentini | 4:eaf6c49a86e4 | 77 | NICKNAME, //!< NICKNAME |
giovannivisentini | 4:eaf6c49a86e4 | 78 | NOTE, //!< NOTE |
giovannivisentini | 4:eaf6c49a86e4 | 79 | ORGANIZATION, //!< ORGANIZATION |
giovannivisentini | 4:eaf6c49a86e4 | 80 | PHOTO_URI, //!< PHOTO_URI |
giovannivisentini | 4:eaf6c49a86e4 | 81 | PHOTO_BASE64, //!< generic hardcoded image add TYPE=XXXX:imagebyte |
giovannivisentini | 4:eaf6c49a86e4 | 82 | REVISION, //!< REVISION |
giovannivisentini | 4:eaf6c49a86e4 | 83 | SOURCE_URL, //!< SOURCE_URL |
giovannivisentini | 4:eaf6c49a86e4 | 84 | TEL, //!< TEL |
giovannivisentini | 4:eaf6c49a86e4 | 85 | TEL_HOME, //!< TEL_HOME |
giovannivisentini | 4:eaf6c49a86e4 | 86 | TEL_WORK, //!< TEL_WORK |
giovannivisentini | 4:eaf6c49a86e4 | 87 | TEL_MOBILE, //!< TEL_MOBILE |
giovannivisentini | 4:eaf6c49a86e4 | 88 | TITLE, //!< TITLE |
giovannivisentini | 4:eaf6c49a86e4 | 89 | URL, //!< URL |
giovannivisentini | 4:eaf6c49a86e4 | 90 | } VCardField_t; |
giovannivisentini | 2:760e36ba9c23 | 91 | |
giovannivisentini | 4:eaf6c49a86e4 | 92 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 93 | * Type used to store the vcard information. |
giovannivisentini | 4:eaf6c49a86e4 | 94 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 95 | typedef std::map<VCardField_t, std::string> VCardInfo_t; |
giovannivisentini | 2:760e36ba9c23 | 96 | |
giovannivisentini | 4:eaf6c49a86e4 | 97 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 98 | * Create a RecordVCard reading the data from the buffer. |
giovannivisentini | 12:ed4d9b8d1410 | 99 | * @param header Record header. |
giovannivisentini | 12:ed4d9b8d1410 | 100 | * @param buffer Buffer to read the data from. |
giovannivisentini | 4:eaf6c49a86e4 | 101 | * @return an object of type RecordVCard or NULL |
giovannivisentini | 12:ed4d9b8d1410 | 102 | * @par User is in charge of freeing the pointer returned by this function. |
giovannivisentini | 4:eaf6c49a86e4 | 103 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 104 | static RecordVCard* parse(const RecordHeader &header, |
giovannivisentini | 2:760e36ba9c23 | 105 | const uint8_t* buffer); |
giovannivisentini | 2:760e36ba9c23 | 106 | |
giovannivisentini | 4:eaf6c49a86e4 | 107 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 108 | * Create a record with the specific information. |
giovannivisentini | 12:ed4d9b8d1410 | 109 | * @param Info optional information to store into the record. |
giovannivisentini | 4:eaf6c49a86e4 | 110 | */ |
giovannivisentini | 5:f2b7efcc5b6e | 111 | explicit RecordVCard(const VCardInfo_t &info=VCardInfo_t()); |
giovannivisentini | 2:760e36ba9c23 | 112 | |
giovannivisentini | 4:eaf6c49a86e4 | 113 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 114 | * Get the specific information stored in this record. |
giovannivisentini | 12:ed4d9b8d1410 | 115 | * @param Type type of information to get. |
giovannivisentini | 12:ed4d9b8d1410 | 116 | * @return if present, the information or an empty string |
giovannivisentini | 4:eaf6c49a86e4 | 117 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 118 | const std::string& operator[](const VCardField_t &type)const { |
giovannivisentini | 4:eaf6c49a86e4 | 119 | VCardInfo_t::const_iterator elem = mCardInfo.find(type); |
giovannivisentini | 4:eaf6c49a86e4 | 120 | if (elem == mCardInfo.end()) |
giovannivisentini | 2:760e36ba9c23 | 121 | return sEmptyTagContent; |
giovannivisentini | 2:760e36ba9c23 | 122 | //else |
giovannivisentini | 2:760e36ba9c23 | 123 | return elem->second; |
giovannivisentini | 2:760e36ba9c23 | 124 | } |
giovannivisentini | 2:760e36ba9c23 | 125 | |
giovannivisentini | 4:eaf6c49a86e4 | 126 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 127 | * Get or set/change an information associated with this record. |
giovannivisentini | 12:ed4d9b8d1410 | 128 | * @param type Type of information to change. |
giovannivisentini | 4:eaf6c49a86e4 | 129 | * @return reference to the string information |
giovannivisentini | 4:eaf6c49a86e4 | 130 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 131 | std::string& operator[](const VCardField_t &type) { |
giovannivisentini | 4:eaf6c49a86e4 | 132 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 133 | return mCardInfo[type]; |
giovannivisentini | 4:eaf6c49a86e4 | 134 | } |
giovannivisentini | 9:689c1f56f359 | 135 | |
giovannivisentini | 9:689c1f56f359 | 136 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 137 | * Get the record type. |
giovannivisentini | 9:689c1f56f359 | 138 | * @return TYPE_MIME_VCARD |
giovannivisentini | 9:689c1f56f359 | 139 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 140 | virtual RecordType_t getType() const { |
giovannivisentini | 2:760e36ba9c23 | 141 | return TYPE_MIME_VCARD; |
giovannivisentini | 4:eaf6c49a86e4 | 142 | } //getType |
giovannivisentini | 4:eaf6c49a86e4 | 143 | |
giovannivisentini | 9:689c1f56f359 | 144 | /** |
giovannivisentini | 9:689c1f56f359 | 145 | * @return update the record content and return the number of |
giovannivisentini | 12:ed4d9b8d1410 | 146 | * bytes needed to store this record |
giovannivisentini | 9:689c1f56f359 | 147 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 148 | virtual uint16_t getByteLength() { |
giovannivisentini | 4:eaf6c49a86e4 | 149 | updateContentInfoString(); |
giovannivisentini | 4:eaf6c49a86e4 | 150 | return RecordMimeType::getByteLength(); |
giovannivisentini | 4:eaf6c49a86e4 | 151 | } |
giovannivisentini | 2:760e36ba9c23 | 152 | |
giovannivisentini | 9:689c1f56f359 | 153 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 154 | * Update the content and write it on the buffer. |
giovannivisentini | 12:ed4d9b8d1410 | 155 | * @param[out] buffer buffer to write the record content into. |
giovannivisentini | 12:ed4d9b8d1410 | 156 | * @return number of bytes written |
giovannivisentini | 9:689c1f56f359 | 157 | * @see Record#write |
giovannivisentini | 9:689c1f56f359 | 158 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 159 | virtual uint16_t write(uint8_t *buffer){ |
giovannivisentini | 4:eaf6c49a86e4 | 160 | updateContentInfoString(); |
giovannivisentini | 4:eaf6c49a86e4 | 161 | return RecordMimeType::write(buffer); |
giovannivisentini | 4:eaf6c49a86e4 | 162 | } |
giovannivisentini | 4:eaf6c49a86e4 | 163 | |
giovannivisentini | 9:689c1f56f359 | 164 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 165 | * Compare two objects. |
giovannivisentini | 9:689c1f56f359 | 166 | * @return true if the records have the same Vcard information |
giovannivisentini | 9:689c1f56f359 | 167 | */ |
giovannivisentini | 7:1ebd6049fa57 | 168 | bool operator==(const RecordVCard &other){ |
giovannivisentini | 7:1ebd6049fa57 | 169 | return (mCardInfo==other.mCardInfo); |
giovannivisentini | 7:1ebd6049fa57 | 170 | } |
giovannivisentini | 7:1ebd6049fa57 | 171 | |
giovannivisentini | 4:eaf6c49a86e4 | 172 | virtual ~RecordVCard() { |
giovannivisentini | 4:eaf6c49a86e4 | 173 | } |
giovannivisentini | 2:760e36ba9c23 | 174 | |
giovannivisentini | 2:760e36ba9c23 | 175 | private: |
giovannivisentini | 4:eaf6c49a86e4 | 176 | VCardInfo_t mCardInfo; |
giovannivisentini | 9:689c1f56f359 | 177 | |
giovannivisentini | 9:689c1f56f359 | 178 | std::string mCardInfoString; ///< buffer containing the Vcard representation for this record |
giovannivisentini | 9:689c1f56f359 | 179 | |
giovannivisentini | 9:689c1f56f359 | 180 | bool mContentIsChange; ///< true if we have to upadte the string rappresentation of the data |
giovannivisentini | 2:760e36ba9c23 | 181 | |
giovannivisentini | 9:689c1f56f359 | 182 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 183 | * Generate a string representing the vcard info |
giovannivisentini | 9:689c1f56f359 | 184 | */ |
giovannivisentini | 9:689c1f56f359 | 185 | void updateContentInfoString(); |
giovannivisentini | 2:760e36ba9c23 | 186 | |
giovannivisentini | 4:eaf6c49a86e4 | 187 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 188 | * Check if the string that starts from the offset position is a valid |
giovannivisentini | 12:ed4d9b8d1410 | 189 | * vcard field. |
giovannivisentini | 12:ed4d9b8d1410 | 190 | * @param content String to search into. |
giovannivisentini | 12:ed4d9b8d1410 | 191 | * @param offset Search offset. |
giovannivisentini | 12:ed4d9b8d1410 | 192 | * @return type index of the found field or a negative number if not a valid vcard |
giovannivisentini | 4:eaf6c49a86e4 | 193 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 194 | static int8_t findVCardFieldType(const std::string &content, |
giovannivisentini | 4:eaf6c49a86e4 | 195 | uint16_t offset); |
giovannivisentini | 2:760e36ba9c23 | 196 | |
giovannivisentini | 4:eaf6c49a86e4 | 197 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 198 | * Return the lenght of a vcard field. |
giovannivisentini | 12:ed4d9b8d1410 | 199 | * @param Content string to search into. |
giovannivisentini | 12:ed4d9b8d1410 | 200 | * @param Offset search offset. |
giovannivisentini | 4:eaf6c49a86e4 | 201 | * @return field length |
giovannivisentini | 12:ed4d9b8d1410 | 202 | * @par This function searches the first sEndVCardTag appearance. |
giovannivisentini | 4:eaf6c49a86e4 | 203 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 204 | static uint16_t findVCardFieldDataLenght(const std::string &content, |
giovannivisentini | 4:eaf6c49a86e4 | 205 | uint16_t offset); |
giovannivisentini | 2:760e36ba9c23 | 206 | |
giovannivisentini | 2:760e36ba9c23 | 207 | static const std::string sVcardMimeType; |
giovannivisentini | 2:760e36ba9c23 | 208 | static const std::string sStartFieldTag[]; |
giovannivisentini | 2:760e36ba9c23 | 209 | static const std::string sEndFieldTag; |
giovannivisentini | 2:760e36ba9c23 | 210 | static const std::string sStartVCardTag; |
giovannivisentini | 2:760e36ba9c23 | 211 | static const std::string sEndVCardTag; |
giovannivisentini | 2:760e36ba9c23 | 212 | static const std::string sEmptyTagContent; |
giovannivisentini | 2:760e36ba9c23 | 213 | }; |
giovannivisentini | 2:760e36ba9c23 | 214 | |
giovannivisentini | 2:760e36ba9c23 | 215 | } /* namespace NDefLib */ |
giovannivisentini | 2:760e36ba9c23 | 216 | |
giovannivisentini | 2:760e36ba9c23 | 217 | #endif /* NDEFLIB_RECORDTYPE_RECORDVCARD_H_ */ |