version 0.3.0
[fms.git] / include / ipaddressacl.h
diff --git a/include/ipaddressacl.h b/include/ipaddressacl.h
new file mode 100644 (file)
index 0000000..100392d
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _ipaddressacl_\r
+#define _ipaddressacl_\r
+\r
+#include <Poco/Net/IPAddress.h>\r
+#include <vector>\r
+#include <string>\r
+\r
+class IPAddressACL\r
+{\r
+public:\r
+       IPAddressACL();\r
+\r
+       const bool IsAllowed(const Poco::Net::IPAddress &addr);\r
+       const bool IsAllowed(const std::string &addrstr);\r
+\r
+       const bool Add(const std::string &aclentry);\r
+\r
+       void SetAllowByDefault(const bool allowbydefault)       { m_allowbydefault=allowbydefault; }\r
+       const bool GetAllowByDefault() const                            { return m_allowbydefault; }\r
+\r
+private:\r
+       const std::string CreateMask(const int maskbits);\r
+\r
+       // Poco 1.3.0 + has Poco::Net::IPAddress::mask - but 1.2.9 does not\r
+       Poco::Net::IPAddress MaskAddress(const Poco::Net::IPAddress &addr, const Poco::Net::IPAddress &mask);\r
+\r
+       struct entry\r
+       {\r
+               entry(const bool allow, const Poco::Net::IPAddress &mask, const Poco::Net::IPAddress &addr):m_allow(allow),m_mask(mask),m_addr(addr)    {}\r
+               bool m_allow;\r
+               Poco::Net::IPAddress m_mask;\r
+               Poco::Net::IPAddress m_addr;\r
+       };\r
+\r
+       bool m_allowbydefault;  // allow or deny hosts if not explicitly defined\r
+\r
+       std::vector<entry> m_entries;\r
+\r
+};\r
+\r
+#endif // _acl_\r