range_limiter.h

Go to the documentation of this file.
00001 #ifndef ADDRESS_LIMITER_CLASS
00002 #define ADDRESS_LIMITER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : range_limiter                                                     *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Provides a way to check whether an IP address is within a range of       *
00012 *  allowed addresses.  Also manages a configuration file that stores the      *
00013 *  sets of ranges.                                                            *
00014 *                                                                             *
00015 *******************************************************************************
00016 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00017 * redistribute it and/or modify it under the terms of the GNU General Public  *
00018 * License as published by the Free Software Foundation; either version 2 of   *
00019 * the License or (at your option) any later version.  This is online at:      *
00020 *     http://www.fsf.org/copyleft/gpl.html                                    *
00021 * Please send any updates to: fred@gruntose.com                               *
00022 \*****************************************************************************/
00023 
00024 // forward.
00025 class limiter_range_list;
00026 class machine_uid;
00027 
00028 #include "sockets_dll.h"
00029 
00030 class SOCKETS_CLASS_STYLE range_limiter
00031 {
00032 public:
00033   range_limiter();
00034     // constructs a blank range_limiter.
00035 
00036   range_limiter(const istring &source_file, const istring &section);
00037     // constructs an range_limiter by loading from the "source_file" in
00038     // the ini "section".
00039 
00040   ~range_limiter();
00041 
00042   enum capabilities {
00043     ALLOW,
00044     DENY
00045   };
00046 
00047   bool is_allowed(const machine_uid &host);
00048     // checks whether a "host" is in one of the allowed ranges.
00049   bool is_allowed(const istring &hostname);
00050     // checks whether a "hostname" is in one of the allowed ranges.  this can
00051     // either be a text string such as "jumbo.gruntose.blurgh" or it can be
00052     // a dotted number representation (like "128.28.48.119").
00053 
00054   // observes or modifies the default access permission.  the default will
00055   // be used when no other permissions apply.
00056   capabilities get_default();
00057   void set_default(capabilities rights);
00058 
00059   // these add addresses to the list with the "rights" specified.
00060   bool add(const machine_uid &address, capabilities rights);
00061   bool add(const istring &hostname, capabilities rights);
00062   bool add(const machine_uid &first, const machine_uid &second,
00063           capabilities rights);
00064 
00065   // takes addresses out of the list of filters.
00066   bool remove(const machine_uid &address);
00067   bool remove(const istring &hostname);
00068   bool remove(const machine_uid &first, const machine_uid &second);
00069 
00070   // retrieves or stores the range and capability information.
00071   bool load(const istring &file_name, const istring &section);
00072   bool save(const istring &file_name, const istring &section);
00073 
00074 private:
00075   limiter_range_list *_ranges;
00076 };
00077 
00078 #endif
00079 

Generated on Fri Nov 28 04:28:56 2008 for HOOPLE Libraries by  doxygen 1.5.1