|
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: Symbian OS Server source. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nsmlsosserver.h" |
|
20 #include "nsmlroam.h" |
|
21 #include "NSmlTransportHandler.h" |
|
22 |
|
23 // -------------------------------------------------------------------------- |
|
24 // CNSmlConnection::CNSmlConnection( const TInt aProfId, const TInt aTransId ) |
|
25 // -------------------------------------------------------------------------- |
|
26 // |
|
27 CNSmlConnection::CNSmlConnection( const TInt aProfId, const TInt aTransId, CNSmlSOSSession& aSession ) |
|
28 : iProfId(aProfId), iTransId(aTransId), iSession(aSession), iDataPtr(NULL, 0, 0) |
|
29 { |
|
30 } |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CNSmlConnection::~CNSmlConnection() |
|
34 // -------------------------------------------------------------------------- |
|
35 // |
|
36 CNSmlConnection::~CNSmlConnection() |
|
37 { |
|
38 delete iBuffer; |
|
39 } |
|
40 |
|
41 // -------------------------------------------------------------------------- |
|
42 // TInt CNSmlConnection::FetchDataL() |
|
43 // -------------------------------------------------------------------------- |
|
44 // |
|
45 TInt CNSmlConnection::FetchDataL() |
|
46 { |
|
47 TInt ret(KErrNotFound); |
|
48 if ( iProfId < KMaxDataSyncID ) // DS Profile |
|
49 { |
|
50 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
51 if ( prof ) |
|
52 { |
|
53 CleanupStack::PushL(prof); |
|
54 |
|
55 // Check if transport id differs from one saved to profile. |
|
56 if ( iTransId != prof->IntValue( EDSProfileTransportId ) ) |
|
57 { |
|
58 CleanupStack::PopAndDestroy(prof); |
|
59 return KErrNotFound; |
|
60 } |
|
61 |
|
62 // String lengths. (+1 is because of zero-length strings which are added to streams also). |
|
63 TInt urllen = prof->StrValue( EDSProfileServerURL ).Size(); |
|
64 TInt unlen = prof->StrValue( EDSProfileHttpAuthUsername ).Size(); |
|
65 TInt pwlen = prof->StrValue( EDSProfileHttpAuthPassword ).Size(); |
|
66 |
|
67 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
68 CleanupStack::PushL( buffer ); |
|
69 RBufWriteStream stream( *buffer ); |
|
70 CleanupClosePushL(stream); |
|
71 |
|
72 stream.WriteInt32L( urllen ); |
|
73 stream << prof->StrValue( EDSProfileServerURL ); |
|
74 |
|
75 stream.WriteInt32L( prof->IntValue(EDSProfileIAPId ) ); |
|
76 |
|
77 CNSmlRoamTable* roamTable = CNSmlRoamTable::NewL( *iSession.DSSettings().Database() ); |
|
78 CleanupStack::PushL( roamTable ); |
|
79 |
|
80 CNSmlIAPArray* array = roamTable->GetItemsForIdL( iProfId ); |
|
81 CleanupStack::PushL( array ); |
|
82 |
|
83 for ( TInt i(0) ; i < array->Count() ; i++ ) |
|
84 { |
|
85 stream.WriteInt32L( array->At(i) ); |
|
86 } |
|
87 |
|
88 TInt iapCount = array->Count() + 1; |
|
89 |
|
90 while ( iapCount < KMaxIAPCount ) |
|
91 { |
|
92 stream.WriteInt32L(0); // write zero values to IAP ids that doesn't exist. |
|
93 iapCount++; |
|
94 } |
|
95 |
|
96 CleanupStack::PopAndDestroy(array); |
|
97 CleanupStack::PopAndDestroy(roamTable); |
|
98 |
|
99 stream.WriteInt32L( prof->IntValue(EDSProfileAutoChangeIAP ) ); |
|
100 |
|
101 stream.WriteInt32L( prof->IntValue(EDSProfileHttpAuthUsed ) ); |
|
102 |
|
103 stream.WriteInt32L( unlen ); |
|
104 stream << prof->StrValue( EDSProfileHttpAuthUsername ); |
|
105 |
|
106 stream.WriteInt32L( pwlen ); |
|
107 stream << prof->StrValue( EDSProfileHttpAuthPassword ); |
|
108 |
|
109 stream.CommitL(); |
|
110 |
|
111 CleanupStack::PopAndDestroy(&stream); |
|
112 |
|
113 delete iBuffer; |
|
114 iBuffer = buffer; |
|
115 CleanupStack::Pop( buffer ); |
|
116 |
|
117 CleanupStack::PopAndDestroy(prof); |
|
118 ret = KErrNone; |
|
119 } |
|
120 } |
|
121 else // DM Profile |
|
122 { |
|
123 CNSmlDMProfile* prof = iSession.DMSettings().ProfileL( iProfId ); |
|
124 if ( prof ) |
|
125 { |
|
126 CleanupStack::PushL(prof); |
|
127 |
|
128 if ( iTransId != prof->IntValue( EDMProfileTransportId ) ) |
|
129 { |
|
130 CleanupStack::PopAndDestroy(prof); |
|
131 return KErrNotFound; |
|
132 } |
|
133 |
|
134 TInt urllen = prof->StrValue( EDMProfileServerURL ).Size(); |
|
135 TInt unlen = prof->StrValue( EDMProfileHttpAuthUsername ).Size(); |
|
136 TInt pwlen = prof->StrValue( EDMProfileHttpAuthPassword ).Size(); |
|
137 |
|
138 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
139 CleanupStack::PushL( buffer ); |
|
140 RBufWriteStream stream( *buffer ); |
|
141 |
|
142 CleanupClosePushL(stream); |
|
143 |
|
144 stream.WriteInt32L( urllen ); |
|
145 stream << prof->StrValue( EDMProfileServerURL ); |
|
146 |
|
147 stream.WriteInt32L( prof->IntValue( EDMProfileIAPId ) ); |
|
148 |
|
149 stream.WriteInt32L( prof->IntValue(EDMProfileHttpAuthUsed ) ); |
|
150 |
|
151 stream.WriteInt32L( unlen ); |
|
152 stream << prof->StrValue( EDMProfileHttpAuthUsername ); |
|
153 |
|
154 stream.WriteInt32L( pwlen ); |
|
155 stream << prof->StrValue( EDMProfileHttpAuthPassword ); |
|
156 |
|
157 stream.CommitL(); |
|
158 |
|
159 CleanupStack::PopAndDestroy(&stream); |
|
160 |
|
161 delete iBuffer; |
|
162 iBuffer = buffer; |
|
163 CleanupStack::Pop( buffer ); |
|
164 |
|
165 CleanupStack::PopAndDestroy(prof); |
|
166 ret = KErrNone; |
|
167 } |
|
168 } |
|
169 return ret; |
|
170 } |
|
171 |
|
172 // -------------------------------------------------------------------------- |
|
173 // TInt CNSmlConnection::DataSize() |
|
174 // -------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CNSmlConnection::DataSize() |
|
177 { |
|
178 return iBuffer->Size(); |
|
179 } |
|
180 |
|
181 // -------------------------------------------------------------------------- |
|
182 // const TPtr8& CNSmlConnection::ReadData() |
|
183 // -------------------------------------------------------------------------- |
|
184 // |
|
185 const TPtr8& CNSmlConnection::ReadData() |
|
186 { |
|
187 if ( iBuffer ) |
|
188 { |
|
189 iDataPtr.Set(iBuffer->Ptr(0)); |
|
190 } |
|
191 return iDataPtr; |
|
192 } |
|
193 |
|
194 // -------------------------------------------------------------------------- |
|
195 // TInt CNSmlConnection::UpdateDataL( const TDesC8& aData ) |
|
196 // -------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CNSmlConnection::UpdateDataL( const TDesC8& aData ) |
|
199 { |
|
200 TInt ret(KErrNotFound); |
|
201 if ( iProfId < KMaxDataSyncID ) // DS Profile |
|
202 { |
|
203 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
204 CleanupStack::PushL(prof); |
|
205 |
|
206 RDesReadStream stream; |
|
207 stream.Open(aData); |
|
208 CleanupClosePushL(stream); |
|
209 |
|
210 TInt maxlen(0); |
|
211 TInt pc(0); |
|
212 |
|
213 // Transport Id |
|
214 TInt transportId = stream.ReadInt32L(); |
|
215 prof->SetIntValue( EDSProfileTransportId, transportId ); |
|
216 |
|
217 CNSmlTransportHandler* tHandler = CNSmlTransportHandler::NewL( ESmlDataSync ); |
|
218 CleanupStack::PushL(tHandler); |
|
219 |
|
220 tHandler->CreateL( transportId ); |
|
221 CSyncMLTransportPropertiesArray& propArray = tHandler->Array(); |
|
222 |
|
223 CNSmlIAPArray* array = new (ELeave) CArrayFixFlat<TUint32>(1); |
|
224 CleanupStack::PushL( array ); |
|
225 |
|
226 // Server URI |
|
227 maxlen = stream.ReadInt32L(); |
|
228 prof->SetStrValue( EDSProfileServerURL, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
229 |
|
230 for ( TInt i(0) ; i < propArray.Count() ; i++ ) |
|
231 { |
|
232 if ( !propArray.At(i).iName.Compare( KNSmlIAPId() ) ) |
|
233 { |
|
234 prof->SetIntValue( EDSProfileIAPId, stream.ReadInt32L() ); |
|
235 } |
|
236 else if ( !propArray.At(i).iName.Compare( KNSmlIAPId2() ) ) |
|
237 { |
|
238 TInt IAPId2 = stream.ReadInt32L(); |
|
239 if ( IAPId2 ) // Add IAP id only if it has a value. |
|
240 { |
|
241 array->AppendL( IAPId2 ); |
|
242 } |
|
243 } |
|
244 else if ( !propArray.At(i).iName.Compare( KNSmlIAPId3() ) ) |
|
245 { |
|
246 TInt IAPId3 = stream.ReadInt32L(); |
|
247 if ( IAPId3 ) // Add IAP id only if it has a value. |
|
248 { |
|
249 array->AppendL( IAPId3 ); |
|
250 } |
|
251 } |
|
252 else if ( !propArray.At(i).iName.Compare( KNSmlIAPId4() ) ) |
|
253 { |
|
254 TInt IAPId4 = stream.ReadInt32L(); |
|
255 if ( IAPId4 ) // Add IAP id only if it has a value. |
|
256 { |
|
257 array->AppendL( IAPId4 ); |
|
258 } |
|
259 } |
|
260 else if ( !propArray.At(i).iName.Compare( KNSmlUseRoaming() ) ) |
|
261 { |
|
262 prof->SetIntValue( EDSProfileAutoChangeIAP, stream.ReadInt32L() ); |
|
263 } |
|
264 else if ( !propArray.At(i).iName.Compare( KNSmlHTTPAuth() ) ) |
|
265 { |
|
266 prof->SetIntValue( EDSProfileHttpAuthUsed, stream.ReadInt32L() ); |
|
267 } |
|
268 else if ( !propArray.At(i).iName.Compare( KNSmlHTTPUsername() ) ) |
|
269 { |
|
270 maxlen = stream.ReadInt32L(); |
|
271 prof->SetStrValue( EDSProfileHttpAuthUsername, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
272 } |
|
273 else if ( !propArray.At(i).iName.Compare( KNSmlHTTPPassword() ) ) |
|
274 { |
|
275 maxlen = stream.ReadInt32L(); |
|
276 prof->SetStrValue( EDSProfileHttpAuthPassword, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
277 } |
|
278 } |
|
279 |
|
280 if ( array->Count() ) // Check if array has values. |
|
281 { |
|
282 CNSmlRoamTable* roamTable = CNSmlRoamTable::NewL( *iSession.DSSettings().Database() ); |
|
283 CleanupStack::PushL( roamTable ); |
|
284 |
|
285 roamTable->PutItemsL( iProfId, array ); |
|
286 CleanupStack::PopAndDestroy(roamTable); |
|
287 } |
|
288 |
|
289 ret = prof->SaveL(); |
|
290 |
|
291 CleanupStack::PopAndDestroy(pc); |
|
292 CleanupStack::PopAndDestroy(array); |
|
293 CleanupStack::PopAndDestroy(tHandler); |
|
294 CleanupStack::PopAndDestroy(&stream); |
|
295 CleanupStack::PopAndDestroy(prof); |
|
296 |
|
297 } |
|
298 else // DM Profile |
|
299 { |
|
300 CNSmlDMProfile* prof = iSession.DMSettings().ProfileL( iProfId ); |
|
301 CleanupStack::PushL(prof); |
|
302 |
|
303 RDesReadStream stream; |
|
304 stream.Open(aData); |
|
305 CleanupClosePushL(stream); |
|
306 |
|
307 TInt maxlen(0); |
|
308 TInt pc(0); |
|
309 |
|
310 // Transport Id |
|
311 TInt transportId = stream.ReadInt32L(); |
|
312 |
|
313 prof->SetIntValue( EDMProfileTransportId, transportId ); |
|
314 |
|
315 CNSmlTransportHandler* tHandler = CNSmlTransportHandler::NewL( ESmlDevMan ); |
|
316 CleanupStack::PushL(tHandler); |
|
317 tHandler->CreateL( transportId ); |
|
318 CSyncMLTransportPropertiesArray& propArray = tHandler->Array(); |
|
319 |
|
320 // Server URI |
|
321 maxlen = stream.ReadInt32L(); |
|
322 prof->SetStrValue( EDMProfileServerURL, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
323 |
|
324 for ( TInt i(0) ; i < propArray.Count() ; i++ ) |
|
325 { |
|
326 if ( !propArray.At(i).iName.Compare( KNSmlIAPId() ) ) |
|
327 { |
|
328 prof->SetIntValue( EDMProfileIAPId, stream.ReadInt32L() ); |
|
329 } |
|
330 else if ( !propArray.At(i).iName.Compare( KNSmlHTTPAuth() ) ) |
|
331 { |
|
332 prof->SetIntValue( EDMProfileHttpAuthUsed, stream.ReadInt32L() ); |
|
333 } |
|
334 else if ( !propArray.At(i).iName.Compare( KNSmlHTTPUsername() ) ) |
|
335 { |
|
336 maxlen = stream.ReadInt32L(); |
|
337 prof->SetStrValue( EDMProfileHttpAuthUsername, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
338 } |
|
339 else if ( !propArray.At(i).iName.Compare( KNSmlHTTPPassword() ) ) |
|
340 { |
|
341 maxlen = stream.ReadInt32L(); |
|
342 prof->SetStrValue( EDMProfileHttpAuthPassword, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
343 } |
|
344 } |
|
345 ret = prof->SaveL(); |
|
346 |
|
347 CleanupStack::PopAndDestroy(pc); |
|
348 CleanupStack::PopAndDestroy(tHandler); |
|
349 CleanupStack::PopAndDestroy(&stream); |
|
350 CleanupStack::PopAndDestroy(prof); |
|
351 } |
|
352 return ret; |
|
353 } |