1.\" $NetBSD: proplib.3,v 1.10 2025/04/23 02:58:52 thorpej Exp $ 2.\" 3.\" Copyright (c) 2006, 2025 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Jason R. Thorpe. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd April 20, 2025 31.Dt PROPLIB 3 32.Os 33.Sh NAME 34.Nm proplib 35.Nd property container object library 36.Sh LIBRARY 37.Lb libprop 38.Sh SYNOPSIS 39.In prop/proplib.h 40.Sh DESCRIPTION 41The 42.Nm 43library provides an abstract interface for creating and manipulating 44property lists. 45Property lists have object types for boolean values, opaque data, numbers, 46and strings. 47Structure is provided by the array and dictionary collection types. 48.Pp 49Property lists can be passed across protection boundaries by translating 50them to an external representation. 51There are two formats availavble for external representation: 52.Bl -bullet 53.It 54An XML document whose format is described by the following DTD: 55.Bd -literal -offset indent 56.Lk http://www.apple.com/DTDs/PropertyList-1.0.dtd 57.Ed 58.It 59A JSON document whose format is described by RFC 8259. 60.El 61.Pp 62Property container objects are reference counted. 63When an object is created, its reference count is set to 1. 64Any code that keeps a reference to an object, including the collection 65types 66.Pq arrays and dictionaries , 67must 68.Dq retain 69the object 70.Pq increment its reference count . 71When that reference is dropped, the object must be 72.Dq released 73.Pq reference count decremented . 74When an object's reference count drops to 0, it is automatically freed. 75.Pp 76The rules for managing reference counts are very simple: 77.Bl -bullet 78.It 79If you create an object and do not explicitly maintain a reference to it, 80you must release it. 81.It 82If you get a reference to an object from other code and wish to maintain 83a reference to it, you must retain the object. 84You are responsible for 85releasing the object once you drop that reference. 86.It 87You must never release an object unless you create it or retain it. 88.El 89.Pp 90Object collections may be iterated by creating a special iterator object. 91Iterator objects are special; they may not be retained, and they are 92released using an iterator-specific release function. 93.Sh SEE ALSO 94.Xr prop_array 3 , 95.Xr prop_array_util 3 , 96.Xr prop_bool 3 , 97.Xr prop_data 3 , 98.Xr prop_dictionary 3 , 99.Xr prop_dictionary_util 3 , 100.Xr prop_number 3 , 101.Xr prop_object 3 , 102.Xr prop_send_ioctl 3 , 103.Xr prop_send_syscall 3 , 104.Xr prop_string 3 105.Sh HISTORY 106The 107.Nm 108property container object library first appeared in 109.Nx 4.0 . 110Support for the JSON serialization format was added in 111.Nx 11.0 . 112.Sh CAVEATS 113.Nm 114does not have a 115.Sq date 116object type, and thus will not parse 117.Sq date 118elements from an Apple XML property list. 119.Pp 120.Nm 121does not have a 122.Sq null 123object type, and thus will not parse 124.Sq null 125elements from a JSON document. 126.Pp 127The 128.Nm 129.Sq number 130object type differs from the Apple XML property list format in the following 131ways: 132.Bl -bullet 133.It 134The external representation for unsigned numbers is in base 16, not base 10. 135.Nm 136is able to parse base 8, base 10, and base 16 137.Sq integer 138elements. 139Signed numbers are represented in base 10. 140.It 141.Nm 142does not support floating point numbers, so 143.Sq real 144elements from an Apple XML property list will not be parsed. 145.El 146.Pp 147Similarly, 148.Nm 149does not parse floating point numbers 150.Pq as described in RFC 8259 151in JSON documents. 152For JSON documents, all numbers are represented in base 10. 153.Pp 154JSON does not have an opaque data element that is functionally equivalent 155to the 156.Sq data 157elements in XML property lists. 158As such, a property list containing 159.Sq data 160objects cannot be externalized into a JSON document. 161.Pp 162In order to facilitate use of 163.Nm 164in kernel, standalone, and user space environments, the 165.Nm 166parser is not a real XML parser. 167It is hard-coded to parse only the property list external representation. 168