1 .\" $NetBSD: prop_ingest.3,v 1.5 2008/04/30 13:10:46 martin Exp $
3 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
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.
34 .Nm prop_ingest_context_alloc ,
35 .Nm prop_ingest_context_free ,
36 .Nm prop_ingest_context_error ,
37 .Nm prop_ingest_context_type ,
38 .Nm prop_ingest_context_key ,
39 .Nm prop_ingest_context_private ,
40 .Nm prop_dictionary_ingest
41 .Nd Ingest a dictionary into an arbitrary binary format
44 .Ft prop_ingest_context_t
45 .Fn prop_ingest_context_alloc "void *private"
47 .Fn prop_ingest_context_free "prop_ingest_context_t ctx"
48 .Ft prop_ingest_error_t
49 .Fn prop_ingest_context_error "prop_ingest_context_t ctx"
51 .Fn prop_ingest_context_type "prop_ingest_context_t ctx"
53 .Fn prop_ingest_context_key "prop_ingest_context_t ctx"
55 .Fn prop_ingest_context_private "prop_ingest_context_t ctx"
57 .Fn prop_dictionary_ingest "prop_dictionary_t dict" \
58 "const prop_ingest_table_entry rules[]" \
59 "prop_ingest_context_t ctx"
62 .Fn (*prop_ingest_handler_t) "prop_ingest_context_t" "prop_object_t"
65 .Nm prop_dictionary_ingest
66 function provides a convenient way to convert a property list into
67 an arbitrary binary format or to extract values from dictionaries in a
68 way that is convenient to an application
69 .Pq for configuration files, for example .
71 .Nm prop_dictionary_ingest
72 is driven by a table of rules provided by the application.
73 Each rule consists of three items:
76 A C string containing a key to be looked up in the dictionary.
78 The expected property type of the object associated with the key
81 to specify that any type is allowed).
83 A callback function of type
84 .Dv prop_ingest_handler_t
85 that will perform the translation for the application.
88 The table is constructed using a series of macros as follows:
90 static const prop_ingest_table_entry ingest_rules[] = {
91 PROP_INGEST("file-name", PROP_TYPE_STRING, ingest_filename),
92 PROP_INGEST("count", PROP_TYPE_NUMBER, ingest_count),
93 PROP_INGEST_OPTIONAL("required", PROP_TYPE_BOOL, ingest_required),
94 PROP_INGEST_OPTIONAL("extra", PROP_TYPE_UNKNOWN, ingest_extra),
101 macro specifies that the key is required to be present in the dictionary.
103 .Dv PROP_INGEST_OPTIONAL
104 macro specifies that the presence of the key in the dictionary is optional.
107 macro marks the end of the rules table.
110 .Nm prop_dictionary_ingest
111 looks up the rule's key in the dictionary.
112 If an object is present in the dictionary at that key, its type is checked
113 against the type specified in the rule.
114 A type specification of
115 .Dv PROP_TYPE_UNKNOWN
116 allows the object to be of any type.
117 If the object does not exist and the rule is not marked as optional, then
118 an error is returned.
119 Otherwise, the handler specified in the rule is invoked with the ingest
120 context and the object
123 if the key does not exist in the dictionary).
124 The handler should return
126 if the value of the object is invalid to indicate failure and
130 The ingest context contains several pieces of information that are
131 useful during the ingest process.
132 The context also provides specific error information should the ingest
134 .Bl -tag -width "xxxxx"
135 .It Fn prop_ingest_context_alloc "void *private"
136 Allocate an ingest context.
139 may be used to pass application-specific context to the ingest handlers.
140 Note that an ingest context can be re-used to perform multiple ingests.
144 .It Fn prop_ingest_context_free "prop_ingest_context_t ctx"
145 Free an ingest context.
146 .It Fn prop_ingest_context_error "prop_ingest_context_t ctx"
147 Returns the code indicating the error encountered during ingest.
148 The following error codes are defined:
150 .Bl -tag -width "PROP_INGEST_ERROR_HANDLER_FAILED" -compact
151 .It Dv PROP_INGEST_ERROR_NO_ERROR
152 No error was encountered during ingest.
153 .It Dv PROP_INGEST_ERROR_NO_KEY
154 A non-optional key was not found in the dictionary.
155 .It Dv PROP_INGEST_ERROR_WRONG_TYPE
156 An object in the dictionary was not the same type specifed in the rules.
157 .It Dv PROP_INGEST_ERROR_HANDLER_FAILED
158 An object's handler returned
162 .It Fn prop_ingest_context_type "prop_ingest_context_t ctx"
163 Returns the type of the last object visited during an ingest.
164 When called by an ingest handler, it returns the type of the object
165 currently being processed.
166 .It Fn prop_ingest_context_key "prop_ingest_context_t ctx"
167 Returns the last dictionary key looked up during an ingest.
168 When called by an ingest handler, it returns the dictionary key corresponding
169 to the object currently being processed.
170 .It Fn prop_ingest_context_private "prop_ingest_context_t ctx"
171 Returns the private data set when the context was allocated with
172 .Fn prop_ingest_context_alloc .
175 .Xr prop_dictionary 3 ,
180 property container object library first appeared in