UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
uri.hpp
Go to the documentation of this file.
1#ifndef UPnPsdk_URI_HPP
2#define UPnPsdk_URI_HPP
3// Copyright (C) 2025+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
4// Redistribution only with this Copyright remark. Last modified: 2026-03-15
12#include <UPnPsdk/port.hpp>
13#include <UPnPsdk/port_sock.hpp>
14
16#include <string>
18
19
21inline constexpr int HTTP_SUCCESS{1};
22
24// Must not use ABSOLUTE, RELATIVE; already defined in Win32 for other meaning.
25enum struct uriType {
26 Absolute,
28};
29
31enum struct pathType {
32 ABS_PATH,
33 REL_PATH,
42};
43
48struct token {
49 const char* buff;
50 size_t size;
51};
52
58 sockaddr_storage IPaddress;
59};
60
75
76namespace UPnPsdk {
77
78// Free functions
79// ==============
104 std::string& a_path);
105
106
115// REF:_[A_practical_guide_to_URI_encoding_and_URI_decoding]
116// (https://qqq.is/research/a-practical-guide-to-URI-encoding-and-URI-decoding)
117UPnPsdk_VIS void
118decode_esc_chars(std::string& a_encoded
120);
121
122
123// CComponent
124// ==========
133 public:
152 enum struct STATE {
153 undef,
154 empty,
155 avail
156 };
157
160 STATE state() const;
161
165 const std::string& str() const;
166
167 protected:
169 STATE m_state{STATE::undef};
171 DISABLE_MSVC_WARN_4251
174 std::string m_component;
176 ENABLE_MSVC_WARN
178};
179
180
181// class CScheme
182// =============
194 public:
196 CScheme(std::string_view a_uri_sv
197 );
198};
199
200
201// Authority sub-component CUserinfo
202// ------------------------=========
209 public:
211 CUserinfo(std::string_view a_uri_sv
212 );
213};
214
215
216// Authority sub-component CHost
217// ------------------------=====
240 public:
245 CHost(std::string_view a_uri_sv
246 );
247};
248
249
250// Authority sub-component CPort
251// ------------------------=====
258 public:
261 CPort(std::string_view a_uri_sv
262 );
263};
264
265
266// CAuthority
267// ==========
273 public:
280
285 CAuthority(std::string_view a_uri_sv
286 );
289 CComponent::STATE state() const;
290
293 std::string str() const;
294
295 private:
296 using STATE = CComponent::STATE;
297};
298
299
300// CPath
301// =====
307 public:
309 CPath(std::string_view a_uri_sv
310 );
312 void remove_dot_segments();
313};
314
315
316// CQuery
317// ======
323 public:
325 CQuery(std::string_view a_uri_sv
326 );
327};
328
329
330// CFragment
331// =========
337 public:
339 CFragment(std::string_view a_uri_sv
340 );
341};
342
343
344// Class CPrepUriStr
345// =================
351 public:
364 CPrepUriStr(std::string& a_uriref_str
365 );
366};
367
368
369// Class CUriRef
370// =============
376 private:
377 using STATE = CComponent::STATE;
378
379 // member classes
380 // --------------
381 // Next attribute must be declared first due to correct initialization of
382 // the following five component member classes.
384 CPrepUriStr prepare_uri_str;
385
386 public:
395
401 // It is important that the argument 'a_uriref_str' is given by value. So
402 // it is coppied to the stack and available for the lifetime of the
403 // constructor and can be used as stable base for string_views.
404 CUriRef(std::string a_uriref_str
405 );
406
408 CComponent::STATE state() const;
409
411 std::string str() const;
412};
413
414
415// Class CUri
416// ==========
444 public:
449
457 CUri(
459 std::string a_uriref_str);
460
461 // Setter
462 // ------
470 void operator=(
473 std::string a_relref_str);
474
475 // Getter
476 // ------
478 CComponent::STATE state() const;
479
484 std::string str() const;
485};
486
487} // namespace UPnPsdk
488
489
511 const char* in,
513 size_t max,
516 uri_type* out);
517
518#endif // UPnPsdk_URI_HPP
token fragment
Member variable.
Definition uri.hpp:71
token scheme
Member variable.
Definition uri.hpp:68
uriType
Type of the URI.
Definition uri.hpp:25
@ Relative
The URI is relative, means it hasn't a 'scheme' component.
@ Absolute
The URI is absolute, means it has a 'scheme' component.
hostport_type hostport
Member variable.
Definition uri.hpp:72
size_t size
Size of the buffer.
Definition uri.hpp:50
pathType
Type of the 'path' part of the URI.
Definition uri.hpp:31
@ ABS_PATH
The 'path' component begins with a '/'.
@ REL_PATH
The 'path' component doesn't begin with a '/'.
pathType path_type
Member variable.
Definition uri.hpp:69
const char * buff
Buffer.
Definition uri.hpp:49
token pathquery
Member variable.
Definition uri.hpp:70
sockaddr_storage IPaddress
Network socket address.
Definition uri.hpp:58
constexpr int HTTP_SUCCESS
Yet another success code.
Definition uri.hpp:21
uriType type
Member variable.
Definition uri.hpp:67
token text
Pointing to the full host:port string representation.
Definition uri.hpp:57
Represents a URI used in parse_uri and elsewhere.
Definition uri.hpp:64
Buffer used in parsing http messages, urls, etc. Generally this simply holds a pointer into a larger ...
Definition uri.hpp:48
Represents a host port, e.g. "[::1]:443".
Definition uri.hpp:56
Authority component of a URI reference.
Definition uri.hpp:272
CUserinfo userinfo
Definition uri.hpp:276
Base class of a component.
Definition uri.hpp:132
std::string m_component
Name of the component.
Definition uri.hpp:174
STATE
Defines the possible states of a URI component.
Definition uri.hpp:152
Fragment component of a URI reference.
Definition uri.hpp:336
Host subcomponent from an authority component of a URI reference.
Definition uri.hpp:239
Path component of a URI reference.
Definition uri.hpp:306
Port subcomponent from an authority component of a URI reference.
Definition uri.hpp:257
Internal class to prepare the input URI string, Not publicly usable.
Definition uri.hpp:350
Query component of a URI reference.
Definition uri.hpp:322
Scheme component of a URI.
Definition uri.hpp:193
This is a URI reference.
Definition uri.hpp:375
CAuthority authority
Definition uri.hpp:390
CFragment fragment
Definition uri.hpp:393
CScheme scheme
Definition uri.hpp:389
CQuery query
Definition uri.hpp:392
Representing a URI that can be modified with a relative reference.
Definition uri.hpp:443
CUriRef target
Resulting URI of merged relative reference to the base URI.
Definition uri.hpp:448
CUriRef base
Base URI.
Definition uri.hpp:446
Userinfo subcomponent from an authority component of a URI reference.
Definition uri.hpp:208
UPnPsdk_VIS int parse_uri(const char *in, size_t max, uri_type *out)
Parses a uri as defined in RFC 3986 (Uniform Resource Identifier).
Definition uri.cpp:1111
UPnPsdk_VIS void remove_dot_segments(std::string &a_path)
Remove dot segments from a path.
Definition uri.cpp:73
Reengineered Object Oriented UPnP+ program code.
UPnPsdk_VIS void decode_esc_chars(std::string &a_encoded)
Replaces http percent encoded characters with their character representation.
Definition uri.cpp:133
Specifications to be portable between different platforms.
Specifications to be portable with sockets between different platforms.
Macros to support visibility of external symbols.
#define UPnPsdk_VIS
Prefix to export symbol for external use.