Added parameter defaults to library function clicon_rpc_get

This commit is contained in:
Jan-Olof Carlson 2022-07-27 11:31:44 +00:00 committed by Olof hagsand
parent 6bee1746e0
commit 14cc88ca39
7 changed files with 15 additions and 29 deletions

View file

@ -437,7 +437,7 @@ cli_auto_show(clicon_handle h,
clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db); clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
goto done; 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; goto done;
} }
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){

View file

@ -484,7 +484,7 @@ cli_show_config1(clicon_handle h,
clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db); clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
goto done; 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; goto done;
} }
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ 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); clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
goto done; 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; goto done;
} }
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){

View file

@ -124,7 +124,7 @@ api_data_get2(clicon_handle h,
cxobj *xtop = NULL; cxobj *xtop = NULL;
cxobj *xbot = NULL; cxobj *xbot = NULL;
yang_stmt *y = NULL; yang_stmt *y = NULL;
char *with_defaults = NULL; char *defaults = NULL;
clicon_debug(1, "%s", __FUNCTION__); clicon_debug(1, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ 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){ if ((attr = cvec_find_str(qvec, "with-defaults")) != NULL){
clicon_debug(1, "%s with_defaults=%s", __FUNCTION__, attr); clicon_debug(1, "%s with_defaults=%s", __FUNCTION__, attr);
with_defaults = attr; defaults = attr;
} }
clicon_debug(1, "%s path:%s", __FUNCTION__, xpath); 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 (ret < 0){
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0) if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0)

View file

@ -256,7 +256,7 @@ snmp_scalar_get(clicon_handle h,
clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&xcache); clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&xcache);
if (xcache==NULL || (x = xpath_first(xcache, nsc, "%s", xpath)) == NULL){ if (xcache==NULL || (x = xpath_first(xcache, nsc, "%s", xpath)) == NULL){
/* If not found do the backend call */ /* 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; goto done;
/* Detect error XXX Error handling could improve */ /* Detect error XXX Error handling could improve */
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
@ -1160,7 +1160,7 @@ snmp_table_getnext(clicon_handle h,
goto done; goto done;
if (snmp_yang2xpath(ys, NULL, &xpath) < 0) if (snmp_yang2xpath(ys, NULL, &xpath) < 0)
goto done; 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; goto done;
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(xerr, "clicon_rpc_get", NULL); clixon_netconf_error(xerr, "clicon_rpc_get", NULL);

View file

@ -375,7 +375,7 @@ mibyang_table_poll(clicon_handle h,
goto done; goto done;
if (snmp_yang2xpath(ys, NULL, &xpath) < 0) if (snmp_yang2xpath(ys, NULL, &xpath) < 0)
goto done; 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; goto done;
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(xerr, "clicon_rpc_get", NULL); clixon_netconf_error(xerr, "clicon_rpc_get", NULL);

View file

@ -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_delete_config(clicon_handle h, char *db);
int clicon_rpc_lock(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_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, char *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_pageable_list(clicon_handle h, char *datastore, char *xpath, int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath,
cvec *nsc, netconf_content content, int32_t depth, cvec *nsc, netconf_content content, int32_t depth,
uint32_t offset, uint32_t limit, uint32_t offset, uint32_t limit,

View file

@ -824,6 +824,7 @@ clicon_rpc_unlock(clicon_handle h,
* @param[in] nsc Namespace context for filter * @param[in] nsc Namespace context for filter
* @param[in] content Clixon extension: all, config, noconfig. -1 means all * @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] 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. * @param[out] xt XML tree. Free with xml_free.
* Either <config> or <rpc-error>. * Either <config> or <rpc-error>.
* @retval 0 OK * @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 * @note the netconf return message is yang populated, as well as the return data
*/ */
int int
clicon_rpc_get(clicon_handle h, clicon_rpc_get(clicon_handle h,
char *xpath, char *xpath,
cvec *nsc, /* namespace context for filter */ cvec *nsc, /* namespace context for filter */
netconf_content content, netconf_content content,
int32_t depth, int32_t depth,
cxobj **xt) char *defaults,
{
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,
cxobj **xt) cxobj **xt)
{ {
int retval = -1; int retval = -1;
@ -912,8 +899,8 @@ clicon_rpc_get2(clicon_handle h,
goto done; goto done;
cprintf(cb, "/>"); cprintf(cb, "/>");
} }
if (with_defaults != NULL) if (defaults != NULL)
cprintf(cb, "<with-defaults xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">%s</with-defaults>", with_defaults); cprintf(cb, "<with-defaults xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">%s</with-defaults>", defaults);
cprintf(cb, "</get></rpc>"); cprintf(cb, "</get></rpc>");
if ((msg = clicon_msg_encode(session_id, if ((msg = clicon_msg_encode(session_id,
"%s", cbuf_get(cb))) == NULL) "%s", cbuf_get(cb))) == NULL)