All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ipacl.h
Go to the documentation of this file.
/*
* ipacl.h
*
* IP Access Control Lists
*
* Portable Windows Library
*
* Copyright (c) 1998-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_IPACL_H
#define PTLIB_IPACL_H
#include <ptlib/sockets.h>
class PIpAccessControlEntry : public PObject
{
PCLASSINFO(PIpAccessControlEntry, PObject)
public:
PIpAccessControlEntry(
PIPSocket::Address addr,
PIPSocket::Address msk,
PBoolean allow
);
PIpAccessControlEntry(
const PString & description
);
PIpAccessControlEntry & operator=(
const PString & pstr
);
PIpAccessControlEntry & operator=(
const char * cstr
);
virtual Comparison Compare(
const PObject & obj
) const;
virtual void PrintOn(
ostream &strm
) const;
virtual void ReadFrom(
istream &strm
);
PString AsString() const;
PBoolean IsValid();
PBoolean Parse(
const PString & description
);
PBoolean Match(
PIPSocket::Address & address
);
const PString & GetDomain() const { return domain; }
const PIPSocket::Address & GetAddress() const { return address; }
const PIPSocket::Address & GetMask() const { return mask; }
PBoolean IsAllowed() const { return allowed; }
PBoolean IsHidden() const { return hidden; }
protected:
PString domain;
PIPSocket::Address address;
PIPSocket::Address mask;
PBoolean allowed;
PBoolean hidden;
};
PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry);
class PIpAccessControlList : public PIpAccessControlList_base
{
PCLASSINFO(PIpAccessControlList, PIpAccessControlList_base)
public:
PIpAccessControlList(
PBoolean defaultAllowance = true
);
PBoolean LoadHostsAccess(
const char * daemonName = NULL
);
#ifdef P_CONFIG_FILE
PBoolean Load(
PConfig & cfg
);
PBoolean Load(
PConfig & cfg,
const PString & baseName
);
void Save(
PConfig & cfg
);
void Save(
PConfig & cfg,
const PString & baseName
);
#endif // P_CONFIG_FILE
PBoolean Add(
PIpAccessControlEntry * entry
);
PBoolean Add(
const PString & description
);
PBoolean Add(
PIPSocket::Address address,
PIPSocket::Address mask,
PBoolean allow
);
PBoolean Remove(
const PString & description
);
PBoolean Remove(
PIPSocket::Address address,
PIPSocket::Address mask
);
virtual PIpAccessControlEntry * CreateControlEntry(
const PString & description
);
PIpAccessControlEntry * Find(
PIPSocket::Address address
) const;
PBoolean IsAllowed(
PTCPSocket & socket
) const;
PBoolean IsAllowed(
PIPSocket::Address address
) const;
PBoolean GetDefaultAllowance() const { return defaultAllowance; }
void SetDefaultAllowance(PBoolean defAllow) { defaultAllowance = defAllow; }
private:
PBoolean InternalLoadHostsAccess(const PString & daemon, const char * file, PBoolean allow);
PBoolean InternalRemoveEntry(PIpAccessControlEntry & entry);
protected:
PBoolean defaultAllowance;
};
#endif // PTLIB_IPACL_H
// End of File ///////////////////////////////////////////////////////////////
PIpAccessControlList::SetDefaultAllowance
void SetDefaultAllowance(PBoolean defAllow)
Set the default state for allowed access if the list is empty.
Definition: ipacl.h:340
PIpAccessControlEntry::ReadFrom
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PIpAccessControlEntry::IsAllowed
PBoolean IsAllowed() const
Get the allowed flag of entry.
Definition: ipacl.h:157
PIpAccessControlEntry::allowed
PBoolean allowed
Definition: ipacl.h:167
PIpAccessControlEntry::address
PIPSocket::Address address
Definition: ipacl.h:165
PIpAccessControlEntry::Compare
virtual Comparison Compare(const PObject &obj) const
Compare the two objects and return their relative rank.
PIpAccessControlEntry::mask
PIPSocket::Address mask
Definition: ipacl.h:166
PIpAccessControlList::IsAllowed
PBoolean IsAllowed(PTCPSocket &socket) const
Test the address/connection for if it is allowed within this access control list. ...
PConfig
A class representing a configuration for the application.
Definition: config.h:67
PObject::Comparison
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PIpAccessControlEntry::Parse
PBoolean Parse(const PString &description)
Parse the description string into this IP access control specification.
PIpAccessControlList::Find
PIpAccessControlEntry * Find(PIPSocket::Address address) const
Find the PIpAccessControl specification for the address.
PIpAccessControlList::LoadHostsAccess
PBoolean LoadHostsAccess(const char *daemonName=NULL)
Load the system wide files commonly use under Linux (hosts.allow and hosts.deny file) for IP access...
PIpAccessControlEntry::PrintOn
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
PIpAccessControlList::CreateControlEntry
virtual PIpAccessControlEntry * CreateControlEntry(const PString &description)
Create a new PIpAccessControl specification entry object.
PIpAccessControlEntry::GetAddress
const PIPSocket::Address & GetAddress() const
Get the address part of entry.
Definition: ipacl.h:149
PIpAccessControlList::Remove
PBoolean Remove(const PString &description)
Remove the specified entry into the list.
PBoolean
BOOL PBoolean
Definition: object.h:102
PIpAccessControlList::Add
PBoolean Add(PIpAccessControlEntry *entry)
Add the specified entry into the list.
PIpAccessControlList::PIpAccessControlList
PIpAccessControlList(PBoolean defaultAllowance=true)
Create a new, empty, access control list.
PIpAccessControlList::Save
void Save(PConfig &cfg)
Save entries in the list to the configuration file specified.
PIpAccessControlEntry::IsHidden
PBoolean IsHidden() const
Get the hidden flag of entry.
Definition: ipacl.h:161
PIpAccessControlEntry::AsString
PString AsString() const
Convert the specification to a string, that can be processed by the Parse() function.
PString
The character string class.
Definition: pstring.h:108
PTCPSocket
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
PIpAccessControlEntry
This class is a single IP access control specification.
Definition: ipacl.h:40
PIpAccessControlList
This class is a list of IP address mask specifications used to validate if an address may or may not ...
Definition: ipacl.h:187
PIpAccessControlEntry::PIpAccessControlEntry
PIpAccessControlEntry(PIPSocket::Address addr, PIPSocket::Address msk, PBoolean allow)
Create a new IP access control specification.
PIpAccessControlEntry::GetMask
const PIPSocket::Address & GetMask() const
Get the mask part of entry.
Definition: ipacl.h:153
PIPSocket::Address
A class describing an IP address.
Definition: ipsock.h:75
PIpAccessControlEntry::domain
PString domain
Definition: ipacl.h:164
PIpAccessControlList::defaultAllowance
PBoolean defaultAllowance
Definition: ipacl.h:347
PIpAccessControlEntry::Match
PBoolean Match(PIPSocket::Address &address)
Check to see if the specified IP address match any of the conditions specifed in the Parse() function...
sockets.h
PIpAccessControlEntry::IsValid
PBoolean IsValid()
Check the internal fields of the specification for validity.
PIpAccessControlEntry::GetDomain
const PString & GetDomain() const
Get the domain part of entry.
Definition: ipacl.h:145
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PIpAccessControlList::Load
PBoolean Load(PConfig &cfg)
Load entries in the list from the configuration file specified.
PIpAccessControlEntry::operator=
PIpAccessControlEntry & operator=(const PString &pstr)
Set a new IP access control specification.
PIpAccessControlList::GetDefaultAllowance
PBoolean GetDefaultAllowance() const
Get the default state for allowed access if the list is empty.
Definition: ipacl.h:336
PIpAccessControlEntry::hidden
PBoolean hidden
Definition: ipacl.h:168
PSORTED_LIST
PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry)