summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/core/kmfnetzone.h
blob: 37d06488f98b72752fae1f5b71021e44c03ac000 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// C++ Interface: kmfnetzone
//
// Description:
//
//
// Author: Christian Hubinger <chubinger@irrsinnig.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef KMFNETZONE_H
#define KMFNETZONE_H

#include "netfilterobject.h"

// TQt includes
#include <tqptrlist.h>
#include <tqguardedptr.h>
#include <tqstring.h>
#include <tquuid.h>
#include <tqobject.h>

// KDE includes
#include <kdemacros.h>

// Project includes
#include "ipaddress.h"

namespace KMF {
class KMFGenericDoc;
class KMFProtocol;
class KMFProtocolUsage;
class KMFError;
class KMFCheckInput;
class IPAddress;
class KMFNetHost;
class KMFTarget;
class KMFNetwork;

//############ KMFNetZone #############
class KDE_EXPORT KMFNetZone : public NetfilterObject {
	TQ_OBJECT
  
public:
	KMFNetZone( NetfilterObject *parent, const char* objectname, const TQString& name );

	virtual ~KMFNetZone();
	
	virtual int type();
	virtual void clear();
	
	IPAddress* address() const {
		return m_address;
	};

	int operator==( const KMFNetZone& );
	
	bool isSameZone( KMFNetZone* );
	
	IPAddress* mask() const {
		IPAddress *addr = new IPAddress();
		addr->setAddress( IPAddress::calcNetworkMaskFromLength( m_maskLen ).toString() );
		return addr;
	};
	
	int maskLength() const {
		return m_maskLen;
	}
	
	KMFGenericDoc* doc() const;
	KMFNetwork* network() const;
	
	KMFNetZone* zone() const;
	KMFNetZone* rootZone();

	int getZoneType() const {
		return m_zoneType;
	};

	const TQString& guiName() const {
		return m_guiName;
	};
	
	virtual const TQString& name();
	const TQString& generateName( const TQString& );
	

	void setGuiName( const TQString& );
	
	void setNetwork( KMFNetwork* );
	void setZone( const IPAddress& , int );
	void setParentZone( KMFNetZone* );
	bool isRootZone();
	
	void setMaskLength( int );
	
	

	const TQDomDocument& getDOMTree();
	virtual void loadXML(const TQDomDocument&, TQStringList& errors );
	virtual void loadXML( TQDomNode, TQStringList& errors );
	
	KMFNetZone* addZone( const TQString& , KMFError* );
	void delZone( KMFNetZone*, bool desructive = true );

	KMFProtocolUsage* addProtocolUsage( const TQUuid& uuid, const TQDomDocument& xml );
	
	void delProtocolUsage( KMFProtocolUsage*, bool desructive = true );

	KMFNetHost* addNetHost( const TQString& name, const TQDomDocument& xml );
	KMFTarget* addTarget( const TQString& name, const TQDomDocument& xml );

	KMFTarget* findTargetByName( const TQString& name, bool fromRoot = true );
	KMFNetHost* findNetHostByName( const TQString& name, bool fromRoot = true );
	KMFNetZone* findNetZoneByName( const TQString& name, bool fromRoot = true );
	
	void delHost( KMFTarget*, bool desructive = true );

	TQPtrList<KMFProtocolUsage>& protocols() const;
	TQPtrList<KMFNetZone>& zones() const;
	TQPtrList<KMFTarget>& hosts() const;

	KMFProtocolUsage* findProtocolUsageByProtocolUuid( const TQUuid& uuid ) const;
	
	bool protocolInherited( const TQUuid& uuid ) const;
	
	KMFTarget* placeHostInZone( KMFTarget* host );
	KMFNetZone* placeZoneInZone( KMFNetZone* zone );
	void refreshNetworkTree();
	
	bool readOnly() const {
		return m_readOnly;
	};
	void setReadOnly( bool );	
	
	TQString toString();
	
	enum { ROOT, NODE } Type;
	
	void getAllTargets( KMFNetZone* zone, TQPtrList<KMFTarget>* list );
	
protected slots:
	void slotOnProtocolUsageDeleted( TQObject* protocol );
	
private: // Methods
	KMFTarget* findTargetByName_internal( const TQString& name );
	KMFNetZone* findNetZoneByName_internal( const TQString& name );
	TQString zoneInfo();
	
	void getAllZones( KMFNetZone* zone, TQPtrList<KMFNetZone>* list );
	void getAllHosts( KMFNetZone* zone, TQPtrList<KMFTarget>* list );
	
	
	
	
private: // Data
	TQGuardedPtr<KMFGenericDoc> m_doc;
	TQGuardedPtr<KMFNetZone> m_zone;
	TQGuardedPtr<KMFNetwork> m_network;
	IPAddress* m_address;
	
	TQPtrList<KMFProtocolUsage> m_protocols;
	TQPtrList<KMFNetZone> m_zones;
	TQPtrList<KMFTarget> m_hosts;
	KMFError *m_err;
	int m_zoneType;
	int m_maskLen;
// 	bool m_deadEnd;
	TQString m_guiName;
	bool m_readOnly;	
};
}


#endif