Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
RecordVCard.h
00001 /** 00002 ****************************************************************************** 00003 * @file RecordVCard.h 00004 * @author ST / Central Labs 00005 * @version V2.0.0 00006 * @date 28 Apr 2017 00007 * @brief {@link RecordMimeType} that contains a VCard data 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 #ifndef NDEFLIB_RECORDTYPE_RECORDVCARD_H_ 00039 #define NDEFLIB_RECORDTYPE_RECORDVCARD_H_ 00040 00041 #include <map> 00042 #include <string> 00043 #include "RecordMimeType.h" 00044 00045 namespace NDefLib { 00046 00047 /** 00048 * Specialize the {@link RecordMimeType} to store VCard information. 00049 * This record handles the VCard version 3 format. 00050 * @see https://en.wikipedia.org/wiki/VCard 00051 */ 00052 class RecordVCard: public RecordMimeType { 00053 public: 00054 00055 /** 00056 * Type of information that you can store inside the tag 00057 */ 00058 typedef enum { 00059 ADDRESS, //!< ADDRESS 00060 ADDRESS_HOME, //!< ADDRESS_HOME 00061 ADDRESS_WORK, //!< ADDRESS_WORK 00062 AGENT, //!< AGENT 00063 BIRDAY, //!< BIRDAY 00064 CATEGORIES, //!< CATEGORIES 00065 EMAIL, //!< EMAIL 00066 EMAIL_HOME, //!< EMAIL_HOME 00067 EMAIL_WORK, //!< EMAIL_WORK 00068 FORMATTED_NAME,//!< FORMATTED_NAME 00069 GEO, //!< GEO latitude and longitude ; separated 00070 IMPP, //!< IMPP 00071 PGPKEY_URL, //!< PGPKEY_URL 00072 PGPGKEY_BASE64,//!< PGPGKEY_BASE64 00073 LOGO, //!< LOGO 00074 LOGO_URI, //!< LOGO_URI 00075 LOGO_BASE64, //!< generic hardcoded image add TYPE=XXXX:imagebyte 00076 NAME, //!< NAME 00077 NICKNAME, //!< NICKNAME 00078 NOTE, //!< NOTE 00079 ORGANIZATION, //!< ORGANIZATION 00080 PHOTO_URI, //!< PHOTO_URI 00081 PHOTO_BASE64, //!< generic hardcoded image add TYPE=XXXX:imagebyte 00082 REVISION, //!< REVISION 00083 SOURCE_URL, //!< SOURCE_URL 00084 TEL, //!< TEL 00085 TEL_HOME, //!< TEL_HOME 00086 TEL_WORK, //!< TEL_WORK 00087 TEL_MOBILE, //!< TEL_MOBILE 00088 TITLE, //!< TITLE 00089 URL, //!< URL 00090 } VCardField_t; 00091 00092 /** 00093 * Type used to store the vcard information. 00094 */ 00095 typedef std::map<VCardField_t, std::string> VCardInfo_t; 00096 00097 /** 00098 * Create a RecordVCard reading the data from the buffer. 00099 * @param header Record header. 00100 * @param buffer Buffer to read the data from. 00101 * @return an object of type RecordVCard or NULL 00102 * @par User is in charge of freeing the pointer returned by this function. 00103 */ 00104 static RecordVCard* parse(const RecordHeader &header, 00105 const uint8_t* buffer); 00106 00107 /** 00108 * Create a record with the specific information. 00109 * @param Info optional information to store into the record. 00110 */ 00111 explicit RecordVCard(const VCardInfo_t &info=VCardInfo_t()); 00112 00113 /** 00114 * Get the specific information stored in this record. 00115 * @param Type type of information to get. 00116 * @return if present, the information or an empty string 00117 */ 00118 const std::string& operator[](const VCardField_t &type)const { 00119 VCardInfo_t::const_iterator elem = mCardInfo.find(type); 00120 if (elem == mCardInfo.end()) { 00121 return sEmptyTagContent; 00122 } 00123 00124 return elem->second; 00125 } 00126 00127 /** 00128 * Get or set/change an information associated with this record. 00129 * @param type Type of information to change. 00130 * @return reference to the string information 00131 */ 00132 std::string& operator[](const VCardField_t &type) { 00133 mContentIsChange=true; 00134 return mCardInfo[type]; 00135 } 00136 00137 /** 00138 * Get the record type. 00139 * @return TYPE_MIME_VCARD 00140 */ 00141 virtual RecordType_t get_type() const { 00142 return TYPE_MIME_VCARD; 00143 } //getType 00144 00145 /** 00146 * @return update the record content and return the number of 00147 * bytes needed to store this record 00148 */ 00149 virtual uint16_t get_byte_length () { 00150 update_content_info_string(); 00151 return RecordMimeType::get_byte_length (); 00152 } 00153 00154 /** 00155 * Update the content and write it on the buffer. 00156 * @param[out] buffer buffer to write the record content into. 00157 * @return number of bytes written 00158 * @see Record#write 00159 */ 00160 virtual uint16_t write(uint8_t *buffer){ 00161 update_content_info_string(); 00162 return RecordMimeType::write(buffer); 00163 } 00164 00165 /** 00166 * Compare two objects. 00167 * @return true if the records have the same Vcard information 00168 */ 00169 bool operator==(const RecordVCard &other){ 00170 return (mCardInfo==other.mCardInfo); 00171 } 00172 00173 virtual ~RecordVCard() { 00174 } 00175 00176 private: 00177 VCardInfo_t mCardInfo; 00178 00179 std::string mCardInfoString; ///< buffer containing the Vcard representation for this record 00180 00181 bool mContentIsChange; ///< true if we have to upadte the string rappresentation of the data 00182 00183 /** 00184 * Generate a string representing the vcard info 00185 */ 00186 void update_content_info_string(); 00187 00188 /** 00189 * Check if the string that starts from the offset position is a valid 00190 * vcard field. 00191 * @param content String to search into. 00192 * @param offset Search offset. 00193 * @return type index of the found field or a negative number if not a valid vcard 00194 */ 00195 static int8_t find_VCard_field_type(const std::string &content, 00196 uint16_t offset); 00197 00198 /** 00199 * Return the lenght of a vcard field. 00200 * @param Content string to search into. 00201 * @param Offset search offset. 00202 * @return field length 00203 * @par This function searches the first sEndVCardTag appearance. 00204 */ 00205 static uint16_t find_VCard_field_data_lenght(const std::string &content, 00206 uint16_t offset); 00207 00208 static const std::string sVcardMimeType; 00209 static const std::string sStartFieldTag[]; 00210 static const std::string sEndFieldTag; 00211 static const std::string sStartVCardTag; 00212 static const std::string sEndVCardTag; 00213 static const std::string sEmptyTagContent; 00214 }; 00215 00216 } /* namespace NDefLib */ 00217 00218 #endif /* NDEFLIB_RECORDTYPE_RECORDVCARD_H_ */ 00219 00220 00221 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 14:14:48 by
1.7.2
