|
1 /* |
|
2 * Copyright (c) 2004 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: Parser for DM 1.2 formatted alert message |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <DevManInternalCRKeys.h> |
|
21 #include "NSmlAlertQueue.h" |
|
22 #include "nsmldebug.h" |
|
23 // --------------------------------------------------------- |
|
24 // CNSmlDSAlertParser11(CSmlAlertInfo& aAlertInfo, CSyncMLHistoryPushMsg& aHistoryInfo ) |
|
25 // Returns pointer to the buffer |
|
26 // --------------------------------------------------------- |
|
27 // |
|
28 CNSmlDMAlertParser11::CNSmlDMAlertParser11( CSmlAlertInfo& aAlertInfo, CSyncMLHistoryPushMsg& aHistoryInfo ) |
|
29 : CNSmlMessageParserBase( aAlertInfo, aHistoryInfo ) |
|
30 {_DBG_FILE("CNSmlDMAlertParser11::CNSmlDMAlertParser11 begin!"); |
|
31 } |
|
32 |
|
33 // --------------------------------------------------------- |
|
34 // CNSmlDMAlertParser11::~CNSmlDMAlertParser11() |
|
35 // Destructor |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CNSmlDMAlertParser11::~CNSmlDMAlertParser11() |
|
39 {_DBG_FILE("CNSmlDMAlertParser11::~CNSmlDMAlertParser11 End"); |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CNSmlDMAlertParser11::ParseMessageL() |
|
44 // Parses the aler message |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 void CNSmlDMAlertParser11::ParseMessageL() |
|
48 { |
|
49 _DBG_FILE("CNSmlDMAlertParser11::ParseMessageL begin!"); |
|
50 |
|
51 //digest |
|
52 CheckLengthL( KNSmlAlertVersionPos + 1 ); |
|
53 iHistoryInfo.SetMsgDigest( Message().Left( KNSmlAlertVersionPos ) ); |
|
54 |
|
55 //version |
|
56 TInt version; |
|
57 version = ((TUint8) Message()[ KNSmlAlertVersionPos ]) << 8; |
|
58 version |= (TUint8) Message()[ KNSmlAlertVersionPos + 1 ]; |
|
59 version = version >> 6; |
|
60 |
|
61 //ui interaction mode |
|
62 TInt uiMode = (TUint8) Message()[ KNSmlAlertVersionPos + 1 ] & KUiModeMask; |
|
63 uiMode = uiMode >> 4; |
|
64 DBG_FILE_CODE(uiMode, _S8("CNSmlDMAlertParser11::ParseMessageL() : ui mode ")); |
|
65 TInt SanSupport( KErrNone ); |
|
66 CRepository* centrep = NULL; |
|
67 TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) ); |
|
68 if( err == KErrNone ) |
|
69 { |
|
70 centrep->Get( KDevManSANUIBitVariation, SanSupport ); |
|
71 } |
|
72 delete centrep; |
|
73 if( SanSupport == 1 ) |
|
74 { |
|
75 iAlertInfo.SetUimode(uiMode); |
|
76 } |
|
77 if (uiMode == 0) |
|
78 { |
|
79 uiMode = CSmlAlertInfo::ECreateJob; |
|
80 } |
|
81 |
|
82 iAlertInfo.SetJobControl((CSmlAlertInfo::TJobControl) uiMode); |
|
83 |
|
84 //initiator |
|
85 TInt initiator = (TUint8) Message()[ KNSmlAlertVersionPos + 1 ] & KInitiatorMask; |
|
86 initiator = initiator >> 3; |
|
87 |
|
88 //reserved |
|
89 TInt futNum = (TUint8) Message()[ KNSmlAlertVersionPos + 1 ] & KMaskUpperFuture; |
|
90 |
|
91 //session id |
|
92 CheckLengthL( KNSmlAlertSession + 1 ); |
|
93 TInt sessionId; |
|
94 sessionId = ((TUint8) Message()[ KNSmlAlertSession ]) << 8; |
|
95 sessionId |= (TUint8) Message()[ KNSmlAlertSession + 1 ]; |
|
96 iAlertInfo.SetSessionId( sessionId ); |
|
97 |
|
98 //server id length |
|
99 CheckLengthL( KNSmlAlertServerIdLength ); |
|
100 TInt serverIdLength; |
|
101 serverIdLength = (TUint8) Message()[ KNSmlAlertServerIdLength ]; |
|
102 |
|
103 //server id |
|
104 CheckLengthL( KNSmlAlertServerIdLenPos + serverIdLength ); |
|
105 HBufC8* hostAddress = HBufC8::NewLC( serverIdLength ); |
|
106 hostAddress->Des().Copy( Message().Mid(KNSmlAlertServerIdLenPos, serverIdLength)); |
|
107 |
|
108 //Try to find profile before accessing content types |
|
109 SearchProfileL( *hostAddress ); |
|
110 |
|
111 if ( iFoundProfiles.Count() == 0 ) |
|
112 { |
|
113 iAlertInfo.SetProfileId( KNSmlNullId ); |
|
114 User::Leave(KErrNotFound); |
|
115 } |
|
116 |
|
117 CleanupStack::PopAndDestroy(); //hostAddress |
|
118 |
|
119 TRAPD(error, CheckLengthL( KNSmlAlertServerIdLenPos + serverIdLength + 1 ) ); |
|
120 |
|
121 if ( error == KErrNone ) |
|
122 { |
|
123 TInt fut = (TUint8) Message()[ KNSmlAlertServerIdLenPos + serverIdLength] & KFutureMask; |
|
124 } |
|
125 |
|
126 TInt firstBytePlace = KNSmlAlertServerIdLenPos + serverIdLength + 1; |
|
127 |
|
128 if ( Message().Length() - firstBytePlace > 0 ) |
|
129 { |
|
130 //vendor-info |
|
131 HBufC8* vendorInfo = HBufC8::NewLC( Message().Length() - firstBytePlace ); |
|
132 vendorInfo->Des().Copy( Message().Mid( firstBytePlace, Message().Length() - firstBytePlace )); |
|
133 iAlertInfo.SetVendorSpecificInfoL( vendorInfo->Des() ); |
|
134 CleanupStack::PopAndDestroy(); //vendorInfo |
|
135 } |
|
136 else |
|
137 { |
|
138 iAlertInfo.SetVendorSpecificInfoL( KNullDesC8() ); |
|
139 } |
|
140 |
|
141 ResolveProfileL(0); |
|
142 _DBG_FILE("CNSmlDMAlertParser11::ParseMessageL End"); |
|
143 } |
|
144 |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CNSmlDMAlertParser11::SearchProfileL(TDesC8& aServerUri) |
|
148 // Searches for the profile |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 void CNSmlDMAlertParser11::SearchProfileL( TDesC8& aServerUri ) |
|
152 { |
|
153 |
|
154 HBufC *serverId = HBufC::NewLC(aServerUri.Size()); |
|
155 TPtr typePtr = serverId->Des(); |
|
156 CnvUtfConverter::ConvertToUnicodeFromUtf8( typePtr, aServerUri); |
|
157 |
|
158 CNSmlDMSettings* settings = CNSmlDMSettings::NewLC(); |
|
159 if ( settings->IsDMAllowedL() ) |
|
160 { |
|
161 CNSmlDMProfileList* profileList = new( ELeave ) CArrayPtrFlat<CNSmlDMProfileListItem>(1); |
|
162 CleanupStack::PushL( PtrArrCleanupItem( CNSmlDMProfileListItem, profileList ) ); |
|
163 settings->GetProfileListL( profileList ); |
|
164 for ( TInt i = 0; i < profileList->Count(); i++) |
|
165 { |
|
166 TInt profileID = (*profileList)[i]->IntValue( TNSmlDMProfileData( EDSProfileId ) ); |
|
167 CNSmlDMProfile* profile = settings->ProfileL( profileID ); |
|
168 CleanupStack::PushL( profile ); |
|
169 if ( profile->IntValue( TNSmlDMProfileData( EDMProfileServerAlertAction ) ) != ESmlDisableSync ) |
|
170 { |
|
171 if ( *serverId == profile->StrValue( EDMProfileServerId ) ) |
|
172 { |
|
173 if ( iAlertInfo.Transport() == KUidNSmlMediumTypeInternet.iUid ) |
|
174 { |
|
175 // accept only internet bearers |
|
176 if ( profile->IntValue(EDMProfileTransportId) == KUidNSmlMediumTypeInternet.iUid ) |
|
177 |
|
178 { |
|
179 CNSmlAlertInfo* info = new (ELeave) CNSmlAlertInfo; |
|
180 info->iProfileId = profile->IntValue( EDMProfileId ); |
|
181 info->iIAPId = profile->IntValue( EDMProfileIAPId ); |
|
182 iFoundProfiles.AppendL( info ); |
|
183 } |
|
184 } |
|
185 else |
|
186 { |
|
187 // accept only local bearers |
|
188 if ( profile->IntValue(EDMProfileTransportId) != KUidNSmlMediumTypeInternet.iUid ) |
|
189 { |
|
190 CNSmlAlertInfo* info = new (ELeave) CNSmlAlertInfo; |
|
191 info->iProfileId = profile->IntValue( EDMProfileId ); |
|
192 info->iIAPId = profile->IntValue( EDMProfileIAPId ); |
|
193 iFoundProfiles.AppendL( info ); |
|
194 } |
|
195 } |
|
196 } |
|
197 } |
|
198 CleanupStack::PopAndDestroy(); // profile |
|
199 } |
|
200 profileList->ResetAndDestroy(); |
|
201 CleanupStack::PopAndDestroy(); //profileList |
|
202 } |
|
203 CleanupStack::PopAndDestroy( 2 ); //settings, serverId |
|
204 |
|
205 if ( iAlertInfo.Transport() == KUidNSmlMediumTypeInternet.iUid ) |
|
206 { |
|
207 if ( iFoundProfiles.Count() > 1 ) |
|
208 { |
|
209 RArray<TInt> indexes; |
|
210 CleanupClosePushL( indexes ); |
|
211 |
|
212 for (TInt j = 0; j < iFoundProfiles.Count(); j++ ) |
|
213 { |
|
214 CNSmlAlertInfo* info = iFoundProfiles[j]; |
|
215 if ( info->iIAPId == -1 ) |
|
216 { |
|
217 indexes.Append( j ); |
|
218 } |
|
219 } |
|
220 |
|
221 if ( indexes.Count() < iFoundProfiles.Count() ) |
|
222 { |
|
223 for ( TInt count(0); count < indexes.Count(); count++ ) |
|
224 { |
|
225 CNSmlAlertInfo* temp = iFoundProfiles[indexes[count]]; |
|
226 iFoundProfiles.Remove( indexes[count] ); |
|
227 delete temp; |
|
228 temp = NULL; |
|
229 } |
|
230 } |
|
231 |
|
232 CleanupStack::PopAndDestroy( &indexes ); |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------- |
|
238 // CNSmlDMAlertParser11::ResolveProfileL(TInt aContentCount) |
|
239 // Resolves profile |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 void CNSmlDMAlertParser11::ResolveProfileL( TInt /*aContentCount*/ ) |
|
243 { |
|
244 iAlertInfo.SetProfileId(iFoundProfiles[0]->iProfileId); |
|
245 } |