|
1 /** @file |
|
2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <S32MEM.H> |
|
21 #include "upnpipfiltering.h" |
|
22 #include "upnpipfilteringdnsquery.h" |
|
23 |
|
24 const TInt KGranularity = 1; |
|
25 |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CUpnpIPFiltering::CUpnpIPFiltering |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CUpnpIPFiltering::CUpnpIPFiltering( RSocketServ& aSocketServer, TInt aIap, |
|
36 MMessageHandlerEngineObserver& aObserver ) : |
|
37 iAllowedIPsList( KGranularity ), |
|
38 iSockServ( aSocketServer ), |
|
39 iActiveIap( aIap ), |
|
40 iObserver( aObserver ) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CUpnpIPFiltering::ConstructL |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void CUpnpIPFiltering::ConstructL( RSocketServ& aSocketServer ) |
|
50 { |
|
51 |
|
52 iConnectionManagerProxy = CUpnpConnectionManagerProxy::NewL( aSocketServer ); |
|
53 User::LeaveIfError( iConnectionManagerProxy->EnsureStart() ); |
|
54 |
|
55 IPList2Des8L(); |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CUpnpIPFiltering::NewL |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CUpnpIPFiltering* CUpnpIPFiltering::NewL( RSocketServ &aSocketServer, TInt aIap, |
|
64 MMessageHandlerEngineObserver& aObserver ) |
|
65 { |
|
66 CUpnpIPFiltering* self = CUpnpIPFiltering::NewLC( aSocketServer, aIap ,aObserver ); |
|
67 CleanupStack::Pop( self ); |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CUpnpIPFiltering::NewLC |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CUpnpIPFiltering* CUpnpIPFiltering::NewLC( RSocketServ &aSocketServer, TInt aIap, |
|
77 MMessageHandlerEngineObserver& aObserver ) |
|
78 { |
|
79 CUpnpIPFiltering* self = new ( ELeave ) CUpnpIPFiltering( aSocketServer, aIap, |
|
80 aObserver ); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL( aSocketServer ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CUpnpIPFiltering::~CUpnpIPFiltering |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CUpnpIPFiltering::~CUpnpIPFiltering() |
|
92 { |
|
93 iDNSQueriesList.ResetAndDestroy(); |
|
94 iAllowedIPsList.Close(); |
|
95 delete iConnectionManagerProxy; |
|
96 |
|
97 iListBuf.Close(); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CUpnpIPFiltering::AddAddress |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CUpnpIPFiltering::AddAddressL( const TInetAddr& aAddress ) |
|
106 { |
|
107 if ( !( aAddress.IsBroadcast() || |
|
108 aAddress.Address() == 0 ) ) |
|
109 { |
|
110 TInt index( FindInList( aAddress ) ); |
|
111 if( index == KErrNotFound ) |
|
112 { |
|
113 iAllowedIPsList.AppendL( aAddress ); |
|
114 IPList2Des8L(); |
|
115 return KErrNone; |
|
116 } |
|
117 return index; |
|
118 } |
|
119 return KErrArgument; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CUpnpIPFiltering::AddAddressL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CUpnpIPFiltering::AddAddressL( CUpnpIPFilteringDNSQuery* aQuery ) |
|
127 { |
|
128 iDNSQueriesList.AppendL( aQuery ); |
|
129 aQuery->AddAddress(); |
|
130 aQuery->StartDNSQuery( iSockServ , iConnectionManagerProxy->ConnectionL() , this ); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CUpnpIPFiltering::RemoveAddress |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CUpnpIPFiltering::RemoveAddressL( const TInetAddr& aAddress ) |
|
138 { |
|
139 if ( !( aAddress.IsBroadcast() || |
|
140 aAddress.Address() ==0 ) ) |
|
141 { |
|
142 TInt index( FindInList( aAddress ) ); |
|
143 if( index != KErrNotFound ) |
|
144 { |
|
145 iAllowedIPsList.Remove( index ); |
|
146 iAllowedIPsList.Compress(); |
|
147 IPList2Des8L(); |
|
148 } |
|
149 return index; |
|
150 } |
|
151 return KErrArgument; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CUpnpIPFiltering::RemoveAddressL |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CUpnpIPFiltering::RemoveAddressL( CUpnpIPFilteringDNSQuery* aQuery ) |
|
159 { |
|
160 iDNSQueriesList.AppendL( aQuery ); |
|
161 aQuery->RemoveAddress(); |
|
162 aQuery->StartDNSQuery( iSockServ , iConnectionManagerProxy->ConnectionL() , this ); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CUpnpIPFiltering::RemoveAll |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TInt CUpnpIPFiltering::RemoveAll( ) |
|
170 { |
|
171 if( iAllowedIPsList.Count() ) |
|
172 { |
|
173 iAllowedIPsList.Reset(); |
|
174 iAllowedIPsList.Compress(); |
|
175 TRAP_IGNORE( IPList2Des8L() ); |
|
176 return KErrNone; |
|
177 } |
|
178 return KErrNotFound; |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CUpnpIPFiltering::IsAllowed |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TBool CUpnpIPFiltering::IsAllowed( const TInetAddr& aAddress ) const |
|
186 { |
|
187 return ( FindInList( aAddress ) != KErrNotFound ); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CUpnpIPFiltering::Count |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 TInt CUpnpIPFiltering::Count( ) const |
|
195 { |
|
196 return iAllowedIPsList.Count(); |
|
197 } |
|
198 |
|
199 const TDesC8& CUpnpIPFiltering::GetIPFilterList( ) |
|
200 { |
|
201 return iListBuf; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CUpnpIPFiltering::FindInList |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 TInt CUpnpIPFiltering::FindInList( const TInetAddr& aAddress ) const |
|
209 { |
|
210 for ( TInt index( 0 ) ; index < iAllowedIPsList.Count() ; index++ ) |
|
211 { |
|
212 if ( iAllowedIPsList[index].Address() == aAddress.Address() ) |
|
213 { |
|
214 return index; |
|
215 } |
|
216 } |
|
217 return KErrNotFound; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CUpnpIPFiltering::IPList2Des8L |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 void CUpnpIPFiltering::IPList2Des8L() |
|
225 { |
|
226 iListBuf.Close(); |
|
227 |
|
228 const TInt KOne( 10 ); |
|
229 |
|
230 CBufFlat* buf = CBufFlat::NewL( KOne ); |
|
231 CleanupStack::PushL( buf ); |
|
232 RBufWriteStream writer( *buf ); |
|
233 CleanupClosePushL( writer ); |
|
234 |
|
235 writer.WriteInt32L( Count() ); |
|
236 |
|
237 for ( TInt i(0) ; i < iAllowedIPsList.Count() ; i++ ) |
|
238 { |
|
239 TPckg<TInetAddr> temp( iAllowedIPsList[i] ); |
|
240 writer << temp; |
|
241 } |
|
242 |
|
243 // create heap descriptor |
|
244 iListBuf.Create( buf->Size() ); |
|
245 buf->Read( 0, iListBuf, buf->Size() ); |
|
246 |
|
247 // clean up; |
|
248 CleanupStack::PopAndDestroy( &writer ); |
|
249 CleanupStack::PopAndDestroy(buf); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CUpnpIPFiltering::RequestCompleted |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CUpnpIPFiltering::RequestCompleted( CUpnpIPFilteringDNSQuery* iQuery ) |
|
257 { |
|
258 for( TInt i(0) ; i < iDNSQueriesList.Count() ; i++ ) |
|
259 { |
|
260 if( iDNSQueriesList[i] == iQuery ) |
|
261 { |
|
262 delete iDNSQueriesList[i]; |
|
263 iDNSQueriesList.Remove( i ); |
|
264 break; |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // CUpnpIPFiltering::IPListChange |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 void CUpnpIPFiltering::IPListChange() |
|
274 { |
|
275 iObserver.IPListChange(); |
|
276 } |
|
277 // End of file |