libyang  3.4.2
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Plugins: Types
Collaboration diagram for Plugins: Types:

Modules

 Plugins: Binary built-in type callbacks
 
 Plugins: Bits built-in type callbacks
 
 Plugins: Boolean built-in type callbacks
 
 Plugins: Decimal64 built-in type callbacks
 
 Plugins: Empty built-in type callbacks
 
 Plugins: Enumeration built-in type callbacks
 
 Plugins: Identityref built-in type callbacks
 
 Plugins: Instance-identifier built-in type callbacks
 
 Plugins: Integer built-in types callbacks
 
 Plugins: Leafref built-in type callbacks
 
 Plugins: Simple Types Callbacks
 
 Plugins: String built-in type callbacks
 
 Plugins: Type store callback options.
 
 Plugins: Union built-in type callbacks
 
 Plugins: xpath1.0 `ietf-yang-types` type callbacks
 

Data Structures

struct  lyplg_type
 Hold type-specific functions for various operations with the data values. More...
 
struct  lyplg_type_record
 

Macros

#define LYPLG_TYPE_API_VERSION   2
 Type API version. More...
 
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)   do { if (LYPLG_TYPE_VAL_IS_DYN(type_val)) free(type_val); } while(0)
 Destroy a prepared value. More...
 
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
 Prepare value memory for storing a specific type value, may be allocated dynamically. More...
 
#define LYPLG_TYPE_VAL_IS_DYN(type_val)   (sizeof *(type_val) > LYD_VALUE_FIXED_MEM_SIZE)
 Check whether specific type value needs to be allocated dynamically. More...
 
#define LYPLG_TYPES
 Macro to define plugin information in external plugins. More...
 

Typedefs

typedef LY_ERR(* lyplg_type_compare_clb )(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
 Callback for comparing 2 values of the same type. More...
 
typedef LY_ERR(* lyplg_type_dup_clb )(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
 Callback to duplicate data in the data structure. More...
 
typedef void(* lyplg_type_free_clb )(const struct ly_ctx *ctx, struct lyd_value *value)
 Callback for freeing the user type values stored by lyplg_type_store_clb. More...
 
typedef const void *(* lyplg_type_print_clb )(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len)
 Callback for getting the value of the data stored in value. More...
 
typedef int(* lyplg_type_sort_clb )(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
 Callback for sorting values. More...
 

Functions

LIBYANG_API_DECL LY_ERR
LIBYANG_API_DECL void 
ly_err_free (void *ptr)
 Destructor for the error records created with ly_err_new(). More...
 
LIBYANG_API_DECL LY_ERR ly_err_new (struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *data_path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
 Create and fill error structure. More...
 
LIBYANG_API_DECL size_t lyplg_type_bits_bitmap_size (const struct lysc_type_bits *type)
 Get the bitmap size of a bits value bitmap. More...
 
LIBYANG_API_DECL ly_bool lyplg_type_bits_is_bit_set (const char *bitmap, size_t size, uint32_t bit_position)
 Check whether a particular bit of a bitmap is set. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints (uint32_t hints, const char *value, size_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
 Check that the type is suitable for the parser's hints (if any) in the specified format. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_check_status (const struct lysc_node *ctx_node, uint16_t val_flags, LY_VALUE_FORMAT format, void *prefix_data, const char *val_name, struct ly_err_item **err)
 Check that the value of a type is allowed based on its status. More...
 
LIBYANG_API_DECL const char * lyplg_type_get_prefix (const struct lys_module *mod, LY_VALUE_FORMAT format, void *prefix_data)
 Get format-specific prefix for a module. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_identity_isderived (const struct lysc_ident *base, const struct lysc_ident *derived)
 Decide if the derived identity is derived from (based on) the base identity. More...
 
LIBYANG_API_DECL struct
lys_module
lyplg_type_identity_module (const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *prefix, size_t prefix_len, LY_VALUE_FORMAT format, const void *prefix_data)
 Get the corresponding module for the identity value. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_check_status (const struct lysc_node *ctx_node, const struct ly_path *path, LY_VALUE_FORMAT format, void *prefix_data, struct ly_err_item **err)
 Check that the lypath instance-identifier value is allowed based on the status of the nodes. More...
 
LIBYANG_API_DECL void lyplg_type_lypath_free (const struct ly_ctx *ctx, struct ly_path *path)
 Free ly_path structure used by instanceid value representation. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_new (const struct ly_ctx *ctx, const char *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, const struct lysc_node *ctx_node, struct lys_glob_unres *unres, struct ly_path **path, struct ly_err_item **err)
 Helper function to create internal schema path representation for instance-identifier value representation. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_make_implemented (struct lys_module *mod, const char **features, struct lys_glob_unres *unres)
 Implement a module (just like lys_set_implemented()), but keep maintaining unresolved items. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_parse_dec64 (uint8_t fraction_digits, const char *value, size_t value_len, int64_t *ret, struct ly_err_item **err)
 Convert a string with a decimal64 value into libyang representation: ret = value * 10^fraction-digits. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_parse_int (const char *datatype, int base, int64_t min, int64_t max, const char *value, size_t value_len, int64_t *ret, struct ly_err_item **err)
 Unsigned integer value parser and validator. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_parse_uint (const char *datatype, int base, uint64_t max, const char *value, size_t value_len, uint64_t *ret, struct ly_err_item **err)
 Unsigned integer value parser and validator. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_prefix_data_dup (const struct ly_ctx *ctx, LY_VALUE_FORMAT format, const void *orig, void **dup)
 Duplicate prefix data. More...
 
LIBYANG_API_DECL void lyplg_type_prefix_data_free (LY_VALUE_FORMAT format, void *prefix_data)
 Free internal prefix data. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_prefix_data_new (const struct ly_ctx *ctx, const void *value, size_t value_len, LY_VALUE_FORMAT format, const void *prefix_data, LY_VALUE_FORMAT *format_p, void **prefix_data_p)
 Store used prefixes in a string into an internal libyang structure used in lyd_value. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_print_xpath10_value (const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data, char **str_value, struct ly_err_item **err)
 Print xpath1.0 value in the specific format. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_resolve_leafref (const struct lysc_type_leafref *lref, const struct lyd_node *node, struct lyd_value *value, const struct lyd_node *tree, struct ly_set **targets, char **errmsg)
 Find leafref target in data. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns (struct lysc_pattern **patterns, const char *str, size_t str_len, struct ly_err_item **err)
 Data type validator for pattern-restricted string values. More...
 
LIBYANG_API_DECL LY_ERR lyplg_type_validate_range (LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval, size_t strval_len, struct ly_err_item **err)
 Data type validator for a range/length-restricted values. More...
 
LIBYANG_API_DEF LY_ERR lyplg_type_xpath10_print_token (const char *token, uint16_t tok_len, ly_bool is_nametest, const struct lys_module **context_mod, const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data, LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, struct ly_err_item **err)
 Print xpath1.0 token in the specific format. More...
 

Variables

LIBYANG_API_DECL typedef LY_ERR(* lyplg_type_store_clb )(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, struct lyd_value *storage, struct lys_glob_unres *unres, struct ly_err_item **err)
 Callback to store the given value according to the given type. More...
 
LIBYANG_API_DECL typedef LY_ERR(* lyplg_type_validate_clb )(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err)
 Callback to validate the stored value in the accessible data tree. More...
 

Detailed Description

Structures and functions to for libyang plugins implementing specific YANG types defined in YANG modules. For more information, see Type Plugins.

This part of libyang API is available by including <libyang/plugins_types.h> header file.


Data Structure Documentation

struct lyplg_type

Hold type-specific functions for various operations with the data values.

libyang includes set of plugins for all the built-in types. They are, by default, inherited to the derived types. However, if the user type plugin for the specific type is loaded, the plugin can provide it's own functions. The built-in types plugin callbacks are public, so even the user type plugins can use them to do part of their own functionality.

Definition at line 625 of file plugins_types.h.

Data Fields
lyplg_type_compare_clb compare

comparison callback to compare 2 values of the same type

lyplg_type_dup_clb duplicate

data duplication callback

lyplg_type_free_clb free

optional function to free the type-spceific way stored value

const char * id

Plugin identification (mainly for distinguish incompatible versions when used by external tools)

int32_t lyb_data_len

Length of the data in LYB format. For variable-length is set to -1.

lyplg_type_print_clb print

printer callback to get string representing the value

lyplg_type_sort_clb sort

comparison callback for sorting values

lyplg_type_store_clb store

store and canonize the value in the type-specific way

lyplg_type_validate_clb validate

optional, validate the value in the accessible data tree

struct lyplg_type_record

Definition at line 639 of file plugins_types.h.

Data Fields
const char * module

name of the module where the type is defined (top-level typedef)

const char * name

name of the typedef

struct lyplg_type plugin

data to utilize plugin implementation

const char * revision

optional module revision - if not specified, the plugin applies to any revision, which is not an optimal approach due to a possible future revisions of the module. Instead, there should be defined multiple items in the plugins list, each with the different revision, but all with the same pointer to the plugin functions. The only valid use case for the NULL revision is the case the module has no revision.

Macro Definition Documentation

#define LYPLG_TYPE_API_VERSION   2

Type API version.

Definition at line 165 of file plugins_types.h.

#define LYPLG_TYPE_VAL_INLINE_DESTROY (   type_val)    do { if (LYPLG_TYPE_VAL_IS_DYN(type_val)) free(type_val); } while(0)

Destroy a prepared value.

Must be called for values prepared with LYPLG_TYPE_VAL_INLINE_PREPARE.

Parameters
[in]type_valPointer to specific type value structure.

Definition at line 206 of file plugins_types.h.

#define LYPLG_TYPE_VAL_INLINE_PREPARE (   storage,
  type_val 
)
Value:
? ((type_val) = ((storage)->dyn_mem = calloc(1, sizeof *(type_val)))) \
: ((type_val) = memset((storage)->fixed_mem, 0, sizeof *(type_val))))
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
#define LYPLG_TYPE_VAL_IS_DYN(type_val)
Check whether specific type value needs to be allocated dynamically.

Prepare value memory for storing a specific type value, may be allocated dynamically.

Must be called for values larger than 8 bytes. To be used in lyplg_type_store_clb.

Parameters
[in]storagePointer to the value storage to use (struct lyd_value *).
[in,out]type_valPointer to specific type value structure.

Definition at line 194 of file plugins_types.h.

#define LYPLG_TYPE_VAL_IS_DYN (   type_val)    (sizeof *(type_val) > LYD_VALUE_FIXED_MEM_SIZE)

Check whether specific type value needs to be allocated dynamically.

Parameters
[in]type_valPointer to specific type value storage.

Definition at line 182 of file plugins_types.h.

#define LYPLG_TYPES
Value:
uint32_t plugins_types_apiver__ = LYPLG_TYPE_API_VERSION; \
const struct lyplg_type_record plugins_types__[]
#define LYPLG_TYPE_API_VERSION
Type API version.

Macro to define plugin information in external plugins.

Use as follows: LYPLG_TYPES = {{<filled information of lyplg_type_record>}, ..., {0}};

Definition at line 173 of file plugins_types.h.

Typedef Documentation

typedef LY_ERR(* lyplg_type_compare_clb)(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)

Callback for comparing 2 values of the same type.

It can be assumed that the same context (dictionary) was used for storing both values and the realtype member of both the values is the same.

Parameters
[in]ctxlibyang context.
[in]val1First value to compare.
[in]val2Second value to compare.
Returns
LY_SUCCESS if values are considered equal.
LY_ENOT if values differ.

Definition at line 554 of file plugins_types.h.

typedef LY_ERR(* lyplg_type_dup_clb)(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)

Callback to duplicate data in the data structure.

Parameters
[in]ctxlibyang context of the original and dup.
[in]originalOriginal data structure to be duplicated.
[in,out]dupPrepared data structure to be filled with the duplicated data of original.
Returns
LY_SUCCESS after successful duplication.
LY_ERR value on error.

Definition at line 605 of file plugins_types.h.

typedef void(* lyplg_type_free_clb)(const struct ly_ctx *ctx, struct lyd_value *value)

Callback for freeing the user type values stored by lyplg_type_store_clb.

Note that this callback is responsible also for freeing the canonized member in the value.

Parameters
[in]ctxlibyang ctx to enable correct manipulation with values that are in the dictionary.
[in,out]valueValue structure to free the data stored there by the plugin's lyplg_type_store_clb callback

Definition at line 615 of file plugins_types.h.

typedef const void*(* lyplg_type_print_clb)(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len)

Callback for getting the value of the data stored in value.

Canonical value (format of LY_VALUE_CANON) must always be a zero-terminated const string stored in the dictionary. The lyd_value._canonical member should be used for storing (caching) it.

Parameters
[in]ctxlibyang context for storing the canonical value. May not be set for LY_VALUE_LYB format.
[in]valueValue to print.
[in]formatFormat in which the data are supposed to be printed. Formats LY_VALUE_SCHEMA and LY_VALUE_SCHEMA_RESOLVED are not supported and should not be implemented.
[in]prefix_dataFormat-specific data for processing prefixes. In case of using one of the built-in's print callback (or lyplg_type_print_simple()), the argument is just simply passed in. If you need to handle prefixes in the value on your own, there is lyplg_type_get_prefix() function to help.
[out]dynamicFlag if the returned value is dynamically allocated. In such a case the caller is responsible for freeing it. Will not be set and should be ignored for format LY_VALUE_CANON.
[out]value_lenOptional returned value length in bytes. For strings it EXCLUDES the terminating zero.
Returns
Pointer to value in the specified format. According to the returned dynamic flag, caller can be responsible for freeing allocated memory.
NULL in case of error.

Definition at line 593 of file plugins_types.h.

typedef int(* lyplg_type_sort_clb)(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)

Callback for sorting values.

It can be assumed that the same context (dictionary) was used for storing both values and the realtype member of both the values is the same.

Parameters
[in]ctxlibyang context.
[in]val1First value to compare.
[in]val2Second value to compare.
Returns
Negative number if val1 < val2,
Zero if val1 == val2,
Positive number if val1 > val2.

Definition at line 570 of file plugins_types.h.

Function Documentation

LIBYANG_API_DECL LY_ERR LIBYANG_API_DECL void ly_err_free ( void *  ptr)

Destructor for the error records created with ly_err_new().

Compatible with the free(), so usable as a generic callback.

Parameters
[in]ptrError record (ly_err_item, the void pointer is here only for compatibility with a generic free() function) to free. With the record, also all the records (if any) connected after this one are freed.
LIBYANG_API_DECL LY_ERR ly_err_new ( struct ly_err_item **  err,
LY_ERR  ecode,
LY_VECODE  vecode,
char *  data_path,
char *  apptag,
const char *  err_format,
  ... 
)

Create and fill error structure.

Helper function for various plugin functions to generate error information structure.

Parameters
[in,out]errPointer to store a new error structure filled according to the input parameters. If the storage already contains error information, the new record is appended into the errors list.
[in]ecodeCode of the error to fill. In case LY_SUCCESS value, nothing is done and LY_SUCCESS is returned.
[in]vecodeValidity error code in case of LY_EVALID error code.
[in]data_pathPath to the data node causing the error.
[in]apptagError-app-tag value.
[in]err_formatFormat string (same like at printf) or string literal. If you want to print just an unknown string, use "%s" for the err_format, otherwise undefined behavior may occur because the unknown string may contain the % character, which is interpreted as conversion specifier.
Returns
The given ecode value if the err is successfully created. The structure can be freed using ly_err_free() or passed back from callback into libyang.
LY_EMEM If there is not enough memory for allocating error record, the err is not touched in that case.
LY_SUCCESS if ecode is LY_SUCCESS, the err is not touched in this case.
LIBYANG_API_DECL size_t lyplg_type_bits_bitmap_size ( const struct lysc_type_bits type)

Get the bitmap size of a bits value bitmap.

Bitmap size is rounded up to the smallest integer size (1, 2, 4, or 8 bytes). If more than 8 bytes are needed to hold all the bit positions, no rounding is performed.

Parameters
[in]typeBits type.
Returns
Bitmap size in bytes.

Definition at line 55 of file bits.c.

LIBYANG_API_DECL ly_bool lyplg_type_bits_is_bit_set ( const char *  bitmap,
size_t  size,
uint32_t  bit_position 
)

Check whether a particular bit of a bitmap is set.

Parameters
[in]bitmapBitmap to read from.
[in]sizeSize of bitmap.
[in]bit_positionBit position to check.
Returns
Whether the bit is set or not.

Definition at line 83 of file bits.c.

LIBYANG_API_DECL LY_ERR lyplg_type_check_hints ( uint32_t  hints,
const char *  value,
size_t  value_len,
LY_DATA_TYPE  type,
int base,
struct ly_err_item **  err 
)

Check that the type is suitable for the parser's hints (if any) in the specified format.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

Parameters
[in]hintsBitmap of value hints of all the allowed value types provided by parsers to lyplg_type_store_clb.
[in]valueLexical representation of the value to be stored.
[in]value_lenLength (number of bytes) of the given value.
[in]typeExpected base type of the value by the caller.
[out]basePointer to store the numeric base for parsing numeric values using strtol()/strtoll() function. Returned (and required) only for numeric type values.
[out]errPointer to store error information in case of failure.
Returns
LY_ERR value
LIBYANG_API_DECL LY_ERR lyplg_type_check_status ( const struct lysc_node ctx_node,
uint16_t  val_flags,
LY_VALUE_FORMAT  format,
void *  prefix_data,
const char *  val_name,
struct ly_err_item **  err 
)

Check that the value of a type is allowed based on its status.

Parameters
[in]ctx_nodeContext node (which references the value).
[in]val_flagsFlags fo the value.
[in]formatFormat of the value.
[in]prefix_dataPrefix data of the value.
[in]val_nameName of the value, only for logging.
[out]errPointer to store error information in case of failure.
Returns
LY_ERR value.
LIBYANG_API_DECL const char* lyplg_type_get_prefix ( const struct lys_module mod,
LY_VALUE_FORMAT  format,
void *  prefix_data 
)

Get format-specific prefix for a module.

Use only in implementations of lyplg_type_print_clb which provide all the necessary parameters for this function.

Parameters
[in]modModule whose prefix to get - the module somehow connected with the value to print.
[in]formatFormat of the prefix (lyplg_type_print_clb's format parameter).
[in]prefix_dataFormat-specific data (lyplg_type_print_clb's prefix_data parameter).
Returns
Module prefix to print.
NULL on using the current module/namespace.
LIBYANG_API_DECL LY_ERR lyplg_type_identity_isderived ( const struct lysc_ident base,
const struct lysc_ident derived 
)

Decide if the derived identity is derived from (based on) the base identity.

Parameters
[in]baseExpected base identity.
[in]derivedExpected derived identity.
Returns
LY_SUCCESS if derived IS based on the base identity.
LY_ENOTFOUND if derived IS NOT not based on the base identity.
LIBYANG_API_DECL struct lys_module* lyplg_type_identity_module ( const struct ly_ctx ctx,
const struct lysc_node ctx_node,
const char *  prefix,
size_t  prefix_len,
LY_VALUE_FORMAT  format,
const void *  prefix_data 
)

Get the corresponding module for the identity value.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

Parameters
[in]ctxlibyang context.
[in]ctx_nodeSchema node where the value is instantiated to determine the module in case of unprefixed value in specific format.
[in]prefixPrefix to resolve - identified beginning of a prefix in lyplg_type_store_clb's value parameter. If NULL, an unprefixed identity is resolved.
[in]prefix_lenLength of prefix.
[in]formatFormat of the prefix (lyplg_type_store_clb's format parameter).
[in]prefix_dataFormat-specific data (lyplg_type_store_clb's prefix_data parameter).
Returns
Resolved prefix module,
NULL otherwise.
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_check_status ( const struct lysc_node ctx_node,
const struct ly_path *  path,
LY_VALUE_FORMAT  format,
void *  prefix_data,
struct ly_err_item **  err 
)

Check that the lypath instance-identifier value is allowed based on the status of the nodes.

Parameters
[in]ctx_nodeContext node (which references the value).
[in]pathPath of the instance-identifier.
[in]formatFormat of the value.
[in]prefix_dataPrefix data of the value.
[out]errPointer to store error information in case of failure.
Returns
LY_ERR value.
LIBYANG_API_DECL void lyplg_type_lypath_free ( const struct ly_ctx ctx,
struct ly_path *  path 
)

Free ly_path structure used by instanceid value representation.

The ly_path representation can be created by lyplg_type_lypath_new().

Parameters
[in]ctxlibyang context.
[in]pathThe structure (sized array) to free.
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_new ( const struct ly_ctx ctx,
const char *  value,
size_t  value_len,
uint32_t  options,
LY_VALUE_FORMAT  format,
void *  prefix_data,
const struct lysc_node ctx_node,
struct lys_glob_unres *  unres,
struct ly_path **  path,
struct ly_err_item **  err 
)

Helper function to create internal schema path representation for instance-identifier value representation.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

Parameters
[in]ctxlibyang Context
[in]valueLexical representation of the value to be stored.
[in]value_lenLength (number of bytes) of the given value.
[in]optionsType plugin store options.
[in]formatInput format of the value.
[in]prefix_dataFormat-specific data for resolving any prefixes (see ly_resolve_prefix()).
[in]ctx_nodeThe value schema context node.
[in,out]unresGlobal unres structure for newly implemented modules.
[out]pathPointer to store the created structure representing the schema path from the value.
[out]errPointer to store the error information provided in case of failure.
Returns
LY_SUCCESS on success,
LY_ERECOMPILE if the context need to be recompiled, should be returned.
LY_ERR value on error.
LIBYANG_API_DECL LY_ERR lyplg_type_make_implemented ( struct lys_module mod,
const char **  features,
struct lys_glob_unres *  unres 
)

Implement a module (just like lys_set_implemented()), but keep maintaining unresolved items.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

Parameters
[in]modModule to implement.
[in]featuresArray of features to enable.
[in,out]unresGlobal unres to add to.
Returns
LY_ERECOMPILE if the context need to be recompiled, should be returned.
LY_ERR value.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_dec64 ( uint8_t  fraction_digits,
const char *  value,
size_t  value_len,
int64_t *  ret,
struct ly_err_item **  err 
)

Convert a string with a decimal64 value into libyang representation: ret = value * 10^fraction-digits.

Parameters
[in]fraction_digitsFraction-digits of the decimal64 type.
[in]valueValue string to parse.
[in]value_lenLength of the value (mandatory parameter).
[out]retParsed decimal64 value representing original value * 10^fraction-digits (optional).
[out]errError information in case of failure. The error structure can be freed by ly_err_free().
Returns
LY_ERR value according to the result of the parsing and validation.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_int ( const char *  datatype,
int  base,
int64_t  min,
int64_t  max,
const char *  value,
size_t  value_len,
int64_t *  ret,
struct ly_err_item **  err 
)

Unsigned integer value parser and validator.

Parameters
[in]datatypeType of the integer for logging.
[in]baseBase of the integer's lexical representation. In case of built-in types, data must be represented in decimal format (base 10), but default values in schemas can be represented also as hexadecimal or octal values (base 0).
[in]minLower bound of the type.
[in]maxUpper bound of the type.
[in]valueValue string to parse.
[in]value_lenLength of the value (mandatory parameter).
[out]retParsed integer value (optional).
[out]errError information in case of failure. The error structure can be freed by ly_err_free().
Returns
LY_ERR value according to the result of the parsing and validation.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_uint ( const char *  datatype,
int  base,
uint64_t  max,
const char *  value,
size_t  value_len,
uint64_t *  ret,
struct ly_err_item **  err 
)

Unsigned integer value parser and validator.

Parameters
[in]datatypeType of the unsigned integer for logging.
[in]baseBase of the integer's lexical representation. In case of built-in types, data must be represented in decimal format (base 10), but default values in schemas can be represented also as hexadecimal or octal values (base 0).
[in]maxUpper bound of the type.
[in]valueValue string to parse.
[in]value_lenLength of the value (mandatory parameter).
[out]retParsed unsigned integer value (optional).
[out]errError information in case of failure. The error structure can be freed by ly_err_free().
Returns
LY_ERR value according to the result of the parsing and validation.
LIBYANG_API_DECL LY_ERR lyplg_type_prefix_data_dup ( const struct ly_ctx ctx,
LY_VALUE_FORMAT  format,
const void *  orig,
void **  dup 
)

Duplicate prefix data.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

Parameters
[in]ctxlibyang context.
[in]formatFormat of the prefixes in the value.
[in]origPrefix data to duplicate.
[out]dupDuplicated prefix data.
Returns
LY_ERR value.
LIBYANG_API_DECL void lyplg_type_prefix_data_free ( LY_VALUE_FORMAT  format,
void *  prefix_data 
)

Free internal prefix data.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

Parameters
[in]formatFormat of the prefixes.
[in]prefix_dataFormat-specific data to free.
LIBYANG_API_DECL LY_ERR lyplg_type_prefix_data_new ( const struct ly_ctx ctx,
const void *  value,
size_t  value_len,
LY_VALUE_FORMAT  format,
const void *  prefix_data,
LY_VALUE_FORMAT format_p,
void **  prefix_data_p 
)

Store used prefixes in a string into an internal libyang structure used in lyd_value.

Use only in implementations of lyplg_type_store_clb which provide all the necessary parameters for this function.

If prefix_data_p are non-NULL, they are treated as valid according to the format_p and new possible prefixes are simply added. This way it is possible to store prefix data for several strings together.

Parameters
[in]ctxlibyang context.
[in]valueValue to be parsed.
[in]value_lenLength of value.
[in]formatFormat of the prefixes in the value.
[in]prefix_dataFormat-specific data for resolving any prefixes (see ly_resolve_prefix()).
[in,out]format_pResulting format of the prefixes.
[in,out]prefix_data_pResulting prefix data for the value in format format_p.
Returns
LY_ERR value.
LIBYANG_API_DECL LY_ERR lyplg_type_print_xpath10_value ( const struct lyd_value_xpath10 xp_val,
LY_VALUE_FORMAT  format,
void *  prefix_data,
char **  str_value,
struct ly_err_item **  err 
)

Print xpath1.0 value in the specific format.

Parameters
[in]xp_valxpath1.0 value structure.
[in]formatFormat to print in.
[in]prefix_dataFormat-specific prefix data.
[out]str_valuePrinted value.
[out]errError structure on error.
Returns
LY_ERR value.

Definition at line 213 of file xpath1.0.c.

LIBYANG_API_DECL LY_ERR lyplg_type_resolve_leafref ( const struct lysc_type_leafref lref,
const struct lyd_node node,
struct lyd_value value,
const struct lyd_node tree,
struct ly_set **  targets,
char **  errmsg 
)

Find leafref target in data.

Parameters
[in]lrefLeafref type.
[in]nodeContext node.
[in]valueTarget value.
[in]treeFull data tree to search in.
[out]targetsPointer to set of target nodes, optional.
[out]errmsgError message in case of error.
Returns
LY_ERR value.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns ( struct lysc_pattern **  patterns,
const char *  str,
size_t  str_len,
struct ly_err_item **  err 
)

Data type validator for pattern-restricted string values.

Parameters
[in]patterns(Sized array) of the compiled list of pointers to the pattern restrictions. The array can be found in the lysc_type_str.patterns structure.
[in]strString to validate.
[in]str_lenLength (number of bytes) of the string to validate (mandatory).
[out]errError information in case of failure or non-matching str. The error structure can be freed by ly_err_free().
Returns
LY_SUCCESS when matches all the patterns.
LY_EVALID when does not match any of the patterns.
LY_ESYS in case of PCRE2 error.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_range ( LY_DATA_TYPE  basetype,
struct lysc_range range,
int64_t  value,
const char *  strval,
size_t  strval_len,
struct ly_err_item **  err 
)

Data type validator for a range/length-restricted values.

Parameters
[in]basetypeBase built-in type of the type with the range specified to get know if the range structure represents range or length restriction.
[in]rangeRange (length) restriction information.
[in]valueValue to check. In case of basetypes using unsigned integer values, the value is actually cast to uint64_t.
[in]strvalString representation of the value for error logging.
[in]strval_lenLength of strval.
[out]errError information in case of failure. The error structure can be freed by ly_err_free().
Returns
LY_ERR value according to the result of the validation.
LIBYANG_API_DEF LY_ERR lyplg_type_xpath10_print_token ( const char *  token,
uint16_t  tok_len,
ly_bool  is_nametest,
const struct lys_module **  context_mod,
const struct ly_ctx resolve_ctx,
LY_VALUE_FORMAT  resolve_format,
const void *  resolve_prefix_data,
LY_VALUE_FORMAT  get_format,
void *  get_prefix_data,
char **  token_p,
struct ly_err_item **  err 
)

Print xpath1.0 token in the specific format.

Parameters
[in]tokenToken to transform.
[in]tok_lenLenghth of token.
[in]is_nametestWhether the token is a nametest, it then always requires a prefix in XML get_format.
[in,out]context_modCurrent context module, may be updated.
[in]resolve_ctxContext to use for resolving prefixes.
[in]resolve_formatFormat of the resolved prefixes.
[in]resolve_prefix_dataResolved prefixes prefix data.
[in]get_formatFormat of the output prefixes.
[in]get_prefix_dataFormat-specific prefix data for the output.
[out]token_pPrinted token.
[out]errError structure on error.
Returns
LY_ERR value.

Definition at line 41 of file xpath1.0.c.

Variable Documentation

LIBYANG_API_DECL typedef LY_ERR(* lyplg_type_store_clb)(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, struct lyd_value *storage, struct lys_glob_unres *unres, struct ly_err_item **err)

Callback to store the given value according to the given type.

plugintypestoreopts Value must always be correctly stored meaning all the other type callbacks (such as print or compare) must function as expected. However, lyd_value._canonical can be left NULL and will be generated and stored on-demand. But if format is LY_VALUE_CANON (or another, which must be equal to the canonical value), the canonical value should be stored so that it does not have to be generated later.

Note that the value is not necessarily used whole (may not be zero-terminated if a string). The provided value_len is always correct. All store functions have to free a dynamically allocated value in all cases (even on error).

No unnecessary validation tasks should be performed by this callback and left for lyplg_type_validate_clb instead.

Parameters
[in]ctxlibyang context.
[in]typeType of the value being stored.
[in]valueValue to be stored.
[in]value_lenLength (number of bytes) of the given value.
[in]optionsType plugin store options.
[in]formatInput format of the value, see the description for details.
[in]prefix_dataFormat-specific data for resolving any prefixes (see ly_resolve_prefix()).
[in]hintsBitmap of value hints of all the allowed value types.
[in]ctx_nodeSchema context node of value, may be NULL for metadata.
[out]storageStorage for the value in the type's specific encoding. Except for canonical, all the members should be filled by the plugin (if it fills them at all).
[in,out]unresGlobal unres structure for newly implemented modules.
[out]errOptionally provided error information in case of failure. If not provided to the caller, a generic error message is prepared instead. The error structure can be created by ly_err_new().
Returns
LY_SUCCESS on success,
LY_EINCOMPLETE in case the lyplg_type_validate_clb should be called to finish value validation in data,
LY_ERR value on error, storage must not have any pointers to dynamic memory.

Definition at line 519 of file plugins_types.h.

LIBYANG_API_DECL typedef LY_ERR(* lyplg_type_validate_clb)(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err)

Callback to validate the stored value in the accessible data tree.

This callback is optional and may not be defined for types that do not require the accessible data tree for validation (::lyplg_type_store_cb fully stores and validates the value).

Parameters
[in]ctxlibyang context.
[in]typeOriginal type of the value (not necessarily the stored one) being validated.
[in]ctx_nodeValue data context node for validation.
[in]treeExternal data tree (e.g. when validating RPC/Notification) with possibly referenced data.
[in,out]storageStorage of the value successfully filled by lyplg_type_store_clb. May be modified.
[out]errOptionally provided error information in case of failure. If not provided to the caller, a generic error message is prepared instead. The error structure can be created by ly_err_new().
Returns
LY_SUCCESS on success,
LY_ERR value on error.

Definition at line 539 of file plugins_types.h.