Skip to content

Commit b4d6698

Browse files
committed
schema: use lys_data_path_pattern
This function has been added to libyang.so. Use it instead of a local one. Link: CESNET/libyang@c831064cb7589ff7 Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent 7d4029c commit b4d6698

File tree

3 files changed

+3
-65
lines changed

3 files changed

+3
-65
lines changed

cffi/cdefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ const struct lys_node_list *lys_is_key(const struct lys_node_leaf *, uint8_t *);
344344
const struct lys_node *lys_getnext(const struct lys_node *, const struct lys_node *, const struct lys_module *, int);
345345
char *lys_data_path(const struct lys_node *);
346346
char *lys_path(const struct lys_node *, int);
347+
char *lys_data_path_pattern(const struct lys_node *, const char *);
347348
struct lys_module *lys_node_module(const struct lys_node *);
348349
struct lys_module *lys_main_module(const struct lys_module *);
349350
struct lys_node *lys_parent(const struct lys_node *);
@@ -447,7 +448,6 @@ void free(void *);
447448
const struct lys_ext_instance *lypy_find_ext(
448449
const struct lys_ext_instance **, uint8_t,
449450
const char *, const char *, const char *);
450-
char *lypy_data_path_pattern(const struct lys_node *);
451451
char *lypy_node_fullname(const struct lys_node *);
452452
int lyd_toprint(const struct lyd_node *node, int options);
453453
uint8_t lypy_module_implemented(const struct lys_module *);

cffi/source.c

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -40,68 +40,6 @@ lypy_find_ext(const struct lys_ext_instance **ext, uint8_t ext_size,
4040
return NULL;
4141
}
4242

43-
static char *lypy_data_path_pattern(const struct lys_node *node)
44-
{
45-
const struct lys_module *prev_mod, *mod;
46-
char *xpath = NULL, *keys = NULL;
47-
struct ly_set *set = NULL;;
48-
size_t x;
49-
50-
if (!node)
51-
goto cleanup;
52-
53-
set = ly_set_new();
54-
if (!set)
55-
goto cleanup;
56-
57-
while (node) {
58-
ly_set_add(set, (void *)node, 0);
59-
do {
60-
node = lys_parent(node);
61-
} while (node && !(node->nodetype & (
62-
LYS_CONTAINER | LYS_LIST | LYS_RPC)));
63-
}
64-
65-
xpath = malloc(2048);
66-
if (!xpath)
67-
goto cleanup;
68-
keys = malloc(512);
69-
if (!keys)
70-
goto cleanup;
71-
72-
x = 0;
73-
xpath[0] = '\0';
74-
75-
prev_mod = NULL;
76-
for (int i = set->number - 1; i > -1; --i) {
77-
size_t k = 0;
78-
keys[0] = '\0';
79-
node = set->set.s[i];
80-
if (node->nodetype == LYS_LIST) {
81-
const struct lys_node_list *list;
82-
list = (const struct lys_node_list *)node;
83-
for (uint8_t j = 0; j < list->keys_size; j++) {
84-
k += sprintf(keys + k, "[%s='%%s']",
85-
list->keys[j]->name);
86-
}
87-
}
88-
89-
mod = lys_node_module(node);
90-
if (mod && mod != prev_mod) {
91-
prev_mod = mod;
92-
x += sprintf(xpath + x, "/%s:%s%s",
93-
mod->name, node->name, keys);
94-
} else {
95-
x += sprintf(xpath + x, "/%s%s", node->name, keys);
96-
}
97-
}
98-
99-
cleanup:
100-
ly_set_free(set);
101-
free(keys);
102-
return xpath;
103-
}
104-
10543
static char *lypy_node_fullname(const struct lys_node *node)
10644
{
10745
const struct lys_module *module;

libyang/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ def schema_path(self):
682682
finally:
683683
lib.free(s)
684684

685-
def data_path(self):
685+
def data_path(self, key_placeholder="'%s'"):
686686
try:
687-
s = lib.lypy_data_path_pattern(self._node)
687+
s = lib.lys_data_path_pattern(self._node, str2c(key_placeholder))
688688
return c2str(s)
689689
finally:
690690
lib.free(s)

0 commit comments

Comments
 (0)