|
1 /* |
|
2 * Copyright (c) 2005 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: Utility classes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include <SyncMLTransportProperties.h> |
|
22 #include <eikenv.h> |
|
23 #include <bautils.h> |
|
24 #include <collate.h> |
|
25 #include <StringLoader.h> |
|
26 #include <avkon.rsg> |
|
27 #include <DevManInternalCRKeys.h> |
|
28 #include <centralrepository.h> |
|
29 #include <SettingEnforcementInfo.h> // VSettingEnforcementInfo |
|
30 #include <ecom/ecom.h> |
|
31 |
|
32 #include "NSmlDMdef.h" |
|
33 #include "NSmlDMSyncUtil.h" |
|
34 #include "NSmlDMSyncDebug.h" |
|
35 #include <featmgr.h> |
|
36 |
|
37 /***************************************************************************** |
|
38 * class TUtil |
|
39 *****************************************************************************/ |
|
40 |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // Panic |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 void TUtil::Panic(TInt aReason) |
|
47 { |
|
48 _LIT(KPanicCategory,"NSmlDMSyncUtil"); |
|
49 |
|
50 User::Panic( KPanicCategory, aReason ); |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // StrCopy |
|
55 // String copy with lenght check. |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 void TUtil::StrCopy( TDes8& aTarget, const TDesC& aSource ) |
|
59 { |
|
60 aTarget.Copy( aSource.Left(aTarget.MaxLength() ) ); |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // StrCopy |
|
65 // String copy with lenght check. |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 void TUtil::StrCopy( TDes& aTarget, const TDesC8& aSource ) |
|
69 { |
|
70 aTarget.Copy( aSource.Left(aTarget.MaxLength() ) ); |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // StrCopy |
|
75 // String copy with lenght check. |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 void TUtil::StrCopy( TDes& aTarget, const TDesC& aSource ) |
|
79 { |
|
80 aTarget.Copy( aSource.Left( aTarget.MaxLength() ) ); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // StrAppend |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 void TUtil::StrAppend( TDes& aTarget, const TDesC& aSource ) |
|
88 { |
|
89 if ( aSource.Length() == 0 ) |
|
90 { |
|
91 return; |
|
92 } |
|
93 TInt free = aTarget.MaxLength() - aTarget.Length(); |
|
94 if ( aSource.Length() <= free ) |
|
95 { |
|
96 aTarget.Append( aSource ); |
|
97 } |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // StrInsert |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void TUtil::StrInsert( TDes& aTarget, const TDesC& aSource ) |
|
105 { |
|
106 TInt free = aTarget.MaxLength() - aTarget.Length(); |
|
107 if (aSource.Length() <= free) |
|
108 { |
|
109 aTarget.Insert(0, aSource); |
|
110 } |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // StrToInt |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 TInt TUtil::StrToInt( const TDesC& aText, TInt& aNum ) |
|
118 { |
|
119 TLex lex( aText ); |
|
120 TInt err = lex.Val( aNum ); |
|
121 return err; |
|
122 } |
|
123 |
|
124 // |
|
125 //----------------------------------------------------------------------------- |
|
126 // IsEmpty |
|
127 // Function returns ETrue if string only contains white space |
|
128 // or has no characters. |
|
129 //----------------------------------------------------------------------------- |
|
130 // |
|
131 TBool TUtil::IsEmpty( const TDesC& aText ) |
|
132 { |
|
133 TInt len = aText.Length(); |
|
134 for ( TInt index=0; index < len; index++ ) |
|
135 { |
|
136 TChar character = aText[index]; |
|
137 if ( !character.IsSpace() ) |
|
138 { |
|
139 return EFalse; |
|
140 } |
|
141 } |
|
142 return ETrue; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // SyncTimeLC |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 HBufC* TUtil::SyncTimeLC( TTime aLastSync ) |
|
150 { |
|
151 FLOG( "[OMADM] TUtil::SyncTimeLC" ); |
|
152 |
|
153 TTime homeTime = ConvertUniversalToHomeTime( aLastSync ); |
|
154 |
|
155 HBufC* hBuf = HBufC::NewLC( KBufSize255 ); |
|
156 TPtr ptr = hBuf->Des(); |
|
157 |
|
158 if ( IsToday( homeTime ) ) |
|
159 { |
|
160 FLOG( "[OMADM] TUtil::SyncTimeLC time" ); |
|
161 |
|
162 TBuf<KBufSize> timeFormat; |
|
163 HBufC* buf = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
164 TUtil::StrCopy( timeFormat, *buf ); |
|
165 CleanupStack::PopAndDestroy( buf ); |
|
166 homeTime.FormatL( ptr, timeFormat ); |
|
167 |
|
168 FLOG( "[OMADM] TUtil::SyncTimeLC time done" ); |
|
169 } |
|
170 else |
|
171 { |
|
172 FLOG( "[OMADM] TUtil::SyncTimeLC date" ); |
|
173 |
|
174 TBuf<KBufSize> dateFormat; |
|
175 HBufC* buf = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
176 TUtil::StrCopy( dateFormat, *buf ); |
|
177 CleanupStack::PopAndDestroy( buf ); |
|
178 homeTime.FormatL(ptr, dateFormat); |
|
179 |
|
180 FLOG( "[OMADM] TUtil::SyncTimeLC date done" ); |
|
181 } |
|
182 FLOG( "[OMADM] TUtil::SyncTimeLC Done" ); |
|
183 return hBuf; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // ConvertUniversalToHomeTime |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TTime TUtil::ConvertUniversalToHomeTime( const TTime& aUniversalTime ) |
|
191 { |
|
192 TTime time( aUniversalTime ); // time stores UTC time. |
|
193 |
|
194 TLocale locale; |
|
195 TTimeIntervalSeconds universalTimeOffset( locale.UniversalTimeOffset() ); |
|
196 |
|
197 // Add locale's universal time offset to universal time. |
|
198 time += universalTimeOffset; // time stores Local Time. |
|
199 |
|
200 // If home daylight saving in effect, add one hour offset. |
|
201 if ( locale.QueryHomeHasDaylightSavingOn() ) |
|
202 { |
|
203 TTimeIntervalHours daylightSaving(1); |
|
204 time += daylightSaving; |
|
205 } |
|
206 |
|
207 return time; |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // IsToDay |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TBool TUtil::IsToday(TTime aTime) |
|
215 { |
|
216 FLOG( "[OMADM] TUtil::IsToday" ); |
|
217 |
|
218 TTime now; |
|
219 now.HomeTime(); |
|
220 TInt day1 = now.DayNoInYear(); |
|
221 TInt day2 = aTime.DayNoInYear(); |
|
222 TTimeIntervalDays daysBetween = now.DaysFrom( aTime ); |
|
223 |
|
224 if ( day1 != day2 ) |
|
225 { |
|
226 FLOG( "[OMADM] TUtil::IsToday False 1" ); |
|
227 return EFalse; |
|
228 } |
|
229 |
|
230 if ( daysBetween.Int() > 0 ) |
|
231 { |
|
232 FLOG( "[OMADM] TUtil::IsToday False 2" ); |
|
233 return EFalse; |
|
234 } |
|
235 |
|
236 FLOG( "[OMADM] TUtil::IsToday True" ); |
|
237 return ETrue; |
|
238 } |
|
239 |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // TUtil::GetDateTextL |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void TUtil::GetDateTextL(TDes& aText, TTime aDateTime) |
|
246 { |
|
247 TTime homeTime = ConvertUniversalToHomeTime( aDateTime ); |
|
248 HBufC* hBuf = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
249 homeTime.FormatL( aText, *hBuf ); |
|
250 CleanupStack::PopAndDestroy( hBuf ); |
|
251 } |
|
252 |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // TUtil::GetTimeTextL |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void TUtil::GetTimeTextL( TDes& aText, TTime aDateTime ) |
|
259 { |
|
260 TTime homeTime = ConvertUniversalToHomeTime( aDateTime ); |
|
261 HBufC* hBuf = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
262 homeTime.FormatL( aText, *hBuf ); |
|
263 CleanupStack::PopAndDestroy( hBuf ); |
|
264 } |
|
265 |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // TUtil::GetDateTimeTextL |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 void TUtil::GetDateTimeTextL( TDes& aText, TTime aDateTime ) |
|
272 { |
|
273 TDateTime dt = aDateTime.DateTime(); |
|
274 aText.Format(_L("%02d.%02d.%04d %02d:%02d:%02d"), dt.Day()+1, |
|
275 dt.Month()+1, |
|
276 dt.Year(), |
|
277 dt.Hour(), |
|
278 dt.Minute(), |
|
279 dt.Second() ); |
|
280 } |
|
281 |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // TUtil::SettingEnforcementStateL |
|
285 // |
|
286 // Checks if setting enforcement is activated. |
|
287 // --------------------------------------------------------- |
|
288 TBool TUtil::SettingEnforcementStateL() |
|
289 { |
|
290 FeatureManager::InitializeLibL(); |
|
291 if(!FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement)) |
|
292 { |
|
293 FeatureManager::UnInitializeLib(); |
|
294 return EFalse; |
|
295 } |
|
296 else |
|
297 { |
|
298 FeatureManager::UnInitializeLib(); |
|
299 CSettingEnforcementInfo* info = CSettingEnforcementInfo::NewL(); |
|
300 CleanupStack::PushL(info); |
|
301 |
|
302 TBool active = EFalse; |
|
303 User::LeaveIfError(info->EnforcementActive(ESyncMLEnforcement, active)); |
|
304 CleanupStack::PopAndDestroy(info); |
|
305 |
|
306 return active; |
|
307 } |
|
308 |
|
309 } |
|
310 |
|
311 |
|
312 // --------------------------------------------------------- |
|
313 // TUtil::SettingEnforcementState |
|
314 // |
|
315 // Checks if setting enforcement is activated. |
|
316 // --------------------------------------------------------- |
|
317 TBool TUtil::SettingEnforcementState() |
|
318 { |
|
319 TBool ret = EFalse; |
|
320 |
|
321 TRAP_IGNORE(ret = SettingEnforcementStateL()); |
|
322 |
|
323 return ret; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // TUtil::iDMNotifier |
|
328 // --------------------------------------------------------- |
|
329 CDMNativeNotifier* TUtil::iDMNotifier=NULL; |
|
330 |
|
331 // --------------------------------------------------------- |
|
332 // TUtil::ShowDialogBox |
|
333 // |
|
334 // Shows the requested dialog |
|
335 // --------------------------------------------------------- |
|
336 TInt TUtil::ShowNativeDialogL(TInt aOperation) |
|
337 { |
|
338 CRepository* centrep = NULL; |
|
339 TInt disclaimerAccepted(0); |
|
340 RImplInfoPtrArray dmImplArray; |
|
341 CleanupClosePushL(dmImplArray); |
|
342 |
|
343 CDMNativeNotifier::ListImplementationsL(dmImplArray); |
|
344 |
|
345 TInt rval = -1; |
|
346 switch(aOperation) |
|
347 { |
|
348 case EPrivacyPolicy: |
|
349 { |
|
350 //Check for implementations and set cenrep if count = 0 |
|
351 if( dmImplArray.Count() == 0 ) //No implementations found |
|
352 { |
|
353 centrep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys ); |
|
354 if(centrep) |
|
355 { |
|
356 centrep->Get( KDMDisclaimerAccepted , disclaimerAccepted ); |
|
357 if(disclaimerAccepted != EDMDialogNotAccepted) |
|
358 { |
|
359 disclaimerAccepted=1; |
|
360 centrep->Set( KDMDisclaimerAccepted , disclaimerAccepted ); //for Disclaimer |
|
361 } |
|
362 CleanupStack::PopAndDestroy(centrep); |
|
363 dmImplArray.ResetAndDestroy(); |
|
364 CleanupStack :: PopAndDestroy(&dmImplArray); |
|
365 return KErrNone ; |
|
366 } |
|
367 } |
|
368 TUid id( dmImplArray[0]->ImplementationUid()); |
|
369 dmImplArray.ResetAndDestroy(); |
|
370 CleanupStack :: PopAndDestroy(&dmImplArray); |
|
371 |
|
372 centrep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys ); |
|
373 if (centrep ) |
|
374 { |
|
375 centrep->Get( KDMDisclaimerAccepted , disclaimerAccepted ); //for Disclaimer |
|
376 CleanupStack::PopAndDestroy(centrep); |
|
377 } |
|
378 if(disclaimerAccepted==EDMDialogAccepted) |
|
379 { |
|
380 return KErrNone; |
|
381 } |
|
382 else |
|
383 { |
|
384 if(iDMNotifier == NULL) |
|
385 { |
|
386 iDMNotifier = CDMNativeNotifier::NewL(id); |
|
387 } |
|
388 if(disclaimerAccepted==EDMDialogActive) |
|
389 { |
|
390 rval = iDMNotifier->ShowDialogL(EPrivacyPolicy); |
|
391 } |
|
392 else if(disclaimerAccepted==EDMDialogNotAccepted) |
|
393 { |
|
394 rval = iDMNotifier->ShowDialogL(EPrivacyPolicy); |
|
395 delete iDMNotifier; |
|
396 iDMNotifier=NULL; |
|
397 REComSession::FinalClose(); |
|
398 } |
|
399 } |
|
400 break; |
|
401 } |
|
402 } |
|
403 |
|
404 return rval; |
|
405 } |
|
406 /***************************************************************************** |
|
407 * class TURIParser |
|
408 *****************************************************************************/ |
|
409 |
|
410 // ---------------------------------------------------------------------------- |
|
411 // Constructor |
|
412 // ---------------------------------------------------------------------------- |
|
413 // |
|
414 TURIParser::TURIParser( const TDesC& aStr ) : iOriginalStr( aStr ) |
|
415 { |
|
416 SkipHttp(); |
|
417 } |
|
418 |
|
419 // ---------------------------------------------------------------------------- |
|
420 // GetUriWithoutPort |
|
421 // URI format: "http://serveraddress/documentname/" |
|
422 // ---------------------------------------------------------------------------- |
|
423 // |
|
424 void TURIParser::GetUriWithoutPort( TDes& aText ) |
|
425 { |
|
426 aText = KNullDesC; |
|
427 TPtrC http = ParseHttp(); |
|
428 TPtrC address = ParseAddress(); |
|
429 TPtrC document = ParseDocument(); |
|
430 TUtil::StrAppend( aText, http ); |
|
431 TUtil::StrAppend( aText, address ); |
|
432 |
|
433 if (document.Length() > 0) |
|
434 { |
|
435 TUtil::StrAppend( aText, KSlash ); |
|
436 TUtil::StrAppend( aText, document ); |
|
437 } |
|
438 else if ( iSlash ) |
|
439 { |
|
440 TUtil::StrAppend( aText, KSlash ); |
|
441 } |
|
442 } |
|
443 |
|
444 // ---------------------------------------------------------------------------- |
|
445 // GetURI |
|
446 // URI format: "http://serveraddress:port/documentname/" |
|
447 // ---------------------------------------------------------------------------- |
|
448 // |
|
449 void TURIParser::GetUri( TDes& aText, const TInt aPort ) |
|
450 { |
|
451 aText = KNullDesC; |
|
452 TPtrC http = ParseHttp(); |
|
453 TPtrC address = ParseAddress(); |
|
454 TPtrC document = ParseDocument(); |
|
455 TUtil::StrAppend( aText, http ); |
|
456 TUtil::StrAppend( aText, address ); |
|
457 |
|
458 TBuf<KBufSize32> buf; |
|
459 buf.Num( aPort ); |
|
460 TUtil::StrAppend( aText, KColon ); |
|
461 TUtil::StrAppend( aText, buf ); |
|
462 |
|
463 if ( document.Length() > 0 ) |
|
464 { |
|
465 TUtil::StrAppend( aText, KSlash ); |
|
466 TUtil::StrAppend( aText, document ); |
|
467 } |
|
468 else if ( iSlash ) |
|
469 { |
|
470 TUtil::StrAppend( aText, KSlash ); |
|
471 } |
|
472 } |
|
473 |
|
474 // ---------------------------------------------------------------------------- |
|
475 // Port |
|
476 // ---------------------------------------------------------------------------- |
|
477 // |
|
478 TInt TURIParser::Port() |
|
479 { |
|
480 TInt port = KErrNotFound; |
|
481 |
|
482 TInt err = ParsePort( port ); |
|
483 if ( err != KErrNone ) |
|
484 { |
|
485 return KErrNotFound; |
|
486 } |
|
487 return port; |
|
488 } |
|
489 |
|
490 // ---------------------------------------------------------------------------- |
|
491 // DefaultPort |
|
492 // |
|
493 // ---------------------------------------------------------------------------- |
|
494 // |
|
495 TInt TURIParser::DefaultPort() |
|
496 { |
|
497 TInt pos = iOriginalStr.FindF( KHttpsHeader ); |
|
498 if ( pos != KErrNotFound ) |
|
499 { |
|
500 return KDefaultHttpsPort; |
|
501 } |
|
502 return KDefaultHttpPort; |
|
503 } |
|
504 |
|
505 // ---------------------------------------------------------------------------- |
|
506 // SkipHttp |
|
507 // Set pointer to the end of "http://". |
|
508 // ---------------------------------------------------------------------------- |
|
509 // |
|
510 void TURIParser::SkipHttp() |
|
511 { |
|
512 TInt start = KErrNotFound; |
|
513 TInt end = KErrNotFound; |
|
514 TStr str(iOriginalStr); |
|
515 |
|
516 GetHttpPos( start, end ); |
|
517 |
|
518 if ( start != KErrNotFound ) |
|
519 { |
|
520 iPtr.Set( str.Right( end + 1 ) ); |
|
521 } |
|
522 else |
|
523 { |
|
524 iPtr.Set( str.Right(0) ); |
|
525 } |
|
526 } |
|
527 |
|
528 // ---------------------------------------------------------------------------- |
|
529 // ParseHttp |
|
530 // |
|
531 // ---------------------------------------------------------------------------- |
|
532 // |
|
533 TPtrC TURIParser::ParseHttp() |
|
534 { |
|
535 TInt start = KErrNotFound; |
|
536 TInt end = KErrNotFound; |
|
537 |
|
538 GetHttpPos(start, end); |
|
539 |
|
540 if (start == KErrNotFound) |
|
541 { |
|
542 return TPtrC(); |
|
543 } |
|
544 |
|
545 TStr str(iOriginalStr); |
|
546 return str.SubStr(start, end); |
|
547 } |
|
548 |
|
549 // ---------------------------------------------------------------------------- |
|
550 // GetHttpPos |
|
551 // ---------------------------------------------------------------------------- |
|
552 // |
|
553 void TURIParser::GetHttpPos( TInt& aStartPos, TInt& aEndPos ) |
|
554 { |
|
555 aEndPos = KErrNotFound; |
|
556 |
|
557 aStartPos = iOriginalStr.FindF( KHttpHeader ); |
|
558 if ( aStartPos != KErrNotFound ) |
|
559 { |
|
560 aEndPos = aStartPos + KHttpHeader().Length() - 1; |
|
561 return; |
|
562 } |
|
563 |
|
564 aStartPos = iOriginalStr.FindF( KHttpsHeader ); |
|
565 if ( aStartPos != KErrNotFound ) |
|
566 { |
|
567 aEndPos = aStartPos + KHttpsHeader().Length() - 1; |
|
568 return; |
|
569 } |
|
570 } |
|
571 |
|
572 // ---------------------------------------------------------------------------- |
|
573 // ParseAddress |
|
574 // ---------------------------------------------------------------------------- |
|
575 TPtrC TURIParser::ParseAddress() |
|
576 { |
|
577 const TChar KSlash('/'); |
|
578 const TChar KColon(':'); |
|
579 TStr str( iPtr ); |
|
580 TInt firstSlash = str.Find( 0, KSlash ); |
|
581 TInt firstcolon = str.Find( 0, KColon ); |
|
582 TBool portFound = EFalse; |
|
583 iSlash = EFalse; |
|
584 if ( firstSlash != KErrNotFound ) |
|
585 { |
|
586 iSlash = ETrue; |
|
587 } |
|
588 if (firstcolon != KErrNotFound) |
|
589 { |
|
590 if ( firstSlash == KErrNotFound ) |
|
591 { |
|
592 portFound = ETrue; |
|
593 } |
|
594 else if ( firstcolon < firstSlash ) |
|
595 { |
|
596 portFound = ETrue; |
|
597 } |
|
598 } |
|
599 |
|
600 if ( portFound ) |
|
601 { |
|
602 // address is text before first colon |
|
603 return str.Left( firstcolon - 1 ); |
|
604 } |
|
605 else if (firstSlash != KErrNotFound) |
|
606 { |
|
607 // address is text before first slash |
|
608 return str.Left( firstSlash - 1 ); |
|
609 } |
|
610 else |
|
611 { |
|
612 // address is all text |
|
613 return str.Right( 0 ); |
|
614 } |
|
615 } |
|
616 |
|
617 // ---------------------------------------------------------------------------- |
|
618 // ParseDocument |
|
619 // ---------------------------------------------------------------------------- |
|
620 TPtrC TURIParser::ParseDocument() |
|
621 { |
|
622 const TChar KSlash('/'); |
|
623 |
|
624 TStr str(iPtr); |
|
625 TInt firstSlash = str.Find( 0, KSlash ); |
|
626 |
|
627 if ( firstSlash != KErrNotFound ) |
|
628 { |
|
629 // document is all text after first slash |
|
630 return str.Right( firstSlash + 1 ); |
|
631 } |
|
632 return TPtrC(); |
|
633 } |
|
634 |
|
635 // ---------------------------------------------------------------------------- |
|
636 // ParsePort |
|
637 // ---------------------------------------------------------------------------- |
|
638 // |
|
639 TInt TURIParser::ParsePort( TInt& aNumber ) |
|
640 { |
|
641 TPtrC port = ParsePort(); |
|
642 if ( port.Length() == 0 ) |
|
643 { |
|
644 return KErrNotFound; |
|
645 } |
|
646 return TUtil::StrToInt( port, aNumber ); |
|
647 } |
|
648 |
|
649 // ---------------------------------------------------------------------------- |
|
650 // ParsePort |
|
651 // ---------------------------------------------------------------------------- |
|
652 // |
|
653 TPtrC TURIParser::ParsePort() |
|
654 { |
|
655 const TChar KSlash('/'); |
|
656 const TChar KColon(':'); |
|
657 |
|
658 TStr str(iPtr); |
|
659 TInt firstSlash = str.Find( 0, KSlash ); |
|
660 TInt firstColon = str.Find( 0, KColon ); |
|
661 |
|
662 if ( firstSlash != KErrNotFound ) |
|
663 { |
|
664 if ( firstColon != KErrNotFound && firstColon < firstSlash ) |
|
665 { |
|
666 // port number is text between colon and slash |
|
667 return str.SubStrEx( firstColon, firstSlash ); |
|
668 } |
|
669 } |
|
670 else |
|
671 { |
|
672 if ( firstColon != KErrNotFound ) |
|
673 { |
|
674 // port number is all text after colon |
|
675 return str.Right(firstColon+1); |
|
676 } |
|
677 } |
|
678 return TPtrC(); |
|
679 } |
|
680 |
|
681 /***************************************************************************** |
|
682 * class TStr |
|
683 *****************************************************************************/ |
|
684 |
|
685 // ---------------------------------------------------------------------------- |
|
686 // TStr::TStr |
|
687 // C++ default constructor can NOT contain any code, that |
|
688 // might leave. |
|
689 // ---------------------------------------------------------------------------- |
|
690 // |
|
691 TStr::TStr( const TDesC& aStr ) : iStr( aStr ) |
|
692 { |
|
693 } |
|
694 |
|
695 // ---------------------------------------------------------------------------- |
|
696 // TStr::Mid |
|
697 // ---------------------------------------------------------------------------- |
|
698 // |
|
699 TPtrC TStr::Mid( TInt aPos ) |
|
700 { |
|
701 if ( ( aPos < 0 ) || ( aPos >= iStr.Length() ) ) |
|
702 { |
|
703 return TPtrC(); // return empty descriptor |
|
704 } |
|
705 return iStr.Mid( aPos ); |
|
706 } |
|
707 |
|
708 // ---------------------------------------------------------------------------- |
|
709 // TStr::Mid |
|
710 // ---------------------------------------------------------------------------- |
|
711 // |
|
712 TPtrC TStr::Mid( TInt aPos, TInt aLen ) |
|
713 { |
|
714 TInt len = iStr.Length(); |
|
715 if ( ( aPos < 0 ) || ( aPos >= len ) ) |
|
716 { |
|
717 return TPtrC(); |
|
718 } |
|
719 if ( ( aLen <= 0 ) || ( aPos + aLen > len ) ) |
|
720 { |
|
721 return TPtrC(); |
|
722 } |
|
723 |
|
724 return iStr.Mid( aPos, aLen ); |
|
725 } |
|
726 |
|
727 // ---------------------------------------------------------------------------- |
|
728 // TStr::Right |
|
729 // ---------------------------------------------------------------------------- |
|
730 // |
|
731 TPtrC TStr::Right( TInt aPos ) |
|
732 { |
|
733 return Mid( aPos ); |
|
734 } |
|
735 |
|
736 // ---------------------------------------------------------------------------- |
|
737 // TStr::Left |
|
738 // ---------------------------------------------------------------------------- |
|
739 // |
|
740 TPtrC TStr::Left( TInt aPos ) |
|
741 { |
|
742 TInt len = iStr.Length(); |
|
743 |
|
744 if ( ( aPos < 0 ) || ( len == 0 ) ) |
|
745 { |
|
746 return TPtrC(); |
|
747 } |
|
748 |
|
749 TInt pos = len; |
|
750 if ( ( aPos + 1 ) < len ) |
|
751 { |
|
752 pos = aPos + 1; |
|
753 } |
|
754 |
|
755 return iStr.Left( pos ); |
|
756 } |
|
757 |
|
758 // ---------------------------------------------------------------------------- |
|
759 // TStr::SubStr |
|
760 // ---------------------------------------------------------------------------- |
|
761 // |
|
762 TPtrC TStr::SubStr( TInt aStartPos, TInt aEndPos ) |
|
763 { |
|
764 return Mid( aStartPos, aEndPos - aStartPos + 1 ); |
|
765 } |
|
766 |
|
767 // ---------------------------------------------------------------------------- |
|
768 // TStr::SubStrEx |
|
769 // ---------------------------------------------------------------------------- |
|
770 // |
|
771 TPtrC TStr::SubStrEx( TInt aStartPos, TInt aEndPos ) |
|
772 { |
|
773 return Mid( aStartPos + 1, aEndPos - aStartPos - 1 ); |
|
774 } |
|
775 |
|
776 // ---------------------------------------------------------------------------- |
|
777 // TStr::LastPos |
|
778 // ---------------------------------------------------------------------------- |
|
779 // |
|
780 TInt TStr::LastPos() |
|
781 { |
|
782 return iStr.Length() - 1; |
|
783 } |
|
784 |
|
785 // ---------------------------------------------------------------------------- |
|
786 // TStr::Len |
|
787 // ---------------------------------------------------------------------------- |
|
788 // |
|
789 TInt TStr::Len() |
|
790 { |
|
791 return iStr.Length(); |
|
792 } |
|
793 |
|
794 // ---------------------------------------------------------------------------- |
|
795 // TStr::Compare |
|
796 // ---------------------------------------------------------------------------- |
|
797 // |
|
798 TBool TStr::Compare( TInt aPos, TChar aChar ) |
|
799 { |
|
800 TInt len = iStr.Length(); |
|
801 if ( ( aPos < 0) || ( aPos >= len ) ) |
|
802 { |
|
803 return EFalse; |
|
804 } |
|
805 TChar ch = iStr[aPos]; |
|
806 if ( ch == aChar ) |
|
807 { |
|
808 return ETrue; |
|
809 } |
|
810 return EFalse; |
|
811 } |
|
812 |
|
813 // ---------------------------------------------------------------------------- |
|
814 // TStr::Find |
|
815 // ---------------------------------------------------------------------------- |
|
816 // |
|
817 TInt TStr::Find(TInt aPos, TChar aChar) |
|
818 { |
|
819 TInt len = iStr.Length(); |
|
820 if ( (aPos < 0) || (aPos >= len) ) |
|
821 { |
|
822 return KErrNotFound; |
|
823 } |
|
824 |
|
825 TPtrC ptr(iStr.Mid(aPos)); // move to possition aPos |
|
826 return ptr.Locate(aChar); |
|
827 } |
|
828 |
|
829 //***************************************************************************** |
|
830 //* class CNSmlDMActiveCaller |
|
831 //***************************************************************************** |
|
832 |
|
833 // ---------------------------------------------------------------------------- |
|
834 // CNSmlDMActiveCaller::NewL |
|
835 // ---------------------------------------------------------------------------- |
|
836 // |
|
837 CNSmlDMActiveCaller* CNSmlDMActiveCaller::NewL( |
|
838 MNSmlDMActiveCallerObserver* aObserver ) |
|
839 { |
|
840 CNSmlDMActiveCaller* self = new(ELeave) CNSmlDMActiveCaller( aObserver ); |
|
841 CleanupStack::PushL(self); |
|
842 self->ConstructL(); |
|
843 CleanupStack::Pop(self); |
|
844 |
|
845 return self; |
|
846 } |
|
847 |
|
848 // ---------------------------------------------------------------------------- |
|
849 // Destructor |
|
850 // ---------------------------------------------------------------------------- |
|
851 // |
|
852 CNSmlDMActiveCaller::~CNSmlDMActiveCaller() |
|
853 { |
|
854 Cancel(); |
|
855 iTimer.Close(); |
|
856 } |
|
857 |
|
858 // ---------------------------------------------------------------------------- |
|
859 // CNSmlDMActiveCaller::CNSmlDMActiveCaller |
|
860 // ---------------------------------------------------------------------------- |
|
861 // |
|
862 CNSmlDMActiveCaller::CNSmlDMActiveCaller( |
|
863 MNSmlDMActiveCallerObserver* aObserver ) |
|
864 : CActive(CActive::EPriorityStandard ) |
|
865 { |
|
866 iObserver = aObserver; |
|
867 } |
|
868 |
|
869 // ---------------------------------------------------------------------------- |
|
870 // CNSmlDMActiveCaller::ConstructL |
|
871 // ---------------------------------------------------------------------------- |
|
872 // |
|
873 void CNSmlDMActiveCaller::ConstructL() |
|
874 { |
|
875 User::LeaveIfError(iTimer.CreateLocal()); |
|
876 CActiveScheduler::Add(this); |
|
877 } |
|
878 |
|
879 // ---------------------------------------------------------------------------- |
|
880 // CNSmlDMActiveCaller::DoCancel |
|
881 // ---------------------------------------------------------------------------- |
|
882 // |
|
883 void CNSmlDMActiveCaller::DoCancel() |
|
884 { |
|
885 iTimer.Cancel(); |
|
886 } |
|
887 |
|
888 // ---------------------------------------------------------------------------- |
|
889 // CNSmlDMActiveCaller::RunL |
|
890 // ---------------------------------------------------------------------------- |
|
891 // |
|
892 void CNSmlDMActiveCaller::RunL() |
|
893 { |
|
894 iObserver->HandleActiveCallL( ); |
|
895 } |
|
896 |
|
897 // ---------------------------------------------------------------------------- |
|
898 // CNSmlDMActiveCaller::RunError |
|
899 // ---------------------------------------------------------------------------- |
|
900 // |
|
901 TInt CNSmlDMActiveCaller::RunError( TInt /*aError*/ ) |
|
902 { |
|
903 return KErrNone; |
|
904 } |
|
905 |
|
906 // ---------------------------------------------------------------------------- |
|
907 // CNSmlDMActiveCaller::CompleteSelf |
|
908 // |
|
909 // This function calls this class RunL. |
|
910 // ---------------------------------------------------------------------------- |
|
911 // |
|
912 void CNSmlDMActiveCaller::CompleteSelf() |
|
913 { |
|
914 SetActive(); |
|
915 TRequestStatus* status = &iStatus; |
|
916 User::RequestComplete( status, KErrNone ); |
|
917 } |
|
918 |
|
919 // ---------------------------------------------------------------------------- |
|
920 // CNSmlDMActiveCaller::Start |
|
921 // ---------------------------------------------------------------------------- |
|
922 // |
|
923 void CNSmlDMActiveCaller::Start( TInt aCallId, TInt aMilliseconds ) |
|
924 { |
|
925 if (IsActive()) |
|
926 { |
|
927 return; |
|
928 } |
|
929 |
|
930 iCallId = aCallId; |
|
931 |
|
932 if (aMilliseconds <= 0) |
|
933 { |
|
934 CompleteSelf(); // no delay - complete right away |
|
935 } |
|
936 else |
|
937 { |
|
938 iTimer.After( iStatus, aMilliseconds*1000 ); |
|
939 SetActive(); |
|
940 } |
|
941 } |
|
942 |
|
943 // End of File |