# 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  * $Revision: 24177 $
    00027  * $Author: rjongbloed $
    00028  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    00029  */
    00030
    00031 #ifndef PTLIB_IPACL_H
    00032 #define PTLIB_IPACL_H
    00033
    00034
    00035 #include <ptlib/sockets.h>
    00036
    00037
    00040 class PIpAccessControlEntry : public PObject
    00041 {
    00042   PCLASSINFO(PIpAccessControlEntry, PObject)
    00043
    00044   public:
    00049     PIpAccessControlEntry(
    00050       PIPSocket::Address addr,
    00051       PIPSocket::Address msk,
    00052       PBoolean allow
    00053     );
    00054     PIpAccessControlEntry(
    00055       const PString & description
    00056     );
    00057
    00062     PIpAccessControlEntry & operator=(
    00063       const PString & pstr
    00064     );
    00065     PIpAccessControlEntry & operator=(
    00066       const char * cstr
    00067     );
    00068
    00075     virtual Comparison Compare(
    00076       const PObject & obj
    00077     ) const;
    00078
    00082     virtual void PrintOn(
    00083       ostream &strm
    00084     ) const;
    00085
    00090     virtual void ReadFrom(
    00091       istream &strm
    00092     );
    00093
    00100     PString AsString() const;
    00101
    00107     PBoolean IsValid();
    00108
    00128     PBoolean Parse(
    00129       const PString & description
    00130     );
    00131
    00132
    00139     PBoolean Match(
    00140       PIPSocket::Address & address
    00141     );
    00142
    00145     const PString & GetDomain() const { return domain; }
    00146
    00149     const PIPSocket::Address & GetAddress() const { return address; }
    00150
    00153     const PIPSocket::Address & GetMask() const { return mask; }
    00154
    00157     PBoolean IsAllowed() const { return allowed; }
    00158
    00161     PBoolean IsHidden()  const { return hidden; }
    00162
    00163   protected:
    00164     PString            domain;
    00165     PIPSocket::Address address;
    00166     PIPSocket::Address mask;
    00167     PBoolean               allowed;
    00168     PBoolean               hidden;
    00169 };
    00170
    00171 PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry);
    00172
    00173
    00187 class PIpAccessControlList : public PIpAccessControlList_base
    00188 {
    00189
    00190   PCLASSINFO(PIpAccessControlList, PIpAccessControlList_base)
    00191
    00192   public:
    00195     PIpAccessControlList(
    00196       PBoolean defaultAllowance = true
    00197     );
    00198
    00213     PBoolean LoadHostsAccess(
    00214       const char * daemonName = NULL
    00215     );
    00216
    00217 #ifdef P_CONFIG_FILE
    00218
    00226     PBoolean Load(
    00227       PConfig & cfg
    00228     );
    00229
    00239     PBoolean Load(
    00240       PConfig & cfg,
    00241       const PString & baseName
    00242     );
    00243
    00247     void Save(
    00248       PConfig & cfg
    00249     );
    00250
    00256     void Save(
    00257       PConfig & cfg,
    00258       const PString & baseName
    00259     );
    00260
    00261 #endif // P_CONFIG_FILE
    00262
    00270     PBoolean Add(
    00271       PIpAccessControlEntry * entry
    00272     );
    00273     PBoolean Add(
    00274       const PString & description
    00275     );
    00276     PBoolean Add(
    00277       PIPSocket::Address address,
    00278       PIPSocket::Address mask,
    00279       PBoolean allow
    00280     );
    00281
    00289     PBoolean Remove(
    00290       const PString & description
    00291     );
    00292     PBoolean Remove(
    00293       PIPSocket::Address address,
    00294       PIPSocket::Address mask
    00295     );
    00296
    00297
    00304     virtual PIpAccessControlEntry * CreateControlEntry(
    00305       const PString & description
    00306     );
    00307
    00310     PIpAccessControlEntry * Find(
    00311       PIPSocket::Address address
    00312     ) const;
    00313
    00326     PBoolean IsAllowed(
    00327       PTCPSocket & socket
    00328     ) const;
    00329     PBoolean IsAllowed(
    00330       PIPSocket::Address address
    00331     ) const;
    00332
    00333
    00336     PBoolean GetDefaultAllowance() const { return defaultAllowance; }
    00337
    00340     void SetDefaultAllowance(PBoolean defAllow) { defaultAllowance = defAllow; }
    00341
    00342   private:
    00343     PBoolean InternalLoadHostsAccess(const PString & daemon, const char * file, PBoolean allow);
    00344     PBoolean InternalRemoveEntry(PIpAccessControlEntry & entry);
    00345
    00346   protected:
    00347     PBoolean defaultAllowance;
    00348 };
    00349
    00350
    00351 #endif  // PTLIB_IPACL_H
    00352
    00353
    00354 // End of File ///////////////////////////////////////////////////////////////