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.11  2005/11/30 12:47:37  csoutheren
00028  * Removed tabs, reformatted some code, and changed tags for Doxygen
00029  *
00030  * Revision 1.10  2005/01/26 05:37:42  csoutheren
00031  * Added ability to remove config file support
00032  *
00033  * Revision 1.9  2002/11/06 22:47:24  robertj
00034  * Fixed header comment (copyright etc)
00035  *
00036  * Revision 1.8  2002/07/17 02:54:24  robertj
00037  * Added access functions for member variables.
00038  *
00039  * Revision 1.7  2002/06/19 05:43:17  robertj
00040  * Added missing return for getting default allowance flag
00041  *
00042  * Revision 1.6  2002/06/19 04:02:58  robertj
00043  * Added default allowance boolean if ACL empty.
00044  * Added ability to override the creation of ACL entry objects with descendents
00045  *   so an application can add information/functionality to each entry.
00046  *
00047  * Revision 1.5  2002/02/13 02:07:14  robertj
00048  * Added const to IsAllowed() function
00049  *
00050  * Revision 1.4  1999/03/09 08:01:46  robertj
00051  * Changed comments for doc++ support (more to come).
00052  *
00053  * Revision 1.3  1999/02/25 05:05:15  robertj
00054  * Added missing test for hidden entries not to be written to config file
00055  *
00056  * Revision 1.2  1999/02/08 08:05:39  robertj
00057  * Changed semantics of IP access control list for empty list.
00058  *
00059  * Revision 1.1  1999/01/31 00:59:26  robertj
00060  * Added IP Access Control List class to PTLib Components
00061  *
00062  */
00063 
00064 #ifndef _IPACL_H
00065 #define _IPACL_H
00066 
00067 
00068 #include <ptlib/sockets.h>
00069 
00070 
00073 class PIpAccessControlEntry : public PObject
00074 {
00075   PCLASSINFO(PIpAccessControlEntry, PObject)
00076 
00077   public:
00082     PIpAccessControlEntry(
00083       PIPSocket::Address addr,
00084       PIPSocket::Address msk,
00085       BOOL allow
00086     );
00087     PIpAccessControlEntry(
00088       const PString & description
00089     );
00090 
00095     PIpAccessControlEntry & operator=(
00096       const PString & pstr
00097     );
00098     PIpAccessControlEntry & operator=(
00099       const char * cstr
00100     );
00101 
00108     virtual Comparison Compare(
00109       const PObject & obj   
00110     ) const;
00111 
00115     virtual void PrintOn(
00116       ostream &strm   
00117     ) const;
00118 
00123     virtual void ReadFrom(
00124       istream &strm   
00125     );
00126 
00133     PString AsString() const;
00134 
00140     BOOL IsValid();
00141 
00161     BOOL Parse(
00162       const PString & description   
00163     );
00164 
00165 
00172     BOOL Match(
00173       PIPSocket::Address & address    
00174     );
00175 
00178     const PString & GetDomain() const { return domain; }
00179 
00182     const PIPSocket::Address & GetAddress() const { return address; }
00183 
00186     const PIPSocket::Address & GetMask() const { return mask; }
00187 
00190     BOOL IsAllowed() const { return allowed; }
00191 
00194     BOOL IsHidden()  const { return hidden; }
00195 
00196   protected:
00197     PString            domain;
00198     PIPSocket::Address address;
00199     PIPSocket::Address mask;
00200     BOOL               allowed;
00201     BOOL               hidden;
00202 };
00203 
00204 PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry);
00205 
00206 
00220 class PIpAccessControlList : public PIpAccessControlList_base
00221 {
00222 
00223   PCLASSINFO(PIpAccessControlList, PIpAccessControlList_base)
00224 
00225   public:
00228     PIpAccessControlList(
00229       BOOL defaultAllowance = TRUE
00230     );
00231 
00246     BOOL LoadHostsAccess(
00247       const char * daemonName = NULL    
00248     );
00249 
00250 #ifdef P_CONFIG_FILE
00251 
00259     BOOL Load(
00260       PConfig & cfg   
00261     );
00262 
00272     BOOL Load(
00273       PConfig & cfg,            
00274       const PString & baseName  
00275     );
00276 
00280     void Save(
00281       PConfig & cfg   
00282     );
00283 
00289     void Save(
00290       PConfig & cfg,            
00291       const PString & baseName  
00292     );
00293 
00294 #endif // P_CONFIG_FILE
00295 
00303     BOOL Add(
00304       PIpAccessControlEntry * entry 
00305     );
00306     BOOL Add(
00307       const PString & description   
00308     );
00309     BOOL Add(
00310       PIPSocket::Address address,   
00311       PIPSocket::Address mask,      
00312       BOOL allow                    
00313     );
00314 
00322     BOOL Remove(
00323       const PString & description   
00324     );
00325     BOOL Remove(
00326       PIPSocket::Address address,   
00327       PIPSocket::Address mask       
00328     );
00329 
00330 
00337     virtual PIpAccessControlEntry * CreateControlEntry(
00338       const PString & description
00339     );
00340 
00343     PIpAccessControlEntry * Find(
00344       PIPSocket::Address address    
00345     ) const;
00346 
00359     BOOL IsAllowed(
00360       PTCPSocket & socket           
00361     ) const;
00362     BOOL IsAllowed(
00363       PIPSocket::Address address    
00364     ) const;
00365 
00366 
00369     BOOL GetDefaultAllowance() const { return defaultAllowance; }
00370 
00373     void SetDefaultAllowance(BOOL defAllow) { defaultAllowance = defAllow; }
00374 
00375   private:
00376     BOOL InternalLoadHostsAccess(const PString & daemon, const char * file, BOOL allow);
00377     BOOL InternalRemoveEntry(PIpAccessControlEntry & entry);
00378 
00379   protected:
00380     BOOL defaultAllowance;
00381 };
00382 
00383 
00384 #endif  // _IPACL_H
00385 
00386 
00387 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1