Webdar 1.0.0
Web user interface to libdar
uri.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef URI_HPP
25#define URI_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <string>
36#include <vector>
37
38 // webdar headers
39#include "chemin.hpp"
40
42
43class uri
44{
45public:
47 uri() { clear(); };
48 uri(const std::string & res) { read(res); };
49 uri(const uri & ref) = default;
50 uri(uri && ref) noexcept = default;
51 uri & operator = (const uri & ref) = default;
52 uri & operator = (uri && ref) noexcept = default;
53 ~uri() = default;
54
56 bool operator == (const uri & arg) const;
57
59 void read(const std::string & res);
60
62 void clear() { path.clear(); hostname = scheme = anchor = ""; };
63
65 void trim_path() { path.clear(); };
66
68 const std::string & get_scheme() const { return scheme; };
69
71 const std::string & get_hostname() const { return hostname; };
72
74 const chemin & get_path() const { return path; };
75
77 const std::string & get_anchor() const { return anchor; };
78
80 void set_anchor_to(const std::string & val) { anchor = val; };
81
83 std::string get_string() const;
84
86 std::string url_path_part() const;
87
89 void add(const std::string & suppath) { path.push_back(suppath); };
90 void add(const chemin & suppath) { path += suppath; };
91
92private:
93 std::string scheme;
94 std::string hostname;
95 chemin path;
96 std::string anchor;
97};
98
99#endif
class chemin definition
Definition: chemin.hpp:51
void clear()
default copy constructor is OK
Definition: chemin.hpp:71
void push_back(const std::string &x)
add a member at the end of the path
Definition: chemin.cpp:72
uri type holds the splitted list of the scheme / hostname / path # anchor
Definition: uri.hpp:44
const std::string & get_anchor() const
retrieve the anchor previously assigned to this uri (empty string if none)
Definition: uri.hpp:77
void read(const std::string &res)
convert an uri from a string
Definition: uri.cpp:86
void trim_path()
clear the path part only
Definition: uri.hpp:65
const chemin & get_path() const
retrieve a path of the uri
Definition: uri.hpp:74
std::string get_string() const
rebuid the uri as a single string
Definition: uri.cpp:53
const std::string & get_hostname() const
obtain the URI host part
Definition: uri.hpp:71
const std::string & get_scheme() const
obtain the URI scheme (http, https, ftp, etc.)
Definition: uri.hpp:68
bool operator==(const uri &arg) const
the anchor part of the path is not used for comparison
Definition: uri.cpp:44
void add(const std::string &suppath)
add members to the uri
Definition: uri.hpp:89
std::string url_path_part() const
get relative url (path + anchor)
Definition: uri.cpp:71
void clear()
clear the uri (empty uri)
Definition: uri.hpp:62
void set_anchor_to(const std::string &val)
assign/replace an anchor to this uri (or remove it "" is provided)
Definition: uri.hpp:80
uri()
constructors
Definition: uri.hpp:47