Uri.h
1/*
2 * Copyright (C) 2010 Tommi Maekitalo
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_System_Uri_h
30#define Pt_System_Uri_h
31
32#include <Pt/System/Api.h>
33#include <Pt/String.h>
34#include <string>
35#include <stdexcept>
36
37namespace Pt {
38
39namespace System {
40
42class PT_SYSTEM_API InvalidUri : public std::runtime_error
43{
44 public:
45 InvalidUri(const std::string& uri);
46
47 ~InvalidUri() throw()
48 {}
49
50 const std::string uri() const
51 { return _uri; }
52
53 private:
54 std::string _uri;
55};
56
58class PT_SYSTEM_API Uri
59{
60 public:
61 Uri()
62 : _port(0)
63 , _ipv6(false)
64 { }
65
66 Uri(const std::string& str);
67
68 void protocol(const std::string& protocol)
69 { _protocol = protocol; }
70
71 const std::string& protocol() const
72 { return _protocol; }
73
74 void user(const std::string& user)
75 { _user = user; }
76
77 const std::string& user() const
78 { return _user; }
79
80 void password(const std::string& password)
81 { _password = password; }
82
83 const std::string& password() const
84 { return _password; }
85
86 void host(const std::string& host)
87 { _host = host; }
88
89 const std::string& host() const
90 { return _host; }
91
92 void port(unsigned short int p)
93 { _port = p; }
94
95 unsigned short int port() const
96 { return _port; }
97
98 void path(const std::string& path)
99 { _path = path; }
100
101 const std::string& path() const
102 { return _path; }
103
104 void query(const std::string& query)
105 { _query = query; }
106
107 const std::string& query() const
108 { return _query; }
109
110 void fragment(const std::string& fragment)
111 { _fragment = fragment; }
112
113 const std::string& fragment() const
114 { return _fragment; }
115
116 std::string str() const;
117
118 public:
119 static Pt::String decode(const std::string& s);
120
121 static std::string encode(const Pt::String& s);
122
123 private:
124 std::string _protocol;
125 std::string _user;
126 std::string _password;
127 std::string _host;
128 unsigned short int _port;
129 bool _ipv6;
130 std::string _path;
131 std::string _query;
132 std::string _fragment;
133};
134
135} // namespace System
136
137} // namespace Pt
138
139#endif // Pt_System_Uri_h
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33