|
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 for for presenceprovitem |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <CWPParameter.h> |
|
23 #include <CWPCharacteristic.h> |
|
24 #include <StringLoader.h> |
|
25 #include <badesca.h> |
|
26 |
|
27 #include "presenceprovitem.h" |
|
28 #include "pressettingsapi.h" |
|
29 #include "presenceprovlogger.h" |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CPresProvItem::CPresProvItem |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CPresProvItem::CPresProvItem() : |
|
38 iPresSetId(KErrNotFound), |
|
39 iSettingsSaved( EFalse ) |
|
40 { |
|
41 iSetName.Set(KNullDesC); |
|
42 iSipProfile = KErrNotFound; |
|
43 iXDMSetting = KErrNotFound; |
|
44 iObjectSize = KErrNotFound; |
|
45 iContSrvrAdd.Set(KNullDesC); |
|
46 iPublicationInt = KErrNotFound; |
|
47 iMaxSubscriptions = KErrNotFound; |
|
48 iMaxContactsInList = KErrNotFound; |
|
49 iDomainSyntax.Set(KNullDesC); |
|
50 iProviderID.Set(KNullDesC); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CPresProvItem::NewL |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CPresProvItem* CPresProvItem::NewL() |
|
59 { |
|
60 CPresProvItem* self = new (ELeave) CPresProvItem(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CPresProvItem::~CPresProvItem |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CPresProvItem::~CPresProvItem() |
|
69 { |
|
70 iToAppReferences.Close(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CPresProvItem::Validate |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TBool CPresProvItem::Validate() const |
|
78 { |
|
79 // Validate that compulsory settings are received |
|
80 PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::Validate()")); |
|
81 |
|
82 if ( !iAppId.Length() ) |
|
83 { |
|
84 PRES_PROV_LOG(LOG_LIT8( " iAppId missing" ) ); |
|
85 return EFalse; |
|
86 } |
|
87 else if ( iAppId.Compare( KPresProvisioningAppId) ) |
|
88 { |
|
89 PRES_PROV_LOG(LOG_LIT8( " Wrong iAppId" ) ); |
|
90 return EFalse; |
|
91 } |
|
92 else if (iSetName == KNullDesC) |
|
93 { |
|
94 PRES_PROV_LOG(LOG_LIT8( " iSetName is missing" )); |
|
95 return EFalse; |
|
96 } |
|
97 else if (iToAppReferences.Count() < 2 ) // if SIP and XDM references are not present |
|
98 { |
|
99 PRES_PROV_LOG(LOG_LIT8( " XDM or SIP reference is missing" )); |
|
100 return EFalse; |
|
101 } |
|
102 else if (iObjectSize < NULL) |
|
103 { |
|
104 PRES_PROV_LOG(LOG_LIT8( " iObjectSize is missing" )); |
|
105 return EFalse; |
|
106 } |
|
107 else if (iDomainSyntax == KNullDesC) |
|
108 { |
|
109 PRES_PROV_LOG(LOG_LIT8( " iDomainSyntax is missing" )); |
|
110 return EFalse; |
|
111 } |
|
112 else if (iProviderID == KNullDesC) |
|
113 { |
|
114 PRES_PROV_LOG(LOG_LIT8( " iProviderID is missing" )); |
|
115 return EFalse; |
|
116 } |
|
117 PRES_PROV_LOG(LOG_LIT8( " return True" ) ); |
|
118 return ETrue; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CPresProvItem::Name |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 const TDesC& CPresProvItem::Name() const |
|
126 { |
|
127 return iSetName; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CPresProvItem::ApplicationId |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 const TDesC& CPresProvItem::ApplicationId() const |
|
135 { |
|
136 return KPresProvisioningAppId; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CPresProvItem::PresSetId |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CPresProvItem::PresSetId() const |
|
144 { |
|
145 return iPresSetId; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CPresProvItem::AppReference |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 const TDesC& CPresProvItem::AppReference() const |
|
153 { |
|
154 return iAppRef; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CPresProvItem::SaveL |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 TInt CPresProvItem::SaveL() |
|
162 { |
|
163 PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::SaveL" ) ); |
|
164 |
|
165 TInt id(KErrNone); |
|
166 |
|
167 if( !iSettingsSaved ) |
|
168 { |
|
169 TPresSettingsSet mySet; |
|
170 (mySet.iSetName).Copy(iSetName); |
|
171 mySet.iSipProfile = iSipProfile; |
|
172 mySet.iXDMSetting = iXDMSetting; |
|
173 mySet.iObjectSize = iObjectSize; |
|
174 (mySet.iContSrvrAdd).Copy(iContSrvrAdd); |
|
175 mySet.iPublicationInt = iPublicationInt; |
|
176 mySet.iMaxSubscriptions = iMaxSubscriptions; |
|
177 mySet.iMaxContactsInList = iMaxContactsInList; |
|
178 (mySet.iDomainSyntax).Copy(iDomainSyntax); |
|
179 (mySet.iProviderID).Copy(iProviderID); |
|
180 |
|
181 CheckDuplicateNameL(mySet.iSetName, iPresSetId); |
|
182 |
|
183 id = PresSettingsApi::CreateSetL(mySet); |
|
184 |
|
185 if(id>KErrNotFound) |
|
186 { |
|
187 iSettingsSaved = ETrue; |
|
188 iPresSetId = id; |
|
189 } |
|
190 |
|
191 PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::SaveL with Id:%d" ),id); |
|
192 } |
|
193 return KErrNone; |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CPresProvItem::ToAppReferences |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 const RArray<TPtrC>& CPresProvItem::ToAppReferences() const |
|
201 { |
|
202 return iToAppReferences; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CPresProvItem::VisitL |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CPresProvItem::VisitL( CWPCharacteristic& aCharacteristic ) |
|
210 { |
|
211 TInt type = aCharacteristic.Type(); |
|
212 PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::VisitL CWPCharacteristic %d" ), type ); |
|
213 if (type == KWPResource) |
|
214 { |
|
215 aCharacteristic.AcceptL( *this ); |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CPresProvItem::VisitL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CPresProvItem::VisitL( CWPParameter& aParameter ) |
|
224 { |
|
225 PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::VisitL" ) ); |
|
226 PRES_PROV_LOG(LOG_LIT(" aParameter.Value(): %S"), &(aParameter.Value())); |
|
227 |
|
228 switch( aParameter.ID() ) |
|
229 { |
|
230 case EWPParameterAppID: |
|
231 { |
|
232 iAppId.Set( aParameter.Value() ); |
|
233 PRES_PROV_LOG(LOG_LIT8( " EWPParameterAppID" ) ); |
|
234 } |
|
235 break; |
|
236 |
|
237 case EWPParameterProviderID: |
|
238 { |
|
239 iProviderID.Set( aParameter.Value() ); |
|
240 PRES_PROV_LOG(LOG_LIT8( " EWPParameterProviderID" ) ); |
|
241 } |
|
242 break; |
|
243 |
|
244 case EWPParameterName: |
|
245 { |
|
246 iSetName.Set( aParameter.Value() ); |
|
247 PRES_PROV_LOG(LOG_LIT8( " EWPParameterName" ) ); |
|
248 } |
|
249 break; |
|
250 |
|
251 case EWPParameterToAppRef: |
|
252 { |
|
253 PRES_PROV_LOG(LOG_LIT8( " EWPParameterToAppRef")); |
|
254 iToAppReferences.Append( aParameter.Value() ); |
|
255 } |
|
256 break; |
|
257 |
|
258 case EWPParameterAppRef: |
|
259 { |
|
260 iAppRef.Set( aParameter.Value() ); |
|
261 PRES_PROV_LOG(LOG_LIT8( " EWPParameterAppRef")); |
|
262 } |
|
263 break; |
|
264 |
|
265 case EWPParameterService: // some setting tools put SERVICE-URI-TEMPLATE |
|
266 { // with this id |
|
267 iDomainSyntax.Set(aParameter.Value()); |
|
268 PRES_PROV_LOG(LOG_LIT8( " EWPParameterService")); |
|
269 } |
|
270 break; |
|
271 |
|
272 default: |
|
273 { |
|
274 DetermineNamedParameter( aParameter.Name(), aParameter.Value() ); |
|
275 } |
|
276 break; |
|
277 } |
|
278 PRES_PROV_LOG(LOG_LIT8( " CPresProvItem::VisitL ends" ) ); |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CPresProvItem::DetermineNamedParameter |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CPresProvItem::DetermineNamedParameter( const TDesC& aName, const TDesC& aValue ) |
|
286 { |
|
287 PRES_PROV_LOG(LOG_LIT( "DetermineNamedParameter(%S, %S)"), &aName, &aValue); |
|
288 if ( !aName.Compare( KPresProvClientObjDataLim ) ) |
|
289 { |
|
290 iObjectSize = DesToInt(aValue); |
|
291 } |
|
292 else if ( !aName.Compare( KPresProvContentSrvUri ) ) |
|
293 { |
|
294 iContSrvrAdd.Set( aValue ); |
|
295 } |
|
296 else if ( !aName.Compare( KPresProvSrcThPublish ) ) |
|
297 { |
|
298 iPublicationInt = DesToInt( aValue ); |
|
299 } |
|
300 else if ( !aName.Compare( KPresProvMaxPresSubs ) ) |
|
301 { |
|
302 iMaxSubscriptions = DesToInt( aValue ); |
|
303 } |
|
304 else if ( !aName.Compare( KPresProvMaxPresSubsInLists ) ) |
|
305 { |
|
306 iMaxContactsInList = DesToInt( aValue ); |
|
307 } |
|
308 else if ( !aName.Compare( KPresProvServiceUriTemp ) ) |
|
309 { |
|
310 iDomainSyntax.Set(aValue); |
|
311 } |
|
312 else if (!aName.Compare(KPresIAppRef)) |
|
313 { |
|
314 iAppRef.Set(aValue); |
|
315 } |
|
316 else if (!aName.Compare(KPresIToAppRef)) |
|
317 { |
|
318 if(iToAppReferences.Count() < 2) // if any of SIP or XDM id is missing |
|
319 iToAppReferences.Append(aValue); |
|
320 } |
|
321 PRES_PROV_LOG(LOG_LIT8( " CPresProvItem::DetermineNamedParameter ends" ) ); |
|
322 } |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CPresProvItem::VisitLinkL |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 void CPresProvItem::VisitLinkL( CWPCharacteristic& /*aLink*/ ) |
|
328 { |
|
329 PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::VisitLinkL" ) ); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CPresProvItem::SetSipSetIdL |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CPresProvItem::SetSipSetIdL(TInt aSipId) |
|
337 { |
|
338 PRES_PROV_LOG(LOG_LIT8( "SetSipSetIdL(%d)" ), aSipId); |
|
339 if (iSipProfile == KErrNotFound) |
|
340 iSipProfile = aSipId; |
|
341 if(iPresSetId>KErrNotFound) |
|
342 PresSettingsApi::UpdatePropertyL( iPresSetId, EPresPropSIPProfile, iSipProfile); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CPresProvItem::SetXDMSetIdL |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CPresProvItem::SetXDMSetIdL(TInt aXdmId) |
|
350 { |
|
351 PRES_PROV_LOG(LOG_LIT8( "SetXDMSetIdL(%d)" ), aXdmId); |
|
352 if (iXDMSetting == KErrNotFound) |
|
353 iXDMSetting = aXdmId; |
|
354 if(iPresSetId>KErrNotFound) |
|
355 PresSettingsApi::UpdatePropertyL( iPresSetId, EPresPropXDMSet, iXDMSetting); |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // CPresProvItem::GetPrefixL() |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 HBufC* CPresProvItem::GetPrefixL( HBufC* aName ) |
|
363 { |
|
364 TPtrC prefix = aName->Des(); |
|
365 TInt lastBrace = aName->LocateReverse('('); |
|
366 if ( lastBrace != KErrNotFound ) |
|
367 { |
|
368 // aName looks like "<prefix><brace><something>". |
|
369 // See if <something> is an integer number and |
|
370 // <something> ends to a brace. |
|
371 TPtrC num = aName->Right( aName->Length() - lastBrace - 1 ); |
|
372 TInt val; |
|
373 TLex lex( num ); |
|
374 if ( lex.Val( val ) == KErrNone && num.Locate(')') == num.Length() - 1 ) |
|
375 { |
|
376 // Yes, the trailer is an integer. |
|
377 prefix.Set( aName->Left( lastBrace ) ); |
|
378 } |
|
379 } |
|
380 return prefix.AllocL(); |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CPresProvAdapter::CheckDuplicateNameL |
|
385 // Checks if duplicate named Presence profiles. Renames if same. |
|
386 // ----------------------------------------------------------------------------- |
|
387 void CPresProvItem::CheckDuplicateNameL( TDes& aSetName, const TInt& aSetId) |
|
388 { |
|
389 PRES_PROV_LOG(LOG_LIT(" CheckDuplicateNameL(%S, %d)"),&aSetName, aSetId); |
|
390 |
|
391 _LIT( KPresProvNumbering, "(%N)" ); |
|
392 const TInt KPresProvFormatExtraLen = 6; |
|
393 |
|
394 HBufC* newName = HBufC::NewLC(KPresSetNameMaxLength); |
|
395 newName->Des().Copy(aSetName); |
|
396 |
|
397 RArray<TInt> setIds; |
|
398 CleanupClosePushL( setIds ); |
|
399 CDesCArray* names = PresSettingsApi::GetAllSetsNamesLC(setIds); |
|
400 TInt count(setIds.Count()); |
|
401 |
|
402 newName = newName->ReAlloc( |
|
403 newName->Length() + KPresProvFormatExtraLen );// enough for formatting |
|
404 |
|
405 HBufC* tempSetName = NULL; |
|
406 TInt pos = 0;// used as dummy |
|
407 TInt found = 0; |
|
408 TInt index = 1; |
|
409 TPtr ptr = newName->Des(); |
|
410 |
|
411 // do the actual checking of name |
|
412 found = names->Find( *newName, pos ); |
|
413 while ( found == 0 ) |
|
414 { |
|
415 if ( !tempSetName ) |
|
416 { |
|
417 tempSetName = GetPrefixL( newName ); |
|
418 tempSetName = tempSetName->ReAlloc( |
|
419 tempSetName->Length() + KPresProvFormatExtraLen );// enough for formatting |
|
420 CleanupStack::PushL( tempSetName ); |
|
421 tempSetName->Des().Append( KPresProvNumbering ); |
|
422 } |
|
423 StringLoader::Format( ptr, *tempSetName, -1, index ); |
|
424 found = names->Find( *newName, pos ); |
|
425 index++; |
|
426 } |
|
427 |
|
428 // cleanup |
|
429 if ( tempSetName ) |
|
430 { |
|
431 CleanupStack::PopAndDestroy( tempSetName ); //tempSetName |
|
432 } |
|
433 |
|
434 CleanupStack::PopAndDestroy(names); // names |
|
435 CleanupStack::PopAndDestroy(1); // setIds |
|
436 |
|
437 aSetName.Copy(newName->Des()); |
|
438 CleanupStack::PopAndDestroy( newName ); |
|
439 |
|
440 PRES_PROV_LOG(LOG_LIT(" CheckDuplicateNameL(%S): end"),&aSetName); |
|
441 } |
|
442 |
|
443 // ---------------------------------------------------------------------------- |
|
444 // CPresProvItem::DesToInt |
|
445 // ---------------------------------------------------------------------------- |
|
446 TInt CPresProvItem::DesToInt( const TDesC& aSrcDes ) const |
|
447 { |
|
448 TLex16 lex( aSrcDes ); |
|
449 TInt value ( KErrNotFound ); |
|
450 lex.Val( value ); |
|
451 return value; |
|
452 } |
|
453 |
|
454 // End of File |
|
455 |