Vidalia
0.3.1
src
vidalia
config
Policy.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 you
4
** did not receive the LICENSE file with this file, you may obtain it from the
5
** 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 Policy.h
13
** \brief Exit policy parsing
14
*/
15
16
#ifndef _POLICY_H
17
#define _POLICY_H
18
19
#include <QCoreApplication>
20
#include <QString>
21
#include <QHostAddress>
22
23
24
class
Policy
25
{
26
Q_DECLARE_TR_FUNCTIONS(
Policy
)
27
28
public
:
29
/** A set of possible actions for a policy */
30
enum
Action
{
31
Accept
,
/**< Connections matching this policy will be accepted. */
32
Reject
/**< Connections matching this policy will be rejected. */
33
};
34
/** Special rule types. */
35
enum
SpecialPolicy
{
36
AcceptAll
,
/**< Accepts all connections. Equivalent to "accept *:*". */
37
RejectAll
/**< Rejects all connections. Equivalent to "reject *:*". */
38
};
39
40
/** Default constructor. Creates an AcceptAll policy. */
41
Policy
();
42
/** Parses the given policy, represented as a string. */
43
Policy
(QString policy);
44
/** Parses the given portions of a policy string. */
45
Policy
(QString
action
, QString
address
, QString
ports
);
46
/** Creates a policy of the given special type. */
47
Policy
(
SpecialPolicy
policy);
48
/** Creates a policy using the specified information. */
49
Policy
(
Action
action
, QHostAddress addr, uchar mask,
50
quint16 fromPort, quint16 toPort = 0);
51
52
/** Returns true if this policy matches <b>policy</b>. */
53
bool
matches
(
const
Policy
&policy)
const
;
54
/** Returns true if this policy is identical to <b>policy</b>. */
55
bool
operator==
(
const
Policy
&policy)
const
;
56
57
/** Parses the given policy string. */
58
void
fromString
(QString policy);
59
/** Converts this policy to a format Tor understands. */
60
QString
toString
()
const
;
61
/** Converts a string action to an Action enum value. */
62
static
Action
toAction
(QString
action
);
63
64
/** Returns the action taken when this policy matches an address. */
65
QString
action
()
const
;
66
/** Returns the host address (including mask, if set) for this policy. */
67
QString
address
()
const
;
68
/** Returns the port or port range for this policy. */
69
QString
ports
()
const
;
70
71
private
:
72
Action
_action
;
/**< The action to take for this policy. */
73
QHostAddress
_address
;
/**< Addresses to which this policy applies. */
74
quint16
_fromPort
;
/**< Start of a port range. */
75
quint16
_toPort
;
/**< End of a port range. */
76
uchar
_mask
;
/**< Address mask. */
77
};
78
79
#endif
80
Policy::Reject
@ Reject
Definition:
Policy.h:32
Policy::_fromPort
quint16 _fromPort
Definition:
Policy.h:74
Policy::toAction
static Action toAction(QString action)
Definition:
Policy.cpp:152
Policy::_address
QHostAddress _address
Definition:
Policy.h:73
Policy::matches
bool matches(const Policy &policy) const
Definition:
Policy.cpp:91
Policy::action
QString action() const
Definition:
Policy.cpp:164
Policy::operator==
bool operator==(const Policy &policy) const
Definition:
Policy.cpp:78
Policy::address
QString address() const
Definition:
Policy.cpp:171
Policy::AcceptAll
@ AcceptAll
Definition:
Policy.h:36
Policy::Action
Action
Definition:
Policy.h:30
Policy::Policy
Policy()
Definition:
Policy.cpp:22
Policy::_action
Action _action
Definition:
Policy.h:72
Policy
Definition:
Policy.h:24
Policy::toString
QString toString() const
Definition:
Policy.cpp:143
Policy::SpecialPolicy
SpecialPolicy
Definition:
Policy.h:35
Policy::fromString
void fromString(QString policy)
Definition:
Policy.cpp:103
Policy::ports
QString ports() const
Definition:
Policy.cpp:187
Policy::RejectAll
@ RejectAll
Definition:
Policy.h:37
Policy::Accept
@ Accept
Definition:
Policy.h:31
Policy::_toPort
quint16 _toPort
Definition:
Policy.h:75
Policy::_mask
uchar _mask
Definition:
Policy.h:76
Generated by
1.8.17