Vidalia  0.2.17
ExitPolicy.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 you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file ExitPolicy.h
00013 ** \brief Collection of Policy objects representing an exit policy
00014 */
00015 
00016 #ifndef _EXITPOLICY_H
00017 #define _EXITPOLICY_H
00018 
00019 #include "Policy.h"
00020 
00021 #include <QList>
00022 #include <QString>
00023 #include <QStringList>
00024 
00025 
00026 class ExitPolicy
00027 {
00028 public:
00029   /** Special exit policy types. */
00030   enum SpecialExitPolicy {
00031     Default,  /**< Specifies the default exit policy. */
00032     Middleman /**< Specifies a middleman-only exit policy. */
00033   };
00034   
00035   /** Default constructor. */
00036   ExitPolicy();
00037   /** Creates an exit policy of the given special type. */
00038   ExitPolicy(SpecialExitPolicy exitPolicy);
00039   /** Creates an exit policy from the given comma-delimited list of policies. */
00040   ExitPolicy(QString exitPolicy);
00041   
00042   /** Adds the ports specified in <b>portList</b> to a list of ports accepted
00043    * by this exit policy. Ports may be given either individually or as ranges. */
00044   void addAcceptedPorts(QStringList portList);
00045   /** Returns true if this exit policy accepts all ports specified in
00046    * <b>portList</b>. Ports in <b>portList</b> may be given either individually
00047    * or as ranges. */
00048   bool acceptsPorts(QStringList portList);
00049   /** Adds the ports specified in <b>portList</b> to a list of ports rejected
00050    * by this exit policy. Ports may be given either individually or as ranges. */
00051   void addRejectedPorts(QStringList portList);
00052   /** Returns true if this exit policy rejects all ports specified in
00053    * <b>portList</b>. Ports in <b>portList</b> may be given either individually
00054    * or as ranges. */
00055   bool rejectsPorts(QStringList portList);
00056   
00057   /** Adds a rule to the exit policy. */
00058   void addPolicy(Policy policy);
00059   /** Removes a rule from the exit policy. */
00060   void removePolicy(Policy policy);
00061   /** Checks if the current exit policy contains the given rule. */
00062   bool contains(Policy policy);
00063 
00064   /** Returns the list of policies for this exit policy. */
00065   QList<Policy> policyList() { return  _exitPolicy; }
00066   
00067   /** Converts the exit policy to a format Tor understands. */  
00068   QString toString();
00069   
00070 private:
00071   /** A collection of policies forming the exit policy. */
00072   QList<Policy> _exitPolicy;
00073 };
00074 
00075 #endif
00076