-
Notifications
You must be signed in to change notification settings - Fork 0
/
iprule.cpp
84 lines (69 loc) · 2.09 KB
/
iprule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
** iprule.cpp
**
** Copyright © Quazaa Development Team, 2009-2013.
** This file is part of the Quazaa Security Library (quazaa.sourceforge.net)
**
** The Quazaa Security Library is free software; this file may be used under the terms of the GNU
** General Public License version 3.0 or later as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** The Quazaa Security Library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**
** Please review the following information to ensure the GNU General Public
** License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** You should have received a copy of the GNU General Public License version
** 3.0 along with the Quazaa Security Library; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "iprule.h"
#include "debug_new.h"
using namespace Security;
IPRule::IPRule()
{
m_nType = RuleType::IPAddress;
}
Rule* IPRule::getCopy() const
{
return new IPRule( *this );
}
bool IPRule::parseContent( const QString& sContent )
{
EndPoint oAddress;
if ( oAddress.setAddress( sContent ) )
{
m_oIP = oAddress;
m_sContent = oAddress.toString();
return true;
}
return false;
}
const QHostAddress& IPRule::IP() const
{
return m_oIP;
}
void IPRule::setIP( const QHostAddress& oIP )
{
m_oIP = oIP;
m_sContent = oIP.toString();
}
bool IPRule::match( const EndPoint& oAddress ) const
{
Q_ASSERT( !oAddress.isNull() && m_nType == RuleType::IPAddress );
// Compares IP only as m_oIP is a QHostAddress.
return oAddress == m_oIP;
}
void IPRule::toXML( QXmlStreamWriter& oXMLdocument ) const
{
Q_ASSERT( m_nType == RuleType::IPAddress );
oXMLdocument.writeStartElement( "rule" );
oXMLdocument.writeAttribute( "type", "address" );
oXMLdocument.writeAttribute( "address", contentString() );
Rule::toXML( *this, oXMLdocument );
oXMLdocument.writeEndElement();
}