Skip to content

Commit 8c24656

Browse files
committed
cffi: allows to usage of libyang v4.2.2
This patch adjust cffi definitions and also all associated functions based on libyang v4.2.2. Signed-off-by: Stefan Gula <[email protected]>
1 parent 1deecd8 commit 8c24656

File tree

10 files changed

+172
-96
lines changed

10 files changed

+172
-96
lines changed

cffi/cdefs.h

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct ly_ctx;
1717
#define LY_CTX_LEAFREF_EXTENDED ...
1818
#define LY_CTX_LEAFREF_LINKING ...
1919
#define LY_CTX_BUILTIN_PLUGINS_ONLY ...
20+
#define LY_CTX_COMPILE_OBSOLETE ...
2021

2122

2223
typedef enum {
@@ -304,20 +305,19 @@ enum lyd_type {
304305
LYD_TYPE_REPLY_RESTCONF
305306
};
306307

307-
#define LYD_PRINT_KEEPEMPTYCONT ...
308308
#define LYD_PRINT_SHRINK ...
309+
#define LYD_PRINT_EMPTY_CONT ...
309310
#define LYD_PRINT_WD_ALL ...
310311
#define LYD_PRINT_WD_ALL_TAG ...
311312
#define LYD_PRINT_WD_EXPLICIT ...
312313
#define LYD_PRINT_WD_IMPL_TAG ...
313314
#define LYD_PRINT_WD_MASK ...
314-
#define LYD_PRINT_WITHSIBLINGS ...
315+
#define LYD_PRINT_SIBLINGS ...
315316
#define LYD_PRINT_WD_TRIM ...
316317
LY_ERR lyd_print_mem(char **, const struct lyd_node *, LYD_FORMAT, uint32_t);
317318
LY_ERR lyd_print_tree(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
318319
LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
319320

320-
#define LYD_PARSE_LYB_MOD_UPDATE ...
321321
#define LYD_PARSE_NO_STATE ...
322322
#define LYD_PARSE_STORE_ONLY ...
323323
#define LYD_PARSE_JSON_NULL ...
@@ -351,7 +351,7 @@ LY_ERR ly_out_new_file(FILE *, struct ly_out **);
351351
LY_ERR ly_out_new_fd(int, struct ly_out **);
352352

353353
LY_ERR lyd_parse_data(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, uint32_t, uint32_t, struct lyd_node **);
354-
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 **);
354+
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 **);
355355

356356
typedef enum {
357357
LYS_OUT_UNKNOWN,
@@ -369,6 +369,7 @@ LY_ERR lys_print_module(struct ly_out *, const struct lys_module *, LYS_OUTFORMA
369369

370370
struct lysc_module {
371371
struct lys_module *mod;
372+
const char **features;
372373
struct lysc_node *data;
373374
struct lysc_node_action *rpcs;
374375
struct lysc_node_notif *notifs;
@@ -388,13 +389,15 @@ struct lys_module {
388389
const char *ref;
389390
struct lysp_module *parsed;
390391
struct lysc_module *compiled;
392+
struct lysc_ext *extensions;
391393
struct lysc_ident *identities;
394+
struct lysc_submodule *submodules;
392395
struct lys_module **augmented_by;
393396
struct lys_module **deviated_by;
394397
ly_bool implemented;
395398
ly_bool to_compile;
396-
uint8_t latest_revision;
397-
...;
399+
uint8_t version : 2;
400+
uint8_t latest_revision : 4;
398401
};
399402

400403
struct lysp_module {
@@ -467,12 +470,11 @@ struct lysp_ext_instance {
467470
const char *argument;
468471
LY_VALUE_FORMAT format;
469472
void *prefix_data;
470-
struct lysp_ext *def;
473+
uintptr_t plugin_ref;
471474
void *parent;
472475
enum ly_stmt parent_stmt;
473476
uint64_t parent_stmt_index;
474477
uint16_t flags;
475-
const struct lyplg_ext_record *record;
476478
struct lysp_ext_substmt *substmts;
477479
void *parsed;
478480
struct lysp_stmt *child;
@@ -610,6 +612,11 @@ struct lysp_node_container {
610612
...;
611613
};
612614

615+
struct lysc_value {
616+
const char *str;
617+
struct lysc_prefix *prefixes;
618+
};
619+
613620
struct lysc_node_leaf {
614621
union {
615622
struct lysc_node node;
@@ -623,7 +630,7 @@ struct lysc_node_leaf {
623630
struct lysc_when **when;
624631
struct lysc_type *type;
625632
const char *units;
626-
struct lyd_value *dflt;
633+
struct lysc_value dflt;
627634
...;
628635
};
629636

@@ -653,7 +660,7 @@ struct lysc_node_leaflist {
653660
struct lysc_when **when;
654661
struct lysc_type *type;
655662
const char *units;
656-
struct lyd_value **dflts;
663+
struct lysc_value *dflts;
657664
uint32_t min;
658665
uint32_t max;
659666
...;
@@ -783,7 +790,7 @@ struct lysp_node_augment {
783790
struct lysc_type {
784791
const char *name;
785792
struct lysc_ext_instance *exts;
786-
struct lyplg_type *plugin;
793+
uintptr_t plugin_ref;
787794
LY_DATA_TYPE basetype;
788795
uint32_t refcount;
789796
};
@@ -859,7 +866,7 @@ struct lysc_ext {
859866
const char *name;
860867
const char *argname;
861868
struct lysc_ext_instance *exts;
862-
struct lyplg_ext *plugin;
869+
uintptr_t plugin_ref;
863870
struct lys_module *module;
864871
uint16_t flags;
865872
};
@@ -982,7 +989,6 @@ typedef struct pcre2_real_code pcre2_code;
982989

983990
struct lysc_pattern {
984991
const char *expr;
985-
pcre2_code *code;
986992
const char *dsc;
987993
const char *ref;
988994
const char *emsg;
@@ -1017,7 +1023,7 @@ struct lysc_ident {
10171023
struct lysc_type_num {
10181024
const char *name;
10191025
struct lysc_ext_instance *exts;
1020-
struct lyplg_type *plugin;
1026+
uintptr_t plugin_ref;
10211027
LY_DATA_TYPE basetype;
10221028
uint32_t refcount;
10231029
struct lysc_range *range;
@@ -1026,7 +1032,7 @@ struct lysc_type_num {
10261032
struct lysc_type_dec {
10271033
const char *name;
10281034
struct lysc_ext_instance *exts;
1029-
struct lyplg_type *plugin;
1035+
uintptr_t plugin_ref;
10301036
LY_DATA_TYPE basetype;
10311037
uint32_t refcount;
10321038
uint8_t fraction_digits;
@@ -1036,7 +1042,7 @@ struct lysc_type_dec {
10361042
struct lysc_type_str {
10371043
const char *name;
10381044
struct lysc_ext_instance *exts;
1039-
struct lyplg_type *plugin;
1045+
uintptr_t plugin_ref;
10401046
LY_DATA_TYPE basetype;
10411047
uint32_t refcount;
10421048
struct lysc_range *length;
@@ -1058,7 +1064,7 @@ struct lysc_type_bitenum_item {
10581064
struct lysc_type_enum {
10591065
const char *name;
10601066
struct lysc_ext_instance *exts;
1061-
struct lyplg_type *plugin;
1067+
uintptr_t plugin_ref;
10621068
LY_DATA_TYPE basetype;
10631069
uint32_t refcount;
10641070
struct lysc_type_bitenum_item *enums;
@@ -1067,7 +1073,7 @@ struct lysc_type_enum {
10671073
struct lysc_type_bits {
10681074
const char *name;
10691075
struct lysc_ext_instance *exts;
1070-
struct lyplg_type *plugin;
1076+
uintptr_t plugin_ref;
10711077
LY_DATA_TYPE basetype;
10721078
uint32_t refcount;
10731079
struct lysc_type_bitenum_item *bits;
@@ -1076,7 +1082,7 @@ struct lysc_type_bits {
10761082
struct lysc_type_leafref {
10771083
const char *name;
10781084
struct lysc_ext_instance *exts;
1079-
struct lyplg_type *plugin;
1085+
uintptr_t plugin_ref;
10801086
LY_DATA_TYPE basetype;
10811087
uint32_t refcount;
10821088
struct lyxp_expr *path;
@@ -1088,7 +1094,7 @@ struct lysc_type_leafref {
10881094
struct lysc_type_identityref {
10891095
const char *name;
10901096
struct lysc_ext_instance *exts;
1091-
struct lyplg_type *plugin;
1097+
uintptr_t plugin_ref;
10921098
LY_DATA_TYPE basetype;
10931099
uint32_t refcount;
10941100
struct lysc_ident **bases;
@@ -1097,7 +1103,7 @@ struct lysc_type_identityref {
10971103
struct lysc_type_instanceid {
10981104
const char *name;
10991105
struct lysc_ext_instance *exts;
1100-
struct lyplg_type *plugin;
1106+
uintptr_t plugin_ref;
11011107
LY_DATA_TYPE basetype;
11021108
uint32_t refcount;
11031109
uint8_t require_instance;
@@ -1106,7 +1112,7 @@ struct lysc_type_instanceid {
11061112
struct lysc_type_union {
11071113
const char *name;
11081114
struct lysc_ext_instance *exts;
1109-
struct lyplg_type *plugin;
1115+
uintptr_t plugin_ref;
11101116
LY_DATA_TYPE basetype;
11111117
uint32_t refcount;
11121118
struct lysc_type **types;
@@ -1115,7 +1121,7 @@ struct lysc_type_union {
11151121
struct lysc_type_bin {
11161122
const char *name;
11171123
struct lysc_ext_instance *exts;
1118-
struct lyplg_type *plugin;
1124+
uintptr_t plugin_ref;
11191125
LY_DATA_TYPE basetype;
11201126
uint32_t refcount;
11211127
struct lysc_range *length;
@@ -1159,16 +1165,14 @@ typedef enum {
11591165
LYD_ANYDATA_DATATREE,
11601166
LYD_ANYDATA_STRING,
11611167
LYD_ANYDATA_XML,
1162-
LYD_ANYDATA_JSON,
1163-
LYD_ANYDATA_LYB
1168+
LYD_ANYDATA_JSON
11641169
} LYD_ANYDATA_VALUETYPE;
11651170

11661171
union lyd_any_value {
11671172
struct lyd_node *tree;
11681173
const char *str;
11691174
const char *xml;
11701175
const char *json;
1171-
char *mem;
11721176
};
11731177

11741178
struct lyd_node_any {
@@ -1320,6 +1324,8 @@ struct lyd_attr {
13201324
LY_ERR lyd_new_attr(struct lyd_node *, const char *, const char *, const char *, struct lyd_attr **);
13211325
void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);
13221326

1327+
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 **);
1328+
13231329
struct lyd_leafref_links_rec {
13241330
const struct lyd_node_term *node;
13251331
const struct lyd_node_term **leafref_nodes;
@@ -1328,13 +1334,14 @@ struct lyd_leafref_links_rec {
13281334

13291335
LY_ERR lyd_leafref_get_links(const struct lyd_node_term *, const struct lyd_leafref_links_rec **);
13301336
LY_ERR lyd_leafref_link_node_tree(struct lyd_node *);
1337+
struct lyplg_ext *lysc_get_ext_plugin(uintptr_t);
13311338
const char *lyplg_ext_stmt2str(enum ly_stmt stmt);
13321339
const struct lysp_module *lyplg_ext_parse_get_cur_pmod(const struct lysp_ctx *);
13331340
struct ly_ctx *lyplg_ext_compile_get_ctx(const struct lysc_ctx *);
13341341
void lyplg_ext_parse_log(const struct lysp_ctx *, const struct lysp_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13351342
void lyplg_ext_compile_log(const struct lysc_ctx *, const struct lysc_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13361343
LY_ERR lyplg_ext_parse_extension_instance(struct lysp_ctx *, struct lysp_ext_instance *);
1337-
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *);
1344+
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *, struct lysc_node *);
13381345
void lyplg_ext_pfree_instance_substatements(const struct ly_ctx *ctx, struct lysp_ext_substmt *substmts);
13391346
void lyplg_ext_cfree_instance_substatements(const struct ly_ctx *ctx, struct lysc_ext_substmt *substmts);
13401347
typedef LY_ERR (*lyplg_ext_parse_clb)(struct lysp_ctx *, struct lysp_ext_instance *);

cffi/source.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#include <libyang/libyang.h>
77
#include <libyang/version.h>
88

9-
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 30801
10-
#error "This version of libyang bindings only works with libyang soversion 3.8.1+"
9+
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 40202
10+
#error "This version of libyang bindings only works with libyang soversion 4.2.2+"
1111
#endif

libyang/context.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def __init__(
205205
builtin_plugins_only: bool = False,
206206
all_implemented: bool = False,
207207
enable_imp_features: bool = False,
208+
compile_obsolete: bool = False,
208209
yanglib_path: Optional[str] = None,
209210
yanglib_fmt: str = "json",
210211
cdata=None, # C type: "struct ly_ctx *"
@@ -231,6 +232,8 @@ def __init__(
231232
options |= lib.LY_CTX_ALL_IMPLEMENTED
232233
if enable_imp_features:
233234
options |= lib.LY_CTX_ENABLE_IMP_FEATURES
235+
if compile_obsolete:
236+
options |= lib.LY_CTX_COMPILE_OBSOLETE
234237
# force priv parsed
235238
options |= lib.LY_CTX_SET_PRIV_PARSED
236239

@@ -259,6 +262,7 @@ def __init__(
259262
fmt = lib.LYD_JSON
260263
else:
261264
fmt = lib.LYD_XML
265+
print("steweg", search_path, yanglib_path, yanglib_fmt, options)
262266
ret = lib.ly_ctx_new_ylpath(
263267
str2c(search_path), str2c(yanglib_path), fmt, options, ctx
264268
)
@@ -542,6 +546,8 @@ def parse_op(
542546
in_data: Union[IO, str],
543547
dtype: DataType,
544548
parent: DNode = None,
549+
opaq: bool = False,
550+
strict: bool = False,
545551
) -> DNode:
546552
fmt = data_format(fmt)
547553
data = ffi.new("struct ly_in **")
@@ -551,13 +557,14 @@ def parse_op(
551557
if ret != lib.LY_SUCCESS:
552558
raise self.error("failed to read input data")
553559

560+
flags = parser_flags(opaq=opaq, strict=strict)
554561
tree = ffi.new("struct lyd_node **", ffi.NULL)
555562
op = ffi.new("struct lyd_node **", ffi.NULL)
556563
par = ffi.new("struct lyd_node **", ffi.NULL)
557564
if parent is not None:
558565
par[0] = parent.cdata
559566

560-
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, tree, op)
567+
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, flags, tree, op)
561568
lib.ly_in_free(data[0], 0)
562569
if ret != lib.LY_SUCCESS:
563570
raise self.error("failed to parse input data")
@@ -570,9 +577,17 @@ def parse_op_mem(
570577
data: str,
571578
dtype: DataType = DataType.DATA_YANG,
572579
parent: DNode = None,
580+
opaq: bool = False,
581+
strict: bool = False,
573582
):
574583
return self.parse_op(
575-
fmt, in_type=IOType.MEMORY, in_data=data, dtype=dtype, parent=parent
584+
fmt,
585+
in_type=IOType.MEMORY,
586+
in_data=data,
587+
dtype=dtype,
588+
parent=parent,
589+
opaq=opaq,
590+
strict=strict,
576591
)
577592

578593
def parse_data(
@@ -581,7 +596,6 @@ def parse_data(
581596
in_type: IOType,
582597
in_data: Union[str, bytes, IO],
583598
parent: DNode = None,
584-
lyb_mod_update: bool = False,
585599
no_state: bool = False,
586600
parse_only: bool = False,
587601
opaq: bool = False,
@@ -596,7 +610,6 @@ def parse_data(
596610
if self.cdata is None:
597611
raise RuntimeError("context already destroyed")
598612
parser_flgs = parser_flags(
599-
lyb_mod_update=lyb_mod_update,
600613
no_state=no_state,
601614
parse_only=parse_only,
602615
opaq=opaq,
@@ -640,7 +653,6 @@ def parse_data_mem(
640653
data: Union[str, bytes],
641654
fmt: str,
642655
parent: DNode = None,
643-
lyb_mod_update: bool = False,
644656
no_state: bool = False,
645657
parse_only: bool = False,
646658
opaq: bool = False,
@@ -657,7 +669,6 @@ def parse_data_mem(
657669
in_type=IOType.MEMORY,
658670
in_data=data,
659671
parent=parent,
660-
lyb_mod_update=lyb_mod_update,
661672
no_state=no_state,
662673
parse_only=parse_only,
663674
opaq=opaq,
@@ -675,7 +686,6 @@ def parse_data_file(
675686
fileobj: IO,
676687
fmt: str,
677688
parent: DNode = None,
678-
lyb_mod_update: bool = False,
679689
no_state: bool = False,
680690
parse_only: bool = False,
681691
opaq: bool = False,
@@ -692,7 +702,6 @@ def parse_data_file(
692702
in_type=IOType.FD,
693703
in_data=fileobj,
694704
parent=parent,
695-
lyb_mod_update=lyb_mod_update,
696705
no_state=no_state,
697706
parse_only=parse_only,
698707
opaq=opaq,

0 commit comments

Comments
 (0)