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

@ -104,8 +104,8 @@ ce_event_cb(clicon_handle h,
void *arg)
{
struct client_entry *ce = (struct client_entry *)arg;
clicon_debug(1, "%s op:%d", __FUNCTION__, op);
clixon_debug(CLIXON_DBG_DEFAULT, "%s op:%d", __FUNCTION__, op);
switch (op){
case 1:
/* Risk of recursion here */
@ -140,7 +140,7 @@ ce_client_string(struct client_entry *ce,
int retval = -1;
cbuf *cb = NULL;
char *id = NULL;
if (ce == NULL || cbp == NULL){
clicon_err(OE_UNIX, EINVAL, "ce or cbp is NULL");
goto done;
@ -273,7 +273,7 @@ backend_monitoring_state_get(clicon_handle h,
goto fail;
retval = 1;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
return retval;
@ -293,7 +293,7 @@ backend_monitoring_state_get(clicon_handle h,
* @see backend_client_delete for actual deallocation of client entry struct
*/
int
backend_client_rm(clicon_handle h,
backend_client_rm(clicon_handle h,
struct client_entry *ce)
{
struct client_entry *c;
@ -311,10 +311,10 @@ backend_client_rm(clicon_handle h,
if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
if (confirmed_commit_state_get(h) == EPHEMERAL) {
/* See if this client is the origin */
clicon_debug(1, "session_id: %u, confirmed_commit.session_id: %u", ce->ce_id, confirmed_commit_session_id_get(h));
clixon_debug(CLIXON_DBG_DEFAULT, "session_id: %u, confirmed_commit.session_id: %u", ce->ce_id, confirmed_commit_session_id_get(h));
if (myid == confirmed_commit_session_id_get(h)) {
clicon_debug(1, "ok, rolling back");
clixon_debug(CLIXON_DBG_DEFAULT, "ok, rolling back");
clicon_log(LOG_NOTICE, "a client with an active ephemeral confirmed-commit has disconnected; rolling back");
/* do_rollback errors are logged internally and there is no client to report errors to, so errors are
@ -326,7 +326,7 @@ backend_client_rm(clicon_handle h,
}
}
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* for all streams: XXX better to do it top-level? */
stream_ss_delete_all(h, ce_event_cb, (void*)ce);
c0 = backend_client_list(h);
@ -367,8 +367,8 @@ clixon_stats_datastore_get(clicon_handle h,
uint64_t nr = 0;
size_t sz = 0;
cxobj *xn = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, dbname);
clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, dbname);
/* This is the db cache */
if ((xt = xmldb_cache_get(h, dbname)) == NULL){
/* Trigger cache if no exist (trick to ensure cache is present) */
@ -409,7 +409,7 @@ clixon_stats_module_get(clicon_handle h,
uint64_t nr = 0;
size_t sz = 0;
cxobj *xn = NULL;
if (ys == NULL)
return 0;
if (yang_stats(ys, &nr, &sz) < 0)
@ -439,7 +439,7 @@ clixon_stats_module_get(clicon_handle h,
* However, what really should be done is to apply the change to the datastore and then
* validate, if error, discard to previous state.
* But this could discard other previous changes to candidate.
*/
*/
static int
from_client_edit_config(clicon_handle h,
cxobj *xn,
@ -480,7 +480,7 @@ from_client_edit_config(clicon_handle h,
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
/* Check if target locked by other client */
iddb = xmldb_islocked(h, target);
if (iddb && myid != iddb){
@ -645,22 +645,21 @@ from_client_edit_config(clicon_handle h,
xml_free(xret);
if (cbx)
cbuf_free(cbx);
clicon_debug(1, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret));
clixon_debug(CLIXON_DBG_DEFAULT, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret));
return retval;
} /* from_client_edit_config */
/*! Create or replace an entire config with another complete config db
*
* @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] 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
* NACM: If source running and target startup --> only exec permission
* else:
* else:
* - omit data nodes to which the client does not have read access
* - access denied if user lacks create/delete/update
*/
@ -679,7 +678,7 @@ from_client_copy_config(clicon_handle h,
uint32_t myid = ce->ce_id;
cbuf *cbx = NULL; /* Assist cbuf */
cbuf *cbmsg = NULL;
if ((source = netconf_db_find(xe, "source")) == NULL){
if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
goto done;
@ -688,7 +687,7 @@ from_client_copy_config(clicon_handle h,
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
if ((target = netconf_db_find(xe, "target")) == NULL){
if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
goto done;
@ -727,10 +726,10 @@ from_client_copy_config(clicon_handle h,
/*! Delete a configuration datastore.
*
* @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] 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
*/
@ -738,7 +737,7 @@ static int
from_client_delete_config(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *arg,
void *regarg)
{
int retval = -1;
@ -759,7 +758,7 @@ from_client_delete_config(clicon_handle h,
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
/* Check if target locked by other client */
iddb = xmldb_islocked(h, target);
if (iddb && myid != iddb){
@ -801,12 +800,12 @@ from_client_delete_config(clicon_handle h,
}
/*! Lock the configuration system of a device
*
*
* @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] 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
*/
@ -814,7 +813,7 @@ static int
from_client_lock(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *arg,
void *regarg)
{
int retval = -1;
@ -838,7 +837,7 @@ from_client_lock(clicon_handle h,
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
/*
* A lock MUST not be granted if either of the following conditions is true:
* 1) A lock is already held by any NETCONF session or another entity.
@ -889,11 +888,11 @@ from_client_lock(clicon_handle h,
/*! Release a configuration lock previously obtained with the 'lock' operation
*
* @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] 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
*/
@ -919,9 +918,9 @@ from_client_unlock(clicon_handle h,
if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
iddb = xmldb_islocked(h, db);
/*
/*
* An unlock operation will not succeed if any of the following
* conditions are true:
* 1) the specified lock is not currently active
@ -944,7 +943,7 @@ from_client_unlock(clicon_handle h,
else{
xmldb_unlock(h, db);
/* user callback */
if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
goto done;
if (cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE) < 0)
goto done;
@ -959,7 +958,7 @@ from_client_unlock(clicon_handle h,
/*! Request graceful termination of a NETCONF session.
*
* @param[in] h Clixon handle
* @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
@ -971,7 +970,7 @@ static int
from_client_close_session(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *arg,
void *regarg)
{
struct client_entry *ce = (struct client_entry *)arg;
@ -986,11 +985,11 @@ from_client_close_session(clicon_handle h,
/*! Internal message: Force the termination of a NETCONF session.
*
* @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] 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
*/
@ -1009,7 +1008,7 @@ from_client_kill_session(clicon_handle h,
cxobj *x;
int ret;
char *reason = NULL;
if ((x = xml_find(xe, "session-id")) == NULL ||
(str = xml_find_value(x, "body")) == NULL){
if (netconf_missing_element(cbret, "protocol", "session-id", NULL) < 0)
@ -1029,7 +1028,7 @@ from_client_kill_session(clicon_handle h,
if (xmldb_islocked(h, db) == id){
xmldb_unlock(h, db);
/* user callback */
if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
goto done;
}
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
@ -1043,11 +1042,11 @@ from_client_kill_session(clicon_handle h,
/*! Create a notification subscription
*
* @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] 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
* @see RFC5277 2.1
@ -1063,7 +1062,7 @@ static int
from_client_create_subscription(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *arg,
void *regarg)
{
int retval = -1;
@ -1078,7 +1077,7 @@ from_client_create_subscription(clicon_handle h,
struct timeval start;
struct timeval stop;
cvec *nsc = NULL;
/* XXX should use prefix cf edit_config */
if ((nsc = xml_nsctx_init(NULL, EVENT_RFC5277_NAMESPACE)) == NULL)
goto done;
@ -1089,7 +1088,7 @@ from_client_create_subscription(clicon_handle h,
str2time(stoptime, &stop) < 0){
if (netconf_bad_element(cbret, "application", "stopTime", "Expected timestamp") < 0)
goto done;
goto ok;
goto ok;
}
}
if ((x = xpath_first(xe, nsc, "//startTime")) != NULL){
@ -1097,8 +1096,8 @@ from_client_create_subscription(clicon_handle h,
str2time(starttime, &start) < 0){
if (netconf_bad_element(cbret, "application", "startTime", "Expected timestamp") < 0)
goto done;
goto ok;
}
goto ok;
}
}
if ((xfilter = xpath_first(xe, nsc, "//filter")) != NULL){
if ((ftype = xml_find_value(xfilter, "type")) != NULL){
@ -1122,13 +1121,13 @@ from_client_create_subscription(clicon_handle h,
starttime?&start:NULL, stoptime?&stop:NULL,
ce_event_cb, (void*)ce) < 0)
goto done;
/* Replay of this stream to specific subscription according to start and
/* Replay of this stream to specific subscription according to start and
* stop (if present).
* RFC 5277: If <startTime> is not present, this is not a replay
* subscription.
* Schedule the replay to occur right after this RPC completes, eg "now"
*/
if (starttime){
if (starttime){
if (stream_replay_trigger(h, stream, ce_event_cb, (void*)ce) < 0)
goto done;
}
@ -1143,7 +1142,7 @@ from_client_create_subscription(clicon_handle h,
/*! Retrieve a schema from the NETCONF server.
*
* @param[in] h Clixon handle
* @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
@ -1156,7 +1155,7 @@ static int
from_client_get_schema(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *arg,
void *regarg)
{
int retval = -1;
@ -1171,7 +1170,7 @@ from_client_get_schema(clicon_handle h,
yang_stmt *yrev;
cbuf *cbyang = NULL;
cbuf *cbmsg = NULL;
const char *filename;
const char *filename;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec");
@ -1221,7 +1220,7 @@ from_client_get_schema(clicon_handle h,
if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
if (version)
cprintf(cbmsg, "No schema matching: %s@%s", identifier, version);
else
@ -1234,7 +1233,7 @@ from_client_get_schema(clicon_handle h,
if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
}
cprintf(cbmsg, "Format not supported: %s", format);
if (netconf_invalid_value(cbret, "protocol", cbuf_get(cbmsg)) < 0)
goto done;
@ -1264,11 +1263,11 @@ from_client_get_schema(clicon_handle h,
return retval;
}
/*! Set debug level.
/*! Set debug level.
*
* @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] 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
@ -1284,7 +1283,7 @@ from_client_debug(clicon_handle h,
int retval = -1;
uint32_t level;
char *valstr;
if ((valstr = xml_find_body(xe, "level")) == NULL){
if (netconf_missing_element(cbret, "application", "level", NULL) < 0)
goto done;
@ -1292,9 +1291,9 @@ from_client_debug(clicon_handle h,
}
level = atoi(valstr);
clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
setlogmask(LOG_UPTO(level?LOG_DEBUG:LOG_INFO)); /* for syslog */
clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, clicon_debug_get());
clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, clixon_debug_get());
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
@ -1304,11 +1303,11 @@ from_client_debug(clicon_handle h,
/*! Check liveness of backend daemon, just send a reply
*
* @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] 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
*/
@ -1325,11 +1324,11 @@ from_client_ping(clicon_handle h,
/*! Check liveness of backend daemon, just send a reply
*
* @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] 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
*/
@ -1348,7 +1347,7 @@ from_client_stats(clicon_handle h,
yang_stmt *yspec;
yang_stmt *ymodext;
cxobj *xt = NULL;
if ((str = xml_find_body(xe, "modules")) != NULL)
modules = strcmp(str, "true") == 0;
yspec = clicon_dbspec_yang(h);
@ -1378,7 +1377,7 @@ from_client_stats(clicon_handle h,
goto done;
if (modules){
ym = NULL;
while ((ym = yn_each(yspec, ym)) != NULL) {
while ((ym = yn_each(yspec, ym)) != NULL) {
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
if (clixon_stats_module_get(h, ym, cbret) < 0)
goto done;
@ -1418,11 +1417,11 @@ from_client_stats(clicon_handle h,
/*! Request restart of specific plugins
*
* @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] 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
*/
@ -1440,8 +1439,8 @@ from_client_restart_plugin(clicon_handle h,
int i;
clixon_plugin_t *cp;
int ret;
if (xpath_vec(xe, NULL, "plugin", &vec, &veclen) < 0)
if (xpath_vec(xe, NULL, "plugin", &vec, &veclen) < 0)
goto done;
for (i=0; i<veclen; i++){
name = xml_body(vec[i]);
@ -1466,11 +1465,11 @@ from_client_restart_plugin(clicon_handle h,
/*! Control a specific process or daemon: start/stop, etc
*
* @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] 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
*/
@ -1486,7 +1485,7 @@ from_client_process_control(clicon_handle h,
char *name = NULL;
char *opstr = NULL;
proc_operation op = PROC_OP_NONE;
if ((x = xml_find_type(xe, NULL, "name", CX_ELMNT)) != NULL)
name = xml_body(x);
if ((x = xml_find_type(xe, NULL, "operation", CX_ELMNT)) != NULL){
@ -1557,7 +1556,7 @@ from_client_hello(clicon_handle h,
*/
static int
from_client_msg(clicon_handle h,
struct client_entry *ce,
struct client_entry *ce,
struct clicon_msg *msg)
{
int retval = -1;
@ -1581,9 +1580,9 @@ from_client_msg(clicon_handle h,
char *namespace = NULL;
int nr = 0;
cbuf *cbce = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
yspec = clicon_dbspec_yang(h);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
yspec = clicon_dbspec_yang(h);
/* Return netconf message. Should be filled in by the dispatch(sub) functions
* as wither rpc-error or by positive response.
*/
@ -1629,7 +1628,7 @@ from_client_msg(clicon_handle h,
* 3. Its a create-subscription message that uses a separate socket(=client)
*/
if (op_id != 0 && ce->ce_id != op_id && strcmp(rpcname, "create-subscription")){
clicon_debug(1, "%s Warning: incoming session-id:%u does not match ce_id:%u on socket: %d", __FUNCTION__, op_id, ce->ce_id, ce->ce_s);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Warning: incoming session-id:%u does not match ce_id:%u on socket: %d", __FUNCTION__, op_id, ce->ce_id, ce->ce_s);
}
/* Note that this validation is also made in xml_yang_validate_rpc, but not for hello
*/
@ -1707,7 +1706,7 @@ from_client_msg(clicon_handle h,
goto done;
}
module = yang_argument_get(ymod);
clicon_debug(CLIXON_DBG_DEFAULT, "%s module:%s rpc:%s ce_id:%u s:%d", __FUNCTION__, module,
clixon_debug(CLIXON_DBG_DEFAULT, "%s module:%s rpc:%s ce_id:%u s:%d", __FUNCTION__, module,
rpc, ce->ce_id, ce->ce_s);
/* Pre-NACM access step */
xnacm = NULL;
@ -1773,7 +1772,7 @@ from_client_msg(clicon_handle h,
if (cbuf_len(cbret) == 0)
if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0)
goto done;
// XXX clicon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret));
// XXX clixon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret));
/* XXX problem here is that cbret has not been parsed so may contain
parse errors */
if (ce_client_string(ce, &cbce) < 0)
@ -1797,8 +1796,8 @@ from_client_msg(clicon_handle h,
}
// ok:
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
done:
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
if (xnacm){
xml_free(xnacm);
if (clicon_nacm_cache_set(h, NULL) < 0)
@ -1813,10 +1812,10 @@ from_client_msg(clicon_handle h,
if (cbret)
cbuf_free(cbret);
/* Sanity: log if clicon_err() is not called ! */
if (retval < 0 && clicon_errno < 0)
if (retval < 0 && clicon_errno < 0)
clicon_log(LOG_NOTICE, "%s: Internal error: No clicon_err call on RPC error (message: %s)",
__FUNCTION__, rpc?rpc:"");
// clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
// clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;// -1 here terminates backend
}
@ -1829,7 +1828,7 @@ from_client_msg(clicon_handle h,
* propagated back to client.
*/
int
from_client(int s,
from_client(int s,
void* arg)
{
int retval = -1;
@ -1839,7 +1838,7 @@ from_client(int s,
int eof = 0;
cbuf *cbce = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (s != ce->ce_s){
clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s");
goto done;
@ -1849,7 +1848,7 @@ from_client(int s,
if (clicon_msg_rcv(ce->ce_s, cbuf_get(cbce), 0, &msg, &eof) < 0)
goto done;
if (eof){
backend_client_rm(h, ce);
backend_client_rm(h, ce);
netconf_monitoring_counter_inc(h, "dropped-sessions");
}
else
@ -1857,7 +1856,7 @@ from_client(int s,
goto done;
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval=%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval=%d", __FUNCTION__, retval);
if (cbce)
cbuf_free(cbce);
if (msg)

View file

@ -39,7 +39,7 @@
/*
* Prototypes
*/
*/
int backend_monitoring_state_get(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
int backend_client_rm(clicon_handle h, struct client_entry *ce);
int from_client(int fd, void *arg);

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

View file

@ -105,6 +105,7 @@ confirmed_commit_init(clicon_handle h)
}
/*! If confirm commit persist-id exists, free it
*
* @param[in] h Clixon handle
* @retval 0 OK
*/
@ -112,7 +113,7 @@ int
confirmed_commit_free(clicon_handle h)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
if (cc != NULL){
if (cc->cc_persist_id != NULL)
@ -130,7 +131,7 @@ enum confirmed_commit_state
confirmed_commit_state_get(clicon_handle h)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
return cc->cc_state;
}
@ -140,7 +141,7 @@ confirmed_commit_state_set(clicon_handle h,
enum confirmed_commit_state state)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
cc->cc_state = state;
return 0;
@ -150,7 +151,7 @@ char *
confirmed_commit_persist_id_get(clicon_handle h)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
return cc->cc_persist_id;
}
@ -160,7 +161,7 @@ confirmed_commit_persist_id_set(clicon_handle h,
char *persist_id)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
if (cc->cc_persist_id)
free(cc->cc_persist_id);
@ -179,7 +180,7 @@ uint32_t
confirmed_commit_session_id_get(clicon_handle h)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
return cc->cc_session_id;
}
@ -189,7 +190,7 @@ confirmed_commit_session_id_set(clicon_handle h,
uint32_t session_id)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
cc->cc_session_id = session_id;
return 0;
@ -201,7 +202,7 @@ confirmed_commit_fn_arg_get(clicon_handle h,
void **arg)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
*fn = cc->cc_fn;
*arg = cc->cc_arg;
@ -214,7 +215,7 @@ confirmed_commit_fn_arg_set(clicon_handle h,
void *arg)
{
struct confirmed_commit *cc = NULL;
clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc);
cc->cc_fn = fn;
cc->cc_arg = arg;
@ -222,6 +223,7 @@ confirmed_commit_fn_arg_set(clicon_handle h,
}
/*! Return if confirmed tag found
*
* @param[in] xe Commit rpc xml
* @retval 1 Confirmed tag exists
* @retval 0 Confirmed tag does not exist
@ -233,6 +235,7 @@ xe_confirmed(cxobj *xe)
}
/*! Return if persist exists and its string value field
*
* @param[in] xe Commit rpc xml
* @param[out] str Pointer to persist
* @retval 1 Persist field exists
@ -274,6 +277,7 @@ xe_persist_id(cxobj *xe,
}
/*! Return timeout
*
* @param[in] xe Commit rpc xml
* @retval sec Timeout in seconds, can be 0 if no timeout exists or is zero
*/
@ -282,7 +286,7 @@ xe_timeout(cxobj *xe)
{
cxobj *xml;
char *str;
if ((xml = xml_find_type(xe, NULL, "confirm-timeout", CX_ELMNT)) != NULL &&
(str = xml_body(xml)) != NULL)
return strtoul(str, NULL, 10);
@ -293,7 +297,7 @@ xe_timeout(cxobj *xe)
*
* @param[in] h Clixon handle
* @retval 0 Rollback event successfully cancelled
* @retval -1 No Rollback event was found
* @retval -1 No Rollback event was found
*/
int
cancel_rollback_event(clicon_handle h)
@ -317,7 +321,7 @@ cancel_rollback_event(clicon_handle h)
* @param[in] fd a dummy argument per the event callback semantics
* @param[in] arg a void pointer to a clicon_handle
* @retval 0 the rollback was successful
* @retval -1 the rollback failed
* @retval -1 the rollback failed
* @see do_rollback()
*/
static int
@ -337,7 +341,7 @@ rollback_fn(int fd,
* @param[in] timeout a uint32 representing the number of seconds before the rollback event should fire
*
* @retval 0 Rollback event successfully scheduled
* @retval -1 Rollback event was not scheduled
* @retval -1 Rollback event was not scheduled
*/
static int
schedule_rollback_event(clicon_handle h,
@ -373,6 +377,7 @@ schedule_rollback_event(clicon_handle h,
}
/*! Cancel a confirming commit by removing rollback, and free state
*
* @param[in] h
* @param[out] cbret
* @retval 0 OK
@ -401,12 +406,12 @@ cancel_confirmed_commit(clicon_handle h)
* without a <persist> value, OR
* 2) be presented with a <persist-id> value that matches the <persist> value accompanying the prior confirmed-commit
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] myid current client session-id
* @retval 1 The confirming-commit is valid
* @retval 0 The confirming-commit is not valid
* @retval -1 Error
* @retval -1 Error
*/
static int
check_valid_confirming_commit(clicon_handle h,
@ -452,7 +457,7 @@ check_valid_confirming_commit(clicon_handle h,
"not issued on the same session as the confirmed-commit");
goto invalid;
default:
clicon_debug(1, "commit-confirmed state !? %d", confirmed_commit_state_get(h));
clixon_debug(CLIXON_DBG_DEFAULT, "commit-confirmed state !? %d", confirmed_commit_state_get(h));
goto invalid;
}
retval = 1; // valid
@ -471,11 +476,11 @@ check_valid_confirming_commit(clicon_handle h,
* In the second phase, the action taken is to handle both confirming- and confirmed-commit by creating the
* rollback database as required, then deleting it once the sequence is complete.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Commit rpc xml or NULL
* @param[in] myid Current session-id, only valid > 0 if call is made as a result of an incoming message
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
* @note There are some calls to this function where myid is 0 (which is invalid). It is unclear if such calls
* actually occur, and if so, if they are correctly handled. The calls are from do_rollback() and load_failsafe()
*/
@ -622,9 +627,9 @@ handle_confirmed_commit(clicon_handle h,
* 2. from_client_cancel_commit() (invoked either by netconf client, or CLI)
* 3. rollback_fn() (invoked by expiration of the rollback event timer)
*
* @param[in] h Clicon handle
* @retval -1 Error
* @param[in] h Clixon handle
* @retval 0 Success
* @retval -1 Error
* @see backend_client_rm()
* @see from_client_cancel_commit()
* @see rollback_fn()
@ -696,12 +701,13 @@ do_rollback(clicon_handle h,
}
/*! Cancel an ongoing confirmed commit.
*
* If the confirmed commit is persistent, the parameter 'persist-id' must be
* given, and it must match the value of the 'persist' parameter.
* If the confirmed-commit is ephemeral, the 'persist-id' must not be given and both the confirmed-commit and the
* cancel-commit must originate from the same session.
*
* @param[in] h Clicon handle
* @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
@ -777,7 +783,8 @@ from_client_cancel_commit(clicon_handle h,
}
/*! Incoming commit handler for confirmed commit
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] myid Client-id
* @param[out] cbret Return xml tree

View file

@ -72,12 +72,15 @@
#include "backend_handle.h"
#include "backend_get.h"
/*!
/*! restrconf get capabilities
*
* Maybe should be in the restconf client instead of backend?
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xpath Xpath selection, not used but may be to filter early
* @param[out] xrs XML restconf-state node
* @retval 0 OK
* @retval -1 Error
* @see netconf_hello_server
* @see rfc8040 Sections 9.1
*/
@ -114,7 +117,8 @@ restconf_client_get_capabilities(clicon_handle h,
}
/*! Get streams state according to RFC 8040 or RFC5277 common function
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xpath Xpath selection, not used but may be to filter early
* @param[in] module Name of yang module
@ -176,7 +180,8 @@ client_get_streams(clicon_handle h,
}
/*! Get system state-data, including streams and plugins
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xpath XPath selection, may be used to filter early
* @param[in] nsc XML Namespace context for xpath
* @param[in] wdef With-defaults parameter, see RFC 6243
@ -213,7 +218,7 @@ get_statedata(clicon_handle h,
cbuf *cb = NULL;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec");
goto done;
@ -368,7 +373,7 @@ get_statedata(clicon_handle h,
} /* switch wdef */
retval = 1; /* OK */
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (xerr)
xml_free(xerr);
if (x1)
@ -390,7 +395,7 @@ get_statedata(clicon_handle h,
* and we need to re-add it.
* Note original xpath
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xret Result XML tree
* @param[in] xvec xpath lookup result on xret
@ -438,7 +443,7 @@ filter_xpath_again(clicon_handle h,
/*! Help function for NACM access and return message
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xret Result XML tree
* @param[in] xvec xpath lookup result on xret
* @param[in] xlen length of xvec
@ -520,7 +525,7 @@ element2value(clicon_handle h,
/*! Extract offset and limit from get/list-pagination
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] offset Number of entries in the working result-set that should be skipped
* @param[out] limit Limits the number of entries returned from the working result-set
@ -552,7 +557,7 @@ list_pagination_hdr(clicon_handle h,
*
* It is specialized enough to have its own function. Specifically, extra attributes as well
* as the list-paginaiton API
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] ce Client entry, for locking
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] content Get config/state/both
@ -764,7 +769,7 @@ get_list_pagination(clicon_handle h,
if ((ret = xml_bind_yang(h, xret, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_debug_xml(1, xret, "Yang bind pagination state");
clixon_debug_xml(1, xret, "Yang bind pagination state");
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML",
NULL) < 0)
@ -821,7 +826,7 @@ get_list_pagination(clicon_handle h,
/*! Common get/get-config code for retrieving configuration and state information.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] ce Client entry, for locking
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] content Get config/state/both
@ -867,7 +872,7 @@ get_common(clicon_handle h,
char *wdefstr;
wdef = WITHDEFAULTS_EXPLICIT;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec9");
@ -1013,7 +1018,7 @@ get_common(clicon_handle h,
(ret = xml_yang_validate_add(h, xret, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_debug_xml(1, xret, "VALIDATE_STATE");
clixon_debug_xml(1, xret, "VALIDATE_STATE");
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML",
NULL) < 0)
@ -1044,7 +1049,7 @@ get_common(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
free(xvec);
if (xret)
@ -1067,12 +1072,12 @@ get_common(clicon_handle h,
}
/*! Retrieve all or part of a 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
* @retval -1 Error
* @see from_client_get
@ -1099,11 +1104,11 @@ from_client_get_config(clicon_handle h,
/*! Retrieve running configuration and device state information.
*
* @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
*
@ -1113,13 +1118,13 @@ int
from_client_get(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *arg,
void *regarg)
{
netconf_content content = CONTENT_ALL;
char *attr;
struct client_entry *ce = (struct client_entry *)arg;
/* Clixon extensions: content */
if ((attr = xml_find_value(xe, "content")) != NULL)
content = netconf_content_str2int(attr);

View file

@ -39,7 +39,7 @@
/*
* Prototypes
*/
*/
int from_client_get_config(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_get(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_get_pageable_list(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); /* XXX */

View file

@ -84,6 +84,7 @@
#define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log"
/*! Clean and close all state of backend (but dont exit).
*
* Cannot use h after this
* @param[in] h Clixon handle
*/
@ -99,7 +100,7 @@ backend_terminate(clicon_handle h)
int ss;
cvec *nsctx;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ss = clicon_socket_get(h)) != -1)
close(ss);
/* Disconnect datastore */
@ -142,7 +143,7 @@ backend_terminate(clicon_handle h)
unlink(sockpath);
backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */
clixon_event_exit();
clicon_debug(1, "%s done", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
clixon_err_exit();
clicon_log_exit();
return 0;
@ -163,19 +164,21 @@ backend_sig_term(int arg)
clixon_exit_set(1); /* checked in clixon_event_loop() */
}
/*! wait for killed child
/*! Wait for killed child
*
* primary use in case restconf daemon forked using process-control API
* This may cause EINTR in eg select() in clixon_event_loop() which will be ignored
*/
static void
backend_sig_child(int arg)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
clicon_sig_child_set(1);
}
/*! Create backend server socket and register callback
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval s Server socket file descriptor (see socket(2))
* @retval -1 Error
*/
@ -278,7 +281,7 @@ xmldb_drop_priv(clicon_handle h,
* - uid is currently 0 (started as root)
* - CLICON_BACKEND_USER is set
* - CLICON_BACKEND_PRIVILEGES is not "none"
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] gid Group id (assume already known)
* @retval 0 OK
* @retval -1 Error
@ -425,7 +428,7 @@ backend_timer_setup(int fd,
struct timeval t;
struct timeval t1 = {10, 0};
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
gettimeofday(&now, NULL);
backend_client_print(h, stderr);
@ -588,7 +591,7 @@ main(int argc,
* double syslogs until fork below.
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Find and read configfile */
@ -1082,7 +1085,7 @@ main(int argc,
clicon_session_id_set(h, 1);
#if 0 /* debug */
/* Enable this to get prints of datastore and session status */
if (0 && clicon_debug_get() &&
if (clixon_debug_get() &&
backend_timer_setup(0, h) < 0)
goto done;
#endif

View file

@ -68,7 +68,7 @@
*
* The system 'state' should be the same as the contents of running_db
* @param[in] cp Plugin handle
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of datastore
* @retval 0 OK
* @retval -1 Error
@ -89,7 +89,7 @@ clixon_plugin_reset_one(clixon_plugin_t *cp,
if (fn(h, db) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (clicon_errno < 0)
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Reset callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
@ -101,7 +101,7 @@ clixon_plugin_reset_one(clixon_plugin_t *cp,
done:
return retval;
}
/*! Call all plugins reset callbacks
*
* The system 'state' should be the same as the contents of running_db
@ -114,10 +114,10 @@ int
clixon_plugin_reset_all(clicon_handle h,
char *db)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
int retval = -1;
clixon_plugin_t *cp = NULL;
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_reset_one(cp, h, db) < 0)
@ -169,7 +169,7 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
* This point in time is after "start" and before
* before daemonization/fork,
* It is not called if backend is started in daemon mode.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
@ -179,7 +179,7 @@ clixon_plugin_pre_daemon_all(clicon_handle h)
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_pre_daemon_one(cp, h) < 0)
@ -202,7 +202,7 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp,
clicon_handle h)
{
int retval = -1;
plgdaemon_t *fn; /* Daemonize plugin callback function */
plgdaemon_t *fn; /* Daemonize plugin callback function */
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_daemon) != NULL){
@ -212,7 +212,7 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp,
if (fn(h) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (clicon_errno < 0)
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
@ -224,14 +224,14 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp,
done:
return retval;
}
/*! Call all plugins "post-" daemonize callbacks
*
*
* This point in time is after "start" and after "pre-daemon" and
* after daemonization/fork, ie when
* daemon is in the background but before dropped privileges.
* In case of foreground mode (-F) it is still called but no fork has occured.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* @note Also called for non-background mode
@ -241,8 +241,8 @@ clixon_plugin_daemon_all(clicon_handle h)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_daemon_one(cp, h) < 0)
@ -289,7 +289,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
plgstatedata_t *fn; /* Plugin statedata fn */
cxobj *x = NULL;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
@ -299,7 +299,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
if (fn(h, nsc, xpath, x) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (clicon_errno < 0)
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
goto fail; /* Dont quit here on user callbacks */
@ -344,10 +344,10 @@ clixon_plugin_statedata_all(clicon_handle h,
int ret;
cxobj *x = NULL;
clixon_plugin_t *cp = NULL;
cbuf *cberr = NULL;
cbuf *cberr = NULL;
cxobj *xerr = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, &x)) < 0)
goto done;
@ -373,7 +373,7 @@ clixon_plugin_statedata_all(clicon_handle h,
x = NULL;
continue;
}
clicon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp));
clixon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp));
/* XXX: ret == 0 invalid yang binding should be handled as internal error */
if ((ret = xml_bind_yang(h, x, YB_MODULE, yspec, &xerr)) < 0)
goto done;
@ -436,13 +436,13 @@ clixon_plugin_lockdb_one(clixon_plugin_t *cp,
int retval = -1;
plglockdb_t *fn; /* Plugin statedata fn */
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_lockdb) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (fn(h, db, lock, id) < 0)
goto done;
goto done;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
}
@ -470,12 +470,12 @@ clixon_plugin_lockdb_all(clicon_handle h,
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_lockdb_one(cp, h, db, lock, id) < 0)
goto done;
}
}
retval = 0;
done:
return retval;
@ -485,6 +485,8 @@ clixon_plugin_lockdb_all(clicon_handle h,
*
* @param[in] h Clixon handle
* @param[in] xpath Registered XPath using canonical prefixes
* @retval 1 OK
* @retval -1 Error
*/
int
clixon_pagination_cb_call(clicon_handle h,
@ -505,17 +507,19 @@ clixon_pagination_cb_call(clicon_handle h,
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable && dispatcher_call_handlers(htable, h, xpath, &pd) < 0)
goto done;
retval = 1;
retval = 1; // XXX 0?
done:
return retval;
}
/*! Register a state data callback
*
/*! Register a state data callback
*
* @param[in] h Clixon handle
* @param[in] fn Callback
* @param[in] xpath Registered XPath using canonical prefixes
* @param[in] arg Domain-specific argument to send to callback
* @retval 0 OK
* @retval -1 Error
*/
int
clixon_pagination_cb_register(clicon_handle h,
@ -526,7 +530,7 @@ clixon_pagination_cb_register(clicon_handle h,
int retval = -1;
dispatcher_definition x = {xpath, fn, arg};
dispatcher_entry_t *htable = NULL;
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (dispatcher_register_handler(&htable, &x) < 0){
clicon_err(OE_PLUGIN, errno, "dispatcher");
@ -547,7 +551,7 @@ int
clixon_pagination_free(clicon_handle h)
{
dispatcher_entry_t *htable = NULL;
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable)
dispatcher_free(htable);
@ -579,7 +583,7 @@ transaction_new(void)
*
* @param[in] td Transaction data will be deallocated after the call
*/
int
int
transaction_free(transaction_data_t *td)
{
if (td->td_src)
@ -608,13 +612,13 @@ transaction_free(transaction_data_t *td)
*/
int
plugin_transaction_begin_one(clixon_plugin_t *cp,
clicon_handle h,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_trans_begin) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -623,7 +627,7 @@ plugin_transaction_begin_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
@ -639,19 +643,19 @@ plugin_transaction_begin_one(clixon_plugin_t *cp,
/*! Call transaction_begin() in all plugins before a validate/commit.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
*/
int
plugin_transaction_begin_all(clicon_handle h,
plugin_transaction_begin_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_begin_one(cp, h, td) < 0)
goto done;
@ -670,8 +674,8 @@ plugin_transaction_begin_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_validate_one(clixon_plugin_t *cp,
clicon_handle h,
plugin_transaction_validate_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
@ -686,7 +690,7 @@ plugin_transaction_validate_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
@ -701,13 +705,13 @@ plugin_transaction_validate_one(clixon_plugin_t *cp,
/*! Call transaction_validate callbacks in all backend plugins
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK. Validation succeeded in all plugins
* @retval -1 Error: one of the plugin callbacks returned validation fail
*/
int
plugin_transaction_validate_all(clicon_handle h,
plugin_transaction_validate_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
@ -732,14 +736,14 @@ plugin_transaction_validate_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_complete_one(clixon_plugin_t *cp,
clicon_handle h,
plugin_transaction_complete_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_trans_complete) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -748,7 +752,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
@ -762,7 +766,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
/*! Call transaction_complete() in all plugins after validation (before commit)
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
@ -770,7 +774,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
* @note Rename to transaction_complete?
*/
int
plugin_transaction_complete_all(clicon_handle h,
plugin_transaction_complete_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
@ -796,21 +800,21 @@ plugin_transaction_complete_all(clicon_handle h,
* plugin 2, then the revert will be made in plugins 1 and 0.
*/
static int
plugin_transaction_revert_all(clicon_handle h,
plugin_transaction_revert_all(clicon_handle h,
transaction_data_t *td,
int nr)
{
int retval = 0;
clixon_plugin_t *cp = NULL;
trans_cb_t *fn;
while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
if ((fn = clixon_plugin_api_get(cp)->ca_trans_revert) == NULL)
continue;
if ((retval = fn(h, (transaction_data)td)) < 0){
clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed",
__FUNCTION__, clixon_plugin_name_get(cp));
break;
break;
}
}
return retval; /* ignore errors */
@ -827,13 +831,13 @@ plugin_transaction_revert_all(clicon_handle h,
*/
int
plugin_transaction_commit_one(clixon_plugin_t *cp,
clicon_handle h,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -842,7 +846,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
@ -856,7 +860,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
/*! Call transaction_commit callbacks in all backend plugins
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
@ -865,18 +869,18 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
* and in reverse order.
*/
int
plugin_transaction_commit_all(clicon_handle h,
plugin_transaction_commit_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
int i=0;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
i++;
if (plugin_transaction_commit_one(cp, h, td) < 0){
/* Make an effort to revert transaction */
plugin_transaction_revert_all(h, td, i-1);
plugin_transaction_revert_all(h, td, i-1);
goto done;
}
}
@ -894,14 +898,14 @@ plugin_transaction_commit_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_commit_done_one(clixon_plugin_t *cp,
clicon_handle h,
plugin_transaction_commit_done_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit_done) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -910,7 +914,7 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
@ -924,14 +928,14 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp,
/*! Call transaction_commit_done callbacks in all backend plugins
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
* @note no revert is done
*/
int
plugin_transaction_commit_done_all(clicon_handle h,
plugin_transaction_commit_done_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
@ -955,14 +959,14 @@ plugin_transaction_commit_done_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_end_one(clixon_plugin_t *cp,
clicon_handle h,
plugin_transaction_end_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_trans_end) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -971,7 +975,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
@ -985,7 +989,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp,
/*! Call transaction_end() in all plugins after a successful commit.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error
@ -997,7 +1001,7 @@ plugin_transaction_end_all(clicon_handle h,
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_end_one(cp, h, td) < 0)
goto done;
@ -1008,14 +1012,14 @@ plugin_transaction_end_all(clicon_handle h,
}
int
plugin_transaction_abort_one(clixon_plugin_t *cp,
clicon_handle h,
plugin_transaction_abort_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_trans_abort) != NULL){
wh = NULL;
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
@ -1024,7 +1028,7 @@ plugin_transaction_abort_one(clixon_plugin_t *cp,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
@ -1038,19 +1042,19 @@ plugin_transaction_abort_one(clixon_plugin_t *cp,
/*! Call transaction_abort() in all plugins after a failed validation/commit.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error
*/
int
plugin_transaction_abort_all(clicon_handle h,
plugin_transaction_abort_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_abort_one(cp, h, td) < 0)
; /* dont abort on error */

View file

@ -70,6 +70,8 @@
* is started.
* @param[in] h Clixon backend
* @param[in] xt XML target
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_pseudo_set_log(clicon_handle h,
@ -78,8 +80,8 @@ restconf_pseudo_set_log(clicon_handle h,
int retval = -1;
char **argv;
int argc;
int i;
char *log = NULL;
int i;
char *log = NULL;
char *dbg = NULL;
cxobj *xb;
@ -138,6 +140,8 @@ restconf_pseudo_set_log(clicon_handle h,
* and insert it as a optimization to reading it from the backend.
* @param[in] h Clixon backend
* @param[in] xt XML target
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_pseudo_set_inline(clicon_handle h,
@ -146,11 +150,11 @@ restconf_pseudo_set_inline(clicon_handle h,
int retval = -1;
char **argv;
int argc;
int i;
int i;
cxobj *xrestconf;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
goto done;
if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL)
@ -170,7 +174,7 @@ restconf_pseudo_set_inline(clicon_handle h,
clicon_err(OE_XML, errno, "stdup");
goto done;
}
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
clixon_debug(CLIXON_DBG_DEFAULT, "%s str:%s", __FUNCTION__, str);
if (argv[i+1])
free(argv[i+1]);
argv[i+1] = str;
@ -186,6 +190,7 @@ restconf_pseudo_set_inline(clicon_handle h,
}
/*! Process rpc callback function
*
* - if RPC op is start, if enable is true, start the service, if false, error or ignore it
* - if RPC op is stop, stop the service
* These rules give that if RPC op is start and enable is false -> change op to none
@ -197,14 +202,14 @@ restconf_rpc_wrapper(clicon_handle h,
{
int retval = -1;
cxobj *xt = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
switch (*operation){
case PROC_OP_STOP:
/* if RPC op is stop, stop the service */
break;
case PROC_OP_START:
/* RPC op is start & enable is true, then start the service,
/* RPC op is start & enable is true, then start the service,
& enable is false, error or ignore it */
if (xmldb_get(h, "running", NULL, "/restconf", &xt) < 0)
goto done;
@ -235,7 +240,8 @@ restconf_rpc_wrapper(clicon_handle h,
}
/*! Enable process-control of restconf daemon, ie start/stop restconf by registering restconf process
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @note Could also look in clixon-restconf and start process if enable is true, but that needs to
* be in start callback using a pseudo plugin.
* - Debug flag inheritance only works if backend is started with debug. If debug is set later
@ -277,24 +283,24 @@ restconf_pseudo_process_control(clicon_handle h)
cprintf(cb, "%s/clixon_restconf", dir0);
pgm = cbuf_get(cb);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm);
}
if (!found &&
(dir1 = CLIXON_CONFIG_SBINDIR) != NULL){
cbuf_reset(cb);
cprintf(cb, "%s/clixon_restconf", dir1);
pgm = cbuf_get(cb);
clicon_debug(1, "Looking for %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Looking for %s", pgm);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm);
}
if (!found){
clicon_err(OE_RESTCONF, 0, "clixon_restconf not found in neither CLICON_RESTCONF_INSTALLDIR(%s) nor CLIXON_CONFIG_SBINDIR(%s). Try overriding with CLICON_RESTCONF_INSTALLDIR",
@ -343,7 +349,7 @@ restconf_pseudo_process_validate(clicon_handle h,
int retval = -1;
cxobj *xtarget;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
xtarget = transaction_target(td);
/* If ssl-enable is true and (at least a) socket has ssl,
* then server-cert-path and server-key-path must exist */
@ -374,8 +380,8 @@ restconf_pseudo_process_commit(clicon_handle h,
cxobj *xsource;
cxobj *cx;
int enabled = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
xtarget = transaction_target(td);
xsource = transaction_src(td);
if (xpath_first(xtarget, NULL, "/restconf[enable='true']") != NULL)
@ -425,13 +431,16 @@ restconf_pseudo_process_commit(clicon_handle h,
}
/*! Register start/stop restconf RPC and create pseudo-plugin to monitor enable flag
*
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
int
backend_plugin_restconf_register(clicon_handle h,
yang_stmt *yspec)
{
int retval = -1;
int retval = -1;
clixon_plugin_t *cp = NULL;
if (clixon_pseudo_plugin(h, "restconf pseudo plugin", &cp) < 0)

View file

@ -78,7 +78,7 @@
/*! Open an INET stream socket and bind it to a file descriptor
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] dst IPv4 address (see inet_pton(3))
* @retval s Socket file descriptor (see socket(2))
* @retval -1 Error
@ -111,7 +111,7 @@ config_socket_init_ipv4(clicon_handle h,
clicon_err(OE_UNIX, errno, "bind");
goto err;
}
clicon_debug(1, "Listen on server socket at %s:%hu", dst, port);
clixon_debug(CLIXON_DBG_DEFAULT, "Listen on server socket at %s:%hu", dst, port);
if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto err;
@ -126,7 +126,7 @@ config_socket_init_ipv4(clicon_handle h,
*
* The socket is accessed via CLICON_SOCK option, has 770 permissions
* and group according to CLICON_SOCK_GROUP option.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] sock Unix file-system path
* @retval s Socket file descriptor (see socket(2))
* @retval -1 Error
@ -154,7 +154,7 @@ config_socket_init_unix(clicon_handle h,
if (group_name2gid(config_group, &gid) < 0)
return -1;
#if 0
if (gid == 0)
if (gid == 0)
clicon_log(LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group);
#endif
/* create unix socket */
@ -169,16 +169,16 @@ config_socket_init_unix(clicon_handle h,
old_mask = umask(S_IRWXO | S_IXGRP | S_IXUSR);
if (bind(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){
clicon_err(OE_UNIX, errno, "bind");
umask(old_mask);
umask(old_mask);
goto err;
}
umask(old_mask);
umask(old_mask);
/* change socket path file group */
if (lchown(sock, -1, gid) < 0){
clicon_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group);
goto err;
}
clicon_debug(1, "Listen on server socket at %s", addr.sun_path);
clixon_debug(CLIXON_DBG_DEFAULT, "Listen on server socket at %s", addr.sun_path);
if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto err;
@ -190,8 +190,8 @@ config_socket_init_unix(clicon_handle h,
}
/*! Open backend socket, the one clients send requests to, either ip or unix
*
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval s Socket file descriptor (see socket(2))
* @retval -1 Error
*/
@ -220,12 +220,15 @@ backend_socket_init(clicon_handle h)
}
/*! Accept new socket client
*
* @param[in] fd Socket (unix or ip)
* @param[in] arg typecast clicon_handle
* @retval 0 OK
* @retval -1 Error
*/
int
backend_accept_client(int fd,
void *arg)
void *arg)
{
int retval = -1;
clicon_handle h = (clicon_handle)arg;
@ -242,7 +245,7 @@ backend_accept_client(int fd,
uid_t guid;
#endif
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
len = sizeof(from);
if ((s = accept(fd, &from, &len)) < 0){
clicon_err(OE_UNIX, errno, "accept");
@ -251,7 +254,7 @@ backend_accept_client(int fd,
if ((ce = backend_client_add(h, &from)) == NULL)
goto done;
/*
/*
* Get credentials of connected peer - only for unix socket
*/
switch (from.sa_family){
@ -281,7 +284,7 @@ backend_accept_client(int fd,
name = NULL;
}
break;
case AF_INET:
case AF_INET:
break;
case AF_INET6:
default:

View file

@ -41,7 +41,7 @@
/*
* Prototypes
*/
*/
int backend_socket_init(clicon_handle h);
int backend_accept_client(int fd, void *arg);

View file

@ -85,7 +85,7 @@ db_merge(clicon_handle h,
{
int retval = -1;
cxobj *xt = NULL;
/* Get data as xml from db1 */
if (xmldb_get0(h, (char*)db1, YB_MODULE, NULL, NULL, 1, WITHDEFAULTS_EXPLICIT, &xt, NULL, NULL) < 0)
goto done;
@ -138,7 +138,7 @@ startup_mode_startup(clicon_handle h,
int ret = 0;
int rollback_exists;
yang_stmt *yspec = clicon_dbspec_yang(h);
if (strcmp(db, "running")==0){
clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db);
goto done;
@ -273,8 +273,6 @@ load_extraxml(clicon_handle h,
* @retval 1 OK
* @retval 0 Validation failed
* @retval -1 Error
running -----------------+----+------>
reset loadfile / merge
@ -289,14 +287,14 @@ startup_extraxml(clicon_handle h,
int retval = -1;
char *tmp_db = "tmp";
int ret;
cxobj *xt0 = NULL;
cxobj *xt = NULL;
cxobj *xt0 = NULL;
cxobj *xt = NULL;
/* Clear tmp db */
if (xmldb_db_reset(h, tmp_db) < 0)
goto done;
/* Application may define extra xml in its reset function */
if (clixon_plugin_reset_all(h, tmp_db) < 0)
if (clixon_plugin_reset_all(h, tmp_db) < 0)
goto done;
/* Extra XML can also be added via file */
if (file){
@ -306,7 +304,7 @@ startup_extraxml(clicon_handle h,
if (ret == 0)
goto fail;
}
/*
/*
* Check if tmp db is empty.
* It should be empty if extra-xml is null and reset plugins did nothing
* then skip validation.
@ -325,7 +323,7 @@ startup_extraxml(clicon_handle h,
goto done;
if (ret == 0)
goto fail;
if (xt==NULL || xml_child_nr(xt)==0)
if (xt==NULL || xml_child_nr(xt)==0)
goto ok;
/* Merge tmp into running (no commit) */
if ((ret = db_merge(h, tmp_db, "running", cbret)) < 0)
@ -338,7 +336,7 @@ startup_extraxml(clicon_handle h,
if (xt0)
xml_free(xt0);
xmldb_get0_free(h, &xt);
if (xmldb_delete(h, tmp_db) != 0 && errno != ENOENT)
if (xmldb_delete(h, tmp_db) != 0 && errno != ENOENT)
return -1;
return retval;
fail:
@ -360,10 +358,10 @@ 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
/* Set up cache
* Now, access brief module cache with clicon_modst_cache_get(h, 1) */
if ((ret = yang_modules_state_get(h, yspec, NULL, NULL, 1, &x)) < 0)
goto done;

View file

@ -41,7 +41,7 @@
/*
* Prototypes
*/
*/
int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret);
int startup_extraxml(clicon_handle h, char *file, cbuf *cbret);
int startup_module_state(clicon_handle h, yang_stmt *yspec);

View file

@ -78,6 +78,7 @@
* entries in the struct below.
*/
/*! Backend specific handle added to header CLICON handle
*
* This file should only contain access functions for the _specific_
* entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c
@ -89,7 +90,7 @@ struct backend_handle {
clicon_hash_t *bh_data; /* internal clicon data (HDR) */
clicon_hash_t *ch_db_elmnt; /* xml datastore element cache data */
event_stream_t *bh_stream; /* notification streams, see clixon_stream.[ch] */
/* ------ end of common handle ------ */
struct client_entry *bh_ce_list; /* The client list */
int bh_ce_nr; /* Number of clients, just increment */
@ -104,7 +105,8 @@ backend_handle_init(void)
}
/*! Deallocates a backend handle, including all client structs
* @Note: handle 'h' cannot be used in calls after this
*
* @note: handle 'h' cannot be used in calls after this
* @see backend_client_rm
*/
int
@ -125,13 +127,14 @@ backend_handle_exit(clicon_handle h)
}
/*! Add new client, typically frontend such as cli, netconf, restconf
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] addr Address of client
* @retval ce Client entry
* @retval NULL Error
*/
struct client_entry *
backend_client_add(clicon_handle h,
backend_client_add(clicon_handle h,
struct sockaddr *addr)
{
struct backend_handle *bh = handle(h);
@ -158,7 +161,8 @@ backend_client_add(clicon_handle h,
}
/*! Return client list
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval ce_list Client entry list (all sessions)
*/
struct client_entry *
@ -170,7 +174,8 @@ backend_client_list(clicon_handle h)
}
/*! Actually remove client from client list
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] ce Client handle
* @see backend_client_rm which is more high-level
*/
@ -201,7 +206,8 @@ backend_client_delete(clicon_handle h,
}
/*! Debug print backend clients
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] f UNIX output stream
*/
int

View file

@ -43,6 +43,7 @@
*/
/*! Transaction data describing a system transition from a src to target state
*
* Clixon internal, presented as void* to app's callback in the 'transaction_data'
* type in clicon_backend_api.h
* The struct contains source and target XML tree (e.g. candidate/running)
@ -68,6 +69,7 @@ typedef struct {
} transaction_data_t;
/*! Pagination userdata
*
* Pagination can use a lock/transaction mechanism
* If locking is not used, the plugin cannot expect more pagination calls, and no state or
* caching should be used
@ -104,7 +106,7 @@ int clixon_plugin_lockdb_all(clicon_handle h, char *db, int lock, int id);
int clixon_pagination_cb_register(clicon_handle h, handler_function fn, char *path, void *arg);
int clixon_pagination_cb_call(clicon_handle h, char *xpath, int locked,
uint32_t offset, uint32_t limit,
uint32_t offset, uint32_t limit,
cxobj *xstate);
int clixon_pagination_free(clicon_handle h);

View file

@ -69,6 +69,7 @@
* would give running in source and 'a' and candidate in 'target'.
*/
/*! Get transaction id
*
* @param[in] td transaction_data
* @retval id transaction id
*/
@ -79,6 +80,7 @@ transaction_id(transaction_data td)
}
/*! Get plugin/application specific callback argument
*
* @param[in] td transaction_data
* @retval arg callback argument
*/
@ -89,6 +91,7 @@ transaction_arg(transaction_data td)
}
/*! Set plugin/application specific callback argument
*
* @param[in] td transaction_data
* @param[in] arg callback argument
*/
@ -101,6 +104,7 @@ transaction_arg_set(transaction_data td,
}
/*! Get source database xml tree
*
* @param[in] td transaction_data
* @retval src source xml tree containing original state
*/
@ -111,6 +115,7 @@ transaction_src(transaction_data td)
}
/*! Get target database xml tree
*
* @param[in] td transaction_data
* @retval xml target xml tree containing wanted state
*/
@ -121,6 +126,7 @@ transaction_target(transaction_data td)
}
/*! Get delete xml vector, ie vector of xml nodes that are deleted src->target
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
*/
@ -131,6 +137,7 @@ transaction_dvec(transaction_data td)
}
/*! Get length of delete xml vector
*
* @param[in] td transaction_data
* @retval len Length of vector of xml nodes
* @see transaction_dvec
@ -142,6 +149,7 @@ transaction_dlen(transaction_data td)
}
/*! Get add xml vector, ie vector of xml nodes that are added src->target
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
*/
@ -152,6 +160,7 @@ transaction_avec(transaction_data td)
}
/*! Get length of add xml vector
*
* @param[in] td transaction_data
* @retval len Length of vector of xml nodes
* @see transaction_avec
@ -163,6 +172,7 @@ transaction_alen(transaction_data td)
}
/*! Get source changed xml vector, ie vector of xml nodes that changed
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
* These are only nodes of type LEAF.
@ -177,6 +187,7 @@ transaction_scvec(transaction_data td)
}
/*! Get target changed xml vector, ie vector of xml nodes that changed
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
* These are only nodes of type LEAF.
@ -191,6 +202,7 @@ transaction_tcvec(transaction_data td)
}
/*! Get length of changed xml vector
*
* @param[in] td transaction_data
* @retval len Length of vector of xml nodes
* This is the length of both the src change vector and the target change vector
@ -211,8 +223,8 @@ int
transaction_print(FILE *f,
transaction_data th)
{
cxobj *xn;
int i;
cxobj *xn;
int i;
transaction_data_t *td;
td = (transaction_data_t *)th;
@ -267,7 +279,7 @@ transaction_dbg(clicon_handle h,
goto done;
}
if (i)
clicon_debug(dbglevel, "%s %" PRIu64 " %s del: %s",
clixon_debug(dbglevel, "%s %" PRIu64 " %s del: %s",
__FUNCTION__, td->td_id, msg, cbuf_get(cb));
cbuf_reset(cb);
for (i=0; i<td->td_alen; i++){
@ -276,7 +288,7 @@ transaction_dbg(clicon_handle h,
goto done;
}
if (i)
clicon_debug(dbglevel, "%s %" PRIu64 " %s add: %s",
clixon_debug(dbglevel, "%s %" PRIu64 " %s add: %s",
__FUNCTION__, td->td_id, msg, cbuf_get(cb));
cbuf_reset(cb);
for (i=0; i<td->td_clen; i++){
@ -290,7 +302,7 @@ transaction_dbg(clicon_handle h,
goto done;
}
if (i)
clicon_debug(dbglevel, "%s %" PRIu64 " %s change: %s",
clixon_debug(dbglevel, "%s %" PRIu64 " %s change: %s",
__FUNCTION__, td->td_id, msg, cbuf_get(cb));
done:
if (cb)
@ -299,7 +311,6 @@ transaction_dbg(clicon_handle h,
}
/*! Log a transaction
*
*/
int
transaction_log(clicon_handle h,

View file

@ -69,9 +69,9 @@ int transaction_log(clicon_handle h, transaction_data th, int level, const char
/* Pagination callbacks
* @see pagination_data_t internal structure
*/
uint32_t pagination_offset(pagination_data pd);
uint32_t pagination_limit(pagination_data pd);
int pagination_locked(pagination_data pd);
cxobj *pagination_xstate(pagination_data pd);
uint32_t pagination_offset(pagination_data pd);
uint32_t pagination_limit(pagination_data pd);
int pagination_locked(pagination_data pd);
cxobj *pagination_xstate(pagination_data pd);
#endif /* _CLIXON_BACKEND_TRANSACTION_H_ */