|
@@ -7,11 +7,18 @@
|
|
|
#include <sysrepo.h>
|
|
|
#include <sysrepo/xpath.h>
|
|
|
|
|
|
+#include <faux/faux.h>
|
|
|
+#include <faux/argv.h>
|
|
|
+
|
|
|
+#define NODETYPE_CONF (LYS_CONTAINER | LYS_LIST | LYS_LEAF | LYS_LEAFLIST)
|
|
|
+
|
|
|
|
|
|
static void process_node(const struct lysc_node *node, size_t level);
|
|
|
static void iterate_nodes(const struct lysc_node *node, size_t level);
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
static int
|
|
|
sr_ly_module_is_internal(const struct lys_module *ly_mod)
|
|
|
{
|
|
@@ -148,15 +155,83 @@ static void iterate_nodes(const struct lysc_node *node, size_t level)
|
|
|
}
|
|
|
|
|
|
|
|
|
+void show(const struct ly_ctx *ctx)
|
|
|
+{
|
|
|
+ struct lys_module *module = NULL;
|
|
|
+ uint32_t i = 0;
|
|
|
+
|
|
|
+
|
|
|
+ i = 0;
|
|
|
+ while ((module = ly_ctx_get_module_iter(ctx, &i))) {
|
|
|
+ if (sr_module_is_internal(module))
|
|
|
+ continue;
|
|
|
+ if (!module->compiled)
|
|
|
+ continue;
|
|
|
+ if (!module->implemented)
|
|
|
+ continue;
|
|
|
+ if (!module->compiled->data)
|
|
|
+ continue;
|
|
|
+ printf("%s\n", module->name);
|
|
|
+ iterate_nodes(module->compiled->data, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const struct lysc_node *ppath2path_node(const struct lys_module *module,
|
|
|
+ const struct lysc_node *parent, const faux_argv_t *argv)
|
|
|
+{
|
|
|
+ const struct lysc_node *node = NULL;
|
|
|
+ const char *search = faux_argv_index(argv, 0);
|
|
|
+
|
|
|
+ printf("searching for %s\n", search);
|
|
|
+
|
|
|
+ node = lys_find_child(node, module, search, 0,
|
|
|
+ NODETYPE_CONF, 0);
|
|
|
+
|
|
|
+ if (node)
|
|
|
+ printf("%s\n", search);
|
|
|
+
|
|
|
+ return node;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void ppath2path(const struct ly_ctx *ctx, const char *ppath)
|
|
|
+{
|
|
|
+ faux_argv_t *argv = NULL;
|
|
|
+ struct lys_module *module = NULL;
|
|
|
+ uint32_t i = 0;
|
|
|
+
|
|
|
+ argv = faux_argv_new();
|
|
|
+ faux_argv_parse(argv, ppath);
|
|
|
+
|
|
|
+
|
|
|
+ i = 0;
|
|
|
+ while ((module = ly_ctx_get_module_iter(ctx, &i))) {
|
|
|
+ if (sr_module_is_internal(module))
|
|
|
+ continue;
|
|
|
+ if (!module->compiled)
|
|
|
+ continue;
|
|
|
+ if (!module->implemented)
|
|
|
+ continue;
|
|
|
+ if (!module->compiled->data)
|
|
|
+ continue;
|
|
|
+ printf("Module %s\n", module->name);
|
|
|
+ if (ppath2path_node(module, NULL, argv)) {
|
|
|
+ printf("Found\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int main(void)
|
|
|
{
|
|
|
int ret = -1;
|
|
|
int err = SR_ERR_OK;
|
|
|
sr_conn_ctx_t *conn = NULL;
|
|
|
sr_session_ctx_t *sess = NULL;
|
|
|
- const struct ly_ctx *lyctx = NULL;
|
|
|
- uint32_t i = 0;
|
|
|
- struct lys_module *module = NULL;
|
|
|
+ const struct ly_ctx *ctx = NULL;
|
|
|
|
|
|
err = sr_connect(SR_CONN_DEFAULT, &conn);
|
|
|
if (err) {
|
|
@@ -168,27 +243,16 @@ int main(void)
|
|
|
printf("Error2\n");
|
|
|
goto out;
|
|
|
}
|
|
|
- lyctx = sr_acquire_context(conn);
|
|
|
- if (!lyctx) {
|
|
|
+ ctx = sr_acquire_context(conn);
|
|
|
+ if (!ctx) {
|
|
|
printf("Cannot acquire context\n");
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- i = 0;
|
|
|
- while ((module = ly_ctx_get_module_iter(lyctx, &i))) {
|
|
|
- if (sr_module_is_internal(module))
|
|
|
- continue;
|
|
|
- if (!module->compiled)
|
|
|
- continue;
|
|
|
- if (!module->implemented)
|
|
|
- continue;
|
|
|
- if (!module->compiled->data)
|
|
|
- continue;
|
|
|
- printf("%s\n", module->name);
|
|
|
- iterate_nodes(module->compiled->data, 1);
|
|
|
- }
|
|
|
|
|
|
+ ppath2path(ctx, "interfaces interface eth0 type");
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
ret = 0;
|