Wolframe, 0.0.3

addressRestriction.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _Wolframe_TYPES_ADDRESS_RESTRICTION_HPP_INCLUDED
37 #define _Wolframe_TYPES_ADDRESS_RESTRICTION_HPP_INCLUDED
38 #include <vector>
39 #include <boost/asio/ip/address.hpp>
40 #include <boost/cstdint.hpp>
41 
42 namespace _Wolframe {
43 namespace types {
44 
48 {
49 public:
55 
57  void defineAddressAllowed( const std::string& adr);
59  void defineAddressDenied( const std::string& adr);
61  void defineAllowedAll();
63  void defineDeniedAll();
64 
66  bool isAllowed( const boost::asio::ip::address& adr) const;
67 
69  std::string tostring() const;
70 
71 public:
72  typedef boost::asio::ip::address IPAddress;
73 
76  struct Element
77  {
79  boost::uint8_t netMask;
80 
81  Element( const Element& o)
82  :ip(o.ip),netMask(o.netMask){}
84  :ip(),netMask(0){}
85  };
86 
87 private:
88  static Element parseAddress( const std::string& adr);
89  static boost::uint8_t parseNetworkMask( bool isIPv6, const char* str);
90  static bool matches( const std::vector<Element>& ar, const IPAddress& addr);
91 
92 private:
93  std::vector<Element> m_allowedar;
94  std::vector<Element> m_deniedar;
95 };
96 
97 }}//namespace
98 #endif
Structure to define and check configured ip based authorization.
Definition: addressRestriction.hpp:47
static boost::uint8_t parseNetworkMask(bool isIPv6, const char *str)
static bool matches(const std::vector< Element > &ar, const IPAddress &addr)
boost::asio::ip::address IPAddress
Definition: addressRestriction.hpp:72
AddressRestriction()
Default constructor.
Definition: addressRestriction.hpp:51
bool isAllowed(const boost::asio::ip::address &adr) const
Check if an address belongs to the set of allowed.
Element(const Element &o)
Definition: addressRestriction.hpp:81
void defineAddressAllowed(const std::string &adr)
Define an explicitely allowed address.
One element of a list of address restrictions (deny or allow)
Definition: addressRestriction.hpp:76
std::string tostring() const
Get all the restriction definitions defined in this structure as string.
IPAddress ip
Definition: addressRestriction.hpp:78
AddressRestriction(const AddressRestriction &o)
Copy constructor.
Definition: addressRestriction.hpp:53
Element()
Definition: addressRestriction.hpp:83
boost::uint8_t netMask
Definition: addressRestriction.hpp:79
void defineAllowedAll()
Define all addresses as allowed.
std::vector< Element > m_allowedar
array of allowed addresses/networks
Definition: addressRestriction.hpp:93
void defineDeniedAll()
Define all addresses as denied.
std::vector< Element > m_deniedar
array of denied addresses/networks
Definition: addressRestriction.hpp:94
static Element parseAddress(const std::string &adr)
void defineAddressDenied(const std::string &adr)
Define an explicitely denied address.