policy.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.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file policy.h
00013 ** \version $Id: policy.h 2362 2008-02-29 04:30:11Z edmanm $
00014 ** \brief Exit policy parsing
00015 */
00016 
00017 #ifndef _POLICY_H
00018 #define _POLICY_H
00019 
00020 #include <QCoreApplication>
00021 #include <QString>
00022 #include <QHostAddress>
00023 
00024 
00025 class Policy
00026 {
00027   Q_DECLARE_TR_FUNCTIONS(Policy)
00028 
00029 public:
00030   /** A set of possible actions for a policy */
00031   enum Action {
00032     Accept, /**< Connections matching this policy will be accepted. */
00033     Reject  /**< Connections matching this policy will be rejected. */
00034   };
00035   /** Special rule types. */
00036   enum SpecialPolicy {
00037     AcceptAll, /**< Accepts all connections. Equivalent to "accept *:*". */
00038     RejectAll  /**< Rejects all connections. Equivalent to "reject *:*". */
00039   };
00040   
00041   /** Default constructor. Creates an AcceptAll policy. */
00042   Policy();
00043   /** Parses the given policy, represented as a string. */
00044   Policy(QString policy);
00045   /** Parses the given portions of a policy string. */
00046   Policy(QString action, QString address, QString ports);
00047   /** Creates a policy of the given special type. */
00048   Policy(SpecialPolicy policy);
00049   /** Creates a policy using the specified information. */
00050   Policy(Action action, QHostAddress addr, uchar mask,
00051          quint16 fromPort, quint16 toPort = 0);
00052 
00053   /** Returns true if this policy matches <b>policy</b>. */
00054   bool matches(const Policy &policy) const;
00055   /** Returns true if this policy is identical to <b>policy</b>. */
00056   bool operator==(const Policy &policy) const;
00057 
00058   /** Parses the given policy string. */
00059   void fromString(QString policy);
00060   /** Converts this policy to a format Tor understands. */
00061   QString toString() const;
00062   /** Converts a string action to an Action enum value. */
00063   static Action toAction(QString action);
00064   
00065   /** Returns the action taken when this policy matches an address. */
00066   QString action() const;
00067   /** Returns the host address (including mask, if set) for this policy. */
00068   QString address() const;
00069   /** Returns the port or port range for this policy. */
00070   QString ports() const;
00071 
00072 private:
00073   Action _action; /**< The action to take for this policy. */
00074   QHostAddress _address; /**< Addresses to which this policy applies. */
00075   quint16 _fromPort;  /**< Start of a port range. */
00076   quint16 _toPort;  /**< End of a port range. */
00077   uchar _mask;  /**< Address mask. */
00078 };
00079 
00080 #endif
00081 

Generated on Wed Dec 23 21:11:09 2009 for Vidalia by  doxygen 1.6.1