Update contrib.
1 // Copyright (c) 2002-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\us_property.cpp
21 Defines a property with the specified category ID. This method should only be
22 used to specify a category different from the creating process's secure ID in
23 exceptional circumstances. In most cases the overload:
25 RProperty::Define(TUint aKey, TInt aAttr, const TSecurityPolicy& aReadPolicy, const TSecurityPolicy& aWritePolicy, TInt aPreallocate)
27 should be used. For details see the document located at:
29 Symbian OS guide » Base » Using User Library (E32) » Publish and Subscribe » Security issues
31 Defines the attributes and access control for a property. This can only be done
32 once for each property. Subsequent attempts to define the same property will return
35 Only processes with the write-system-data capability are allowed to define
36 properties either in the system category (KUidSystemCategory) or with
37 aCategory < KUidSecurityThresholdCategoryValue. Any attempt to define
38 a property with these categories by a process with insufficient capabilities
39 will fail with a KErrPermissionDenied error.
41 Following the property's definition, it will have a default value, 0 for integer
42 properties and zero-length data for byte-array and text properties.
43 Pending subscriptions for this property will not be completed until a new
46 @param aCategory The UID that identifies the property category.
47 This must either be the current process's Secure ID, or
48 KUidSystemCategoryValue.
49 @param aKey The property sub-key, i.e. the key that identifies the
50 specific property within the category.
51 @param aAttr This describes the property type, a TType value;
52 persistence, as defined by the KPersistent bit, may
54 @param aReadPolicy A security policy defining the security attributes a
55 process must have in order to read this value.
56 @param aWritePolicy A security policy defining the security attributes a
57 process must have in order to write this value.
58 @param aPreallocate The number of bytes to be pre-allocated for variable
59 sized properties. Pre-allocating enough space ensures that
60 a variable sized property can be set in 'real-time',
61 (i.e. the time to set the property is bounded).
63 @return KErrNone, if successful;
64 KErrArgument, if the wrong type or attribute was specified;
65 KErrArgument, if aType is TInt and aPreallocate is not 0;
66 KErrTooBig, if aPreallocate is greater than KMaxPropertySize;
67 KErrPermissionDenied, if an attempt is made to define a property in
68 the system category by a process with insufficient capabilities, or
69 the category secified wasn't the same as the current process's Secure ID.
71 @capability WriteDeviceData if aCategory==KUidSystemCategoryValue.
72 @capability WriteDeviceData if aCategory not equal to the current process's
73 Secure ID and aCategory<KUidSecurityThresholdCategoryValue.
76 @see KUidSecurityThresholdCategoryValue
81 EXPORT_C TInt RProperty::Define(TUid aCategory, TUint aKey, TInt aAttr, const TSecurityPolicy& aReadPolicy, const TSecurityPolicy& aWritePolicy, TInt aPreallocate)
85 if(aPreallocate > KMaxLargePropertySize)
89 info.iType = (RProperty::TType)(aAttr & RProperty::ETypeMask);
90 info.iAttr = (aAttr & ~RProperty::ETypeMask);
91 info.iSize = (TUint16) aPreallocate;
92 info.iReadPolicy = aReadPolicy;
93 info.iWritePolicy = aWritePolicy;
94 return(Exec::PropertyDefine(TUint(aCategory.iUid), aKey, &info));
101 Defines the attributes and access control for a property. This can only be done
102 once for each property. Subsequent attempts to define the same property will return
105 The category ID for the property will be the same as the current processes Secure ID.
107 Following the property's definition, it will have a default value, 0 for integer
108 properties and zero-length data for byte-array and text properties.
109 Pending subscriptions for this property will not be completed until a new
112 @param aKey The property sub-key, i.e. the key that identifies the
113 specific property within the category.
114 @param aAttr This describes the property type, a TType value;
115 persistence, as defined by the KPersistent bit, may
117 @param aReadPolicy A security policy defining the security attributes a
118 process must have in order to read this value.
119 @param aWritePolicy A security policy defining the security attributes a
120 process must have in order to write this value.
121 @param aPreallocate The number of bytes to be pre-allocated for variable
122 sized properties. Pre-allocating enough space ensures that
123 a variable sized property can be set in 'real-time',
124 (i.e. the time to set the property is bounded).
126 @return KErrNone, if successful;
127 KErrArgument, if the wrong type or attribute was specified;
128 KErrArgument, if aType is TInt and aPreallocate is not 0;
129 KErrTooBig, if aPreallocate is greater than KMaxPropertySize;
134 EXPORT_C TInt RProperty::Define(TUint aKey, TInt aAttr, const TSecurityPolicy& aReadPolicy, const TSecurityPolicy& aWritePolicy, TInt aPreallocate)
136 TUid category = {-1};
137 return Define(category, aKey, aAttr, aReadPolicy, aWritePolicy, aPreallocate);
143 NOTE - The use of this method is deprecated.
145 Defines a property with the specified category ID. This method should only be
146 used to specify a category different from the creating process's secure ID in
147 exceptional circumstances. In most cases the overload:
149 RProperty::Define(TUint aKey, TInt aAttr, const TSecurityPolicy& aReadPolicy, const TSecurityPolicy& aWritePolicy, TInt aPreallocate)
151 should be used. For details see the document located at:
153 Symbian OS guide » Base » Using User Library (E32) » Publish and Subscribe » Security issues
155 Defines the attributes and access control for a property. This can only be done
156 once for each property. Subsequent attempts to define the same property will
157 return KErrAlreadyExists.
159 Only processes with the write-system-data capability are allowed to define
160 properties either in the system category (KUidSystemCategory) or with
161 aCategory < KUidSecurityThresholdCategoryValue. Any attempt to define
162 a property with these categories by a process with insufficient capabilities
163 will fail with a KErrPermissionDenied error.
165 Following the property's definition, it will have a default value, 0 for integer
166 properties and zero-length data for byte-array and text properties.
167 Pending subscriptions for this property will not be completed until a new
170 @param aCategory The UID that identifies the property category.
171 @param aKey The property sub-key, i.e. the key that identifies the
172 specific property within the category.
173 @param aAttr This describes the property type, a TType value;
174 persistence, as defined by the KPersistent bit, may
176 @param aPreallocate The number of bytes to be pre-allocated for variable
177 sized properties. Pre-allocating enough space ensures that
178 a variable sized property can be set in 'real-time',
179 (i.e. the time to set the property is bounded).
181 @return KErrNone, if successful;
182 KErrArgument, if the wrong type or attribute was specified;
183 KErrArgument, if aType is TInt and aPreallocate is not 0;
184 KErrTooBig, if aPreallocate is greater than KMaxPropertySize;
185 KErrPermissionDenied, if an attempt is made to define a property in
186 the system category by a process with insufficient capabilities.
188 @capability WriteDeviceData if aCategory==KUidSystemCategoryValue.
189 @capability WriteDeviceData if aCategory not equal to the current process's
190 Secure ID and aCategory<KUidSecurityThresholdCategoryValue.
192 @see KUidSecurityThresholdCategoryValue
194 @deprecated Use RProperty::Define(TUint aKey, TInt aAttr, const TSecurityPolicy &aReadPolicy, const TSecurityPolicy &aWritePolicy, TInt aPreallocated=0)
197 EXPORT_C TInt RProperty::Define(TUid aCategory, TUint aKey, TInt aAttr, TInt aPreallocate)
200 info.iType = (RProperty::TType)(aAttr & RProperty::ETypeMask);
201 info.iAttr = (aAttr & ~RProperty::ETypeMask);
202 info.iSize = (TUint16) aPreallocate;
203 info.iReadPolicy = TSecurityPolicy(TSecurityPolicy::EAlwaysPass);
204 info.iWritePolicy = TSecurityPolicy(TSecurityPolicy::EAlwaysPass);
205 return(Exec::PropertyDefine(TUint(aCategory.iUid), aKey, &info));
212 This can only be called by the property owner, as defined by
213 the process Security ID; any attempt by another process to delete
214 the property will fail.
216 Any pending subscriptions for this property will be completed
218 Any new request will not complete until the property is defined
221 @param aCategory The UID that identifies the property category.
222 @param aKey The property sub-key, i.e. the key that identifies the
223 specific property within the category.
225 @return KErrNone, if successful;
226 KErrPermissionDenied, if a process that is not the owner of
227 the property attempts to delete it.
228 KErrNotFound, if the property has not been defined.
230 EXPORT_C TInt RProperty::Delete(TUid aCategory, TUint aKey)
232 return(Exec::PropertyDelete(TUint(aCategory.iUid), aKey));
240 The category ID for the property will be the same as the current processes Secure ID.
242 Any pending subscriptions for this property will be completed
244 Any new request will not complete until the property is defined
247 @param aKey The property sub-key, i.e. the key that identifies the
248 specific property within the category.
250 @return KErrNone, if successful;
251 KErrNotFound, if the property has not been defined.
253 EXPORT_C TInt RProperty::Delete(TUint aKey)
255 return(Exec::PropertyDelete(KMaxTUint, aKey));
260 Gets an integer property.
262 The function gets the integer value of the specified property.
264 The Platform Security attributes of the current process are checked against
265 the Read Policy which was specified when the property was defined.
266 If this check fails the action taken is determined by the system wide Platform Security
267 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
268 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
271 @param aCategory The UID that identifies the property category.
272 @param aKey The property sub-key, i.e. the key that identifies the
273 specific property within the category.
274 @param aValue A reference to the variable where the property value will
277 @return KErrNone, if successful;
278 KErrPermissionDenied, if the caller process doesn't pass the Read Policy;
279 KErrNotFound, if the property has not been defined;
280 KErrArgument, if the property is not of integral type.
282 EXPORT_C TInt RProperty::Get(TUid aCategory, TUint aKey, TInt& aValue)
284 return(Exec::PropertyFindGetI(TUint(aCategory.iUid), aKey, &aValue));
291 Gets a binary property.
293 The function gets the byte-array (binary) value of the specified property.
295 The Platform Security attributes of the current process are checked against
296 the Read Policy which was specified when the property was defined.
297 If this check fails the action taken is determined by the system wide Platform Security
298 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
299 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
302 @param aCategory The UID that identifies the property category.
303 @param aKey The property sub-key, i.e. the key that identifies the
304 specific property within the category.
305 @param aDes A reference to the buffer descriptor where the property value
308 @return KErrNone if successful;
309 KErrPermissionDenied, if the caller process doesn't pass the Read Policy;
310 KErrNotFound, if the property has not been defined;
311 KErrArgument, if the property is not a byte-array (binary) type;
312 KErrOverflow, if the supplied buffer is too small to contain the full
313 property value, and note that the buffer aDes contains the
314 truncated property value.
316 EXPORT_C TInt RProperty::Get(TUid aCategory, TUint aKey, TDes8& aDes)
318 TInt size = aDes.MaxSize();
319 TInt r = Exec::PropertyFindGetB(TUint(aCategory.iUid), aKey, (TUint8*) aDes.Ptr(), size);
322 if (r == KErrOverflow)
324 aDes.SetLength(size);
336 Gets a text property.
338 The function gets the text value of the specified property.
340 The Platform Security attributes of the current process are checked against
341 the Read Policy which was specified when the property was defined.
342 If this check fails the action taken is determined by the system wide Platform Security
343 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
344 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
347 @param aCategory The UID that identifies the property category.
348 @param aKey The property sub-key, i.e. the key that identifies the
349 specific property within the category.
350 @param aDes A reference to the buffer descriptor where the property value
353 @return KErrNone, if successful;
354 KErrPermissionDenied, if the caller process doesn't pass the Read Policy;
355 KErrNotFound, if the property has not been defined;
356 KErrArgument, if the property is not a text type;
357 KErrOverflow, if the supplied buffer is too small to contain the full
358 property value, and note that the buffer aDes contains the
359 truncated property value.
361 EXPORT_C TInt RProperty::Get(TUid aCategory, TUint aKey, TDes16& aDes)
363 TInt size = aDes.MaxSize();
364 TInt r = Exec::PropertyFindGetB(TUint(aCategory.iUid), aKey, (TUint8*) aDes.Ptr(), size);
367 if (r == KErrOverflow)
369 aDes.SetLength(size >> 1);
373 aDes.SetLength(r >> 1);
381 Sets an integer property.
383 The function publishes a new integral property value.
385 Any pending subscriptions for this property will be completed.
387 The Platform Security attributes of the current process are checked against
388 the Write Policy which was specified when the property was defined.
389 If this check fails the action taken is determined by the system wide Platform Security
390 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
391 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
394 @param aCategory The UID that identifies the property category.
395 @param aKey The property sub-key, i.e. the key that identifies the
396 specific property within the category.
397 @param aValue The new property value.
399 @return KErrNone, if successful;
400 KErrPermissionDenied, if the caller process doesn't pass the Write Policy;
401 KErrNotFound, if the property has not been defined;
402 KErrArgument, if the property is not of integral type.
404 EXPORT_C TInt RProperty::Set(TUid aCategory, TUint aKey, TInt aValue)
406 return(Exec::PropertyFindSetI(TUint(aCategory.iUid), aKey, aValue));
413 Sets a binary property.
415 The function Publishes a new byte-array (binary) value for
416 the specified property.
418 Any pending subscriptions for this property will be completed.
420 Note that if the new property value requires more storage space than is
421 currently allocated, then memory allocation will be required.
422 This invalidates any real-time guarantee, i.e. the guarantee that the operation
423 will complete within a bounded time.
425 The Platform Security attributes of the current process are checked against
426 the Write Policy which was specified when the property was defined.
427 If this check fails the action taken is determined by the system wide Platform Security
428 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
429 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
432 @param aCategory The UID that identifies the property category.
433 @param aKey The property sub-key, i.e. the key that identifies the
434 specific property within the category.
435 @param aDes A reference to the descriptor containing the
438 @return KErrNone, if successful;
439 KErrPermissionDenied, if the caller process doesn't pass the Write Policy;
440 KErrNotFound, if the property has not been defined;
441 KErrArgument, if the property is not a byte-array (binary) type;
442 KErrNoMemory, if memory allocation is required, and there is
443 insufficient available.
445 EXPORT_C TInt RProperty::Set(TUid aCategory, TUint aKey, const TDesC8& aDes)
447 return(Exec::PropertyFindSetB(TUint(aCategory.iUid), aKey, (TUint8*) aDes.Ptr(), aDes.Size()));
454 Sets a text property.
456 The function publishes a new text value for the specified property.
458 Any pending subscriptions for this property will be completed.
460 Note that if the new property value requires more storage space than is
461 currently allocated, then memory allocation will be required.
462 This invalidates any real-time guarantee, i.e. the guarantee that the operation
463 will complete within a bounded time.
465 The Platform Security attributes of the current process are checked against
466 the Write Policy which was specified when the property was defined.
467 If this check fails the action taken is determined by the system wide Platform Security
468 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
469 If PlatSecEnforcement is OFF, then this function will return KErrNone even though the
472 @param aCategory The UID that identifies the property category.
473 @param aKey The property sub-key, i.e. the key that identifies the
474 specific property within the category.
475 @param aDes A reference to the descriptor containing the
478 @return KErrNone, if successful;
479 KErrPermissionDenied, if the caller process doesn't pass the Write Policy;
480 KErrNotFound, if the property has not been defined;
481 KErrArgument, if the property is not a text type;
482 KErrNoMemory, if memory allocation is required, and there is
483 insufficient available;
484 KErrTooBig, if the property is larger than KMaxPropertySize;
486 EXPORT_C TInt RProperty::Set(TUid aCategory, TUint aKey, const TDesC16& aDes)
488 return(Exec::PropertyFindSetB(TUint(aCategory.iUid), aKey, (TUint8*) aDes.Ptr(), aDes.Size()));
495 Attaches to the specified property.
497 The function creates a handle (this object) to the specified property.
498 This allows the caller to subscribe for notification of changes to this
499 property, and to faster and real-time property access methods.
501 If the specified property does not exist, then this operation will
502 still succeed. However, memory allocation will be required.
503 Note that this invalidates any real-time guarantee, i.e. the guarantee that
504 the operation completes within a bounded time.
506 @param aCategory The UID that identifies the property category.
507 @param aKey The property sub-key, i.e. the key that identifies the
508 specific property within the category.
509 @param aType The ownership of this property handle.
510 By default, ownership is vested in the current process,
511 but can be vested in the current thread by
512 specifying EOwnerThread.
514 @return KErrNone, if successful;
515 KErrNoMemory, if memory allocation is required, and there is
516 insufficient available.
518 EXPORT_C TInt RProperty::Attach(TUid aCategory, TUint aKey, TOwnerType aType)
520 TInt r = Exec::PropertyAttach(TUint(aCategory.iUid), aKey, aType);
534 Subscribes to a property.
536 The function issues an asynchronous request to be notified when the property
537 is changed. The calling thread is signalled, and the specified request status
538 object is updated when the property is next changed.
540 The property may change several times before the subscribing thread can deal
541 with a notification request completion. To ensure that the subscriber does not
542 miss updates, it should re-issue a subscription request before retrieving
543 the current value and acting on it.
545 If the property has not been defined, the request does not complete until
546 the property is subsequently defined and published. When defined, if the caller
547 process doesn't pass the Read Policy, then the request completes with KErrPermissionDenied.
549 If the property is already defined, and the caller process doesn't pass the Read Policy,
550 then the request completes immediately with KErrPermissionDenied.
552 When Read Policy checks fail the action taken is determined by the system wide Platform Security
553 configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
554 If PlatSecEnforcement is OFF, then the request will complete successfully even though the
557 If an outstanding request is cancelled through a call to Cancel(), then it
558 completes with KErrCancel.
560 @param aRequest The request status object to be signalled on update.
562 @panic KERN-EXEC 9 if there is already a subscription on this property handle;
563 only one subscription per RProperty is allowed.
565 EXPORT_C void RProperty::Subscribe(TRequestStatus& aRequest)
567 aRequest = KRequestPending;
568 Exec::PropertySubscribe(iHandle, &aRequest);
575 Cancels an outstanding subscription request for this property handle.
577 If the request has not already completed, then it completes with KErrCancel.
579 EXPORT_C void RProperty::Cancel()
581 Exec::PropertyCancel(iHandle);
588 Gets the integer value of this property.
590 The implementation guarantees that this call has a bounded response time.
592 @param aValue A reference to the variable where the property value
595 @return KErrNone, if successful;
596 KErrPermissionDenied, if the caller process doesn't pass the Read Policy;
597 KErrNotFound, if the property has not been defined;
598 KErrArgument, if the property is not of integral type.
600 EXPORT_C TInt RProperty::Get(TInt& aValue)
602 return(Exec::PropertyGetI(iHandle, &aValue));
609 Gets the byte-array (binary) value of this property.
611 The implementation guarantees that this call has a bounded response time.
613 @param aDes A reference to the buffer descriptor where the property value
616 @return KErrNone, if successful;
617 KErrPermissionDenied, if the caller process doesn't pass the Read Policy;
618 KErrNotFound, if the property has not been defined;
619 KErrArgument, if the property is not a byte-array (binary) type.
620 KErrOverflow, if the supplied buffer is too small to contain the full
621 property value, and note that the buffer aDes contains the
622 truncated property value.
624 EXPORT_C TInt RProperty::Get(TDes8& aDes)
626 TInt size = aDes.MaxSize();
627 TInt r = Exec::PropertyGetB(iHandle, (TUint8*) aDes.Ptr(), size);
630 if (r == KErrOverflow)
632 aDes.SetLength(size);
644 Gets the text value of this property.
646 The implementation guarantees that this call has a bounded response time.
648 @param aDes A reference to the buffer descriptor where the property value
651 @return KErrNone, if successful;
652 KErrPermissionDenied, if the caller process doesn't pass the Read Policy;
653 KErrNotFound, if the property has not been defined;
654 KErrArgument, if the property is not a text type;
655 KErrOverflow, if the supplied buffer is too small to contain the full
656 property value, and note that the buffer aDes contains the
657 truncated property value.
659 EXPORT_C TInt RProperty::Get(TDes16& aDes)
661 TInt size = aDes.MaxSize();
662 TInt r = Exec::PropertyGetB(iHandle, (TUint8*) aDes.Ptr(), size);
665 if (r == KErrOverflow)
667 aDes.SetLength(size >> 1);
671 aDes.SetLength(r >> 1);
679 Sets a new integer value for this property.
681 The function publishes the attached new integral property value, and any
682 pending subscriptions for this property are completed.
684 The implementation guarantees that this call has a bounded response time.
686 @param aValue The property new value.
688 @return KErrNone, if successful;
689 KErrPermissionDenied, if the caller process doesn't pass the Write Policy;
690 KErrNotFound, if the property has not been defined;
691 KErrArgument, if the property is not of integral type.
693 EXPORT_C TInt RProperty::Set(TInt aValue)
695 return(Exec::PropertySetI(iHandle, aValue));
702 Sets the byte-array (binary) property.
704 The function publishes the attached new binary property value, and any
705 pending subscriptions for this property are completed.
707 The implementation guarantees that this call has a bounded response time only
708 if the new property value requires no more storage space than is
709 currently allocated. If more memory needs to be allocated, then this
710 invalidates the real-time guarantee.
712 @param aDes A reference to the descriptor containing the property new value.
714 @return KErrNone, if successful;
715 KErrPermissionDenied, if the caller process doesn't pass the Write Policy;
716 KErrNotFound, if the property has not been defined;
717 KErrArgument, if the property is not a byte-array (binary) type;
718 KErrNoMemory, if memory allocation is required, and there is
719 insufficient available.
720 KMaxPropertySize, if the property is larger than KErrTooBig.
722 EXPORT_C TInt RProperty::Set(const TDesC8& aDes)
724 return(Exec::PropertySetB(iHandle, (TUint8*) aDes.Ptr(), aDes.Size()));
731 Sets the text property
733 The function publishes the attached new text property value, and any
734 pending subscriptions for this property are completed.
736 The implementation guarantees that this call has a bounded response time only
737 if the new property value requires no more storage space than is
738 currently allocated. If more memory needs to be allocated, then this
739 invalidates the real-time guarantee.
741 @param aDes A reference to the descriptor containing the property new value.
743 @return KErrNone, if successful;
744 KErrPermissionDenied, if the caller process doesn't pass the Write Policy;
745 KErrNotFound, if the property has not been defined;
746 KErrArgument, if the property is not a byte-array (binary) type;
747 KErrNoMemory, if memory allocation is required, and there is
748 insufficient available.
749 KMaxPropertySize, if the property is larger than KErrTooBig.
751 EXPORT_C TInt RProperty::Set(const TDesC16& aDes)
753 return(Exec::PropertySetB(iHandle, (TUint8*) aDes.Ptr(), aDes.Size()));