flux_conf_create(3)
SYNOPSIS
#include <flux/core.h>
flux_conf_t *flux_conf_create (void);
const flux_conf_t *flux_conf_incref (const flux_conf_t *conf);
void flux_conf_decref (const flux_conf_t *conf);
flux_conf_t *flux_conf_copy (const flux_conf_t *conf);
int flux_conf_unpack (const flux_conf_t *conf,
flux_error_t *error,
const char *fmt,
...);
flux_conf_t *flux_conf_pack (const char *fmt, ...);
flux_conf_t *flux_conf_parse (const char *path, flux_error_t *error);
int flux_conf_update (flux_conf_t *conf,
const char *value,
flux_error_t *error);
Link with -lflux-core.
DESCRIPTION
Flux configuration is represented by a flux_conf_t object.
flux_conf_create() creates an empty object with a reference
count of one.
flux_conf_incref() increments the object reference count.
flux_conf_decref() decrements the object reference count
and destroys it when the count reaches zero.
flux_conf_copy() duplicates an object.
flux_conf_unpack() unpacks an object using Jansson
json_unpack() style arguments.
flux_conf_pack() creates an object using Jansson
json_pack() style arguments.
flux_conf_parse() parse a TOML configuration file at path
and creates a config object that contains the result.
flux_conf_update() updates conf in place from value.
The format of value is determined as follows:
KEY=VALIf
valuecontains=, set the configuration key at the dotted pathKEYtoVAL.VALis parsed as JSON; if it is not valid JSON, it is treated as a plain string. Note: file paths containing=are interpreted as KEY=VAL rather than as file names.- inline JSON object
If
valuestarts with{, it is parsed as an inline JSON object and merged intoconf.- inline TOML string
If
valuecontains a newline (and does not start with{), it is parsed as an inline TOML string and merged intoconf.- path ending in
.json Parse the file at
valueas JSON and merge the result intoconf.- any other string
Treated as a path to a TOML file.
ENCODING JSON PAYLOADS
Flux API functions that are based on Jansson's json_pack()
accept the following tokens in their format string.
The type in parenthesis denotes the resulting JSON type, and
the type in brackets (if any) denotes the C type that is expected as
the corresponding argument or arguments.
- s (string)['const char *']
Convert a null terminated UTF-8 string to a JSON string.
- s? (string)['const char *']
Like s, but if the argument is NULL, outputs a JSON null value.
- s* (string) ['const char *']
Like s, but if the argument is NULL, do not output any value. This format can only be used inside an object or an array. If used inside an object, the corresponding key is additionally suppressed when the value is omitted.
- s# (string)['const char *', 'int']
Convert a UTF-8 buffer of a given length to a JSON string.
- s% (string)['const char *', 'size_t']
Like s# but the length argument is of type size_t.
- + ['const char *']
Like s, but concatenate to the previous string. Only valid after a string.
- +# ['const char *', 'int']
Like s#, but concatenate to the previous string. Only valid after a string.
- +% ['const char *', 'size_t']
Like +#, but the length argument is of type size_t.
- n (null)
Output a JSON null value. No argument is consumed.
- b (boolean)['int']
Convert a C int to JSON boolean value. Zero is converted to false and non-zero to true.
- i (integer)['int']
Convert a C int to JSON integer.
- I (integer)['int64_t']
Convert a C int64_t to JSON integer. Note: Jansson expects a json_int_t here without committing to a size, but Flux guarantees that this is a 64-bit integer.
- f (real)['double']
Convert a C double to JSON real.
- o (any value)['json_t *']
Output any given JSON value as-is. If the value is added to an array or object, the reference to the value passed to o is stolen by the container.
- O (any value)['json_t *']
Like o, but the argument's reference count is incremented. This is useful if you pack into an array or object and want to keep the reference for the JSON value consumed by O to yourself.
- o?, O? (any value)['json_t *']
Like o and O, respectively, but if the argument is NULL, output a JSON null value.
- o*, O* (any value) ['json_t *']
Like o and O, respectively, but if the argument is NULL, do not output any value. This format can only be used inside an object or an array. If used inside an object, the corresponding key is additionally suppressed.
- [fmt] (array)
Build an array with contents from the inner format string. fmt may contain objects and arrays, i.e. recursive value building is supported.
- {fmt} (object)
Build an object with contents from the inner format string fmt. The first, third, etc. format specifier represent a key, and must be a string as object keys are always strings. The second, fourth, etc. format specifier represent a value. Any value may be an object or array, i.e. recursive value building is supported.
Whitespace, : (colon) and , (comma) are ignored.
These descriptions came from the Jansson 2.11 manual.
See also: Jansson API: Building Values: http://jansson.readthedocs.io/en/2.11/apiref.html#building-values
DECODING JSON PAYLOADS
Flux API functions that are based on Jansson's json_unpack()
accept the following tokens in their format string.
The type in parenthesis denotes the resulting JSON type, and
the type in brackets (if any) denotes the C type that is expected as
the corresponding argument or arguments.
- s (string)['const char *']
Convert a JSON string to a pointer to a null terminated UTF-8 string. The resulting string is extracted by using 'json_string_value()' internally, so it exists as long as there are still references to the corresponding JSON string.
- s% (string)['const char *', 'size_t']
Convert a JSON string to a pointer to a null terminated UTF-8 string and its length.
- n (null)
Expect a JSON null value. Nothing is extracted.
- b (boolean)['int']
Convert a JSON boolean value to a C int, so that true is converted to 1 and false to 0.
- i (integer)['int']
Convert a JSON integer to a C int.
- I (integer)['int64_t']
Convert a JSON integer to a C int64_t. Note: Jansson expects a json_int_t here without committing to a size, but Flux guarantees that this is a 64-bit integer.
- f (real)['double']
Convert JSON real to a C double.
- F (real)['double']
Convert JSON number (integer or real) to a C double.
- o (any value)['json_t *']
Store a JSON value, with no conversion, to a json_t pointer.
- O (any value)['json_t *']
Like o, but the JSON value's reference count is incremented. Storage pointers should be initialized NULL before using unpack. The caller is responsible for releasing all references incremented by unpack, even when an error occurs.
- [fmt] (array)
Convert each item in the JSON array according to the inner format string. fmt may contain objects and arrays, i.e. recursive value extraction is supported.
- {fmt} (object)
Convert each item in the JSON object according to the inner format string fmt. The first, third, etc. format specifier represents a key, and must be s. The corresponding argument to unpack functions is read as the object key. The second, fourth, etc. format specifier represents a value and is written to the address given as the corresponding argument. Note that every other argument is read from and every other is written to. fmt may contain objects and arrays as values, i.e. recursive value extraction is supported. Any s representing a key may be suffixed with ? to make the key optional. If the key is not found, nothing is extracted.
- !
This special format specifier is used to enable the check that all object and array items are accessed, on a per-value basis. It must appear inside an array or object as the last format specifier before the closing bracket or brace.
Whitespace, : (colon) and , (comma) are ignored.
These descriptions came from the Jansson 2.11 manual.
See also: Jansson API: Parsing and Validating Values: http://jansson.readthedocs.io/en/2.11/apiref.html#parsing-and-validating-values
RETURN VALUE
flux_conf_create(), flux_conf_copy(), flux_conf_pack(),
and flux_conf_incref() return a flux_conf_t object on success.
On error, NULL is returned, and errno is set.
flux_conf_unpack() returns 0 on success, or -1 on failure with
errno set.
flux_conf_parse() returns a flux_conf_t object on success.
On error, NULL is returned, errno is set, and if error is
non-NULL, it is filled with a human readable error message.
flux_conf_update() returns 0 on success. On error, it returns -1,
errno is set, and if error is non-NULL, it is filled with
a human readable error message.
ERRORS
- EINVAL
Invalid argument.
- ENOMEM
Out of memory.
RESOURCES
Flux: http://flux-framework.org
Flux RFC: https://flux-framework.readthedocs.io/projects/flux-rfc
Issue Tracker: https://github.com/flux-framework/flux-core/issues
TOML: Tom's Oblivious, Minimal Language https://github.com/toml-lang/toml