addressmap.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If 
00004 **  you did not receive the LICENSE file with this file, you may obtain it
00005 **  from the Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to
00008 **  the terms described in the LICENSE file.
00009 */
00010 
00011 /* 
00012 ** \file addressmap.h
00013 ** \version $Id: bandwidthevent.h 1563 2006-12-26 06:06:04Z edmanm $
00014 ** \brief Stores a list of address mappings and their expiration times
00015 */
00016 
00017 #ifndef _ADDRESSMAP_H
00018 #define _ADDRESSMAP_H
00019 
00020 #include <QHash>
00021 #include <QDateTime>
00022 #include <QPair>
00023 
00024 /** Defines a type that pairs a mapping's target address with an expiration
00025  * time for that mapping. */
00026 typedef QPair<QString, QDateTime> addr_map_entry_t;
00027 
00028 
00029 class AddressMap : public QHash<QString, addr_map_entry_t>
00030 {
00031 public:
00032   /** Types of address mappings. */
00033   enum AddressMapType {
00034     AddressMapAll,    /**< All address mapping types. */
00035     AddressMapConfig, /**< Address mappings set in the torrc. */
00036     AddressMapCache,  /**< Address mappings cached by Tor. */
00037     AddressMapControl /**< Address mappings set by a controller. */
00038   };
00039 
00040   /** Constructor. Creates an empty table for storing address mappinsgs. */
00041   AddressMap()
00042    : QHash<QString, addr_map_entry_t>() {}
00043 
00044   /** Adds a new address mapping or updates an existing one for the address
00045    * specified by <b>from</b>. The mapping will remain valid until the date in
00046    * <b>expires</b>. */
00047   void add(QString from, QString to, QDateTime expires);
00048   /** Adds a new address mapping or updates an existing one based on fields
00049    * parsed from <b>mapping</b>. */
00050   void add(QString mapping);
00051 
00052   /** Returns true if the address map table contains a mapping for <b>addr</b>
00053    * that is not expired. */
00054   bool isMapped(QString addr) const;
00055   
00056   /** Returns the address to which <b>addr</b> is currently mapped. If there
00057    * is no mapping for <b>addr</b> (or the mapping is expired), then an
00058    * empty string is returned. */
00059   QString mappedTo(QString addr) const;
00060 
00061   /** Returns the reverse of this address map. */
00062   AddressMap reverse() const;
00063 
00064 private:
00065   /** Returns true if <b>entry</b> is expired; false otherwise. */
00066   bool isExpired(addr_map_entry_t entry) const;
00067 };
00068 
00069 #endif
00070 

Generated on Tue Jul 7 16:58:26 2009 for Vidalia by  doxygen 1.4.7