version 0.3.0
[fms.git] / include / ipaddressacl.h
1 #ifndef _ipaddressacl_\r
2 #define _ipaddressacl_\r
3 \r
4 #include <Poco/Net/IPAddress.h>\r
5 #include <vector>\r
6 #include <string>\r
7 \r
8 class IPAddressACL\r
9 {\r
10 public:\r
11         IPAddressACL();\r
12 \r
13         const bool IsAllowed(const Poco::Net::IPAddress &addr);\r
14         const bool IsAllowed(const std::string &addrstr);\r
15 \r
16         const bool Add(const std::string &aclentry);\r
17 \r
18         void SetAllowByDefault(const bool allowbydefault)       { m_allowbydefault=allowbydefault; }\r
19         const bool GetAllowByDefault() const                            { return m_allowbydefault; }\r
20 \r
21 private:\r
22         const std::string CreateMask(const int maskbits);\r
23 \r
24         // Poco 1.3.0 + has Poco::Net::IPAddress::mask - but 1.2.9 does not\r
25         Poco::Net::IPAddress MaskAddress(const Poco::Net::IPAddress &addr, const Poco::Net::IPAddress &mask);\r
26 \r
27         struct entry\r
28         {\r
29                 entry(const bool allow, const Poco::Net::IPAddress &mask, const Poco::Net::IPAddress &addr):m_allow(allow),m_mask(mask),m_addr(addr)    {}\r
30                 bool m_allow;\r
31                 Poco::Net::IPAddress m_mask;\r
32                 Poco::Net::IPAddress m_addr;\r
33         };\r
34 \r
35         bool m_allowbydefault;  // allow or deny hosts if not explicitly defined\r
36 \r
37         std::vector<entry> m_entries;\r
38 \r
39 };\r
40 \r
41 #endif  // _acl_\r