root/uri.hh

Revision 43f521291669f483d361949fa6c886c0fbd94daf, 2.4 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 21 months ago)

Add support for paginating thread and article lists.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_URI_HH
21#define GUARD_URI_HH
22
23#include <string>
24
25class uri
26{
27public:
28        class invalid : public std::exception
29        {
30                static const char msgprefix[];
31                const std::string msg;
32        public:
33                invalid() : msg(msgprefix) {}
34                invalid(std::string msg)
35                        : msg(std::string(msgprefix) + ": " + msg)
36                        {}
37                ~invalid() throw () {}
38                const char *what() const throw () { return msg.c_str(); }
39        };
40
41        uri() : port(-1) {}
42        uri(std::string str);
43
44        static std::string percent_decode(std::string);
45
46        // note! does not encode the solidus ('/')
47        static std::string percent_encode(std::string);
48
49
50        // none of these has been percent-decoded
51        std::string get_scheme() const { return scheme; }
52        std::string get_userinfo() const { return userinfo; }
53        std::string get_host() const { return host; }
54        int get_port() const { return port; } // -1 means missing
55        std::string get_path() const { return path; }
56        std::string get_query() const { return query; }
57
58        std::string get_query_param(std::string name) const;
59        void replace_query_param(std::string name, std::string new_value);
60        void replace_query_param(std::string name, int new_value);
61        void remove_query_param(std::string name);
62
63        std::string to_string() const;
64
65private:
66        std::string scheme;
67        std::string userinfo;
68        std::string host;
69        int port; /* missing port is -1 */
70        std::string path;
71        std::string query;
72};
73
74#endif /* GUARD_URI_HH */
Note: See TracBrowser for help on using the browser.