sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
using namespace NCentralRepositoryConstants;
|
sl@0
|
17 |
|
sl@0
|
18 |
inline TServerSetting::TServerSetting()
|
sl@0
|
19 |
: iKey(0),
|
sl@0
|
20 |
iMeta(0),
|
sl@0
|
21 |
iAccessPolicy(0)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
Mem::FillZ(&iValue, sizeof(iValue));
|
sl@0
|
24 |
}
|
sl@0
|
25 |
|
sl@0
|
26 |
inline TServerSetting::TServerSetting(const TUint32 aKey)
|
sl@0
|
27 |
: iKey(aKey),
|
sl@0
|
28 |
iMeta(0),
|
sl@0
|
29 |
iAccessPolicy(0)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
Mem::FillZ(&iValue, sizeof(iValue));
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
/** Ensures this setting has the same type and value of source. Where EString types
|
sl@0
|
35 |
are involved, safely removes previously-owned string, and deep copies string taken
|
sl@0
|
36 |
from source.
|
sl@0
|
37 |
Does not require source and destination type to match. Callers must check if important.
|
sl@0
|
38 |
@return KErrNone if successful or KErrNoMemory if no memory available for copying any string.
|
sl@0
|
39 |
@post If error code is not KErrNone, object is guaranteed to be in its original state.
|
sl@0
|
40 |
*/
|
sl@0
|
41 |
inline TInt TServerSetting::ReplaceTypeAndValue(const TServerSetting& source)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
ASSERT(IsDeleted());
|
sl@0
|
44 |
|
sl@0
|
45 |
if (source.IsStr())
|
sl@0
|
46 |
{
|
sl@0
|
47 |
const HBufC8* sourceBuf = source.GetStrValue();
|
sl@0
|
48 |
HBufC8* buf = sourceBuf ? sourceBuf->Alloc() : NULL;
|
sl@0
|
49 |
if (sourceBuf && !buf)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
return KErrNoMemory;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
ResetValue();
|
sl@0
|
55 |
SetType(EString);
|
sl@0
|
56 |
iValue.s = buf;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
else if (source.IsReal())
|
sl@0
|
59 |
{
|
sl@0
|
60 |
if(!source.iValue.r)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
return KErrCorrupt;
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
TReal* temp = new TReal(source.GetRealValue());
|
sl@0
|
66 |
if (temp == NULL)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
return KErrNoMemory;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
ResetValue();
|
sl@0
|
72 |
SetType(EReal);
|
sl@0
|
73 |
iValue.r = temp;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
else
|
sl@0
|
76 |
{
|
sl@0
|
77 |
ResetValue();
|
sl@0
|
78 |
SetType(source.Type());
|
sl@0
|
79 |
if (source.IsInt())
|
sl@0
|
80 |
{
|
sl@0
|
81 |
iValue.i = source.GetIntValue();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
return KErrNone;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
/** Replaces the contents of this setting with those of source, safely cleaning up previously-
|
sl@0
|
89 |
owned string, and making a deep copy of source string if of string type.
|
sl@0
|
90 |
Does not require source and destination type to match. Callers must check if important.
|
sl@0
|
91 |
@return KErrNone if successful or KErrNoMemory if no memory available for copying any string.
|
sl@0
|
92 |
@post If error code is not KErrNone, object is guaranteed to be in its original state.
|
sl@0
|
93 |
*/
|
sl@0
|
94 |
inline TInt TServerSetting::Replace(const TServerSetting& aSetting)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
if (aSetting.IsStr())
|
sl@0
|
97 |
{
|
sl@0
|
98 |
const HBufC8* sourceBuf = aSetting.GetStrValue();
|
sl@0
|
99 |
HBufC8* targetBuf = sourceBuf ? sourceBuf->Alloc() : NULL;
|
sl@0
|
100 |
if (sourceBuf && !targetBuf)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
return KErrNoMemory;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
Reset();
|
sl@0
|
105 |
*this = aSetting;
|
sl@0
|
106 |
iValue.s = targetBuf;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
else if (aSetting.IsReal())
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TReal* temp = new TReal(aSetting.GetRealValue());
|
sl@0
|
111 |
if(temp == NULL)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
return KErrNoMemory;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
Reset();
|
sl@0
|
117 |
*this = aSetting;
|
sl@0
|
118 |
iValue.r = temp;
|
sl@0
|
119 |
temp = NULL;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
else
|
sl@0
|
122 |
{
|
sl@0
|
123 |
Reset();
|
sl@0
|
124 |
*this = aSetting;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
return KErrNone;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
/** Transfer ownership of the contents of this setting with those of source, safely cleaning up previously-
|
sl@0
|
130 |
owned string, and making a deep copy of source string if of string type.
|
sl@0
|
131 |
Does not require source and destination type to match. Callers must check if important.
|
sl@0
|
132 |
@return KErrNone if successful or KErrNoMemory if no memory available for copying any string.
|
sl@0
|
133 |
@post If error code is not KErrNone, object is guaranteed to be in its original state.
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
inline TInt TServerSetting::Transfer(TServerSetting& aSetting)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
Reset();
|
sl@0
|
138 |
*this = aSetting;
|
sl@0
|
139 |
|
sl@0
|
140 |
Mem::FillZ(&aSetting.iValue, sizeof(aSetting.iValue));
|
sl@0
|
141 |
aSetting.SetType(EDeleted);
|
sl@0
|
142 |
|
sl@0
|
143 |
return KErrNone;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
inline TUint32 TServerSetting::Key() const
|
sl@0
|
148 |
{
|
sl@0
|
149 |
return iKey;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
inline void TServerSetting::SetKey(TUint32 aKey)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
iKey = aKey;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
inline TUint32 TServerSetting::Meta() const
|
sl@0
|
158 |
{
|
sl@0
|
159 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
160 |
return iMeta & ~KMetaInternal;
|
sl@0
|
161 |
#else
|
sl@0
|
162 |
return iMeta & ~KMetaType;
|
sl@0
|
163 |
#endif
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
inline void TServerSetting::SetMeta(const TUint32 aMeta)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
iMeta = (iMeta & KMetaType) | (aMeta & ~KMetaType);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
inline TUint32 TServerSetting::Type() const
|
sl@0
|
172 |
{
|
sl@0
|
173 |
return iMeta & KMetaType;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
inline void TServerSetting::SetType(const TUint32 aType)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
iMeta = (iMeta & ~KMetaType) | (aType & KMetaType);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
inline TInt TServerSetting::GetIntValue() const
|
sl@0
|
182 |
{
|
sl@0
|
183 |
return iValue.i;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
inline const TReal& TServerSetting::GetRealValue() const
|
sl@0
|
187 |
{
|
sl@0
|
188 |
return *(iValue.r);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
inline const HBufC8* TServerSetting::GetStrValue() const
|
sl@0
|
192 |
{
|
sl@0
|
193 |
return iValue.s;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
inline void TServerSetting::SetIntValue(TInt aVal)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
SetType(EInt);
|
sl@0
|
199 |
iValue.i = aVal;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
inline void TServerSetting::SetRealValue(const TReal* aVal)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
ASSERT(aVal);
|
sl@0
|
205 |
SetType(EReal);
|
sl@0
|
206 |
iValue.r = const_cast<TReal*>(aVal);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
|
sl@0
|
210 |
inline void TServerSetting::SetStrValue(const HBufC8* aVal)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
SetType(EString);
|
sl@0
|
213 |
if(aVal && !aVal->Length())
|
sl@0
|
214 |
{
|
sl@0
|
215 |
delete aVal;
|
sl@0
|
216 |
iValue.s = NULL;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
else
|
sl@0
|
219 |
{
|
sl@0
|
220 |
iValue.s = const_cast<HBufC8*>(aVal);
|
sl@0
|
221 |
}
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
inline void TServerSetting::SetDeleted()
|
sl@0
|
225 |
{
|
sl@0
|
226 |
SetType(EDeleted);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
inline TInt TServerSetting::CopyValue(TInt aVal)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
Reset();
|
sl@0
|
232 |
SetIntValue(aVal);
|
sl@0
|
233 |
return KErrNone;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
inline TInt TServerSetting::CopyValue(const TReal& aVal)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
Reset();
|
sl@0
|
239 |
TReal* temp=new TReal(aVal);
|
sl@0
|
240 |
if (!temp)
|
sl@0
|
241 |
return KErrNoMemory;
|
sl@0
|
242 |
SetRealValue(temp);
|
sl@0
|
243 |
return KErrNone;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
inline TInt TServerSetting::CopyValue(const TDesC8& aVal)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
Reset();
|
sl@0
|
249 |
if (aVal.Length())
|
sl@0
|
250 |
{
|
sl@0
|
251 |
HBufC8* temp=aVal.Alloc();
|
sl@0
|
252 |
if (!temp)
|
sl@0
|
253 |
return KErrNoMemory;
|
sl@0
|
254 |
SetStrValue(temp);
|
sl@0
|
255 |
}
|
sl@0
|
256 |
else
|
sl@0
|
257 |
{
|
sl@0
|
258 |
SetStrValue(NULL);
|
sl@0
|
259 |
}
|
sl@0
|
260 |
return KErrNone;
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
inline void TServerSetting::CopyValueL(TInt aVal)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
User::LeaveIfError(CopyValue(aVal));
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
inline void TServerSetting::CopyValueL(const TReal& aVal)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
User::LeaveIfError(CopyValue(aVal));
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
inline void TServerSetting::CopyValueL(const TDesC8& aVal)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
User::LeaveIfError(CopyValue(aVal));
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
inline TInt TServerSetting::AssignValueTo(TInt& aVal) const
|
sl@0
|
279 |
{
|
sl@0
|
280 |
return IsInt() ? (aVal=iValue.i, KErrNone) : KErrArgument;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
inline TInt TServerSetting::AssignValueTo(TReal& aVal) const
|
sl@0
|
284 |
{
|
sl@0
|
285 |
return IsReal() ?
|
sl@0
|
286 |
(iValue.r ? (aVal=*(iValue.r), KErrNone) : KErrCorrupt)
|
sl@0
|
287 |
: KErrArgument;
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
inline TInt TServerSetting::AssignValueTo(TDes8& aVal) const
|
sl@0
|
291 |
{
|
sl@0
|
292 |
return IsStr() ?
|
sl@0
|
293 |
(iValue.s ? (aVal=iValue.s->Des(), KErrNone) : (aVal=KNullDesC8, KErrNone))
|
sl@0
|
294 |
: KErrArgument;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
inline TInt TServerSetting::AssignValueFrom(TInt aVal)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
return IsInt() ? (iValue.i=aVal, KErrNone) : KErrArgument;
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
inline TInt TServerSetting::AssignValueFrom(const TReal& aVal)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
if(!IsReal())
|
sl@0
|
305 |
{
|
sl@0
|
306 |
return KErrArgument;
|
sl@0
|
307 |
}
|
sl@0
|
308 |
TReal* temp = new TReal(aVal);
|
sl@0
|
309 |
if (!temp)
|
sl@0
|
310 |
return KErrNoMemory;
|
sl@0
|
311 |
delete iValue.r;
|
sl@0
|
312 |
iValue.r = temp;
|
sl@0
|
313 |
temp = NULL;
|
sl@0
|
314 |
return KErrNone;
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
inline TInt TServerSetting::AssignValueFrom(const TDesC8& aVal)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
if(!IsStr())
|
sl@0
|
320 |
return KErrArgument;
|
sl@0
|
321 |
|
sl@0
|
322 |
if(aVal.Length())
|
sl@0
|
323 |
{
|
sl@0
|
324 |
HBufC8* buf = aVal.Alloc();
|
sl@0
|
325 |
if (!buf)
|
sl@0
|
326 |
return KErrNoMemory;
|
sl@0
|
327 |
delete iValue.s;
|
sl@0
|
328 |
iValue.s = buf;
|
sl@0
|
329 |
}
|
sl@0
|
330 |
else
|
sl@0
|
331 |
{
|
sl@0
|
332 |
delete iValue.s;
|
sl@0
|
333 |
iValue.s = NULL;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
return KErrNone;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
inline void TServerSetting::Reset()
|
sl@0
|
339 |
{
|
sl@0
|
340 |
ResetValue();
|
sl@0
|
341 |
iAccessPolicy = NULL;
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
inline void TServerSetting::ResetValue()
|
sl@0
|
345 |
{
|
sl@0
|
346 |
if(IsStr())
|
sl@0
|
347 |
{
|
sl@0
|
348 |
if(iValue.s)
|
sl@0
|
349 |
{
|
sl@0
|
350 |
delete iValue.s;
|
sl@0
|
351 |
}
|
sl@0
|
352 |
}
|
sl@0
|
353 |
if(IsReal())
|
sl@0
|
354 |
{
|
sl@0
|
355 |
ASSERT(iValue.r);
|
sl@0
|
356 |
delete iValue.r;
|
sl@0
|
357 |
}
|
sl@0
|
358 |
iValue.i = 0;
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
inline void TServerSetting::PushL() const
|
sl@0
|
362 |
{
|
sl@0
|
363 |
if(IsStr() && iValue.s)
|
sl@0
|
364 |
{
|
sl@0
|
365 |
CleanupStack::PushL(iValue.s);
|
sl@0
|
366 |
}
|
sl@0
|
367 |
else if(IsReal())
|
sl@0
|
368 |
{
|
sl@0
|
369 |
CleanupStack::PushL(iValue.r);
|
sl@0
|
370 |
}
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|
sl@0
|
373 |
inline void TServerSetting::Pop() const
|
sl@0
|
374 |
{
|
sl@0
|
375 |
if(IsStr() && iValue.s)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
CleanupStack::Pop(iValue.s);
|
sl@0
|
378 |
}
|
sl@0
|
379 |
else if(IsReal())
|
sl@0
|
380 |
{
|
sl@0
|
381 |
CleanupStack::Pop(iValue.r);
|
sl@0
|
382 |
}
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
inline void TServerSetting::PopAndDestroy() const
|
sl@0
|
386 |
{
|
sl@0
|
387 |
if(IsStr() && iValue.s)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
CleanupStack::PopAndDestroy(iValue.s);
|
sl@0
|
390 |
}
|
sl@0
|
391 |
else if(IsReal())
|
sl@0
|
392 |
{
|
sl@0
|
393 |
CleanupStack::PopAndDestroy(iValue.r);
|
sl@0
|
394 |
}
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
inline TInt TServerSetting::operator==(const TServerSetting& aSetting) const
|
sl@0
|
398 |
{
|
sl@0
|
399 |
return aSetting.IsInt() && *this==aSetting.iValue.i ||
|
sl@0
|
400 |
aSetting.IsReal() && aSetting.iValue.r && *this==*(aSetting.iValue.r) ||
|
sl@0
|
401 |
aSetting.IsStr() && !aSetting.iValue.s && !iValue.s ||
|
sl@0
|
402 |
aSetting.IsStr() && aSetting.iValue.s && *this==aSetting.iValue.s->Des();
|
sl@0
|
403 |
}
|
sl@0
|
404 |
|
sl@0
|
405 |
inline TInt TServerSetting::operator==(TInt aVal) const
|
sl@0
|
406 |
{
|
sl@0
|
407 |
return IsInt() && iValue.i==aVal;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
|
sl@0
|
410 |
inline TInt TServerSetting::operator==(const TReal& aVal) const
|
sl@0
|
411 |
{
|
sl@0
|
412 |
return IsReal() && iValue.r && *(iValue.r)==aVal;
|
sl@0
|
413 |
}
|
sl@0
|
414 |
|
sl@0
|
415 |
inline TInt TServerSetting::operator==(const TDesC8& aVal) const
|
sl@0
|
416 |
{
|
sl@0
|
417 |
return IsStr() && iValue.s && iValue.s->Des()==aVal;
|
sl@0
|
418 |
}
|
sl@0
|
419 |
|
sl@0
|
420 |
inline TSettingsAccessPolicy* TServerSetting::AccessPolicy() const
|
sl@0
|
421 |
{
|
sl@0
|
422 |
return iAccessPolicy;
|
sl@0
|
423 |
}
|
sl@0
|
424 |
|
sl@0
|
425 |
inline void TServerSetting::SetAccessPolicy(TSettingsAccessPolicy* aPolicy)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
iAccessPolicy = aPolicy;
|
sl@0
|
428 |
}
|
sl@0
|
429 |
|
sl@0
|
430 |
//inline const RArray<TSecurityPolicy>& TServerSetting::GetReadAccessPolicy()
|
sl@0
|
431 |
inline const TSecurityPolicy* TServerSetting::GetReadAccessPolicy() const
|
sl@0
|
432 |
{
|
sl@0
|
433 |
return iAccessPolicy ? iAccessPolicy->GetReadAccessPolicy() : NULL;
|
sl@0
|
434 |
}
|
sl@0
|
435 |
|
sl@0
|
436 |
//inline const RArray<TSecurityPolicy>& TServerSetting::GetWriteAccessPolicy()
|
sl@0
|
437 |
inline const TSecurityPolicy* TServerSetting::GetWriteAccessPolicy() const
|
sl@0
|
438 |
{
|
sl@0
|
439 |
return iAccessPolicy ? iAccessPolicy->GetWriteAccessPolicy() : NULL;
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
inline TBool TServerSetting::HasAccessPolicy() const
|
sl@0
|
443 |
{
|
sl@0
|
444 |
return NULL != iAccessPolicy;
|
sl@0
|
445 |
}
|
sl@0
|
446 |
|
sl@0
|
447 |
inline void TServerSetting::ExternalizeMetaL(RWriteStream& aStream) const
|
sl@0
|
448 |
{
|
sl@0
|
449 |
//Historically, CRE file stores type and meta information seperately for
|
sl@0
|
450 |
//TServerSetting. To save memory, this has been changed for the
|
sl@0
|
451 |
//in-memory representation but we must store and retrieve the meta in the
|
sl@0
|
452 |
//same way for compatibility with existing backup and cre files.
|
sl@0
|
453 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
454 |
aStream << (Meta() | (iMeta & KMetaIndividual)) ;
|
sl@0
|
455 |
#else
|
sl@0
|
456 |
aStream << Meta();
|
sl@0
|
457 |
#endif
|
sl@0
|
458 |
TUint32 type = Type();
|
sl@0
|
459 |
TUint8 temp = static_cast<TUint8>(type >> 28) ;
|
sl@0
|
460 |
aStream << temp ;
|
sl@0
|
461 |
}
|
sl@0
|
462 |
|
sl@0
|
463 |
inline void TServerSetting::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
464 |
{
|
sl@0
|
465 |
aStream << iKey ;
|
sl@0
|
466 |
ExternalizeMetaL(aStream);
|
sl@0
|
467 |
switch (Type())
|
sl@0
|
468 |
{
|
sl@0
|
469 |
case EInt:
|
sl@0
|
470 |
{
|
sl@0
|
471 |
TInt32 integerValue = iValue.i ;
|
sl@0
|
472 |
aStream << integerValue ;
|
sl@0
|
473 |
break ;
|
sl@0
|
474 |
}
|
sl@0
|
475 |
case EReal :
|
sl@0
|
476 |
ASSERT(iValue.r);
|
sl@0
|
477 |
aStream << *(iValue.r) ;
|
sl@0
|
478 |
break ;
|
sl@0
|
479 |
|
sl@0
|
480 |
case EString :
|
sl@0
|
481 |
if(iValue.s)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
aStream << *(iValue.s) ;
|
sl@0
|
484 |
}
|
sl@0
|
485 |
else
|
sl@0
|
486 |
{
|
sl@0
|
487 |
aStream << KNullDesC8 ;
|
sl@0
|
488 |
}
|
sl@0
|
489 |
break ;
|
sl@0
|
490 |
|
sl@0
|
491 |
case EDeleted :
|
sl@0
|
492 |
// Deleted settings should never be in a settings list being made
|
sl@0
|
493 |
// persistent. Hence, fail assert if attempting to externalize them:
|
sl@0
|
494 |
ASSERT(EFalse);
|
sl@0
|
495 |
break ;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
}
|
sl@0
|
498 |
|
sl@0
|
499 |
|
sl@0
|
500 |
inline void TServerSetting::InternalizeMetaL(RReadStream& aStream)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
//Historically, CRE file stores type and meta information seperately for
|
sl@0
|
503 |
//TServerSetting. To save memory, this has been changed for the
|
sl@0
|
504 |
//in-memory representation but we must store and retrieve the meta in the
|
sl@0
|
505 |
//same way for compatibility with existing backup and cre files.
|
sl@0
|
506 |
TUint32 meta;
|
sl@0
|
507 |
aStream >> meta;
|
sl@0
|
508 |
SetMeta(meta) ;
|
sl@0
|
509 |
|
sl@0
|
510 |
TUint8 temp ;
|
sl@0
|
511 |
aStream >> temp ;
|
sl@0
|
512 |
TUint32 type = (static_cast<TUint32>(temp)) << 28;
|
sl@0
|
513 |
SetType(type);
|
sl@0
|
514 |
}
|
sl@0
|
515 |
|
sl@0
|
516 |
inline void TServerSetting::InternalizeL(RReadStream& aStream)
|
sl@0
|
517 |
{
|
sl@0
|
518 |
aStream >> iKey ;
|
sl@0
|
519 |
InternalizeMetaL(aStream);
|
sl@0
|
520 |
switch (Type())
|
sl@0
|
521 |
{
|
sl@0
|
522 |
case EInt:
|
sl@0
|
523 |
{
|
sl@0
|
524 |
TInt32 integerValue;
|
sl@0
|
525 |
aStream >> integerValue ;
|
sl@0
|
526 |
iValue.i = integerValue ;
|
sl@0
|
527 |
break ;
|
sl@0
|
528 |
}
|
sl@0
|
529 |
case EReal:
|
sl@0
|
530 |
iValue.r = new(ELeave)TReal;
|
sl@0
|
531 |
aStream >> *(iValue.r);
|
sl@0
|
532 |
break ;
|
sl@0
|
533 |
|
sl@0
|
534 |
case EString :
|
sl@0
|
535 |
{
|
sl@0
|
536 |
HBufC8* string = HBufC8::NewL (aStream, KMaxBinaryLength) ;
|
sl@0
|
537 |
if(string->Length())
|
sl@0
|
538 |
{
|
sl@0
|
539 |
iValue.s = string;
|
sl@0
|
540 |
}
|
sl@0
|
541 |
else
|
sl@0
|
542 |
{
|
sl@0
|
543 |
delete string;
|
sl@0
|
544 |
iValue.s = NULL;
|
sl@0
|
545 |
}
|
sl@0
|
546 |
break ;
|
sl@0
|
547 |
}
|
sl@0
|
548 |
|
sl@0
|
549 |
case EDeleted :
|
sl@0
|
550 |
// Deleted settings should never be in a persistent settings list.
|
sl@0
|
551 |
// Hence, fail assert if attempting to internalize them:
|
sl@0
|
552 |
ASSERT(EFalse);
|
sl@0
|
553 |
break ;
|
sl@0
|
554 |
}
|
sl@0
|
555 |
}
|
sl@0
|
556 |
|
sl@0
|
557 |
inline TBool TServerSetting::IsType(const TInt&) const
|
sl@0
|
558 |
{
|
sl@0
|
559 |
return Type() == EInt;
|
sl@0
|
560 |
}
|
sl@0
|
561 |
|
sl@0
|
562 |
inline TBool TServerSetting::IsType(const TReal&) const
|
sl@0
|
563 |
{
|
sl@0
|
564 |
return Type() == EReal;
|
sl@0
|
565 |
}
|
sl@0
|
566 |
|
sl@0
|
567 |
inline TBool TServerSetting::IsType(const TDesC8&) const
|
sl@0
|
568 |
{
|
sl@0
|
569 |
return Type() == EString;
|
sl@0
|
570 |
}
|
sl@0
|
571 |
|
sl@0
|
572 |
inline TBool TServerSetting::IsType(const TDesC16&) const
|
sl@0
|
573 |
{
|
sl@0
|
574 |
return Type() == EString;
|
sl@0
|
575 |
}
|
sl@0
|
576 |
|
sl@0
|
577 |
inline TBool TServerSetting::IsInt() const
|
sl@0
|
578 |
{
|
sl@0
|
579 |
return (iMeta & KMetaType) == EInt;
|
sl@0
|
580 |
}
|
sl@0
|
581 |
|
sl@0
|
582 |
inline TBool TServerSetting::IsReal() const
|
sl@0
|
583 |
{
|
sl@0
|
584 |
return (iMeta & KMetaType) == EReal;
|
sl@0
|
585 |
}
|
sl@0
|
586 |
|
sl@0
|
587 |
inline TBool TServerSetting::IsStr() const
|
sl@0
|
588 |
{
|
sl@0
|
589 |
return (iMeta & KMetaType) == EString;
|
sl@0
|
590 |
}
|
sl@0
|
591 |
|
sl@0
|
592 |
inline TBool TServerSetting::IsDeleted() const
|
sl@0
|
593 |
{
|
sl@0
|
594 |
return (iMeta & KMetaType) == EDeleted;
|
sl@0
|
595 |
}
|
sl@0
|
596 |
|
sl@0
|
597 |
inline TSettingsAccessPolicy::TSettingsAccessPolicy(TSecurityPolicy& aReadPolicy,
|
sl@0
|
598 |
TSecurityPolicy& aWritePolicy,
|
sl@0
|
599 |
TUint32 aLowKey, TUint32 aHighKey,
|
sl@0
|
600 |
TUint32 aKeyMask)
|
sl@0
|
601 |
{
|
sl@0
|
602 |
iLowKey = aLowKey;
|
sl@0
|
603 |
iHighKey = aHighKey;
|
sl@0
|
604 |
iKeyMask = aKeyMask;
|
sl@0
|
605 |
iReadAccessPolicy.Set(aReadPolicy.Package());
|
sl@0
|
606 |
iWriteAccessPolicy.Set(aWritePolicy.Package());
|
sl@0
|
607 |
}
|
sl@0
|
608 |
|
sl@0
|
609 |
inline TSettingsAccessPolicy::TSettingsAccessPolicy(TSecurityPolicy& aReadPolicy,
|
sl@0
|
610 |
TSecurityPolicy& aWritePolicy,
|
sl@0
|
611 |
TUint32 aKey)
|
sl@0
|
612 |
{
|
sl@0
|
613 |
iLowKey = aKey;
|
sl@0
|
614 |
iHighKey = 0;
|
sl@0
|
615 |
iKeyMask = 0;
|
sl@0
|
616 |
iReadAccessPolicy.Set(aReadPolicy.Package());
|
sl@0
|
617 |
iWriteAccessPolicy.Set(aWritePolicy.Package());
|
sl@0
|
618 |
}
|
sl@0
|
619 |
|
sl@0
|
620 |
inline TSettingsAccessPolicy::TSettingsAccessPolicy(TUint32 key)
|
sl@0
|
621 |
{
|
sl@0
|
622 |
iLowKey = key;
|
sl@0
|
623 |
iHighKey = 0;
|
sl@0
|
624 |
iKeyMask = 0;
|
sl@0
|
625 |
}
|
sl@0
|
626 |
|
sl@0
|
627 |
inline TSettingsAccessPolicy::TSettingsAccessPolicy()
|
sl@0
|
628 |
{
|
sl@0
|
629 |
iLowKey = 0;
|
sl@0
|
630 |
iHighKey = 0;
|
sl@0
|
631 |
iKeyMask = 0;
|
sl@0
|
632 |
}
|
sl@0
|
633 |
|
sl@0
|
634 |
inline TBool TSettingsAccessPolicy::IsInRange(TUint32 aKey) const
|
sl@0
|
635 |
{
|
sl@0
|
636 |
if((iLowKey<=aKey)&&(aKey<=iHighKey))
|
sl@0
|
637 |
return ETrue;
|
sl@0
|
638 |
else if((0 != iKeyMask)&&((iKeyMask&aKey)==iLowKey))
|
sl@0
|
639 |
return ETrue;
|
sl@0
|
640 |
|
sl@0
|
641 |
return EFalse;
|
sl@0
|
642 |
}
|
sl@0
|
643 |
|
sl@0
|
644 |
inline void TSettingsAccessPolicy::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
645 |
{
|
sl@0
|
646 |
aStream << iLowKey ;
|
sl@0
|
647 |
aStream << iHighKey ;
|
sl@0
|
648 |
aStream << iKeyMask ;
|
sl@0
|
649 |
|
sl@0
|
650 |
// Externalize TSecurityPolicy objects as descriptors
|
sl@0
|
651 |
aStream << (iReadAccessPolicy.Package()) ;
|
sl@0
|
652 |
aStream << (iWriteAccessPolicy.Package()) ;
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
inline void TSettingsAccessPolicy::InternalizeL(RReadStream& aStream)
|
sl@0
|
656 |
{
|
sl@0
|
657 |
aStream >> iLowKey ;
|
sl@0
|
658 |
aStream >> iHighKey ;
|
sl@0
|
659 |
aStream >> iKeyMask ;
|
sl@0
|
660 |
|
sl@0
|
661 |
// Internalize TSecurityPolicy objects as descriptors and then use them
|
sl@0
|
662 |
// to set the actual TSecurityPolicy member data.
|
sl@0
|
663 |
HBufC8* securityPolicyPackage ;
|
sl@0
|
664 |
securityPolicyPackage = HBufC8::NewLC(aStream, 10000);
|
sl@0
|
665 |
iReadAccessPolicy.Set(securityPolicyPackage->Des()) ;
|
sl@0
|
666 |
CleanupStack::PopAndDestroy(securityPolicyPackage) ;
|
sl@0
|
667 |
|
sl@0
|
668 |
securityPolicyPackage = HBufC8::NewLC(aStream, 10000);
|
sl@0
|
669 |
iWriteAccessPolicy.Set(securityPolicyPackage->Des()) ;
|
sl@0
|
670 |
CleanupStack::PopAndDestroy(securityPolicyPackage) ;
|
sl@0
|
671 |
|
sl@0
|
672 |
}
|
sl@0
|
673 |
|
sl@0
|
674 |
inline TUint32 TSettingsAccessPolicy::LowKey() const
|
sl@0
|
675 |
{
|
sl@0
|
676 |
return iLowKey;
|
sl@0
|
677 |
}
|
sl@0
|
678 |
inline TUint32 TSettingsAccessPolicy::HighKey() const
|
sl@0
|
679 |
{
|
sl@0
|
680 |
return iHighKey;
|
sl@0
|
681 |
}
|
sl@0
|
682 |
inline TUint32 TSettingsAccessPolicy::KeyMask() const
|
sl@0
|
683 |
{
|
sl@0
|
684 |
return iKeyMask;
|
sl@0
|
685 |
}
|
sl@0
|
686 |
|
sl@0
|
687 |
/**
|
sl@0
|
688 |
@internalTechnology
|
sl@0
|
689 |
It is responsility of client to check the key,
|
sl@0
|
690 |
this simply returns the TSecurityPolicy - it is set to EAlwaysFail if uninitialised
|
sl@0
|
691 |
*/
|
sl@0
|
692 |
inline const TSecurityPolicy* TSettingsAccessPolicy::GetReadAccessPolicy() const
|
sl@0
|
693 |
{
|
sl@0
|
694 |
return &iReadAccessPolicy;
|
sl@0
|
695 |
}
|
sl@0
|
696 |
|
sl@0
|
697 |
|
sl@0
|
698 |
/**
|
sl@0
|
699 |
@internalTechnology
|
sl@0
|
700 |
It is responsility of client to check the key,
|
sl@0
|
701 |
this simply returns the TSecurityPolicy - it is set to EAlwaysFail if uninitialised
|
sl@0
|
702 |
*/
|
sl@0
|
703 |
inline const TSecurityPolicy* TSettingsAccessPolicy::GetWriteAccessPolicy() const
|
sl@0
|
704 |
{
|
sl@0
|
705 |
return &iWriteAccessPolicy;
|
sl@0
|
706 |
}
|
sl@0
|
707 |
|
sl@0
|
708 |
inline TSettingsDefaultMeta::TSettingsDefaultMeta(TUint32 aValue, TUint32 aLowKey,
|
sl@0
|
709 |
TUint32 aHighKey, TUint32 aKeyMask)
|
sl@0
|
710 |
{
|
sl@0
|
711 |
iLowKey = aLowKey;
|
sl@0
|
712 |
iHighKey = aHighKey;
|
sl@0
|
713 |
iKeyMask = aKeyMask;
|
sl@0
|
714 |
iDefaultMetaData = aValue;
|
sl@0
|
715 |
}
|
sl@0
|
716 |
|
sl@0
|
717 |
inline TSettingsDefaultMeta::TSettingsDefaultMeta()
|
sl@0
|
718 |
{
|
sl@0
|
719 |
iLowKey = 0;
|
sl@0
|
720 |
iHighKey = 0;
|
sl@0
|
721 |
iKeyMask = 0;
|
sl@0
|
722 |
iDefaultMetaData = 0;
|
sl@0
|
723 |
}
|
sl@0
|
724 |
|
sl@0
|
725 |
inline TUint32 TSettingsDefaultMeta::LowKey() const
|
sl@0
|
726 |
{
|
sl@0
|
727 |
return iLowKey;
|
sl@0
|
728 |
}
|
sl@0
|
729 |
|
sl@0
|
730 |
inline TUint32 TSettingsDefaultMeta::HighKey() const
|
sl@0
|
731 |
{
|
sl@0
|
732 |
return iHighKey;
|
sl@0
|
733 |
}
|
sl@0
|
734 |
|
sl@0
|
735 |
inline TUint32 TSettingsDefaultMeta::KeyMask() const
|
sl@0
|
736 |
{
|
sl@0
|
737 |
return iKeyMask;
|
sl@0
|
738 |
}
|
sl@0
|
739 |
|
sl@0
|
740 |
inline TBool TSettingsDefaultMeta::IsInRange(TUint32 aKey) const
|
sl@0
|
741 |
{
|
sl@0
|
742 |
if((iLowKey<=aKey)&&(aKey<=iHighKey))
|
sl@0
|
743 |
return ETrue;
|
sl@0
|
744 |
else if((0 != iKeyMask)&&((iKeyMask&aKey)==iLowKey))
|
sl@0
|
745 |
return ETrue;
|
sl@0
|
746 |
|
sl@0
|
747 |
return EFalse;
|
sl@0
|
748 |
}
|
sl@0
|
749 |
|
sl@0
|
750 |
inline void TSettingsDefaultMeta::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
751 |
{
|
sl@0
|
752 |
aStream << iLowKey ;
|
sl@0
|
753 |
aStream << iHighKey ;
|
sl@0
|
754 |
aStream << iKeyMask ;
|
sl@0
|
755 |
aStream << iDefaultMetaData ;
|
sl@0
|
756 |
}
|
sl@0
|
757 |
|
sl@0
|
758 |
inline void TSettingsDefaultMeta::InternalizeL(RReadStream& aStream)
|
sl@0
|
759 |
{
|
sl@0
|
760 |
aStream >> iLowKey ;
|
sl@0
|
761 |
aStream >> iHighKey ;
|
sl@0
|
762 |
aStream >> iKeyMask ;
|
sl@0
|
763 |
aStream >> iDefaultMetaData;
|
sl@0
|
764 |
}
|
sl@0
|
765 |
|
sl@0
|
766 |
inline TSettingSingleMeta::TSettingSingleMeta(TUint32 aKey, TUint32 aMeta) : iKey(aKey), iMeta(aMeta)
|
sl@0
|
767 |
{
|
sl@0
|
768 |
}
|
sl@0
|
769 |
|
sl@0
|
770 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
771 |
inline void TServerSetting::SetIndividualMeta(TBool aIndividualSettingMeta)
|
sl@0
|
772 |
{
|
sl@0
|
773 |
if (aIndividualSettingMeta)
|
sl@0
|
774 |
iMeta|= KMetaIndividual;
|
sl@0
|
775 |
else
|
sl@0
|
776 |
iMeta&=~KMetaIndividual;
|
sl@0
|
777 |
}
|
sl@0
|
778 |
|
sl@0
|
779 |
//NEW: Copy the value only from a source, already validate the type
|
sl@0
|
780 |
inline TInt TServerSetting::CopyTypeValue(const TServerSetting& source)
|
sl@0
|
781 |
{
|
sl@0
|
782 |
|
sl@0
|
783 |
if (source.IsStr())
|
sl@0
|
784 |
{
|
sl@0
|
785 |
const HBufC8* sourceBuf = source.GetStrValue();
|
sl@0
|
786 |
HBufC8* buf = sourceBuf ? sourceBuf->Alloc() : NULL;
|
sl@0
|
787 |
if (sourceBuf && !buf)
|
sl@0
|
788 |
{
|
sl@0
|
789 |
return KErrNoMemory;
|
sl@0
|
790 |
}
|
sl@0
|
791 |
ResetValue();
|
sl@0
|
792 |
SetType(EString);
|
sl@0
|
793 |
iValue.s = buf;
|
sl@0
|
794 |
}
|
sl@0
|
795 |
else if (source.IsReal())
|
sl@0
|
796 |
{
|
sl@0
|
797 |
if(!source.iValue.r)
|
sl@0
|
798 |
{
|
sl@0
|
799 |
return KErrCorrupt;
|
sl@0
|
800 |
}
|
sl@0
|
801 |
|
sl@0
|
802 |
TReal* temp = new TReal(source.GetRealValue());
|
sl@0
|
803 |
if (temp == NULL)
|
sl@0
|
804 |
{
|
sl@0
|
805 |
return KErrNoMemory;
|
sl@0
|
806 |
}
|
sl@0
|
807 |
ResetValue();
|
sl@0
|
808 |
SetType(EReal);
|
sl@0
|
809 |
iValue.r = temp;
|
sl@0
|
810 |
}
|
sl@0
|
811 |
else
|
sl@0
|
812 |
{
|
sl@0
|
813 |
SetType(source.Type());
|
sl@0
|
814 |
if (source.IsInt())
|
sl@0
|
815 |
{
|
sl@0
|
816 |
iValue.i = source.GetIntValue();
|
sl@0
|
817 |
}
|
sl@0
|
818 |
}
|
sl@0
|
819 |
|
sl@0
|
820 |
return KErrNone;
|
sl@0
|
821 |
}
|
sl@0
|
822 |
#endif
|