22
|
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 |
const TInt maxModifyLength =
|
|
179 |
KMaxNodeNameLength - KMaxProfileNameAppendLength;
|
|
180 |
RArray<TInt> settingIds;
|
|
181 |
CleanupClosePushL( settingIds ); // CS:1
|
|
182 |
// CS:2
|
|
183 |
CDesCArray* names = TXdmSettingsApi::CollectionNamesLC( settingIds );
|
|
184 |
|
|
185 |
HBufC* newName = HBufC::NewLC( KMaxNodeNameLength ); // CS:3
|
|
186 |
newName->Des().Copy( aName.Left( maxModifyLength ) );
|
|
187 |
const TInt count( names->MdcaCount() );
|
|
188 |
TUint i( 1 ); // Add number to the name if name already in use.
|
|
189 |
|
|
190 |
// Go through each profile and see if the name of the new profile
|
|
191 |
// matches one of the existing names. If it does change it and
|
|
192 |
// check the new name again.
|
|
193 |
for ( TInt counter = 0; counter < count; counter++ )
|
|
194 |
{
|
|
195 |
TBuf<KMaxNodeValueLength> loadedName;
|
|
196 |
loadedName.Copy( names->MdcaPoint( counter ));
|
|
197 |
if ( 0 == newName->Des().Compare( loadedName ) )
|
|
198 |
{
|
|
199 |
// If the name is changed we need to begin the comparison
|
|
200 |
// again from the first profile.
|
|
201 |
newName->Des().Copy( aName.Left( maxModifyLength ) );
|
|
202 |
newName->Des().Append( KOpenParenthesis() );
|
|
203 |
newName->Des().AppendNum( i );
|
|
204 |
newName->Des().Append( KClosedParenthesis() );
|
|
205 |
counter = 0;
|
|
206 |
i++;
|
|
207 |
if ( KMaxProfileNames < i )
|
|
208 |
{
|
|
209 |
User::Leave( KErrBadName );
|
|
210 |
}
|
|
211 |
}
|
|
212 |
}
|
|
213 |
aName.Copy( newName->Des() );
|
|
214 |
|
|
215 |
// newName, names, &settingIds
|
|
216 |
CleanupStack::PopAndDestroy( 3, &settingIds );
|
|
217 |
DBG_PRINT( "CVoipXmlXdmHandler::CreateProviderNameL end" );
|
|
218 |
}
|
|
219 |
|
|
220 |
// End of file.
|