Vidalia
0.2.21
Main Page
Namespaces
Classes
Files
File List
File Members
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
Generated on Thu Dec 6 2012 04:33:17 for Vidalia by
1.8.2