UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
url.hpp
Go to the documentation of this file.
1#ifndef UPNPLIB_NET_URI_URL_HPP
2#define UPNPLIB_NET_URI_URL_HPP
3// Copyright (C) 2022+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
4// Redistribution only with this Copyright remark. Last modified: 2024-08-18
10// This class is based on the "URL Living Standard"
11// ================================================
12// At time the Url parser was coded this
13// Commit Snapshot — Last Updated 21 February 2022 of the URL standard:
14// https://url.spec.whatwg.org/commit-snapshots/9a83e251778046b20f4822f15ad4e2a469de2f57//
15// was used.
16//
17// To understand the parser follow there the [basic URL parser]
18// (https://url.spec.whatwg.org/#concept-basic-url-parse://url.spec.whatwg.org/commit-snapshots/9a83e251778046b20f4822f15ad4e2a469de2f57/#concept-basic-url-parser)
19//
20// To have it available here:
21// "A URI is opaque if, and only if, it is absolute and its scheme-specific
22// part does not begin with a slash character ('/'). An opaque URI has a
23// scheme, a scheme-specific part, and possibly a fragment; all other
24// components are undefined." E.g.: mailto:a@b
25// (http://docs.oracle.com/javase/8/docs/api/java/net/URI.html#isOpaque--)
26//
27// To manual verify URLs conforming to the standard you can use the
28// [Live URL Viewer](https://jsdom.github.io/whatwg-url/).
29
30#include <string>
31#include <cstdint>
32
34namespace UPnPsdk {
35
36// clang-format off
56// clang-format on
57class Url {
58
59 public:
67 void operator=(std::string_view a_url);
68
69 // Get serialized url, e.g.: ser_url = (std::string)url
70 operator std::string() const;
71
72 void clear();
73
74 // getter
75 std::string scheme() const;
76 std::string authority() const;
77 std::string username() const;
78 std::string password() const;
79 std::string host() const;
80 std::string port() const;
81 uint16_t port_num() const;
82 std::string path() const;
83 std::string query() const;
84 std::string fragment() const;
85
86 private:
87 // The strings are initialized to "" by its constructor.
88 std::string m_given_url; // unmodified input to the object
89 std::string m_ser_url;
90 std::string m_ser_base_url;
91 std::string m_scheme;
92 std::string m_authority;
93 std::string m_username;
94 std::string m_password;
95 std::string m_host;
96 std::string m_port; // Always set to the current port
97 uint16_t m_port_num{}; // Only set if not default port of the scheme
98 std::string m_path;
99 std::string m_query;
100 std::string m_fragment;
101
102 void clear_private();
103
104 // Settings for the simple Finite State Machine
105 enum {
106 STATE_NO_STATE,
107 STATE_SCHEME_START,
108 STATE_SCHEME,
109 STATE_NO_SCHEME,
110 STATE_PATH_OR_AUTHORITY,
111 STATE_SPECIAL_AUTHORITY_SLASHES,
112 STATE_SPECIAL_AUTHORITY_IGNORE_SLASHES,
113 STATE_AUTHORITY,
114 STATE_HOST,
115 STATE_PORT,
116 STATE_FILE,
117 STATE_PATH_START,
118 STATE_PATH,
119 STATE_OPAQUE_PATH,
120 STATE_SPECIAL_RELATIVE_OR_AUTHORITY,
121 };
122 int m_state{STATE_NO_STATE};
123
124 std::string m_input; // cleaned up copy of m_given_url for the state machine
125 std::string::iterator m_pointer; // will hold a pointer to m_input
126 std::string m_buffer;
127 bool m_atSignSeen;
128 bool m_insideBrackets;
129 bool m_passwordTokenSeen;
130
131 void clean_and_copy_url_to_input();
132 void fsm_scheme_start();
133 void fsm_scheme();
134 void fsm_no_scheme();
135 void fsm_path_or_authority();
136 void fsm_special_authority_slashes();
137 void fsm_special_authority_ignore_slashes();
138 void fsm_authority();
139 void fsm_host();
140 void fsm_port();
141 void fsm_file();
142 void fsm_path_start();
143 void fsm_path();
144 void fsm_opaque_path();
145 void fsm_special_relative_or_authority();
146};
147
148} // namespace UPnPsdk
150
151#endif // UPNPLIB_NET_URI_URL_HPP
Reengineered Object Oriented UPnP+ program code.