bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
AllowedHosts.h
1// AllowedHosts.h
2
3// -*- mode: c++; c-basic-offset:4 -*-
4
5// This file is part of the OPeNDAP Back-End Server (BES)
6// and creates a set of allowed hosts that may be
7// accessed by the server as part of its routine operation.
8
9// Copyright (c) 2018 OPeNDAP, Inc.
10// Author: Nathan D. Potter <ndp@opendap.org>
11//
12// This library is free software; you can redistribute it and/or
13// modify it under the terms of the GNU Lesser General Public
14// License as published by the Free Software Foundation; either
15// version 2.1 of the License, or (at your option) any later version.
16//
17// This library is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20// Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public
23// License along with this library; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25//
26// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27
28// Authors:
29// ndp Nathan D. Potter <ndp@opendap.org>
30
31#ifndef I_AllowedHosts_H
32#define I_AllowedHosts_H 1
33
34#include <string>
35#include <vector>
36
37#include "url_impl.h"
38
39#define ALLOWED_HOSTS_BES_KEY "AllowedHosts"
40
41namespace http {
42
53class AllowedHosts {
54private:
55 std::vector<std::string> d_allowed_hosts;
56
57 bool check(const std::string &url) const;
58
59 // Private constructor to prevent direct instantiation
60 AllowedHosts();
61public:
62 AllowedHosts(const AllowedHosts &) = delete;
63 AllowedHosts &operator=(const AllowedHosts &) = delete;
64
65 virtual ~AllowedHosts() = default;
66
67 // Static member function that returns the pointer to the singleton instance
68 static AllowedHosts *theHosts();
69
70 bool is_allowed(const http::url &candidate_url);
71 bool is_allowed(const http::url &candidate_url, std::string &whynot);
72
73 bool is_allowed(const std::shared_ptr<http::url> &candidate_url);
74 bool is_allowed(const std::shared_ptr<http::url> &candidate_url, std::string &whynot);
75};
76
77} // namespace bes
78
79#endif // I_AllowedHosts_H
80
Parse a URL into the protocol, host, path and query parts.
Definition url_impl.h:44
utility class for the HTTP catalog module
Definition TheBESKeys.h:51