Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

ipacl.h

Go to the documentation of this file.
00001 /*
00002  * ipacl.h
00003  *
00004  * IP Access Control Lists
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1998-2002 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Log: ipacl.h,v $
00027  * Revision 1.9  2002/11/06 22:47:24  robertj
00028  * Fixed header comment (copyright etc)
00029  *
00030  * Revision 1.8  2002/07/17 02:54:24  robertj
00031  * Added access functions for member variables.
00032  *
00033  * Revision 1.7  2002/06/19 05:43:17  robertj
00034  * Added missing return for getting default allowance flag
00035  *
00036  * Revision 1.6  2002/06/19 04:02:58  robertj
00037  * Added default allowance boolean if ACL empty.
00038  * Added ability to override the creation of ACL entry objects with descendents
00039  *   so an application can add information/functionality to each entry.
00040  *
00041  * Revision 1.5  2002/02/13 02:07:14  robertj
00042  * Added const to IsAllowed() function
00043  *
00044  * Revision 1.4  1999/03/09 08:01:46  robertj
00045  * Changed comments for doc++ support (more to come).
00046  *
00047  * Revision 1.3  1999/02/25 05:05:15  robertj
00048  * Added missing test for hidden entries not to be written to config file
00049  *
00050  * Revision 1.2  1999/02/08 08:05:39  robertj
00051  * Changed semantics of IP access control list for empty list.
00052  *
00053  * Revision 1.1  1999/01/31 00:59:26  robertj
00054  * Added IP Access Control List class to PTLib Components
00055  *
00056  */
00057 
00058 #ifndef _IPACL_H
00059 #define _IPACL_H
00060 
00061 
00062 #include <ptlib/sockets.h>
00063 
00064 
00067 class PIpAccessControlEntry : public PObject
00068 {
00069   PCLASSINFO(PIpAccessControlEntry, PObject)
00070 
00071   public:
00076     PIpAccessControlEntry(
00077       PIPSocket::Address addr,
00078       PIPSocket::Address msk,
00079       BOOL allow
00080     );
00081     PIpAccessControlEntry(
00082       const PString & description
00083     );
00084 
00089     PIpAccessControlEntry & operator=(
00090       const PString & pstr
00091     );
00092     PIpAccessControlEntry & operator=(
00093       const char * cstr
00094     );
00095 
00102     virtual Comparison Compare(
00103       const PObject & obj   // Object to compare against.
00104     ) const;
00105 
00109     virtual void PrintOn(
00110       ostream &strm   // Stream to print the object into.
00111     ) const;
00112 
00117     virtual void ReadFrom(
00118       istream &strm   // Stream to read the objects contents from.
00119     );
00120 
00127     PString AsString() const;
00128 
00134     BOOL IsValid();
00135 
00155     BOOL Parse(
00156       const PString & description   // Description of the specification
00157     );
00158 
00159 
00166     BOOL Match(
00167       PIPSocket::Address & address    // Address to search for
00168     );
00169 
00172     const PString & GetDomain() const { return domain; }
00173 
00176     const PIPSocket::Address & GetAddress() const { return address; }
00177 
00180     const PIPSocket::Address & GetMask() const { return mask; }
00181 
00184     BOOL IsAllowed() const { return allowed; }
00185 
00188     BOOL IsHidden()  const { return hidden; }
00189 
00190   protected:
00191     PString            domain;
00192     PIPSocket::Address address;
00193     PIPSocket::Address mask;
00194     BOOL               allowed;
00195     BOOL               hidden;
00196 };
00197 
00198 PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry);
00199 
00200 
00214 class PIpAccessControlList : public PIpAccessControlList_base
00215 {
00216 
00217   PCLASSINFO(PIpAccessControlList, PIpAccessControlList_base)
00218 
00219   public:
00222     PIpAccessControlList(
00223       BOOL defaultAllowance = TRUE
00224     );
00225 
00240     BOOL LoadHostsAccess(
00241       const char * daemonName = NULL    // Name of "daemon" application
00242     );
00243 
00251     BOOL Load(
00252       PConfig & cfg   // Configuration file to load entries from.
00253     );
00254 
00264     BOOL Load(
00265       PConfig & cfg,            // Configuration file to load entries from.
00266       const PString & baseName  // Base name string for each entry in file.
00267     );
00268 
00272     void Save(
00273       PConfig & cfg   // Configuration file to save entries to.
00274     );
00275 
00281     void Save(
00282       PConfig & cfg,            // Configuration file to save entries to.
00283       const PString & baseName  // Base name string for each entry in file.
00284     );
00285 
00293     BOOL Add(
00294       PIpAccessControlEntry * entry // Entry for IP match parameters
00295     );
00296     BOOL Add(
00297       const PString & description   // Description of the IP match parameters
00298     );
00299     BOOL Add(
00300       PIPSocket::Address address,   // IP network address
00301       PIPSocket::Address mask,      // Mask for IP network
00302       BOOL allow                    // Flag for if network is allowed or not
00303     );
00304 
00312     BOOL Remove(
00313       const PString & description   // Description of the IP match parameters
00314     );
00315     BOOL Remove(
00316       PIPSocket::Address address,   // IP network address
00317       PIPSocket::Address mask       // Mask for IP network
00318     );
00319 
00320 
00327     virtual PIpAccessControlEntry * CreateControlEntry(
00328       const PString & description
00329     );
00330 
00333     PIpAccessControlEntry * Find(
00334       PIPSocket::Address address    // IP Address to find
00335     ) const;
00336 
00349     BOOL IsAllowed(
00350       PTCPSocket & socket           // Socket to test
00351     ) const;
00352     BOOL IsAllowed(
00353       PIPSocket::Address address    // IP Address to test
00354     ) const;
00355 
00356 
00359     BOOL GetDefaultAllowance() const { return defaultAllowance; }
00360 
00363     void SetDefaultAllowance(BOOL defAllow) { defaultAllowance = defAllow; }
00364 
00365   private:
00366     BOOL InternalLoadHostsAccess(const PString & daemon, const char * file, BOOL allow);
00367     BOOL InternalRemoveEntry(PIpAccessControlEntry & entry);
00368 
00369   protected:
00370     BOOL defaultAllowance;
00371 };
00372 
00373 
00374 #endif  // _IPACL_H
00375 
00376 
00377 // End of File ///////////////////////////////////////////////////////////////

Generated on Wed Sep 28 10:27:33 2005 for PWLib by  doxygen 1.4.4