1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "logseventdataparser.h" |
|
20 #include "logseventdata.h" |
|
21 #include <e32std.h> |
|
22 #include <logeng.h> |
|
23 #include <logsmspdudata.h> |
|
24 #include "LogsApiConsts.h" |
|
25 |
|
26 |
|
27 // Separator for gprs data (old legacy non-tagged format for sent and |
|
28 // received grps data) |
|
29 _LIT8(KDataSeparator,","); |
|
30 |
|
31 // ---------------------------------------------------------------------------- |
|
32 // LogsEventDataParser::parse |
|
33 // ---------------------------------------------------------------------------- |
|
34 // |
|
35 int LogsEventDataParser::parse( |
|
36 const CLogEvent& source, LogsEventData& dest ) |
|
37 { |
|
38 // For SMS'es part data is packed into data field (by sms stack), so in |
|
39 // this case there is no need to try to parse S60 specific data from it. |
|
40 bool readMessageParts = ( |
|
41 source.EventType() == KLogShortMessageEventTypeUid || |
|
42 source.EventType() == KLogsEngMmsEventTypeUid ); |
|
43 const TDesC8& data = source.Data(); |
|
44 |
|
45 //All default values must already be set in case there is no data in the |
|
46 //event's data field. |
|
47 dest.mIsCNAP = false; |
|
48 dest.mIsVT = false; |
|
49 dest.mIsVoIP = false; |
|
50 dest.mIsPoC = false; |
|
51 dest.mIsEmerg = false; |
|
52 dest.mMsgPartsNumber = 0; //Meaningful only for sms |
|
53 dest.mServiceId = 0; |
|
54 dest.mContactLocalId = 0; |
|
55 dest.mDataSent = 0; |
|
56 dest.mDataReceived = 0; |
|
57 dest.mRemoteUrl.clear(); |
|
58 dest.mLocalUrl.clear(); |
|
59 |
|
60 // 1. Msg parts are written in different format in data field. |
|
61 if( readMessageParts ) { |
|
62 setMsgPartsNumber( data, dest ); |
|
63 } |
|
64 // 2. else check if the sent & received data is in old format (this can be |
|
65 // removed when creating log data field entries is similar to format of |
|
66 // other data field entries (i.e is tagged)) |
|
67 else if ( !checkNonTaggedData( data, dest ) ) { |
|
68 // 3. Otherwise check if tagged data is available. |
|
69 checkTaggedData( data, dest ); |
|
70 } |
|
71 return 0; |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // LogsEventDataParser::setMsgPartsNumber |
|
76 // Read msg parts. They are written in format of TLogSmsPduData in Data field |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 void LogsEventDataParser::setMsgPartsNumber( const TDesC8 &data, LogsEventData& dest ) |
|
80 { |
|
81 TPckgBuf<TLogSmsPduData> packedData; |
|
82 packedData.Copy( data.Ptr(), sizeof( TLogSmsPduData ) ); |
|
83 dest.mMsgPartsNumber = packedData().iTotal; |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // LogsEventDataParser::checkNonTaggedData |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 bool LogsEventDataParser::checkNonTaggedData( const TDesC8 &data, LogsEventData& dest ) |
|
91 { |
|
92 if( data.Length() < 1 ) { |
|
93 return false; |
|
94 } |
|
95 |
|
96 //At least 1 byte of data available. Check does it begin with number. |
|
97 TInt v; |
|
98 TPtrC8 ptr( data.Left(1) ); |
|
99 TLex8 lex = ptr; |
|
100 if( lex.Val( v ) != KErrNone ) { |
|
101 //First byte does not contain number |
|
102 return false; |
|
103 } |
|
104 |
|
105 //Ok, data begins with number. Try to read a pair of comma separated numbers |
|
106 TInt separatorOffset = data.Find( KDataSeparator ); |
|
107 if( separatorOffset + 1 > data.Length() || separatorOffset < 0 ) { |
|
108 //No separator found. |
|
109 return false; |
|
110 } |
|
111 |
|
112 ptr.Set( data.Left( separatorOffset ) ); |
|
113 lex = ptr; |
|
114 lex.Val( dest.mDataSent ); |
|
115 |
|
116 if( (separatorOffset + 1) < data.Length() ){ |
|
117 // Parse rest |
|
118 ptr.Set( data.Mid(separatorOffset + 1, data.Length() - separatorOffset - 1) ); |
|
119 lex = ptr; |
|
120 lex.Val( dest.mDataReceived ); |
|
121 } |
|
122 |
|
123 return true; |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // LogsEventDataParser::checkTaggedData |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 void LogsEventDataParser::checkTaggedData( const TDesC8 &data, LogsEventData& dest ) |
|
131 { |
|
132 TPtrC8 dataPtr( data ); |
|
133 TInt dataLeft = dataPtr.Length(); |
|
134 while( dataLeft > 0 ){ |
|
135 TInt nextTokenStart = dataPtr.Find( KLogsDataFldNameDelimiter() ); |
|
136 if ( nextTokenStart > dataPtr.Length() || nextTokenStart < 0 ) { |
|
137 nextTokenStart = dataPtr.Length(); |
|
138 } |
|
139 |
|
140 TPtrC8 nameValue = dataPtr.Left( nextTokenStart ); |
|
141 TPtrC8 name; |
|
142 TPtrC8 value; |
|
143 |
|
144 TInt delimiterStart = nameValue.Find( KLogsDataFldValueDelimiter() ); |
|
145 if( delimiterStart > dataPtr.Length() || delimiterStart < 0 ){ |
|
146 name.Set( nameValue ); |
|
147 //No value. Initialised to null in above (TPtrC8 value) |
|
148 } else { |
|
149 name.Set( dataPtr.Left( delimiterStart ) ); |
|
150 TInt length = nameValue.Length() - delimiterStart - 1; |
|
151 value.Set( dataPtr.Mid( delimiterStart + 1, length) ); |
|
152 } |
|
153 |
|
154 // Below a minor attempt to slightly speed up the string comparisons: |
|
155 // If value already found, no need to compare same name anymore. |
|
156 // Most likely there is VT, VOIP or POC tag in the beginning of data |
|
157 // field if any tags. |
|
158 if( !dest.mIsVT && name.Compare( KLogsDataFldTag_VT ) == 0 ){ |
|
159 dest.mIsVT = true; |
|
160 } else if( !dest.mIsCNAP && name.Compare( KLogsDataFldTag_CNAP ) == 0 ){ |
|
161 dest.mIsCNAP = true; |
|
162 } else if( !dest.mIsEmerg && name.Compare( KLogsDataFldTag_Emergency ) == 0 ){ |
|
163 dest.mIsEmerg = true; |
|
164 } else if( !dest.mIsPoC && name.Compare( KLogsDataFldTag_POC ) == 0 ){ |
|
165 dest.mIsPoC = true; |
|
166 } else if( !dest.mIsVoIP && name.Compare( KLogsDataFldTag_IP ) == 0 ){ |
|
167 dest.mIsVoIP = true; |
|
168 } else if( !dest.mServiceId && name.Compare( KLogsDataFldTag_ServiceId ) == 0 ) { |
|
169 TLex8 lex( value ); |
|
170 TUint32 temp( 0 ); |
|
171 TInt err = lex.Val( temp , EDecimal ); |
|
172 if ( KErrNone == err ) { |
|
173 //if an error occurred we leave the service id unchanged |
|
174 dest.mServiceId = temp; |
|
175 } |
|
176 } else if ( !dest.mContactLocalId && |
|
177 name.Compare( KLogsDataFldTag_ContactLink ) == 0 ) { |
|
178 HBufC8* contactLink = value.AllocLC(); |
|
179 TLex8 lex( contactLink->Des() ); |
|
180 TUint32 temp( 0 ); |
|
181 TInt err = lex.Val( temp , EDecimal ); |
|
182 if ( KErrNone == err ) { |
|
183 dest.mContactLocalId = temp; |
|
184 } |
|
185 CleanupStack::PopAndDestroy(contactLink); |
|
186 |
|
187 } else if ( dest.mRemoteUrl.isEmpty() && name.Compare( KLogsDataFldTag_URL ) == 0 ) { |
|
188 // VoIP strips unneeded stuff from uri before writing the log |
|
189 // event to db (it removes '<' '>', "sip:", and everything after ';', |
|
190 // see svpsslogcall.cpp) so no need to postprocess. |
|
191 dest.mRemoteUrl = QString::fromUtf8( (char*)value.Ptr(), value.Length() ); |
|
192 } else if ( dest.mLocalUrl.isEmpty() && name.Compare( KLogsDataFldTag_MA ) == 0 ) { |
|
193 dest.mLocalUrl = QString::fromUtf8( (char*)value.Ptr(), value.Length() ); |
|
194 } |
|
195 |
|
196 //Process remaining data |
|
197 dataLeft = dataPtr.Length() - nextTokenStart - 1; |
|
198 if ( dataLeft > 0 ) { |
|
199 //Continue with remaining data on the right side of token |
|
200 nameValue.Set( dataPtr.Right( dataLeft ) ); |
|
201 dataPtr.Set( nameValue ); |
|
202 } |
|
203 } |
|
204 } |
|