|
1 /* |
|
2 * Copyright (c) 2004 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: Utils for IM api. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "apiutils.h" |
|
22 |
|
23 #include <CImpssapsettingsstore.h> |
|
24 #include <CImpssapsettings.h> |
|
25 #include <CImpsSAPSettingsList.h> |
|
26 #include <CImpsSAPSettingsListItem.h> |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KLogBufferLength = 256; |
|
30 |
|
31 _LIT( KLogDir, "impsc" ); |
|
32 _LIT( KLogFile, "imapi.txt" ); |
|
33 |
|
34 void CImApiLogger::Log( TRefByValue<const TDesC> aFmt, ... ) |
|
35 { |
|
36 VA_LIST list; |
|
37 VA_START( list, aFmt ); |
|
38 |
|
39 // Print to log file |
|
40 TBuf<KLogBufferLength> buf; |
|
41 buf.FormatList( aFmt, list ); |
|
42 |
|
43 // Write to log file |
|
44 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, buf ); |
|
45 |
|
46 } |
|
47 |
|
48 |
|
49 const TDesC* SSapSettingsReader::ClientIdLC( const TDesC& aSapUrl ) |
|
50 { |
|
51 TBool isFound( EFalse ); |
|
52 HBufC* retVal( NULL ); |
|
53 _LIT( httpString, "http://" ); |
|
54 TChar slash( '/' ); |
|
55 TPtrC16 wohttpstr; |
|
56 TPtrC16 wohttpstr2; |
|
57 wohttpstr.Set( aSapUrl ); |
|
58 |
|
59 // parsing aSAPUrl |
|
60 if ( ( wohttpstr.Find( httpString ) == NULL ) ) // if string is found at the begining |
|
61 wohttpstr.Set( wohttpstr.Mid( httpString().Length() ) ); |
|
62 |
|
63 // search for / at the end |
|
64 if ( ( wohttpstr.LocateReverse( slash ) ) == ( ( wohttpstr.Length() ) - 1 ) ) |
|
65 wohttpstr.Set( wohttpstr.Left( ( ( wohttpstr.Length() ) - 1 ) ) ); |
|
66 |
|
67 |
|
68 CIMPSSAPSettingsStore* store = CIMPSSAPSettingsStore::NewLC(); // <<< |
|
69 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); // <<< |
|
70 store->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
71 |
|
72 for ( TInt i = 0; i < sapList->MdcaCount(); ++i ) |
|
73 { |
|
74 CIMPSSAPSettings* sapSettings = CIMPSSAPSettings::NewLC(); // <<< |
|
75 store->GetSAPL( sapList->At( i )->Uid(), sapSettings ); |
|
76 const TDesC& server = sapSettings->SAPAddress(); |
|
77 if ( server.Length() <= 0 ) |
|
78 { |
|
79 CleanupStack::PopAndDestroy( 1 ); // sapSettings |
|
80 continue; |
|
81 } |
|
82 wohttpstr2.Set( server ); |
|
83 |
|
84 // parsing aSAPUrl |
|
85 if ( ( wohttpstr2.Find( httpString ) == NULL ) ) // if string found at the begining |
|
86 wohttpstr2.Set( wohttpstr2.Mid( httpString().Length() ) ); |
|
87 |
|
88 // search for / at the end |
|
89 if ( ( wohttpstr2.LocateReverse( slash ) ) == ( ( wohttpstr2.Length() ) - 1 ) ) |
|
90 wohttpstr2.Set( wohttpstr2.Left( ( ( wohttpstr2.Length() ) - 1 ) ) ); |
|
91 |
|
92 if ( wohttpstr == wohttpstr2 ) |
|
93 { |
|
94 isFound = ETrue; |
|
95 retVal = ( sapSettings->ClientId() ).AllocL(); |
|
96 CleanupStack::PopAndDestroy( 1 ); // sapSettings |
|
97 break; |
|
98 } |
|
99 else |
|
100 { |
|
101 CleanupStack::PopAndDestroy( 1 ); // sapSettings |
|
102 } |
|
103 } |
|
104 CleanupStack::PopAndDestroy( 2 ); // >>> sapList, store |
|
105 |
|
106 if ( !isFound ) |
|
107 { |
|
108 retVal = KImOpenAppID().AllocLC(); |
|
109 } |
|
110 else |
|
111 CleanupStack::PushL( retVal ); |
|
112 |
|
113 return retVal; |
|
114 } |
|
115 |
|
116 // End of File |