|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : CSIPClientResolver2.cpp |
|
15 // Part of : SIP Client Resolver |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "CSIPClientResolver2.h" |
|
23 #include "sipresolvedclient2.h" |
|
24 #include "TSipClient.h" |
|
25 #include "SIPCRLogs.h" |
|
26 #include "sipclientresolverconfig.h" |
|
27 #include "siprequest.h" |
|
28 #include "sipuri.h" |
|
29 #include "sipcodecutils.h" |
|
30 #include "uricontainer.h" |
|
31 #include "CleanupResetAndDestroy.h" |
|
32 #include "CSipHeaderStrategyBase.h" |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // CSIPClientResolver2::NewL |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 CSIPClientResolver2* CSIPClientResolver2::NewL ( CSIPRequest& aRequest ) |
|
39 { |
|
40 SIP_CR_LOG("CSIPClientResolver2::NewL") |
|
41 CSIPClientResolver2* self = CSIPClientResolver2::NewLC ( aRequest ); |
|
42 CleanupStack::Pop ( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CSIPClientResolver2::NewLC |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 CSIPClientResolver2* CSIPClientResolver2::NewLC ( CSIPRequest& aRequest ) |
|
51 { |
|
52 SIP_CR_LOG("CSIPClientResolver2::NewLC") |
|
53 CSIPClientResolver2* self = new( ELeave ) CSIPClientResolver2; |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL( aRequest ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CSIPClientResolver2::CSIPClientResolver2 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 CSIPClientResolver2::CSIPClientResolver2() |
|
64 { |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CSIPClientResolver2::ConstructL |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 void CSIPClientResolver2::ConstructL( CSIPRequest& aRequest ) |
|
72 { |
|
73 iClientResolverConfig = CSipClientResolverConfig::NewL(); |
|
74 UIDsForUserNameL( aRequest ); |
|
75 LoadImplementationsL(); |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CSIPClientResolver2::~CSIPClientResolver2 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 CSIPClientResolver2::~CSIPClientResolver2 () |
|
83 { |
|
84 SIP_CR_LOG("CSIPClientResolver2::~CSIPClientResolver2") |
|
85 iResolvedClients.ResetAndDestroy(); |
|
86 iUids.Reset(); |
|
87 iClientsData.Reset(); |
|
88 delete iClientResolverConfig; |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CSIPClientResolver2::ClientsData |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 RArray< TSipClient >& CSIPClientResolver2::ClientsData() |
|
96 { |
|
97 SIP_CR_LOG("CSIPClientResolver2::ClientsData") |
|
98 return iClientsData; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CSIPClientResolver2::GetSipClientDataL |
|
103 // ---------------------------------------------------------------------------- |
|
104 // |
|
105 TBool CSIPClientResolver2::GetSipClientDataL( RArray< TSipClient >& aUids ) |
|
106 { |
|
107 SIP_CR_LOG("CSIPClientResolver2::GetSipClientDataL") |
|
108 TBool found(EFalse); |
|
109 |
|
110 if ( iClientsData.Count() > 0 ) |
|
111 { |
|
112 ListImplementationsL(); |
|
113 for( TInt i = 0; i < iClientsData.Count(); ++i ) |
|
114 { |
|
115 TSipClient tmp = iClientsData[i]; |
|
116 if ( tmp.PluginType() == TSipClient::EFirstGeneration ) |
|
117 { |
|
118 found = EFalse; |
|
119 return found; |
|
120 } |
|
121 found = ETrue; |
|
122 aUids.AppendL( tmp ); |
|
123 } |
|
124 } |
|
125 SIP_CR_INT_LOG("CSIPClientResolver2::GetSipClientDataL count:",iUids.Count()) |
|
126 return found; |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CSIPClientResolver2::FetchMatchingUidsL |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 void CSIPClientResolver2::FetchMatchingUidsL( CSIPRequest& aRequest, |
|
134 CSipHeaderStrategyBase& aStrategy) |
|
135 { |
|
136 SIP_CR_LOG("CSIPClientResolver2::FetchMatchingUidsL") |
|
137 iClientsData.Reset(); |
|
138 TBool match = EFalse; |
|
139 TUid clientUid; |
|
140 RPointerArray< CSIPResolvedClient2 > tempClients; |
|
141 CSIPClientResolver2::PushLC( &tempClients ); |
|
142 for ( TInt i = iResolvedClients.Count()-1; i >= 0; --i ) |
|
143 { |
|
144 CSIPResolvedClient2* client = iResolvedClients[i]; |
|
145 match = aStrategy.MatchL( *client,aRequest,clientUid ); |
|
146 if ( match ) |
|
147 { |
|
148 SIP_CR_LOG("CSIPClientResolver2::FetchMatchingUidsL match") |
|
149 TSipClient temp( clientUid, client->ConnectSupported(), EFalse ); |
|
150 temp.SetImplementationUid( client->iImplementationUid ); |
|
151 iClientsData.AppendL( temp ); |
|
152 match = EFalse; |
|
153 tempClients.AppendL( client ); |
|
154 iResolvedClients.Remove( i ); |
|
155 iResolvedClients.Compress(); |
|
156 } |
|
157 } |
|
158 |
|
159 if ( tempClients.Count() ) |
|
160 { |
|
161 iResolvedClients.ResetAndDestroy(); |
|
162 for ( TInt i = tempClients.Count()-1; i >= 0; --i ) |
|
163 { |
|
164 iResolvedClients.AppendL( tempClients[i] ); |
|
165 tempClients.Remove( i ); |
|
166 tempClients.Compress(); |
|
167 } |
|
168 } |
|
169 CleanupStack::Pop();//tempClients |
|
170 tempClients.Reset(); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CSIPClientResolver2::PushLC |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CSIPClientResolver2::PushLC(RPointerArray<CSIPResolvedClient2>* aArray) |
|
178 { |
|
179 CleanupStack::PushL(TCleanupItem(ResetAndDestroyArray,aArray)); |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CSIPClientResolver2::ResetAndDestroyArray |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CSIPClientResolver2::ResetAndDestroyArray(TAny* anArray) |
|
187 { |
|
188 RPointerArray<CSIPResolvedClient2>* array = |
|
189 reinterpret_cast<RPointerArray<CSIPResolvedClient2>*>(anArray); |
|
190 if (array) |
|
191 { |
|
192 array->ResetAndDestroy(); |
|
193 } |
|
194 } |
|
195 |
|
196 // ---------------------------------------------------------------------------- |
|
197 // CSIPClientResolver2::Clients |
|
198 // ---------------------------------------------------------------------------- |
|
199 // |
|
200 RPointerArray< CSIPResolvedClient2 >& CSIPClientResolver2::Clients() |
|
201 { |
|
202 SIP_CR_LOG("CSIPClientResolver2::Clients") |
|
203 return iResolvedClients; |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CSIPClientResolver2::UIDsForUserNameL |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 RArray <TUid> CSIPClientResolver2::UIDsForUserNameL( CSIPRequest& aRequest ) |
|
211 { |
|
212 SIP_CR_LOG("CSIPClientResolver2::UIDsForUserNameL") |
|
213 iUids.Reset(); |
|
214 if ( aRequest.RequestURI() ) |
|
215 { |
|
216 if ( !aRequest.RequestURI()->IsSIPURI() ) |
|
217 { |
|
218 User::Leave(KErrCorrupt); |
|
219 } |
|
220 iClientResolverConfig->GetUIDsForUserNameL( |
|
221 aRequest.RequestURI()->SIPURI()->User(),iUids ); |
|
222 } |
|
223 SIP_CR_INT_LOG("CSIPClientResolver2::UIDsForUserNameL count:",iUids.Count()) |
|
224 return iUids; |
|
225 } |
|
226 |
|
227 // ---------------------------------------------------------------------------- |
|
228 // CSIPClientResolver2::ListImplementationsL |
|
229 // ---------------------------------------------------------------------------- |
|
230 // |
|
231 void CSIPClientResolver2::ListImplementationsL() |
|
232 { |
|
233 SIP_CR_LOG("CSIPClientResolver2::ListImplementationsL") |
|
234 RImplInfoPtrArray allClients; |
|
235 REComSession::ListImplementationsL( KSIPResolvedClient2IFUid, allClients ); |
|
236 CleanupResetAndDestroyPushL( allClients ); |
|
237 SIP_CR_INT_LOG("All new plug-ins count", allClients.Count()) |
|
238 TInt err = KErrNone; |
|
239 |
|
240 for ( TInt i = 0; i < allClients.Count(); ++i ) |
|
241 { |
|
242 CImplementationInformation* info = allClients[i]; |
|
243 TRAP(err, AddClientDataL( *info ) ); |
|
244 |
|
245 if( err == KErrNoMemory ) |
|
246 { |
|
247 User::Leave( err ); |
|
248 } |
|
249 } |
|
250 |
|
251 CleanupStack::PopAndDestroy( 1 ); // allClients |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------------------------------- |
|
255 // CSIPClientResolver2::AddClientDataL |
|
256 // ---------------------------------------------------------------------------- |
|
257 // |
|
258 void CSIPClientResolver2::AddClientDataL( CImplementationInformation& aInfo ) |
|
259 { |
|
260 SIP_CR_LOG("CSIPClientResolver2::AddClientDataL") |
|
261 for ( TInt i = 0; i < iClientsData.Count(); ++i ) |
|
262 { |
|
263 if ( iClientsData[i].ImplementationUid() == aInfo.ImplementationUid() ) |
|
264 { |
|
265 SIP_CR_LOG("CSIPClientResolver2::AddClientDataL check rombased") |
|
266 iClientsData[i].SetRomBased( aInfo.RomBased() ); |
|
267 iClientsData[i].SetPluginType( TSipClient::ESecondGeneration ); |
|
268 return; |
|
269 } |
|
270 } |
|
271 } |
|
272 |
|
273 // ---------------------------------------------------------------------------- |
|
274 // CSIPClientResolver2::LoadImplementationsL |
|
275 // ---------------------------------------------------------------------------- |
|
276 // |
|
277 void CSIPClientResolver2::LoadImplementationsL() |
|
278 { |
|
279 SIP_CR_LOG("CSIPClientResolver2::LoadImplementationsL") |
|
280 CSIPResolvedClient2* resolvedClient2 = NULL; |
|
281 |
|
282 for ( TInt i = 0; i < iUids.Count(); ++i ) |
|
283 { |
|
284 TRAPD( err, resolvedClient2 = reinterpret_cast< CSIPResolvedClient2* >( |
|
285 REComSession::CreateImplementationL( iUids[i], |
|
286 _FOFF( CSIPResolvedClient2, iInstanceKey ) ) ) ); |
|
287 if ( !err ) |
|
288 { |
|
289 CleanupStack::PushL( resolvedClient2 ); |
|
290 resolvedClient2->iImplementationUid = iUids[i]; |
|
291 iResolvedClients.AppendL( resolvedClient2 ); |
|
292 CleanupStack::Pop( resolvedClient2 ); |
|
293 } |
|
294 err = 0; |
|
295 } |
|
296 |
|
297 iUids.Reset(); |
|
298 SIP_CR_INT_LOG("CSIPClientResolver2::LoadImplementationsL count:", |
|
299 iResolvedClients.Count()) |
|
300 } |
|
301 |
|
302 |
|
303 // End of File |
|
304 |