|
1 /* |
|
2 * Copyright (c) 2005-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 "stunutils.h" |
|
22 #include "natfwunsafmessage.h" |
|
23 #include "natfwunsafmappedaddressattribute.h" |
|
24 #include "natfwunsafxormappedaddressattribute.h" |
|
25 #include "natfwunsafunknownattributesattribute.h" |
|
26 #include "stunturnclientlogs.h" |
|
27 #include "natfwunsafrelayaddressattribute.h" |
|
28 #include "natfwunsaftimervalattribute.h" |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // STUNUtils::GetMappedAddress |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 TBool STUNUtils::GetMappedAddress( const CNATFWUNSAFMessage& aResponse, |
|
37 TInetAddr& aAddr ) |
|
38 { |
|
39 __STUNTURNCLIENT( "STUNUtils::GetMappedAddress" ) |
|
40 CNATFWUNSAFMappedAddressAttribute* mappedAddress = |
|
41 static_cast<CNATFWUNSAFMappedAddressAttribute*> |
|
42 ( aResponse.Attribute( CNATFWUNSAFAttribute::EMappedAddress ) ); |
|
43 if ( mappedAddress ) |
|
44 { |
|
45 aAddr = mappedAddress->Address(); |
|
46 return ETrue; |
|
47 } |
|
48 |
|
49 return EFalse; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // STUNUtils::GetXorMappedAddressL |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 TBool STUNUtils::GetXorMappedAddressL( const CNATFWUNSAFMessage& aResponse, |
|
57 TInetAddr& aAddr ) |
|
58 { |
|
59 __STUNTURNCLIENT( "STUNUtils::GetXorMappedAddressL" ) |
|
60 CNATFWUNSAFXorMappedAddressAttribute* xorMappedAddress = |
|
61 static_cast<CNATFWUNSAFXorMappedAddressAttribute*> |
|
62 ( aResponse.Attribute( CNATFWUNSAFAttribute::EXorMappedAddress ) ); |
|
63 if ( xorMappedAddress ) |
|
64 { |
|
65 xorMappedAddress->SetTransactionIDAndXorL( aResponse.TransactionID() ); |
|
66 aAddr = xorMappedAddress->Address(); |
|
67 return ETrue; |
|
68 } |
|
69 |
|
70 return EFalse; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // STUNUtils::GetRelayAddressL |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TBool STUNUtils::GetRelayAddressL( const CNATFWUNSAFMessage& aResponse, |
|
78 TInetAddr& aAddr ) |
|
79 { |
|
80 __STUNTURNCLIENT( "STUNUtils::GetRelayAddressL" ) |
|
81 CNATFWUNSAFRelayAddressAttribute* relayAddress = |
|
82 static_cast<CNATFWUNSAFRelayAddressAttribute*> |
|
83 ( aResponse.Attribute( CNATFWUNSAFAttribute::ERelayAddress ) ); |
|
84 |
|
85 if ( relayAddress ) |
|
86 { |
|
87 aAddr = relayAddress->Address(); |
|
88 return ETrue; |
|
89 } |
|
90 return EFalse; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // STUNUtils::GetTimerValueL |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 TBool STUNUtils::GetTimerValueL( const CNATFWUNSAFMessage& aResponse, |
|
98 TUint32& aTimerVal ) |
|
99 { |
|
100 __STUNTURNCLIENT( "STUNUtils::GetTimerValueL" ) |
|
101 CNATFWUNSAFTimerValAttribute* timerval = |
|
102 static_cast<CNATFWUNSAFTimerValAttribute*> |
|
103 ( aResponse.Attribute( CNATFWUNSAFAttribute::ETimerVal ) ); |
|
104 |
|
105 if ( timerval ) |
|
106 { |
|
107 aTimerVal = timerval->TimerVal(); |
|
108 return ETrue; |
|
109 } |
|
110 return EFalse; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // STUNUtils::Is5xxResponse |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TBool STUNUtils::Is5xxResponse( TInt aResponseCode ) |
|
118 { |
|
119 return ( aResponseCode >= 500 && aResponseCode < 600 ); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // STUNUtils::RemoveUnknownAttributes |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void STUNUtils::RemoveUnknownAttributes( CNATFWUNSAFMessage& aMessage, |
|
127 const CNATFWUNSAFUnknownAttributesAttribute& aUnknownAttr ) |
|
128 { |
|
129 __STUNTURNCLIENT( "STUNUtils::RemoveUnknownAttributes" ) |
|
130 const RArray<TUint32>& unknown = aUnknownAttr.ContainedAttributes(); |
|
131 |
|
132 for ( TInt i = 0; i < unknown.Count(); ++i ) |
|
133 { |
|
134 aMessage.DeleteAttribute( static_cast<TUint16>( unknown[i] ) ); |
|
135 } |
|
136 __STUNTURNCLIENT( "STUNUtils::RemoveUnknownAttributes end" ) |
|
137 } |