28
|
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: Presence handler for VoIP XML processor
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32cmn.h>
|
|
20 |
#include <coecntrl.h>
|
|
21 |
#include <pressettingsapi.h>
|
|
22 |
#include <pressettingsset.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 "voipxmlpresencehandler.h"
|
|
31 |
#include "voipxmlprocessorlogger.h"
|
|
32 |
#include "voipxmlprocessordefaults.h"
|
|
33 |
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
// Default constructor.
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CVoipXmlPresenceHandler::CVoipXmlPresenceHandler()
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
// Constructor.
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
CVoipXmlPresenceHandler* CVoipXmlPresenceHandler::NewL()
|
|
47 |
{
|
|
48 |
CVoipXmlPresenceHandler* self = new ( ELeave ) CVoipXmlPresenceHandler;
|
|
49 |
CleanupStack::PushL( self );
|
|
50 |
self->ConstructL();
|
|
51 |
CleanupStack::Pop( self );
|
|
52 |
return self;
|
|
53 |
}
|
|
54 |
|
|
55 |
// ---------------------------------------------------------------------------
|
|
56 |
// Constructor.
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
void CVoipXmlPresenceHandler::ConstructL()
|
|
60 |
{
|
|
61 |
iProfile.iObjectSize = KMaxObjectSize;
|
|
62 |
iProfile.iPublicationInt = KPublishInterval;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// Destructor.
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
CVoipXmlPresenceHandler::~CVoipXmlPresenceHandler()
|
|
70 |
{
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
// Sets Presence setting.
|
|
75 |
// ---------------------------------------------------------------------------
|
|
76 |
//
|
|
77 |
void CVoipXmlPresenceHandler::SetSetting( TInt aParam, const TDesC& aValue )
|
|
78 |
{
|
|
79 |
// Ignore too long descriptors.
|
|
80 |
if ( KMaxNodeValueLength < aValue.Length() )
|
|
81 |
{
|
|
82 |
return;
|
|
83 |
}
|
|
84 |
|
|
85 |
TInt intVal( KErrNotFound );
|
|
86 |
switch ( aParam )
|
|
87 |
{
|
|
88 |
case EName:
|
|
89 |
{
|
|
90 |
TBuf<KMaxNodeValueLength> name( KNullDesC );
|
|
91 |
name.Copy( aValue );
|
|
92 |
TRAPD( err, CreateProviderNameL( name ) );
|
|
93 |
if ( KErrNone == err )
|
|
94 |
{
|
|
95 |
iProfile.iSetName.Copy( name );
|
|
96 |
iSettingsSet = ETrue;
|
|
97 |
}
|
|
98 |
break;
|
|
99 |
}
|
|
100 |
case EMaxObjectSize:
|
|
101 |
{
|
|
102 |
if ( KErrNone == VoipXmlUtils::DesToInt( aValue, intVal ))
|
|
103 |
{
|
|
104 |
iProfile.iObjectSize = intVal;
|
|
105 |
iSettingsSet = ETrue;
|
|
106 |
}
|
|
107 |
break;
|
|
108 |
}
|
|
109 |
case EPublishInterval:
|
|
110 |
{
|
|
111 |
if ( KErrNone == VoipXmlUtils::DesToInt( aValue, intVal ))
|
|
112 |
{
|
|
113 |
iProfile.iPublicationInt = intVal;
|
|
114 |
iSettingsSet = ETrue;
|
|
115 |
}
|
|
116 |
break;
|
|
117 |
}
|
|
118 |
case EMaxSubscriptions:
|
|
119 |
{
|
|
120 |
if ( KErrNone == VoipXmlUtils::DesToInt( aValue, intVal ))
|
|
121 |
{
|
|
122 |
iProfile.iMaxSubscriptions = intVal;
|
|
123 |
iSettingsSet = ETrue;
|
|
124 |
}
|
|
125 |
break;
|
|
126 |
}
|
|
127 |
case EMaxContacts:
|
|
128 |
{
|
|
129 |
if ( KErrNone == VoipXmlUtils::DesToInt( aValue, intVal ))
|
|
130 |
{
|
|
131 |
iProfile.iMaxContactsInList = intVal;
|
|
132 |
iSettingsSet = ETrue;
|
|
133 |
}
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
case EDomainSyntax:
|
|
137 |
{
|
|
138 |
iProfile.iDomainSyntax.Copy( aValue );
|
|
139 |
iSettingsSet = ETrue;
|
|
140 |
break;
|
|
141 |
}
|
|
142 |
default:
|
|
143 |
break;
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
// Stores settings to 'Presence registry', i.e. creates a new Presence set.
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
TInt CVoipXmlPresenceHandler::StoreSettings()
|
|
152 |
{
|
|
153 |
if ( !iSettingsSet )
|
|
154 |
{
|
|
155 |
// No settings to be stored => method not supported.
|
|
156 |
return KErrNotSupported;
|
|
157 |
}
|
|
158 |
iProfile.iStatusOfProps = EPresSettingOpened;
|
|
159 |
TRAPD( err, iProfileId = PresSettingsApi::CreateSetL( iProfile ));
|
|
160 |
if ( KErrNone != err )
|
|
161 |
{
|
|
162 |
err = KErrCompletion;
|
|
163 |
}
|
|
164 |
return err;
|
|
165 |
}
|
|
166 |
|
|
167 |
// ---------------------------------------------------------------------------
|
|
168 |
// Returns the profile ID if the profile saved in StoreSettings.
|
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
TUint32 CVoipXmlPresenceHandler::SettingsId()
|
|
172 |
{
|
|
173 |
return iProfileId;
|
|
174 |
}
|
|
175 |
|
|
176 |
// ---------------------------------------------------------------------------
|
|
177 |
// Links other settings to presence profile.
|
|
178 |
// ---------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
void CVoipXmlPresenceHandler::LinkSettings( TInt aType, TUint32 aSettingsId )
|
|
181 |
{
|
|
182 |
switch ( aType )
|
|
183 |
{
|
|
184 |
case ESip:
|
|
185 |
iProfile.iSipProfile = aSettingsId;
|
|
186 |
break;
|
|
187 |
case EXdm:
|
|
188 |
iProfile.iXDMSetting = aSettingsId;
|
|
189 |
break;
|
|
190 |
default:
|
|
191 |
break;
|
|
192 |
}
|
|
193 |
}
|
|
194 |
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
// Finalizes profile, i.e. stores the profile with linkage information.
|
|
197 |
// ---------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
TInt CVoipXmlPresenceHandler::FinalizeSettings()
|
|
200 |
{
|
|
201 |
TInt err1( KErrNone );
|
|
202 |
TRAPD( err2, err1 = PresSettingsApi::UpdateSetL( iProfile, iProfileId ));
|
|
203 |
if ( KErrNone != err1 || KErrNone != err2 )
|
|
204 |
{
|
|
205 |
err1 = KErrGeneral;
|
|
206 |
}
|
|
207 |
return err1;
|
|
208 |
}
|
|
209 |
|
|
210 |
// ---------------------------------------------------------------------------
|
|
211 |
// Checks for duplicate named Presence profiles. Renames if same.
|
|
212 |
// ---------------------------------------------------------------------------
|
|
213 |
//
|
|
214 |
void CVoipXmlPresenceHandler::CreateProviderNameL( TDes& aName )
|
|
215 |
{
|
|
216 |
DBG_PRINT( "CVoipXmlPresenceHandler::CreateProviderNameL begin" );
|
|
217 |
|
|
218 |
const TInt maxModifyLength =
|
|
219 |
KMaxNodeNameLength - KMaxProfileNameAppendLength;
|
|
220 |
RArray<TInt> settingIds;
|
|
221 |
CleanupClosePushL( settingIds ); // CS:1
|
|
222 |
// CS:2
|
|
223 |
CDesCArray* names = PresSettingsApi::GetAllSetsNamesLC( settingIds );
|
|
224 |
|
|
225 |
HBufC* newName = HBufC::NewLC( KMaxNodeNameLength ); // CS:3
|
|
226 |
newName->Des().Copy( aName.Left( maxModifyLength ) );
|
|
227 |
const TInt count( names->MdcaCount() );
|
|
228 |
TUint i( 1 ); // Add number to the name if name already in use.
|
|
229 |
|
|
230 |
// Go through each profile and see if the name of the new profile
|
|
231 |
// matches one of the existing names. If it does change it and
|
|
232 |
// check the new name again.
|
|
233 |
for ( TInt counter = 0; counter < count; counter++ )
|
|
234 |
{
|
|
235 |
TBuf<KMaxNodeValueLength> loadedName;
|
|
236 |
loadedName.Copy( names->MdcaPoint( counter ));
|
|
237 |
if ( 0 == newName->Des().Compare( loadedName ) )
|
|
238 |
{
|
|
239 |
// If the name is changed we need to begin the comparison
|
|
240 |
// again from the first profile.
|
|
241 |
newName->Des().Copy( aName.Left( maxModifyLength ) );
|
|
242 |
newName->Des().Append( KOpenParenthesis() );
|
|
243 |
newName->Des().AppendNum( i );
|
|
244 |
newName->Des().Append( KClosedParenthesis() );
|
|
245 |
counter = 0;
|
|
246 |
i++;
|
|
247 |
if ( KMaxProfileNames < i )
|
|
248 |
{
|
|
249 |
User::Leave( KErrBadName );
|
|
250 |
}
|
|
251 |
}
|
|
252 |
}
|
|
253 |
aName.Copy( newName->Des() );
|
|
254 |
// newName, names, &settingIds
|
|
255 |
CleanupStack::PopAndDestroy( 3, &settingIds );
|
|
256 |
DBG_PRINT( "CVoipXmlPresenceHandler::CreateProviderNameL end" );
|
|
257 |
}
|
|
258 |
|
|
259 |
// End of file.
|