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@6:739e3211749d, 2015-12-03 (annotated)
- Committer:
- giovannivisentini
- Date:
- Thu Dec 03 14:56:01 2015 +0000
- Revision:
- 6:739e3211749d
- Parent:
- 5:f2b7efcc5b6e
- Child:
- 7:1ebd6049fa57
Add License
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 | 6:739e3211749d | 4 | * @author ST / CentralLabs |
giovannivisentini | 6:739e3211749d | 5 | * @version V1.0.0 |
giovannivisentini | 6:739e3211749d | 6 | * @date 16 Nov 2015 |
giovannivisentini | 6:739e3211749d | 7 | * @brief RecordVCard implementation |
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 | 2:760e36ba9c23 | 47 | //https://en.wikipedia.org/wiki/VCard |
giovannivisentini | 2:760e36ba9c23 | 48 | |
giovannivisentini | 4:eaf6c49a86e4 | 49 | /** |
giovannivisentini | 4:eaf6c49a86e4 | 50 | * Specialize the mimeType record for store a VCard information. |
giovannivisentini | 4:eaf6c49a86e4 | 51 | * this record handle the VCard version 3 format |
giovannivisentini | 4:eaf6c49a86e4 | 52 | */ |
giovannivisentini | 2:760e36ba9c23 | 53 | class RecordVCard: public RecordMimeType { |
giovannivisentini | 2:760e36ba9c23 | 54 | public: |
giovannivisentini | 4:eaf6c49a86e4 | 55 | /** |
giovannivisentini | 4:eaf6c49a86e4 | 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 | 4:eaf6c49a86e4 | 93 | * type used for 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 | 4:eaf6c49a86e4 | 98 | * create an RecordVCard reading the data from the buffer |
giovannivisentini | 4:eaf6c49a86e4 | 99 | * @param header record header already read |
giovannivisentini | 4:eaf6c49a86e4 | 100 | * @param buffer buffer where read the data |
giovannivisentini | 4:eaf6c49a86e4 | 101 | * @return an object of type RecordVCard or NULL |
giovannivisentini | 4:eaf6c49a86e4 | 102 | * @par free the pointer return 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 | 4:eaf6c49a86e4 | 108 | * create a record with the specific information |
giovannivisentini | 4:eaf6c49a86e4 | 109 | * @param info optional information to store in 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 | 4:eaf6c49a86e4 | 114 | * get the specificic information stored in this record |
giovannivisentini | 4:eaf6c49a86e4 | 115 | * @param type type of information to get |
giovannivisentini | 4:eaf6c49a86e4 | 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 | 4:eaf6c49a86e4 | 127 | * get or set/change an information associated with this record |
giovannivisentini | 4:eaf6c49a86e4 | 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 | 4:eaf6c49a86e4 | 135 | |
giovannivisentini | 4:eaf6c49a86e4 | 136 | virtual RecordType_t getType() const { |
giovannivisentini | 2:760e36ba9c23 | 137 | return TYPE_MIME_VCARD; |
giovannivisentini | 4:eaf6c49a86e4 | 138 | } //getType |
giovannivisentini | 4:eaf6c49a86e4 | 139 | |
giovannivisentini | 4:eaf6c49a86e4 | 140 | |
giovannivisentini | 4:eaf6c49a86e4 | 141 | virtual uint16_t getByteLength() { |
giovannivisentini | 4:eaf6c49a86e4 | 142 | updateContentInfoString(); |
giovannivisentini | 4:eaf6c49a86e4 | 143 | return RecordMimeType::getByteLength(); |
giovannivisentini | 4:eaf6c49a86e4 | 144 | } |
giovannivisentini | 2:760e36ba9c23 | 145 | |
giovannivisentini | 4:eaf6c49a86e4 | 146 | virtual uint16_t write(uint8_t *buffer){ |
giovannivisentini | 4:eaf6c49a86e4 | 147 | updateContentInfoString(); |
giovannivisentini | 4:eaf6c49a86e4 | 148 | return RecordMimeType::write(buffer); |
giovannivisentini | 4:eaf6c49a86e4 | 149 | } |
giovannivisentini | 4:eaf6c49a86e4 | 150 | |
giovannivisentini | 4:eaf6c49a86e4 | 151 | virtual ~RecordVCard() { |
giovannivisentini | 4:eaf6c49a86e4 | 152 | } |
giovannivisentini | 2:760e36ba9c23 | 153 | |
giovannivisentini | 2:760e36ba9c23 | 154 | private: |
giovannivisentini | 4:eaf6c49a86e4 | 155 | VCardInfo_t mCardInfo; |
giovannivisentini | 4:eaf6c49a86e4 | 156 | //buffer containing the Vcard representation for this record |
giovannivisentini | 4:eaf6c49a86e4 | 157 | std::string mCardInfoString; |
giovannivisentini | 2:760e36ba9c23 | 158 | |
giovannivisentini | 4:eaf6c49a86e4 | 159 | bool mContentIsChange; |
giovannivisentini | 4:eaf6c49a86e4 | 160 | |
giovannivisentini | 4:eaf6c49a86e4 | 161 | void updateContentInfoString(); |
giovannivisentini | 2:760e36ba9c23 | 162 | |
giovannivisentini | 4:eaf6c49a86e4 | 163 | /** |
giovannivisentini | 4:eaf6c49a86e4 | 164 | * check if in the string that start in position offset, is present a known |
giovannivisentini | 4:eaf6c49a86e4 | 165 | * vcard file, if yes it return type index, otherwise a negative number |
giovannivisentini | 4:eaf6c49a86e4 | 166 | * @param content string where search |
giovannivisentini | 4:eaf6c49a86e4 | 167 | * @param offset offset where start to search |
giovannivisentini | 4:eaf6c49a86e4 | 168 | * @return index of the field found or a negative number |
giovannivisentini | 4:eaf6c49a86e4 | 169 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 170 | static int8_t findVCardFieldType(const std::string &content, |
giovannivisentini | 4:eaf6c49a86e4 | 171 | uint16_t offset); |
giovannivisentini | 2:760e36ba9c23 | 172 | |
giovannivisentini | 4:eaf6c49a86e4 | 173 | /** |
giovannivisentini | 4:eaf6c49a86e4 | 174 | * search the end of a vcard field |
giovannivisentini | 4:eaf6c49a86e4 | 175 | * @param content string where search |
giovannivisentini | 4:eaf6c49a86e4 | 176 | * @param offset offset where start to search |
giovannivisentini | 4:eaf6c49a86e4 | 177 | * @return field length |
giovannivisentini | 4:eaf6c49a86e4 | 178 | * @par this function search the first sEndVCardTag appearance |
giovannivisentini | 4:eaf6c49a86e4 | 179 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 180 | static uint16_t findVCardFieldDataLenght(const std::string &content, |
giovannivisentini | 4:eaf6c49a86e4 | 181 | uint16_t offset); |
giovannivisentini | 2:760e36ba9c23 | 182 | |
giovannivisentini | 2:760e36ba9c23 | 183 | static const std::string sVcardMimeType; |
giovannivisentini | 2:760e36ba9c23 | 184 | static const std::string sStartFieldTag[]; |
giovannivisentini | 2:760e36ba9c23 | 185 | static const std::string sEndFieldTag; |
giovannivisentini | 2:760e36ba9c23 | 186 | static const std::string sStartVCardTag; |
giovannivisentini | 2:760e36ba9c23 | 187 | static const std::string sEndVCardTag; |
giovannivisentini | 2:760e36ba9c23 | 188 | static const std::string sEmptyTagContent; |
giovannivisentini | 2:760e36ba9c23 | 189 | }; |
giovannivisentini | 2:760e36ba9c23 | 190 | |
giovannivisentini | 2:760e36ba9c23 | 191 | } /* namespace NDefLib */ |
giovannivisentini | 2:760e36ba9c23 | 192 | |
giovannivisentini | 2:760e36ba9c23 | 193 | #endif /* NDEFLIB_RECORDTYPE_RECORDVCARD_H_ */ |