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 <string>
34 #include <stdexcept>
35 
36 namespace Pt {
37 
38 namespace System {
39 
41 class PT_SYSTEM_API InvalidUri : public std::runtime_error
42 {
43  public:
44  InvalidUri(const std::string& uri);
45 
46  ~InvalidUri() throw()
47  {}
48 
49  const std::string uri() const
50  { return _uri; }
51 
52  private:
53  std::string _uri;
54 };
55 
57 class PT_SYSTEM_API Uri
58 {
59  public:
60  Uri()
61  : _port(0)
62  , _ipv6(false)
63  { }
64 
65  Uri(const std::string& str);
66 
67  void protocol(const std::string& protocol)
68  { _protocol = protocol; }
69 
70  const std::string& protocol() const
71  { return _protocol; }
72 
73  void user(const std::string& user)
74  { _user = user; }
75 
76  const std::string& user() const
77  { return _user; }
78 
79  void password(const std::string& password)
80  { _password = password; }
81 
82  const std::string& password() const
83  { return _password; }
84 
85  void host(const std::string& host)
86  { _host = host; }
87 
88  const std::string& host() const
89  { return _host; }
90 
91  void port(unsigned short int p)
92  { _port = p; }
93 
94  unsigned short int port() const
95  { return _port; }
96 
97  void path(const std::string& path)
98  { _path = path; }
99 
100  const std::string& path() const
101  { return _path; }
102 
103  void query(const std::string& query)
104  { _query = query; }
105 
106  const std::string& query() const
107  { return _query; }
108 
109  void fragment(const std::string& fragment)
110  { _fragment = fragment; }
111 
112  const std::string& fragment() const
113  { return _fragment; }
114 
115  std::string str() const;
116 
117  private:
118  std::string _protocol;
119  std::string _user;
120  std::string _password;
121  std::string _host;
122  unsigned short int _port;
123  bool _ipv6;
124  std::string _path;
125  std::string _query;
126  std::string _fragment;
127 };
128 
129 } // namespace System
130 
131 } // namespace Pt
132 
133 #endif // Pt_System_Uri_h