Skip to content

Commit d6faad4

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 2cae616 commit d6faad4

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 {
@@ -303,20 +304,19 @@ enum lyd_type {
303304
LYD_TYPE_REPLY_RESTCONF
304305
};
305306

306-
#define LYD_PRINT_KEEPEMPTYCONT ...
307307
#define LYD_PRINT_SHRINK ...
308+
#define LYD_PRINT_EMPTY_CONT ...
308309
#define LYD_PRINT_WD_ALL ...
309310
#define LYD_PRINT_WD_ALL_TAG ...
310311
#define LYD_PRINT_WD_EXPLICIT ...
311312
#define LYD_PRINT_WD_IMPL_TAG ...
312313
#define LYD_PRINT_WD_MASK ...
313-
#define LYD_PRINT_WITHSIBLINGS ...
314+
#define LYD_PRINT_SIBLINGS ...
314315
#define LYD_PRINT_WD_TRIM ...
315316
LY_ERR lyd_print_mem(char **, const struct lyd_node *, LYD_FORMAT, uint32_t);
316317
LY_ERR lyd_print_tree(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
317318
LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
318319

319-
#define LYD_PARSE_LYB_MOD_UPDATE ...
320320
#define LYD_PARSE_NO_STATE ...
321321
#define LYD_PARSE_STORE_ONLY ...
322322
#define LYD_PARSE_JSON_NULL ...
@@ -350,7 +350,7 @@ LY_ERR ly_out_new_file(FILE *, struct ly_out **);
350350
LY_ERR ly_out_new_fd(int, struct ly_out **);
351351

352352
LY_ERR lyd_parse_data(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, uint32_t, uint32_t, struct lyd_node **);
353-
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 **);
353+
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 **);
354354

355355
typedef enum {
356356
LYS_OUT_UNKNOWN,
@@ -368,6 +368,7 @@ LY_ERR lys_print_module(struct ly_out *, const struct lys_module *, LYS_OUTFORMA
368368

369369
struct lysc_module {
370370
struct lys_module *mod;
371+
const char **features;
371372
struct lysc_node *data;
372373
struct lysc_node_action *rpcs;
373374
struct lysc_node_notif *notifs;
@@ -387,13 +388,15 @@ struct lys_module {
387388
const char *ref;
388389
struct lysp_module *parsed;
389390
struct lysc_module *compiled;
391+
struct lysc_ext *extensions;
390392
struct lysc_ident *identities;
393+
struct lysc_submodule *submodules;
391394
struct lys_module **augmented_by;
392395
struct lys_module **deviated_by;
393396
ly_bool implemented;
394397
ly_bool to_compile;
395-
uint8_t latest_revision;
396-
...;
398+
uint8_t version : 2;
399+
uint8_t latest_revision : 4;
397400
};
398401

399402
struct lysp_module {
@@ -466,12 +469,11 @@ struct lysp_ext_instance {
466469
const char *argument;
467470
LY_VALUE_FORMAT format;
468471
void *prefix_data;
469-
struct lysp_ext *def;
472+
uintptr_t plugin_ref;
470473
void *parent;
471474
enum ly_stmt parent_stmt;
472475
uint64_t parent_stmt_index;
473476
uint16_t flags;
474-
const struct lyplg_ext_record *record;
475477
struct lysp_ext_substmt *substmts;
476478
void *parsed;
477479
struct lysp_stmt *child;
@@ -609,6 +611,11 @@ struct lysp_node_container {
609611
...;
610612
};
611613

614+
struct lysc_value {
615+
const char *str;
616+
struct lysc_prefix *prefixes;
617+
};
618+
612619
struct lysc_node_leaf {
613620
union {
614621
struct lysc_node node;
@@ -622,7 +629,7 @@ struct lysc_node_leaf {
622629
struct lysc_when **when;
623630
struct lysc_type *type;
624631
const char *units;
625-
struct lyd_value *dflt;
632+
struct lysc_value dflt;
626633
...;
627634
};
628635

@@ -652,7 +659,7 @@ struct lysc_node_leaflist {
652659
struct lysc_when **when;
653660
struct lysc_type *type;
654661
const char *units;
655-
struct lyd_value **dflts;
662+
struct lysc_value *dflts;
656663
uint32_t min;
657664
uint32_t max;
658665
...;
@@ -782,7 +789,7 @@ struct lysp_node_augment {
782789
struct lysc_type {
783790
const char *name;
784791
struct lysc_ext_instance *exts;
785-
struct lyplg_type *plugin;
792+
uintptr_t plugin_ref;
786793
LY_DATA_TYPE basetype;
787794
uint32_t refcount;
788795
};
@@ -858,7 +865,7 @@ struct lysc_ext {
858865
const char *name;
859866
const char *argname;
860867
struct lysc_ext_instance *exts;
861-
struct lyplg_ext *plugin;
868+
uintptr_t plugin_ref;
862869
struct lys_module *module;
863870
uint16_t flags;
864871
};
@@ -981,7 +988,6 @@ typedef struct pcre2_real_code pcre2_code;
981988

982989
struct lysc_pattern {
983990
const char *expr;
984-
pcre2_code *code;
985991
const char *dsc;
986992
const char *ref;
987993
const char *emsg;
@@ -1016,7 +1022,7 @@ struct lysc_ident {
10161022
struct lysc_type_num {
10171023
const char *name;
10181024
struct lysc_ext_instance *exts;
1019-
struct lyplg_type *plugin;
1025+
uintptr_t plugin_ref;
10201026
LY_DATA_TYPE basetype;
10211027
uint32_t refcount;
10221028
struct lysc_range *range;
@@ -1025,7 +1031,7 @@ struct lysc_type_num {
10251031
struct lysc_type_dec {
10261032
const char *name;
10271033
struct lysc_ext_instance *exts;
1028-
struct lyplg_type *plugin;
1034+
uintptr_t plugin_ref;
10291035
LY_DATA_TYPE basetype;
10301036
uint32_t refcount;
10311037
uint8_t fraction_digits;
@@ -1035,7 +1041,7 @@ struct lysc_type_dec {
10351041
struct lysc_type_str {
10361042
const char *name;
10371043
struct lysc_ext_instance *exts;
1038-
struct lyplg_type *plugin;
1044+
uintptr_t plugin_ref;
10391045
LY_DATA_TYPE basetype;
10401046
uint32_t refcount;
10411047
struct lysc_range *length;
@@ -1057,7 +1063,7 @@ struct lysc_type_bitenum_item {
10571063
struct lysc_type_enum {
10581064
const char *name;
10591065
struct lysc_ext_instance *exts;
1060-
struct lyplg_type *plugin;
1066+
uintptr_t plugin_ref;
10611067
LY_DATA_TYPE basetype;
10621068
uint32_t refcount;
10631069
struct lysc_type_bitenum_item *enums;
@@ -1066,7 +1072,7 @@ struct lysc_type_enum {
10661072
struct lysc_type_bits {
10671073
const char *name;
10681074
struct lysc_ext_instance *exts;
1069-
struct lyplg_type *plugin;
1075+
uintptr_t plugin_ref;
10701076
LY_DATA_TYPE basetype;
10711077
uint32_t refcount;
10721078
struct lysc_type_bitenum_item *bits;
@@ -1075,7 +1081,7 @@ struct lysc_type_bits {
10751081
struct lysc_type_leafref {
10761082
const char *name;
10771083
struct lysc_ext_instance *exts;
1078-
struct lyplg_type *plugin;
1084+
uintptr_t plugin_ref;
10791085
LY_DATA_TYPE basetype;
10801086
uint32_t refcount;
10811087
struct lyxp_expr *path;
@@ -1087,7 +1093,7 @@ struct lysc_type_leafref {
10871093
struct lysc_type_identityref {
10881094
const char *name;
10891095
struct lysc_ext_instance *exts;
1090-
struct lyplg_type *plugin;
1096+
uintptr_t plugin_ref;
10911097
LY_DATA_TYPE basetype;
10921098
uint32_t refcount;
10931099
struct lysc_ident **bases;
@@ -1096,7 +1102,7 @@ struct lysc_type_identityref {
10961102
struct lysc_type_instanceid {
10971103
const char *name;
10981104
struct lysc_ext_instance *exts;
1099-
struct lyplg_type *plugin;
1105+
uintptr_t plugin_ref;
11001106
LY_DATA_TYPE basetype;
11011107
uint32_t refcount;
11021108
uint8_t require_instance;
@@ -1105,7 +1111,7 @@ struct lysc_type_instanceid {
11051111
struct lysc_type_union {
11061112
const char *name;
11071113
struct lysc_ext_instance *exts;
1108-
struct lyplg_type *plugin;
1114+
uintptr_t plugin_ref;
11091115
LY_DATA_TYPE basetype;
11101116
uint32_t refcount;
11111117
struct lysc_type **types;
@@ -1114,7 +1120,7 @@ struct lysc_type_union {
11141120
struct lysc_type_bin {
11151121
const char *name;
11161122
struct lysc_ext_instance *exts;
1117-
struct lyplg_type *plugin;
1123+
uintptr_t plugin_ref;
11181124
LY_DATA_TYPE basetype;
11191125
uint32_t refcount;
11201126
struct lysc_range *length;
@@ -1158,16 +1164,14 @@ typedef enum {
11581164
LYD_ANYDATA_DATATREE,
11591165
LYD_ANYDATA_STRING,
11601166
LYD_ANYDATA_XML,
1161-
LYD_ANYDATA_JSON,
1162-
LYD_ANYDATA_LYB
1167+
LYD_ANYDATA_JSON
11631168
} LYD_ANYDATA_VALUETYPE;
11641169

11651170
union lyd_any_value {
11661171
struct lyd_node *tree;
11671172
const char *str;
11681173
const char *xml;
11691174
const char *json;
1170-
char *mem;
11711175
};
11721176

11731177
struct lyd_node_any {
@@ -1319,6 +1323,8 @@ struct lyd_attr {
13191323
LY_ERR lyd_new_attr(struct lyd_node *, const char *, const char *, const char *, struct lyd_attr **);
13201324
void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);
13211325

1326+
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 **);
1327+
13221328
struct lyd_leafref_links_rec {
13231329
const struct lyd_node_term *node;
13241330
const struct lyd_node_term **leafref_nodes;
@@ -1327,13 +1333,14 @@ struct lyd_leafref_links_rec {
13271333

13281334
LY_ERR lyd_leafref_get_links(const struct lyd_node_term *, const struct lyd_leafref_links_rec **);
13291335
LY_ERR lyd_leafref_link_node_tree(struct lyd_node *);
1336+
struct lyplg_ext *lysc_get_ext_plugin(uintptr_t);
13301337
const char *lyplg_ext_stmt2str(enum ly_stmt stmt);
13311338
const struct lysp_module *lyplg_ext_parse_get_cur_pmod(const struct lysp_ctx *);
13321339
struct ly_ctx *lyplg_ext_compile_get_ctx(const struct lysc_ctx *);
13331340
void lyplg_ext_parse_log(const struct lysp_ctx *, const struct lysp_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13341341
void lyplg_ext_compile_log(const struct lysc_ctx *, const struct lysc_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13351342
LY_ERR lyplg_ext_parse_extension_instance(struct lysp_ctx *, struct lysp_ext_instance *);
1336-
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *);
1343+
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *, struct lysc_node *);
13371344
void lyplg_ext_pfree_instance_substatements(const struct ly_ctx *ctx, struct lysp_ext_substmt *substmts);
13381345
void lyplg_ext_cfree_instance_substatements(const struct ly_ctx *ctx, struct lysc_ext_substmt *substmts);
13391346
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
yanglib_path: Optional[str] = None,
207207
yanglib_fmt: str = "json",
208+
compile_obsolete: bool = False,
208209
cdata=None, # C type: "struct ly_ctx *"
209210
):
210211
if cdata is not None:
@@ -225,6 +226,8 @@ def __init__(
225226
options |= lib.LY_CTX_LEAFREF_LINKING
226227
if builtin_plugins_only:
227228
options |= lib.LY_CTX_BUILTIN_PLUGINS_ONLY
229+
if compile_obsolete:
230+
options |= lib.LY_CTX_COMPILE_OBSOLETE
228231
# force priv parsed
229232
options |= lib.LY_CTX_SET_PRIV_PARSED
230233

@@ -253,6 +256,7 @@ def __init__(
253256
fmt = lib.LYD_JSON
254257
else:
255258
fmt = lib.LYD_XML
259+
print("steweg", search_path, yanglib_path, yanglib_fmt, options)
256260
ret = lib.ly_ctx_new_ylpath(
257261
str2c(search_path), str2c(yanglib_path), fmt, options, ctx
258262
)
@@ -536,6 +540,8 @@ def parse_op(
536540
in_data: Union[IO, str],
537541
dtype: DataType,
538542
parent: DNode = None,
543+
opaq: bool = False,
544+
strict: bool = False,
539545
) -> DNode:
540546
fmt = data_format(fmt)
541547
data = ffi.new("struct ly_in **")
@@ -545,13 +551,14 @@ def parse_op(
545551
if ret != lib.LY_SUCCESS:
546552
raise self.error("failed to read input data")
547553

554+
flags = parser_flags(opaq=opaq, strict=strict)
548555
tree = ffi.new("struct lyd_node **", ffi.NULL)
549556
op = ffi.new("struct lyd_node **", ffi.NULL)
550557
par = ffi.new("struct lyd_node **", ffi.NULL)
551558
if parent is not None:
552559
par[0] = parent.cdata
553560

554-
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, tree, op)
561+
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, flags, tree, op)
555562
lib.ly_in_free(data[0], 0)
556563
if ret != lib.LY_SUCCESS:
557564
raise self.error("failed to parse input data")
@@ -564,9 +571,17 @@ def parse_op_mem(
564571
data: str,
565572
dtype: DataType = DataType.DATA_YANG,
566573
parent: DNode = None,
574+
opaq: bool = False,
575+
strict: bool = False,
567576
):
568577
return self.parse_op(
569-
fmt, in_type=IOType.MEMORY, in_data=data, dtype=dtype, parent=parent
578+
fmt,
579+
in_type=IOType.MEMORY,
580+
in_data=data,
581+
dtype=dtype,
582+
parent=parent,
583+
opaq=opaq,
584+
strict=strict,
570585
)
571586

572587
def parse_data(
@@ -575,7 +590,6 @@ def parse_data(
575590
in_type: IOType,
576591
in_data: Union[str, bytes, IO],
577592
parent: DNode = None,
578-
lyb_mod_update: bool = False,
579593
no_state: bool = False,
580594
parse_only: bool = False,
581595
opaq: bool = False,
@@ -590,7 +604,6 @@ def parse_data(
590604
if self.cdata is None:
591605
raise RuntimeError("context already destroyed")
592606
parser_flgs = parser_flags(
593-
lyb_mod_update=lyb_mod_update,
594607
no_state=no_state,
595608
parse_only=parse_only,
596609
opaq=opaq,
@@ -648,7 +661,6 @@ def parse_data_mem(
648661
data: Union[str, bytes],
649662
fmt: str,
650663
parent: DNode = None,
651-
lyb_mod_update: bool = False,
652664
no_state: bool = False,
653665
parse_only: bool = False,
654666
opaq: bool = False,
@@ -665,7 +677,6 @@ def parse_data_mem(
665677
in_type=IOType.MEMORY,
666678
in_data=data,
667679
parent=parent,
668-
lyb_mod_update=lyb_mod_update,
669680
no_state=no_state,
670681
parse_only=parse_only,
671682
opaq=opaq,
@@ -683,7 +694,6 @@ def parse_data_file(
683694
fileobj: IO,
684695
fmt: str,
685696
parent: DNode = None,
686-
lyb_mod_update: bool = False,
687697
no_state: bool = False,
688698
parse_only: bool = False,
689699
opaq: bool = False,
@@ -700,7 +710,6 @@ def parse_data_file(
700710
in_type=IOType.FD,
701711
in_data=fileobj,
702712
parent=parent,
703-
lyb_mod_update=lyb_mod_update,
704713
no_state=no_state,
705714
parse_only=parse_only,
706715
opaq=opaq,

0 commit comments

Comments
 (0)