Mistake on this page?
Report an issue in GitHub or email us
URI.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef NFC_COMMON_URI_H_
19 #define NFC_COMMON_URI_H_
20 
21 #include <stdint.h>
22 #include <string.h>
23 
24 #include "platform/Span.h"
25 
26 #include "nfc/ndef/RecordParser.h"
27 #include "nfc/ndef/MessageBuilder.h"
28 
29 namespace mbed {
30 namespace nfc {
31 namespace ndef {
32 namespace common {
33 
34 /**
35  * @addtogroup nfc
36  * @{
37  */
38 
39 /**
40  * Model the well known type URI.
41  */
42 class URI {
43 public:
44  /**
45  * Identifier codes
46  */
48  NA = 0x00, /// Not applicable
49  HTTP_WWW = 0x01, /// http://www.
50  HTTPS_WWW = 0x02, /// https://www.
51  HTTP = 0x03, /// http://
52  HTTPS = 0x04, /// https://
53  TEL = 0x05, /// tel:
54  MAILTO = 0x06, /// mailto:
55  FTP_ANONYMOUS = 0x07, /// ftp://anonymous:anonymous@
56  FTP_FTP = 0x08, /// ftp://ftp.
57  FTPS = 0x09, /// ftps://
58  SFTP = 0x0A, /// sftp://
59  SMB = 0x0B, /// smb://
60  NFS = 0x0C, /// nfs://
61  FTP = 0x0D, /// ftp://
62  DAV = 0x0E, /// dav://
63  NEWS = 0x0F, /// news:
64  TELNET = 0x10, /// telnet://
65  IMAP = 0x11, /// imap:
66  RSTP = 0x12, /// rstp://
67  URN = 0x13, /// urn:
68  POP = 0x14, /// pop:
69  SIP = 0x15, /// sip:
70  SIPS = 0x16, /// sips:
71  TFTP = 0x17, /// tftp:
72  BTSPP = 0x18, /// btspp://
73  BTL2CAP = 0x19, /// btl2cap://
74  BTGOEP = 0x1A, /// btgoep://
75  TCPOBEX = 0x1B, /// tcpobex://
76  IRDAOBEX = 0x1C, /// irdaobex://
77  FILE = 0x1D, /// file://
78  URN_EPC_ID = 0x1E, /// urn:epc:id:
79  URN_EPC_TAG = 0x1F, /// urn:epc:tag:
80  URN_EPC_PAT = 0x20, /// urn:epc:pat:
81  URN_EPC_RAW = 0x21, /// urn:epc:raw:
82  URN_EPC = 0x22, /// urn:epc:
83  URN_NFC = 0x23, /// urn:nfc:
84  };
85 
86  /**
87  * Construct an empty URI object.
88  */
89  URI();
90 
91  /**
92  * Construct a URI from an id and a uri field.
93  *
94  * @param id The code of the URI prefix.
95  * @param uri_field The URI itself.
96  *
97  * @note To remove the NULL terminator of the C-string of the uri_field
98  * parameter, you can use the utility function span_from_cstr.
99  */
100  URI(uri_identifier_code_t id, const Span<const uint8_t> &uri_field);
101 
102  /**
103  * Construct a URI from another URI.
104  * @param to_copy The uri copied.
105  */
106  URI(const URI &to_copy);
107 
108  /**
109  * Destroy a URI object.
110  */
111  ~URI();
112 
113  /**
114  * Replace the content by the one of an existing URI.
115  * @param to_copy The URI to copy.
116  * @return a reference to this object
117  */
118  URI &operator=(const URI &to_copy);
119 
120  /**
121  * Replace the value of the URI.
122  *
123  * @param id The ID of the URI
124  * @param uri_field A buffer containing the value of the URI field.
125  *
126  * @note To remove the NULL terminator of the C-string of the uri_field
127  * parameter, you can use the utility function span_from_cstr.
128  */
129  void set_uri(
131  const Span<const uint8_t> &uri_field
132  );
133 
134  /**
135  * Return the id of the uri.
136  * @return The id of the uri.
137  */
139 
140  /**
141  * Return the current value of the uri field.
142  * @return The value of the uri field.
143  */
145 
146  /**
147  * Append into a message builder
148  */
149  bool append_as_record(
150  MessageBuilder &message_builder,
151  bool is_last_record = false
152  ) const;
153 
154  /**
155  * Compute the size of this object in a ndef record.
156  *
157  * @return The size of the ndef record required to store this object.
158  */
159  size_t get_record_size() const;
160 
161  /**
162  * Equal operator between two URIs
163  * @param lhs The URI on the left hand side
164  * @param rhs The URI on the right hand side
165  * @return true if lhs equals rhs or false.
166  */
167  friend bool operator==(const URI &lhs, const URI &rhs)
168  {
169  if (lhs._uri_size != rhs._uri_size) {
170  return false;
171  }
172 
173  return memcmp(lhs._uri, rhs._uri, lhs._uri_size) == 0;
174  }
175 
176  friend bool operator!=(const URI &lhs, const URI &rhs)
177  {
178  return !(lhs == rhs);
179  }
180 
181 private:
182  friend class URIParser;
183 
184  void move_data(uint8_t *text, size_t size);
185 
186  uint8_t *_uri;
187  size_t _uri_size;
188 };
189 
190 /**
191  * Parser of a URI.
192  */
193 class URIParser : public GenericRecordParser<URIParser, URI> {
194 public:
195  bool do_parse(const Record &record, URI &uri);
196 };
197 
198 /**
199  * @}
200  */
201 
202 } // namespace common
203 } // namespace ndef
204 } // namespace nfc
205 } // namespace mbed
206 
207 #endif /* NFC_COMMON_URI_H_ */
Construct a NDEF Message.
bool append_as_record(MessageBuilder &message_builder, bool is_last_record=false) const
Append into a message builder.
Model the well known type URI.
Definition: URI.h:42
Span< const uint8_t > get_uri_field() const
Return the current value of the uri field.
size_t get_record_size() const
Compute the size of this object in a ndef record.
ftp://anonymous:anonymous@
Definition: URI.h:56
void set_uri(uri_identifier_code_t id, const Span< const uint8_t > &uri_field)
Replace the value of the URI.
Represent a record.
Definition: Record.h:149
friend bool operator==(const URI &lhs, const URI &rhs)
Equal operator between two URIs.
Definition: URI.h:167
Parser of a URI.
Definition: URI.h:193
URI & operator=(const URI &to_copy)
Replace the content by the one of an existing URI.
uri_identifier_code_t
Identifier codes.
Definition: URI.h:47
URI()
Construct an empty URI object.
uri_identifier_code_t get_id() const
Return the id of the uri.
Definition: ATHandler.h:46
~URI()
Destroy a URI object.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.