Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ LY_ERR lyd_print_mem(char **, const struct lyd_node *, LYD_FORMAT, uint32_t);
LY_ERR lyd_print_tree(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);

#define LYD_PARSE_LYB_MOD_UPDATE ...
#define LYD_PARSE_NO_STATE ...
#define LYD_PARSE_STORE_ONLY ...
#define LYD_PARSE_JSON_NULL ...
Expand Down Expand Up @@ -350,7 +349,7 @@ LY_ERR ly_out_new_file(FILE *, struct ly_out **);
LY_ERR ly_out_new_fd(int, struct ly_out **);

LY_ERR lyd_parse_data(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, uint32_t, uint32_t, struct lyd_node **);
LY_ERR lyd_parse_op(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, enum lyd_type, struct lyd_node **, struct lyd_node **);
LY_ERR lyd_parse_op(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, enum lyd_type, uint32_t, struct lyd_node **, struct lyd_node **);

typedef enum {
LYS_OUT_UNKNOWN,
Expand All @@ -368,6 +367,7 @@ LY_ERR lys_print_module(struct ly_out *, const struct lys_module *, LYS_OUTFORMA

struct lysc_module {
struct lys_module *mod;
const char **features;
struct lysc_node *data;
struct lysc_node_action *rpcs;
struct lysc_node_notif *notifs;
Expand All @@ -387,13 +387,15 @@ struct lys_module {
const char *ref;
struct lysp_module *parsed;
struct lysc_module *compiled;
struct lysc_ext *extensions;
struct lysc_ident *identities;
struct lysc_submodule *submodules;
struct lys_module **augmented_by;
struct lys_module **deviated_by;
ly_bool implemented;
ly_bool to_compile;
uint8_t latest_revision;
...;
uint8_t version : 2;
uint8_t latest_revision : 4;
};

struct lysp_module {
Expand Down Expand Up @@ -466,12 +468,11 @@ struct lysp_ext_instance {
const char *argument;
LY_VALUE_FORMAT format;
void *prefix_data;
struct lysp_ext *def;
uintptr_t plugin_ref;
void *parent;
enum ly_stmt parent_stmt;
uint64_t parent_stmt_index;
uint16_t flags;
const struct lyplg_ext_record *record;
struct lysp_ext_substmt *substmts;
void *parsed;
struct lysp_stmt *child;
Expand Down Expand Up @@ -609,6 +610,11 @@ struct lysp_node_container {
...;
};

struct lysc_value {
const char *str;
struct lysc_prefix *prefixes;
};

struct lysc_node_leaf {
union {
struct lysc_node node;
Expand All @@ -622,7 +628,7 @@ struct lysc_node_leaf {
struct lysc_when **when;
struct lysc_type *type;
const char *units;
struct lyd_value *dflt;
struct lysc_value dflt;
...;
};

Expand Down Expand Up @@ -652,7 +658,7 @@ struct lysc_node_leaflist {
struct lysc_when **when;
struct lysc_type *type;
const char *units;
struct lyd_value **dflts;
struct lysc_value *dflts;
uint32_t min;
uint32_t max;
...;
Expand Down Expand Up @@ -782,7 +788,7 @@ struct lysp_node_augment {
struct lysc_type {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
};
Expand Down Expand Up @@ -858,7 +864,7 @@ struct lysc_ext {
const char *name;
const char *argname;
struct lysc_ext_instance *exts;
struct lyplg_ext *plugin;
uintptr_t plugin_ref;
struct lys_module *module;
uint16_t flags;
};
Expand Down Expand Up @@ -981,7 +987,6 @@ typedef struct pcre2_real_code pcre2_code;

struct lysc_pattern {
const char *expr;
pcre2_code *code;
const char *dsc;
const char *ref;
const char *emsg;
Expand Down Expand Up @@ -1016,7 +1021,7 @@ struct lysc_ident {
struct lysc_type_num {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_range *range;
Expand All @@ -1025,7 +1030,7 @@ struct lysc_type_num {
struct lysc_type_dec {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
uint8_t fraction_digits;
Expand All @@ -1035,7 +1040,7 @@ struct lysc_type_dec {
struct lysc_type_str {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_range *length;
Expand All @@ -1057,7 +1062,7 @@ struct lysc_type_bitenum_item {
struct lysc_type_enum {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_type_bitenum_item *enums;
Expand All @@ -1066,7 +1071,7 @@ struct lysc_type_enum {
struct lysc_type_bits {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_type_bitenum_item *bits;
Expand All @@ -1075,7 +1080,7 @@ struct lysc_type_bits {
struct lysc_type_leafref {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lyxp_expr *path;
Expand All @@ -1087,7 +1092,7 @@ struct lysc_type_leafref {
struct lysc_type_identityref {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_ident **bases;
Expand All @@ -1096,7 +1101,7 @@ struct lysc_type_identityref {
struct lysc_type_instanceid {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
uint8_t require_instance;
Expand All @@ -1105,7 +1110,7 @@ struct lysc_type_instanceid {
struct lysc_type_union {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_type **types;
Expand All @@ -1114,7 +1119,7 @@ struct lysc_type_union {
struct lysc_type_bin {
const char *name;
struct lysc_ext_instance *exts;
struct lyplg_type *plugin;
uintptr_t plugin_ref;
LY_DATA_TYPE basetype;
uint32_t refcount;
struct lysc_range *length;
Expand Down Expand Up @@ -1158,16 +1163,14 @@ typedef enum {
LYD_ANYDATA_DATATREE,
LYD_ANYDATA_STRING,
LYD_ANYDATA_XML,
LYD_ANYDATA_JSON,
LYD_ANYDATA_LYB
LYD_ANYDATA_JSON
} LYD_ANYDATA_VALUETYPE;

union lyd_any_value {
struct lyd_node *tree;
const char *str;
const char *xml;
const char *json;
char *mem;
};

struct lyd_node_any {
Expand Down Expand Up @@ -1319,6 +1322,8 @@ struct lyd_attr {
LY_ERR lyd_new_attr(struct lyd_node *, const char *, const char *, const char *, struct lyd_attr **);
void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);

LY_ERR lyd_value_validate_dflt(const struct lysc_node *, const char *, struct lysc_prefix *, const struct lyd_node *, const struct lysc_type **, const char **);

struct lyd_leafref_links_rec {
const struct lyd_node_term *node;
const struct lyd_node_term **leafref_nodes;
Expand All @@ -1327,13 +1332,14 @@ struct lyd_leafref_links_rec {

LY_ERR lyd_leafref_get_links(const struct lyd_node_term *, const struct lyd_leafref_links_rec **);
LY_ERR lyd_leafref_link_node_tree(struct lyd_node *);
struct lyplg_ext *lysc_get_ext_plugin(uintptr_t);
const char *lyplg_ext_stmt2str(enum ly_stmt stmt);
const struct lysp_module *lyplg_ext_parse_get_cur_pmod(const struct lysp_ctx *);
struct ly_ctx *lyplg_ext_compile_get_ctx(const struct lysc_ctx *);
void lyplg_ext_parse_log(const struct lysp_ctx *, const struct lysp_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
void lyplg_ext_compile_log(const struct lysc_ctx *, const struct lysc_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
LY_ERR lyplg_ext_parse_extension_instance(struct lysp_ctx *, struct lysp_ext_instance *);
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *);
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *, struct lysc_node *);
void lyplg_ext_pfree_instance_substatements(const struct ly_ctx *ctx, struct lysp_ext_substmt *substmts);
void lyplg_ext_cfree_instance_substatements(const struct ly_ctx *ctx, struct lysc_ext_substmt *substmts);
typedef LY_ERR (*lyplg_ext_parse_clb)(struct lysp_ctx *, struct lysp_ext_instance *);
Expand Down
4 changes: 2 additions & 2 deletions cffi/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#include <libyang/libyang.h>
#include <libyang/version.h>

#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 30801
#error "This version of libyang bindings only works with libyang soversion 3.8.1+"
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 40100
#error "This version of libyang bindings only works with libyang soversion 4.1.0+"
#endif
21 changes: 13 additions & 8 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ def parse_op(
in_data: Union[IO, str],
dtype: DataType,
parent: DNode = None,
opaq: bool = False,
strict: bool = False,
) -> DNode:
fmt = data_format(fmt)
data = ffi.new("struct ly_in **")
Expand All @@ -545,13 +547,14 @@ def parse_op(
if ret != lib.LY_SUCCESS:
raise self.error("failed to read input data")

flags = parser_flags(opaq=opaq, strict=strict)
tree = ffi.new("struct lyd_node **", ffi.NULL)
op = ffi.new("struct lyd_node **", ffi.NULL)
par = ffi.new("struct lyd_node **", ffi.NULL)
if parent is not None:
par[0] = parent.cdata

ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, tree, op)
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, flags, tree, op)
lib.ly_in_free(data[0], 0)
if ret != lib.LY_SUCCESS:
raise self.error("failed to parse input data")
Expand All @@ -564,9 +567,17 @@ def parse_op_mem(
data: str,
dtype: DataType = DataType.DATA_YANG,
parent: DNode = None,
opaq: bool = False,
strict: bool = False,
):
return self.parse_op(
fmt, in_type=IOType.MEMORY, in_data=data, dtype=dtype, parent=parent
fmt,
in_type=IOType.MEMORY,
in_data=data,
dtype=dtype,
parent=parent,
opaq=opaq,
strict=strict,
)

def parse_data(
Expand All @@ -575,7 +586,6 @@ def parse_data(
in_type: IOType,
in_data: Union[str, bytes, IO],
parent: DNode = None,
lyb_mod_update: bool = False,
no_state: bool = False,
parse_only: bool = False,
opaq: bool = False,
Expand All @@ -590,7 +600,6 @@ def parse_data(
if self.cdata is None:
raise RuntimeError("context already destroyed")
parser_flgs = parser_flags(
lyb_mod_update=lyb_mod_update,
no_state=no_state,
parse_only=parse_only,
opaq=opaq,
Expand Down Expand Up @@ -648,7 +657,6 @@ def parse_data_mem(
data: Union[str, bytes],
fmt: str,
parent: DNode = None,
lyb_mod_update: bool = False,
no_state: bool = False,
parse_only: bool = False,
opaq: bool = False,
Expand All @@ -665,7 +673,6 @@ def parse_data_mem(
in_type=IOType.MEMORY,
in_data=data,
parent=parent,
lyb_mod_update=lyb_mod_update,
no_state=no_state,
parse_only=parse_only,
opaq=opaq,
Expand All @@ -683,7 +690,6 @@ def parse_data_file(
fileobj: IO,
fmt: str,
parent: DNode = None,
lyb_mod_update: bool = False,
no_state: bool = False,
parse_only: bool = False,
opaq: bool = False,
Expand All @@ -700,7 +706,6 @@ def parse_data_file(
in_type=IOType.FD,
in_data=fileobj,
parent=parent,
lyb_mod_update=lyb_mod_update,
no_state=no_state,
parse_only=parse_only,
opaq=opaq,
Expand Down
3 changes: 0 additions & 3 deletions libyang/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def newval_flags(

# -------------------------------------------------------------------------------------
def parser_flags(
lyb_mod_update: bool = False,
no_state: bool = False,
parse_only: bool = False,
opaq: bool = False,
Expand All @@ -120,8 +119,6 @@ def parser_flags(
json_string_datatypes: bool = False,
) -> int:
flags = 0
if lyb_mod_update:
flags |= lib.LYD_PARSE_LYB_MOD_UPDATE
if no_state:
flags |= lib.LYD_PARSE_NO_STATE
if parse_only:
Expand Down
Loading
Loading