Vidalia  0.2.21
AddressMap.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If
4 ** you did not receive the LICENSE file with this file, you may obtain it
5 ** from the Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file AddressMap.h
13 ** \brief Stores a list of address mappings and their expiration times
14 */
15 
16 #ifndef _ADDRESSMAP_H
17 #define _ADDRESSMAP_H
18 
19 #include <QHash>
20 #include <QDateTime>
21 #include <QPair>
22 
23 /** Defines a type that pairs a mapping's target address with an expiration
24  * time for that mapping. */
25 typedef QPair<QString, QDateTime> AddressMapEntry;
26 
27 
28 class AddressMap : public QHash<QString, AddressMapEntry>
29 {
30 public:
31  /** Types of address mappings. */
33  AddressMapAll, /**< All address mapping types. */
34  AddressMapConfig, /**< Address mappings set in the torrc. */
35  AddressMapCache, /**< Address mappings cached by Tor. */
36  AddressMapControl /**< Address mappings set by a controller. */
37  };
38 
39  /** Constructor. Creates an empty table for storing address mappinsgs. */
41  : QHash<QString, AddressMapEntry>() {}
42 
43  /** Adds a new address mapping or updates an existing one for the address
44  * specified by <b>from</b>. The mapping will remain valid until the date in
45  * <b>expires</b>. */
46  void add(const QString &from, const QString &to, const QDateTime &expires);
47  /** Adds a new address mapping or updates an existing one based on fields
48  * parsed from <b>mapping</b>. */
49  void add(const QString &mapping);
50 
51  /** Returns true if the address map table contains a mapping for <b>addr</b>
52  * that is not expired. */
53  bool isMapped(const QString &addr) const;
54 
55  /** Returns the address to which <b>addr</b> is currently mapped. If there
56  * is no mapping for <b>addr</b> (or the mapping is expired), then an
57  * empty string is returned. */
58  QString mappedTo(const QString &addr) const;
59 
60  /** Returns the reverse of this address map. */
61  AddressMap reverse() const;
62 
63 private:
64  /** Returns true if <b>entry</b> is expired; false otherwise. */
65  bool isExpired(const AddressMapEntry &entry) const;
66 };
67 
68 #endif
69