C-style update: Unified comment, retvals in order, remove trailing spaces

Changed function name for `clicon_debug` functions
This commit is contained in:
Olof hagsand 2023-10-22 18:04:47 +02:00
parent 6e314dd96f
commit 62348fc9c7
204 changed files with 6047 additions and 4904 deletions

View file

@ -102,7 +102,7 @@ generic_validate(clicon_handle h,
cbuf *cb = NULL;
/* All entries */
if ((ret = xml_yang_validate_all_top(h, td->td_target, xret)) < 0)
if ((ret = xml_yang_validate_all_top(h, td->td_target, xret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -135,10 +135,11 @@ generic_validate(clicon_handle h,
}
/*! Common startup validation
*
* Get db, upgrade it w potential transformed XML, populate it w yang spec,
* sort it, validate it by triggering a transaction
* and call application callback validations.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The startup database. The wanted backend state
* @param[in] td Transaction data
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
@ -157,7 +158,7 @@ generic_validate(clicon_handle h,
* @see validate_common for incoming validate/commit
*/
static int
startup_common(clicon_handle h,
startup_common(clicon_handle h,
char *db,
transaction_data_t *td,
cbuf *cbret)
@ -177,7 +178,7 @@ startup_common(clicon_handle h,
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
if ((msdiff = modstate_diff_new()) == NULL)
goto done;
clicon_debug(1, "Reading initial config from %s", db);
clixon_debug(CLIXON_DBG_DEFAULT, "Reading initial config from %s", db);
/* Get the startup datastore WITHOUT binding to YANG, sorting and default setting.
* It is done below, later in this function
*/
@ -189,7 +190,7 @@ startup_common(clicon_handle h,
if (clicon_quit_upgrade_get(h) == 1){
xml_print(stderr, xerr);
clicon_err(OE_XML, 0, "invalid configuration before upgrade");
exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
* See similar clause below
*/
}
@ -202,7 +203,7 @@ startup_common(clicon_handle h,
if (xmldb_get0(h, db, YB_NONE, NULL, "/", 0, 0, &xt, msdiff, &xerr) < 0)
goto done;
}
clicon_debug_xml(CLIXON_DBG_DETAIL, xt, "startup");
clixon_debug_xml(CLIXON_DBG_DETAIL, xt, "startup");
if (msdiff && msdiff->md_status == 0){ // Possibly check for CLICON_XMLDB_MODSTATE
clicon_log(LOG_WARNING, "Modstate expected in startup datastore but not found\n"
"This may indicate that the datastore is not initialized corrrectly, such as copy/pasted.\n"
@ -212,7 +213,7 @@ startup_common(clicon_handle h,
clicon_err(OE_YANG, 0, "Yang spec not set");
goto done;
}
clicon_debug(1, "Reading startup config done");
clixon_debug(CLIXON_DBG_DEFAULT, "Reading startup config done");
/* Clear flags xpath for get */
xml_apply0(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
(void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
@ -253,7 +254,7 @@ startup_common(clicon_handle h,
stack. Alternative is to make a separate function stack for this. */
}
/* If empty skip. Note upgrading can add children, so it may be empty before that. */
if (xml_child_nr(xt) == 0){
if (xml_child_nr(xt) == 0){
td->td_target = xt;
xt = NULL;
goto ok;
@ -264,7 +265,7 @@ startup_common(clicon_handle h,
if (ret == 0){
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
goto fail;
goto fail;
}
/* After upgrade check no state data */
if ((ret = xml_non_config_data(xt, &xret)) < 0)
@ -272,7 +273,7 @@ startup_common(clicon_handle h,
if (ret == 0){
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
goto fail;
goto fail;
}
/* Sort xml */
if (xml_sort_recurse(xt) < 0)
@ -283,7 +284,7 @@ startup_common(clicon_handle h,
/* Apply default values (removed in clear function) */
if (xml_default_recurse(xt, 0) < 0)
goto done;
/* Handcraft transition with with only add tree */
td->td_target = xt;
xt = NULL;
@ -291,7 +292,7 @@ startup_common(clicon_handle h,
while ((x = xml_child_each(td->td_target, x, CX_ELMNT)) != NULL){
xml_flag_set(x, XML_FLAG_ADD); /* Also down */
xml_apply(x, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_ADD);
if (cxvec_append(x, &td->td_avec, &td->td_alen) < 0)
if (cxvec_append(x, &td->td_avec, &td->td_alen) < 0)
goto done;
}
@ -301,7 +302,7 @@ startup_common(clicon_handle h,
/* 5. Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
clicon_debug(1, "Validating startup %s", db);
clixon_debug(CLIXON_DBG_DEFAULT, "Validating startup %s", db);
if ((ret = generic_validate(h, yspec, td, &xret)) < 0)
goto done;
if (ret == 0){
@ -328,14 +329,14 @@ startup_common(clicon_handle h,
if (msdiff)
modstate_diff_free(msdiff);
return retval;
fail:
fail:
retval = 0;
goto done;
}
/*! Read startup db, check upgrades and validate it, return upgraded XML
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The startup database. The wanted backend state
* @param[out] xtr (Potentially) transformed XML
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
@ -344,7 +345,7 @@ startup_common(clicon_handle h,
* @retval -1 Error - or validation failed (but cbret not set)
*/
int
startup_validate(clicon_handle h,
startup_validate(clicon_handle h,
char *db,
cxobj **xtr,
cbuf *cbret)
@ -369,7 +370,7 @@ startup_validate(clicon_handle h,
if (xmldb_get0_clear(h, td->td_target) < 0)
goto done;
if (xtr){
*xtr = td->td_target;
*xtr = td->td_target;
td->td_target = NULL;
}
retval = 1;
@ -386,7 +387,7 @@ startup_validate(clicon_handle h,
/*! Read startup db, check upgrades and commit it
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The startup database. The wanted backend state
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
* @retval 1 Validation OK
@ -395,7 +396,7 @@ startup_validate(clicon_handle h,
* Only called from startup_mode_startup
*/
int
startup_commit(clicon_handle h,
startup_commit(clicon_handle h,
char *db,
cbuf *cbret)
{
@ -426,7 +427,7 @@ startup_commit(clicon_handle h,
/* [Delete and] create running db */
if (xmldb_exists(h, "running") == 1){
if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
goto done;;
}
if (xmldb_create(h, "running") < 0)
@ -463,9 +464,10 @@ startup_commit(clicon_handle h,
}
/*! Validate a candidate db and comnpare to running
*
* Get both source and dest datastore, validate target, compute diffs
* and call application callback validations.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The (candidate) database. The wanted backend state
* @param[in] td Transaction data
* @param[out] xret Error XML tree, if retval is 0. Free with xml_free after use
@ -477,7 +479,7 @@ startup_commit(clicon_handle h,
* @see startup_common for startup scenario
*/
static int
validate_common(clicon_handle h,
validate_common(clicon_handle h,
char *db,
transaction_data_t *td,
cxobj **xret)
@ -487,11 +489,11 @@ validate_common(clicon_handle h,
int i;
cxobj *xn;
int ret;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
}
}
/* This is the state we are going to */
if ((ret = xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, 0, &td->td_target, NULL, xret)) < 0)
goto done;
@ -500,7 +502,7 @@ validate_common(clicon_handle h,
/* Clear flags xpath for get */
xml_apply0(td->td_target, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
(void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
/* 2. Parse xml trees
/* 2. Parse xml trees
* This is the state we are going from */
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, 0, &td->td_src, NULL, xret)) < 0)
goto done;
@ -520,7 +522,7 @@ validate_common(clicon_handle h,
&td->td_tcvec, /* changed: wanted values */
&td->td_clen) < 0)
goto done;
if (clicon_debug_get() & CLIXON_DBG_DETAIL)
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
transaction_dbg(h, CLIXON_DBG_DETAIL, td, __FUNCTION__);
/* Mark as changed in tree */
for (i=0; i<td->td_dlen; i++){ /* Also down */
@ -571,7 +573,7 @@ validate_common(clicon_handle h,
/*! Start a validate transaction
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db A candidate database, typically "candidate" but not necessarily so
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
* @retval 1 Validation OK
@ -579,7 +581,7 @@ validate_common(clicon_handle h,
* @retval -1 Error - or validation failed
*/
int
candidate_validate(clicon_handle h,
candidate_validate(clicon_handle h,
char *db,
cbuf *cbret)
{
@ -587,8 +589,8 @@ candidate_validate(clicon_handle h,
transaction_data_t *td = NULL;
cxobj *xret = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (db == NULL || cbret == NULL){
clicon_err(OE_CFG, EINVAL, "db or cbret is NULL");
goto done;
@ -647,7 +649,7 @@ candidate_validate(clicon_handle h,
* The code reverts changes if the commit fails. But if the revert
* fails, we just ignore the errors and proceed. Maybe we should
* do something more drastic?
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc> (or NULL)
* @param[in] db A candidate database, not necessarily "candidate"
* @param[in] myid Client id of triggering incoming message (or 0)
@ -658,7 +660,7 @@ candidate_validate(clicon_handle h,
* @retval -1 Error - or validation failed
*/
int
candidate_commit(clicon_handle h,
candidate_commit(clicon_handle h,
cxobj *xe,
char *db,
uint32_t myid,
@ -713,7 +715,7 @@ candidate_commit(clicon_handle h,
/* After commit, make a post-commit call (sure that all plugins have committed) */
if (plugin_transaction_commit_done_all(h, td) < 0)
goto done;
/* Clear cached trees from default values and marking */
if (xmldb_get0_clear(h, td->td_target) < 0)
goto done;
@ -738,7 +740,6 @@ candidate_commit(clicon_handle h,
/* 9. Call plugin transaction end callbacks */
plugin_transaction_end_all(h, td);
retval = 1;
done:
/* In case of failure (or error), call plugin transaction termination callbacks */
@ -759,11 +760,11 @@ candidate_commit(clicon_handle h,
/*! Commit the candidate configuration as the device's new current configuration
*
* @param[in] h Clicon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
* @param[in] regarg User argument given at rpc_callback_register()
* @param[in] regarg User argument given at rpc_callback_register()
* @retval 0 OK
* @retval -1 Error
* @note NACM: The server MUST determine the exact nodes in the running
@ -815,13 +816,13 @@ from_client_commit(clicon_handle h,
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
if (netconf_in_use(cbret, "protocol", "Operation failed, lock is already held") < 0)
goto done;
goto ok;
}
if ((ret = candidate_commit(h, xe, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */
clicon_debug(1, "Commit candidate failed");
clixon_debug(CLIXON_DBG_DEFAULT, "Commit candidate failed");
if (ret < 0)
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
goto done;
@ -839,13 +840,12 @@ from_client_commit(clicon_handle h,
/*! Revert the candidate configuration to the current running configuration.
*
* @param[in] h Clicon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
* @param[in] regarg User argument given at rpc_callback_register()
* @retval 0 OK. This may indicate both ok and err msg back to client
* @retval 0 OK
* @param[in] regarg User argument given at rpc_callback_register()
* @retval 0 OK. This may indicate both ok and err msg back to client
* @retval -1 Error
* NACM: No datastore permissions are needed.
*/
@ -861,14 +861,14 @@ from_client_discard_changes(clicon_handle h,
uint32_t myid = ce->ce_id;
uint32_t iddb;
cbuf *cbx = NULL; /* Assist cbuf */
/* Check if target locked by other client */
iddb = xmldb_islocked(h, "candidate");
if (iddb && myid != iddb){
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
cprintf(cbx, "<session-id>%u</session-id>", iddb);
if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0)
goto done;
@ -890,11 +890,12 @@ from_client_discard_changes(clicon_handle h,
}
/*! Validates the contents of the specified configuration.
* @param[in] h Clicon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
*
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
* @param[in] regarg User argument given at rpc_callback_register()
* @param[in] regarg User argument given at rpc_callback_register()
* @retval 0 OK. This may indicate both ok and err msg back to client
* (eg invalid)
* @retval -1 Error
@ -910,7 +911,7 @@ from_client_validate(clicon_handle h,
int ret;
char *db;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((db = netconf_db_find(xe, "source")) == NULL){
if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
goto done;
@ -927,6 +928,7 @@ from_client_validate(clicon_handle h,
} /* from_client_validate */
/*! Restart specific backend plugins without full backend restart
*
* Note, depending on plugin callbacks, there may be other dependencies which may make this
* difficult in the general case.
*/
@ -945,7 +947,7 @@ from_client_restart_one(clicon_handle h,
int i;
cxobj *xn;
void *wh = NULL;
yspec = clicon_dbspec_yang(h);
if (xmldb_db_reset(h, db) < 0)
goto done;
@ -955,7 +957,7 @@ from_client_restart_one(clicon_handle h,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if ((retval = resetfn(h, db)) < 0) {
clicon_debug(1, "plugin_start() failed");
clixon_debug(CLIXON_DBG_DEFAULT, "plugin_start() failed");
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -1049,7 +1051,7 @@ from_client_restart_one(clicon_handle h,
}
/*! Reset running and start in failsafe mode. If no failsafe then quit.
*
*
* param[in] h Clixon handle
* param[in] phase Debug string
Typically done when startup status is not OK so