Line data Source code
1 : // Snap Websites Servers -- HTTP link handling (outgoing)
2 : // Copyright (c) 2013-2019 Made to Order Software Corp. All Rights Reserved
3 : //
4 : // This program is free software; you can redistribute it and/or modify
5 : // it under the terms of the GNU General Public License as published by
6 : // the Free Software Foundation; either version 2 of the License, or
7 : // (at your option) any later version.
8 : //
9 : // This program is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : // GNU General Public License for more details.
13 : //
14 : // You should have received a copy of the GNU General Public License
15 : // along with this program; if not, write to the Free Software
16 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 : #pragma once
18 :
19 : // libsnapwebsites
20 : //
21 : #include "snapwebsites/snap_exception.h"
22 :
23 : // C++
24 : //
25 : #include <map>
26 :
27 :
28 : namespace snap
29 : {
30 :
31 0 : class http_link_exception : public snap_exception
32 : {
33 : public:
34 0 : http_link_exception(char const * what_msg) : snap_exception("http_link", what_msg) {}
35 : http_link_exception(std::string const & what_msg) : snap_exception("http_link", what_msg) {}
36 : http_link_exception(QString const & what_msg) : snap_exception("http_link", what_msg) {}
37 : };
38 :
39 :
40 0 : class http_link_parse_exception : public http_link_exception
41 : {
42 : public:
43 0 : http_link_parse_exception(char const * what_msg) : http_link_exception(what_msg) {}
44 : http_link_parse_exception(std::string const & what_msg) : http_link_exception(what_msg) {}
45 : http_link_parse_exception(QString const & what_msg) : http_link_exception(what_msg) {}
46 : };
47 :
48 :
49 0 : class http_link_parameter_exception : public http_link_exception
50 : {
51 : public:
52 0 : http_link_parameter_exception(char const * what_msg) : http_link_exception(what_msg) {}
53 : http_link_parameter_exception(std::string const & what_msg) : http_link_exception(what_msg) {}
54 : http_link_parameter_exception(QString const & what_msg) : http_link_exception(what_msg) {}
55 : };
56 :
57 :
58 :
59 : class snap_child;
60 :
61 : #pragma GCC diagnostic push
62 : #pragma GCC diagnostic ignored "-Weffc++"
63 0 : class http_link
64 : {
65 : public:
66 : typedef std::map<std::string, http_link> map_t;
67 : typedef std::map<std::string, std::string> param_t;
68 :
69 : // define a default http_link() because of map_t
70 : http_link();
71 :
72 : http_link(snap_child * snap, std::string const & link, std::string const & rel);
73 :
74 : std::string get_name() const;
75 :
76 : void set_redirect(bool redirect = true);
77 : bool get_redirect() const;
78 :
79 : void add_param(std::string const & name, std::string const & value);
80 :
81 : bool has_param(std::string const & name) const;
82 : std::string get_param(std::string const & name) const;
83 :
84 : param_t const & get_params() const;
85 :
86 : std::string to_http_header() const;
87 :
88 : private:
89 : snap_child * f_snap = nullptr; // the snap child that created this link
90 : std::string f_link = std::string(); // this link URI
91 : std::string f_rel = std::string(); // rel attribute, a.k.a. link name
92 : bool f_redirect = false; // whether to include this link in a redirect header
93 : param_t f_params = param_t(); // other attributes
94 : };
95 : #pragma GCC diagnostic pop
96 :
97 :
98 :
99 : } // namespace snap
100 : // vim: ts=4 sw=4 et
|