|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file XmlParsing.cpp |
|
18 */ |
|
19 |
|
20 #include "XmlParsing.h" |
|
21 #include <comms-infras/ss_msgintercept.h> |
|
22 |
|
23 |
|
24 #ifdef _DEBUG |
|
25 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
26 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
27 _LIT(KSpecAssert_ESockTestXmlPrsn, "ESockTestXmlPrsn"); |
|
28 #endif |
|
29 |
|
30 using namespace ESockDebug; |
|
31 using namespace Den; |
|
32 |
|
33 TLookupTableEntry8 KUidLookupTable[] = |
|
34 { |
|
35 // MCPRs |
|
36 {_S8("NetworkMCPR"), 0x10274547}, |
|
37 {_S8("IpProtoMCPR"), 0x10281DEE}, |
|
38 //{_S8("AgentMCPR"), 0xFFFFFFFF}, // Not instantiated |
|
39 {_S8("PPPMCPR"), 0x10281DEC}, |
|
40 {_S8("EthMCPR"), 0x10281DFC}, |
|
41 {_S8("RawIpMCPR"), 0x10281e00}, |
|
42 {_S8("TunnelMCPR"), 0x10281E02}, |
|
43 {_S8("PdpMCPR"), 0x102822F0}, |
|
44 {_S8("DummyMCPR"), 0x10281E04}, |
|
45 |
|
46 // CPRs |
|
47 {_S8("AgentCPR"), 0x10281DE8}, |
|
48 //{_S8("DummyCPR"), 0xFFFFFFFF}, // No ReceivedL() |
|
49 {_S8("IpProtoCPR"), 0x10281DD3}, |
|
50 {_S8("IpCPR"), 0x102070EF}, |
|
51 |
|
52 // SCPRs |
|
53 {_S8("DummySCPR"), 0x1028302E}, |
|
54 {_S8("AgentSCPR"), 0x10281DEA}, |
|
55 {_S8("PPPSCPR"), 0x102822FC}, |
|
56 {_S8("IpProtoSCPR"), 0x10281DD1}, |
|
57 {_S8("PdpSCPR"), 0x102822E0}, |
|
58 {_S8("IpDefaultSCPR"), 0x10204308}, |
|
59 {_S8("IpSCPR"), 0x10204308}, |
|
60 |
|
61 // Non-provider based nodes |
|
62 {_S8("Socket"), KSocketNodeUid}, |
|
63 {_S8("Conn"), KConnectionNodeUid}, |
|
64 {_S8("SubConn"), KSubConnectionNodeUid}, |
|
65 {_S8("HostRslv"), KHostResolverNodeUid}, |
|
66 }; |
|
67 |
|
68 #define MESSAGE_ID_LOOKUP_TABLE_ENTRY(messageid, idvalue) {_S8(#messageid), (idvalue)} |
|
69 |
|
70 TLookupTableEntry8 KMessageIdLookupTable[] = |
|
71 { |
|
72 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFNull, 1), |
|
73 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStart, 2), |
|
74 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStop, 3), |
|
75 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStarted, 4), |
|
76 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStopped, 5), |
|
77 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFGoneDown, 6), |
|
78 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFJoinComplete, 7), |
|
79 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFLeaveComplete, 8), |
|
80 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFProvisionConfig, 9), |
|
81 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFBindToRequest, 10), |
|
82 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFBindTo, 11), |
|
83 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFBindToComplete, 12), |
|
84 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFReBindTo, 13), |
|
85 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFReConnect, 14), |
|
86 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFReBindComplete, 15), |
|
87 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCommsBinderRequest, 16), |
|
88 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCommsBinderResponse, 17), |
|
89 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFBearer, 18), |
|
90 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFNoBearer, 19), |
|
91 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFRejoin, 20), |
|
92 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFRejoinComplete, 21), |
|
93 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFRejoinDataClientRequest, 22), |
|
94 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCancel, 23), |
|
95 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFError, 24), |
|
96 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDestroy, 25), |
|
97 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCreateDataClient, 26), |
|
98 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStart, 27), |
|
99 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStarted, 28), |
|
100 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStop, 29), |
|
101 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStopped, 30), |
|
102 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDataClientJoinRequest, 31), |
|
103 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDataClientJoined, 32), |
|
104 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDataClientGoneDown, 33), |
|
105 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDataClientRouted, 34), |
|
106 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDataClientIdle, 35), |
|
107 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCtrlClientJoinRequest, 36), |
|
108 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCtrlClientJoined, 37), |
|
109 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFErrorRecoveryRequest, 38), |
|
110 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFErrorRecoveryResponse, 39), |
|
111 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFClientLeavingRequest, 40), |
|
112 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFClientLeaving, 41), |
|
113 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFApplyRequest, 42), |
|
114 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFApplyResponse, 43), |
|
115 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFStateChange, 44), |
|
116 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFServiceChangeNotification, 45), |
|
117 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFRegisterHookError, 46), |
|
118 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFAttachRequest, 47), |
|
119 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFFindOrCreateFactoryObject, 48), |
|
120 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFFactoryObjectCreated, 49), |
|
121 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCreateCSR, 50), |
|
122 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFCSRCreated, 51), |
|
123 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFSelect, 52), |
|
124 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFSelectComplete, 53), |
|
125 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFImplicitFlowRequest, 54), |
|
126 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFConnFlowRequest, 55), |
|
127 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFParamsRequest, 56), |
|
128 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFParamsResponse, 57), |
|
129 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFSubConnFlowRequest, 58), |
|
130 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFSubConnNotification, 59), |
|
131 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFFindOrCreateTM, 60), |
|
132 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFTierStatusQuery, 61), |
|
133 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFTierStatus, 62), |
|
134 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFTierStatusCancel, 63), |
|
135 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFTierNotificationRegistration, 64), |
|
136 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFTierNotification, 65), |
|
137 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFTierNotificationCancel, 66), |
|
138 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFAvailabilityNotificationRegistration, 67), |
|
139 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFAvailabilityNotification, 68), |
|
140 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFDataMonitoringNotification, 69), |
|
141 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFFlowRequest, 70), |
|
142 MESSAGE_ID_LOOKUP_TABLE_ENTRY(ECFSubSess, 71) |
|
143 }; |
|
144 |
|
145 TLookupTableEntry8 KTiedIdLookupTable[] = |
|
146 { |
|
147 {_S8("_dummyTier"), 0x12345678} // TODO_CDG what are these values |
|
148 }; |
|
149 |
|
150 TLookupTableEntry8 KAccessPointIdLookupTable[] = |
|
151 { |
|
152 {_S8("_dummyAccessPoint"), 0x12345678} // TODO_CDG what are these values |
|
153 }; |
|
154 |
|
155 |
|
156 #define ERROR_CODE_LOOKUP_TABLE_ENTRY(errorcode) {_S8(#errorcode), static_cast<TUint>(errorcode)} |
|
157 TLookupTableEntry8 KErrorCodeLookupTable[] = |
|
158 { |
|
159 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrNone), |
|
160 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrNotFound), |
|
161 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrGeneral), |
|
162 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrCancel), |
|
163 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrNoMemory), |
|
164 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrNotSupported), |
|
165 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrArgument), |
|
166 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrAbort), |
|
167 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrBadHandle), |
|
168 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrAlreadyExists), |
|
169 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrInUse), |
|
170 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrServerTerminated), |
|
171 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrServerBusy), |
|
172 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrNotReady), |
|
173 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrAccessDenied), |
|
174 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrCouldNotConnect), |
|
175 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrCouldNotDisconnect), |
|
176 ERROR_CODE_LOOKUP_TABLE_ENTRY(KErrDisconnected) |
|
177 }; |
|
178 |
|
179 TLookupTableEntry8 KActionTypeLookupTable[] = |
|
180 { |
|
181 {_S8("None"), TAction::ENoAction}, |
|
182 {_S8("Leave"), TAction::ELeaveAction}, |
|
183 {_S8("Panic"), TAction::EPanicAction} |
|
184 }; |
|
185 |
|
186 TLookupTableEntry8 KRealmIdLookupTable[] = |
|
187 { |
|
188 {_S8("Zero"), 0} |
|
189 }; |
|
190 |
|
191 #define LOOKUP_TABLE_LENGTH(tableinstance) (sizeof(tableinstance) / sizeof(TLookupTableEntry8)) |
|
192 |
|
193 void CExpressionXmlHandler::LookupValueByNameL(TLookupTableType aLookupType, const TDesC8& aName, TUint& aValue) |
|
194 { |
|
195 TLookupTableEntry8* table = NULL; |
|
196 TUint tableLength = 0; |
|
197 |
|
198 // Find the table first |
|
199 switch(aLookupType) |
|
200 { |
|
201 case EUidTable: |
|
202 table = KUidLookupTable; |
|
203 tableLength = LOOKUP_TABLE_LENGTH(KUidLookupTable); |
|
204 break; |
|
205 |
|
206 case EMessageIdTable: |
|
207 table = KMessageIdLookupTable; |
|
208 tableLength = LOOKUP_TABLE_LENGTH(KMessageIdLookupTable); |
|
209 break; |
|
210 |
|
211 case ETierIdTable: |
|
212 table = KTiedIdLookupTable; |
|
213 tableLength = LOOKUP_TABLE_LENGTH(KTiedIdLookupTable); |
|
214 break; |
|
215 |
|
216 case EAccessPointIdTable: |
|
217 table = KAccessPointIdLookupTable; |
|
218 tableLength = LOOKUP_TABLE_LENGTH(KAccessPointIdLookupTable); |
|
219 break; |
|
220 |
|
221 case EErrorCodeTable: |
|
222 table = KErrorCodeLookupTable; |
|
223 tableLength = LOOKUP_TABLE_LENGTH(KErrorCodeLookupTable); |
|
224 break; |
|
225 |
|
226 case EActionTypeTable: |
|
227 table = KActionTypeLookupTable; |
|
228 tableLength = LOOKUP_TABLE_LENGTH(KActionTypeLookupTable); |
|
229 break; |
|
230 |
|
231 case ERealmIdTable: |
|
232 table = KRealmIdLookupTable; |
|
233 tableLength = LOOKUP_TABLE_LENGTH(KRealmIdLookupTable); |
|
234 break; |
|
235 |
|
236 default: |
|
237 User::Panic(_L("Illegal name lookup access"), KErrArgument); |
|
238 break; |
|
239 } |
|
240 |
|
241 TLookupTableEntry8* tablePtr = table; |
|
242 for(TUint index = 0; index < tableLength; index++) |
|
243 { |
|
244 // Simply return the first match |
|
245 if(tablePtr[index].iIdentifier == aName) |
|
246 { |
|
247 aValue = tablePtr[index].iValue; |
|
248 return; |
|
249 } |
|
250 } |
|
251 |
|
252 // Couldn't find it |
|
253 User::Leave(KErrNotFound); |
|
254 } |
|
255 |
|
256 void CExpressionXmlHandler::ParseIdentifierValueL(const TDesC8& aBuffer, TDes8& aIdentifier) |
|
257 { |
|
258 TLex8 lexer(aBuffer); |
|
259 |
|
260 // Skip whitespace to start with |
|
261 lexer.SkipSpace(); |
|
262 |
|
263 // First char must be "_" or alpha |
|
264 if(!lexer.Peek().IsAlpha() && !(lexer.Peek() == TChar('_'))) |
|
265 User::Leave(KErrNotFound); |
|
266 else |
|
267 lexer.Mark(); |
|
268 |
|
269 // All and only identifier chararacters (alpha, digit and underscore) |
|
270 while(lexer.Peek().IsDigit() || lexer.Peek().IsAlpha() || (lexer.Peek() == TChar('_'))) |
|
271 { |
|
272 lexer.Inc(); |
|
273 } |
|
274 |
|
275 // Fetch the token (identifier) we marked out |
|
276 aIdentifier.Copy(lexer.MarkedToken()); |
|
277 } |
|
278 |
|
279 void CExpressionXmlHandler::FetchAttributeValueByNameL( |
|
280 const Xml::RAttributeArray& aAttributes, |
|
281 const TDesC8& aAttributeTag, |
|
282 TDes8& aAttributeValue) |
|
283 { |
|
284 // Step thru the array of attributes return the first found with name specified |
|
285 for(TUint index = 0; index < aAttributes.Count(); index++) |
|
286 { |
|
287 if(aAttributes[index].Attribute().LocalName().DesC() == aAttributeTag) |
|
288 { |
|
289 // Found our attribute so copy its value as expected |
|
290 aAttributeValue.Copy(aAttributes[index].Value().DesC()); |
|
291 return; |
|
292 } |
|
293 } |
|
294 |
|
295 // Didn't find the attribute we expected to |
|
296 User::Leave(KErrNotFound); |
|
297 } |
|
298 |
|
299 void CExpressionXmlHandler::FetchValueOrNamedValueL(TLookupTableType aType, const TDesC8& aBuffer, TUint& aValue) |
|
300 { |
|
301 _LIT8(KHexPrefix, "0x"); |
|
302 |
|
303 // First see if this is a hex value |
|
304 TLex8 lexer(aBuffer); |
|
305 lexer.SkipSpaceAndMark(); |
|
306 |
|
307 if(lexer.Remainder().Length() > 2) |
|
308 { |
|
309 lexer.Inc(2); |
|
310 if(lexer.MarkedToken() == KHexPrefix) |
|
311 { |
|
312 // If we had the hex prefix but no value then something wrong |
|
313 User::LeaveIfError(lexer.Val(aValue, EHex)); |
|
314 |
|
315 // Otherwise we got our value so out of here |
|
316 return; |
|
317 } |
|
318 } |
|
319 |
|
320 // Maybe its a decimal value (and allow for it to be signed) |
|
321 lexer.UnGetToMark(); |
|
322 TInt error = lexer.Val(reinterpret_cast<TInt&>(aValue)); |
|
323 |
|
324 // No? Then perhaps its a named value |
|
325 if(error != KErrNone) |
|
326 { |
|
327 TXmlTempBuf8 identifier; |
|
328 TRAP(error, ParseIdentifierValueL(aBuffer, identifier)); |
|
329 if(error == KErrNone) |
|
330 { |
|
331 // Lookup identifier |
|
332 TRAP(error, LookupValueByNameL(aType, identifier, aValue)); |
|
333 if(error != KErrNone) |
|
334 { |
|
335 User::Leave(KErrNotFound); |
|
336 } |
|
337 } |
|
338 else |
|
339 { |
|
340 User::Leave(KErrNotFound); |
|
341 } |
|
342 } |
|
343 } |
|
344 |
|
345 // CActionXmlHandler |
|
346 //------------------ |
|
347 _LIT8(KActionElementName, "Action"); |
|
348 _LIT8(KActionTypeAttributeName, "Type"); |
|
349 _LIT8(KActionErrorCodeAttributeName, "ErrorCode"); |
|
350 |
|
351 void CActionXmlHandler::ParseActionTypeAttributeL(const Xml::RAttributeArray& aAttributes, TAction::TActionType& aActionType) |
|
352 { |
|
353 TXmlTempBuf8 tempBuffer; |
|
354 FetchAttributeValueByNameL(aAttributes, KActionTypeAttributeName, tempBuffer); |
|
355 |
|
356 // Parse out the attribute in to the action's type value |
|
357 TUint actionTypeValue; |
|
358 FetchValueOrNamedValueL(EActionTypeTable, tempBuffer, actionTypeValue); |
|
359 aActionType = static_cast<TAction::TActionType>(actionTypeValue); |
|
360 } |
|
361 |
|
362 void CActionXmlHandler::ParseActionErrorCodeAttributeL(const Xml::RAttributeArray& aAttributes, TInt& aError) |
|
363 { |
|
364 TXmlTempBuf8 tempBuffer; |
|
365 FetchAttributeValueByNameL(aAttributes, KActionErrorCodeAttributeName, tempBuffer); |
|
366 |
|
367 // Parse out the attribute in to the action's error code |
|
368 TUint errorCodeValue; |
|
369 FetchValueOrNamedValueL(EErrorCodeTable, tempBuffer, errorCodeValue); |
|
370 aError = static_cast<TInt>(errorCodeValue); |
|
371 } |
|
372 |
|
373 |
|
374 void CActionXmlHandler::OnStartElementL( |
|
375 const Xml::RTagInfo& aElementName, |
|
376 const Xml::RAttributeArray& aAttributes, |
|
377 TInt /*aErrorCode*/) |
|
378 { |
|
379 // Check we are on the correct element first of all |
|
380 if (aElementName.LocalName().DesC() == KActionElementName) |
|
381 { |
|
382 // Parse the "Type" attribute. Must have this attribute so let if leave here if not found |
|
383 TAction::TActionType actionType; |
|
384 ParseActionTypeAttributeL(aAttributes, actionType); |
|
385 |
|
386 // Parse the "ErrorCode" attribute. Must have this attribute so let if leave here if not found |
|
387 TInt errorCode; |
|
388 ParseActionErrorCodeAttributeL(aAttributes, errorCode); |
|
389 |
|
390 // Got the attributes we need so build the action |
|
391 iAction = TAction(actionType, errorCode); |
|
392 } |
|
393 else |
|
394 { |
|
395 User::Leave(KErrNotFound); |
|
396 } |
|
397 } |
|
398 |
|
399 |
|
400 // CEventExpressionXmlHandler |
|
401 //--------------------------- |
|
402 |
|
403 void CEventExpressionXmlHandler::ParseNamedNumericAttributeL( |
|
404 const TDesC8& aAttribName, |
|
405 const Xml::RAttributeArray& aAttributes, |
|
406 TLookupTableType aTableId, |
|
407 TUint& aParsedValue) |
|
408 { |
|
409 TXmlTempBuf8 tempBuffer; |
|
410 FetchAttributeValueByNameL(aAttributes, aAttribName, tempBuffer); |
|
411 FetchValueOrNamedValueL(aTableId, tempBuffer, aParsedValue); |
|
412 } |
|
413 |
|
414 void CEventExpressionXmlHandler::ParseMessageElementL( |
|
415 const Xml::RTagInfo& aElementName, |
|
416 const Xml::RAttributeArray& aAttributes, |
|
417 TMsgExpression& aMessage) |
|
418 { |
|
419 _LIT8(KMsgElementName, "Msg"); |
|
420 _LIT8(KMsgIdAttributeName, "Id"); |
|
421 _LIT8(KRealmAttributeName, "Realm"); |
|
422 |
|
423 // Check we have the element name first |
|
424 if (aElementName.LocalName().DesC() == KMsgElementName) |
|
425 { |
|
426 // Now check we have the "Id" attribute which is mandatory |
|
427 TUint msgId; |
|
428 ParseNamedNumericAttributeL(KMsgIdAttributeName, aAttributes, EMessageIdTable, msgId); |
|
429 |
|
430 // And check for a realm which is optional (default to esock) |
|
431 TUint realm = 0x101F7482; // esocksvr uid |
|
432 TRAPD(error, ParseNamedNumericAttributeL(KRealmAttributeName, aAttributes, ERealmIdTable, realm)); |
|
433 if(error != KErrNone && error != KErrNotFound) |
|
434 User::Leave(error); |
|
435 |
|
436 aMessage = TMsgExpression(msgId, realm); |
|
437 } |
|
438 else |
|
439 { |
|
440 User::Leave(KErrNotFound); |
|
441 } |
|
442 } |
|
443 |
|
444 _LIT8(KNodeElementName, "Node"); |
|
445 _LIT8(KNodeTagToApplyAttributeName, "ApplyTag"); |
|
446 _LIT8(KProviderInfoAttributeName, "ProviderInfo"); |
|
447 _LIT8(KUidAttributeName, "Uid"); |
|
448 _LIT8(KNodeTagAttributeName, "Tag"); |
|
449 |
|
450 void CEventExpressionXmlHandler::ParseNodeExpressionElementL( |
|
451 const Xml::RTagInfo& aElementName, |
|
452 const Xml::RAttributeArray& aAttributes, |
|
453 TNodeExpression& aNodeExpression) |
|
454 { |
|
455 // Check we have the element itself first |
|
456 if (aElementName.LocalName().DesC() == KNodeElementName) |
|
457 { |
|
458 // First look to see if we have an "ApplyTag" attribute |
|
459 // its not mandatory so if not found then no bother |
|
460 TInt error; |
|
461 TNodeTag tagToApplyOnMatch(KNullDesC8); |
|
462 TRAP(error, ParseNodeTagToApplyAttributeL(aAttributes, tagToApplyOnMatch)); |
|
463 if(error != KErrNone && error != KErrNotFound) |
|
464 User::Leave(error); |
|
465 |
|
466 TUid tierId; |
|
467 TUint accessPoint; |
|
468 TRAP(error, ParseProviderInfoAttributeL(aAttributes, tierId, accessPoint)); |
|
469 if(error == KErrNone) |
|
470 { |
|
471 //TODO: TNodeExpression need to be based on a more dynamic mechanism |
|
472 aNodeExpression = TNodeExpression(tierId, /*accessPoint,*/ tagToApplyOnMatch); |
|
473 } |
|
474 else if(error == KErrNotFound) |
|
475 { |
|
476 TUid uid; |
|
477 TRAP(error, ParseUidAttributeL(aAttributes, uid)); |
|
478 if(error == KErrNone) |
|
479 { |
|
480 aNodeExpression = TNodeExpression(uid, tagToApplyOnMatch); |
|
481 } |
|
482 else if (error == KErrNotFound) |
|
483 { |
|
484 TNodeTag nodeMatchTag; |
|
485 TRAP(error, ParseNodeTagAttributeL(aAttributes, nodeMatchTag)); |
|
486 if(error == KErrNone) |
|
487 { |
|
488 aNodeExpression = TNodeExpression(nodeMatchTag); |
|
489 } |
|
490 else |
|
491 { |
|
492 User::Leave(error); |
|
493 } |
|
494 } |
|
495 } |
|
496 else |
|
497 { |
|
498 // Any other error then just get out of here |
|
499 User::Leave(error); |
|
500 } |
|
501 } |
|
502 else |
|
503 { |
|
504 User::Leave(KErrNotFound); |
|
505 } |
|
506 } |
|
507 |
|
508 void CEventExpressionXmlHandler::OnStartElementL( |
|
509 const Xml::RTagInfo& aElementName, |
|
510 const Xml::RAttributeArray& aAttributes, |
|
511 TInt /*aErrorCode*/) |
|
512 { |
|
513 // Check which element we are supposed to be parsing |
|
514 switch(iParseState) |
|
515 { |
|
516 case EEventElement: |
|
517 iParseState = ESenderNodeElement; |
|
518 break; |
|
519 |
|
520 case ESenderNodeElement: |
|
521 ParseNodeExpressionElementL(aElementName, aAttributes, iSender); |
|
522 break; |
|
523 |
|
524 case EMsgElement: |
|
525 ParseMessageElementL(aElementName, aAttributes, iMessage); |
|
526 break; |
|
527 |
|
528 case EReceiverNodeElement: |
|
529 ParseNodeExpressionElementL(aElementName, aAttributes, iReceiver); |
|
530 break; |
|
531 |
|
532 default: |
|
533 __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestXmlPrsn, 1)); |
|
534 break; |
|
535 } |
|
536 } |
|
537 |
|
538 void CEventExpressionXmlHandler::OnEndElementL(const Xml::RTagInfo& /*aElement*/, TInt /*aErrorCode*/) |
|
539 { |
|
540 // Check which element we are supposed to be parsing |
|
541 switch(iParseState) |
|
542 { |
|
543 case EEventElement: |
|
544 // This is the last element we were looking for so build our event expression |
|
545 iEventExpression = TEventExpression(iSender, iMessage, iReceiver); |
|
546 iParseState = EDone; |
|
547 break; |
|
548 |
|
549 case ESenderNodeElement: |
|
550 iParseState = EMsgElement; |
|
551 break; |
|
552 |
|
553 case EMsgElement: |
|
554 iParseState = EReceiverNodeElement; |
|
555 break; |
|
556 |
|
557 case EReceiverNodeElement: |
|
558 iParseState = EEventElement; |
|
559 break; |
|
560 |
|
561 case EDone: |
|
562 break; |
|
563 |
|
564 default: |
|
565 __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestXmlPrsn, 2)); |
|
566 break; |
|
567 } |
|
568 } |
|
569 |
|
570 void CEventExpressionXmlHandler::ParseProviderInfoAttributeL( |
|
571 const Xml::RAttributeArray& aAttributes, |
|
572 TUid& aTierId, |
|
573 TUint& aAPId) |
|
574 { |
|
575 TXmlTempBuf8 tempBuffer; |
|
576 FetchAttributeValueByNameL(aAttributes, KProviderInfoAttributeName, tempBuffer); |
|
577 |
|
578 TPtrC8 tierIdentifier; |
|
579 TPtrC8 accessPointIdentifier; |
|
580 |
|
581 // Provider info is several fields |
|
582 // Split in to comma separated fields |
|
583 TLex8 lexer(tempBuffer); |
|
584 lexer.SkipSpace(); |
|
585 lexer.Mark(); |
|
586 while((lexer.Peek() != TChar(',')) && !lexer.Eos()) |
|
587 { |
|
588 lexer.Inc(); |
|
589 } |
|
590 |
|
591 // If indeed we have just finished the first chunk |
|
592 if(lexer.Peek() == TChar(',')) |
|
593 { |
|
594 // Grab the first chunk and slurp the comma |
|
595 tierIdentifier.Set(lexer.MarkedToken()); |
|
596 lexer.Inc(); |
|
597 |
|
598 // Grab the rest |
|
599 if(lexer.Eos()) |
|
600 { |
|
601 User::Leave(KErrArgument); |
|
602 } |
|
603 else |
|
604 { |
|
605 lexer.Mark(); |
|
606 accessPointIdentifier.Set(lexer.Remainder()); |
|
607 } |
|
608 } |
|
609 else |
|
610 { |
|
611 User::Leave(KErrArgument); |
|
612 } |
|
613 |
|
614 // Now parse out the values themselves |
|
615 TUint tierIdValue; |
|
616 FetchValueOrNamedValueL(ETierIdTable, tierIdentifier, tierIdValue); |
|
617 FetchValueOrNamedValueL(EAccessPointIdTable, accessPointIdentifier, aAPId); |
|
618 |
|
619 aTierId = TUid::Uid(tierIdValue); |
|
620 } |
|
621 |
|
622 void CEventExpressionXmlHandler::ParseUidAttributeL( |
|
623 const Xml::RAttributeArray& aAttributes, |
|
624 TUid& aUid) |
|
625 { |
|
626 TXmlTempBuf8 tempBuffer; |
|
627 FetchAttributeValueByNameL(aAttributes, KUidAttributeName, tempBuffer); |
|
628 |
|
629 TUint fetchedValue; |
|
630 FetchValueOrNamedValueL(EUidTable, tempBuffer, fetchedValue); |
|
631 aUid = TUid::Uid(fetchedValue); |
|
632 } |
|
633 |
|
634 void CEventExpressionXmlHandler::ParseNodeTagAttributeL(const Xml::RAttributeArray& aAttributes, TDes8& aTagToApply) |
|
635 { |
|
636 TXmlTempBuf8 tempBuffer; |
|
637 FetchAttributeValueByNameL(aAttributes, KNodeTagAttributeName, tempBuffer); |
|
638 aTagToApply.Copy(tempBuffer); |
|
639 } |
|
640 |
|
641 void CEventExpressionXmlHandler::ParseNodeTagToApplyAttributeL(const Xml::RAttributeArray& aAttributes, TDes8& aTagToApply) |
|
642 { |
|
643 TXmlTempBuf8 tempBuffer; |
|
644 FetchAttributeValueByNameL(aAttributes, KNodeTagToApplyAttributeName, tempBuffer); |
|
645 aTagToApply.Copy(tempBuffer); |
|
646 } |
|
647 |
|
648 |