policy.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  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 policy.h
00024  * \version $Id: policy.h 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief Exit policy parsing
00026  */
00027 
00028 #ifndef _POLICY_H
00029 #define _POLICY_H
00030 
00031 #include <QCoreApplication>
00032 #include <QString>
00033 #include <QHostAddress>
00034 
00035 
00036 class Policy
00037 {
00038   Q_DECLARE_TR_FUNCTIONS(Policy)
00039 
00040 public:
00041   /** A set of possible actions for a policy */
00042   enum Action {
00043     Accept, /**< Connections matching this policy will be accepted. */
00044     Reject  /**< Connections matching this policy will be rejected. */
00045   };
00046   /** Special rule types. */
00047   enum SpecialPolicy {
00048     AcceptAll, /**< Accepts all connections. Equivalent to "accept *:*". */
00049     RejectAll  /**< Rejects all connections. Equivalent to "reject *:*". */
00050   };
00051   
00052   /** Default constructor. Creates an AcceptAll policy. */
00053   Policy();
00054   /** Parses the given policy, represented as a string. */
00055   Policy(QString policy);
00056   /** Parses the given portions of a policy string. */
00057   Policy(QString action, QString address, QString ports);
00058   /** Creates a policy of the given special type. */
00059   Policy(SpecialPolicy policy);
00060   /** Creates a policy using the specified information. */
00061   Policy(Action action, QHostAddress addr, uchar mask,
00062          quint16 fromPort, quint16 toPort = 0);
00063  
00064   /** Overloads the == operator. */
00065   bool operator==(const Policy &policy) const;
00066 
00067   /** Parses the given policy string. */
00068   void fromString(QString policy);
00069   /** Converts this policy to a format Tor understands. */
00070   QString toString();
00071   /** Converts a string action to an Action enum value. */
00072   static Action toAction(QString action);
00073   
00074   /** Returns the action taken when this policy matches an address. */
00075   QString action();
00076   /** Returns the host address (including mask, if set) for this policy. */
00077   QString address();
00078   /** Returns the port or port range for this policy. */
00079   QString ports();
00080 
00081 private:
00082   Action _action; /**< The action to take for this policy. */
00083   QHostAddress _address; /**< Addresses to which this policy applies. */
00084   quint16 _fromPort;  /**< Start of a port range. */
00085   quint16 _toPort;  /**< End of a port range. */
00086   uchar _mask;  /**< Address mask. */
00087 };
00088 
00089 #endif
00090 

Generated on Mon Oct 23 20:08:16 2006 for Vidalia by  doxygen 1.5.0