diff --git a/CHANGELOG.md b/CHANGELOG.md index c5e53f55..f05faa26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,9 @@ ### API changes on existing features (you may need to change your code) +* Changed return values in internal functions + * These functions are affected: `netconf_trymerge`, `startup_module_state`, `yang_modules_state_get` + * They now comply to Clixon validation: Error: -1; Invalid: 0; OK: 1. * New Clixon Yang RPC: ping. To check if backup is running. * Try with `]]>]]>` * Restconf with startup feature will now copy all edit changes to startup db (as it should according to RFC 8040) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index cdb9393d..cfed0167 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -158,8 +158,8 @@ backend_client_rm(clicon_handle h, * @param[in] top Top symbol, ie netconf or restconf-state * @param[in,out] xret Existing XML tree, merge x into this * @retval -1 Error (fatal) - * @retval 0 OK - * @retval 1 Statedata callback failed + * @retval 0 Statedata callback failed + * @retval 1 OK */ static int client_get_streams(clicon_handle h, @@ -174,6 +174,7 @@ client_get_streams(clicon_handle h, yang_stmt *yns = NULL; /* yang namespace */ cxobj *x = NULL; cbuf *cb = NULL; + int ret; if ((ystream = yang_find(yspec, Y_MODULE, module)) == NULL){ clicon_err(OE_YANG, 0, "%s yang module not found", module); @@ -195,16 +196,22 @@ client_get_streams(clicon_handle h, if (xml_parse_string(cbuf_get(cb), yspec, &x) < 0){ if (netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0) goto done; - retval = 1; - goto done; + goto fail; } - retval = netconf_trymerge(x, yspec, xret); + if ((ret = netconf_trymerge(x, yspec, xret)) < 0) + goto done; + if (ret == 0) + goto fail; + retval = 1; done: if (cb) cbuf_free(cb); if (x) xml_free(x); return retval; + fail: + retval = 0; + goto done; } /*! Get system state-data, including streams and plugins @@ -212,8 +219,8 @@ client_get_streams(clicon_handle h, * @param[in] xpath Xpath selection, not used but may be to filter early * @param[in,out] xret Existing XML tree, merge x into this * @retval -1 Error (fatal) - * @retval 0 OK - * @retval 1 Statedata callback failed (clicon_err called) + * @retval 0 Statedata callback failed (clicon_err called) + * @retval 1 OK */ static int client_statedata(clicon_handle h, @@ -225,22 +232,34 @@ client_statedata(clicon_handle h, size_t xlen; int i; yang_stmt *yspec; + int ret; if ((yspec = clicon_dbspec_yang(h)) == NULL){ clicon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } - if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277")) - if ((retval = client_get_streams(h, yspec, xpath, "clixon-rfc5277", "netconf", xret)) != 0) + if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277")){ + if ((ret = client_get_streams(h, yspec, xpath, "clixon-rfc5277", "netconf", xret)) < 0) goto done; - if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040")) - if ((retval = client_get_streams(h, yspec, xpath, "ietf-restconf-monitoring", "restconf-state", xret)) != 0) + if (ret == 0) + goto fail; + } + if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040")){ + if ((ret = client_get_streams(h, yspec, xpath, "ietf-restconf-monitoring", "restconf-state", xret)) < 0) goto done; - if (clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895")) - if ((retval = yang_modules_state_get(h, yspec, xpath, 0, xret)) != 0) + if (ret == 0) + goto fail; + } + if (clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895")){ + if ((ret = yang_modules_state_get(h, yspec, xpath, 0, xret)) < 0) goto done; - if ((retval = clixon_plugin_statedata(h, yspec, xpath, xret)) != 0) + if (ret == 0) + goto fail; + } + if ((ret = clixon_plugin_statedata(h, yspec, xpath, xret)) < 0) goto done; + if (ret == 0) + goto fail; /* Code complex to filter out anything that is outside of xpath */ if (xpath_vec(*xret, "%s", &xvec, &xlen, xpath?xpath:"/") < 0) goto done; @@ -259,12 +278,15 @@ client_statedata(clicon_handle h, /* reset flag */ if (xml_apply(*xret, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0) goto done; - retval = 0; /* OK */ + retval = 1; /* OK */ done: clicon_debug(1, "%s %d", __FUNCTION__, retval); if (xvec) free(xvec); return retval; + fail: + retval = 0; + goto done; } /*! Retrieve all or part of a specified configuration. @@ -783,7 +805,7 @@ from_client_get(clicon_handle h, clicon_err_reset(); if ((ret = client_statedata(h, xpath, &xret)) < 0) goto done; - if (ret == 1){ /* Error from callback (error in xret) */ + if (ret == 0){ /* Error from callback (error in xret) */ if (clicon_xml2cbuf(cbret, xret, 0, 0) < 0) goto done; goto ok; diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 19b98c7e..de04d161 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -115,8 +115,8 @@ clixon_plugin_reset(clicon_handle h, * @param[in] xpath String with XPATH syntax. or NULL for all * @param[in,out] xtop State XML tree is merged with existing tree. * @retval -1 Error - * @retval 0 OK - * @retval 1 Statedata callback failed (xret set with netconf-error) + * @retval 0 Statedata callback failed (xret set with netconf-error) + * @retval 1 OK * @note xtop can be replaced */ int @@ -136,24 +136,25 @@ clixon_plugin_statedata(clicon_handle h, continue; if ((x = xml_new("config", NULL, NULL)) == NULL) goto done; - if (fn(h, xpath, x) < 0){ - retval = 1; - goto done; /* Dont quit here on user callbacks */ - } - if ((ret = netconf_trymerge(x, yspec, xret)) != 0){ - retval = ret; + if (fn(h, xpath, x) < 0) + goto fail; /* Dont quit here on user callbacks */ + if ((ret = netconf_trymerge(x, yspec, xret)) < 0) goto done; - } + if (ret == 0) + goto fail; if (x){ xml_free(x); x = NULL; } } - retval = 0; + retval = 1; done: if (x) xml_free(x); return retval; + fail: + retval = 0; + goto done; } /*! Create and initialize transaction */ diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index 367ed627..ee2e3440 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -336,6 +336,8 @@ startup_failsafe(clicon_handle h) /*! Init modules state of the backend (server). To compare with startup XML * Set the modules state as setopt to the datastore module. * Only if CLICON_XMLDB_MODSTATE is enabled + * @retval -1 Error + * @retval 0 OK */ int startup_module_state(clicon_handle h, @@ -343,17 +345,23 @@ startup_module_state(clicon_handle h, { int retval = -1; cxobj *x = NULL; + int ret; if (!clicon_option_bool(h, "CLICON_XMLDB_MODSTATE")) goto ok; /* Set up cache * Now, access brief module cache with clicon_modst_cache_get(h, 1) */ - if (yang_modules_state_get(h, yspec, NULL, 1, &x) < 0) + if ((ret = yang_modules_state_get(h, yspec, NULL, 1, &x)) < 0) goto done; + if (ret == 0) + goto fail; ok: - retval = 0; + retval = 1; done: if (x) xml_free(x); return retval; + fail: + retval = 0; + goto done; } diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index 75d577e5..b02fa04d 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -1048,8 +1048,8 @@ netconf_minmax_elements(cbuf *cb, * @param[in] yspec Yang spec * @param[in,out] xret Existing XML tree, merge x into this * @retval -1 Error (fatal) - * @retval 0 OK - * @retval 1 Statedata callback failed + * @retval 0 Statedata callback failed + * @retval 1 OK */ int netconf_trymerge(cxobj *x, @@ -1072,18 +1072,19 @@ netconf_trymerge(cxobj *x, xml_purge(xc); if (netconf_operation_failed_xml(xret, "rpc", reason)< 0) goto done; - retval = 1; - goto done; + goto fail; } ok: - retval = 0; + retval = 1; done: if (reason) free(reason); return retval; + fail: + retval = 0; + goto done; } - /*! Load ietf netconf yang module and set enabled features * The features added are (in order): * candidate (8.3) diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c index 96593246..d9303061 100644 --- a/lib/src/clixon_yang_module.c +++ b/lib/src/clixon_yang_module.c @@ -255,8 +255,8 @@ yms_build(clicon_handle h, * @param[in] brief Just name, revision and uri (no cache) * @param[in,out] xret Existing XML tree, merge x into this * @retval -1 Error (fatal) - * @retval 0 OK - * @retval 1 Statedata callback failed + * @retval 0 Statedata callback failed + * @retval 1 OK * @notes NYI: schema, deviation x +--ro modules-state x +--ro module-set-id string @@ -288,6 +288,7 @@ yang_modules_state_get(clicon_handle h, char *msid; /* modules-set-id */ cxobj *x1; cbuf *cb = NULL; + int ret; msid = clicon_option_str(h, "CLICON_MODULE_SET_ID"); if ((x = clicon_modst_cache_get(h, brief)) != NULL){ @@ -313,8 +314,7 @@ yang_modules_state_get(clicon_handle h, if (xml_parse_string(cbuf_get(cb), yspec, &x) < 0){ if (netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0) goto done; - retval = 1; - goto done; + goto fail; } if (xml_rootchild(x, 0, &x) < 0) goto done; @@ -326,10 +326,12 @@ yang_modules_state_get(clicon_handle h, /* Wrap x (again) with new top-level node "top" which merge wants */ if ((x = xml_wrap(x, "top")) < 0) goto done; - if (netconf_trymerge(x, yspec, xret) < 0) + if ((ret = netconf_trymerge(x, yspec, xret)) < 0) goto done; + if (ret == 0) + goto fail; } - retval = 0; + retval = 1; done: clicon_debug(1, "%s %d", __FUNCTION__, retval); if (cb) @@ -337,6 +339,9 @@ yang_modules_state_get(clicon_handle h, if (x) xml_free(x); return retval; + fail: + retval = 0; + goto done; } /*! For single module state with namespace, get revisions and send upgrade callbacks