From 14cc88ca39864228eaddfd0a7b7f3f857cf0554c Mon Sep 17 00:00:00 2001 From: Jan-Olof Carlson Date: Wed, 27 Jul 2022 11:31:44 +0000 Subject: [PATCH] Added parameter defaults to library function clicon_rpc_get --- apps/cli/cli_auto.c | 2 +- apps/cli/cli_show.c | 4 ++-- apps/restconf/restconf_methods_get.c | 6 +++--- apps/snmp/snmp_handler.c | 4 ++-- apps/snmp/snmp_register.c | 2 +- lib/clixon/clixon_proto_client.h | 3 +-- lib/src/clixon_proto_client.c | 23 +++++------------------ 7 files changed, 15 insertions(+), 29 deletions(-) diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 8f771bd8..db151e12 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -437,7 +437,7 @@ cli_auto_show(clicon_handle h, clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db); goto done; } - if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0) + if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; } if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 6045485e..9533a946 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -484,7 +484,7 @@ cli_show_config1(clicon_handle h, clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db); goto done; } - if (clicon_rpc_get(h, cbuf_get(cbxpath), nsc, CONTENT_ALL, -1, &xt) < 0) + if (clicon_rpc_get(h, cbuf_get(cbxpath), nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; } if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ @@ -749,7 +749,7 @@ cli_show_auto1(clicon_handle h, clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db); goto done; } - if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0) + if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; } if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ diff --git a/apps/restconf/restconf_methods_get.c b/apps/restconf/restconf_methods_get.c index 2059666c..cbb13f41 100644 --- a/apps/restconf/restconf_methods_get.c +++ b/apps/restconf/restconf_methods_get.c @@ -124,7 +124,7 @@ api_data_get2(clicon_handle h, cxobj *xtop = NULL; cxobj *xbot = NULL; yang_stmt *y = NULL; - char *with_defaults = NULL; + char *defaults = NULL; clicon_debug(1, "%s", __FUNCTION__); if ((yspec = clicon_dbspec_yang(h)) == NULL){ @@ -197,11 +197,11 @@ api_data_get2(clicon_handle h, } if ((attr = cvec_find_str(qvec, "with-defaults")) != NULL){ clicon_debug(1, "%s with_defaults=%s", __FUNCTION__, attr); - with_defaults = attr; + defaults = attr; } clicon_debug(1, "%s path:%s", __FUNCTION__, xpath); - ret = clicon_rpc_get2(h, xpath, nsc, content, depth, with_defaults, &xret); + ret = clicon_rpc_get(h, xpath, nsc, content, depth, defaults, &xret); if (ret < 0){ if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index 9854790d..f6e4a438 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -256,7 +256,7 @@ snmp_scalar_get(clicon_handle h, clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&xcache); if (xcache==NULL || (x = xpath_first(xcache, nsc, "%s", xpath)) == NULL){ /* If not found do the backend call */ - if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0) + if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; /* Detect error XXX Error handling could improve */ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ @@ -1160,7 +1160,7 @@ snmp_table_getnext(clicon_handle h, goto done; if (snmp_yang2xpath(ys, NULL, &xpath) < 0) goto done; - if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0) + if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ clixon_netconf_error(xerr, "clicon_rpc_get", NULL); diff --git a/apps/snmp/snmp_register.c b/apps/snmp/snmp_register.c index b3e85b3c..2031c5c4 100644 --- a/apps/snmp/snmp_register.c +++ b/apps/snmp/snmp_register.c @@ -375,7 +375,7 @@ mibyang_table_poll(clicon_handle h, goto done; if (snmp_yang2xpath(ys, NULL, &xpath) < 0) goto done; - if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0) + if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ clixon_netconf_error(xerr, "clicon_rpc_get", NULL); diff --git a/lib/clixon/clixon_proto_client.h b/lib/clixon/clixon_proto_client.h index 4fafae31..f6a43b0e 100644 --- a/lib/clixon/clixon_proto_client.h +++ b/lib/clixon/clixon_proto_client.h @@ -54,8 +54,7 @@ int clicon_rpc_copy_config(clicon_handle h, char *db1, char *db2); int clicon_rpc_delete_config(clicon_handle h, char *db); int clicon_rpc_lock(clicon_handle h, char *db); int clicon_rpc_unlock(clicon_handle h, char *db); -int clicon_rpc_get2(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *with_defaults, cxobj **xret); -int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, cxobj **xret); +int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, cxobj **xret); int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath, cvec *nsc, netconf_content content, int32_t depth, uint32_t offset, uint32_t limit, diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 1ffdcf5e..214fec60 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -824,6 +824,7 @@ clicon_rpc_unlock(clicon_handle h, * @param[in] nsc Namespace context for filter * @param[in] content Clixon extension: all, config, noconfig. -1 means all * @param[in] depth Nr of XML levels to get, -1 is all, 0 is none + * @param[in] defaults Value of the with-defaults mode, rfc6243, or NULL * @param[out] xt XML tree. Free with xml_free. * Either or . * @retval 0 OK @@ -852,26 +853,12 @@ clicon_rpc_unlock(clicon_handle h, * @note the netconf return message is yang populated, as well as the return data */ int -clicon_rpc_get(clicon_handle h, +clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, /* namespace context for filter */ netconf_content content, int32_t depth, - cxobj **xt) -{ - return clicon_rpc_get2(h, xpath, nsc, content, depth, NULL, xt); -} - -/*! Same functionality as the 'clicon_rpc_get' function, but with an additional input parameter 'with-defaults'. - * @see clicon_rpc_get - */ -int -clicon_rpc_get2(clicon_handle h, - char *xpath, - cvec *nsc, /* namespace context for filter */ - netconf_content content, - int32_t depth, - char *with_defaults, + char *defaults, cxobj **xt) { int retval = -1; @@ -912,8 +899,8 @@ clicon_rpc_get2(clicon_handle h, goto done; cprintf(cb, "/>"); } - if (with_defaults != NULL) - cprintf(cb, "%s", with_defaults); + if (defaults != NULL) + cprintf(cb, "%s", defaults); cprintf(cb, ""); if ((msg = clicon_msg_encode(session_id, "%s", cbuf_get(cb))) == NULL)