1 /* |
|
2 * Copyright (c) 2009-2010 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: XDM handler for VoIP XML processor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32cmn.h> |
|
20 #include <coecntrl.h> |
|
21 #include <xdmsettingsapi.h> |
|
22 #include <XdmSettingsCollection.h> |
|
23 #include <sysutil.h> |
|
24 #include <pathinfo.h> |
|
25 #include <Authority16.h> |
|
26 #include <stringloader.h> |
|
27 #include <escapeutils.h> |
|
28 |
|
29 #include "voipxmlutils.h" |
|
30 #include "voipxmlxdmhandler.h" |
|
31 #include "voipxmlprocessorlogger.h" |
|
32 #include "voipxmlprocessordefaults.h" |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CVoipXmlXdmHandler::CVoipXmlXdmHandler |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CVoipXmlXdmHandler::CVoipXmlXdmHandler() |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CVoipXmlXdmHandler::NewL |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CVoipXmlXdmHandler* CVoipXmlXdmHandler::NewL() |
|
47 { |
|
48 CVoipXmlXdmHandler* self = new ( ELeave ) CVoipXmlXdmHandler; |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CVoipXmlXdmHandler::ConstructL |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 void CVoipXmlXdmHandler::ConstructL() |
|
60 { |
|
61 DBG_PRINT( "CVoipXmlXdmHandler::ConstructL begin" ); |
|
62 iProfile = new (ELeave) CXdmSettingsCollection(); |
|
63 iProfile->AppendL( KDefaultXdmAuthType, EXdmPropAuthType ); |
|
64 iProfile->AppendL( KDefaultXdmUri, EXdmPropUri ); |
|
65 DBG_PRINT( "CVoipXmlXdmHandler::ConstructL end" ); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CVoipXmlXdmHandler::~CVoipXmlXdmHandler |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CVoipXmlXdmHandler::~CVoipXmlXdmHandler() |
|
73 { |
|
74 delete iProfile; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Sets XDM setting. |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CVoipXmlXdmHandler::SetSetting( TInt aParam, const TDesC& aValue ) |
|
82 { |
|
83 // Ignore too long descriptors. |
|
84 if ( KMaxNodeValueLength < aValue.Length() ) |
|
85 { |
|
86 return; |
|
87 } |
|
88 |
|
89 TRAP_IGNORE( SetSettingL( aParam, aValue ) ); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Stores settings through XDM settings API. |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 TInt CVoipXmlXdmHandler::StoreSettings() |
|
97 { |
|
98 if ( !iSettingsSet ) |
|
99 { |
|
100 // No settings to be stored => method not supported. |
|
101 return KErrNotSupported; |
|
102 } |
|
103 TRAPD( err, iProfileId = TXdmSettingsApi::CreateCollectionL( *iProfile )); |
|
104 if ( KErrNone != err ) |
|
105 { |
|
106 err = KErrCompletion; |
|
107 } |
|
108 return err; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Returns the profile ID if the profile saved in StoreSettings. |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 TUint32 CVoipXmlXdmHandler::SettingsId() |
|
116 { |
|
117 return iProfileId; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // Sets XDM setting. |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CVoipXmlXdmHandler::SetSettingL( TInt aParam, const TDesC& aValue ) |
|
125 { |
|
126 switch ( aParam ) |
|
127 { |
|
128 case EName: |
|
129 { |
|
130 TBuf<KMaxNodeValueLength> name( KNullDesC ); |
|
131 name.Copy( aValue ); |
|
132 CreateProviderNameL( name ); |
|
133 iProfile->AppendL( name, EXdmPropName ); |
|
134 iSettingsSet = ETrue; |
|
135 break; |
|
136 } |
|
137 case EType: |
|
138 { |
|
139 // First remove default value. |
|
140 iProfile->RemoveL( EXdmPropAuthType ); |
|
141 iProfile->AppendL( aValue, EXdmPropAuthType ); |
|
142 iSettingsSet = ETrue; |
|
143 break; |
|
144 } |
|
145 case EUri: |
|
146 { |
|
147 // First remove default value. |
|
148 iProfile->RemoveL( EXdmPropUri ); |
|
149 iProfile->AppendL( aValue, EXdmPropUri ); |
|
150 iSettingsSet = ETrue; |
|
151 break; |
|
152 } |
|
153 case EUsername: |
|
154 { |
|
155 iProfile->AppendL( aValue, EXdmPropAuthName ); |
|
156 iSettingsSet = ETrue; |
|
157 break; |
|
158 } |
|
159 case EPassword: |
|
160 { |
|
161 iProfile->AppendL( aValue, EXdmPropAuthSecret ); |
|
162 iSettingsSet = ETrue; |
|
163 break; |
|
164 } |
|
165 default: |
|
166 break; |
|
167 } |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // Checks for duplicate named XDM sets. Renames if same. |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CVoipXmlXdmHandler::CreateProviderNameL( TDes& aName ) |
|
175 { |
|
176 DBG_PRINT( "CVoipXmlXdmHandler::CreateProviderNameL begin" ); |
|
177 |
|
178 RArray<TInt> settingIds; |
|
179 CleanupClosePushL( settingIds ); // CS:1 |
|
180 // CS:2 |
|
181 CDesCArray* names = TXdmSettingsApi::CollectionNamesLC( settingIds ); |
|
182 |
|
183 HBufC* newName = HBufC::NewLC( KMaxNodeNameLength ); // CS:3 |
|
184 newName->Des().Copy( aName ); |
|
185 const TInt count( names->MdcaCount() ); |
|
186 TUint i( 1 ); // Add number to the name if name already in use. |
|
187 |
|
188 // Go through each profile and see if the name of the new profile |
|
189 // matches one of the existing names. If it does change it and |
|
190 // check the new name again. |
|
191 for ( TInt counter = 0; counter < count; counter++ ) |
|
192 { |
|
193 TBuf<KMaxNodeValueLength> loadedName; |
|
194 loadedName.Copy( names->MdcaPoint( counter )); |
|
195 if ( 0 == newName->Des().Compare( loadedName ) ) |
|
196 { |
|
197 // If the name is changed we need to begin the comparison |
|
198 // again from the first profile. |
|
199 newName->Des().Copy( aName ); |
|
200 newName->Des().Append( KOpenParenthesis() ); |
|
201 newName->Des().AppendNum( i ); |
|
202 newName->Des().Append( KClosedParenthesis() ); |
|
203 counter = 0; |
|
204 i++; |
|
205 if ( KMaxProfileNames < i ) |
|
206 { |
|
207 User::Leave( KErrBadName ); |
|
208 } |
|
209 } |
|
210 } |
|
211 aName.Copy( newName->Des() ); |
|
212 |
|
213 // newName, names, &settingIds |
|
214 CleanupStack::PopAndDestroy( 3, &settingIds ); |
|
215 DBG_PRINT( "CVoipXmlXdmHandler::CreateProviderNameL end" ); |
|
216 } |
|
217 |
|
218 // End of file. |
|