Policy Class Reference

#include <Policy.h>

List of all members.

Public Types

enum  Action { Accept, Reject }
enum  SpecialPolicy { AcceptAll, RejectAll }

Public Member Functions

 Policy ()
 Policy (QString policy)
 Policy (QString action, QString address, QString ports)
 Policy (SpecialPolicy policy)
 Policy (Action action, QHostAddress addr, uchar mask, quint16 fromPort, quint16 toPort=0)
bool matches (const Policy &policy) const
bool operator== (const Policy &policy) const
void fromString (QString policy)
QString toString () const
QString action () const
QString address () const
QString ports () const

Static Public Member Functions

static Action toAction (QString action)

Private Attributes

Action _action
QHostAddress _address
quint16 _fromPort
quint16 _toPort
uchar _mask

Detailed Description

Definition at line 25 of file Policy.h.


Member Enumeration Documentation

A set of possible actions for a policy

Enumerator:
Accept 

Connections matching this policy will be accepted.

Reject 

Connections matching this policy will be rejected.

Definition at line 31 of file Policy.h.

Special rule types.

Enumerator:
AcceptAll 

Accepts all connections. Equivalent to "accept *:*".

RejectAll 

Rejects all connections. Equivalent to "reject *:*".

Definition at line 36 of file Policy.h.


Constructor & Destructor Documentation

Policy::Policy (  ) 

Default constructor. Creates an AcceptAll policy.

Definition at line 23 of file Policy.cpp.

References _action, _address, _fromPort, _mask, _toPort, and Accept.

Policy::Policy ( QString  policy  ) 

Parses the given policy, represented as a string.

Constructor. Creates a new Policy object from the given string.

Definition at line 32 of file Policy.cpp.

References _action, _address, _fromPort, _mask, _toPort, Accept, and fromString().

Policy::Policy ( QString  action,
QString  address,
QString  ports 
)

Parses the given portions of a policy string.

Constructor. Creates a new Policy object from the string parts.

Definition at line 45 of file Policy.cpp.

References _action, _address, _fromPort, _mask, _toPort, Accept, and fromString().

Policy::Policy ( SpecialPolicy  policy  ) 

Creates a policy of the given special type.

Constructor. Creates a new Policy object depending on the specified special policy type.

Definition at line 58 of file Policy.cpp.

References _action, _address, _fromPort, _mask, _toPort, Accept, AcceptAll, and Reject.

Policy::Policy ( Action  action,
QHostAddress  addr,
uchar  mask,
quint16  fromPort,
quint16  toPort = 0 
)

Creates a policy using the specified information.

Constructor. Creates a new policy object based on the given rules.

Definition at line 67 of file Policy.cpp.

References _action, _address, _fromPort, _mask, and _toPort.


Member Function Documentation

QString Policy::action (  )  const

Returns the action taken when this policy matches an address.

Returns the action associated with this policy. NOTE: This string will be translated to whatever the current language setting is.

Definition at line 165 of file Policy.cpp.

References _action, and Accept.

QString Policy::address (  )  const

Returns the host address (including mask, if set) for this policy.

Returns the address (and mask, if specified) for this policy.

Definition at line 172 of file Policy.cpp.

References _address, and _mask.

Referenced by toString().

void Policy::fromString ( QString  policy  ) 

Parses the given policy string.

Parses the given exit policy string.

Definition at line 104 of file Policy.cpp.

References _action, _address, _fromPort, _mask, _toPort, ports(), and toAction().

Referenced by Policy().

bool Policy::matches ( const Policy policy  )  const

Returns true if this policy matches policy.

Returns true if this policy matches policy. For example, if this policy is "reject *:6660-6669" and policy is "reject *:6662-6664", this will return true. For strict comparison, use the == operator.

Definition at line 92 of file Policy.cpp.

References _action, _address, _fromPort, _mask, and _toPort.

Referenced by ExitPolicy::contains().

bool Policy::operator== ( const Policy policy  )  const

Returns true if this policy is identical to policy.

Definition at line 79 of file Policy.cpp.

References _action, _address, _fromPort, _mask, and _toPort.

QString Policy::ports (  )  const

Returns the port or port range for this policy.

Returns the port (or port range, if specified) for this policy.

Definition at line 188 of file Policy.cpp.

References _fromPort, and _toPort.

Referenced by fromString(), and toString().

Policy::Action Policy::toAction ( QString  action  )  [static]

Converts a string action to an Action enum value.

Converts the given action to a string. This function tolerates both the translated and untranslated forms of the string "accept" and "reject".

Definition at line 153 of file Policy.cpp.

References Accept, and Reject.

Referenced by fromString().

QString Policy::toString (  )  const

Converts this policy to a format Tor understands.

Converts this policy to a form Tor understands. The format is: "accept|reject ADDR[/MASK][:PORT]"

PORT can be a single port number, an interval of ports "FROM_PORT-TO_PORT", or "*". If PORT is omitted, that means "*"

Definition at line 144 of file Policy.cpp.

References _action, Accept, address(), and ports().

Referenced by ExitPolicy::toString().


Member Data Documentation

The action to take for this policy.

Definition at line 73 of file Policy.h.

Referenced by action(), fromString(), matches(), operator==(), Policy(), and toString().

QHostAddress Policy::_address [private]

Addresses to which this policy applies.

Definition at line 74 of file Policy.h.

Referenced by address(), fromString(), matches(), operator==(), and Policy().

quint16 Policy::_fromPort [private]

Start of a port range.

Definition at line 75 of file Policy.h.

Referenced by fromString(), matches(), operator==(), Policy(), and ports().

uchar Policy::_mask [private]

Address mask.

Definition at line 77 of file Policy.h.

Referenced by address(), fromString(), matches(), operator==(), and Policy().

quint16 Policy::_toPort [private]

End of a port range.

Definition at line 76 of file Policy.h.

Referenced by fromString(), matches(), operator==(), Policy(), and ports().


The documentation for this class was generated from the following files:

Generated on 31 Mar 2010 for Vidalia by  doxygen 1.6.1