|
1 /* |
|
2 * Copyright (c) 2006-2007 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 |
|
21 #include "natfwcandidatepair.h" |
|
22 #include "natfwcandidate.h" |
|
23 #include "natfwcredentials.h" |
|
24 #include "natfwclientlogs.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CNATFWCandidatePair::CNATFWCandidatePair |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CNATFWCandidatePair::CNATFWCandidatePair() |
|
33 { |
|
34 __NATFWCLIENT( "CNATFWCandidatePair::CNATFWCandidatePair" ) |
|
35 } |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CNATFWCandidatePair::ConstructL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void CNATFWCandidatePair::ConstructL() |
|
43 { |
|
44 __NATFWCLIENT( "CNATFWCandidatePair::ConstructL" ) |
|
45 |
|
46 iFoundation.Assign( KNullDesC8().AllocL() ); |
|
47 iLocalCand = CNATFWCandidate::NewL(); |
|
48 iRemoteCand = CNATFWCandidate::NewL(); |
|
49 } |
|
50 |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CNATFWCandidatePair::ConstructL |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CNATFWCandidatePair::ConstructL( const CNATFWCandidatePair& aPair ) |
|
57 { |
|
58 __NATFWCLIENT( "CNATFWCandidatePair::ConstructL (copy)" ) |
|
59 |
|
60 iFoundation.Assign( aPair.Foundation().AllocL() ); |
|
61 iLocalCand = CNATFWCandidate::NewL( aPair.LocalCandidate() ); |
|
62 iRemoteCand = CNATFWCandidate::NewL( aPair.RemoteCandidate() ); |
|
63 iPairPriority = aPair.Priority(); |
|
64 iSelected = aPair.Selected(); |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CNATFWCandidatePair::ConstructL |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CNATFWCandidatePair::ConstructL( |
|
73 const CNATFWCandidate& aLocalCand, |
|
74 const CNATFWCandidate& aRemoteCand ) |
|
75 { |
|
76 __NATFWCLIENT( "CNATFWCandidatePair::ConstructL (parametrized)" ) |
|
77 |
|
78 iLocalCand = CNATFWCandidate::NewL( aLocalCand ); |
|
79 iRemoteCand = CNATFWCandidate::NewL( aRemoteCand ); |
|
80 |
|
81 UpdateFoundationL(); |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CNATFWCandidatePair::NewL |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CNATFWCandidatePair* CNATFWCandidatePair::NewL() |
|
90 { |
|
91 __NATFWCLIENT( "CNATFWCandidatePair::NewL" ) |
|
92 |
|
93 CNATFWCandidatePair* self = CNATFWCandidatePair::NewLC(); |
|
94 CleanupStack::Pop( self ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CNATFWCandidatePair::NewLC |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C CNATFWCandidatePair* CNATFWCandidatePair::NewLC() |
|
104 { |
|
105 __NATFWCLIENT( "CNATFWCandidatePair::NewLC" ) |
|
106 |
|
107 CNATFWCandidatePair* self = new( ELeave ) CNATFWCandidatePair(); |
|
108 CleanupStack::PushL( self ); |
|
109 self->ConstructL(); |
|
110 return self; |
|
111 } |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CNATFWCandidatePair::NewL |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 EXPORT_C CNATFWCandidatePair* CNATFWCandidatePair::NewL( |
|
119 const CNATFWCandidatePair& aPair ) |
|
120 { |
|
121 __NATFWCLIENT( "CNATFWCandidatePair::NewL (copy)" ) |
|
122 |
|
123 CNATFWCandidatePair* self = CNATFWCandidatePair::NewLC( aPair ); |
|
124 CleanupStack::Pop( self ); |
|
125 return self; |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CNATFWCandidatePair::NewLC |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C CNATFWCandidatePair* CNATFWCandidatePair::NewLC( |
|
134 const CNATFWCandidatePair& aPair ) |
|
135 { |
|
136 __NATFWCLIENT( "CNATFWCandidatePair::NewLC (copy)" ) |
|
137 |
|
138 CNATFWCandidatePair* self = new( ELeave ) CNATFWCandidatePair(); |
|
139 CleanupStack::PushL( self ); |
|
140 self->ConstructL( aPair ); |
|
141 |
|
142 return self; |
|
143 } |
|
144 |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CNATFWCandidatePair::NewL |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C CNATFWCandidatePair* CNATFWCandidatePair::NewL( |
|
151 const CNATFWCandidate& aLocalCand, |
|
152 const CNATFWCandidate& aRemoteCand ) |
|
153 { |
|
154 __NATFWCLIENT( "CNATFWCandidatePair::NewL (parametrized)" ) |
|
155 |
|
156 CNATFWCandidatePair* self |
|
157 = CNATFWCandidatePair::NewLC( aLocalCand, aRemoteCand ); |
|
158 CleanupStack::Pop( self ); |
|
159 return self; |
|
160 } |
|
161 |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CNATFWCandidatePair::NewLC |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C CNATFWCandidatePair* CNATFWCandidatePair::NewLC( |
|
168 const CNATFWCandidate& aLocalCand, |
|
169 const CNATFWCandidate& aRemoteCand ) |
|
170 { |
|
171 __NATFWCLIENT( "CNATFWCandidatePair::NewLC (parametrized)" ) |
|
172 |
|
173 CNATFWCandidatePair* self = new( ELeave ) CNATFWCandidatePair(); |
|
174 CleanupStack::PushL( self ); |
|
175 self->ConstructL( aLocalCand, aRemoteCand ); |
|
176 |
|
177 return self; |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CNATFWCandidatePair::~CNATFWCandidatePair |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 CNATFWCandidatePair::~CNATFWCandidatePair() |
|
186 { |
|
187 __NATFWCLIENT( "CNATFWCandidatePair::~CNATFWCandidatePair" ) |
|
188 |
|
189 delete iRemoteCand; |
|
190 delete iLocalCand; |
|
191 iFoundation.Close(); |
|
192 } |
|
193 |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CNATFWCandidatePair::Foundation |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C const TDesC8& CNATFWCandidatePair::Foundation() const |
|
200 { |
|
201 __NATFWCLIENT_STR8( "CNATFWCandidatePair::Foundation", iFoundation ) |
|
202 |
|
203 return iFoundation; |
|
204 } |
|
205 |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // CNATFWCandidatePair::SetLocalCandidateL |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C void CNATFWCandidatePair::SetLocalCandidateL( |
|
212 const CNATFWCandidate& aCandidate ) |
|
213 { |
|
214 __NATFWCLIENT( "CNATFWCandidatePair::SetLocalCandidateL" ) |
|
215 |
|
216 if ( NULL != iLocalCand ) |
|
217 { |
|
218 iLocalCand->CopyL( aCandidate ); |
|
219 } |
|
220 else |
|
221 { |
|
222 iLocalCand = CNATFWCandidate::NewL( aCandidate ); |
|
223 } |
|
224 |
|
225 UpdateFoundationL(); |
|
226 } |
|
227 |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CNATFWCandidatePair::LocalCandidate |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C const CNATFWCandidate& CNATFWCandidatePair::LocalCandidate() const |
|
234 { |
|
235 __NATFWCLIENT( "CNATFWCandidatePair::LocalCandidate" ) |
|
236 |
|
237 return *iLocalCand; |
|
238 } |
|
239 |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // CNATFWCandidatePair::SetRemoteCandidateL |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C void CNATFWCandidatePair::SetRemoteCandidateL( |
|
246 const CNATFWCandidate& aCandidate ) |
|
247 { |
|
248 __NATFWCLIENT( "CNATFWCandidatePair::SetRemoteCandidateL" ) |
|
249 |
|
250 if ( NULL != iRemoteCand ) |
|
251 { |
|
252 iRemoteCand->CopyL( aCandidate ); |
|
253 } |
|
254 else |
|
255 { |
|
256 iRemoteCand = CNATFWCandidate::NewL( aCandidate ); |
|
257 } |
|
258 |
|
259 UpdateFoundationL(); |
|
260 } |
|
261 |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CNATFWCandidatePair::RemoteCandidate |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 EXPORT_C const CNATFWCandidate& CNATFWCandidatePair::RemoteCandidate() const |
|
268 { |
|
269 __NATFWCLIENT( "CNATFWCandidatePair::RemoteCandidate" ) |
|
270 |
|
271 return *iRemoteCand; |
|
272 } |
|
273 |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // CNATFWCandidatePair::SetPriority |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 EXPORT_C void CNATFWCandidatePair::SetPriority( const TUint64 aPriority ) |
|
280 { |
|
281 __NATFWCLIENT_INT1( "CNATFWCandidatePair::SetPriority", |
|
282 static_cast<TUint>( aPriority ) ) |
|
283 |
|
284 iPairPriority = aPriority; |
|
285 } |
|
286 |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CNATFWCandidatePair::Priority |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 EXPORT_C TUint64 CNATFWCandidatePair::Priority() const |
|
293 { |
|
294 __NATFWCLIENT_INT1( "CNATFWCandidatePair::Priority", |
|
295 static_cast<TUint>( iPairPriority ) ) |
|
296 |
|
297 return iPairPriority; |
|
298 } |
|
299 |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CNATFWCandidatePair::SetSelected |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 EXPORT_C void CNATFWCandidatePair::SetSelected( TBool aSelected ) |
|
306 { |
|
307 __NATFWCLIENT_INT1( "CNATFWCandidatePair::SetSelected", aSelected ) |
|
308 |
|
309 iSelected = aSelected; |
|
310 } |
|
311 |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CNATFWCandidatePair::Selected |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C TBool CNATFWCandidatePair::Selected() const |
|
318 { |
|
319 __NATFWCLIENT_INT1( "CNATFWCandidatePair::Selected", iSelected ) |
|
320 |
|
321 return iSelected; |
|
322 } |
|
323 |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CNATFWCandidatePair::PriorityOrder |
|
327 // Implements TLinearOrder (descending order). |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 EXPORT_C TInt CNATFWCandidatePair::PriorityOrder( |
|
331 const CNATFWCandidatePair& aA, |
|
332 const CNATFWCandidatePair& aB ) |
|
333 { |
|
334 return static_cast<TInt>( aB.Priority() - aA.Priority() ); |
|
335 } |
|
336 |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // CNATFWCandidatePair::CopyL |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 EXPORT_C void CNATFWCandidatePair::CopyL( const CNATFWCandidatePair& aPair ) |
|
343 { |
|
344 __NATFWCLIENT( "CNATFWCandidatePair::CopyL" ) |
|
345 |
|
346 if ( iLocalCand ) |
|
347 { |
|
348 iLocalCand->CopyL( aPair.LocalCandidate() ); |
|
349 } |
|
350 else |
|
351 { |
|
352 iLocalCand = CNATFWCandidate::NewL( aPair.LocalCandidate() ); |
|
353 } |
|
354 |
|
355 if ( iRemoteCand ) |
|
356 { |
|
357 iRemoteCand->CopyL( aPair.RemoteCandidate() ); |
|
358 } |
|
359 else |
|
360 { |
|
361 iRemoteCand = CNATFWCandidate::NewL( aPair.RemoteCandidate() ); |
|
362 } |
|
363 |
|
364 iPairPriority = aPair.Priority(); |
|
365 iSelected = aPair.Selected(); |
|
366 } |
|
367 |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // CNATFWCandidatePair::operator== |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 EXPORT_C TBool CNATFWCandidatePair::operator==( |
|
374 const CNATFWCandidatePair& aPair ) const |
|
375 { |
|
376 return ( |
|
377 iPairPriority == aPair.Priority() |
|
378 && *iLocalCand == aPair.LocalCandidate() |
|
379 && *iRemoteCand == aPair.RemoteCandidate() |
|
380 && iSelected == aPair.Selected() ); |
|
381 } |
|
382 |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // CNATFWCandidatePair::operator!= |
|
386 // --------------------------------------------------------------------------- |
|
387 // |
|
388 EXPORT_C TBool CNATFWCandidatePair::operator!=( |
|
389 const CNATFWCandidatePair& aPair ) const |
|
390 { |
|
391 return !( |
|
392 iPairPriority == aPair.Priority() |
|
393 && *iLocalCand == aPair.LocalCandidate() |
|
394 && *iRemoteCand == aPair.RemoteCandidate() |
|
395 && iSelected == aPair.Selected() ); |
|
396 } |
|
397 |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|
400 // CNATFWCandidatePair::Compare |
|
401 // Implements TIdentityRelation. Foundation is compared by comparing |
|
402 // foundations of local and remote candidates. |
|
403 // --------------------------------------------------------------------------- |
|
404 // |
|
405 EXPORT_C TBool CNATFWCandidatePair::Compare( |
|
406 const CNATFWCandidatePair& aItem1, |
|
407 const CNATFWCandidatePair& aItem2 ) |
|
408 { |
|
409 return ( |
|
410 aItem1.Priority() == aItem2.Priority() |
|
411 && aItem1.LocalCandidate() == aItem2.LocalCandidate() |
|
412 && aItem1.RemoteCandidate() == aItem2.RemoteCandidate() |
|
413 && aItem1.Selected() == aItem2.Selected() ); |
|
414 } |
|
415 |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // CNATFWCandidatePair::MatchAddresses |
|
419 // Implements TIdentityRelation. |
|
420 // --------------------------------------------------------------------------- |
|
421 // |
|
422 EXPORT_C TBool CNATFWCandidatePair::MatchAddresses( |
|
423 const CNATFWCandidatePair& aItem1, |
|
424 const CNATFWCandidatePair& aItem2 ) |
|
425 { |
|
426 const TInetAddr& localAddrA( aItem1.LocalCandidate().TransportAddr() ); |
|
427 const TInetAddr& localAddrB( aItem2.LocalCandidate().TransportAddr() ); |
|
428 const TInetAddr& remoteAddrA( aItem1.RemoteCandidate().TransportAddr() ); |
|
429 const TInetAddr& remoteAddrB( aItem2.RemoteCandidate().TransportAddr() ); |
|
430 |
|
431 return ( ( localAddrA.CmpAddr( localAddrB ) ) |
|
432 && ( remoteAddrA.CmpAddr( remoteAddrB ) ) ); |
|
433 } |
|
434 |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // CNATFWCandidatePair::UpdateFoundationL |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 void CNATFWCandidatePair::UpdateFoundationL() |
|
441 { |
|
442 __NATFWCLIENT( "CNATFWCandidatePair::UpdateFoundationL" ) |
|
443 |
|
444 if ( iLocalCand && iRemoteCand ) |
|
445 { |
|
446 iFoundation.Close(); |
|
447 iFoundation.CreateL( iLocalCand->Foundation().Size() |
|
448 + iRemoteCand->Foundation().Size() ); |
|
449 iFoundation.Append( iLocalCand->Foundation() ); |
|
450 iFoundation.Append( iRemoteCand->Foundation() ); |
|
451 } |
|
452 } |