]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/libucl/doc/libucl.3
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / libucl / doc / libucl.3
1 .TH LIBUCL 5 "March 20, 2014" "Libucl manual"
2 .SH NAME
3 .PP
4 \f[B]ucl_parser_new\f[], \f[B]ucl_parser_register_macro\f[],
5 \f[B]ucl_parser_register_variable\f[], \f[B]ucl_parser_add_chunk\f[],
6 \f[B]ucl_parser_add_string\f[], \f[B]ucl_parser_add_file\f[],
7 \f[B]ucl_parser_get_object\f[], \f[B]ucl_parser_get_error\f[],
8 \f[B]ucl_parser_free\f[], \f[B]ucl_pubkey_add\f[],
9 \f[B]ucl_parser_set_filevars\f[] \- universal configuration library
10 parser and utility functions
11 .SH LIBRARY
12 .PP
13 UCL library (libucl, \-lucl)
14 .SH SYNOPSIS
15 .PP
16 \f[C]#include\ <ucl.h>\f[]
17 .SH DESCRIPTION
18 .PP
19 Libucl is a parser and \f[C]C\f[] API to parse and generate \f[C]ucl\f[]
20 objects.
21 Libucl consist of several groups of functions:
22 .SS Parser functions
23 .PP
24 Used to parse \f[C]ucl\f[] files and provide interface to extract
25 \f[C]ucl\f[] object.
26 Currently, \f[C]libucl\f[] can parse only full \f[C]ucl\f[] documents,
27 for instance, it is impossible to parse a part of document and therefore
28 it is impossible to use \f[C]libucl\f[] as a streaming parser.
29 In future, this limitation can be removed.
30 .SS Emitting functions
31 .PP
32 Convert \f[C]ucl\f[] objects to some textual or binary representation.
33 Currently, libucl supports the following exports:
34 .IP \[bu] 2
35 \f[C]JSON\f[] \- valid json format (can possibly loose some original
36 data, such as implicit arrays)
37 .IP \[bu] 2
38 \f[C]Config\f[] \- human\-readable configuration format (losseless)
39 .IP \[bu] 2
40 \f[C]YAML\f[] \- embedded yaml format (has the same limitations as
41 \f[C]json\f[] output)
42 .SS Conversion functions
43 .PP
44 Help to convert \f[C]ucl\f[] objects to C types.
45 These functions are used to convert \f[C]ucl_object_t\f[] to C primitive
46 types, such as numbers, strings or boolean values.
47 .SS Generation functions
48 .PP
49 Allow creating of \f[C]ucl\f[] objects from C types and creating of
50 complex \f[C]ucl\f[] objects, such as hashes or arrays from primitive
51 \f[C]ucl\f[] objects, such as numbers or strings.
52 .SS Iteration functions
53 .PP
54 Iterate over \f[C]ucl\f[] complex objects or over a chain of values, for
55 example when a key in an object has multiple values (that can be treated
56 as implicit array or implicit consolidation).
57 .SS Validation functions
58 .PP
59 Validation functions are used to validate some object \f[C]obj\f[] using
60 json\-schema compatible object \f[C]schema\f[].
61 Both input and schema must be UCL objects to perform validation.
62 .SS Utility functions
63 .PP
64 Provide basic utilities to manage \f[C]ucl\f[] objects: creating,
65 removing, retaining and releasing reference count and so on.
66 .SH PARSER FUNCTIONS
67 .PP
68 Parser functions operates with \f[C]struct\ ucl_parser\f[].
69 .SS ucl_parser_new
70 .IP
71 .nf
72 \f[C]
73 struct\ ucl_parser*\ ucl_parser_new\ (int\ flags);
74 \f[]
75 .fi
76 .PP
77 Creates new parser with the specified flags:
78 .IP \[bu] 2
79 \f[C]UCL_PARSER_KEY_LOWERCASE\f[] \- lowercase keys parsed
80 .IP \[bu] 2
81 \f[C]UCL_PARSER_ZEROCOPY\f[] \- try to use zero\-copy mode when reading
82 files (in zero\-copy mode text chunk being parsed without copying
83 strings so it should exist till any object parsed is used)
84 .IP \[bu] 2
85 \f[C]UCL_PARSER_NO_TIME\f[] \- treat time values as strings without
86 parsing them as floats
87 .SS ucl_parser_register_macro
88 .IP
89 .nf
90 \f[C]
91 void\ ucl_parser_register_macro\ (struct\ ucl_parser\ *parser,
92 \ \ \ \ const\ char\ *macro,\ ucl_macro_handler\ handler,\ void*\ ud);
93 \f[]
94 .fi
95 .PP
96 Register new macro with name .\f[C]macro\f[] parsed by handler
97 \f[C]handler\f[] that accepts opaque data pointer \f[C]ud\f[].
98 Macro handler should be of the following type:
99 .IP
100 .nf
101 \f[C]
102 bool\ (*ucl_macro_handler)\ (const\ unsigned\ char\ *data,
103 \ \ \ \ size_t\ len,\ void*\ ud);`
104 \f[]
105 .fi
106 .PP
107 Handler function accepts macro text \f[C]data\f[] of length \f[C]len\f[]
108 and the opaque pointer \f[C]ud\f[].
109 If macro is parsed successfully the handler should return \f[C]true\f[].
110 \f[C]false\f[] indicates parsing failure and the parser can be
111 terminated.
112 .SS ucl_parser_register_variable
113 .IP
114 .nf
115 \f[C]
116 void\ ucl_parser_register_variable\ (struct\ ucl_parser\ *parser,
117 \ \ \ \ const\ char\ *var,\ const\ char\ *value);
118 \f[]
119 .fi
120 .PP
121 Register new variable $\f[C]var\f[] that should be replaced by the
122 parser to the \f[C]value\f[] string.
123 .SS ucl_parser_add_chunk
124 .IP
125 .nf
126 \f[C]
127 bool\ ucl_parser_add_chunk\ (struct\ ucl_parser\ *parser,\ 
128 \ \ \ \ const\ unsigned\ char\ *data,\ size_t\ len);
129 \f[]
130 .fi
131 .PP
132 Add new text chunk with \f[C]data\f[] of length \f[C]len\f[] to the
133 parser.
134 At the moment, \f[C]libucl\f[] parser is not a streamlined parser and
135 chunk \f[I]must\f[] contain the \f[I]valid\f[] ucl object.
136 For example, this object should be valid:
137 .IP
138 .nf
139 \f[C]
140 {\ "var":\ "value"\ }
141 \f[]
142 .fi
143 .PP
144 while this one won\[aq]t be parsed correctly:
145 .IP
146 .nf
147 \f[C]
148 {\ "var":\ 
149 \f[]
150 .fi
151 .PP
152 This limitation may possible be removed in future.
153 .SS ucl_parser_add_string
154 .IP
155 .nf
156 \f[C]
157 bool\ ucl_parser_add_string\ (struct\ ucl_parser\ *parser,\ 
158 \ \ \ \ const\ char\ *data,\ size_t\ len);
159 \f[]
160 .fi
161 .PP
162 This function acts exactly like \f[C]ucl_parser_add_chunk\f[] does but
163 if \f[C]len\f[] argument is zero, then the string \f[C]data\f[] must be
164 zero\-terminated and the actual length is calculated up to \f[C]\\0\f[]
165 character.
166 .SS ucl_parser_add_file
167 .IP
168 .nf
169 \f[C]
170 bool\ ucl_parser_add_file\ (struct\ ucl_parser\ *parser,\ 
171 \ \ \ \ const\ char\ *filename);
172 \f[]
173 .fi
174 .PP
175 Load file \f[C]filename\f[] and parse it with the specified
176 \f[C]parser\f[].
177 This function uses \f[C]mmap\f[] call to load file, therefore, it should
178 not be \f[C]shrinked\f[] during parsing.
179 Otherwise, \f[C]libucl\f[] can cause memory corruption and terminate the
180 calling application.
181 This function is also used by the internal handler of \f[C]include\f[]
182 macro, hence, this macro has the same limitation.
183 .SS ucl_parser_get_object
184 .IP
185 .nf
186 \f[C]
187 ucl_object_t*\ ucl_parser_get_object\ (struct\ ucl_parser\ *parser);
188 \f[]
189 .fi
190 .PP
191 If the \f[C]ucl\f[] data has been parsed correctly this function returns
192 the top object for the parser.
193 Otherwise, this function returns the \f[C]NULL\f[] pointer.
194 The reference count for \f[C]ucl\f[] object returned is increased by
195 one, therefore, a caller should decrease reference by using
196 \f[C]ucl_object_unref\f[] to free object after usage.
197 .SS ucl_parser_get_error
198 .IP
199 .nf
200 \f[C]
201 const\ char\ *ucl_parser_get_error(struct\ ucl_parser\ *parser);
202 \f[]
203 .fi
204 .PP
205 Returns the constant error string for the parser object.
206 If no error occurred during parsing a \f[C]NULL\f[] object is returned.
207 A caller should not try to free or modify this string.
208 .SS ucl_parser_free
209 .IP
210 .nf
211 \f[C]
212 void\ ucl_parser_free\ (struct\ ucl_parser\ *parser);
213 \f[]
214 .fi
215 .PP
216 Frees memory occupied by the parser object.
217 The reference count for top object is decreased as well, however if the
218 function \f[C]ucl_parser_get_object\f[] was called previously then the
219 top object won\[aq]t be freed.
220 .SS ucl_pubkey_add
221 .IP
222 .nf
223 \f[C]
224 bool\ ucl_pubkey_add\ (struct\ ucl_parser\ *parser,\ 
225 \ \ \ \ const\ unsigned\ char\ *key,\ size_t\ len);
226 \f[]
227 .fi
228 .PP
229 This function adds a public key from text blob \f[C]key\f[] of length
230 \f[C]len\f[] to the \f[C]parser\f[] object.
231 This public key should be in the \f[C]PEM\f[] format and can be used by
232 \f[C]\&.includes\f[] macro for checking signatures of files included.
233 \f[C]Openssl\f[] support should be enabled to make this function
234 working.
235 If a key cannot be added (e.g.
236 due to format error) or \f[C]openssl\f[] was not linked to
237 \f[C]libucl\f[] then this function returns \f[C]false\f[].
238 .SS ucl_parser_set_filevars
239 .IP
240 .nf
241 \f[C]
242 bool\ ucl_parser_set_filevars\ (struct\ ucl_parser\ *parser,\ 
243 \ \ \ \ const\ char\ *filename,\ bool\ need_expand);
244 \f[]
245 .fi
246 .PP
247 Add the standard file variables to the \f[C]parser\f[] based on the
248 \f[C]filename\f[] specified:
249 .IP \[bu] 2
250 \f[C]$FILENAME\f[] \- a filename of \f[C]ucl\f[] input
251 .IP \[bu] 2
252 \f[C]$CURDIR\f[] \- a current directory of the input
253 .PP
254 For example, if a \f[C]filename\f[] param is
255 \f[C]\&../something.conf\f[] then the variables will have the following
256 values:
257 .IP \[bu] 2
258 \f[C]$FILENAME\f[] \- "../something.conf"
259 .IP \[bu] 2
260 \f[C]$CURDIR\f[] \- ".."
261 .PP
262 if \f[C]need_expand\f[] parameter is \f[C]true\f[] then all relative
263 paths are expanded using \f[C]realpath\f[] call.
264 In this example if \f[C]\&..\f[] is \f[C]/etc/dir\f[] then variables
265 will have these values:
266 .IP \[bu] 2
267 \f[C]$FILENAME\f[] \- "/etc/something.conf"
268 .IP \[bu] 2
269 \f[C]$CURDIR\f[] \- "/etc"
270 .SS Parser usage example
271 .PP
272 The following example loads, parses and extracts \f[C]ucl\f[] object
273 from stdin using \f[C]libucl\f[] parser functions (the length of input
274 is limited to 8K):
275 .IP
276 .nf
277 \f[C]
278 char\ inbuf[8192];
279 struct\ ucl_parser\ *parser\ =\ NULL;
280 int\ ret\ =\ 0,\ r\ =\ 0;
281 ucl_object_t\ *obj\ =\ NULL;
282 FILE\ *in;
283
284 in\ =\ stdin;
285 parser\ =\ ucl_parser_new\ (0);
286 while\ (!feof\ (in)\ &&\ r\ <\ (int)sizeof\ (inbuf))\ {
287 \ \ \ \ r\ +=\ fread\ (inbuf\ +\ r,\ 1,\ sizeof\ (inbuf)\ \-\ r,\ in);
288 }
289 ucl_parser_add_chunk\ (parser,\ inbuf,\ r);
290 fclose\ (in);
291
292 if\ (ucl_parser_get_error\ (parser))\ {
293 \ \ \ \ printf\ ("Error\ occured:\ %s\\n",\ ucl_parser_get_error\ (parser));
294 \ \ \ \ ret\ =\ 1;
295 }
296 else\ {
297 \ \ \ \ obj\ =\ ucl_parser_get_object\ (parser);
298 }
299
300 if\ (parser\ !=\ NULL)\ {
301 \ \ \ \ ucl_parser_free\ (parser);
302 }
303 if\ (obj\ !=\ NULL)\ {
304 \ \ \ \ ucl_object_unref\ (obj);
305 }
306 return\ ret;
307 \f[]
308 .fi
309 .SH EMITTING FUNCTIONS
310 .PP
311 Libucl can transform UCL objects to a number of tectual formats:
312 .IP \[bu] 2
313 configuration (\f[C]UCL_EMIT_CONFIG\f[]) \- nginx like human readable
314 configuration file where implicit arrays are transformed to the
315 duplicate keys
316 .IP \[bu] 2
317 compact json: \f[C]UCL_EMIT_JSON_COMPACT\f[] \- single line valid json
318 without spaces
319 .IP \[bu] 2
320 formatted json: \f[C]UCL_EMIT_JSON\f[] \- pretty formatted JSON with
321 newlines and spaces
322 .IP \[bu] 2
323 compact yaml: \f[C]UCL_EMIT_YAML\f[] \- compact YAML output
324 .PP
325 Moreover, libucl API allows to select a custom set of emitting functions
326 allowing efficent and zero\-copy output of libucl objects.
327 Libucl uses the following structure to support this feature:
328 .IP
329 .nf
330 \f[C]
331 struct\ ucl_emitter_functions\ {
332 \ \ \ \ /**\ Append\ a\ single\ character\ */
333 \ \ \ \ int\ (*ucl_emitter_append_character)\ (unsigned\ char\ c,\ size_t\ nchars,\ void\ *ud);
334 \ \ \ \ /**\ Append\ a\ string\ of\ a\ specified\ length\ */
335 \ \ \ \ int\ (*ucl_emitter_append_len)\ (unsigned\ const\ char\ *str,\ size_t\ len,\ void\ *ud);
336 \ \ \ \ /**\ Append\ a\ 64\ bit\ integer\ */
337 \ \ \ \ int\ (*ucl_emitter_append_int)\ (int64_t\ elt,\ void\ *ud);
338 \ \ \ \ /**\ Append\ floating\ point\ element\ */
339 \ \ \ \ int\ (*ucl_emitter_append_double)\ (double\ elt,\ void\ *ud);
340 \ \ \ \ /**\ Opaque\ userdata\ pointer\ */
341 \ \ \ \ void\ *ud;
342 };
343 \f[]
344 .fi
345 .PP
346 This structure defines the following callbacks:
347 .IP \[bu] 2
348 \f[C]ucl_emitter_append_character\f[] \- a function that is called to
349 append \f[C]nchars\f[] characters equal to \f[C]c\f[]
350 .IP \[bu] 2
351 \f[C]ucl_emitter_append_len\f[] \- used to append a string of length
352 \f[C]len\f[] starting from pointer \f[C]str\f[]
353 .IP \[bu] 2
354 \f[C]ucl_emitter_append_int\f[] \- this function applies to integer
355 numbers
356 .IP \[bu] 2
357 \f[C]ucl_emitter_append_double\f[] \- this function is intended to
358 output floating point variable
359 .PP
360 The set of these functions could be used to output text formats of
361 \f[C]UCL\f[] objects to different structures or streams.
362 .PP
363 Libucl provides the following functions for emitting UCL objects:
364 .SS ucl_object_emit
365 .IP
366 .nf
367 \f[C]
368 unsigned\ char\ *ucl_object_emit\ (const\ ucl_object_t\ *obj,\ enum\ ucl_emitter\ emit_type);
369 \f[]
370 .fi
371 .PP
372 Allocate a string that is suitable to fit the underlying UCL object
373 \f[C]obj\f[] and fill it with the textual representation of the object
374 \f[C]obj\f[] according to style \f[C]emit_type\f[].
375 The caller should free the returned string after using.
376 .SS ucl_object_emit_full
377 .IP
378 .nf
379 \f[C]
380 bool\ ucl_object_emit_full\ (const\ ucl_object_t\ *obj,\ enum\ ucl_emitter\ emit_type,
381 \ \ \ \ \ \ \ \ struct\ ucl_emitter_functions\ *emitter);
382 \f[]
383 .fi
384 .PP
385 This function is similar to the previous with the exception that it
386 accepts the additional argument \f[C]emitter\f[] that defines the
387 concrete set of output functions.
388 This emit function could be useful for custom structures or streams
389 emitters (including C++ ones, for example).
390 .SH CONVERSION FUNCTIONS
391 .PP
392 Conversion functions are used to convert UCL objects to primitive types,
393 such as strings, numbers or boolean values.
394 There are two types of conversion functions:
395 .IP \[bu] 2
396 safe: try to convert an ucl object to a primitive type and fail if such
397 a conversion is not possible
398 .IP \[bu] 2
399 unsafe: return primitive type without additional checks, if the object
400 cannot be converted then some reasonable default is returned (NULL for
401 strings and 0 for numbers)
402 .PP
403 Also there is a single \f[C]ucl_object_tostring_forced\f[] function that
404 converts any UCL object (including compound types \- arrays and objects)
405 to a string representation.
406 For compound and numeric types this function performs emitting to a
407 compact json format actually.
408 .PP
409 Here is a list of all conversion functions:
410 .IP \[bu] 2
411 \f[C]ucl_object_toint\f[] \- returns \f[C]int64_t\f[] of UCL object
412 .IP \[bu] 2
413 \f[C]ucl_object_todouble\f[] \- returns \f[C]double\f[] of UCL object
414 .IP \[bu] 2
415 \f[C]ucl_object_toboolean\f[] \- returns \f[C]bool\f[] of UCL object
416 .IP \[bu] 2
417 \f[C]ucl_object_tostring\f[] \- returns \f[C]const\ char\ *\f[] of UCL
418 object (this string is NULL terminated)
419 .IP \[bu] 2
420 \f[C]ucl_object_tolstring\f[] \- returns \f[C]const\ char\ *\f[] and
421 \f[C]size_t\f[] len of UCL object (string can be not NULL terminated)
422 .IP \[bu] 2
423 \f[C]ucl_object_tostring_forced\f[] \- returns string representation of
424 any UCL object
425 .PP
426 Strings returned by these pointers are associated with the UCL object
427 and exist over its lifetime.
428 A caller should not free this memory.
429 .SH GENERATION FUNCTIONS
430 .PP
431 It is possible to generate UCL objects from C primitive types.
432 Moreover, libucl permits to create and modify complex UCL objects, such
433 as arrays or associative objects.
434 .SS ucl_object_new
435 .IP
436 .nf
437 \f[C]
438 ucl_object_t\ *\ ucl_object_new\ (void)
439 \f[]
440 .fi
441 .PP
442 Creates new object of type \f[C]UCL_NULL\f[].
443 This object should be released by caller.
444 .SS ucl_object_typed_new
445 .IP
446 .nf
447 \f[C]
448 ucl_object_t\ *\ ucl_object_typed_new\ (unsigned\ int\ type)
449 \f[]
450 .fi
451 .PP
452 Create an object of a specified type: \- \f[C]UCL_OBJECT\f[] \- UCL
453 object \- key/value pairs \- \f[C]UCL_ARRAY\f[] \- UCL array \-
454 \f[C]UCL_INT\f[] \- integer number \- \f[C]UCL_FLOAT\f[] \- floating
455 point number \- \f[C]UCL_STRING\f[] \- NULL terminated string \-
456 \f[C]UCL_BOOLEAN\f[] \- boolean value \- \f[C]UCL_TIME\f[] \- time value
457 (floating point number of seconds) \- \f[C]UCL_USERDATA\f[] \- opaque
458 userdata pointer (may be used in macros) \- \f[C]UCL_NULL\f[] \- null
459 value
460 .PP
461 This object should be released by caller.
462 .SS Primitive objects generation
463 .PP
464 Libucl provides the functions similar to inverse conversion functions
465 called with the specific C type: \- \f[C]ucl_object_fromint\f[] \-
466 converts \f[C]int64_t\f[] to UCL object \-
467 \f[C]ucl_object_fromdouble\f[] \- converts \f[C]double\f[] to UCL object
468 \- \f[C]ucl_object_fromboolean\f[] \- converts \f[C]bool\f[] to UCL
469 object \- \f[C]ucl_object_fromstring\f[] \- converts
470 \f[C]const\ char\ *\f[] to UCL object (this string is NULL terminated)
471 \- \f[C]ucl_object_fromlstring\f[] \- converts \f[C]const\ char\ *\f[]
472 and \f[C]size_t\f[] len to UCL object (string can be not NULL
473 terminated)
474 .PP
475 Also there is a function to generate UCL object from a string performing
476 various parsing or conversion operations called
477 \f[C]ucl_object_fromstring_common\f[].
478 .SS ucl_object_fromstring_common
479 .IP
480 .nf
481 \f[C]
482 ucl_object_t\ *\ ucl_object_fromstring_common\ (const\ char\ *str,\ 
483 \ \ \ \ size_t\ len,\ enum\ ucl_string_flags\ flags)
484 \f[]
485 .fi
486 .PP
487 This function is used to convert a string \f[C]str\f[] of size
488 \f[C]len\f[] to an UCL objects applying \f[C]flags\f[] conversions.
489 If \f[C]len\f[] is equal to zero then a \f[C]str\f[] is assumed as
490 NULL\-terminated.
491 This function supports the following flags (a set of flags can be
492 specified using logical \f[C]OR\f[] operation):
493 .IP \[bu] 2
494 \f[C]UCL_STRING_ESCAPE\f[] \- perform JSON escape
495 .IP \[bu] 2
496 \f[C]UCL_STRING_TRIM\f[] \- trim leading and trailing whitespaces
497 .IP \[bu] 2
498 \f[C]UCL_STRING_PARSE_BOOLEAN\f[] \- parse passed string and detect
499 boolean
500 .IP \[bu] 2
501 \f[C]UCL_STRING_PARSE_INT\f[] \- parse passed string and detect integer
502 number
503 .IP \[bu] 2
504 \f[C]UCL_STRING_PARSE_DOUBLE\f[] \- parse passed string and detect
505 integer or float number
506 .IP \[bu] 2
507 \f[C]UCL_STRING_PARSE_TIME\f[] \- parse time values as floating point
508 numbers
509 .IP \[bu] 2
510 \f[C]UCL_STRING_PARSE_NUMBER\f[] \- parse passed string and detect
511 number (both float, integer and time types)
512 .IP \[bu] 2
513 \f[C]UCL_STRING_PARSE\f[] \- parse passed string (and detect booleans,
514 numbers and time values)
515 .IP \[bu] 2
516 \f[C]UCL_STRING_PARSE_BYTES\f[] \- assume that numeric multipliers are
517 in bytes notation, for example \f[C]10k\f[] means \f[C]10*1024\f[] and
518 not \f[C]10*1000\f[] as assumed without this flag
519 .PP
520 If parsing operations fail then the resulting UCL object will be a
521 \f[C]UCL_STRING\f[].
522 A caller should always check the type of the returned object and release
523 it after using.
524 .SH ITERATION FUNCTIONS
525 .PP
526 Iteration are used to iterate over UCL compound types: arrays and
527 objects.
528 Moreover, iterations could be performed over the keys with multiple
529 values (implicit arrays).
530 To iterate over an object, an array or a key with multiple values there
531 is a function \f[C]ucl_iterate_object\f[].
532 .SS ucl_iterate_object
533 .IP
534 .nf
535 \f[C]
536 const\ ucl_object_t*\ ucl_iterate_object\ (const\ ucl_object_t\ *obj,\ 
537 \ \ \ \ ucl_object_iter_t\ *iter,\ bool\ expand_values);
538 \f[]
539 .fi
540 .PP
541 This function accept opaque iterator pointer \f[C]iter\f[].
542 In the first call this iterator \f[I]must\f[] be initialized to
543 \f[C]NULL\f[].
544 Iterator is changed by this function call.
545 \f[C]ucl_iterate_object\f[] returns the next UCL object in the compound
546 object \f[C]obj\f[] or \f[C]NULL\f[] if all objects have been iterated.
547 The reference count of the object returned is not increased, so a caller
548 should not unref the object or modify its content (e.g.
549 by inserting to another compound object).
550 The object \f[C]obj\f[] should not be changed during the iteration
551 process as well.
552 \f[C]expand_values\f[] flag speicifies whether
553 \f[C]ucl_iterate_object\f[] should expand keys with multiple values.
554 The general rule is that if you need to iterate throught the
555 \f[I]object\f[] or \f[I]explicit array\f[], then you always need to set
556 this flag to \f[C]true\f[].
557 However, if you get some key in the object and want to extract all its
558 values then you should set \f[C]expand_values\f[] to \f[C]false\f[].
559 Mixing of iteration types are not permitted since the iterator is set
560 according to the iteration type and cannot be reused.
561 Here is an example of iteration over the objects using libucl API
562 (assuming that \f[C]top\f[] is \f[C]UCL_OBJECT\f[] in this example):
563 .IP
564 .nf
565 \f[C]
566 ucl_object_iter_t\ it\ =\ NULL,\ it_obj\ =\ NULL;
567 const\ ucl_object_t\ *cur,\ *tmp;
568
569 /*\ Iterate\ over\ the\ object\ */
570 while\ ((obj\ =\ ucl_iterate_object\ (top,\ &it,\ true)))\ {
571 \ \ \ \ printf\ ("key:\ \\"%s\\"\\n",\ ucl_object_key\ (obj));
572 \ \ \ \ /*\ Iterate\ over\ the\ values\ of\ a\ key\ */
573 \ \ \ \ while\ ((cur\ =\ ucl_iterate_object\ (obj,\ &it_obj,\ false)))\ {
574 \ \ \ \ \ \ \ \ printf\ ("value:\ \\"%s\\"\\n",\ 
575 \ \ \ \ \ \ \ \ \ \ \ \ ucl_object_tostring_forced\ (cur));
576 \ \ \ \ }
577 }
578 \f[]
579 .fi
580 .SH VALIDATION FUNCTIONS
581 .PP
582 Currently, there is only one validation function called
583 \f[C]ucl_object_validate\f[].
584 It performs validation of object using the specified schema.
585 This function is defined as following:
586 .SS ucl_object_validate
587 .IP
588 .nf
589 \f[C]
590 bool\ ucl_object_validate\ (const\ ucl_object_t\ *schema,
591 \ \ \ \ const\ ucl_object_t\ *obj,\ struct\ ucl_schema_error\ *err);
592 \f[]
593 .fi
594 .PP
595 This function uses ucl object \f[C]schema\f[], that must be valid in
596 terms of \f[C]json\-schema\f[] draft v4, to validate input object
597 \f[C]obj\f[].
598 If this function returns \f[C]true\f[] then validation procedure has
599 been succeed.
600 Otherwise, \f[C]false\f[] is returned and \f[C]err\f[] is set to a
601 specific value.
602 If caller set \f[C]err\f[] to NULL then this function does not set any
603 error just returning \f[C]false\f[].
604 Error is the structure defined as following:
605 .IP
606 .nf
607 \f[C]
608 struct\ ucl_schema_error\ {
609 \ \ \ \ enum\ ucl_schema_error_code\ code;\ \ \ \ /*\ error\ code\ */
610 \ \ \ \ char\ msg[128];\ \ \ \ \ \ \ \ \ \ \ \ \ \ /*\ error\ message\ */
611 \ \ \ \ ucl_object_t\ *obj;\ \ \ \ \ \ \ \ \ \ /*\ object\ where\ error\ occured\ */
612 };
613 \f[]
614 .fi
615 .PP
616 Caller may use \f[C]code\f[] field to get a numeric error code:
617 .IP
618 .nf
619 \f[C]
620 enum\ ucl_schema_error_code\ {
621 \ \ \ \ UCL_SCHEMA_OK\ =\ 0,\ \ \ \ \ \ \ \ \ \ /*\ no\ error\ */
622 \ \ \ \ UCL_SCHEMA_TYPE_MISMATCH,\ \ \ /*\ type\ of\ object\ is\ incorrect\ */
623 \ \ \ \ UCL_SCHEMA_INVALID_SCHEMA,\ \ /*\ schema\ is\ invalid\ */
624 \ \ \ \ UCL_SCHEMA_MISSING_PROPERTY,/*\ missing\ properties\ */
625 \ \ \ \ UCL_SCHEMA_CONSTRAINT,\ \ \ \ \ \ /*\ constraint\ found\ */
626 \ \ \ \ UCL_SCHEMA_MISSING_DEPENDENCY,\ /*\ missing\ dependency\ */
627 \ \ \ \ UCL_SCHEMA_UNKNOWN\ \ \ \ \ \ \ \ \ \ /*\ generic\ error\ */
628 };
629 \f[]
630 .fi
631 .PP
632 \f[C]msg\f[] is a stiring description of an error and \f[C]obj\f[] is an
633 object where error has been occurred.
634 Error object is not allocated by libucl, so there is no need to free it
635 after validation (a static object should thus be used).
636 .SH AUTHORS
637 Vsevolod Stakhov <vsevolod@highsecure.ru>.