|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <unsafprotocolscrkeys.h> |
|
21 #include "CTcSIPContext.h" |
|
22 #include "TCmdUNSAFTimers.h" |
|
23 #include "SIPConstants.h" |
|
24 |
|
25 //NOTE: This value must be same as in CUNSAFCRSettings.h |
|
26 const TInt KMaxServerNameLen = 256; |
|
27 |
|
28 TInt TCmdUNSAFTimers::ReadTimerValuesL( CRepository& aRepository, |
|
29 TUint32& aKey, |
|
30 TInt& aBindingRequestInterval, |
|
31 TInt& aUdpKeepAliveInterval, |
|
32 TInt& aTcpKeepAliveInterval ) const |
|
33 { |
|
34 TPtrC8 iapName = ExtractTextL( KParamIAPName, EFalse ); |
|
35 if( iapName != KNullDesC8 ) |
|
36 { |
|
37 return ReadIapTimersL( aRepository, |
|
38 // Leaves if not found |
|
39 iContext.IAPIdL( iapName ), |
|
40 aKey, |
|
41 aBindingRequestInterval, |
|
42 aUdpKeepAliveInterval, |
|
43 aTcpKeepAliveInterval ); |
|
44 } |
|
45 |
|
46 // Since IAP was not given, domain is mandatory |
|
47 TPtrC8 domainName = ExtractTextL( KParamDomainName, ETrue ); |
|
48 return ReadDomainTimersL( aRepository, |
|
49 domainName, |
|
50 aKey, |
|
51 aUdpKeepAliveInterval, |
|
52 aTcpKeepAliveInterval ); |
|
53 } |
|
54 |
|
55 TInt TCmdUNSAFTimers::ReadIapTimersL( CRepository& aRepository, |
|
56 TInt aIapId, |
|
57 TUint32& aKey, |
|
58 TInt& aBindingRequestInterval, |
|
59 TInt& aUdpKeepAliveInterval, |
|
60 TInt& aTcpKeepAliveInterval ) const |
|
61 { |
|
62 TInt status = FindIapKeyL( aRepository, aIapId, aKey ); |
|
63 if ( status == KErrNone ) |
|
64 { |
|
65 // It doesn't matter if some parameter doesn't exist |
|
66 Read( aRepository, |
|
67 KUNSAFProtocolsIntervalUDPMask | aKey, |
|
68 aUdpKeepAliveInterval ); |
|
69 Read( aRepository, |
|
70 KUNSAFProtocolsIntervalTCPMask | aKey, |
|
71 aTcpKeepAliveInterval ); |
|
72 Read( aRepository, |
|
73 KUNSAFProtocolsSTUNRetransmitTimerMask | aKey, |
|
74 aBindingRequestInterval ); |
|
75 } |
|
76 return status; |
|
77 } |
|
78 |
|
79 TInt TCmdUNSAFTimers::FindIapKeyL( CRepository& aRepository, |
|
80 TInt aIapId, |
|
81 TUint32& aKey ) const |
|
82 { |
|
83 RArray<TUint32> keys; |
|
84 CleanupClosePushL( keys ); |
|
85 TInt err = aRepository.FindL( KUNSAFProtocolsIAPIdMask, |
|
86 KUNSAFProtocolsFieldTypeMask, |
|
87 keys ); |
|
88 TInt ret = KErrNotFound; |
|
89 if ( err == KErrNone && keys.Count() > 0 ) |
|
90 { |
|
91 for ( TInt i = 0; i < keys.Count() && ret == KErrNotFound; i++ ) |
|
92 { |
|
93 TUint32 key = ( KUNSAFProtocolsIAPIdMask ^ ( keys[ i ] ) ); |
|
94 key |= KUNSAFProtocolsIAPTableMask; |
|
95 |
|
96 TInt iapId( 0 ); |
|
97 Read( aRepository, KUNSAFProtocolsIAPIdMask | key, iapId ); |
|
98 |
|
99 if ( iapId == aIapId ) |
|
100 { |
|
101 aKey = key; |
|
102 ret = KErrNone; |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 CleanupStack::PopAndDestroy( &keys ); |
|
108 return ret; |
|
109 } |
|
110 |
|
111 TInt TCmdUNSAFTimers::ReadDomainTimersL( CRepository& aRepository, |
|
112 TPtrC8 aDomain, |
|
113 TUint32& aKey, |
|
114 TInt& aUdpKeepAliveInterval, |
|
115 TInt& aTcpKeepAliveInterval ) const |
|
116 { |
|
117 TInt status = FindDomainKeyL( aRepository, aDomain, aKey ); |
|
118 if ( status == KErrNone ) |
|
119 { |
|
120 Read( aRepository, |
|
121 KUNSAFProtocolsDomainIntervalUDPMask | aKey, |
|
122 aUdpKeepAliveInterval ); |
|
123 Read( aRepository, |
|
124 KUNSAFProtocolsDomainIntervalTCPMask | aKey, |
|
125 aTcpKeepAliveInterval ); |
|
126 } |
|
127 return status; |
|
128 } |
|
129 |
|
130 TInt TCmdUNSAFTimers::FindDomainKeyL( CRepository& aRepository, |
|
131 TPtrC8 aDomain, |
|
132 TUint32& aKey ) const |
|
133 { |
|
134 RArray<TUint32> keys; |
|
135 CleanupClosePushL( keys ); |
|
136 TInt err = aRepository.FindL( KUNSAFProtocolsDomainMask, |
|
137 KUNSAFProtocolsFieldTypeMask, |
|
138 keys ); |
|
139 TInt ret = KErrNotFound; |
|
140 if ( err == KErrNone && keys.Count() > 0 ) |
|
141 { |
|
142 for ( TInt i = 0; i < keys.Count() && ret == KErrNotFound; i++ ) |
|
143 { |
|
144 TUint32 key = ( KUNSAFProtocolsDomainMask ^ ( keys[ i ] ) ); |
|
145 key |= KUNSAFProtocolsDomainTableMask; |
|
146 |
|
147 TBuf8<KMaxServerNameLen> domain; |
|
148 if ( ( Read( aRepository, |
|
149 KUNSAFProtocolsDomainMask | key, |
|
150 domain ) == KErrNone ) && |
|
151 ( domain == aDomain ) ) |
|
152 { |
|
153 aKey = key; |
|
154 ret = KErrNone; |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 CleanupStack::PopAndDestroy( &keys ); |
|
160 return ret; |
|
161 } |
|
162 |
|
163 void TCmdUNSAFTimers::Read( CRepository& aRepository, |
|
164 const TUint32& aKey, |
|
165 TInt& aKeyValue ) const |
|
166 { |
|
167 TInt tmp( 0 ); |
|
168 if ( aRepository.Get( aKey, tmp ) == KErrNone ) |
|
169 { |
|
170 aKeyValue = tmp; |
|
171 } |
|
172 } |
|
173 |
|
174 TInt TCmdUNSAFTimers::Read( CRepository& aRepository, |
|
175 const TUint32& aKey, |
|
176 TDes8& aKeyValue ) const |
|
177 { |
|
178 TBuf8<1> tmp; |
|
179 TInt actualLength = 0; |
|
180 // This Get call returns KErrOverflow, but it doesn't matter as we are only |
|
181 // interested in actualLength. |
|
182 aRepository.Get( aKey, tmp, actualLength ); |
|
183 |
|
184 if ( actualLength <= 0 || actualLength > aKeyValue.MaxLength() ) |
|
185 { |
|
186 return KErrOverflow; |
|
187 } |
|
188 |
|
189 return aRepository.Get( aKey, aKeyValue ); |
|
190 } |
|
191 |
|
192 // Allow writing value zero, so that STUN client's behaviour can be tested also |
|
193 // in such case. If aKeyValue is KErrNotFound, then application didn't provide |
|
194 // it, and it is not written. |
|
195 void TCmdUNSAFTimers::WriteL( CRepository& aRepository, |
|
196 const TUint32& aKey, |
|
197 TInt aKeyValue ) const |
|
198 { |
|
199 if ( aKeyValue != KErrNotFound ) |
|
200 { |
|
201 User::LeaveIfError( aRepository.Set( aKey, aKeyValue ) ); |
|
202 } |
|
203 } |
|
204 |
|
205 void TCmdUNSAFTimers::WriteL( CRepository& aRepository, |
|
206 const TUint32& aKey, |
|
207 const TDesC8& aKeyValue ) const |
|
208 { |
|
209 if ( aKeyValue != KNullDesC8 ) |
|
210 { |
|
211 User::LeaveIfError( aRepository.Set( aKey, aKeyValue ) ); |
|
212 } |
|
213 } |
|
214 |
|
215 TUint32 TCmdUNSAFTimers::CreateNewKeyL( CRepository& aRepository, |
|
216 TUint32 aKey, |
|
217 TUint32 aTable ) const |
|
218 { |
|
219 const TUint32 KInitialKey = 1; |
|
220 TUint32 newKey = KInitialKey; |
|
221 RArray<TUint32> keys; |
|
222 CleanupClosePushL( keys ); |
|
223 TInt err = aRepository.FindL( aKey, |
|
224 KUNSAFProtocolsFieldTypeMask, |
|
225 keys ); |
|
226 if ( err != KErrNotFound ) |
|
227 { |
|
228 User::LeaveIfError( err ); |
|
229 TInt keyCount = keys.Count(); |
|
230 if ( keyCount != 0 ) |
|
231 { |
|
232 // Find the biggest key and increment it by one |
|
233 keys.SortUnsigned(); |
|
234 TUint32 maxKey = aKey ^ keys[ keyCount - 1 ]; |
|
235 newKey = maxKey + 1; |
|
236 } |
|
237 } |
|
238 |
|
239 newKey |= aTable; |
|
240 CleanupStack::PopAndDestroy( &keys ); |
|
241 return newKey; |
|
242 } |
|
243 |
|
244 void TCmdUNSAFTimers::RemoveParameterL( CRepository& aRepository, |
|
245 TUint32 aKey ) const |
|
246 { |
|
247 const TUint32 KSingleKeyMask = 0xffffffff; |
|
248 TUint32 dummy( 0 ); |
|
249 TInt status = aRepository.Delete( aKey, KSingleKeyMask, dummy ); |
|
250 __ASSERT_ALWAYS( status == KErrNone || status == KErrNotFound, |
|
251 User::Leave( status ) ); |
|
252 } |