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.
URI.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef NFC_COMMON_URI_H_ 00018 #define NFC_COMMON_URI_H_ 00019 00020 #include <stdint.h> 00021 #include <string.h> 00022 00023 #include "platform/Span.h" 00024 00025 #include "nfc/ndef/RecordParser.h" 00026 #include "nfc/ndef/MessageBuilder.h" 00027 00028 namespace mbed { 00029 namespace nfc { 00030 namespace ndef { 00031 namespace common { 00032 00033 /** 00034 * @addtogroup nfc 00035 * @{ 00036 */ 00037 00038 /** 00039 * Model the well known type URI. 00040 */ 00041 class URI { 00042 public: 00043 /** 00044 * Identifier codes 00045 */ 00046 enum uri_identifier_code_t { 00047 NA = 0x00, /// Not applicable 00048 HTTP_WWW = 0x01, /// http://www. 00049 HTTPS_WWW = 0x02, /// https://www. 00050 HTTP = 0x03, /// http:// 00051 HTTPS = 0x04, /// https:// 00052 TEL = 0x05, /// tel: 00053 MAILTO = 0x06, /// mailto: 00054 FTP_ANONYMOUS = 0x07, /// ftp://anonymous:anonymous@ 00055 FTP_FTP = 0x08, /// ftp://ftp. 00056 FTPS = 0x09, /// ftps:// 00057 SFTP = 0x0A, /// sftp:// 00058 SMB = 0x0B, /// smb:// 00059 NFS = 0x0C, /// nfs:// 00060 FTP = 0x0D, /// ftp:// 00061 DAV = 0x0E, /// dav:// 00062 NEWS = 0x0F, /// news: 00063 TELNET = 0x10, /// telnet:// 00064 IMAP = 0x11, /// imap: 00065 RSTP = 0x12, /// rstp:// 00066 URN = 0x13, /// urn: 00067 POP = 0x14, /// pop: 00068 SIP = 0x15, /// sip: 00069 SIPS = 0x16, /// sips: 00070 TFTP = 0x17, /// tftp: 00071 BTSPP = 0x18, /// btspp:// 00072 BTL2CAP = 0x19, /// btl2cap:// 00073 BTGOEP = 0x1A, /// btgoep:// 00074 TCPOBEX = 0x1B, /// tcpobex:// 00075 IRDAOBEX = 0x1C, /// irdaobex:// 00076 FILE = 0x1D, /// file:// 00077 URN_EPC_ID = 0x1E, /// urn:epc:id: 00078 URN_EPC_TAG = 0x1F, /// urn:epc:tag: 00079 URN_EPC_PAT = 0x20, /// urn:epc:pat: 00080 URN_EPC_RAW = 0x21, /// urn:epc:raw: 00081 URN_EPC = 0x22, /// urn:epc: 00082 URN_NFC = 0x23, /// urn:nfc: 00083 }; 00084 00085 /** 00086 * Construct an empty URI object. 00087 */ 00088 URI(); 00089 00090 /** 00091 * Construct a URI from an id and a uri field. 00092 * 00093 * @param id The code of the URI prefix. 00094 * @param uri_field The URI itself. 00095 * 00096 * @note To remove the NULL terminator of the C-string of the uri_field 00097 * parameter, you can use the utility function span_from_cstr. 00098 */ 00099 URI(uri_identifier_code_t id, const Span<const uint8_t> &uri_field); 00100 00101 /** 00102 * Construct a URI from another URI. 00103 * @param to_copy The uri copied. 00104 */ 00105 URI(const URI &to_copy); 00106 00107 /** 00108 * Destroy a URI object. 00109 */ 00110 ~URI(); 00111 00112 /** 00113 * Replace the content by the one of an existing URI. 00114 * @param to_copy The URI to copy. 00115 * @return a reference to this object 00116 */ 00117 URI &operator=(const URI &to_copy); 00118 00119 /** 00120 * Replace the value of the URI. 00121 * 00122 * @param id The ID of the URI 00123 * @param uri_field A buffer containing the value of the URI field. 00124 * 00125 * @note To remove the NULL terminator of the C-string of the uri_field 00126 * parameter, you can use the utility function span_from_cstr. 00127 */ 00128 void set_uri( 00129 uri_identifier_code_t id, 00130 const Span<const uint8_t> &uri_field 00131 ); 00132 00133 /** 00134 * Return the id of the uri. 00135 * @return The id of the uri. 00136 */ 00137 uri_identifier_code_t get_id() const; 00138 00139 /** 00140 * Return the current value of the uri field. 00141 * @return The value of the uri field. 00142 */ 00143 Span<const uint8_t> get_uri_field() const; 00144 00145 /** 00146 * Append into a message builder 00147 */ 00148 bool append_as_record( 00149 MessageBuilder &message_builder, 00150 bool is_last_record = false 00151 ) const; 00152 00153 /** 00154 * Compute the size of this object in a ndef record. 00155 * 00156 * @return The size of the ndef record required to store this object. 00157 */ 00158 size_t get_record_size() const; 00159 00160 /** 00161 * Equal operator between two URIs 00162 * @param lhs The URI on the left hand side 00163 * @param rhs The URI on the right hand side 00164 * @return true if lhs equals rhs or false. 00165 */ 00166 friend bool operator==(const URI &lhs, const URI &rhs) 00167 { 00168 if (lhs._uri_size != rhs._uri_size) { 00169 return false; 00170 } 00171 00172 return memcmp(lhs._uri, rhs._uri, lhs._uri_size) == 0; 00173 } 00174 00175 friend bool operator!=(const URI &lhs, const URI &rhs) 00176 { 00177 return !(lhs == rhs); 00178 } 00179 00180 private: 00181 friend class URIParser; 00182 00183 void move_data(uint8_t *text, size_t size); 00184 00185 uint8_t *_uri; 00186 size_t _uri_size; 00187 }; 00188 00189 /** 00190 * Parser of a URI. 00191 */ 00192 class URIParser : public GenericRecordParser<URIParser, URI> { 00193 public: 00194 bool do_parse(const Record &record, URI &uri); 00195 }; 00196 00197 /** 00198 * @} 00199 */ 00200 00201 } // namespace common 00202 } // namespace ndef 00203 } // namespace nfc 00204 } // namespace mbed 00205 00206 #endif /* NFC_COMMON_URI_H_ */
Generated on Tue Aug 9 2022 00:37:24 by
1.7.2