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