Ver código fonte

Use sr_get_data() for xpath show

Serj Kalichev 10 meses atrás
pai
commit
3242b06144
4 arquivos alterados com 28 adições e 17 exclusões
  1. 2 1
      src/klish_plugin_sysrepo.h
  2. 3 1
      src/pline.c
  3. 20 14
      src/show.c
  4. 3 1
      src/syms.c

+ 2 - 1
src/klish_plugin_sysrepo.h

@@ -311,7 +311,8 @@ enum diff_op {
     DIFF_OP_NONE,
 };
 
-bool_t show_xpath(sr_session_ctx_t *sess, const char *xpath, pline_opts_t *opts);
+bool_t show_xpath(sr_session_ctx_t *sess, const char *xpath,
+	size_t xpath_depth, pline_opts_t *opts);
 void show_subtree(const struct lyd_node *nodes_list, size_t level,
 	enum diff_op op, pline_opts_t *opts, bool_t parent_is_oneliner);
 

+ 3 - 1
src/pline.c

@@ -357,6 +357,7 @@ void pline_debug(pline_t *pline)
 		syslog(LOG_ERR, "pexpr.args_num = %lu", pexpr->args_num);
 		syslog(LOG_ERR, "pexpr.list_pos = %lu", pexpr->list_pos);
 		syslog(LOG_ERR, "pexpr.last_keys = %s", pexpr->last_keys ? pexpr->last_keys : "NULL");
+		syslog(LOG_ERR, "pexpr.tree_depth = %lu", pexpr->tree_depth);
 		syslog(LOG_ERR, "---");
 	}
 
@@ -387,7 +388,6 @@ static bool_t pexpr_xpath_add_node(pexpr_t *pexpr,
 	faux_str_cat(&pexpr->xpath, tmp);
 	faux_str_free(tmp);
 	pexpr->args_num++;
-	pexpr->tree_depth++;
 	// Activate current expression. Because it really has
 	// new component
 	pexpr->active = BOOL_TRUE;
@@ -573,6 +573,7 @@ static bool_t pline_parse_module(const struct lys_module *module,
 		} else if (node->nodetype & LYS_CONTAINER) {
 
 			pexpr->pat = PAT_CONTAINER;
+			pexpr->tree_depth++;
 
 			// Completion
 			if (!str) {
@@ -736,6 +737,7 @@ static bool_t pline_parse_module(const struct lys_module *module,
 			}
 
 			pexpr->pat = PAT_LIST_KEY;
+			pexpr->tree_depth++;
 
  			// Completion
 			if (!str) {

+ 20 - 14
src/show.c

@@ -368,28 +368,34 @@ void show_subtree(const struct lyd_node *nodes_list, size_t level,
 }
 
 
-bool_t show_xpath(sr_session_ctx_t *sess, const char *xpath, pline_opts_t *opts)
+bool_t show_xpath(sr_session_ctx_t *sess, const char *xpath,
+	size_t xpath_depth, pline_opts_t *opts)
 {
 	sr_data_t *data = NULL;
 	struct lyd_node *nodes_list = NULL;
+	const char *expath = xpath; // Effective XPath
+	size_t edepth = xpath_depth;
 
 	assert(sess);
 
-	if (xpath) {
-		if (sr_get_subtree(sess, xpath, 0, &data) != SR_ERR_OK)
-			return BOOL_FALSE;
-		if (!data) // Not found
-			return BOOL_TRUE;
-		nodes_list = lyd_child(data->tree);
-	} else {
-		if (sr_get_data(sess, "/*", 0, 0, 0, &data) != SR_ERR_OK)
-			return BOOL_FALSE;
-		if (!data) // Not found
-			return BOOL_TRUE;
-		nodes_list = data->tree;
+	if (!expath) {
+		expath = "/*";
+		edepth = 0;
+	}
+
+	if (sr_get_data(sess, expath, 0, 0, 0, &data) != SR_ERR_OK)
+		return BOOL_FALSE;
+	if (!data) // Not found
+		return BOOL_TRUE;
+	nodes_list = data->tree;
+
+	while (nodes_list && (edepth > 0)) {
+		nodes_list = lyd_child(nodes_list);
+		edepth--;
 	}
 
-	show_subtree(nodes_list, 0, DIFF_OP_NONE, opts, BOOL_FALSE);
+	if (nodes_list)
+		show_subtree(nodes_list, 0, DIFF_OP_NONE, opts, BOOL_FALSE);
 	sr_release_data(data);
 
 	return BOOL_TRUE;

+ 3 - 1
src/syms.c

@@ -928,6 +928,7 @@ static int show(kcontext_t *context, sr_datastore_t ds,
 	pexpr_t *expr = NULL;
 	faux_argv_t *cur_path = NULL;
 	char *xpath = NULL;
+	size_t xpath_depth = 0;
 
 	assert(context);
 
@@ -965,9 +966,10 @@ static int show(kcontext_t *context, sr_datastore_t ds,
 			goto err;
 		}
 		xpath = expr->xpath;
+		xpath_depth = expr->tree_depth;
 	}
 
-	show_xpath(sess, xpath, srp_udata_opts(context));
+	show_xpath(sess, xpath, xpath_depth, srp_udata_opts(context));
 
 	ret = 0;
 err: