1 | #pragma once |
2 | |
3 | #include <vector> |
4 | #include <unordered_set> |
5 | #include <Poco/URI.h> |
6 | #include <Poco/Util/AbstractConfiguration.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | class RemoteHostFilter |
12 | { |
13 | /** |
14 | * This class checks if url is allowed. |
15 | * If primary_hosts and regexp_hosts are empty all urls are allowed. |
16 | */ |
17 | public: |
18 | void checkURL(const Poco::URI & uri) const; /// If URL not allowed in config.xml throw UNACCEPTABLE_URL Exception |
19 | |
20 | void setValuesFromConfig(const Poco::Util::AbstractConfiguration & config); |
21 | |
22 | void checkHostAndPort(const std::string & host, const std::string & port) const; /// Does the same as checkURL, but for host and port. |
23 | |
24 | private: |
25 | std::unordered_set<std::string> primary_hosts; /// Allowed primary (<host>) URL from config.xml |
26 | std::vector<std::string> regexp_hosts; /// Allowed regexp (<hots_regexp>) URL from config.xml |
27 | |
28 | bool checkForDirectEntry(const std::string & str) const; /// Checks if the primary_hosts and regexp_hosts contain str. If primary_hosts and regexp_hosts are empty return true. |
29 | }; |
30 | } |
31 | |