addressmap.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2007,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020   ****************************************************************/
00021 
00022 /** 
00023  * \file addressmap.h
00024  * \version $Id: bandwidthevent.h 1563 2006-12-26 06:06:04Z edmanm $
00025  * \brief Stores a list of address mappings and their expiration times
00026  */
00027 
00028 #ifndef _ADDRESSMAP_H
00029 #define _ADDRESSMAP_H
00030 
00031 #include <QHash>
00032 #include <QDateTime>
00033 #include <QPair>
00034 
00035 /** Defines a type that pairs a mapping's target address with an expiration
00036  * time for that mapping. */
00037 typedef QPair<QString, QDateTime> addr_map_entry_t;
00038 
00039 
00040 class AddressMap : public QHash<QString, addr_map_entry_t>
00041 {
00042 public:
00043   /** Types of address mappings. */
00044   enum AddressMapType {
00045     AddressMapAll,    /**< All address mapping types. */
00046     AddressMapConfig, /**< Address mappings set in the torrc. */
00047     AddressMapCache,  /**< Address mappings cached by Tor. */
00048     AddressMapControl /**< Address mappings set by a controller. */
00049   };
00050 
00051   /** Constructor. Creates an empty table for storing address mappinsgs. */
00052   AddressMap()
00053    : QHash<QString, addr_map_entry_t>() {}
00054 
00055   /** Adds a new address mapping or updates an existing one for the address
00056    * specified by <b>from</b>. The mapping will remain valid until the date in
00057    * <b>expires</b>. */
00058   void add(QString from, QString to, QDateTime expires);
00059   /** Adds a new address mapping or updates an existing one based on fields
00060    * parsed from <b>mapping</b>. */
00061   void add(QString mapping);
00062 
00063   /** Returns true if the address map table contains a mapping for <b>addr</b>
00064    * that is not expired. */
00065   bool isMapped(QString addr) const;
00066   
00067   /** Returns the address to which <b>addr</b> is currently mapped. If there
00068    * is no mapping for <b>addr</b> (or the mapping is expired), then an
00069    * empty string is returned. */
00070   QString mappedTo(QString addr) const;
00071 
00072   /** Returns the reverse of this address map. */
00073   AddressMap reverse() const;
00074 
00075 private:
00076   /** Returns true if <b>entry</b> is expired; false otherwise. */
00077   bool isExpired(addr_map_entry_t entry) const;
00078 };
00079 
00080 #endif
00081 

Generated on Wed Sep 5 15:49:27 2007 for Vidalia by  doxygen 1.5.3