|
1 /* |
|
2 * Copyright (c) 2006 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: XML SAX Parser for UPnP. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include <xml/parser.h> |
|
24 #include <xml/parserfeature.h> |
|
25 #include <upnpstring.h> |
|
26 #include <xml/matchdata.h> |
|
27 |
|
28 #include "upnpxmleventparser.h" |
|
29 |
|
30 _LIT( KComponentLogfile, "upnpxmlparser.txt"); |
|
31 #include "upnplog.h" |
|
32 |
|
33 _LIT8( KXmlMimeType, "text/xml" ); |
|
34 _LIT8( KLIB2XML, "libxml2" ); |
|
35 |
|
36 _LIT8( KEvent, "Event" ); |
|
37 _LIT8( KInstanceID, "InstanceID" ); |
|
38 _LIT8( KVolume, "Volume" ); |
|
39 _LIT8( KMute, "Mute" ); |
|
40 _LIT8( KDIDL, "DIDL-Lite" ); |
|
41 _LIT8( KDesc, "desc" ); |
|
42 _LIT8( KDlnaDoc, "X_DLNADOC" ); |
|
43 _LIT8( KVal, "val" ); |
|
44 _LIT8( KChannel, "channel" ); |
|
45 _LIT8( KMaster, "Master" ); |
|
46 |
|
47 // -------------------------------------------------------------------------- |
|
48 // CUPnPXMLEventParser::CUPnPXMLEventParser() |
|
49 // See upnpxmlparser.h |
|
50 // -------------------------------------------------------------------------- |
|
51 CUPnPXMLEventParser::CUPnPXMLEventParser() |
|
52 { |
|
53 } |
|
54 |
|
55 // -------------------------------------------------------------------------- |
|
56 // CUPnPXMLEventParser::ConstructL |
|
57 // See upnpxmlparser.h |
|
58 // -------------------------------------------------------------------------- |
|
59 void CUPnPXMLEventParser::ConstructL() |
|
60 { |
|
61 __LOG( "CUPnPXMLEventParser::CostructL" ); |
|
62 |
|
63 } |
|
64 |
|
65 // -------------------------------------------------------------------------- |
|
66 // CUPnPXMLEventParser::NewL |
|
67 // See upnpxmlparser.h |
|
68 // -------------------------------------------------------------------------- |
|
69 EXPORT_C CUPnPXMLEventParser* CUPnPXMLEventParser::NewL() |
|
70 { |
|
71 __LOG( "CUPnPXMLEventParser::NewL" ); |
|
72 CUPnPXMLEventParser* self = new( ELeave ) CUPnPXMLEventParser(); |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(self); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CUPnPXMLEventParser::~CUPnPXMLEventParser |
|
81 // See upnpxmlparser.h |
|
82 // -------------------------------------------------------------------------- |
|
83 CUPnPXMLEventParser::~CUPnPXMLEventParser() |
|
84 { |
|
85 __LOG( "CUPnPXMLEventParser::~CUPnPXMLEventParser" ); |
|
86 |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CUPnPXMLEventParser::ParseResultDataL |
|
91 // See upnpxmlparser.h |
|
92 // -------------------------------------------------------------------------- |
|
93 EXPORT_C void CUPnPXMLEventParser::ParseResultDataL( const TDesC8& aData, |
|
94 TInt& aInstanceId, TInt& aVolume, TBool& aMute ) |
|
95 { |
|
96 __LOG( "CUPnPXMLEventParser::ParseResultDataL, begin" ); |
|
97 |
|
98 if ( !aData.Length() ) |
|
99 { |
|
100 User::Leave( KErrArgument ); |
|
101 } |
|
102 |
|
103 Reset(); |
|
104 |
|
105 // Create parser |
|
106 CMatchData* matchData = CMatchData::NewLC(); |
|
107 matchData->SetMimeTypeL( KXmlMimeType ); |
|
108 matchData->SetVariantL( KLIB2XML ); |
|
109 CParser* parser = CParser::NewLC( *matchData, *this ); |
|
110 parser->EnableFeature( Xml::EReportNamespaceMapping ); |
|
111 |
|
112 Xml::ParseL( *parser, aData ); |
|
113 |
|
114 CleanupStack::PopAndDestroy( parser ); |
|
115 CleanupStack::PopAndDestroy( matchData ); |
|
116 |
|
117 if( iInstanceID != KErrNotFound ) |
|
118 { |
|
119 aInstanceId = iInstanceID; |
|
120 if( iVolume != KErrNotFound ) |
|
121 { |
|
122 aVolume = iVolume; |
|
123 } |
|
124 if( iMute != KErrNotFound ) |
|
125 { |
|
126 aMute = iMute; |
|
127 } |
|
128 } |
|
129 else |
|
130 { |
|
131 User::Leave( KErrArgument ); |
|
132 } |
|
133 |
|
134 __LOG( "CUPnPXMLEventParser::ParseResultDataL, end" ); |
|
135 } |
|
136 |
|
137 // -------------------------------------------------------------------------- |
|
138 // CUPnPXMLEventParser::OnStartDocumentL |
|
139 // See upnpxmlparser.h |
|
140 // -------------------------------------------------------------------------- |
|
141 void CUPnPXMLEventParser::OnStartDocumentL( |
|
142 const RDocumentParameters& /*aDocParam*/, |
|
143 TInt /*aErrorCode*/ ) |
|
144 { |
|
145 // No implementation needed |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CUPnPXMLEventParser::OnEndDocumentL |
|
150 // See upnpxmlparser.h |
|
151 // -------------------------------------------------------------------------- |
|
152 void CUPnPXMLEventParser::OnEndDocumentL( TInt /*aErrorCode*/ ) |
|
153 { |
|
154 // No implementation needed |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------- |
|
158 // CUPnPXMLEventParser::OnStartElementL |
|
159 // See upnpxmlparser.h |
|
160 // -------------------------------------------------------------------------- |
|
161 void CUPnPXMLEventParser::OnStartElementL( const RTagInfo& aElement, |
|
162 const RAttributeArray& aAttributes, |
|
163 TInt aErrorCode ) |
|
164 { |
|
165 __LOG1( "CUPnPXMLEventParser::OnStartElementL, error: %d", aErrorCode ); |
|
166 if ( aErrorCode != KErrNone ) |
|
167 { |
|
168 return; |
|
169 } |
|
170 const TDesC8& desName = aElement.LocalName().DesC(); |
|
171 //const TDesC8& prefix = aElement.Prefix().DesC(); |
|
172 |
|
173 if ( !desName.CompareF( KEvent ) ) |
|
174 { |
|
175 iParserState = EEvent; |
|
176 } |
|
177 else if ( !desName.CompareF( KInstanceID ) ) |
|
178 { |
|
179 iParserState = EInstanceID; |
|
180 SetAttributesL( aAttributes ); |
|
181 } |
|
182 else if( !desName.CompareF( KVolume ) ) |
|
183 { |
|
184 iParserState = EVolume; |
|
185 SetAttributesL( aAttributes ); |
|
186 } |
|
187 else if( !desName.CompareF( KMute ) ) |
|
188 { |
|
189 iParserState = EMute; |
|
190 SetAttributesL( aAttributes ); |
|
191 } |
|
192 // Ignore DIDL-Lite, desc and X_DLNADOC -elements (DLNA req) |
|
193 else if( desName.Compare( KDIDL ) == KErrNone || |
|
194 desName.Compare( KDesc ) == KErrNone || |
|
195 desName.Compare( KDlnaDoc ) == KErrNone |
|
196 ) |
|
197 { |
|
198 // Ignore |
|
199 } |
|
200 else |
|
201 { |
|
202 __LOG( "OnStartElementL - unknown element!" ); |
|
203 __LOG8( desName ); |
|
204 } |
|
205 |
|
206 __LOG( "CUPnPXMLEventParser::OnStartElementL, end" ); |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CUPnPXMLEventParser::OnEndElementL |
|
211 // See upnpxmlparser.h |
|
212 // -------------------------------------------------------------------------- |
|
213 void CUPnPXMLEventParser::OnEndElementL( const RTagInfo& /*aElement*/, |
|
214 TInt /*aErrorCode*/ ) |
|
215 { |
|
216 __LOG( "CUPnPXMLSAXParser::OnEndElementL(), begin" ); |
|
217 } |
|
218 |
|
219 // -------------------------------------------------------------------------- |
|
220 // CUPnPXMLEventParser::OnContentL |
|
221 // See upnpxmlparser.h |
|
222 // -------------------------------------------------------------------------- |
|
223 void CUPnPXMLEventParser::OnContentL( const TDesC8& /*aBytes*/, |
|
224 TInt /*aErrorCode*/ ) |
|
225 { |
|
226 __LOG( "CUPnPXMLSAXParser::OnContentL(), begin" ); |
|
227 } |
|
228 |
|
229 // -------------------------------------------------------------------------- |
|
230 // CUPnPXMLEventParser::OnStartPrefixMappingL |
|
231 // See upnpxmlparser.h |
|
232 // -------------------------------------------------------------------------- |
|
233 void CUPnPXMLEventParser::OnStartPrefixMappingL( const RString& /*aPrefix*/, |
|
234 const RString& /*aUri*/, |
|
235 TInt /*aErrorCode*/ ) |
|
236 { |
|
237 // No implementation needed |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 // CUPnPXMLEventParser::OnEndPrefixMappingL |
|
242 // See upnpxmlparser.h |
|
243 // -------------------------------------------------------------------------- |
|
244 void CUPnPXMLEventParser::OnEndPrefixMappingL( const RString& /*aPrefix*/, |
|
245 TInt /*aErrorCode*/ ) |
|
246 { |
|
247 // No implementation needed |
|
248 } |
|
249 |
|
250 // -------------------------------------------------------------------------- |
|
251 // CUPnPXMLEventParser::OnIgnorableWhiteSpaceL |
|
252 // See upnpxmlparser.h |
|
253 // -------------------------------------------------------------------------- |
|
254 void CUPnPXMLEventParser::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/, |
|
255 TInt /*aErrorCode*/ ) |
|
256 { |
|
257 // No implementation needed |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CUPnPXMLEventParser::OnSkippedEntityL |
|
262 // See upnpxmlparser.h |
|
263 // -------------------------------------------------------------------------- |
|
264 void CUPnPXMLEventParser::OnSkippedEntityL( const RString& /*aName*/, |
|
265 TInt /*aErrorCode*/ ) |
|
266 { |
|
267 // No implementation needed |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------- |
|
271 // CUPnPXMLEventParser::OnProcessingInstructionL |
|
272 // See upnpxmlparser.h |
|
273 // -------------------------------------------------------------------------- |
|
274 void CUPnPXMLEventParser::OnProcessingInstructionL( const TDesC8& /*aTarget*/, |
|
275 const TDesC8& /*aData*/, |
|
276 TInt /*aErrorCode*/ ) |
|
277 { |
|
278 // No implementation needed |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // CUPnPXMLEventParser::OnError |
|
283 // See upnpxmlparser.h |
|
284 // -------------------------------------------------------------------------- |
|
285 void CUPnPXMLEventParser::OnError( TInt /*aErrorCode*/ ) |
|
286 { |
|
287 // No implementation needed |
|
288 } |
|
289 |
|
290 // -------------------------------------------------------------------------- |
|
291 // CUPnPXMLEventParser::GetExtendedInterface |
|
292 // See upnpxmlparser.h |
|
293 // -------------------------------------------------------------------------- |
|
294 TAny* CUPnPXMLEventParser::GetExtendedInterface( const TInt32 /*aUid*/ ) |
|
295 { |
|
296 // No implementation needed |
|
297 return NULL; |
|
298 } |
|
299 |
|
300 // -------------------------------------------------------------------------- |
|
301 // CUPnPXMLEventParser::SetAttributesL |
|
302 // See upnpxmlparser.h |
|
303 // -------------------------------------------------------------------------- |
|
304 void CUPnPXMLEventParser::SetAttributesL( |
|
305 const RAttributeArray& aAttributes ) |
|
306 { |
|
307 __LOG( "CUPnPXMLEventParser::SetAttributesL" ); |
|
308 |
|
309 RAttribute attribute; |
|
310 TInt count = aAttributes.Count(); |
|
311 TInt volume = KErrNotFound; |
|
312 iMasterVolumeState = EFalse; |
|
313 for ( TInt i = 0; i < count ; i++ ) |
|
314 { |
|
315 attribute = aAttributes[i]; |
|
316 const TDesC8& name = attribute.Attribute().LocalName().DesC(); |
|
317 |
|
318 if ( iParserState == EVolume ) |
|
319 { |
|
320 // assign the value of Volume to volume |
|
321 if ( name.CompareF( KVal ) == KErrNone ) |
|
322 { |
|
323 __LOG( "SetAttributesL - \"val\" found!" ); |
|
324 TLex8 lexer( attribute.Value().DesC() ); |
|
325 User::LeaveIfError( lexer.Val(volume) ); |
|
326 __LOG1( "SetAttributesL - volume = %d", volume ); |
|
327 } |
|
328 else if ( name.CompareF( KChannel ) == KErrNone ) |
|
329 { |
|
330 // channel is found, check if is Master |
|
331 const TDesC8& channelname = attribute.Value().DesC(); |
|
332 if ( channelname.CompareF( KMaster ) == KErrNone ) |
|
333 { |
|
334 __LOG( "SetAttributesL - MasterVolume found!" ); |
|
335 iMasterVolumeState = ETrue; |
|
336 } |
|
337 } |
|
338 } |
|
339 else |
|
340 { |
|
341 |
|
342 if ( name.Compare( KVal ) == KErrNone ) |
|
343 { |
|
344 __LOG( "SetAttributesL - \"val\" found!" ); |
|
345 |
|
346 TLex8 lexer( attribute.Value().DesC() ); |
|
347 if ( iParserState == EInstanceID ) |
|
348 { |
|
349 User::LeaveIfError( lexer.Val( iInstanceID ) ); |
|
350 } |
|
351 else |
|
352 if ( iParserState == EMute ) |
|
353 { |
|
354 User::LeaveIfError( lexer.Val( iMute ) ); |
|
355 } |
|
356 else |
|
357 { |
|
358 __LOG( "SetAttributesL - unknown state!" ); |
|
359 } |
|
360 } |
|
361 } |
|
362 } |
|
363 |
|
364 // check Mastervolume if was found, and volume if was found |
|
365 if ( iParserState == EVolume && |
|
366 iMasterVolumeState && |
|
367 volume != KErrNotFound ) |
|
368 { |
|
369 // all is found ,so assign the iVolume |
|
370 __LOG1( "SetAttributesL - set iVolume : %d", volume ); |
|
371 iVolume = volume; |
|
372 } |
|
373 |
|
374 __LOG( "CUPnPXMLEventParser::SetAttributesL - End" ); |
|
375 } |
|
376 |
|
377 // -------------------------------------------------------------------------- |
|
378 // CUPnPXMLEventParser::Reset |
|
379 // See upnpxmlparser.h |
|
380 // -------------------------------------------------------------------------- |
|
381 void CUPnPXMLEventParser::Reset() |
|
382 { |
|
383 iInstanceID = KErrNotFound; |
|
384 iMute = KErrNotFound; |
|
385 iVolume = KErrNotFound; |
|
386 iParserState = ENotSupported; |
|
387 iMasterVolumeState = EFalse; |
|
388 } |
|
389 |
|
390 // end of file |
|
391 |