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: VoIP settings XML handler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <gmxmldocument.h>
|
|
21 |
#include <gmxmltext.h>
|
|
22 |
#include <e32cmn.h>
|
|
23 |
#include <e32def.h>
|
|
24 |
|
|
25 |
#include "voipxmlparser.h"
|
|
26 |
#include "voipxmlparamhandler.h"
|
|
27 |
#include "voipxmlprocessordefaults.h"
|
|
28 |
#include "voipxmlprocessorlogger.h"
|
|
29 |
|
|
30 |
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
// CVoipXmlParser::NewL
|
|
33 |
// ---------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
EXPORT_C CVoipXmlParser* CVoipXmlParser::NewL()
|
|
36 |
{
|
|
37 |
CVoipXmlParser* self = NewLC();
|
|
38 |
CleanupStack::Pop( self );
|
|
39 |
return self;
|
|
40 |
}
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
// CVoipXmlParser::NewLC
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
EXPORT_C CVoipXmlParser* CVoipXmlParser::NewLC()
|
|
47 |
{
|
|
48 |
CVoipXmlParser* self = new ( ELeave ) CVoipXmlParser();
|
|
49 |
CleanupStack::PushL( self );
|
|
50 |
self->ConstructL();
|
|
51 |
return self;
|
|
52 |
}
|
|
53 |
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
// CVoipXmlParser::ConstructL
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
void CVoipXmlParser::ConstructL()
|
|
59 |
{
|
|
60 |
DBG_PRINT( "CVoipXmlParser::ConstructL begin" );
|
|
61 |
|
|
62 |
iParser = CMDXMLParser::NewL( this );
|
|
63 |
iParamHandler = CVoipXmlParamHandler::NewL();
|
|
64 |
iDescription = HBufC::NewL( 0 );
|
|
65 |
iBrandUrl = HBufC::NewL( 0 );
|
|
66 |
|
|
67 |
DBG_PRINT( "CVoipXmlParser::ConstructL end" );
|
|
68 |
}
|
|
69 |
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
// CVoIPXmlHandler::~CVoIPXmlHandler()
|
|
72 |
// Destructor
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
CVoipXmlParser::~CVoipXmlParser()
|
|
76 |
{
|
|
77 |
delete iParser;
|
|
78 |
delete iParamHandler;
|
|
79 |
if ( iXmlDoc )
|
|
80 |
{
|
|
81 |
delete iXmlDoc;
|
|
82 |
}
|
|
83 |
if ( iDescription )
|
|
84 |
{
|
|
85 |
delete iDescription;
|
|
86 |
}
|
|
87 |
if( iBrandUrl )
|
|
88 |
{
|
|
89 |
delete iBrandUrl;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
// CVoipXmlParser::CVoipXmlParser
|
|
95 |
// ---------------------------------------------------------------------------
|
|
96 |
//
|
|
97 |
CVoipXmlParser::CVoipXmlParser()
|
|
98 |
{
|
|
99 |
}
|
|
100 |
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
// CVoipXmlParser::ImportDocumentL
|
|
103 |
// Reads document.
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
EXPORT_C TInt CVoipXmlParser::ImportDocument( RFile& aFile,
|
|
107 |
TUint32& aServiceTabId )
|
|
108 |
{
|
|
109 |
DBG_PRINT( "CVoipXmlParser::ImportDocumentL - begin" );
|
|
110 |
iParseDescription = EFalse;
|
|
111 |
iParser->ParseFile( aFile );
|
|
112 |
CActiveScheduler::Start();
|
|
113 |
if ( KErrNone == iError )
|
|
114 |
{
|
|
115 |
iError = iParamHandler->StoreSettings();
|
|
116 |
}
|
|
117 |
if ( KErrNone == iError )
|
|
118 |
{
|
|
119 |
// Give other applications 2 seconds to react
|
|
120 |
// to the newly created service.
|
|
121 |
const TInt KTwoSeconds( 2000000 );
|
|
122 |
User::After( KTwoSeconds );
|
|
123 |
aServiceTabId = iParamHandler->ServiceTabId();
|
|
124 |
}
|
|
125 |
DBG_PRINT2( "CVoipXmlParser::ImportDocumentL - end (%d)", iError );
|
|
126 |
return iError;
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
// CVoipXmlParser::ReadDescription
|
|
131 |
// Reads document description.
|
|
132 |
// ---------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
EXPORT_C HBufC* CVoipXmlParser::ReadDescriptionLC( RFile& aFile,
|
|
135 |
TDes8& aBrandUrl )
|
|
136 |
{
|
|
137 |
DBG_PRINT( "CVoipXmlParser::ReadDescriptionLC begin" );
|
|
138 |
iParseDescription = ETrue;
|
|
139 |
iParser->ParseFile( aFile );
|
|
140 |
CActiveScheduler::Start();
|
|
141 |
if ( !iDescription )
|
|
142 |
{
|
|
143 |
iDescription = HBufC::NewL( 0 );
|
|
144 |
}
|
|
145 |
HBufC* buf = HBufC::NewLC( iDescription->Des().Length() );
|
|
146 |
buf->Des().Copy( iDescription->Des() );
|
|
147 |
if ( !iBrandUrl )
|
|
148 |
{
|
|
149 |
iBrandUrl = HBufC::NewL( 0 );
|
|
150 |
}
|
|
151 |
aBrandUrl.Copy( iBrandUrl->Des() );
|
|
152 |
DBG_PRINT( "CVoipXmlParser::ReadDescriptionLC end" );
|
|
153 |
return buf;
|
|
154 |
}
|
|
155 |
|
|
156 |
// ---------------------------------------------------------------------------
|
|
157 |
// From base class MMDXMLParserObserver.
|
|
158 |
// CVoipXmlParser::ParseFileCompleteL
|
|
159 |
// ---------------------------------------------------------------------------
|
|
160 |
//
|
|
161 |
void CVoipXmlParser::ParseFileCompleteL()
|
|
162 |
{
|
|
163 |
DBG_PRINT( "CVoipXmlParser::ParseFileCompleteL - begin" );
|
|
164 |
// We may have already received XML document from iParser since we
|
|
165 |
// commit two parsing operations (first the description and then the
|
|
166 |
// settings). Thus we need to delete iXmlDoc because iParser has given
|
|
167 |
// its responsibility here.
|
|
168 |
if ( iXmlDoc )
|
|
169 |
{
|
|
170 |
delete iXmlDoc;
|
|
171 |
iXmlDoc = NULL;
|
|
172 |
}
|
|
173 |
iXmlDoc = iParser->DetachXMLDoc();
|
|
174 |
CActiveScheduler::Stop();
|
|
175 |
if ( !iXmlDoc )
|
|
176 |
{
|
|
177 |
iError = KErrCorrupt;
|
|
178 |
return;
|
|
179 |
}
|
|
180 |
CMDXMLElement* xmlElement = iXmlDoc->DocumentElement();
|
|
181 |
if ( !xmlElement )
|
|
182 |
{
|
|
183 |
iError = KErrCorrupt;
|
|
184 |
DBG_PRINT( "CVoipXmlParser::ParseFileCompleteL - end KErrCorrupt" );
|
|
185 |
return;
|
|
186 |
}
|
|
187 |
|
|
188 |
if ( iParseDescription )
|
|
189 |
{
|
|
190 |
ParseDescription( *xmlElement );
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
ParseRoot( *xmlElement );
|
|
195 |
}
|
|
196 |
DBG_PRINT( "CVoipXmlParser::ParseFileCompleteL - end" );
|
|
197 |
}
|
|
198 |
|
|
199 |
// ---------------------------------------------------------------------------
|
|
200 |
// Parses description node.
|
|
201 |
// ---------------------------------------------------------------------------
|
|
202 |
//
|
|
203 |
void CVoipXmlParser::ParseDescription( CMDXMLElement& aXmlElement )
|
|
204 |
{
|
|
205 |
CMDXMLNode* node = aXmlElement.FirstChild();
|
|
206 |
if ( !node )
|
|
207 |
{
|
|
208 |
iError = KErrCorrupt;
|
|
209 |
return;
|
|
210 |
}
|
|
211 |
TBuf<KMaxNodeNameLength> nodeName;
|
|
212 |
nodeName.Copy( node->NodeName() );
|
|
213 |
nodeName.LowerCase();
|
|
214 |
|
|
215 |
// <nokia-confdoc> is the root node; thus parse it first.
|
|
216 |
while ( nodeName != KNodeNokiaConfDoc && node )
|
|
217 |
{
|
|
218 |
node = node->NextSibling();
|
|
219 |
if ( !node )
|
|
220 |
{
|
|
221 |
DBG_PRINT( "CVoipXmlParser::ParseRoot - end KErrEof" );
|
|
222 |
iError = KErrEof;
|
|
223 |
return;
|
|
224 |
}
|
|
225 |
nodeName.Copy( node->NodeName() );
|
|
226 |
nodeName.LowerCase();
|
|
227 |
}
|
|
228 |
// After <nokia-confdoc> has been found, search for <confdescription>
|
|
229 |
// and <confbrandurl> from its children.
|
|
230 |
node = node->FirstChild();
|
|
231 |
while ( node )
|
|
232 |
{
|
|
233 |
nodeName.Copy( node->NodeName() );
|
|
234 |
nodeName.LowerCase();
|
|
235 |
CMDXMLNode* child = node->FirstChild();
|
|
236 |
//lint -e{960} No need for else statement here
|
|
237 |
if ( KNodeConfDescription() == nodeName && child &&
|
|
238 |
CMDXMLNode::ETextNode == child->NodeType() )
|
|
239 |
{
|
|
240 |
CMDXMLText* text = NULL;
|
|
241 |
text = static_cast<CMDXMLText*>( child );
|
|
242 |
delete iDescription;
|
|
243 |
iDescription = NULL;
|
|
244 |
TRAP_IGNORE( iDescription = text->Data().AllocL() );
|
|
245 |
}
|
|
246 |
else if ( KNodeConfBrandUrl() == nodeName && child &&
|
|
247 |
CMDXMLNode::ETextNode == child->NodeType() )
|
|
248 |
{
|
|
249 |
CMDXMLText* text = NULL;
|
|
250 |
text = static_cast<CMDXMLText*>( child );
|
|
251 |
delete iBrandUrl;
|
|
252 |
iBrandUrl = NULL;
|
|
253 |
TRAP_IGNORE( iBrandUrl = text->Data().AllocL() );
|
|
254 |
}
|
|
255 |
node = node->NextSibling();
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
// CVoipXmlParser::ParseRoot
|
|
261 |
// Parses root node.
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void CVoipXmlParser::ParseRoot( CMDXMLElement& aXmlElement )
|
|
265 |
{
|
|
266 |
DBG_PRINT( "CVoipXmlParser::ParseRoot - begin" );
|
|
267 |
|
|
268 |
CMDXMLNode* node = aXmlElement.FirstChild();
|
|
269 |
if ( !node )
|
|
270 |
{
|
|
271 |
iError = KErrCorrupt;
|
|
272 |
return;
|
|
273 |
}
|
|
274 |
TBuf<KMaxNodeNameLength> nodeName;
|
|
275 |
nodeName.Copy( node->NodeName() );
|
|
276 |
nodeName.LowerCase();
|
|
277 |
|
|
278 |
while ( nodeName != KNodeNokiaConfDoc )
|
|
279 |
{
|
|
280 |
node = node->NextSibling();
|
|
281 |
if ( !node )
|
|
282 |
{
|
|
283 |
DBG_PRINT( "CVoipXmlParser::ParseRoot - end KErrEof" );
|
|
284 |
iError = KErrEof;
|
|
285 |
return;
|
|
286 |
}
|
|
287 |
nodeName.Copy( node->NodeName() );
|
|
288 |
nodeName.LowerCase();
|
|
289 |
}
|
|
290 |
|
|
291 |
node = node->FirstChild();
|
|
292 |
|
|
293 |
TInt settingsCount( 0 );
|
|
294 |
while ( node )
|
|
295 |
{
|
|
296 |
nodeName.Copy( node->NodeName() );
|
|
297 |
nodeName.LowerCase();
|
|
298 |
// At this level in XML tree only 'settings' nodes are allowed.
|
|
299 |
if ( nodeName == KNodeSettings )
|
|
300 |
{
|
|
301 |
ParseSettings( node );
|
|
302 |
settingsCount++;
|
|
303 |
}
|
|
304 |
node = node->NextSibling();
|
|
305 |
}
|
|
306 |
if ( !settingsCount )
|
|
307 |
{
|
|
308 |
iError = KErrAbort;
|
|
309 |
}
|
|
310 |
DBG_PRINT( "CVoipXmlParser::ParseRoot - end" );
|
|
311 |
|
|
312 |
}
|
|
313 |
|
|
314 |
// ---------------------------------------------------------------------------
|
|
315 |
// CVoipXmlParser::ParseSettingsL
|
|
316 |
// Parses 'settings' nodes.
|
|
317 |
// ---------------------------------------------------------------------------
|
|
318 |
//
|
|
319 |
void CVoipXmlParser::ParseSettings( CMDXMLNode* aXmlNode )
|
|
320 |
{
|
|
321 |
DBG_PRINT( "CVoipXmlParser::ParseSettings - begin" );
|
|
322 |
if ( CMDXMLNode::EElementNode != aXmlNode->NodeType() )
|
|
323 |
{
|
|
324 |
DBG_PRINT(
|
|
325 |
"CVoipXmlParser::ParseSettings - node type not element, end" );
|
|
326 |
iError = KErrBadHandle;
|
|
327 |
return;
|
|
328 |
}
|
|
329 |
|
|
330 |
CMDXMLElement* element = NULL;
|
|
331 |
element = static_cast<CMDXMLElement*>( aXmlNode );
|
|
332 |
TPtrC attributeValue;
|
|
333 |
element->GetAttribute( KAttributeType(), attributeValue );
|
|
334 |
if ( !attributeValue.Length() )
|
|
335 |
{
|
|
336 |
DBG_PRINT(
|
|
337 |
"CVoipXmlParser::ParseSettings - attribute type not ok, end" );
|
|
338 |
iError = KErrBadName;
|
|
339 |
}
|
|
340 |
|
|
341 |
iParamHandler->SettingsStart( attributeValue );
|
|
342 |
|
|
343 |
|
|
344 |
CMDXMLNode* node = element->FirstChild();
|
|
345 |
|
|
346 |
while ( node )
|
|
347 |
{
|
|
348 |
if ( node->NodeType() == CMDXMLNode::EElementNode )
|
|
349 |
{
|
|
350 |
|
|
351 |
TBuf<KMaxNodeNameLength> nodeName;
|
|
352 |
nodeName.Copy( node->NodeName() );
|
|
353 |
nodeName.LowerCase();
|
|
354 |
element = NULL;
|
|
355 |
element = static_cast<CMDXMLElement*>( node );
|
|
356 |
|
|
357 |
//lint -e{960} No need for else statement here
|
|
358 |
if ( KNodeParam() == nodeName )
|
|
359 |
{
|
|
360 |
TPtrC nameVal;
|
|
361 |
element->GetAttribute( KAttributeName(), nameVal );
|
|
362 |
if ( nameVal.Length() )
|
|
363 |
{
|
|
364 |
TPtrC attVal;
|
|
365 |
element->GetAttribute( KAttributeValue(), attVal );
|
|
366 |
{
|
|
367 |
if ( attVal.Length() )
|
|
368 |
{
|
|
369 |
iParamHandler->HandleParameter(
|
|
370 |
nameVal, attVal );
|
|
371 |
}
|
|
372 |
}
|
|
373 |
}
|
|
374 |
}
|
|
375 |
else if ( KNodeSettings() == nodeName )
|
|
376 |
{
|
|
377 |
ParseSettings( element );
|
|
378 |
}
|
|
379 |
}
|
|
380 |
node = node->NextSibling();
|
|
381 |
}
|
|
382 |
|
|
383 |
iParamHandler->SettingsEnd();
|
|
384 |
|
|
385 |
DBG_PRINT( "CVoipXmlParser::ParseSettings - end" );
|
|
386 |
}
|
|
387 |
|
|
388 |
// End of file.
|